Competition Template (ROBOTC Code Help)

OK, I am trying to put our drive code into a Competition Template so I can use the Competition Switch.

Here is the code we are using now to drive the robot around

#pragma config(Motor,  port1,           HP393LeftFront, tmotorVex393, openLoop, reversed)
#pragma config(Motor,  port2,           HP393LeftBack, tmotorVex393, openLoop, reversed)
#pragma config(Motor,  port3,           IntakeLeft,    tmotorVex393, openLoop)
#pragma config(Motor,  port4,           IntakeRight,   tmotorVex393, openLoop)
#pragma config(Motor,  port5,           StrafingWheelLeft, tmotorVex393, openLoop)
#pragma config(Motor,  port6,           StrafingWheelRight, tmotorVex393, openLoop)
#pragma config(Motor,  port7,           LiftRight,     tmotorVex393, openLoop)
#pragma config(Motor,  port8,           LiftLeft,      tmotorVex393, openLoop)
#pragma config(Motor,  port9,           HP393RightFront, tmotorVex393, openLoop)
#pragma config(Motor,  port10,          HP393RightBack, tmotorVex393, openLoop)
//*!!Code automatically generated by 'ROBOTC' configuration wizard               !!*//

task main()
{

  while(1 == 1)
  {
    motor[HP393LeftFront] = vexRT[Ch2];
    motor[HP393LeftBack] = vexRT[Ch2];
    motor[HP393RightFront] = vexRT[Ch3];
    motor[HP393RightBack] = vexRT[Ch3];
    motor[StrafingWheelLeft] = (vexRT[Btn6U] - vexRT[Btn5U])*127;
    motor[StrafingWheelRight] = (vexRT[Btn6U] - vexRT[Btn5U])*127;
    motor[LiftLeft] = (vexRT[Btn7DXmtr2] - vexRT[Btn7UXmtr2])*127;
    motor[LiftRight] = (vexRT[Btn7DXmtr2] - vexRT[Btn7UXmtr2])*127;
    motor[IntakeLeft] = (vexRT[Btn8DXmtr2] - vexRT[Btn8UXmtr2])*127;
    motor[IntakeRight] = (vexRT[Btn8DXmtr2] - vexRT[Btn8UXmtr2])*127;
  }
}
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

How do I put the above code into a Competition Template? I’m guessing I stick it somewhere here

task usercontrol()
{
	// User control code here, inside the loop

	while (true)
	{
	  // This is the main execution loop for the user control program. Each time through the loop
	  // your program should update motor + servo values based on feedback from the joysticks.

	  // .....................................................................................
	  // Insert user code here. This is where you use the joystick values to update your motors, etc.
	  // .....................................................................................

	  UserControlCodePlaceholderForTesting(); // Remove this function call once you have "real" code.
	}
}

But I don’t know how, or really where…

Thanks!
Team_323Z_Drive_Code.c (1.61 KB)

Read the comments in the competition templete!!! It tells you what to do :stuck_out_tongue:

// .....................................................................................
// Insert user code here. This is where you use the joystick values to update your motors, etc.
// .....................................................................................

Your code would look like this:


task usercontrol()
{
  while(true)
  {
    motor[HP393LeftFront] = vexRT[Ch2];
    motor[HP393LeftBack] = vexRT[Ch2];
    motor[HP393RightFront] = vexRT[Ch3];
    motor[HP393RightBack] = vexRT[Ch3];
    motor[StrafingWheelLeft] = (vexRT[Btn6U] - vexRT[Btn5U])*127;
    motor[StrafingWheelRight] = (vexRT[Btn6U] - vexRT[Btn5U])*127;
    motor[LiftLeft] = (vexRT[Btn7DXmtr2] - vexRT[Btn7UXmtr2])*127;
    motor[LiftRight] = (vexRT[Btn7DXmtr2] - vexRT[Btn7UXmtr2])*127;
    motor[IntakeLeft] = (vexRT[Btn8DXmtr2] - vexRT[Btn8UXmtr2])*127;
    motor[IntakeRight] = (vexRT[Btn8DXmtr2] - vexRT[Btn8UXmtr2])*127;
  }
}

