Difference between revisions of "Self driving car"

From Advanced Projects Lab
Jump to: navigation, search
(Completed So Far)
(=Computer Vision)
 
(5 intermediate revisions by the same user not shown)
Line 2: Line 2:
  
 
== Getting Started ==
 
== Getting Started ==
 +
Note: All files are currently on the top Raspberry Pi labeled "Master", use this Raspberry Pi for all the following steps.
 +
 
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.
 
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.
  
Line 36: Line 38:
 
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 circuit for that is [http://www.bristolwatch.com/ele/h_bridge.htm here.] 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. [https://circuitdigest.com/fullimage?i=circuitdiagram_mic/Interfacing-ADC0804-with-Raspberry-Pi-circuit-diagram.png 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.
 
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 circuit for that is [http://www.bristolwatch.com/ele/h_bridge.htm here.] 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. [https://circuitdigest.com/fullimage?i=circuitdiagram_mic/Interfacing-ADC0804-with-Raspberry-Pi-circuit-diagram.png 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.
+
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.
 +
 
 +
===[[Computer Vision]]===
 +
 
 +
Code for the Raspberry Pi camera has also been written and is discussed in the Computer Vision subsection and can be accessed here ([[Computer Vision]]).
  
 
== To Do ==
 
== To Do ==
Line 45: Line 51:
 
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.  
  
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.
+
Slave-Master: The RP's should be 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 should be hooked up through a WiFi signal.
  
 
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.
 
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.

Latest revision as of 14:03, 4 February 2019

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

Note: All files are currently on the top Raspberry Pi labeled "Master", use this Raspberry Pi for all the following steps.

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.

Third: Getting into the pi. Connecting via wifi requires finding the Raspberry Pi's wifi (rpbot_spot) and connecting, then using the command line typing " ssh rpbot0 -l rpbot0 -p 22" this should prompt you with a password which is the usual APL password.

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 designed to be part of the multinode set up on our system. Any changes to one mirror directory should change the mirror directory in the other node. This functionality has not yet been implemented.

Fifth: Make sure everything is wired correctly. Some of the circuits have links describing what they should look like, but here is a brief description of all that should be connected as of now. First, from the Raspberry Pi are five wires that go into our two H-bridges, a common ground and two control wires each. Exactly which wires is found in the code for driving and turning the car. These wires go directly behind the resistors on the side of the breadboard with less FETs. From each H-bridge are the power and ground for the two motors which connect to the long row of pins starting on the left if you are facing the car from the front and go power for the thrust motor, skip a pin, ground for the thrust motor, skip a pin, power for the turning motor, skip a pin, ground for the turning motor. Second is the analog to digital converter circuit which has a ton of wires, but is very well described further down on this page. Next is the GPS which is a USB that plugs into the Raspberry Pi's and has four wires coming out of it that connect to the pins which connect to the chip. The wires should be on every other pin and if you are looking at the car from the front then they go from left to right in the order white, green, black, red. The final piece currently hooked up is the accelerometer which uses the pins to the right of the chip (again if you are looking from the front). In order from closest to the Raspberry Pi to furthest they go purple, white, red. Where they go on the Raspberry Pi can be found in the code, accel.py.

IMPORTANT: Do not close the laptop or shut it down with the Raspberry Pi connected. If you want to disconnect the Raspberry Pi or close or turn off the computer, run the command sudo shutdown -h while ssh'd into the Raspberry Pi. Then wait for the Wi-fi signal to disconnect thus signalling a proper shutdown of the Raspberry Pi. !!!!WARNING!!!! -> Use FSCK to fix raspberry pi (and other Ubuntu OP systems) if the pi becomes corrupted due to improper shutdown procedure. FSCK is a built in tool that is very dangerous! YOU CAN CORRUPT THE ENTIRE SYSTEM! Carefully read about the -a and -A flags and how one of them can ruin the entire project. You also need to be careful where (in terms of directory) you implement the FSCK command. !!!!WARNING!!!!!

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.

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 circuit for that is here. 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.

Computer Vision

Code for the Raspberry Pi camera has also been written and is discussed in the Computer Vision subsection and can be accessed here (Computer Vision).

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. This issue was actually solved by resoldering some of the connections, but the solutions are good things to know in case something else goes wrong (as it so often seems to do). 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.

Slave-Master: The RP's should be 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 should be hooked up through a WiFi signal.

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