Code
import blinkstick
import matplotlib as mpt
import numpy as np
from enum import Enum
import time
Jasper Day S2265891
Goal: Write a python program which uses a blinkstick to simulate the TOUCAN pedestrian crossing at the corner of Mayfeild Road and West Mains Road
Period | Use | Signal for Pedestrians | Signal for Vehicles | Timing | Variation |
---|---|---|---|---|---|
I | Vehicle Running | Red | Green | 20 - 60 (ends at either max time or on pedestrian demand + gap. Vehicle actuation cancels gap for 6 sec) | Traffic volume |
II | Amber to Vehicles | Red | Amber | 3 | n/a |
III | Vehicle Clearance | Red | Red | 1 (gap in vehicles) - 3 (vehicle present) | Vehicle actuation |
IV | Pedestrian Crossing | Green | Red | 4 - 7 | Check maps |
V | Pedestrians keep crossing | Black | Red | 3 | n/a |
VI | Pedestrian clearance | Black | Red | 0 - 22 (pedestrian detection adds 2 sec) | Pedestrian actuation |
VII | Additional Pedestrian Crossing | Black | Red | 0 - 3 | Pedestrian detection |
VIII | All red | Red | Red | 1 - 3 | Free choice |
IX | Red / Amber to Vehicles | Red | Red/Amber | 2 | NA |
class Period(int, Enum):
# Enum type allows state comparison of our traffic light variable.
# `int` enum lets us augment state by addition operator +=
I = 1
II = 2
III = 3
IV = 4
V = 5
VI = 6
VII = 7
VIII = 8
IX = 9
# class TrafficLight():
# # container class for our state
# def __init__(self):
# self.state = TrafficLightState.I
# Size of the crosswalk simulation matrix. One square is 1 meter on a side.
ROWS = 70
COLUMNS = 30
TIME = 0 # seconds
class Scene():
scene = np.zeros([ROWS, COLUMNS])
state = Period.I # global traffic light state
def simulation_step(self): # advance simulation
TIME += 1
time.sleep(1)
class TrafficLight(Scene):
pass
class SceneObject(Scene):
def __init__(self, row_start, row_end, col_start, col_end):
if not (row_start < row_end < super().scene.shape[0] and col_start < col_end < super().scene.shape[1]):
# Check if bounds are valid
raise Exception("Incorrect bounds for object")
self.row_start = row_start
self.row_end = row_end
self.col_start = col_start
self.col_end = col_end
class Pedestrians(SceneObject):
pass
class Car(SceneObject): # Contents of Address Register. just kidding.
pass
window = Scene()
pedestriandetector = SceneObject(35,50,7,17)
print(f"window state {window.state}")
print(pedestriandetector.state)
window state 1
Period.I