question

Edgar A avatar image
0 Likes"
Edgar A asked Phil BoBo commented

How can I create a traffic light logic?

I'm trying to make a simple traffic intersection control by traffic litght. But I dont know how to control the times. I think it will be necessary use Time Table, im trying but not successful.

FlexSim 16.1.2
traffic light
· 4
5 |100000

Up to 12 attachments (including images) can be used with a maximum of 23.8 MiB each and 47.7 MiB total.

Jeff Nordgren avatar image Jeff Nordgren commented ·
@Edgar A

I notice that your FlexSim license expired over 2 years ago. The first thing you should do is contact your local distributor in Brazil and get the latest version of FlexSim. Although we try and support all versions of FlexSim, it is not practical to try and do something in an older version that may be easier in the latest version of FlexSim. But if you have created a model that we can look at, that would make it easier for us.

Have you tried closing and opening node edges to stop traffic? You could use a User Event, that is timed, to send a message to an object and open/close the appropriate node edges.

0 Likes 0 ·
Edgar A avatar image Edgar A Jeff Nordgren commented ·

Thanks a lot for answer. I've try every mode close and open nodes. I'm working now with a extra processor than utilize global variables to use with time process.

I'm using 3 variables: 1º time, 2º time and Flag (to sinalizate wich open). It's work, but too complicate to see that.

Thanks..

0 Likes 0 ·
sem-titulo.png (74.1 KiB)
Jeff Nordgren avatar image Jeff Nordgren Edgar A commented ·
@Edgar A

Not sure what you mean by it being "too complicated to see that"?

0 Likes 0 ·
Show more comments

1 Answer

·
Phil BoBo avatar image
3 Likes"
Phil BoBo answered Phil BoBo commented

You can customize the Traffic Control object's logic by writing code in its OnEntryRequest trigger and using the trafficcontrolinfo() command:

Thus, you could write custom logic that keeps track of which lanes are open on labels and change those values based on time like a traffic light.


· 3
5 |100000

Up to 12 attachments (including images) can be used with a maximum of 23.8 MiB each and 47.7 MiB total.

Edgar A avatar image Edgar A commented ·

It works.. I'll learn more about traffic controll. Thanks!!

0 Likes 0 ·
Andrew J3 avatar image Andrew J3 commented ·

@phil.bobo would it be possible for you to provide an example or example code related to the above commands. For example, a 3 lane roadway whose light would turn red every 10 minutes and stay red for 40 seconds. Thanks in advance, Drew.

0 Likes 0 ·
rumlx.png (67.6 KiB)
Phil BoBo avatar image Phil BoBo ♦♦ Andrew J3 commented ·

custom-traffic-control.fsm

The attached model shows you how to do this. You can set the labels timeRed and timeGreen on the traffic control to control how long it is red vs green.

The On Reset and On Message triggers control whether the state label is 1 or 0 (red or green).

The On Entry Request trigger checks the state label and returns TC_ON_ENTRY_REQUEST_QUEUE if the light is red and TC_ON_ENTRY_REQUEST_ALLOW if the light is green.

In the On Message, when the light turns green, it calls the following code to release any requests that are currently pending:

int numWaiting = trafficcontrolinfo(current, TCI_NR_ENTRY_REQUESTS);
for (int i = numWaiting; i >= 1; i--) {
	trafficcontrolinfo(current, TCI_ALLOW_ENTRY, i);
}
0 Likes 0 ·

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 12 attachments (including images) can be used with a maximum of 23.8 MiB each and 47.7 MiB total.