Traffic light simulation
Archiver
Posts: 46,084
In a message dated 5/24/2004 7:27:08 PM Eastern Daylight Time,
m_cstar@y... writes:
> Hi there. Wondering if anyone could help me. I am doing a
> simulation of a traffic intersection and cannot get the program to
> work everything simultaneously. I have limit switches under the
> roads ways to trigger the lights, photocells to sense dark that will
> turn on the street lamps and make just the red lights blink. I have
> gotten this to all work seperately, but not all together. Does
> anyone have any suggestions? Thanks for anything.
>
>
The one thing you have to remember is that the Stamp can not do two things at
once. If you have a light blinking, then Stamp can do nothing until it quits
blinking. If you have pauses, try to accompish tasks during the pause.
[noparse][[/noparse]Non-text portions of this message have been removed]
m_cstar@y... writes:
> Hi there. Wondering if anyone could help me. I am doing a
> simulation of a traffic intersection and cannot get the program to
> work everything simultaneously. I have limit switches under the
> roads ways to trigger the lights, photocells to sense dark that will
> turn on the street lamps and make just the red lights blink. I have
> gotten this to all work seperately, but not all together. Does
> anyone have any suggestions? Thanks for anything.
>
>
The one thing you have to remember is that the Stamp can not do two things at
once. If you have a light blinking, then Stamp can do nothing until it quits
blinking. If you have pauses, try to accompish tasks during the pause.
[noparse][[/noparse]Non-text portions of this message have been removed]
Comments
m_cstar@y... writes:
> Hi there. Wondering if anyone could help me. I am doing a
> simulation of a traffic intersection and cannot get the program to
> work everything simultaneously. I have limit switches under the
> roads ways to trigger the lights, photocells to sense dark that will
> turn on the street lamps and make just the red lights blink. I have
> gotten this to all work seperately, but not all together. Does
> anyone have any suggestions? Thanks for anything.
>
>
Also, if you have the Stamp waiting for a photo senssor to tell it that it is
dark,
you tie up the Stamp. Try just making a quick check now and then.
Sid Weaver
512K plug-in EEPROM.......
http://www.visualmuses.com/chipcircuit/index.html
[noparse][[/noparse]Non-text portions of this message have been removed]
simulation of a traffic intersection and cannot get the program to
work everything simultaneously. I have limit switches under the
roads ways to trigger the lights, photocells to sense dark that will
turn on the street lamps and make just the red lights blink. I have
gotten this to all work seperately, but not all together. Does
anyone have any suggestions? Thanks for anything.
Newzed@a... wrote:
In a message dated 5/24/2004 7:27:08 PM Eastern Daylight Time,
m_cstar@y... writes:
> Hi there. Wondering if anyone could help me. I am doing a
> simulation of a traffic intersection and cannot get the program to
> work everything simultaneously. I have limit switches under the
> roads ways to trigger the lights, photocells to sense dark that will
> turn on the street lamps and make just the red lights blink. I have
> gotten this to all work seperately, but not all together. Does
> anyone have any suggestions? Thanks for anything.
>
>
The one thing you have to remember is that the Stamp can not do two things at
once. If you have a light blinking, then Stamp can do nothing until it quits
blinking. If you have pauses, try to accompish tasks during the pause.
[noparse][[/noparse]Non-text portions of this message have been removed]
To UNSUBSCRIBE, just send mail to:
basicstamps-unsubscribe@yahoogroups.com
from the same email address that you subscribed. Text in the Subject and Body of the message will be ignored.
Yahoo! Groups Links
Do you Yahoo!?
Friends. Fun. Try the all-new Yahoo! Messenger
[noparse][[/noparse]Non-text portions of this message have been removed]
many lights, what they are supposed to do, and all the other stuff you want
to accomplish. Then maybe we can give you some specific help.
Jonathan
www.madlabs.info
Original Message
From: "Mima Ciani" <m_cstar@y...>
To: <basicstamps@yahoogroups.com>
Sent: Monday, May 24, 2004 4:54 PM
Subject: Re: [noparse][[/noparse]basicstamps] Traffic light simulation
> Someone has mentioned something about loops or sub routines. Do you know
anything about these? I have tried, but with no success.
>
> Newzed@a... wrote:
> In a message dated 5/24/2004 7:27:08 PM Eastern Daylight Time,
> m_cstar@y... writes:
>
>
> > Hi there. Wondering if anyone could help me. I am doing a
> > simulation of a traffic intersection and cannot get the program to
> > work everything simultaneously. I have limit switches under the
> > roads ways to trigger the lights, photocells to sense dark that will
> > turn on the street lamps and make just the red lights blink. I have
> > gotten this to all work seperately, but not all together. Does
> > anyone have any suggestions? Thanks for anything.
> >
> >
>
> The one thing you have to remember is that the Stamp can not do two things
at
> once. If you have a light blinking, then Stamp can do nothing until it
quits
> blinking. If you have pauses, try to accompish tasks during the pause.
>
>
>
> [noparse][[/noparse]Non-text portions of this message have been removed]
>
>
>
> To UNSUBSCRIBE, just send mail to:
> basicstamps-unsubscribe@yahoogroups.com
> from the same email address that you subscribed. Text in the Subject and
Body of the message will be ignored.
>
> Yahoo! Groups Links
>
>
>
>
>
>
>
> Do you Yahoo!?
> Friends. Fun. Try the all-new Yahoo! Messenger
>
> [noparse][[/noparse]Non-text portions of this message have been removed]
>
>
>
>
> To UNSUBSCRIBE, just send mail to:
> basicstamps-unsubscribe@yahoogroups.com
> from the same email address that you subscribed. Text in the Subject and
Body of the message will be ignored.
>
> Yahoo! Groups Links
>
>
>
>
>
>
Jonathan Peakall <jpeakall@p...> wrote:What exactly do you want to do? Give us all the details you can, like how
many lights, what they are supposed to do, and all the other stuff you want
to accomplish. Then maybe we can give you some specific help.
Jonathan
www.madlabs.info
Original Message
From: "Mima Ciani"
To:
Sent: Monday, May 24, 2004 4:54 PM
Subject: Re: [noparse][[/noparse]basicstamps] Traffic light simulation
> Someone has mentioned something about loops or sub routines. Do you know
anything about these? I have tried, but with no success.
>
> Newzed@a... wrote:
> In a message dated 5/24/2004 7:27:08 PM Eastern Daylight Time,
> m_cstar@y... writes:
>
>
> > Hi there. Wondering if anyone could help me. I am doing a
> > simulation of a traffic intersection and cannot get the program to
> > work everything simultaneously. I have limit switches under the
> > roads ways to trigger the lights, photocells to sense dark that will
> > turn on the street lamps and make just the red lights blink. I have
> > gotten this to all work seperately, but not all together. Does
> > anyone have any suggestions? Thanks for anything.
> >
> >
>
> The one thing you have to remember is that the Stamp can not do two things
at
> once. If you have a light blinking, then Stamp can do nothing until it
quits
> blinking. If you have pauses, try to accompish tasks during the pause.
>
>
>
> [noparse][[/noparse]Non-text portions of this message have been removed]
>
>
>
> To UNSUBSCRIBE, just send mail to:
> basicstamps-unsubscribe@yahoogroups.com
> from the same email address that you subscribed. Text in the Subject and
Body of the message will be ignored.
>
> Yahoo! Groups Links
>
>
>
>
>
>
>
> Do you Yahoo!?
> Friends. Fun. Try the all-new Yahoo! Messenger
>
> [noparse][[/noparse]Non-text portions of this message have been removed]
>
>
>
>
> To UNSUBSCRIBE, just send mail to:
> basicstamps-unsubscribe@yahoogroups.com
> from the same email address that you subscribed. Text in the Subject and
Body of the message will be ignored.
>
> Yahoo! Groups Links
>
>
>
>
>
>
To UNSUBSCRIBE, just send mail to:
basicstamps-unsubscribe@yahoogroups.com
from the same email address that you subscribed. Text in the Subject and Body of the message will be ignored.
Yahoo! Groups Links
Do you Yahoo!?
Friends. Fun. Try the all-new Yahoo! Messenger
[noparse][[/noparse]Non-text portions of this message have been removed]
> Hi there. Wondering if anyone could help me. I am doing a
> simulation of a traffic intersection and cannot get the program to
> work everything simultaneously. I have limit switches under the
> roads ways to trigger the lights, photocells to sense dark that
will
> turn on the street lamps and make just the red lights blink. I have
> gotten this to all work seperately, but not all together. Does
> anyone have any suggestions? Thanks for anything.
If you go into a loop to blink something, then you cannot do other
things.
considder letting the program run without going into loops, but each
scan turn on the light, then the next, turn off the light. you can
let a light be on for 5 scans and off for 5 and do others for 4 or 6
so they do not all appear to be connected.
then just pause the whole program to make each scan something you
want.
if you want to have the stop light at the corner of Broad and Vine
change red yellow green repetitivly, you can use a simple counter for
that.
if you don't want a change goto the next part of the program.
or, you can have x=x+1 and if X is greater than 100 then
go to the part that selects the color to be lit. That way, the
program has to go thru 100 scans to get the light to change color.
if you go into a pause, you lock up the whole works till it is done.
Dave
> simulation of a traffic intersection and cannot get the program to
> work everything simultaneously. I have limit switches under the
> roads ways to trigger the lights, photocells to sense dark that will
> turn on the street lamps and make just the red lights blink. I have
> gotten this to all work separately, but not all together. Does
> anyone have any suggestions? Thanks for anything.
I've done this for model railroads several times. I typically just use one
or more state machines that run off the inputs.
It can get tricky if you're trying to do several state machines in parallel.
In that case you might consider a scheduler where each event checks the
input states and then schedules future events based on those inputs. These
events can overlap; the scheduler will keep track of knowing when the next
event will fire. This is also similar to how elevator load schedulers are
written.
--
Enjoy,
George Warner,
Schizophrenic Optimization Scientists
Apple Developer Technical Support (DTS)
> Hi there. Wondering if anyone could help me. I am doing a
> simulation of a traffic intersection and cannot get the program to
> work everything simultaneously. I have limit switches under the
> roads ways to trigger the lights, photocells to sense dark that
will
> turn on the street lamps and make just the red lights blink. I
have
> gotten this to all work seperately, but not all together. Does
> anyone have any suggestions? Thanks for anything.
I read all the replies before coming back to this one. I think it's
a little simpler than what you think. We had to do a Traffic Light
Simulation in Digital Lab when I was in College.
The fact is the Stamp can do this quite easily. I saw that some of
the replies centered around the Stamps inability to do multiple
tasks. That doesn't matter in this case. If you break it down:
If you're monitoring an intersection, normally you would have 4
sensors in the road (These are usually metal detectors using coils)
to detect a vehicle at the Red light. At this point many systems
will check the opposite intersection for traffic (By monitoring the
sensors) and start a countdown of around 10 seconds or so, depending
on the type of intersection.
Once the countdown is complete, you start the change cycle, by
making the green lights yellow, then after a few seconds (depending
on the size of the intersection) red, at which time the red ones
become green.
The Stamp doesn't need to check sensors during this time. You're in
the middle of a change cycle, so it doesn't matter what traffic is
doing. The lights have to complete the cycle anyway. Once that has
happened, you can either do the same routine on the sensors again,
or, if this is an intersection with a primary street, you can start
a timer and start the switch back. I hope this makes sense and
helps you.
Chris Savage
Knight Designs
project didn't require light/dark sensors it could easily be handled
with a BS1.
-- Jon Williams
-- Applications Engineer, Parallax
-- Dallas Office
Original Message
From: Chris Savage [noparse]/noparse]mailto:[url=http://forums.parallaxinc.com/group/basicstamps/post?postID=Jxz48S3_9GcW4DWy-nAODu6AextdV0pl-dXZZ3Jv2VaoEr8jN0JaVYV07wfDZfbI2tOQEK0UG6nDGgZTUMc]knight_designs@y...[/url
Sent: Tuesday, May 25, 2004 10:45 PM
To: basicstamps@yahoogroups.com
Subject: [noparse][[/noparse]basicstamps] Re: Traffic light simulation
--- In basicstamps@yahoogroups.com, "m_cstar" <m_cstar@y...> wrote:
> Hi there. Wondering if anyone could help me. I am doing a
> simulation of a traffic intersection and cannot get the program to
> work everything simultaneously. I have limit switches under the
> roads ways to trigger the lights, photocells to sense dark that
will
> turn on the street lamps and make just the red lights blink. I
have
> gotten this to all work seperately, but not all together. Does
> anyone have any suggestions? Thanks for anything.
I read all the replies before coming back to this one. I think it's
a little simpler than what you think. We had to do a Traffic Light
Simulation in Digital Lab when I was in College.
The fact is the Stamp can do this quite easily. I saw that some of
the replies centered around the Stamps inability to do multiple
tasks. That doesn't matter in this case. If you break it down:
If you're monitoring an intersection, normally you would have 4
sensors in the road (These are usually metal detectors using coils)
to detect a vehicle at the Red light. At this point many systems
will check the opposite intersection for traffic (By monitoring the
sensors) and start a countdown of around 10 seconds or so, depending
on the type of intersection.
Once the countdown is complete, you start the change cycle, by
making the green lights yellow, then after a few seconds (depending
on the size of the intersection) red, at which time the red ones
become green.
The Stamp doesn't need to check sensors during this time. You're in
the middle of a change cycle, so it doesn't matter what traffic is
doing. The lights have to complete the cycle anyway. Once that has
happened, you can either do the same routine on the sensors again,
or, if this is an intersection with a primary street, you can start
a timer and start the switch back. I hope this makes sense and
helps you.
Chris Savage
Knight Designs
green, yellow, red... I am then wanting the routine to be interrupted when the
sensor in the road is driven over, this will changes the state of the lights to
stop east and west bound traffic if a sensor for north or south bound traffic is
triggered. Then I am wanting the photo sensors to override everything when it
is dark so that only the red lights will blink on and off, while the street
lamps are on ( like when it gets dark). I don't know if this is a clear enough
explanation, but I hope maybe it will help. By the way thanks!
QED! It's just a simple state machine. You didn't mention if you had turn
lanes (or how many lanes in each direction). Here's some pseudo code:
# for safety
set all lights off
set all red lights on
FlashLoop:
delay flash_on_time
set all lights off
delay flash_off_time
set all red lights on
if nite switch goto FlashLoop
NorthSouth:
set NS lights green
delay minimum_traffic_time
if not EW switches delay max_traffic_time
set NS lights yellow
delay slow_time
set NS lights red
If nite switch goto FlashLoop
EastWest:
set EW lights green
delay minimum_traffic_time
if not NS switches delay max_traffic_time
set EW lights yellow
delay slow_time
set EW lights red
If nite switch goto FlashLoop
goto NorthSouth
--
Enjoy,
George Warner,
Schizophrenic Optimization Scientists
Apple Developer Technical Support (DTS)
Here is what I did for a digital electronics course in
undergrad school. We were using a 68HC11
microcontroller and they wanted us to use some other
method of doing this. But my partner and I came up
with this simple and elegant method. The TA thought
we were weird for using this method...smile.
Essentially, it is a sequencer. I "borrowed" the idea
of sequencers from the PLC (programmable logic
controller) world. Most PLC's have sequencers built
into the software. Anyway, I wrote this program for
the Basic Stamp II more for my own experience. It
took about 10 minutes to program and wire up.
'***************************************************
'* This program simulates two-way traffic light *
'* system. *
'* N/S E/W *
'* RYG RYG *
'* ========== *
'* 001 100 10 sec. *
'* 010 100 5 sec *
'* 100 001 10 sec. *
'* 100 010 5 sec. *
'* This sequence continues until a malfunction *
'* occurs in the system, then *
'* the red lights flash every second until the *
'* malfunction is fixed. *
'* The lights are connected to pins 5 through 10. *
'* The 'malfunction' is controlled through *
'* pin 11. If the pin is high there is a *
'* malfunction *
'* and when the pin is low there is normal *
'* operation. *
dirs = %00111111
Normal: if in6 = 1 then Flash
outl= %001100
pause 10000
outl= %010100
pause 5000
if in6 = 1 then Flash
outl= %100001
pause 10000
outl= %100010
pause 5000
if in6 = 1 then Flash
goto Normal
Flash: outl= %100100
if in6 = 0 then Normal
pause 1000
goto Flash
Hope this helps. Have fun with this project, it is a
good project to learn teh stamp with.
Have a great day!!
James E. Merritt
--- Mima Ciani <m_cstar@y...> wrote:
> I am wanting the traffic signals to function in a
> normal routine ex: red, green, yellow, red... I am
> then wanting the routine to be interrupted when the
> sensor in the road is driven over, this will changes
> the state of the lights to stop east and west bound
> traffic if a sensor for north or south bound traffic
> is triggered. Then I am wanting the photo sensors
> to override everything when it is dark so that only
> the red lights will blink on and off, while the
> street lamps are on ( like when it gets dark). I
> don't know if this is a clear enough explanation,
> but I hope maybe it will help. By the way thanks!
>
__________________________________
Do you Yahoo!?
Friends. Fun. Try the all-new Yahoo! Messenger.
http://messenger.yahoo.com/
wrote:
> Thanks for bringing some sanity to this discussion, Chris. If the
> project didn't require light/dark sensors it could easily be
handled
> with a BS1.
> -- Jon Williams
> -- Applications Engineer, Parallax
> -- Dallas Office
Thanks Jon, and you brought up something I FORGOT to mention, but
that again, could easily be handled. All you have to do (The person
that needed the info) is when you sense a vehicle at the
intersection, you quickly branch off (Or GOSUB to) a subroutine to
check the light/dark sensors. I did forget to mention that in my
description, but somewhere around here is a book from college with a
circuit using pure discrete logic chips to do it without the
light/dark sensors. Which means if you're running this with a BS2,
or even a BS1 (Using a 74HC595) you're all set.
I think a BS1 could do it, if you used the 74HC595 in a standard
intersection, since the lights on one street will usually be the
same on both sides of the light, you only need 3 lines for each
street. That's 6 outputs for LEDs, using 3 lines from the BS1 that
leaves 5. Pair up sensor inputs for each side of the intesection on
the same street and you could do it! It'd be pushing it, but I
think it could be done. And it would simplify the code. Anyway, if
the person who needed the information needs more, I will try to
diagram this and upload it.
Chris Savage
Knight Designs
> sensors in the road (These are usually metal detectors using coils)
> to detect a vehicle at the Red light. At this point many systems
> will check the opposite intersection for traffic (By monitoring the
> sensors) and start a countdown of around 10 seconds or so,
depending
> on the type of intersection.
My question is how they can tell when my car approaches ? It seems
that the light will be green for some time and just as I approach, it
will turn yellow.
Some type of aritficial intelegence sensor trying to get back at me
for taking apart all those electroncis gizmo's over the years I bet.
Dave
'{$STAMP BS2}
x var word
a var bit
b var bit
c var bit
f var bit
output 5
'traffic lights
Tlights:
f=0
f=in9
debug ? f
High 15 'ns red on
High 3 'ew greem on
pause 6000
Low 3 'ew green off
if f=1 then flashloop
High 2 'ew yellow on
pause 3000
Low 2 'ew yellow off
Low 15 'ns red off
if f=1 then flashloop
High 4 'ew red on
High 14 'ns green on
pause 6000
Low 14 'nw green off
if f=1 then flashloop
High 13 'ns yellow on
pause 3000
Low 13 'ns yellow off
Low 4 'ew red off
if f=1 then flashloop
if f=0 then Tlights
flashloop:
for x= 1 to 1000
high 5
pause 1000
low 4
low 15
pause 500
high 15
high 4
If f=0 then Tlights
If f=1 then flashloop
goto Tlights
Dave Mucha <davemucha@j...> wrote:
> If you're monitoring an intersection, normally you would have 4
> sensors in the road (These are usually metal detectors using coils)
> to detect a vehicle at the Red light. At this point many systems
> will check the opposite intersection for traffic (By monitoring the
> sensors) and start a countdown of around 10 seconds or so,
depending
> on the type of intersection.
My question is how they can tell when my car approaches ? It seems
that the light will be green for some time and just as I approach, it
will turn yellow.
Some type of aritficial intelegence sensor trying to get back at me
for taking apart all those electroncis gizmo's over the years I bet.
Dave
To UNSUBSCRIBE, just send mail to:
basicstamps-unsubscribe@yahoogroups.com
from the same email address that you subscribed. Text in the Subject and Body of the message will be ignored.
Yahoo! Groups Links
Do you Yahoo!?
Friends. Fun. Try the all-new Yahoo! Messenger
[noparse][[/noparse]Non-text portions of this message have been removed]
If f=1 then flashloop
f=in9
debug ? f
goto Tlights
wrote:
> My question is how they can tell when my car approaches ? It seems
> that the light will be green for some time and just as I approach,
it
> will turn yellow.
>
> Some type of aritficial intelegence sensor trying to get back at
me
> for taking apart all those electroncis gizmo's over the years I
bet.
> Dave
Good one Dave... Seriously though, I know how you feel, and
from the OPPOSITE point of view, I ride a Motorcycle, and MOST
lights WON'T change for me! I have to sit there until a car pulls
up behind me so that the light can sense it.
Once, I tried turning right on red after sitting at a light for 10
minutes. Then I went through a Bar parking lot on the left, and out
it's rear entrance to get down the road I was heading home on (At
2:00AM after work). A cop pulled me over and tried to give me a
ticket for "avoiding an traffic device" or something like that.
Fortunately I knew one of his fellow deputies and he let me go.
Yes, traffic lights need better technology...But not necessarily
computer control (Ever seen the movie? ;-) ).
Chris Savage
Knight Designs