This example shows how to use blocks from the LEGO® MINDSTORMS® NXT™ library to create a Simulink® model and run it on the LEGO MINDSTORMS NXT hardware.
A robot is an automatic device that performs functions usually attributed to humans. The robots are normally controlled by embedded processors that execute a controller algorithm. A robot usually operates autonomously, but sometimes can be assisted by a human over a communication channel.
In this example you will use LEGO MINDSTORMS NXT hardware to build Roving Explorer, a robot that can perform several complex tasks autonomously or with your guidance over the Bluetooth communication channel.
Roving Explorer starts or stops moving when it detects a clapping sound. When it encounters an obstacle, the robot beeps. If the obstacle is small, the robot grasps it with its claws and makes a right turn. If the obstacle is large, the robot turns right to avoid it. The robot may also detect surface edges.
The robot functions are implemented in a Simulink model. In this example you will review how the individual functions, such as collision avoidance, or object detection and retrieval, is implemented. You will learn the roles of individual LEGO MINDSTORMS NXT library blocks in controlling the robot.
We recommend completing Communicating with LEGO MINDSTORMS NXT Hardware example.
LEGO MINDSTORMS NXT Base Set
LEGO MINDSTORMS NXT-compatible Bluetooth® dongle (optional for Tasks 3 and 4)
1. Build the robot. You can use the instructions on the LEGO Web site.
2. Connect a USB cable from your computer to the robot.
3. If you are using Bluetooth, set up the Bluetooth connection between the computer and the robot. See Task 1 in Communicating with LEGO MINDSTORMS NXT Hardware example for details.
4. On LEGO MINDSTORMS NXT Intelligent Brick, press the orange button to turn the power on.
Note Your version of the LEGO MINDSTORMS NXT set may include a color sensor instead of a light sensor. If that is the case, you can use it, but you will need to modify the model used in this example.
In automatic mode, the robot automatically steers itself and uses its claws to grab obstacles.
1. Open the robot Roving Explorer model.
2. If your robot has a color sensor, replace the Light Sensor block in the model with the Color Sensor block from the LEGO MINDSTORMS NXT library. Set the LEGO MINDSTORMS NXT input port to 3, Sensor type to Light, Output mode to Normalized and Sample time to 1.
3. In the model, click the Deploy To Hardware button on the toolbar.
4. The robot performs its functions autonomously. On LEGO MINDSTORMS NXT Intelligent Brick, press the gray rectangle button to turn the power off.
If there is Bluetooth connection between your computer and LEGO MINDSTORMS NXT hardware, you can operate the robot in manual mode. In this mode, you control the robot by changing the Speed, Turn Angle and Claw Control inputs to the Controller.
1. On LEGO MINDSTORMS NXT Intelligent Brick, press the orange button to turn the power on.
2. In the model, click the Switch block to change to mode of operation to Manual.
3. In the model, change the Simulation mode on the toolbar to External.
4. In the model, click the Run button on the toolbar.
5. Double-click the blocks connected to the Speed, Turn Angle and Claw Control inputs. Then, update the Constant value parameter on the Main tab. To see acceptable range of values, look at the Output minimum and Output maximum parameters on the Signal Attributes tab.
The model is running on the robot. The Simulink model and the robot are communicating using External mode over Bluetooth connection. Observe how the model states change in the Simulink scopes while the robot interacts with the environment. Stop the robot by pressing the Stop button on the model.
Change the settings of the existing or add new LEGO MINDSTORMS NXT blocks. For example:
Change the text displayed on the LCD that monitors the Ultrasonic Sensor output
Change the volume of the sound emitted by the robot when it encounters an obstacle
Add an LCD block to monitor the claw action.
This example showed a Simulink model that controls a simple robot. As part of that, the example showed how complex robot functions can be implemented in Simulink. The functions and parameters of several blocks from LEGO MINDSTORMS NXT library were described. The example also showed how to monitor and control the robot remotely using External mode.