Sie sind auf Seite 1von 16

Getting started with Simulink Support Package for Android Devices

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

Create Simulink models, and deploy as an independent application on Android


smartphones and tablets.

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.

Generation of Android Studio compatible projects.

Product and System Requirements

o Available from R2014a onwards.

o Supported in 64-bit Windows, 32-bit Windows (till R2015b) and Mac.

o Linux : supported only on R2014a

o Supported Android devices :

R2014a : Samsung GALAXY S4 and Tab 2 10.1 devices.

R2016a : All Samsung GALAXY Android devices.

R2016b : All Samsung GALAXY and Google Nexus devices.

How to install and Get Started


o On the MATLAB Home tab, in the Environment section, click Add-Ons > Get
Hardware Support Packages.
o In the Add-On Manager window, find and click the support package, and then
click Install.
o Follow the on screen instructions and complete the installation.

User workflow

o Configure the Android device for deployment (using 'targetupdater' command).


Upon success, a sample test application will be built and deployed to the Android
device and will start running.

o Configure the Simulink model for Android device (Configuration parameters ->
Hardware implementation -> Hardware board -> Android device)

o Create the Simulink model.

o Deploy the model to the device (Build, load and run the 'apk' file in the Android
device)

o Advanced users : Export code to Android Studio and perform further


enhancements to the application.

How to create Android Applications from Simulink models :

This example will get you started with using Simulink Support Package for creating standalone
Android applications from Simulink models.

Step 1: Configuring the Android device for deployment

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.

On the MATLAB Home tab, in the Environment section, click Add-


Ons > Manage Add-Ons. When the Add-On Manager opens, click Setup

Enter targetupdater in the MATLAB Command Window.


2. On the Support Package Installer screen, next to Support package for, select Android
(Simulink).

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')

Click Verify to start the process.


On the Verifying configuration of your Android device screen, the dialog box
shows a green check mark next to each successfully completed task in the verification
process. Click Next to complete the installation process.
Click Finish.
If you leave Show support package examples selected on the Support package setup
complete screen, the installer opens the example page for Android devices.

Step 2: Configuring the Simulink model for Android device

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

5. In the Configuration Parameter dialog box, click Hardware Implementation.


Set Hardware board to Android Device. Then, click OK.
6. Click Deploy to Hardware.

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.

Example 2: Color Detection

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.

Step 5: Export code to Android Studio

1. Download and install Google Android Studio IDE.


As part of the Google Android Studio installation process, you can optionally choose to
install the following components:
Android SDK
Android SDK Platform
Android Virtual Device
Performance
These components provide extra functionality within the Android Studio IDE but are not
required to build projects created with the Simulink Support Package for Android Devices.

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.

Das könnte Ihnen auch gefallen