Difference between revisions of "Pi Car Comm"

From ESE205 Wiki
Jump to navigation Jump to search
m (Protected "Pi Car Comm" ([Edit=Allow only administrators] (indefinite) [Move=Allow only administrators] (indefinite)))
 
(45 intermediate revisions by 3 users not shown)
Line 13: Line 13:
 
<li>Jacob Cytron</li>
 
<li>Jacob Cytron</li>
 
<li>TA: Sam Hoff</li>
 
<li>TA: Sam Hoff</li>
<li>Instructor: Proffesor Mell</li>
+
<li>Instructor: Professor Mell</li>
 
</ul>
 
</ul>
 
</div>
 
</div>
Line 30: Line 30:
 
<h3>Security</h3>
 
<h3>Security</h3>
 
<p>Since we're using Wi-Fi, there is a potential for a malicious actor to transmit faulty messages that could trick a car.</p>
 
<p>Since we're using Wi-Fi, there is a potential for a malicious actor to transmit faulty messages that could trick a car.</p>
<p>Fortunately, since the Pi's and/or cars will not be connected to the internet, a malicious actor would have to be physically close to the car (within the range of the Wi-Fi), substantially limiting the number of potential attackers.</p>
+
<p>Fortunately, since the Pi's and/or cars will not be connected to the Internet, a malicious actor would have to be physically close to the car (within the range of the Wi-Fi), substantially limiting the number of potential attackers.</p>
 +
<h3>Hardware</h3>
 +
<p>As the project progressed, it became clear that interacting with the hardware of the PiCars was going to be a large challenge. First, the Raspberry Pi itself cannot source or sink enough current to drive the steering servo and its native PWM capabilities are not capable of reliably signaling the ESC for the drive motor. These two problems required that the Pi communicate with an on board Arduino to drive the car's two motors. Additionally, power supplies on the cars were quite unreliable. Some cars ran off of 7.4 V batteries, while others required 11.1 V. Furthermore, sometimes batteries were completely unavailable which frustrated efforts to test the cars and demo multiple times. The voltage disparity also caused one motor to drive much faster than the other.</p>
 
</div>
 
</div>
 
<div class="subsection" id="Gantt-Chart">
 
<div class="subsection" id="Gantt-Chart">
 
<h2>Gantt Chart and Presentation</h2>
 
<h2>Gantt Chart and Presentation</h2>
 +
<p>Below is the Gantt-Chart that helped schedule when we would achieve certain milestones for the project. Additionally, there is a link to the presentation we originally gave to propose this project.</p>
 
