[CLOSED] State machine for traffic light

Thread Starter

Pushkar1

Joined Apr 5, 2021
416
I am asking for help to make state machine for traffic light system with pedestrian crossing . It is facts that traffic rules are not strictly followed in my country India. The fixed time traffic light system controller works for the vehicle in the city I live in. If you are driving car and you get green signal then you can go towards east north and south direction. One direction is active for one minute and on three directions the driver has to wait for one minute.

When the signal is green, the countdown timer starts at 60 seconds, so the driver can go in three directions. The yellow light turns on when the timer reaches 10 seconds. The red light turns on when the timer reaches 0 seconds. Driver has to stop when he sees a red light. It is a busy traffic system with long stops. In some places, automatic as well as manual traffic light system is operated.

I would like to design state machine for UK/US based traffic light system with six LED's and two push buttons. I presume the traffic light for vehicles on the main road has three possible states- Red, Yellow and Green while the traffic lights for pedestrians to cross the road have two lights- red for Wait (W) and green for ( G ).

I am having trouble to setting timing for vehicle and pedestrian crossing.

Obviously goal is not to create a real world system for traffic controller. I just want to learn state machine so that's the only reason using example traffic light system with pedestrian crossing system
 
Last edited by a moderator:

Thread Starter

Pushkar1

Joined Apr 5, 2021
416
hi P,
This link may help explain the UK sequence Red, Amber, Green
E
https://theorytest.org.uk/traffic-lights/
I assume simple UK-style traffic light sequence is as follows:

Red (stop, wait for 10 sec)
Red / Yellow (stay stopped but get ready light turns green soon, approx 5 sec )
Green (Go safe to proceed, 10 sec)
Yellow (slow down, Red light soon, wait for 5 sec)

Edit : I have timing setting for vehicles but I don't know what to do about timing of pedestrians lights. Do the all vehicles stop if traffic signal is green for pedestrian
 
Last edited:

ericgibbs

Joined Jan 29, 2010
18,766
hi P,
UK Pedestrian light signalling is very different from traffic road junction signalling.

I would recommend you consider them as two separate problems.

I assume simple UK-style traffic light sequence is as follows:

Red (stop)
Red / Amber (stay stopped but get ready light turns green soon, approx 5 sec )
Green (Go safe to proceed)
Amber (stop if it safe to do so, else keep going., Red light soon, wait for 5 sec)

Most traffic junction 'Stop/Go' light timings are based on traffic density

Detector pads in the road ways, ahead of the lights...
E

Update:

There are Five different pedestrian light systems in the UK.

https://www.4wheelz.co.uk/learning-to-drive/pedestrian-crossings/
 

Thread Starter

Pushkar1

Joined Apr 5, 2021
416
There are Five different pedestrian light systems in the UK.
https://www.4wheelz.co.uk/learning-to-drive/pedestrian-crossings/
I would use zebra crossing

I assume simple UK-style traffic light sequence is as follows:

Red (stop)
Red / Amber (stay stopped but get ready light turns green soon, approx 5 sec )
Green (Go safe to proceed)
Amber (stop if it safe to do so, else keep going., Red light soon, wait for 5 sec)

Most traffic junction 'Stop/Go' light timings are based on traffic density
I don't understand how long the traffic signal stays red and green. I had timing for red and green in my sequence but you have removed in your sequence what's the reason behind it
 

ericgibbs

Joined Jan 29, 2010
18,766
hi P,
The detector pads preceeding the lights measure the traffic density, so the light control electronics can make decisions on the Red or Green state duration.
At night time it is common when driving on a main road to find all the lights ahead at Green or turn to Green as you approach the lights.
The side roads are often at Red unless a vehicle has be detected.

When you consider this, it makes sense to have a 'smart' controller at busy intersections.
E
 

Thread Starter

Pushkar1

Joined Apr 5, 2021
416
When you consider this, it makes sense to have a 'smart' controller at busy intersections.
E
Thinking about a real world traffic light controller can be complicated to explain the state machine concept. considering only an individual light; ie, just one set of red/green/yellow and go/stop for simplicity

Let's say traffic light controller system has two function. system tells the driver when to cross the road and when not. system tells the Pedestrians when to cross the road and when not.

Simple traffic light sequence is as follows:

Red (stop)
Red / Yellow (stay stopped but get ready light turns green soon )
Green (Go safe to proceed)
Yellow (slow down, Red light soon)

I will simulate the traffic system with six LEDs and two buttons after making the state machine.

This is my attempt so far to make a state machine for a simple traffic light system. If I succeed in doing this, I will try to design a more complex system.

I would like someone's help to make a state machine for Simple traffic light
 

click_here

Joined Sep 22, 2020
548
It's great to hear that you have a project to work on!

Let's start with what you've learnt - Draw a state diagram describing how you want it to behave.

You can use 1sec ticks for your state machine to simplify things
 

Thread Starter

Pushkar1

Joined Apr 5, 2021
416
Let's start with what you've learnt - Draw a state diagram describing how you want it to behave.
Earlier i was following UK rules but now i have changed my mind i will try to make it as simple as possible.

Right now my idea is to keep one direction active and stop all other for 1 minute. it will repeat for all direction. This procedure is for vehicle traffic lights. I want the vehicle traffic to stop for 1 minute when the pedestrian presses the button

I am stuck in planning to design a simple traffic light system when my planning is complete then I will definitely make an state machine for system
 

PointTwoPA

Joined Jan 28, 2021
4
If you want to learn state machines, you can't go wrong with the Quantum Framework references. You don't have to use their framework, but their documents will help you understand UML hierarchical state charts which is a good way to do the design. If you have the time to learn their setup, then you can use their QM modeling tool, you can simulate the whole thing on your desktop using their framework. I use their QM modeling tool just to document my designs.

https://www.state-machine.com/doc/AN_PELICAN.pdf

Miro Samek's book is online in PDF formart and it contains this pedestrian crosswalk example as well.
https://www.state-machine.com/psicc2
https://www.state-machine.com/doc/PSiCC2.pdf
 

olphart

Joined Sep 22, 2012
114
I designed one as a product (sold several thousand since '15).
A simple structure is to decide on a data format for what any given step needs to do.
Something like: {relays 1-n}{cadence / # counts @ cadence} as bitmap / number fields.
Write the main section to parse and execute each step.
Keep track of the current step address, then loop to top at end.
Makes it easy to change what the step sequence needs to be.
Good Hunting <<<)))
 

Thread Starter

Pushkar1

Joined Apr 5, 2021
416
@click_here

At first I was planning to build a state machine for a traffic light system, but I came to the conclusion that the traffic light system is too complicated for now.

So I postponed my plan and I am looking for how to implement Preemptive Multitasking. I will come back soon if needed
 
Top