DC Motors Control – Synchronize 2 motors with PID

Motors control is very important in Micromouse. The better we control the motors, the more accurate the mouse turns.

The very basic motor control technique is using PWM (Pulse-width Modulation):

This technique allows us to change the speed of DC motors. However, there is no feedback loop, so we have no idea what is the actual speed of motors. This can be solved by test and modify the PWM value so that the motors can reach the set speed. That means we basically do a mapping between set speed and PWM value. For example, PWM duty cycle – motors rpm, 10% – 1000rpm, 20% – 2000rpm, 30% – 3000rpm, … Then if we want to run at 2500rpm, we set PWM duty cycle to 25%. But this is very inaccurate.

Let add a feedback loop to the system:

Now we have a feedback signal from motors so we know how to adjust the value that set the PWM duty cycle. The minus sign from feedback loop means we calculate the error and send this error to PWM function. This can be understood as “if actual speed is slower than set speed, increase PWM duty cycle, if actual speed is higher than set speed, decrease PWM cycle”. I think you all see the problem in this control system. The speed will oscillate at the set speed.

How to solve this problem? Fortunately, we have PID control algorithm. The easiest way to understand how PID works is thinking as we are driving a car from A to B. If we are too far from B, we hit the gas pedal to gain speed (P). As we get closer to B, we will hit on the break to slow down (D). And when we are very close to B, we move slowly to B (I).  I will not go too deep in PID here (we can find a lot of articles online). So our system will look like this:

So now we have a perfect system that works very well. This basic design is using everywhere in robotic industrial include servo system in which the accuracy go down to nanometers.

When the distance come into place, we need to modify our system. Let’s say we need our Micromouse to run 16cm, how do we do? This design can solve the problem:

We add the function Distance to Speed into our system. The very basic Distance to Speed function is just set the speed to “set speed” when error bigger than zero. That means keep going until we reach desired distance. As desired distance has been reached, set “set speed” to zero to stop the mouse. Later we can modify this “Distance to speed” function to make the Micromouse accelerate and decelerate.

Now when we have one motor that goes exactly at the speed that we set, thanks to PID, we see that it is so much easier to synchronize to motors to make the mouse go straight:

There are some other designs that use to synchronize two motors by using one as a master and the other one as a follower. That also works too, but I just don’t prefer it.

Next problem is how to make the mouse turn? .. .. .. .. ..

 

Leave a Reply