Okay, to do this is very simple, we simply take Cody’s code (Haha. =D ), and edit the motor power and direction calculation part:
m1 = (joy_1_y) + (-1 * joy_1_x) + (-1 * joy_2_x);
m2 = (-1 * joy_1_y) + (-1 * joy_1_x) + (-1 * joy_2_x);
m3 = (-1 * joy_1_y) + (joy_1_x) + (-1 * joy_2_x);
m4 = (joy_1_y) + (joy_1_x) + (-1 * joy_2_x);
Now we can just remove the joy_1_x parts (the right joystick’s X axis movement, that causes the robot to move left and right), as the only thing we want the “main” four motors/wheels (the ones set up in the tank drive configuration) to do, is to drive forward, backward, and spin, no left to right movement, as that is done by the 5th drive motor/wheel. So, we will get this: (Remember, since you want the right side to control the direction, and the left to control spinning/turning, we flip which joystick is “1” and which one is “2”.)
m1 = (joy_2_y) + (-1 * joy_1_x);
m2 = (-1 * joy_2_y) + (-1 * joy_1_x);
m3 = (-1 * joy_2_y) + (-1 * joy_1_x);
m4 = (joy_2_y) + (-1 * joy_1_x);
**EDIT:
Now, since this part is only tank drive, both left motors will be equal in direction and speed, same with the right, but also our motor setup is a little different, so we will do this:
**m1 = (joy_2_y) + (-1 * joy_1_x);
m2 = (joy_2_y) + (-1 * joy_1_x);
m3 = (joy_2_y) + (joy_1_x);
m4 = (joy_2_y) + (joy_1_x);**
**
Now we simply add in the 5th drive motor/wheel, which is equal to joy_1_x (the right joystick’s X axis movement), to get this:
m1 = (joy_2_y) + (-1 * joy_1_x);
m2 = (joy_2_y) + (-1 * joy_1_x);
m3 = (joy_2_y) + (joy_1_x);
m4 = (joy_2_y) + (joy_1_x);
m5 = (joy_1_y);
NOTE: You may have to reverse some of the drive motors to get this to work properly, but you should not have to edit this code.
All in all you will get something like this:
//Vars
joy_1_x = 127;
joy_1_y = 127;
joy_2_x = 127;
joy_2_y = 127;
m1 = 0;
m2 = 0;
m3 = 0;
m4 = 0;
m5 = 0;
while(teleop)
{
// Grab Values
joy_1_x = vexrx(1,1) - 127;
joy_1_y = vexrx(1,2) - 127;
joy_2_x = vexrx(1,2) - 127;
//Math...
m1 = (joy_2_y) + (-1 * joy_1_x);
m2 = (joy_2_y) + (-1 * joy_1_x);
m3 = (joy_2_y) + (joy_1_x);
m4 = (joy_2_y) + (joy_1_x);
m5 = joy_2_x;
//Checks
if (m1 >= 127)
{
m1 = 127;
}
else if(m1 <= -127)
{
m1 = -127;
}
if (m2 >= 127)
{
m2 = 127;
}
else if(m2 <= -127)
{
m2 = -127;
}
if (m3 >= 127)
{
m3 = 127;
}
else if(m3 <= -127)
{
m3 = -127;
}
if (m4 >= 127)
{
m4 = 127;
}
else if(m4 <= -127)
{
m4 = -127;
}
//Output
pwm(1, m1 + 127);
pwm(2, m2 + 127);
pwm(3, m3 + 127);
pwm(4, m4 + 127);
pwm(5, m5 + 127);
}
-Jordan