Documentation

Sensor Application

This example shows you how to use Simulink® Support Package for Android™ Devices to design an algorithm and augment the same with a custom GUI.

Introduction

The raw output of the sensors are very noisy - they change rapidly even when the device is resting on a stable surface. In this example, you will implement a simple low pass filter that will smooth out the output.

The following sections will describe how the low pass filter is specified, run on the device, how the outputs can be analyzed and finally add a custom GUI that uses the output.

Prerequisites

We recommend completing Getting Started with Android Devices and Communicating with Android Devices examples.

Required Products

  • DSP System Toolbox™

Required Hardware

  • Android device, configured using targetupdater

  • USB cable to connect the device to host computer

Task 1 - Filter design

1. Open the Filtering Sensor Data model.

2. In your Simulink model, click Simulation > Model Configuration Parameters to open Configuration Parameters dialog.

3. Select the Hardware Implementation pane and review the parameters on the page that opens.

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 and the Stop time is set to 40.

6. In the model, click the Run button on the toolbar to run the model on your Android device.

7. Once the model finishes running, double click After running the model... to plot the data.

Task 2 - Use OpenGL for Custom GUI

1. Open the Sensor application model.

2. This model uses the same filter to smooth out the Accelerometer data and send the filtered data to app using To App block.

3. Double click To App block and observe the function name specified: FilteredData. This is the function that will be called with vector as input.

4. In your Simulink model, click Simulation > Model Configuration Parameters to open Configuration Parameters dialog.

5. Select the Hardware Implementation pane and review the parameters on the page that opens.

6. Click the Deploy to Hardware button on the toolbar. The model will now be deployed to your Android device.

7. Now you can update the app with a custom GUI by double clicking Double click this block.... This will add a base class that implements a rotating membrane. The amount of rotation will depend on the acceleration along the X-Axis.

8. Open androidSensorExample.java under src directory and observe that FilteredData method is implemented by this class. This method passes its input to an OpenGL renderer.

Other Things to Try

Replace Accelerometer with Gyroscope and repeat the same exercise. Also try rotating the membrane about all three axis.

Summary

This example showed you how to use Simulink Support Package for Android Devices to design an algorithm and augment the same with a custom GUI.

Was this topic helpful?