Need help setting up drive on robotc

I am not at my computer so i cannot post the code but it a simple tank control. We have a 6 motor drive that we are trying to switch to a PS4 type of control where forward and backward is on the left stick and left right is on the right stick… just like a PS4 controller in a typical video game. We have ports 2 3 and 4 on the left and 5 6 7 on the right.

Some questions keep causing me some thinking issues. Would the slavemotor command help control other motors on one side or does each motor have to have a seperate vexrt line.

The other issue is the coding to make it like the ps4.

Can you guys shed some light on this or suggest solutions?

I believe that what you are describing is similar to split arcade control. RobotC already includes a sample arcade control program that maps the 4 functions to a single stick. You can use the same formula and replace the horizontal axis channel with the horizontal channel on the other stick.

We call it channel mixing… some basic code would look like this where leftDrive(speed) moves the left wheels and rightDrive(speed) moves the right wheels.


int left = vexRT[channel3] - vexRT[channel1];
int right = vexRT[channel3] + vexRT[channel1];

if(left > -15 && left < 15){
     left = 0;
}
if(right > -15 && right < 15){
     right = 0;
}

leftDrive(left);
rightDrive(right);

Play around with the signs and order of the first block to make it do what you want it to.

Thanks guys! I will get on it in the morning.

My team doesn’t like using the slaveMotor command, partly because you just look at the code and see motor[port1] = 127; and if you aren’t looking at the top of the program, you wonder why ports 2 and 3 are also spinning. Instead, we just do this:


motor[port1] =
  motor[port2] =
  motor[port3] =
  127;

It’s a few extra lines, but it does the same thing. It works because the assignment operator = returns the value being assigned (on the right side). I personally also make a function for assignments like this because it requires fewer changes to the code if we add motors to one system and take them from another.
As for your split arcade control scheme, you will want the right side of the drive reversed (assuming the motors are closer to the middle of the robot than the wheels and not driving gears). Arcade control looks like this:


#define RX vexRT[Ch1]
#define LY vexRT[Ch3]

const int stickThresh = 15;

void setLDrive(int pwr) {
  motor[flWheel] =
    motor[mlWheel] =
    motor[blWheel] =
    pwr;
}

void setRDrive(int pwr) {
  motor[frWheel] =
    motor[mrWheel] =
    motor[brWheel] =
    pwr;
}

task main() {
  int ly,
    rx;
  while(true) {
    if(abs(LY) > thresh)
      ly = LY;
    else
      ly = 0;
    if(abs(RX) > thresh)
      rx = RX;
    else
      rx = 0;

    setLDrive(ly + rx);
    setRDrive(ly - rx);
  }
}

The left y-axis is positive on both sides because it controls the robot’s forward and backward motion, and the wheels should be spinning in the same direction. The right x-axis is positive on the left side and negative on the right side because when it is positive, the robot should turn right. This requires the left side to go forward (positive) and the right side to go backward (negative).

Thanks lpieroni ! That actually answered some long time questions about code structure in RobotC. Thanks
Bill R.