This example shows how to tune the parameters and monitor the signals of an algorithm running on an Android device.
Simulink® Support Package for Android™ Devices enables you to monitor and tune algorithms running on Android devices from the same Simulink models, which you use to develop the algorithms.
In this example you will learn how to tune and monitor an 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 an iterative fashion. For example, you may want to adjust the gains of a simple filter that smooths out varying values of a sensor. 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:
Set up communication between Simulink and an Android device.
Use a Simulink model to tune the parameters of an algorithm that is running on the device.
Use Simulink scopes to monitor the state of an algorithm running on the device
When you have completed this example, try the following example:
Working with Android Devices: How to use Simulink blocks from Android Devices block library.
We recommend completing Getting Started with Android™ Devices example
Android device, configured using androidhwsetup
USB cable to connect the device to host computer
In this task, you will ensure that you are able to communicate with your device.
1. Connect your Android device to your host computer.
2. Turn on the device and ensure USB debugging is enabled. If not, run androidhwsetup to setup the device.
1. Open the Communicating with Android Devices model.
2. In your Simulink model, click Simulation > Model Configuration Parameters to open Configuration Parameters dialog.
3. Select the Hardware Implementation pane and select Android Device from the Hardware board parameter list.
4. Click Device options under the Target Hardware Resources section and ensure the listed Device matches your connected device. Click OK.
5. In the model, make sure that the Simulation mode on the toolbar is set to External.
6. In the model, click the Run button on the toolbar.
In this task, you will change value the gains of the filter.
1. Leave the device on a stable surface. Notice the values changing rapidly in the display.
2. Double click Gain1 and change Gain from 1 to 0.0167. Click OK or Apply.
3. Similarly change Gain in Gain2 and Gain3 from 0 to 0.4833.
4. Click OK or Apply.
5. Notice the output changing less rapidly than before.
6. Click Stop button in the Simulink model.
You have interactively found an optimal value for your filters while the algorithm is running on the device.
Replace Accelerometer with Gyroscope and repeat the same exercise to smooth out the output.
Increase the number of filter taps by adding pairs of Unit Delay and Gain.
This example showed a workflow for tuning and monitoring an algorithm running on an Android device.
In this example you learned:
How to set up and establish a network connection between a host computer and an Android device.
How to tune an algorithm parameter on the device using the External mode feature.