This example shows you how to use the Simulink Support Package for LEGO MINDSTORMS Hardware to run a Simulink model on a LEGO MINDSTORMS hardware.
The Simulink Support Package for LEGO MINDSTORMS Hardware enables you to create and run Simulink models on LEGO MINDSTORMS hardware. The target includes a library of Simulink blocks for configuring and accessing LEGO MINDSTORMS sensors, actuators, and communication interfaces. Additionally, the target enables you to monitor and tune algorithms running on LEGO MINDSTORMS hardware from the same Simulink models from which you developed the algorithms.
In this example, you will learn how to create and run a simple Simulink model on LEGO MINDSTORMS hardware. See other examples for LEGO MINDSTORMS hardware to learn how to use External mode and to learn how to implement more complex algorithms.
If you are new to Simulink, we recommend completing the Interactive Simulink Tutorial, reading the Getting Started section of the Simulink documentation, and running the Simulink Getting Started example.
To run this example, you will need the following hardware:
- LEGO MINDSTORMS Intelligent Brick
- USB cable
The Simulink Support Package for LEGO MINDSTORMS Hardware provides an easy way to create algorithms that use LEGO MINDSTORMS sensors and actuators by using blocks that can be added to your Simulink model. The blocks are used to configure the associated sensors and actuators, as well as to read and write data to them.
1. Enter ‘simulink’ at the MATLAB prompt. This opens the Simulink Library Browser.
2. In the Simulink Library Browser, navigate to Simulink Support Package for LEGO MINDSTORMS Hardware.
3. Double-click the Button and LCD block. Review each block mask, which contains a description of the block and parameters for configuring the associated LEGO MINDSTORMS sensor and actuator.
In this task, you will create a simple Simulink model that detects the state of the orange button on the LEGO MINDSTORMS Intelligent Brick and displays it on the LEGO MINDSTORMS Intelligent Brick LCD.
1. In MATLAB, select HOME > New > Simulink Model.
2. Drag the Button and LCD blocks to the model. Use the default settings for both blocks.
3. Connect the Button block to the LCD block.
4. Save your model.
In this task, you will configure and run your model on the LEGO MINDSTORMS hardware.
1. Connect the LEGO MINDSTORMS board to your computer with a USB cable.
2. Connect LEGO MINDSTORMS Intelligent Brick to your computer with a USB cable.
3. Press the orange button on LEGO MINDSTORMS Intelligent Brick. The LEGO MINDSTORMS Intelligent Brick LCD shows the startup screen.
4. In your Simulink model, click the Deploy To Hardware button on the toolbar.
5. When the Configuration Parameters page opens up, set the Target hardware parameter to LEGO MINDSTORMS . Do not change any other settings.
6. Click OK.
7. The model will now be deployed to the LEGO MINDSTORMS hardware.
8. Look at the LEGO MINDSTORMS Intelligent Brick LCD while you press the orange button. The LCD displays the state of the orange button, 0 for not pressed, 1 for pressed.
9. Save your model.
Experiment with other LEGO MINDSTORMS blocks. For example:
- Create and run a model that shows the level of the sound detected by LEGO MINDSTORMS Sound Sensor.
- Create and run a model that shows the intensity of the light detected by LEGO MINDSTORMS Light Sensor.
This example introduced the workflow for creating an algorithm in a Simulink model, and then running it on LEGO MINDSTORMS hardware. In this example, you learned that:
- The Simulink Support Package for LEGO MINDSTORMS Hardware provides blocks for configuring, reading, and writing to LEGO MINDSTORMS sensors and actuators.
- You can use the Deploy To Hardware button to configure and run the model on LEGO MINDSTORMS NXT hardware.