In a vehicle using independent wheel control, applying the same power to each wheel generally does not result in the vehicle moving straight. This is caused by mechanical and surface differences experienced by each of the wheels. To reduce deviation in the vehicle heading, a better approach is to use a closed-loop controller that adjusts the power applied to two motors based on the difference in their rotations. One such controller is a well-known proportional-integral-derivative (PID) controller.
PID control is a basic control loop feedback mechanism. The controller minimizes the difference between the measured and the desired value of a chosen system variable by adjusting the system control inputs.
This example shows you 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). This example also illustrates how to switch between simulating the PID controller and running it on hardware in the same model.
PrerequisitesWe recommend completing the Communicating with LEGO MINDSTORMS NXT Hardware example.
Required Hardware- LEGO MINDSTORMS NXT Intelligent Brick
- Two LEGO MINDSTORMS NXT interactive servo motors
- USB cable
- LEGO MINDSTORMS NXT–compatible Bluetooth dongle (optional for Steps 3 and 5)
1. Build a vehicle using two motors to control two independent wheels. For example, you can use a vehicle similar to the LEGO Tri Bot. The building instructions for Tri Bot are given on the LEGO web site.
2. Connect the USB cable from your computer to the LEGO MINDSTORMS NXT Intelligent Brick.
3. If you are using External mode, set up the Bluetooth connection between the computer and the LEGO MINDSTORMS NXT Intelligent Brick. See Task 1 of the Communicating with LEGO MINDSTORMS NXT Hardware example for details.
4. On the LEGO MINDSTORMS NXT Intelligent Brick, press the orange button to turn the power on.
Task 2 – Simulate the Open-Loop Control ModelThis step illustrates that independently powered wheels cause deviations in vehicle heading.
1. Open the ‘lego_drive_openloop’ model that comes with the LEGO NXT Support Package. Observe two subsystems in the model.
2. Open the Open-Loop Controller subsystem. This subsystem controls the vehicle driving. Observe that the controller does not use the difference between two encoder outputs to control the motors.
3. Notice the Motors subsystem. The subsystem contains both simulated and actual motors. The Environment Controller block takes the outputs of the simulated or actual motors, depending on the current environment. This allows you to represent both simulated and actual motors in one model. As an alternative, you may create two models, one for simulation and the other one for running on actual hardware.
4. Click the Run button in the Simulink toolbar. Click the Scope block and observe that the Encoder Output Mismatch increases over time. This indicates that the vehicle will not move straight.
1. If you are using External mode, configure the model as described in Task 2 of the Communicating with LEGO MINDSTORMS NXT Hardwareexample.
2. In your Simulink model, click the Deploy To Hardware button on the toolbar. The model runs on the LEGO MINDSTORMS NXT hardware and the vehicle starts moving.
3. Notice that the path of the vehicle is not straight, as predicted by the simulation.
4. If you are using External mode, press the Stop button in the model. Otherwise, press the gray rectangle button on the LEGO MINDSTORMS NXT Intelligent Brick to turn the power off.
Task 4 – Simulate the Closed-Loop Control Model1. Open the ‘lego_drive_closedloop’ model that comes with the LEGO NXT Support Package. Observe two subsystems in the model.
2. Double-click the PID Controller subsystem. Notice that the P control is used to synchronize two motors when the vehicle runs straight. Also, notice that during a turn, no synchronization is applied.
3. Click the Run button in the Simulink toolbar. Click the Scope block and observe that the Encoder Output Mismatch remains close to zero. This indicates that the vehicle will skew less compared with the Open Loop Control model.
1. If you are using External mode, configure the model as described in Task 2 of the Communicating with LEGO MINDSTORMS NXT Hardwareexample.
2. In your Simulink model, click the Deploy To Hardware button on the toolbar. The model runs on the LEGO MINDSTORMS NXT hardware and the vehicle starts moving.
3. Observe that the path of the vehicle is more straight, as predicted by the simulation.
4. If you are using External mode, press the Stop button in the model. Otherwise, press the gray rectangle button on the LEGO MINDSTORMS NXT Intelligent Brick to turn the power off.
Other Things to Try- Adjust the PID Controller settings. Improve the vehicle’s ability to move straight on a rough or tilted surface.
This example showed how to simulate and implement a basic closed-loop controller on LEGO MINDSTORMS NXT hardware. In the example, you learned that:
- 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 the power that should be applied to each wheel individually.
- Both simulated and actual hardware may be used in the same model, provided that a mechanism for switching between them exists.
Comments
Please log in or sign up to comment.