Arduino Driverless Rover
A side view of the vehicle
The rover avoiding a rock and a few plants
The rover avoiding an Adirondack chair
The rover stops to let another, human controlled rover pass during a Vehicle to Vehicle Communication demo
A top view, showing the ultrasonic sensors, GPS, Pulse Width Modulation driver, and Arduino 101
The ultrasonic sensors are the heart of collision avoidance mode
A complete top down view
The Vehicle to Vehicle Communication demo, this time carried out in the grass
The rover avoids a wall
Another complete top down view
The rover avoids the small lip of a porch
The back of the rover, showing the rear motor and Electronic Speed Control
Another image of the rover stopping during a Vehicle to Vehicle Communication demo
A close-up of the vehicle's brain, the Arduino 101 (with a protective case around it)
The two boards in the center of this photo are the GPS (top) and the Pulse Width Modulation Driver (bottom)
Wiring Diagram is a labeled picture
Many kinds of everyday automation exist in the world of today. Home control systems allow you to control lights in your house over the internet, coffee makers start before you wake up, and you can release a small robot to vacuum your floor.
While not everyone may have the need for a robotic vacuum, or want to control their house over the internet, it is extremely difficult if not impossible to find someone in the developed world who will be left unaffected by self driving vehicles. You won’t even have to own one to have your life revolutionized by them. Public transportation will become driverless, traffic flows will become seamless, and people will even release their cars out into their local area to work as taxis for them!
These vehicles will need to use collision avoidance systems, still being perfected today, to stay out of the way of obstacles such as people, signs, the side of the road, and other vehicles. This kind of system is adequate in today’s world, full of traffic lights and conscious drivers, but another technology will need to be proven before humans get off the road. This technology is vehicle to vehicle communication. Without this, driverless cars will be restricted to relying on local sensors, and the traffic jams of today will only become worse. Using vehicle to vehicle communication, not only can cars practice actions such as synchronized acceleration and deceleration, alleviating these jams, but can talk to each other ahead of an intersection to avoid a collision. The latter was the focus of this project.
My project used an Arduino 101, along with some electronic sensors, to convert an old remote-control car into an intelligent, driverless vehicle that can communicate with other vehicles in order to avoid an imminent collision, along with being able to avoid simple obstacles.
What it does
The vehicle has two main functions:
Continuous Collision Avoidance Mode
In this mode, I simply send the vehicle an “On” signal through bluetooth, and it turns on the rear motor. I can then step back and watch it avoid trees, houses, chairs people, and just about anything else it encounters in its path. The vehicle can successfully navigate an obstacle course on its own.
Demo of Driverless Vehicle to Vehicle Communication in an Intersection
This mode exists to show what an intersection between two cars might look like in a future with vehicle to vehicle communication. The scenario goes as follows: Two cars, at least one of them driverless, are approaching an intersection of two roads, one vehicle traveling on each road. When the driverless car receives information indicating the other car is approaching dangerously from the other road, it slows down and/or stops to avoid a collision. In this mode, I can connect the driverless Arduino 101-powered vehicle to another vehicle with an onboard computer. The other vehicle is a simple RC car being controlled by a human being, with an onboard computer running linux that is bluetooth enabled. This mode is tested in the following way: the two vehicles are connected and sent on a possible collision course. The Arduino receives GPS information from the RC vehicle, and determines if the two are headed for a collision. If so, the Arduino vehicle will stop and let the RC vehicle pass by.
How It Works
The vehicle is built upon an old hobbyist remote-control car chassis, and uses the servo motor, motor controller, battery, and rear motor of the vehicle. The Arduino 101 serves as the brain of the vehicle, processing input from different kinds of sensors.
Continuous Collision Avoidance Mode
When powered on, the Arduino becomes visible to bluetooth devices. I wrote an iOS application using Swift and loaded it onto an iPad. The application is simply a switch in the center of the screen that appears upon connecting with the Arduino 101. The switch represents a Bluetooth Low Energy (BLE) characteristic. When the switch is off, it sets the characteristic to 0, and when it is on, it sets the characteristic to 1. 20 times a second, the Arduino does two things. The first thing is check the state of the characteristic. If the characteristic is 0, it shuts off its rear motor and stops checking for collisions. If the characteristic is 1, it turns the rear motor on and starts checking for collisions. The second thing the Arduino does is, as already mentioned, check for collisions. It does this using three ultrasonic sensors placed in the front of the vehicle. One of the sensors is facing directly in front of the vehicle, and the other two are angled to the left and right of the direction the vehicle is facing. If a distance is measured by one of the sensors that is considered dangerous, the Arduino will check the offset sensor readings for a clear path, and turn in the direction that gives it the most space.
Demo of Driverless Vehicle to Vehicle Communication in an Intersection
There are two cars involved in this demonstration. The first is the self-driving Arduino 101 powered rover, and the second is a regular, human controlled RC car with a raspberry pi and a GPS on board. The cars are placed away from each other and oriented so that they will both converge on the same point, like an intersection. I then remotely run a python script I wrote on the raspberry pi, which connects with the Arduino through bluetooth, and once connected, writes the vehicle's track angle to the bluetooth characteristic. Once connected, the Arduino starts moving, and the human drives the raspberry pi car into the path of the Arduino. After a delay of a couple seconds, the Arduino car reads its own track angle (the direction it’s moving) from its GPS and the other car’s track angle over bluetooth. The Arduino then decides whether or not the cars could collide. If a collision is possible, the Arduino stops and lets the raspberry pi car pass.
Challenges I ran into
There were so many challenges involved with carrying out this project, and some of the most difficult were not even software related!
In the beginning
I like to divide my projects up into individual tests that demonstrate the different technologies needed to complete the project, and then bring them all together. One of the first tests, reverse engineering the motor controller, proved to be quite challenging. Since the controller was designed to be controlled via a radio receiver, not much documentation exists as to which input produces which output. I had to sit down and write some test programs that looped through different analog outputs and tested different PWM pulse lengths in order to find which ones caused the motor to run at different speeds or spin in different directions.
Simple electronics can sometimes be not so simple
Probably the most significant problem that took up entire days of work on this project was caused by the power supply. Initially, I discovered that the controller had a 5 volt output pin, supplied by the motor battery, and attempted to use this to power the vehicle components. However, I soon found out that with many sensors, a GPS, an Arduino, and a servo motor, the output was simply not powerful enough, and this caused a lot of weird behavior. After hours of fiddling with the hardware, I ended up using a USB power bank to power the Arduino, and using the motor controller output to power the rest of the vehicle. Since a lot of the power was used in outputting signals from the Arduino, this solution worked very nicely.
I used two Adafruit Ultimate GPS Breakout Boards for this project, and would recommend them to anyone else in a heartbeat. However, unfortunately, I found that my Arduino 101 hardware serial did not work with them, and I ended up having to write my own GPS library including an NMEA sentence parser in order to work with them. I was able to get them to work using SoftwareSerial, and I plan to upload my library and solution to GitHub in order to help out anyone else who may come across the same dilemma.
Creating a Reliable Obstacle Avoidance System
I started out just giving the rover the ability to dodge small obstacles in its path. Now, with my most updated code, the rover almost looks alive when weaving through an obstacle course.
Demonstrating Vehicle to Vehicle Communication
The Arduino 101 powered rover successfully stops on analysis of data transmitted from another moving vehicle near it.
I also found out some useful things about vehicle to vehicle communication. The intersection demonstration uses the track angles of the rovers to determine if they will collide. In a real world application, a more advanced system would need to be deployed, as explained below, since a system only using the two track angles has the potential to calculate false positives. Through tests of more advanced systems that used more measurements from the GPS and more sophisticated ways to calculate a potential collision, I learned a lot about this technology.
1) Bluetooth does not have the range to support this communication in full. Bluetooth also takes time to connect, and does not reliably stay connected between two moving vehicles even if they are in range.
2) A more accurate method of location must be used in order to implement full collision detection in an intersection using more than just track angles. Either a much more accurate GPS is required, or more likely, an assisted GPS system possibly using cell towers.
Why this is so:
If the Raspberry Pi supported a larger bluetooth range, the vehicles could have been started at a greater distance from each other, and more information could have been collected up to the intersection, allowing for a more accurate collision avoidance calculation. I attempted demonstrations where the vehicles start out of bluetooth range, building up a history of data as they move, and connect once in range, but the bluetooth technology on board the Raspberry Pi had lots of trouble connecting the two vehicles while they were moving. I wrote an Arduino sketch that read both vehicles' latitude, longitude, speed, and track angle, and used their position history to plot their paths as lines on an Equirectangular Grid Model of the Earth. The Arduino then found the intersect of the lines, and used the two vehicles' velocities to determine if they would be at the intersection at the same time. This demonstration worked using test values, but the aforementioned limitations of the GPS and Bluetooth hardware led to inaccurate and untimely readings. In order to be utilized in a real intersection between two cars, these calculations would need to be supplied with data from an assisted GPS and a larger Bluetooth range.
What I learned
I had never touched an Arduino before this project, and I have come to love how easy it is to automate things with one.
Before this project I had worked with Java, Swift, Python, PHP, and SQL, but my past projects did not require any programs written in C++. Since the Arduino compiles C++, I learned a lot about the language, especially when writing the GPS library and NMEA sentence parser.
It was very cool to learn what most GPSs output, and how to interact with the GPS in order to get the information desired.
Bluetooth Low Energy
I had always had a small fascination with bluetooth, and writing code that worked with it was very cool to me. I enjoyed how easy the Arduino 101 BLE API was to use.
PWM (Pulse Width Modulation)
I had used PWM in the past to control servo motors, but this project took me into the details of it. I learned the different between PWM frequency, duty cycle, and pulse length.
What's next for Self Driving Arduino Rover
Starting my first year of college in about a month, there will be many more resources for me to use in developing my projects. This will open up many possibilities to where this could go. I plan to continue developing the rover, adding different sensors to it and giving it new and improved capabilities. In college and beyond, I will use my knowledge of GPS, BLE, micro controllers, and more gained during this project to aid future efforts in making this planet a safer, more efficient, and more exciting place to live.
Continuous Collision Avoidance Mode
- Place the rover in a fairly open area (such as a playground, backyard, gymnasium, etc), with at least 2 meters of space in between the front of the vehicle and the nearest obstacle
- Supply power to the Arduino by plugging in the cable attached to the power supply, and turn on the Electronic Speed Control
- Wait 5-15 seconds
- Open iPad Rover Controller Application
- Wait for on/off switch to appear in center of iPad screen
- Turn switch on to start the back motor of the rover and enable collision avoidance
- The rover should start moving forwards and turning its front wheels left or right when it approaches an object
Vehicle to Vehicle Communication Intersection Demonstration
- Place the driverless Arduino rover and the RC raspberry pi rover about 9 meters apart (try closer if the vehicles are failing to connect, the raspberry pi 3 has a relatively small bluetooth range)
- Orient the two vehicles such that they are pointing towards a common point, from directions around 90 degrees relative to each other
- Plug the raspberry pi and the Arduino, turning the two devices on, and turn on the Electronic Speed Control on the Arduino rover
- Wait until both GPSs indicate a fix (when the blinking red light on the GPS starts blinking much less frequently)
- SSH into the raspberry pi and start the intersection demo python program
- Once the Arduino rover starts moving, using the Remote Control, drive the raspberry pi rover into the path of the Arduino rover, so that they are on a collision path and moving in directions around 90 degrees relative to each other
- Do not stop raspberry pi rover; drive it straight through the intersection
- The Arduino rover should now stop and let the raspberry pi rover pass
Note: for both the sketches, the pulse length that determines the speed of the Arduino rover is defined by a C++ macro. The rover must be set at a lower pulse width (higher speed) to be able to move through the grass, but must be set to higher pulse width (lower speed) in order to achieve the same velocity on pavement (the rover goes way too fast on pavement if set to the grass speed). A pulse width of between 1050 and 1080 work well in the grass, and 1120 works well on level pavement. Pulse widths in between will achieve different speeds as well. A pulse width of 1140 will stop the rover completely.