PID control with X-Drive

Hello, I am not the best at programming and am unsure how to set up PID control for my x drive base with Omni wheels. I understand how PID control works with a tank drive setup. This is a blank state of what I understand, but am unsure how to implement this for x drive. If anyone could explain how I could go about setting up my PID for x-drive that would be great, thank you.
Kp = ;
Ki = ;
Kd = ;

error = 0;
lastError = 0;
integral = 0;
derivative = 0;

while ( leftEncoderClicks < targetClicks ) {
error = leftEncoderClicks - rightEncoderClicks;
integral = integral + error;
derivative = error - lastError;

rightPower = leftPower + (error * Kp)
+ (integral * Ki)
+ (derivative * Kd);


rightPower = 0;
leftPower = 0;

One approach might be to understand what is different between what you do understand and what you don’t.

A PID is one instance of a control-loop - you have some desired state you want to achieve, and applying the PID algorithm is one way to achieve that desired state.

A tank drive has 2 degrees of freedom - front/back and rotating clockwise/counter-clockwise. An x-drive has 3 degrees of freedom - front/back, rotating clockwise/counter-clockwise, and left/right strafing.

How did you apply PID to your tank drive? Does that same application exist in the x-drive? Are there additional applications in the x-drive not present in the tank-drive?


The answer (as it turns out) is you can treat an x-drive exactly how you would a tank drive. Setting all the motors in one direction makes the robot move front to back (or vice-versa) and adding and subtracting power from the left/right side makes the robot turn. Of course this is dependent on your motor definitions, but under the assumption that positive voltage for all the motors gets the robot moving forward –– then that’s how it would work.

To better understand why this works, pay attention to how the velocity vectors of each wheel combine for the resultant vector. Otherwise, just take my word for it.


Mind you, this does not describe how to strafe and turn/translate simultaneously. That requires a bit more math. This is ONLY for translating while rotating or either one independently.