Tuesday, March 23, 2021

Fun With Racket: Traffic Lights

Traffic Lights

Working with Racket and Arduino.  




The Challenge


To design and implement a Racket / Arduino traffic light system. Demonstrate what you know about Racked, arduino, design, states, etc.

Project specification drawing

T-junction with 2 road signals
Road is 200m
Speed limit is 30mph

Traffic lights Racket project visual


Resources


Arduino (running Firmata), LEDs (red, orange, green), resistors, pushbuttons, any sensors you may need, and so on
Racket, the firmata.rkt library
Sample racket code showing a simple prototype for a single traffic light


Behaviour of System


Finite State Machine for traffic light working


The FSM above was used to, in a way, simulate and plan our ideas thoroughly before implementing or making any further decisions. It has 14 states as represented by the coloured circles.

Q = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14 }

T = { a, b, c, d, e, f, g, h }

Q0 = { 1 }

F = { }

t = { ((1, b), 2), ((2, f), 5), ((2, g), 4), ((2, h), 3), ((3, a), 8), ((3, d) 14), ((4, a), 7), ((4, d), 12), ((5, a), 6), ((5, d), 13), ((6, c), 10), ((6, d), 13), ((7, c), 11), ((7, d), 12), ((8, c), 9), ((8, d), 14), ((9, a), 5), ((9, d), 14), ((9, e), 1), ((10, a), 4), ((10, d), 13), ((10, e), 1), ((11, a), 3), ((11, d), 12), ((11, e), 1), ((12, a), 11), ((13, a), 10), ((14, a), 9) }

;; a = 5s   b = 10s  c = 20s  d = PB  e = IfPBswitch  f = 5s (from state 2 to 5)  g = 5s (from state 2 to 4)  h = 5s (from state 2 to 3)

State

Rep. in FSM

1

0/ped1/s1

2

0/ped0/s0

3

003

4

030

5

300

6

100

7

010


State

Rep. in FSM

8

001

9

002

10

200

11

020

12

ButtOnorange

13

ButtOnpurple

14

ButtOngreen


;; 0 means RED,   1 means GREEN,   2 means AMBER,   3 means RED-AMBER.

;; So, 001 indicates signal1 at red, signal2 at red and signal3 at green

The language accepted:

    b [ (f| g| h) (a (c (d a| e b | a (a| d) ) | d a (d| e| a) ) | d (a (d a| e b| a (a| d) ) ) ) ]+

State transition diagram

Evaluation


We haven’t put in a pedestrian button as the time delay did not work when we tried the coding. This did not allow us to proceed with the remaining plan, and had to use “sleep” which does not effectively use the button.

The system will only work on a certain time and will not change, even if there is a traffic jam on one side and the other side, empty. It will still run its course.

No blinking lights to indicate signal change or physical state change.


This task was a group project done by:
Tayyab Sultan

0 comments:

Post a Comment




 
Loading...