Turning left/right using PID controller

Hello guys, I’m having trouble understanding how to specify where to turn (left/right) using a PID controller, I’ve been doing research on PID loops and no one goes in depth on how to code the actual movement of the robot.

Any help will be appreciated.

So most teams separate turning from lateral movement. The logic is the same as driving straight but your constants may differ. Setting one side of motors to spin in the opposite direction will cause the robot to turn and inputting a negative value into the function would cause it to turn in the opposite direction. You also have to account for the opposing rotations when calculating error. Since the motors are spinning in different directions unless you take the absolute value of the motor encoders, which is not recommended, the left and right side will read different values just keep that in mind.

4 Likes