Driving a known distance
We’ll need to bring together some of the previous techniques for this. Then, we’ll build a variation of the speed controller – a distance controller – so that we can update the distance and let the motor PIDs reach it. This app will use a similar structure, including control and asynchronous tasks, as in the previous example.
Theory of operation
The following diagram shows the theory of operation for this behavior:
Figure 11.7 – Controlling distance and speed
The preceding diagram shows an overview of this system. The distance tracker tracks distance over time at a given speed, and the distance controller directly controls the motors to try and match a distance. Note the feedback from the motor into the distance controller. We will have one of these per motor.
Let’s take a closer look at the distance tracker:
Figure 11.8 – The distance tracker
The left...