LogixPro Traffic Light Simulator

PhilipD

Member
Join Date
Nov 2009
Location
Humboldt, TN
Posts
117
Hi All,

I am going through the exercises in LogixPro and I just finished one step of the traffic light exercises. In this exercise I was required to control a standard light you would find at most any two lane intersection. The requirement was to use "Word Comparison" instructions using only one timer. Here is my version of this exercise. Please give me any advice, tips or comments (good or bad) on my program. (I hope this is large enough to see.)

Thanks.

TrafficLight.jpg
 
Your logic looks perfect to me.

I guess you got tired on the comments for the last 3 rungs. Imagine some poor street department worker finding those in a real traffic light at 3 AM during a snowstorm!!
 
The only thing that I could see as an issue is the fact that if the PLC stopped running and the timer was at 20, 100, 160, or 240 that you would have multiple lights on at once.

Secondly, comments are over rated. The code should speak for itself.
 
Secondly, comments are over rated. The code should speak for itself.

NOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO


Comments are NOT over-rated! They are absolutely essential! Get in the habit of documenting early and often. People who have to follow after you will thank you! (Heck, you'll even thank yourself if you have to go back to one of your own programs a year later...)


Baref00t, if you ever come to apply for a job with me, please make sure you let me know your moniker here -- so I'll know you don't document and, therefore, to not hire you!
 
Your logic looks perfect to me.

I guess you got tired on the comments for the last 3 rungs. Imagine some poor street department worker finding those in a real traffic light at 3 AM during a snowstorm!!

Thanks Lancie your comments are always welcome.

I came up with the logic during church Sunday. (Sorry, but I just couldn't get into the sermon.)

Yeah, I got lazy on the last three rungs. How many ways can you say the same thing? I should have tried harder but maybe the street department worker will get a little laugh out of it and make being out at 3 AM more tolerable.
 
The only thing that I could see as an issue is the fact that if the PLC stopped running and the timer was at 20, 100, 160, or 240 that you would have multiple lights on at once.

Secondly, comments are over rated. The code should speak for itself.

Thanks baref00t25,

I can redo the LIM statements so that there is a .1 second period where no light is on. It will make a good exercise to work on.

I both agree and disagree with you about comments. If the comments are meaningless (see the comments on rung 5 & 6) then they are useless. However, EFFECTIVE communication is the most important aspect of our lives. It dosen't matter if that communication is comments within a PLC program, a chat with a son or daughter, a letter to a customer and so on. The key word there is "effective." It is one of the hardest things to accomplish. Long winded, techno-jargon, business-speak morons who think they are the "Great Communicator" and go on and on for thirty minutes without communicating anything really get my goat.

Your statement was effective communication -- I just don't fully agree with it.

Thanks for taking the time to comment.
 
Comments are not over rated!

Good annotation and/or Tags help a lot, and should be encouraged. That does not mean you should not comment your code. I started programming in 8080 Machine Code, and have gone back a few months later. My first efforts were not commented, and I did not have a clue what I was thinking when I wrote it. How do you think someone else is going to do?

I learned my lesson, and as I moved up through higher languages, I made sure everything was commented. The tools are there, use them! I have had to use programming Panels and software that had little or no mechanism for commenting, and it was a pain. I have even had to work on programs with no annotation whatsoever, and believe me, it was not fun.

Yes, Ladder Logic is generally a little more obvious, but there are many many ways of achieving the same thing. Just because it made sense to you, doesn't mean that it will the next person who has to look at it. Or even yourself, I don't remember PLC Code verbatim that I did 2 years ago. Way too much water under the bridge for that.

Now that doesn't mean you have to comment every rung, especially if you are repeating yourself. How about something like "The next 3 rungs fetch the PLC Real Time Clock, and converts it to six Integer Values. This is used throughout the program for timed events." For Allen Bradley, something missing from RSLogix 5000 is Page Titles. I found them very useful in 5 and 500 Programs.

Other PLC Vendors have their own ways of doing things, but most have a mechanism for commenting the PLC Code, and it should be used. You are doing yourself a favor, as well as anyone who follows you.

My opinion for what it is worth.

Stu.....
 
I actually wrote that comment to see what type of response I'd get. I've been writing code for more than 20 years now. Everything from Motorola assembly to Java/C++/SQL to PLC code. My code is almost always commented. But as PhilipD points out, comments need to be effective. Nothing gets me more frustrated then when you get some code that someone has written that doesn't work and the comments are so through that you have to change the comments after you change the code. Or when the comments don't match the code.
Comments should be written either before you write the program or after you have tested the program. In RSLogix I like to make my comments highlighted in yellow so that I can use that to break up the different sections of code.
I have had a couple of times where sections of my code went undocumented but that was usually due to the section of code never working properly for weeks and needing constant modifications to get it to function properly.
 
I can redo the LIM statements so that there is a .1 second period where no light is on. It will make a good exercise to work on.
From past experience fooling with the LogixPro Traffic Light, if there is even a small gap between lights, accidents will occur and the bodies will pile up!

Best to leave it like you have it. We all know that a PLC will not be used to control a traffic light, but if it was, and it quit with the lights green for one direction, or even both red, that is not so bad.

When power is lost, real traffic lights go dead completely, but it is not usually a big problem for people. Most people quickly figure out the situation and take turns going through the intersection, just like in the horse-and-buggy days. When I see people cooperating like that, I begin to think that traffic lights are very obsolete. Most of them can't look down the highway and count the number of cars coming in each lane, then adjust their cycle to maximize the traffic flow through the intersection. How many times have you sat at a light, looking down the perpendicular road and not seeing any traffic for miles, saying to yourself, "why am I sitting here burning up fuel?"

For another practice exercise, you can do the above with the LogixPro Traffic Light....
 
Last edited:
From past experience fooling with the LogixPro Traffic Light, if there is even a small gap between lights, accidents will occur and the bodies will pile up!

LOL, Yeah, the smallest of gaps does lead to a spectacular crash. On my first draft I started at 1 and it was crash after crash after crash. Took me some time staring at the code before I realized that computers start counting at zero. I know that computers start counting at zero for a reason but dang I still trip over that at times.

Best to leave it like you have it.
OK.

We all know that a PLC will not be used to control a traffic light, but if it was, and it quit with the lights green for one direction, or even both red, that is not so bad. When power is lost, real traffic lights go dead completely, but it is not usually a big problem for people. Most people quickly figure out the situation and take turns going through the intersection, just like in the horse-and-buggy days. When I see people cooperating like that, I begin to think that traffic lights are very obsolete. Most of them can't look down the highway and count the number of cars coming in each lane, then adjust their cycle to maximize the traffic flow through the intersection. How many times have you sat at a light, looking down the perpendicular road and not seeing any traffic for miles, saying to yourself, "why am I sitting here burning up fuel?"

For another practice exercise, you can do the above with the LogixPro Traffic Light....
WOW! Quite a challenge you have issued here Lance. I will take a stab at it and get back. I have a feeling this will be a real head scratcher so be patient.
 
Kinda off topic, but Lancie said:
"I begin to think that traffic lights are very obsolete. Most of them can't look down the highway and count the number of cars coming in each lane, then adjust their cycle to maximize the traffic flow through the intersection. How many times have you sat at a light, looking down the perpendicular road and not seeing any traffic for miles, saying to yourself, "why am I sitting here burning up fuel?"

I'm thinking that's why my area has this "round-a-bouts are awesome and should go everywhere" mentality.
 

Similar Topics

Hello to the PLC forum, I have a question on the excellent Logixpro Simulator. Im trying to complete the more advanced Traffic Light simulator and...
Replies
7
Views
3,978
I have just completed the Traffic Light Control with a delayed green light. What I am asking here is if my rung comments are easy to follow for...
Replies
5
Views
4,446
I'm currently going through trade school and struggling with the plc class. I just cant wrap my head around this stuff. Ive managed to struggle my...
Replies
2
Views
4,725
i am working on the raffic light simulator and i have the timing exaclty how i want it but i cant quite get the cross walks down. i can get them...
Replies
2
Views
3,424
I'm going through the LogixPro labs and like a critique on my solution to the traffic light lab. I know this can be done many different ways, but...
Replies
6
Views
12,227
Back
Top Bottom