Communicating with BeagleBone Blue Hardware

This example shows you how to tune the parameters and monitor the signals of a model running on BeagleBone Blue™ hardware.

Copyright(C) 2017 The MathWorks, Inc.

Introduction

The Simulink Coder® Support Package for BeagleBone Blue Hardware enables you to tune model parameters and evaluate the effects of different parameter values in the model while it is running on the hardware. This process is called parameter tuning.

External mode accelerates parameter tuning. You do not have to generate code, build, and run the model each time you change the value of a parameter. When you change parameter values from Simulink®, the modified parameter values are communicated to the hardware immediately.

In this example, a surveillance model is used to understand the External mode feature. Using the External mode feature, we will find an optimal threshold value to detect the presence of an intruder in ambient noise. % If the threshold value is set too low, the model may erroneously interpret any movement as an intruder. If the threshold value is set too high, the model may not be able to detect any movement.

Surveillance Model

The surveillance model measures motion energy in a room to determine the presence of an intruder in a room to distinguish the movement of an intruder from ambient noise.

In the model, the Pulse Generator block outputs the motion energy in a room every 0.1 seconds. The threshold value is set to 5. If the motion energy is higher than the threshold value at the given sample time, an intruder might be in the room. The green LED on the hardware turns on. If the motion energy at the given sample time is lower than the threshold value, the green LED on the hardware turns off.

Prerequisites

Before you start with example, we recommend you complete the Getting Started with Simulink Coder Support Package for BeagleBone Blue Hardware example.

Required Hardware

To run this example you need a BeagleBone Blue board and a micro USB cable.

Task 1: Configure the Model

1. Open the Communicating with BeagleBone Blue Hardware model.

2. To configure the model, click the Model Configuration Parameters button on the Simulink toolbar.

3. In the Configuration Parameters dialog box, select Hardware Implementation.

4. Set the Hardware board parameter to BeagleBone Blue and click OK.

Task 2: Run the Model on Computer in Normal Mode

1. To run the model, change the Simulation mode to Normal on the model toolbar.

2. Click Run. The model starts running on your computer.

3. To view the simulation output, double-click the Scope block.

1 indicates the possible presence of an intruder at the given sample time. 0 indicates no intruder at the given sample time.

4. To stop the model, click Stop on the toolbar.

Task 3: Run the Model on Hardware in External Mode

1. To run the model in External mode, change the Simulation mode to External on the toolbar.

2. Click Run. The hardware starts running on the BeagleBone Blue hardware. The hardware communicates with the model in External mode using TCP/IP.

The green LED on the hardware glows at almost every sample time. This indicates that the threshold is set too low. The model misinterprets even a minor motion energy change as an intrusion. A more optimal threshold value is needed to detect an intruder.

3. Double-click the Threshold block in the model, and increase the value specified in the Block Parameters dialog box.

4. Click OK.

The threshold value specified in the model is communicated immediately to the model running on the hardware.

6. The glowing pattern of the LED on the hardware changes. In a correctly tuned model, the LED lights up at multiples of 10 and 11.5 seconds. If the LED is glowing more often than at these intervals, increase the threshold value again. Repeat this step until the LED glows at only at multiples of 10 and 11.5 seconds.

5. To stop the model running on the hardware, click Stop on the toolbar.

Other Things to Try

  • Monitor other signals in the model. For example, add another Scope block to monitor the value of the recorded motion energy.

  • Improve the detection model by filtering out any motion energy change with a duration of less than 0.2 seconds.