Progress Report 4
We met with the following goals:
- Successfully build a traffic simulation with LEDs
- Develop an understanding of how that will connect to our system of four sensors
- Implement our eight cases that we previously defined in some form
Last time, it was difficult to build the LEDs on top of our sensor system, so we opted to build a separate circuit that had a red, yellow, and green LED to accurately represent the traffic signal. We built this new traffic signal system as its own entity connected to the other Raspberry Pi, which became useful since it effectively represents the traffic signal as an external input signal to our device. We were then able to connect the traffic light system to our pedestrian light system so that our sensors could refer to the status of the traffic light system as an input signal. As a result, we are now using two Raspberry Pis in our project. Once we had our traffic signal system fully working on its own, we connected a red and green LED to our pedestrian signal system to act as the lights of the signal itself.
In order to test the traffic light system in conjunction with our pedestrian signal lights we wrote a small code example that made the pedestrian signal turn red when the traffic light is green or yellow and green when the traffic light is red. This was just a quick test example. The photo below shows this code running on our two systems. In this particular photo, the traffic light is red, so the pedestrian light is red.
As we connected the LEDs to both systems, we ran into a lot of issues with making sure that the lights were coming on at the correct times. We decided that, in order to ensure maximum safety, if there were to be any errors, they should happen when the traffic light is red, not when the traffic light is green. After a lot of error elimination, we ended up with having a small error in the second if statement in our code (always the second if statement, never the first one) where the wrong light will flicker on and off and then stay off. Thus, we decided to make the first if statement always the most important one that involves the traffic light being green.
We were then able to upgrade to some code that incorporated the sensors. This time, we built our sensor code into the LED code which actually worked. In order to successfully do this we had to implement our eight conditions that were discussed previously. We broke those eight conditions into the following conditions:
- If there is no person then the whole signal should be turned off
- If there is a vehicle and the traffic light is green, then the pedestrian light is red
- If there is no vehicle and the traffic light is green, then the pedestrian light is red
- If there is a vehicle and the traffic light is red, then the pedestrian light is red
- If there is no vehicle and the traffic light is red, then the pedestrian light is green
As such, we essentially redefined what it means for a vehicle to be present. Since we have adopted the motion sensor to be facing the road, we only consider a vehicle to be moving. So if there is a moving vehicle, no matter what the traffic light condition is, the pedestrian should not be crossing the street. Thus, our signal does go beyond just blindly following the traffic signal and assuming that all cars are following the rules of the road.
The image below shows are integrated traffic light with pedestrian signal, complete with commands for the pedestrian that are printed out in the terminal corresponding to the pedestrian signal status. If the pedestrian signal is red, “WAIT” is printed; if the signal is green, “Cross the street!” is printed; if the signal is off, “no person” is printed.