In this example, you will learn how to simulate a simple closed-loop control algorithm in Simulink® and then run it on a wheeled vehicle with LEGO® MINDSTORMS® EV3™ hardware.
Building controllers for vehicles with independent wheel controls is challenging because applying the same power to each wheel generally doesn’t make the vehicle move in a straight line. To reduce the effect of mechanical and surface differences in the vehicle heading, you can use a closed-loop controller. This example uses a proportional-integral-derivative (PID) controller to adjust the power applied to two motors based on difference in their rotations.
PID control is a basic control-loop feedback mechanism. The controller minimizes the difference between the measured and the desired value of a system variable by adjusting the system control inputs.
This example shows how to simulate the controller using a simple plant model, first with no feedback control (open-loop control), and then with feedback control (closed-loop control). You’ll also learn how to switch between simulating the PID controller and running it on hardware in the same model.
Keep these points in mind when building the example system:
- Adjusting the PID controller settings helps to improve the vehicle’s ability to move straight on a rough or tilted surface.
- Using Simulink External mode lets you tune parameters and monitor signals.
- Open-loop control does not ensure straight driving in a vehicle with independently powered wheels.
- Closed-loop control uses the difference between two encoder outputs to calculate how much power to apply to each wheel individually.
- You can use both simulated and actual hardware in the same model, provided there’s a mechanism for switching between them.
For step-by-step details and to download the code visit: http://www.mathworks.com/examples/simulink/4278-drive-with-pid-control