Documente Academic
Documente Profesional
Documente Cultură
General Description
Overview
o Simulink Support Package for Android Devices enables the usage of Simulink to
create standalone Android applications from Simulink models.
Key Features
Provides a library of Simulink blocks for accessing the device's sensors, capturing and
playing audio and video, creating UI widgets and communicating with other devices
through a network interface.
Monitor and fine-tune the application using the sensors of your smartphone or tablet.
User workflow
o Configure the Simulink model for Android device (Configuration parameters ->
Hardware implementation -> Hardware board -> Android device)
o Deploy the model to the device (Build, load and run the 'apk' file in the Android
device)
This example will get you started with using Simulink Support Package for creating standalone
Android applications from Simulink models.
Configure the Android device, install a required app, and set up communications between your
host computer and the Android device.
1. If you clicked Setup Later at the end of the Add-On Manager installation process, you
can restart hardware setup process.
1. On the Enable on-device Developer options screen, complete the instructions on your
Android device.
After completing the instructions, a new Developer options tab appears in the settings of
your Android device.
2. On the Enable USB debugging screen, complete the instructions on your Android
device.
3. (Windows) On the Install USB driver for your Android device screen, select
your Device Family. Complete the driver installation instructions for your Android device
family.
4. On the Connect and select your Android device screen, connect your Android device to
the MATLAB host computer using your USB cable.
5. Select your Android device from the Device list.
6. On the Prepare your Android device for verification screen, the verification process
requires that:
o Your device is connected to the same WiFi network as your host computer.
o Your device screen is unlocked. Keep your device screen unlocked throughout the
verification process.
The verification process will install and run a test app on your Android device. The test app
creates an XML file containing your device hardware specifications. To view the location of
this file, enter the following code in the MATLAB command window:
>> fullfile(prefdir,'MWAndroidDeviceInfo')
1. Connect the Android device to your host computer using a USB cable.
2. Connect the Android device to the same WiFi network used by your host computer.
3. Create a new Simulink model or open an existing model.
4. In the Simulink Editor, select Simulation > Model Configuration Parameters
This creates an app with the same name as the model. Simulink software then uses the USB
cable to load and run the model on the Android device.
You can see the deployment status in the lower left corner of the model.
When you redeploy the model to the Android device, it stops and replaces the previous instance
of the model.
Step 3 & 4: Create Simulink model and deploy to Android device
Example 1: Filtering Sensor Data
1. Type the following command in your MATLAB Command prompt to open the Filtering
Sensor Data example model:
>> androidSensorFilterExample
2. Complete Step 2 to deploy the model to the Android device which can be used as a stand-
alone App.
3. You can also run the model in External mode by setting the Simulation mode on the toolbar
to External and the Stop time to inf. (Running the model in External mode allows you to tune
any parameters in the model and see the corresponding changes in real time).
4. In the model, click the Run button on the toolbar to run the model on your Android device.
5. Once the model finishes running, double click After running the model... to plot the data.
You can change the Accelerometer in the model to a Gyroscope and repeat the same exercise.
Also try rotating the membrane about all three axes.
1.Type the following command in your MATLAB Command prompt to open the Color
Detection with Camera example model:
>> androidColorDetectionCamera
2. Load and display a sample color image into the MATLAB workspace by executing the following
command in the MATLAB command window:
RGB_image = imread('imagename.png');
imshow(RGB_image)
3. In the model, double click on the Reference Color block to open the block mask.
4. In the block mask, set the Constant value field to the vector [ 58, 68, 117 ] to detect the color purple in
the image. The vector value represents the red, green, and blue components of the color for detection
(e.g. [R, G, B] ).
5. In the model, click the Run button on the toolbar to run the simulation. When the simulation completes,
you can see the resulting image where the originally purple regions are now white.
6. (Optionally) You can modify the value of the Reference Color block and run the simulation again to
isolate different color regions from the image.
7. Perform Step 2 above to deploy the model to the Android device so that it can be used as a standalone
App.
9. You can also try changing the detection algorithm by modifying the threshold values used in the Color
Detection subsystem.
2. Open the Simulink model Getting Started with Samsung GALAXY Android Devices by
typing the following command in the MATLAB Command prompt:
>> androidGettingStartedExample
3. Press the Build Model button to build and deploy the Simulink model to your
Android device.
4. The Android Studio IDE requires the same tools that Simulink used to build the project.
Execute the following function at the MATLAB command line to get the tool paths:
>> getAndroidSLSupportPkgToolPaths
ans =
AndroidSDKLocation: 'F:\share\apps\RTT\Android\v003\win64\android-sdk-24.3.4'
JDKLocation: 'F:\share\apps\RTT\Android\v003\win64\jdk1.7.0_79'
AndroidNDKLocation: 'F:\share\apps\RTT\Android\v003\win64\android-ndk-r12'
GradleHome: 'F:\share\apps\RTT\Android\v003\gradle-2.4'
OpenCVLocation: 'F:\share\apps\RTT\Android\v003\opencv-android-sdk'
5. Open Android Studio and select Import project (Eclipse ADT, Gradle, etc).
Note: The first time you open Android Studio, you must select a UI Theme.
6. Select the second-level project folder with the same name as the project. For example, in
the androidGettingStatedExample_ert_rtw project, select
theandroidGettingStartedExample_ert_rtw\androidGettingStartedExample folder.
7. Click OK to open and import your project into the Android Studio IDE.
8. In the Android Studio IDE window, select File > Project Structure.
9. In the Project Structure window, select SDK Location from the left pane. Then set
the Android SDK location and JDK location fields to the values returned by
getAndroidSLSupportPkgToolPaths. Click OK.
10. On Windows, in the Android Studio IDE, select File > Settings.
On Mac, in the Android Studio IDE, select Android Studio > Preferences.
11. In the Settings (Windows) or Preferences (Mac) window, select Build, Execution,
Deployment > Build Tools > Gradle.
12. Select Use local gradle distribution and set Gradle home to the Gradle path returned
by getAndroidSLSupportPkgToolPaths previously. Then click OK.
13. In the Android Studio IDE, select Build > Clean Project to clear the original project and
path settings.
14. After the project clean completes, select Gradle tab on the right side to expand
the Gradle projects pane.
Note: If you cannot see any files or folders in the Gradle projects pane, click the Refresh button .
15. In the Gradle projects pane, double-
click androidGettingStartedExample > androidGettingStartedExample
(root) > Tasks > build > assembleDebug to build the Android application package (APK).
16. In the Android Studio IDE, from the Run/Debug configuration list in the tool bar,
select androidGettingStartedExample.
17. Click the Run button to open the Choose Device window.
18. In the Choose Device window, select your connected device. Click OK to deploy and run
the app on the selected device.