RobotC drive programming help.

Hello, we are attempting to use dual controllers to our robot. our essential issue is that we are trying to allow both remotes to drive, the motors barely run while either controller is attempting to drive, but it runs fine while using only one controller. Our goal is to have both sets of joysticks to have the ability to drive.

task usercontrol()
{
//joysticks—drive
While (true)
{
motor[port1] = vexRT[Ch2];
motor[port10] = vexRT[Ch2];
motor[port2] = vexRT[Ch3];
motor[port3] = vexRT[Ch3];

motor[port1] = vexRT[Ch2Xmtr2];
motor[port10] = vexRT[Ch2Xmtr2];
motor[port2] = vexRT[Ch3Xmtr2];
motor[port3] = vexRT[Ch3Xmtr2];

Try combining both joysticks’ values:


motor[port1] = vexRT[Ch2] + vexRT[Ch2Xmtr2];
// etc.

Thanks a million @TexasVex

Or you can give one controller (probably the main one) priority, and do something like this:



#define RX Ch1
#define LY Ch3

#define RX2 Ch1Xmtr2
#define LY2 Ch3Xmtr2

int driveY,
  driveX;
const int driveThresh = 7;

task main() {
  while(true) {

    if(abs(vexRT[RX]) > thresh)
      driveX = vexRT[RX];
    else if(abs(vexRT[RX2]) > thresh)
      driveX = vexRT[RX2];
    else
      driveX = 0;

    if(abs(vexRT[LY]) > thresh)
      driveY = vexRT[LY];
    else if(abs(vexRT[LY2]) > thresh)
      driveY = vexRT[LY2];
    else
      driveY = 0;

  motor[rDrive] =
    driveY - driveX;

  motor[lDrive] =
    driveY + driveX;

  }

}

Note: This code is for arcade control on a 2 motor drive, but to add another motor to each drive, you just need to change this


  motor[rDrive] =
    driveY - driveX;

  motor[lDrive] =
    driveY + driveX;

to this


  motor[rDrive1] =
    motor[rDrive2] =
    driveY - driveX;

  motor[lDrive1] =
    motor[lDrive2] =
    driveY + driveX;

and for tank control, you need to change driveY to driveLY, driveX to driveRY, and vexRT[Ch1] (in the code, it’s vexRT[RX] because of a #define) to vexRT[Ch2]. Then, set the left drive to driveLY and the right drive to driveRY.
I personally prefer arcade control, but that’s just me.

By configuring your control scheme this way, your primary driver always has priority over the secondary driver’s instructions, so if the drivers go in opposite directions, the drive, rather than being set to zero, is controlled by the main driver. It also has a built in threshold, since that is really easy to include here and prevents a joystick that doesn’t rest at 0 from locking out the secondary controller.

Notes about a few of my practices:

If, else if, and else statements, as well as while loops, do not always need curly braces { }. When they don’t have curly braces, only the code up to the next semicolon ; is included in the statement. Generally I avoid doing this, at least on Vex Forum, where other programmers look over my code, but curly braces on iPhones are really annoying.

#define is a preprocessor directive. Basically, before the code is compiled into assembly language, the compiler replaces every instance of the first word with the second one. It makes code more readable, which is good. I use them very frequently, and they are really handy.