MATLAB Examples

Communicating with Apple iOS Devices

This example shows how to tune the parameters and monitor the signals of an algorithm running on an iOS device like iPhone, iPad or iPod.

Contents

Introduction

Simulink® Support Package for Apple iOS devices enables you to monitor and tune algorithms running on Apple iOS devices like iPhone, iPod and iPad. from the same Simulink models from which you developed the algorithms.

In this example you will learn how to tune and monitor the 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 a Apple iOS 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 Apple iOS Block Library: How to use Simulink blocks from Apple iOS library.

Prerequisites

We recommend completing Getting Started with Apple iOS Devices example.

Required Hardware

  • iPhone, iPod or iPad
  • USB cable to connect the device to your host computer

Task 1 - Setting up the device

In this task, you will ensure that you are able to communicate with your device.

1. Connect your Apple iOS device to your host computer.

2. Turn on the device and ensure that the device is provisioned. If not, run targetupdater to provision the device.

Task 2 - Run the Model in External Mode

1. Open the Communicating with Apple iOS 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 Apple iOS Device from the Hardware board parameter list.

4. Click Device options and ensure that the Device matches your device setting. 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.

Task 3 - Communicate with the Device

In this task, you will change value of the gains of the filters.

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.

Other Things to Try

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.

Summary

This example showed a workflow for tuning and monitoring an algorithm running on Apple iOS device. In this example you learned:

  • How to set up and establish a network connection between a computer and Apple iOS device.
  • How to tune an algorithm parameter on the device using the External mode feature.