<li>[https://docs.google.com/presentation/d/1Qw1U6OoA2HyIEAeCU43uPkf5Al_VXnE7jFS3_973BfQ/edit#slide=id.p Presentation]</li>
 
<li>[https://docs.google.com/presentation/d/1Qw1U6OoA2HyIEAeCU43uPkf5Al_VXnE7jFS3_973BfQ/edit#slide=id.p Presentation]</li>
[[File:Pi Car Gantt.png | 650px]]
+
[[File:PiCarGanttFinal.png | 650px]]
 
<li>[https://docs.google.com/spreadsheets/d/1l-uonILNOf7LNyLRQjS6_3iuBaKgYDPUZ7XWaD08LFs/edit?usp=drive_web&ouid=100964140046585702557 Gantt Chart]</li>
 
<li>[https://docs.google.com/spreadsheets/d/1l-uonILNOf7LNyLRQjS6_3iuBaKgYDPUZ7XWaD08LFs/edit?usp=drive_web&ouid=100964140046585702557 Gantt Chart]</li>
  
Line 45: Line 48:
 
<li>Large Gear and Pinion Gear ($34.72)</li>
 
<li>Large Gear and Pinion Gear ($34.72)</li>
 
<li>2 mm and 3 mm Bore Bearings ($19.37)</li>
 
<li>2 mm and 3 mm Bore Bearings ($19.37)</li>
<li>Total: 113.32 </li>
+
<li>Total: $113.32 </li>
  
 
<div class="subsection" id="Design & Solutions">
 
<div class="subsection" id="Design & Solutions">
Line 52: Line 55:
 
<h2>Establishing a network</h2>
 
<h2>Establishing a network</h2>
  
<p>The WiFi protocol was used to communicate between cars. In order to use this protocol, the cars must establish a network over which to broadcast their messages. For this project, an ad-hoc mesh network was chosen as an appropriate configuration for two main reasons. First, it is distributed meaning that no car depends on any others being connected to the network to use it. If a given car doesn't find the network it's trying to join, it simply creates it. Second, it is adaptive. Because of the nature of driving cars, the topology of any network connecting them is subject to rapid change as they move in and out of range of each other. A mesh network can easily handle this changing structure (unlike the more static networks traditionally used to connect devices to the Internet). Each Pi Car was modified such that they would either try to join a network called "bakery" on startup or, failing that, would create such a network. This meant that as soon as a car booted up, it would be connected to all of the other cars in its vicinity.</p>
+
<p>The WiFi protocol was used to communicate between cars (for a more in depth primer on WiFi, see this [https://docs.google.com/presentation/d/1i24kcTkZkO07AewHi7dX0TPoBz8FgFZ6z463n4dyRH0/edit?usp=sharing presentation]). In order to use this protocol, the cars must establish a network over which to broadcast their messages. For this project, an ad-hoc mesh network was chosen as an appropriate configuration for two main reasons. First, it is distributed meaning that no car depends on any others being connected to the network to use it. If a given car doesn't find the network it's trying to join, it simply creates it. Second, it is adaptive. Because of the nature of driving cars, the topology of any network connecting them is subject to rapid change as they move in and out of range of each other. A mesh network can easily handle this changing structure (unlike the more static networks traditionally used to connect devices to the Internet). Each Pi Car was modified such that they would either try to join a network called "bakery" on startup or, failing that, would create such a network. This meant that as soon as a car booted up, it would be connected to all of the other cars in its vicinity.</p>
  
 
<h2>Sending data over the network</h2>
 
<h2>Sending data over the network</h2>
Line 61: Line 64:
 
<h2>Intra-car communication</h2>
 
<h2>Intra-car communication</h2>
  
<p>The Raspberry Pi often has difficulty sending multiple PWM signals simultaneously, and therefore was not a suitable board to control the physical elements of the car, namely the steering servo and ESC. Because of this, an Arduino Uno was used to interface between these hardware components and the Pi. The two boards communicated over serial.</p>
+
<p>The Raspberry Pi often has difficulty sending PWM signals, and therefore was not a suitable board to control the physical elements of the car, namely the steering servo and ESC. Because of this, an Arduino Uno was used to interface between these hardware components and the Pi. The two boards communicated over serial. This solution was effective but slow. In the future, using a SPI bus for communication would likely allow the car to respond more quickly to commands from the Pi.</p>
 
<h2>Resources</h2>
 
<h2>Resources</h2>
  
<p>An Instructable on how to build a Pi Car can be found here. It includes parts needed- both 3d printed parts and parts ordered, as well as a step by step guide to putting the car together.</p>
+
<p>An Instructable on how to build a Pi Car can be found  
 +
[http://www.instructables.com/id/PiCar-an-Autonomous-Car-Platform/ here].
 +
It includes parts needed- both 3d printed parts and parts ordered, as well as a step by step guide to putting the car together.</p>
  
<p>Our GitHub with all code used in this project. Documentation provided.</p>
+
<p>Our [https://github.com/patricknaughton01/comm_scripts GitHub] with all code used in this project. Documentation is expanded upon here.</p>
 +
 
 +
<p>Here are two tutorials on [https://classes.engineering.wustl.edu/ese205/core/index.php?title=Creating_an_Ad-Hoc_Network_on_the_Raspberry_Pi Creating an Ad Hoc Network on the Raspberry Pi] and [https://classes.engineering.wustl.edu/ese205/core/index.php?title=Socket_Programming Socket Programming].</p>
 +
 
 +
<p> Our UML can be found below</p>
 +
[[ File : PiUML.png |500px]]
 +
<p>The software of the project was designed to be easily integrated into any future project. To include network functionality in a new project, one simply has to <code>from core.network import Network</code> and then construct a network object: <code>network = Network(1024, 10)</code>. To allow one network object to both listen for and broadcast packets, if the user calls <code>network.start_listening()</code>, the program will create a separate process (similar to a second thread) that will report back any messages it hears. This combined functionality simplifies and reduces the amount of code necessary to integrate this project's functionality in future endeavors. Further documentation and more examples can be found on our GitHub.</p>
  
 
<h1>Results</h1>
 
<h1>Results</h1>
<p>We were able to achieve our baseline goal of establishing a network of communication between Pi Cars. They are able to send information to and from each other just as we hoped.</p>
+
<h2>Network</h2>
<p>Our biggest limiting factor was the hardware. Most of the cars we were using were not identical and the motors of the two cars we were using were vastly different. Because of this, our originally planned demo of having several cars driving around each other without colliding was not feasible. Though, we weren't able to have one car follow another car. We have the code and network set up to allow that. We were able to implement a demo in which we drove two cars around and those cars sent information to a stationary raspberry pi. The cars were sending values representing how much throttle they had and how much they were steering. If the cars were identical, then they could use this sent information to replicate it and theoretically follow the other car. But because the motors were different, it would not work. Instead, we had the stationary Raspberry Pi hooked up to a computer and was displaying all the different values that both cars were sending</p>
+
<p>We were able to achieve our baseline goal of establishing an ad network of communication between Pi Cars. As shown in the picture below the Pis were able to create an ad-hoc network.</p>
<p>A link to our final poster can be found [https://docs.google.com/presentation/d/1K00z0XiwqRIQKJIYg6rRnQgwf8CRW-JIitwONuT0LrY/edit#slide=id.p here]</p>
+
[[ File:Ad-hoc.png | 200px]]
 +
<p>They are able to send information (up to 4 KB) to and from each other just as we hoped. Below are two pictures of one Pi sending a series of texts and a different Pi receiving the messages and displaying them proving our network works.</p>
 +
[[ File : Sending.jpeg | 350px]] [[ File : Receiving.jpeg | 350px]]
 +
<p>We were ultimately able to establish a network and send packets quite quickly. To test the network, a PiCar was mounted on a mobile base which was driven past a stationary Pi. The stationary Pi simply compared the timestamps of incoming messages with the current time to figure out the time of flight of the messages. A video of the experiment and a file containing its results are displayed below. Messages consistently spent less than a tenth of a second between cars which, given the scale and speed at which the cars operate, can be considered almost instantaneous.</p>
 +
[https://classes.engineering.wustl.edu/ese205/core/images/8/80/Mobile_timing.txt Mobile Test Results]
 +
[https://classes.engineering.wustl.edu/ese205/core/images/0/00/Mobile_timing_movie.qt Mobile Timing Movie]
 +
<h2>Demo</h2>
 +
<p>Below is a picture of the main car we were using for the demonstration.</p>
 +
[[ File : Car.png | 350px]]
 +
<p>For our demo, we had one mobile car and one stationary Raspberry Pi. The Pi represented the leader of the network that is designated to receive the messages from the other cars, and the mobile Pi Car shows that messages are able to be sent while moving. While we only used one car in our demo, the network can support an arbitrary number of cars all sending messages simultaneously.</p>
 +
<h2>Challenges and Critical Decisions</h2>
 +
<p>1. The cars were sending values representing how much throttle they had and how much they were steering. If the cars were identical, then they could use this sent information to mimic each other. However, the motors and battery voltages were different, so an increase in the throttle of one Pi Car had a much different effect on the speed of the other. This led us to decide to instead implement a demo in which we drove two cars around that sent information to a stationary Raspberry Pi. The stationary Pi then displayed the information it received. Though we weren't able to have one car follow another car, improvements in hardware would have made this goal much more feasible.</p>
 +
 
 +
<p>2. The batteries on the cars weren't reliable, and in fact, one of them got so discharged as to be rendered unusable. This meant that only one car could actually be driven during the final demonstration, so we chose to have a stationary Pi and a moving car to show that messages could be sent wirelessly.</p>
 +
 
 +
<p>If we could do this project over again, we would build our own Pi Cars, both so that we could have more of them to demonstrate with, and so that they would be more standardized. We would also look into a more reliable power source.</p>
 +
 
 +
<h2>Ethics</h2>
 +
 
 +
<p>A main ethical concern with this technology is that if it were implemented with cars on the street, someone could potentially hack into the network of cars and maliciously control them. Security measures would have to be implemented to prevent this from happening. For example, encrypting and signing each message would make them take slightly longer to transmit and receive but would allow cars to verify that they were receiving legitimate information. Additionally, limiting the range of the WiFi signal to only what is necessary would minimize the chance that malicious actors could intercept signals or inject their own.</p>
 +
 
 +
<p>Another ethical concern is the lack of control humans have of their vehicles. There would of course be a way to manually control a given car, but like all machinery, self driving cars cannot be 100% reliable. If a fatal car crash happens, the blame would fall on the computer and not the human, and although the rate of fatal car crashes would surely go down due to self driving cars, the lack of direct control over one's safety concerns many.</p>
  
 +
<h2>Poster</h2>
 +
<p>A link to our final poster has been added below</p>
 +
[[ File : PiPoster.png |600px]]
 +
<h2>Improvements</h2>
 +
<p>The most obvious way this project could be improved would be to create some sort of GPS that could give the cars a sense of their global position. This would allow us to close the loop of the car-following-another-car demo because the lead car could broadcast its position instead of its control outputs and the following car could try to get to that position, rather than simply try to mimic the first car's control outputs. Additionally, a way for the cars to find their global position would allow them to know if they were on a collision course and negotiate trajectories for each of them to follow to minimize the chance that a collision actually occurs.</p>
  
 
[[Category:Projects]]
 
[[Category:Projects]]
 
[[Category:Spring 2018 Projects]]
 
[[Category:Spring 2018 Projects]]

Latest revision as of 12:09, 5 May 2018

Pi Car Comm Log

Proposal

Overview

The goal of this project is to establish vehicular communication between a group of PiCars. The end goal is to demonstrate this capability, specifically as it applies to collision avoidance between two or more vehicles.

Members

  • Patrick Naughton
  • Yak Fishman
  • Jacob Cytron
  • TA: Sam Hoff
  • Instructor: Professor Mell

Objectives

  • Establish an ad hoc network between many (potentially up to 10, at least 2) Pi Cars
  • Use this communication capability to avoid collisions in a demonstration involving at least 2 Pi Cars

Challenges

Data Transfer Rate

As the cars will be moving quickly, one of the main challenges will be ensuring that each car can establish and modify its network extremely quickly. Thus, not just data transfer, but also network establishment speed will be important.

Additionally, simultaneously addressing all valid addresses will be difficult to do efficiently.

Security

Since we're using Wi-Fi, there is a potential for a malicious actor to transmit faulty messages that could trick a car.

Fortunately, since the Pi's and/or cars will not be connected to the Internet, a malicious actor would have to be physically close to the car (within the range of the Wi-Fi), substantially limiting the number of potential attackers.

Hardware

As the project progressed, it became clear that interacting with the hardware of the PiCars was going to be a large challenge. First, the Raspberry Pi itself cannot source or sink enough current to drive the steering servo and its native PWM capabilities are not capable of reliably signaling the ESC for the drive motor. These two problems required that the Pi communicate with an on board Arduino to drive the car's two motors. Additionally, power supplies on the cars were quite unreliable. Some cars ran off of 7.4 V batteries, while others required 11.1 V. Furthermore, sometimes batteries were completely unavailable which frustrated efforts to test the cars and demo multiple times. The voltage disparity also caused one motor to drive much faster than the other.

Gantt Chart and Presentation

Below is the Gantt-Chart that helped schedule when we would achieve certain milestones for the project. Additionally, there is a link to the presentation we originally gave to propose this project.

  • Presentation
  • PiCarGanttFinal.png
  • Gantt Chart
  • Budget

  • First Pi Car Provided - $0
  • Brushless motor, ESC, and Servor Motor ($59.23)
  • Battery ($10.23)
  • Large Gear and Pinion Gear ($34.72)
  • 2 mm and 3 mm Bore Bearings ($19.37)
  • Total: $113.32
  • Design & Solutions

    Establishing a network

    The WiFi protocol was used to communicate between cars (for a more in depth primer on WiFi, see this presentation). In order to use this protocol, the cars must establish a network over which to broadcast their messages. For this project, an ad-hoc mesh network was chosen as an appropriate configuration for two main reasons. First, it is distributed meaning that no car depends on any others being connected to the network to use it. If a given car doesn't find the network it's trying to join, it simply creates it. Second, it is adaptive. Because of the nature of driving cars, the topology of any network connecting them is subject to rapid change as they move in and out of range of each other. A mesh network can easily handle this changing structure (unlike the more static networks traditionally used to connect devices to the Internet). Each Pi Car was modified such that they would either try to join a network called "bakery" on startup or, failing that, would create such a network. This meant that as soon as a car booted up, it would be connected to all of the other cars in its vicinity.

    Sending data over the network

    Because the information being sent between cars was relatively simple (it can be represented as a string of bytes), sockets were used as the network interface. Each car initiated a process to listen on a socket for any messages being broadcast and created a different socket for sending messages of its own. To send a message of its own, the cars could simply send a packet of bytes to the network broadcast address, "255.255.255.255" and any cars that were listening would receive it.

    As the topology of the network could change rapidly, the cars send UDP packets because UDP is connectionless (cars don't need to perform a handshake with one specific other car to send data to them). This allows cars to "fire and forget" packets across the network. Dropped packets are not that large of a concern because cars rebroadcast their status every few milliseconds, so one dropped data point will not make that large of a difference.

    Intra-car communication

    The Raspberry Pi often has difficulty sending PWM signals, and therefore was not a suitable board to control the physical elements of the car, namely the steering servo and ESC. Because of this, an Arduino Uno was used to interface between these hardware components and the Pi. The two boards communicated over serial. This solution was effective but slow. In the future, using a SPI bus for communication would likely allow the car to respond more quickly to commands from the Pi.

    Resources

    An Instructable on how to build a Pi Car can be found here. It includes parts needed- both 3d printed parts and parts ordered, as well as a step by step guide to putting the car together.

    Our GitHub with all code used in this project. Documentation is expanded upon here.

    Here are two tutorials on Creating an Ad Hoc Network on the Raspberry Pi and Socket Programming.

    Our UML can be found below

    PiUML.png

    The software of the project was designed to be easily integrated into any future project. To include network functionality in a new project, one simply has to from core.network import Network and then construct a network object: network = Network(1024, 10). To allow one network object to both listen for and broadcast packets, if the user calls network.start_listening(), the program will create a separate process (similar to a second thread) that will report back any messages it hears. This combined functionality simplifies and reduces the amount of code necessary to integrate this project's functionality in future endeavors. Further documentation and more examples can be found on our GitHub.

    Results

    Network

    We were able to achieve our baseline goal of establishing an ad network of communication between Pi Cars. As shown in the picture below the Pis were able to create an ad-hoc network.

    Ad-hoc.png

    They are able to send information (up to 4 KB) to and from each other just as we hoped. Below are two pictures of one Pi sending a series of texts and a different Pi receiving the messages and displaying them proving our network works.

    Sending.jpeg Receiving.jpeg

    We were ultimately able to establish a network and send packets quite quickly. To test the network, a PiCar was mounted on a mobile base which was driven past a stationary Pi. The stationary Pi simply compared the timestamps of incoming messages with the current time to figure out the time of flight of the messages. A video of the experiment and a file containing its results are displayed below. Messages consistently spent less than a tenth of a second between cars which, given the scale and speed at which the cars operate, can be considered almost instantaneous.

    Mobile Test Results Mobile Timing Movie

    Demo

    Below is a picture of the main car we were using for the demonstration.

    Car.png

    For our demo, we had one mobile car and one stationary Raspberry Pi. The Pi represented the leader of the network that is designated to receive the messages from the other cars, and the mobile Pi Car shows that messages are able to be sent while moving. While we only used one car in our demo, the network can support an arbitrary number of cars all sending messages simultaneously.

    Challenges and Critical Decisions

    1. The cars were sending values representing how much throttle they had and how much they were steering. If the cars were identical, then they could use this sent information to mimic each other. However, the motors and battery voltages were different, so an increase in the throttle of one Pi Car had a much different effect on the speed of the other. This led us to decide to instead implement a demo in which we drove two cars around that sent information to a stationary Raspberry Pi. The stationary Pi then displayed the information it received. Though we weren't able to have one car follow another car, improvements in hardware would have made this goal much more feasible.

    2. The batteries on the cars weren't reliable, and in fact, one of them got so discharged as to be rendered unusable. This meant that only one car could actually be driven during the final demonstration, so we chose to have a stationary Pi and a moving car to show that messages could be sent wirelessly.

    If we could do this project over again, we would build our own Pi Cars, both so that we could have more of them to demonstrate with, and so that they would be more standardized. We would also look into a more reliable power source.

    Ethics

    A main ethical concern with this technology is that if it were implemented with cars on the street, someone could potentially hack into the network of cars and maliciously control them. Security measures would have to be implemented to prevent this from happening. For example, encrypting and signing each message would make them take slightly longer to transmit and receive but would allow cars to verify that they were receiving legitimate information. Additionally, limiting the range of the WiFi signal to only what is necessary would minimize the chance that malicious actors could intercept signals or inject their own.

    Another ethical concern is the lack of control humans have of their vehicles. There would of course be a way to manually control a given car, but like all machinery, self driving cars cannot be 100% reliable. If a fatal car crash happens, the blame would fall on the computer and not the human, and although the rate of fatal car crashes would surely go down due to self driving cars, the lack of direct control over one's safety concerns many.

    Poster

    A link to our final poster has been added below

    PiPoster.png

    Improvements

    The most obvious way this project could be improved would be to create some sort of GPS that could give the cars a sense of their global position. This would allow us to close the loop of the car-following-another-car demo because the lead car could broadcast its position instead of its control outputs and the following car could try to get to that position, rather than simply try to mimic the first car's control outputs. Additionally, a way for the cars to find their global position would allow them to know if they were on a collision course and negotiate trajectories for each of them to follow to minimize the chance that a collision actually occurs.