Introduction

This project is an extension of the mobile rover project in the Arduino Engineering Kit. I added the following features to change how one can control the rover –

  • Instead of programmatically specifying a set of waypoints for the rover to travel, I control it using my android phone.
    • The inspiration for this project came from remote controlled cars, hence the design – tilt phone forward and backward to control the drive and tilt the phone sideways to control the steering.
  • Instead of controlling rotation angle or distance moved, I implemented separate PID Controller on each wheel to get the desired angular velocity.

Here is a video of the final project in action.

 

Simulink to program Arduino and Android

Simulink is a block diagram-based environment for modeling and simulating dynamic systems. You can develop algorithms here that can be embedded directly onto Arduino and other hardware devices including Android phones. When deployed to the phone, Simulink builds an Android app on your phone, which can be used to a) access different sensors and b) visualize them on your phone.

There are two Simulink models associated with this project: an Arduino model and an Android model. The Arduino model is deployed to the rover, while the phone model is deployed to the Android device.  Both models contain TCP/IP send and receive communication blocks that allow the devices to talk to each other over Wi-Fi. All we have to do is type the IP address of each device and specify a unique port for the communication to work.

Arduino model

Phone model

Phone App

 

Now let’s dig a little deeper into the models.

 

In the Android model, The DeviceOrientation block outputs the XYZ tilt of the phone. Since, we only need the X and Y values to control the rover; only those two are sent and they are also displayed on the Android app for reference. A slider is used that ranges from 1-4 to control which state the rover is in: disable, drive, turn, or move forklift. Another slider is used to control the forklift angle. Each block is connected to the TCP send and the datatype conversion block is used to make sure the data transfer to the Arduino is seamless.

 

In the Arduino model, TCP receive blocks are used to read the data sent by my phone (as long as they are on the same Wi-Fi network). These blocks, along with encoder speed calculation blocks from the Arduino Engineering Kit Learning materials act as the inputs to the control logic. Before I describe the logic in detail, the outputs of the logic are angular velocity command to each dc motor, and angle command to the servo. These are then fed into the respective motor block.

 

State Logic

The logic consists of 4 states:

  1. disabled - here the wheel velocities are always commanded to be zero
  2. WheelCtrl - here the rover is driven straight using PID control
  3. AngleCtrl - here the rover is turned according to the turn commands from the phone using PID control
  4. forklift - here the forklift can be controlled using the commands from the phone.

As mentioned before, The PID control is different from the Engineering kit models because with good wheel speed control we can achieve better straight-line motion. I set a 15-degree cushion. What this means is that when I turn the phone, it starts moving the rover itself only after reaching this mark so that small changes do not command the rover.

The WheelCtrl and AngleCtrl states read the speed from the TCP receive block in deg/s and sends that as the reference speed for the PID controller to both wheels. Both states use the same PID controller.

The forklift state reads the commanded angle from the slider on the app and commands the servo to that angle.

Future ideas

  1. Implement a feature to turn and drive the rover simultaneously (like a car).
  2. Have the forklift motion be smooth, by adding more resolution to the commanded angle.
  3. Remove the slider that changes rover’s states. This can be done by adding some smarts to the algorithm which will decide automatically which state the rover should be in based on the tilt of the phone.

Note: All these techniques described here can be used to program any Arduino and Android device.

The models can be downloaded here.