MATLAB Examples

# Control LEGO MINDSTORMS EV3 Robot Using Apple iOS Device

This example shows how to use the Accelerometer sensor data of an Apple iOS device to control the motion of a LEGO® MINDSTORMS® EV3 robot.

## Introduction

Apple iOS devices provide wireless connectivity and a graphical user interface. LEGO MINDSTORMS EV3 is a programmable robotics construction set. The EV3 Brick is a programmable intelligent Brick that acts as the brain of your robot, controls motors and sensors, and also provides wireless communication through Wi-Fi and Bluetooth. In this example, you learn how to control EV3 robot using an Apple iOS device by connecting them wirelessly.

This example provides two Simulink models

• iOS model In this model, you read the Accelerometer sensor data of an Apple iOS device and use the acceleration data to determine the motor speeds for an EV3 robot. A network connection is set up between the Apple iOS device and the EV3 robot for data exchange.If the distance information received from the EV3 is less than 10 cm, the Apple iOS device beeps.
• LEGO MINDSTORMS EV3 model In this model, the left and right motor speed received from the Apple iOS device are used to drive the motors of the EV3 robot. Distance of the obstacle present in front of EV3 robot, measured by ultrasonic sensor is sent to the Apple iOS device.

With these models, you will:

• Set up a network connection between an Apple iOS device and an EV3 robot
• Configure and run a Simulink model for the Apple iOS device to send and receive TCP/IP packets to the EV3 robot.
• Configure and run a Simulink model for the EV3 robot to receive and send TCP/IP packets from the Apple iOS device.

## Required Hardware

• iPhone, iPod or iPad
• EV3 Brick
• Two EV3 Large Motors
• EV3 Ultrasonic sensor
• EV3 Wi-Fi Dongle

## Working Principle of Robot Motion Control

The acceleration data of the Apple iOS device is used to control the motion of the robot.

From the Accelerometer data, you can mathematically determine the value of pitch and roll for a given position of the Apple iOS device. Then you can map the pitch and roll movement of the Apple iOS device to the motion of the EV3 robot. The pitch represents the forward and reverse motion of the motor. The roll represents the sideways motion of the robot.

In the provided Android model, a MATLAB Function block models the mathematical equations required to convert the pitch and roll values to the linear speed of the motors.

A communication link for data exchange is set up between the Apple iOS device and the EV3 brick. The linear motor speed derived from the pitch and roll values is sent over TCP/IP from the Apple iOS device to the EV3. The EV3 receives this data and uses it as input to drive the two motors.

## Task 1 - Set Up LEGO MINDSTORMS EV3 Robot

1. Build a two-wheeled robot. You can build a robot similar to the one described in the printed building instructions in the education core set or as shown here.

2. Connect the ultrasonic sensor to port 1 of the EV3 brick. Place the sensor in front of the robot as shown in the image.

## Task 2 - Configure and Run models on the Apple iOS device and the LEGO MINDSTORMS EV3 robot

1. Open the iOS model.

2. Double-click on the TCP/IP Send block and change the Remote address to the IP Address of the EV3.

3. Open the LEGO MINDSTORMS EV3 model.

4. Double-click on the TCP/IP Send block and change the Remote address to the IP address of the Apple iOS device.

5. In the iOS model, click Deploy to Hardware to run this model on your Apple iOS device.

6. In the EV3 model, click Deploy to Hardware to run this model on your EV3 hardware.

7. Control the EV3 robot using the Apple iOS device.

## Summary

This example showed you how to wirelessly control the movement of an EV3 robot by using an Apple iOS device.