Driving a Car with an iPhone - Part 2 Technical Breakdown
What happens when you have a control system Kit of Parts from the FIRST Robotics Competition, a $300 car from Craigslist and some extra time after work? Simple controls allow us to do a little car surfing and unleash the cowboy engineering spirit.
Delta '88 + cRIO + Motors + Potentiometers + iPhone = Awesome
Driving a Car with an iPhone and cRIO (Part 1 - Overview) - Episode 03
The Team
Huge thanks to the engineers that made this project possible:
Doug Farrell
Will Schoettler
Stephen Meserve
Hunter Smith
Anita Bowman
John Boiles
Steve Wolf
Justin Parker
Pat Corcoran
Pat Quinn
Ben Chojnacki
Automobile Control System
The goal of this project is to be able to remotely control an automobile. This involves building an automobile control system (ACS), and a remote system that sends commands to the ACS. These two systems are then connected by a wireless network to complete communication. This allows a controller - such as an iPhone, Power Wheels, computer, etc – to wirelessly command the car to actuate its pedals and steering. Commands from the remote system are sent to the ACS. The ACS processes the values it receives by performing some basic PID calculations and outputs signals to the motors that define where they should move. Each of the pedals and the steering has a dedicated motor and motor controller such that each can be controlled individually.The ACS consists of three main elements: motor control, electronic control, and power distribution.
Motor Control
What we used:
-
3 Brushless DC Motors (power window motors work great)
-
2 Single-Turn 10 kΩ Potentiometers
-
1 10-Turn 10 kΩ Potentiometer
-
3 5 kΩ Resistors
The DC motors must be positioned such that they can actuate the pedals and steering. For the pedal motors, ‘U’ brackets are used to fasten the motors to the floor of the car at the base of each pedal. ¾” wrenches are then attached to the sprockets to provide lever arm to actuate the pedals. Single-turn potentiometers (Z1) are connected to the sprockets as well using nylon tubing such that their resistance changes when the motors turn. A 5 kΩ resistor (Z2) is placed in series with the potentiometer to create a voltage divider. Applying a voltage across both resistors and measuring across the Z2 shows a change in voltage (Vout) when the potentiometer rotates with the motor. This provides position feedback.
Voltage Divider Calculation
Motor Installed for Brake Pedal
Completed Motor Installation
for Gas Pedal
Gear Attached to Steering Shaft
Motor Sprocket and
Potentiometer Connection
The steering is implemented in a similar manner. The motor is mounted such that it is parallel with the steering column. The steering wheel is replaced with a gear that is fastened to its shaft. A motorcycle chain is laid over the gear and the sprocket of the steering motor. This causes the steering shaft to turn when the motor turns, controlling the angle of the wheels. The multiple-turn potentiometer is connected to the motor sprocket similarly to the pedal motors. It is also put in series with a 5 kΩ resistor in a voltage divider configuration.
To control the motors, the PWM output of the motor controllers must be connected to the voltage input of the motors. They are fed digital inputs from the electronic control that defines how much the motors should turn.
Electronic Control
What we used:
-
NI 9403
-
FIRST Digital Side Card (Digital breakout board)
The CompactRIO (cRIO) is an embedded controller that is programmed with LabVIEW. We program the FPGA to gain fast access to its inputs and outputs, and deploy code to its Real-Time OS for quick testing. We use its network communication capabilities to connect to the remote system and receive commands. All processing is done on the cRIO itself, and outputs signals to the motor controllers via the NI 9403 digital output module to set motor position. The NI 9201 analog input module is used to acquire motor position data from the voltage dividers in the ACS.
In summary, the cRIO receives motor position commands from the remote system. It uses these values in conjunction with the current motor position values received from the NI 9201 module to implement a PID algorithm that sends digital outputs to the Jaguar motor controllers via the NI 9403 module. This allows the remote system to command all three motors simultaneously. The FIRST digital side card is connected between the NI 9403 and Jaguars to simplify the digital connections between the two.
cRIO 9074
FIRST Digital Sidecar
Power Distribution
What we used:
-
12 V Battery (Standard Car battery works great)
-
FIRST Fused Power Distribution Board
The cRIO, wireless gaming adapter (found in the Remote System), and Jaguar motor controllers all require power. The FIRST power distribution board provides the voltage conversion from 12 V to 24 V so that the cRIO receives adequate voltage. It also provides all necessary outputs to power the motor controllers and gaming adapter. The fuses on the power distribution board protect the motor controllers and cRIO from any power surges. The power distribution board is powered by the 12 V battery.
FIRST Fused Power Distribution Board
Remote Control System
Remote System (PC)
The remote system consists of a wireless network through which all components of the system are connected. It can be monitored and controlled from a laptop with wireless capability.
What we used:
Wireless G Router
Wireless Gaming Adapter
Laptop with Wireless Card
The wireless G router creates a network that all elements of the system can join. The wireless gaming adapter joins this network and plugs into the cRIO, adding the cRIO to the network. The laptop joins the network as well. This allows the user to wirelessly monitor the cRIO and change all parameters dynamically.
iPhone Communication
iPhone communication consists of UDP packets sent directly from the iPhone to the cRIO via wireless network.
What we used:
iPhone (or iPod Touch)
Remote System
ACS (Automobile Control System)
The iPhone application has 2 sliders. One for controlling the brake, one for the gas. The on-board accelerometer is used to pick up rotation, which is used to control the steering. In order to communicate these values to the cRIO over UDP, they must be incorporated into strings. We do this by defining each iPhone control’s range of motion as values from 0-255. The values are then converted ASCII characters, packaged together, and sent to the cRIO. The cRIO is programmed to take characters 2,3, & 4 to be the values for steering, gas, & brake, respectively. For example, if the cRIO receives a string “c€!t” then it knows to assign a value of €(128) to steering, !(33) to gas, and t(116) to brake. These values are processed on the cRIO as commands to move position. ‘c’ is present so that the cRIO can always find the start of a new data packet.
Communication between cRIO and Laptop
The communication between cRIO is more or less automatic. Once the cRIO has been configured and has a known IP address, a project in LabVIEW can deploy VIs to the FPGA and Real-Time OS automatically.
When sending data between VIs that are running on different targets, Network-Published Shared Variables are used. These are also configured in the LabVIEW project and implement communication automatically.
Communication between iPhone and cRIO
The iPhone communication bypasses the laptop entirely. It sends packets of data in character form directly to the cRIO via UDP communication.
User Datagram Protocol, or UDP, does not guarantee the safe arrival of data to the destination. In addition, data sent in multiple packets may not arrive at the destination in the order they were sent. Because of this, data is sent at rates of ~30 packets/second. Each packet begins with a ‘c’ character to identify the beginning of a new packet to remove corrupted or misinterpreted packets.
John Shows off the iPhone App
Power Wheels System
The Power Wheels commands the automobile by sending steering angle and speed information to the laptop on the remote system, which relays the values to the cRIO on the ACS.
What we used:
Power Wheels
WLS-9215 (cDAQ 9191 + NI 9215)
1 10 kΩ Single-Turn Potentiometer
1 5 kΩ Resistor
1 Encoder (In our case a photo-resistor and striped PVC)
12 V Battery
To monitor the steering angle, the potentiometer and resistor are connected in a voltage divider configuration similar to the one described in the ACS section above. A gear is placed on the rotor of the potentiometer and the steering wheel of the potentiometer with a bike chain connecting the two. In this manner, rotating the steering wheel rotates the potentiometer. An encoder is attached to the side of a wheel such that it turns when the wheel turns. Based on the number of turns per second, speed can be calculated.
The WLS-9215 joins the Remote System’s wireless network. It acquires the voltage signals from the voltage divider and encoder and sends them to the laptop for processing. These processed values are forwarded on to the cRIO via Shared Variables, which direct the motors to their appropriate positions.
NI WLS 9215
Laptop + Power Wheels = WIN!
FAQ
Driving a Car with an iPhone
Where did yall find that car?
We searched for awhile on Craigslist before finding "Wendy". We paid just $300 for a working Delta Olesmobile 88' (actually made in 1990). A nice lady in south Austin sold us this car with no idea what we had planned for it.
Will this app work with any car?
Well to be clear the app only controls the motors we installed in the car. This same set up could work with any car, but it requires some hefty modifications. With a FIRST Kit of Parts and an iPhone and a lot of engineering know how you could make this system work for any car.
Can I download your App from the iTunes App Store?
Unfortunately no, shortly after we released this video Apple added a line to their terms and agreements for the App Store that explicitly forbids apps the operate cars.
Are you using the FIRST (FRC) Kit of Parts?
Heck Yes! We are big fans of FIRST, and we love the hardware included in the kit of parts. For this project we used the digital sidecar, power distribution board, and motor controllers directly from the FRC 2009 KoP. We uses a cRIO 9074, which is a little different from the FRC cRIO, but the same code would work on both systems, we just happen to have a 9074 laying around.