# How to make a diff robot (2 traction wheels front and 2 castor wheels back) to go straight?

I’m developing a differential robot. My wheeled robot has two castor wheels in the back and two driven wheels in the front. The motor controller I’m using can handle two motors each with 90 cpr. Each motor has a PI controller built-in in the motor controller to control how much current (torque) goes to the motors. I have a Python code that sends ticks/s to the motor controller for each motor. If I want the robot to go straight, I just send the same ticks for both of the motors. I know that is impossible to achieve perfect straight line. The problem is that I’m not able to maneuver the rover because whenever I want to go straight (sending same speed for both motors), it ends up rotating in place to the right. Therefore, the left side is moving way quicker than the right ride. Could it be and issue with the tuning? I have the same value of the PI constants (KP and KI) for both motors. I was thinking in implementing a PID controller in the Python side to have another closed loop system besides the one in the motor controller. Is it recommended this approach? What else I can try?

Best,

• You don't mention what is the input to the PIDs. Do you have rotation enconders on each wheel, or some kind of angular velocity measurement? – Juancho Nov 30 '19 at 14:45
• As @Juancho said, try to implement a control for the angular speed/position of the wheel. I had similar problem and solved it with measurements of encoders and and a PI controller, as for the weights I didn't use any specific method, just trial and error – nionios Nov 30 '19 at 19:56
• @Juancho I have three hall effect sensors in each wheel. The motor controller is using a PI not a PID. – andrestoga Dec 2 '19 at 1:55
• @nionios basically, implementing another control loop (PID) on top of the PI of the motor controller? – andrestoga Dec 2 '19 at 2:06
• @andrestoga Yep exactly, but this one is going to control the angular speed of the motor, because basically this is what you want to control. Same current doesn't mean same angular velocity because of abnormalities in each motor. – nionios Dec 2 '19 at 8:26