Difference between revisions of "Self driving car"

From Advanced Projects Lab
Jump to: navigation, search
(Completed So Far)
(To Do)
Line 35: Line 35:
 
== To Do ==
 
== To Do ==
 
RC: The next thing we need to do with the RC car is make all of the circuitry we have permanent. Right now, we have two breadboards, one with the two H-bridges on it and another with the analog to digital converter circuit on it. We need to make this a more permanent set up so that we no longer have to worry about the circuit getting changed and so that we can mount them on the car so it can move easily with the circuits on it.
 
RC: The next thing we need to do with the RC car is make all of the circuitry we have permanent. Right now, we have two breadboards, one with the two H-bridges on it and another with the analog to digital converter circuit on it. We need to make this a more permanent set up so that we no longer have to worry about the circuit getting changed and so that we can mount them on the car so it can move easily with the circuits on it.
 +
 +
Servo Motor: The servo motor which turns the front wheels left and right is very testy. Sometimes it will work and other times, without changing any code or circuitry it will not. The theory is that the Pulse Width Modulation signal we are using creates interference that is causing the motor not to run. Some theories on how to fix this include connecting all motors to a star ground which is any disconnected ground source that all grounds will connect to, this is supposed to limit the interference. Another idea is to shield the wires going from the H-bridge to the motors and from the H-bridge to the Raspberry Pi, again limiting interference.
  
 
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.  
 
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.  

Revision as of 10:05, 7 June 2017

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.

Mount: We have constructed a mount for the RC car that screws in to pre-existing holes on the body of the car. All of the wires from the motors and sensors that are under the mount have been soldered to pins that go through the board we are using as a mount so that now all necessary connections are available from the top of the board. This means there are pins for the power and ground for both motors as well as the brown (ground), white (power), and blue (signal) wires from the servo motor that turns the front wheels. There are also a set of pins for each sensor that has all of the necessary connections that need to go to the Raspberry Pi's.

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 car is make all of the circuitry we have permanent. Right now, we have two breadboards, one with the two H-bridges on it and another with the analog to digital converter circuit on it. We need to make this a more permanent set up so that we no longer have to worry about the circuit getting changed and so that we can mount them on the car so it can move easily with the circuits on it.

Servo Motor: The servo motor which turns the front wheels left and right is very testy. Sometimes it will work and other times, without changing any code or circuitry it will not. The theory is that the Pulse Width Modulation signal we are using creates interference that is causing the motor not to run. Some theories on how to fix this include connecting all motors to a star ground which is any disconnected ground source that all grounds will connect to, this is supposed to limit the interference. Another idea is to shield the wires going from the H-bridge to the motors and from the H-bridge to the Raspberry Pi, again limiting interference.

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.

Optical Sensor: The final sensor we would like our car to have is some sort of optic sensor. A design for the sensor still needs to be drawn up and then constructed and attached to the RC.

Machine Learning: We have code written code that moves the car forward and backwards as well as turn the wheels left, right, and back to the center. The next step in the coding process is to begin experimenting with machine learning code so that the car can attempt to drive itself.

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