Traffic Light Simulation - State Machine Approach

HWilson

Member
Join Date
Apr 2018
Location
Richmond,VA
Posts
1
Hello!

This is my first post on this forum. So I'm working on a Ladder Diagram on LogixPro for the Traffic Light simulator. I am supposed to use the finite state machine approach to get the 6 traffic lights working. So far I have timers set up to work as I think they should. The simulation is supposed to run the green light indefinitely when there is no car coming in the opposite direction then when a car is sensed from the other direction, then the timer for lights is energized and it goes yellow-->red. What am I missing?
 
First, welcome to the forums! :)

Second, thank you, thank you, thank you! You have shown your work, then asked the question, instead of posting a 'please do this for me' post. You, good person, give me hope for humanity.

Now, looking over your code, try moving the 'Hold West' contact in rung 4 to rung 5 as an XIC after the timer contact. This should give you the minimum time for the light and still need the car sensor to go the Yellow-Red state.

EDIT: Sorry, you'll likely have to do the same thing for the 'Hold East' contact.
 
One thing to remember when writing ladder logic is timing is everything. And I’m not talking about the timing in timers but rather the location of objects in the ladder.
 
FSM for a Traffic Light? Really?

Hello!

This is my first post on this forum. So I'm working on a Ladder Diagram on LogixPro for the Traffic Light simulator. I am supposed to use the finite state machine approach to get the 6 traffic lights working. So far I have timers set up to work as I think they should. The simulation is supposed to run the green light indefinitely when there is no car coming in the opposite direction then when a car is sensed from the other direction, then the timer for lights is energized and it goes yellow-->red. What am I missing?

I may be ready for the "Glue Factory".
The instructor is most likely highly educated, and least-likely a hands-on PLC integrator.

Times are changing. PLC programmers were formerly electricians only. But due to the explosive growth in industrial automation, talent is coming from all directions at the same solutions.

We recently had a programmer retire, and leave a legacy of machines that work perfectly. But when they need service, no one can jump in rapidly, and decipher, as they are ill-accustomed to FSM programming.

I guess a simple solution, is for us to advertise for FSM programmer to sustain our revenue chain?

If you are savvy with ladder, function block, SFC, statement list, C++, etc...we need to bone-up on FSM.

Thoughts?

Here is a link to FSM https://en.wikipedia.org/wiki/Finite-state_machine
 
If you are savvy with ladder, function block, SFC, statement list, C++, etc...we need to bone-up on FSM.

Thoughts?

Here is a link to FSM https://en.wikipedia.org/wiki/Finite-state_machine

Finite State Machine is a concept rather than yet another language in addition to ladder, ST, C++ etc. The theoretical background in computer science (the mathematical models and automata theory) can be a bit daunting but one does not necessarily need that to build and make good use of FSMs.

The concept itself is not that hard to grasp and quite powerful for a wide range of programming applications. It can also be very useful in PLC programming. If you understand the concept, just start building one or two, with a limited number of states and transitions.
 
http://accautomation.ca/building-a-plc-program-that-you-can-be-proud-of-part-1/

The above is a link to a series that takes you through using discrete inputs and outputs to control traffic lights and cylinders. As we progress we introduce additional methods to solve logic. We look at sequencers in a new way and learn how to write programs to allow users to teach the new sequence.

Thought that this may be of interest to you for learning.
Regards,
 
When doing a "State Machine", it helps to draw out the actual states, and the transitions between them. (See below). Note that there are two identically named states, with identical conditions, but they have different transitions paths, and so must be different states.

Once you have that diagram, it becomes fairly straightforward to write code to transition from one state to another.

You appear to be attempting to do one thing correctly -- namely separating the STATES (where you are on the map) from the ACTIONS (what happens when you are at a particular place). But I've been trying to 'translate' the meaning of your states based on your abbreviations, and am still scratching my head. You should be commenting your code more.

Your code (mostly) correctly sets what I'm going to assume is the North-South light as the default. I'll walk you through how to do the code for this state; the rest will be up to you:

Here are the rules for being in what my diagram calls "N/S Go / E/W Stop" (which for shorthand I'll call "NS_Go"):
  1. If no states are set, be in this state.
  2. If on All_Stop2 and the All_Stop2 timer completes, go to this state.
  3. Once on the state, stay in the state as long as the NS_Go timer is NOT done.

The ladder now matches this exactly, branch by branch:
         NS_Go   NS_Hld  All_Stop1  EW_Go   EW_Hld  All_Stop2       NS_Go
---+-----|/|-------|/|------|/|------|/|------|/|------|/|------+---( )
| |
| All_Stop2 All_Stop2_TMR.Dn |
+-----| |----------------| |---------------------------------+
| |
| NS_Go NS_Go_TMR.Dn |
+-----| |----------------|/|---------------------------------+


Of course, the NS_Go timer only runs when in the NS_Go state. This naturally translates to:
     NS_Go                           NS_Go_TMR
------| |-----------------------------[TON] 80 sec.


Since state engine leaves the NS_Go state when the timer is done, the NS_Go contact will drop out, de-energizing the TON. No RES reset is needed (depending on PLC brand).

And so on.

Good luck.

PLCs_Net.png
 
Last edited:

Similar Topics

Hi ! I got this example of semaphore, it works. But now i want something more complicated. Using a timer. The LED Q0.2 is turn on (2 seconds)...
Replies
10
Views
4,792
hello there i m working with the traffic light simulation program in rslogix... i want it to work for priority road control... my right hand side...
Replies
5
Views
3,303
Hi.. I've just completed Exercise 2 of Traffic Light simulation (using WordCompare). The one about Walk sign showing and blinking. Please...
Replies
2
Views
3,070
I am a complete newbie to this stuff and wanted to try this out and was looking for any information on how I can complete this by Wednesday...
Replies
19
Views
12,704
Hey Folks I've done some browsing along the forum for some help in a matter. It would seem the question has been asked many times but it just...
Replies
41
Views
16,821
Back
Top Bottom