Robotc

i need help with code making a arcade drive with four motor on the right analog stick.:eek:

Something like this (not tested or compiled), motor_left_1 etc. should be defined in motors and sensors setup.

#define     JOY_DRIVE_V     vexJSRightV
#define     JOY_DRIVE_H     vexJSRightH

void arcade_drive()
{
    int    ctl_v;
    int    ctl_h;
    int    drive_l;
    int    drive_r;
    
    ctl_v = vexRT JOY_DRIVE_V ];
    ctl_h = vexRT JOY_DRIVE_H ];

    // Create drive for left and right motors
    drive_l = (ctl_v + ctl_h) / 2;
    drive_r = (ctl_v - ctl_h) / 2;
    
    motor motor_left_1 ]  = drive_l;
    motor motor_left_2 ]  = drive_l;
    motor motor_right_1 ] = drive_r;
    motor motor_right_2 ] = drive_r;
}

could u break it down and help me??

Here I am defining the two joystick axis I want to use
vexJSRightV is the same as Ch2
vexJSRightH is the same as Ch1
I’m doing this so if I decided to change to the left stick it’s easy to find, you could skip if you want and just use Ch1 and Ch2 in the code.

#define     JOY_DRIVE_V     vexJSRightV
#define     JOY_DRIVE_H     vexJSRightH

Some variables to make the code easier to read

    int    ctl_v;
    int    ctl_h;
    int    drive_l;
    int    drive_r;

Get the values of the vertical and horizontal joystick and save in two variables

    ctl_v = vexRT JOY_DRIVE_V ];
    ctl_h = vexRT JOY_DRIVE_H ];

This is the classic arcade drive algorithm, you could skip the divide by 2 for a faster drive. store the result in two variables, one for the left motors and one for the right.

    // Create drive for left and right motors
    drive_l = (ctl_v + ctl_h) / 2;
    drive_r = (ctl_v - ctl_h) / 2;

Send the left drive value to the two left motors

    motor motor_left_1 ]  = drive_l;
    motor motor_left_2 ]  = drive_l;

Send the right drive value to the two right motors

    motor motor_right_1 ] = drive_r;
    motor motor_right_2 ] = drive_r;

This code is deliberately long, it could be shortened to perhaps 4 lines but I thought it would be easier to understand this way.

what would the one in four lines look like?

    motor motor_left_1 ]  = (vexRT vexJSRightV ] + vexRT vexJSRightH ]) / 2;
    motor motor_left_2 ]  = (vexRT vexJSRightV ] + vexRT vexJSRightH ]) / 2;
    motor motor_right_1 ] = (vexRT vexJSRightV ] - vexRT vexJSRightH ]) / 2;
    motor motor_right_2 ] = (vexRT vexJSRightV ] - vexRT vexJSRightH ]) / 2;

just so i can understand it can u break it down?

do u also know how to program a four motor drive with a holonomic drive all on the right joy stick?

You can’t really, while still taking full advantage of the holo drive. One joystick is needed to control forward/back/side-side motion, while the other would be needed to control spin. (At least, that’s the way I see it)

//Andrew

i figured it out

Will you tell how? :slight_smile:

//Andrew

well you have to have a seprate joystick for the strafe.

Ok, thanks! :slight_smile:

//Andrew