Using PID to maintain speed and a straight line
In this section, we’ll learn how to combine the motor distance measurement with a PID controller driving each motor, moving at a particular speed, and keeping the robot straight. Let’s start by understanding this system.
The speed control system
We can set a target speed in meters per second for the robot and compare the converted wheel speeds with it.
The following diagram shows how we’ll use this to regulate the robot’s driving speed:
Figure 11.5 – Controlling the speed of two motors
The preceding diagram shows the control system. It starts at the left from a set speed and compares that with the actual speed. The actual speed comes from the encoders, with their ticks converted into m/s. The error is the difference between the speeds.
The error goes into the PID controller, which then produces an acceleration for the motor PWM. The motor power will increase for...