X drive programming Help

My team and i wish to program our robot so you can control it like a drone (ie. left joystick = fwd bwd strafe. right joystick = spin) but our programer’s have been unable to get full control.

our robot could not turn and drive at the same time (when turning it would override the driving command) and we could only strafe right or left (no 45 deg angles or anything)

i believe this was because they were using condition statements. i plan on trying to do it using a math based approach.

my idea was to be able to have full control of turning while strafing and driving.

any help would be greatly appreciated .


A math based approach is normally better when dealing with analogs in programming. If you have made an arcade style controller before, the concept is similar. For reference, the normal arcade drive normally looks something like this pseudo code.

leftMotor.move(throttle + turn); 
rightMotor.move(throttle - turn);

For an X-Drive, you need to do the same thing, but with 4 motors and 3 inputs instead of just 2 of each. The below is my code for 3260H’s X-Drive. It was written with PROS V5 C++ so your code will be a bit different.

leftFront_m.move(throttle+ turn + strafe);
rightFront_m.move(throttle - turn - strafe);
rightBack_m.move(throttle - turn + strafe);
leftBack_m.move(throttle + turn - strafe);

You can also add in a gyro to the code so the robot drives relative to the driver and not to the front of the robot, but you should get the normal drive working first.

1 Like

The code he put up there should work but I’m gonna put a v5 text up for text users since I’m pretty sure that’s not v5 text

Thanks alot. I figured something along the lines of that would be what is needed. Thanks again