Self driving car

From Advanced Projects Lab
Revision as of 11:35, 2 June 2017 by Aplstudent (talk | contribs)
Jump to: navigation, search

The goal of this project is to create a car that can move on it's own using sensor input. Writing from early 2017 self driving cars are still in development. Nevertheless many, including everyone is this lab, believe that they are the future. For the moment our car is a little RC car that has a $4 electric motor. We are using a pair of Raspberry Pi 3's for the brain of the car and are using varies sensors to act as the eyes, ears, and balance for the car. This wiki will serve as a guide for work that has been completed so far and work that is left.

Getting Started

First: Make sure the power is on. The cable to power the raspberry pi is a microusb. Any usb port should provide power to the pi.

Second: Connect a device to have wireless access to the cluster (we used a laptop). This device will not be part of the cluster but will be able to access cluster resources. All you have to do is "nano /etc/hosts" for every single slave Pi and the master Pi and the connection device (this could be any device with wifi). Every host file needs to have the IP addresses and name of every single computer in the cluster (rpbot0 & rpbot1 for now) and the IP address and name of the connection device. For simplicity, just use the laptop provided. Follow this step when you want to upgrade to a faster device.

Third: Getting into the pi. After a minute of having the power the pi should be sending out a WiFi signal called rpbot_spot get in using the usual password. From there, open up a command prompt and type in ssh rpbot0.

Fourth: For the moment we are storing all our code in the /mirror directory, all future downloads and novel code should be in this directory. The mirror directory is part of the multinode set up on our system. Any changes to one mirror directory should change the mirror directory in the other node.

Completed So Far

Raspberry Pi's (RP): For this project we have two RP's that will connect all our sensors, process their input, and make decisions on where to go, when to stop, when to turn, etc.

Slave-Master: The RP's are setup in a slave/master pair. The master node will connect all our sensors and will run the majority of our code. The slave node will be used to enhance the computing power of the master node. The two are hooked up through a WiFi signal.

WiFi enabled: Currently the RP's are configured to automatically send out a WiFi signal on start up. From this signal we can connect to the RP's from any WiFi enabled device (right now we are using a laptop). Code is located on rpbot0 (/usr/local/bin/WAP2.sh). You will need to understand basic cron and bash code.

RC: Out of the box the RC works by a radio frequency signal from an external controller. We are not planning on using the controller for our car. Instead we plan on feeding in our own voltages from the RPs to tell the car when to move, stop and turn. Using a multimeter and a oscilloscope we measured the various voltages applied to the RC from the logic chip in the housing. The motor is in the back of the car and only has two wires going into the engine. We measured the voltages applied with red on red and black on black. When it is moving forward we measured about 9.4V and for backwards about -8.5V. The front of the car uses a servo motor to turn the front wheels. Measuring the red and black wires we see that turning to the right we get a postive voltage and left is negative. Measuring the white, brown and blue cables we found that when there is no turn signal the voltage is roughly 1.5. When the wheels turn to the right the voltage goes up to about 3V and when it is left it is roughly 0V.

Sonar: Following this tutorial we were able to hook up the sonar system. Important note: Our set up differs from this guide in that ours is plugged into GPIO pin GPIO05 instead of GPIO23 and GPIO12 instead of GPIO24. These pins were set up differently in the code (TRIG = 5 and ECHO = 12) but otherwise everything is identical to the guide. The code we are using is in the /mirror directory, as is all our sensor code.


GPS: The GPS is an Adafruit Ultimate GPS Breakout. Following this guide we were able to get the GPS working in the atrium. We have hooked it up through a USB to TTL cable. We also have the optional antenna for it which helps pick up a signal in about 2 minutes (as opposed to about 15 minutes). The end of the antenna is magnetic which helps if you need to place it up high somewhere that is metal. To access the GPS daemon just type in 'cgps -s' into the command line and that should bring up the GUI and once the GPS has a signal the GUI will update with all the data.

Compass/accelerometer: The details for the device can be found here. We are using some code provided on git_hub which has been installed and runs great. This sensor is very sensitive, it can detect going up and down an elevator, running, turning, and stopping. However, that also means that small vibrations on the sensor are picked up. All of this is to say however the sensor is being used it needs to be firmly mounted as to not pick up more noise than necessary. For the moment the compass isn't really being used, it works well though so if/when we need to use it we will have it.

Circuitry: The Raspberry Pi's power the motors of the RC car through an H-bridge. The main components of the H-bridge are the four FET transistors. This set up takes a Pulse Width Modulation Signal from the Raspberry Pi and, based on what kind of pulse is sent, draws the proper amount of power from the battery and sends it to the motor in either the forwards or backwards direction (so the car can move both forwards and backwards as well as both left and right). The second large circuit that is set up is for the analog to digital converter. The front motor of the Raspberry Pi sends an analog signal back out which shows which way the wheels are facing. This information is necessary to get back to The Raspberry Pi so that it is possible to turn the wheels such that they are facing directly forwards. However, Raspberry Pi's have no analog input, just digital, so the converter is necessary. Here is a diagram of the circuit. The converter takes the analog signal and converts it to an 8-bit digital signal which the Pi can interpret and work with.

Coding: So far code has been written to make the car go forward, backward, turn left, turn right, and turn back middle as well as retrieve data from some of the sensors. All of this code is stored in the mirror directory under the names pulse_forward.py pulse_backward.py pulse_right.py pulse_left.py and turnsignal.py(turns the wheels back middle). To call these in the terminal you enter sudo python pulse_forward.py. Sometimes it will ask for a password, you will soon learn the password. Be careful when calling these files because if you use pulse_forward.py you need to be ready for the car to start going forward. Code has also been written to retrieve data from some of our sensors in a way such the data can eventually be easily manipulated for further use. These are accel.py and gpsdata.py for the accelerometer and GPS. These can also be found in the mirror directory (Note the sensors must be set up correctly using the correct pins on the Raspberry Pi for the code to work). It is advised with all this code that you look over it and understand what all of the little pieces are doing before running them. Some of them have notes in them briefly explaining what they do.


To Do

RC: The next thing we need to do with the RC is get a mount that will fit all our sensors and our RPs on. John from the machine shop said that a student would probably be able to make a mount in a couple of hours. Whoever makes the mount can either use poly acrylic glass or aluminum but acrylic will probably be best. The mount will probably use the holes that were used to hold the covers in place. There are 8 holes in total. Afterwards we need to wire the RPs into the RC. We think we can use either the GPIOs or maybe one of the USBs. We're planning on just using voltages from the Pis and fine tuning the outputs to control the car rather than using the pre-built logic chip.

Sonar: When we tested the sonar it had a range of about 1 meter before the data got to gargled. In general though the data is pretty noisy. One solution would be to write code that acts as a high/low pass filter for the times the sensor goes way off track.

GPS: The GPS works great, what we need to do is write our own code to grab the data and store it. The guide for the GPS has some example python code that shows how the GPS works.

Compass/accelerometer: We have yet to write our own novel code for this sensor. The example python function (found in /mirror/git_stuff/LSM303_RPi/examples) will run the sensor and hopefully be helpful in writing our own code for the sensor.

Tutorials

I2C

Helpful Links

RP3 GPIO pins: This links to a comprehensive guide about the pins on the RP3. This will prove helpful when connecting future devices or reconnecting current ones in a different configuration.

Learn Python: All our sensors use python to operate. If you are not familiar with python Code Academy is a good way to learn the basics