image thumbnail
from Simulink Support Package for Pandaboard hardware (R2012b) by MathWorks Simulink Team
Simulink block library for creating standalone applications for the Pandaboard

Getting Started with PandaBoard™ Hardware
pandaboard_gettingstarted.mdl

Getting Started with PandaBoard™ Hardware

This example shows you how to use Target for Use with PandaBoard Hardware to run a Simulink® model on PandaBoard hardware.

Contents

Introduction

Target for Use with PandaBoard Hardware enables you to create and run Simulink models on PandaBoard hardware. The target includes a library of Simulink blocks for configuring and accessing PandaBoard hardware's I/O peripherals and communication interfaces. Additionally, the target enables you to monitor and tune algorithms running on PandaBoard 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 PandaBoard hardware, and how to tune and monitor the algorithm in real time as it is executing. When you are developing algorithms, it is often necessary to determine appropriate values of critical algorithm parameters in iterative fashion. For example, an algorithm that detects hand clapping may use a threshold to determine hand clapping in the presence of ambient noise. If the threshold value is set too low, the algorithm may confuse any sound for hand clapping. If the threshold value is set too high, the algorithm may not be able to detect any sound at all. In such cases, the right threshold value may be obtained by trying different values until the desired algorithm performance is reached. This iterative process is called parameter tuning.

Simulink’s External mode feature enables you to accelerate the process of parameter tuning by letting you change certain parameter values while the model is running on target hardware, without stopping the model. When you change parameter values from within Simulink, the modified parameter values are communicated to the target hardware immediately. The effects of the parameters tuning activity may be monitored by viewing algorithm signals on scopes or displays in Simulink.

This example introduces the Simulink External mode feature by showing you how to:

  • Configure communications between Simulink and PandaBoard hardware
  • Tune parameters of an algorithm from the same Simulink model that is running on the PandaBoard hardware
  • Use Simulink scopes to monitor results from an algorithm running on PandaBoard hardware

Prerequisites

If you are new to Simulink, we recommend completing Interactive Simulink Tutorial, reading the Getting Started section of the Simulink documentation and running Simulink Getting Started example.

Required Hardware

To run this example you will need the following hardware:

  • PandaBoard or PandaBoard ES hardware
  • Speakers or headphones connected to the HEADPHONE port of the PandaBoard hardware to hear spoken IP address (for IP address verification)

Task 1 - Create a Model

In this task, you will create a simple model that will run on your PandaBoard hardware.

1. In MATLAB®, select File > New > Model.

2. Enter simulink at the MATLAB command line to open the Simulink Library Browser.

3. Click on Simulink > Sources tab in the Simulink Library Browser. Drag and drop a Sine Wave block to the model. Double-click on the Sine Wave block to set parameters of the block as shown in the picture below. Click OK to save and close the block mask.

4. Click on Simulink > Math Operations tab in the Simulink Library Browser. Drag and drop a Slider Gain block to the model. Connect the output port of the Sine Wave block to the input port of the Slider Gain block.

5. Click on Simulink > Sinks tab on the Simulink Library Browser. Drag and drop a Scope block to the model. Connect the output port of the Slider Gain block to the input port of the Scope block.

6. Save your model.

Task 2 - Configure the Model to Run on PandaBoard Hardware

In this task, you will configure your model to run on PandaBoard hardware.

1. If your PandaBoard hardware is not connected to an Ethernet network, follow the instructions in Configure IP Settings on the PandaBoard Hardware.

2. In your model, Select Tools > Run on Target Hardware > Prepare to Run.

3. Review the parameters on the page that opens. If you performed a Firmware Update, Board information will be automatically populated with the IP address, user name and password of your PandaBoard hardware. Press and release the USER button on the PandaBoard hardware to hear the PandaBoard hardware speak its IP address. Verify that the spoken IP address matches the IP address displayed on the Board information pane. If not, set the Host name parameter in the Board information pane to the spoken IP address.

4. Check on the Enable External mode option. An edit box called the TCP/IP port becomes visible. The default value of TCP/IP port is 17725. Simulink uses this TCP/IP port to communicate with PandaBoard hardware. Leave the TCP/IP port parameter to its default value.

5. Click OK.

6. Set simulation stop time to 'inf' to run the simulation until you explicitly pause or stop the model.

7. Save your model. A pre-configured model is included for your convenience.

Task 3 - Run the Model on PandaBoard Hardware

In this task, you will run your model on PandaBoard hardware in External mode. When you are prototyping and developing an algorithm, it is useful to monitor and tune the algorithm while it runs on hardware. The External mode feature in Simulink enables this capability.

1. In your Simulink model, select Tools > Run on Target Hardware > Run to run the model on PandaBoard hardware. A system command window will open that shows the messages coming from the model running on PandaBoard hardware:

Note that pressing the Run button on the Simulink model starts simulation on the host computer. It does not run the model on the PandaBoard hardware. To run the model on the PandaBoard hardware, you must use Tools > Run on Target Hardware > Run.

2. Open the Scope block. Observe the scope displaying a sine wave.

3. Double-click the Slider Gain block. Change the Slider Gain value and observe that the amplitude of the waveform on the Scope block changes appropriately in response.

4. When you are done changing model parameters, press the Stop button on the model. Observe that system command window opened in the previous step indicates that the model has been stopped. At this point, you may close the system command window.

Summary

This example introduced the workflow for creating an algorithm in a Simulink model, and then running the model on PandaBoard hardware. Using External mode, you tuned an algorithm parameter while the model was running and observed the effects of parameter value changes.

Contact us