For your consideration:

I noticed you are using a tank drive. You may want to switch to arcade-style driving, as it is more intuitive (for me, at least). There is an arcade-drive function in the RobotC Natural Language library, although I’ve never tried it myself.

Also, our team found that 1 driver is far faster/better than having two.

On another topic:

I also need some help with RobotC Code. I’m trying to develop a holonomic drive robot, but my program (attached) doesn’t seem to be working. The motors are jumpy, and channels 1 and 4 don’t seem to be doing anything.

I’ve tried my ConvertToHolonomic function in a computer application (using Code::Blocks), and it works just fine. Any help?
Holonomic Drive 2.c (4.97 KB)

So I ran the code and it looks like it should work, just considering channels 3&4 as arcade drive the motors seems to be doing the right thing, however, as two of the motors need to be reversed somewhere, and you did not do it in the “motors and sensors” setup then did you reverse the wiring somewhere ?

Do they work correctly if the robot is not on the ground and the motors and wheels can free run?

Which version of ROBOTC, master firmware etc. are you using ?

I have the wires reversed on the robot such that setting them all to +127 drives the robot forwards.

I’ve been testing entirely with the wheels elevated, so that shouldn’t be the problem.

I just updated my Cortex on monday (both master and robotc firmware), but I’ll check it again on monday when I can access the robot. I was running RobotC 3.5 when I downloaded, so I’ll try again with 3.51 and see if that fixes it.

Ok, 3.51 will fix your issue.

V3.50 has some problems with the order that expressions are evaluated, the divide is evaluated before the multiply, this is wrong.

To resolve this under 3.50, add parenthesis as follows.

    MTarget[0] = (( y1 + x1 + Strafe ) * B) / A;//These four lines of code are the meat of this function. everything else is just to make them work.
    MTarget[1] = (( y1 + x1 - Strafe ) * B) / A;// Multiplying by B / A ensures that no motor value exceeds the greatest input value (which is 127 or -127 for joystick input).
    MTarget[2] = (( y1 - x1 - Strafe ) * B) / A;
    MTarget[3] = (( y1 - x1 + Strafe ) * B) / A;

V3.51 fixes most of these issues, I recommend that everyone updates, V3.51 was released yesterday ( 9/21/2012 ).

Edit:

For the technically minded, here is an excerp from the assembly code for 3.50 with and without parenthesis, and also the improved 3.51.

//V3.50 - wrong evaluation order
//MTarget[1] = ( y1 + x1 - Strafe ) * B / A;
0088: A9060600290000290400     G06(short) = x1:S00(short) - (Strafe:S04(short))
0092: 08060600290200           G06(short) += y1:S02(short)        
0099: C510290800               S10(short) = B:S08(short)           // Store in temp variable
009E: 0B291000290600           S10(short) /= A:S06(short)          // Perform <op> on temp variable
00A5: 0A060600291000           G06(short) *= S10(short)           

//V3.50 - using parenthesis
//MTarget[1] = (( y1 + x1 - Strafe )) * B / A;
0083: A9060600290000290400     G06(short) = x1:S00(short) - (Strafe:S04(short))
008D: 08060600290200           G06(short) += y1:S02(short)        
0094: 0A060600290800           G06(short) *= B:S08(short)         
009B: 0B060600290600           G06(short) /= A:S06(short)         

//V3.51
//MTarget[1] = ( y1 + x1 - Strafe ) * B / A;
0083: A8060600290200290000     G06(short) = y1:S02(short) + x1:S00(short)
008D: 09060600290400           G06(short) -= Strafe:S04(short)    
0094: 0A060600290800           G06(short) *= B:S08(short)         
009B: 0B060600290600           G06(short) /= A:S06(short)

That solved my problem, many thanks.

I can’t update to 3.51 on the school computers where I’m at (it requires administrative priveleges) so the tip regarding v3.5 was very helpful.

Now I can move on to more fun things, like encoder-based mapping and associated functions :D.

.