Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add automatic timed traffic lights #540

Closed
kianzarrin opened this issue Nov 1, 2019 · 24 comments · Fixed by #554
Closed

add automatic timed traffic lights #540

kianzarrin opened this issue Nov 1, 2019 · 24 comments · Fixed by #554
Assignees
Labels
discussion Contains debate on certain topics feature A new distinct feature TRAFFIC LIGHTS Feature: Traffic lights - toggle, timed, etc Usability Make mod easier to use

Comments

@kianzarrin
Copy link
Collaborator

people spend a tone of time to add timed traffic lights. i suggest to add a default time traffic lights which allows one road to go through at a time and automatically modifies the turning lanes all with one click would be a massive help.

@kianzarrin kianzarrin added feature A new distinct feature triage Awaiting issue categorisation labels Nov 1, 2019
@kianzarrin
Copy link
Collaborator Author

please assign to me.

@krzychu124 krzychu124 added discussion Contains debate on certain topics TRAFFIC LIGHTS Feature: Traffic lights - toggle, timed, etc Usability Make mod easier to use and removed triage Awaiting issue categorisation labels Nov 1, 2019
@originalfoo
Copy link
Member

If possible:

  • Make it work with left hand traffic, not just right hand traffic
  • Factor in things like priority signs and junction restrictions
  • Handle things like lane connectors and lane arrows

@kianzarrin
Copy link
Collaborator Author

@aubergine10

Make it work with left hand traffic, not just right hand traffic

of course!

Factor in things like priority signs and junction restrictions

there are no priority signs when there is traffic lights. so nothing to do here. U turns are same as left turns.

Handle things like lane connectors and lane arrows.

lane arrows will be separated using code from #537 . Lane connectors are too complicated for what I had originally in mind. I just wanted something simple and effective. people always can make further modifications. If you have something cool in mind though I am totally up for it! adding lane connectors all over is going to create a big mess. furthermore if the next junction is too close we should avoid lane connections and let cars choose their lane.

Taking the amount of traffic on each lane into account might also be a good Idea but it may prove to be too difficult. I will see what I can do.

@originalfoo
Copy link
Member

there are no priority signs when there is traffic lights. so nothing to do here. U turns are same as left turns.

TMPE has existing option to factor in the TMPE priority signs at traffic lights: Vehicles follow priority rules at junctions with timed traffic lights on Policies tab in mod options.

For example, priority signs could tell the default traffic light config which 'route' gets prioritised at the junction, The order of priority would be:

  1. Priority sign = highest priority
  2. Yield sign = medium priority
  3. Stop sign = lowest priority

If no priority signs are checked, road UI category (or number of lanes or speed?) could be used to determine prioritisation of routes entering the junction?

I just wanted something simple and effective

Agreed. We can add extra features later (including the stuff about prioritisation I mentioned above).

@kianzarrin
Copy link
Collaborator Author

kianzarrin commented Nov 10, 2019

Made some progress with time traffic light. At least I learnt how to use the damn thing (while coding of course)!
Ctrl+click creates a default (recommended by none other than me!) timed traffic light. see pictures bellow:
Screenshot (28)
Screenshot (29)
There are two more steps of course

@kianzarrin
Copy link
Collaborator Author

kianzarrin commented Nov 10, 2019

if would be a good idea to create automatic timed traffic lights for multi nodes like a green wave #278 or something. but not in this issue.

Now I need to handle cases where its 3 segments or 5 or more segments. they all use the same concept though. one side can go at a time, the road to its right can only turn right. also there are one way roads I need to consider.

Ideas are welcome!

@kianzarrin
Copy link
Collaborator Author

And I WILL remember to separate turning lanes as necessary by the timed traffic lights. its a good thing I have a code for that already!

@kianzarrin
Copy link
Collaborator Author

It is not a good idea to have a mode that bans left turns. for that simple traffic light would do just fine.

@brunoais
Copy link

I think that default you made is quite sensible and provides a good start.
The only other default I'd like to have is with the addition of banned left turns. Like this:
If there's two roads "in front" of each other (with sensible margin of error) where both have left turning banned, then use a template that provides green light forward for those at the same time instead of one at a time.
Is that doable for this PR? Does it need a different PR (due to complexity)?

Also,
@kianzarrin With such little amount of time between messages, please just edit the previous one.... I get an e-mail for each message you send.

@kianzarrin
Copy link
Collaborator Author

@brunoais

The only other default I'd like to have is with the addition of banned left turns

As I said before:

It is not a good idea to have a mode that bans left turns. for that simple traffic light would do just fine.

so yeah timer traffic light is unnecessary when left turns are banned. Just use a default one.

@brunoais
Copy link

brunoais commented Nov 10, 2019

Alright. Fair enough. I still think that when two have banned left turns and, for example, there's 2 more without banned left turns, this could still be useful... Specially because of pedestrians.
Maybe later on, users can make their own list of defaults by template...

@kianzarrin
Copy link
Collaborator Author

kianzarrin commented Nov 10, 2019

I also was thinking of the template thing :)
I can even provide some default templates.

If there is only two segments that ban left turns I recommend:
1- to use the auto timed traffic light to set things up and then make simple modifications.

2- use templates. The built-in ones can even modify lane arrows.

3- ban left turns then use the default timed traffic lights. I can add a feature to read lane arrows and use them as guideline for creating timed traffic lights.

I don't recommend this:
Add a complex state machine that confuses people. Keep in mind there are some other possibilities to like dedicated short step for turning left.

Edit: I'd like to do the advanced features in a separate review.

@brunoais
Copy link

brunoais commented Nov 10, 2019

I like these two:

The built-in ones can even modify lane arrows.

I can add a feature to read lane arrows and use them as guideline for creating timed traffic lights.

As for:

Edit: I'd like to do the advanced features in a separate review.

Sure thing! Get this sorted out and I will be waiting for the followup PR \o/

@kianzarrin
Copy link
Collaborator Author

What should I do about one way roads. So far I do this:
Screenshot (35)
two options:
1- two roads can turn into the same one way road in one traffic cycle as in the picture above.
2- write extra code to make sure only one road turns into it at any given traffic light cycle.

@kvakvs
Copy link
Collaborator

kvakvs commented Nov 11, 2019

@kianzarrin Don't invest too much work into making the UI pretty, the UI will be reviewed and reworked, possibly already this year. Make the simplest UI changes as much as possible.

@kianzarrin
Copy link
Collaborator Author

@kvakvs

@kianzarrin Don't invest too much work into making the UI pretty, the UI will be reviewed and reworked, possibly already this year. Make the simplest UI changes as much as possible.

I am not touching the UI at all.


I am almost done with this. In debug mode its a bit slow. but even in release mode and in extreme cases it can take a moment(half a second) to insert the custom traffic lights.

I did some tests to determine what is slowing it down: my code or the interface. So I disabled most of my code (so that it just puts traffic lights without calculations) and felt no improvement in speed. So the interface is to blame.

@kianzarrin
Copy link
Collaborator Author

Feature ideas:
Service vehicles get to go first.
store timed traffic lights. (that requires some changes to the option page.

@kianzarrin
Copy link
Collaborator Author

kianzarrin commented Nov 26, 2019

Wiki documentation:

Quick setup

Are you not interested in spending ages to setup a timed traffic light? Do you hate traffic jams? Then don't worry ... you CAN have it both ways! Just press CTRL-click on a junction and TMPE creates a basic timed traffic light on that junction for you:

  • It automatically allocates dedicated turning lanes where possible.
  • at each step it gives a green light to one entry(to go to all directions). so the total number of steps equals the number of entries to the junction (Except when there are one-way roads).
  • It allows the entry to the left to turn right only (where possible).
  • The traffic light rotates clockwise at each step.
  • one way roads are taken into consideration.
  • for the time being the quick setup only works on one junction at a time. In future we may consider the idea of green wave

Screenshot (84)
T junction has 3 steps. One road gets a green light to all directions at each step while another road will be able to go straight or turn right.


quick-setup-4way
4 road junction has 4 steps. one road gets a green light to all directions at each step while the road to its left can turn right only.


quick-setup-3way-2steps
In this T junction because there is a one-way road, it was possible to make it 2 steps.

@originalfoo
Copy link
Member

Thanks for the docs :) Few questions:

Just press CTRL-click on a junction and TMPE creates a basic timed traffic light on that junction for you

I assume they need the timed traffic lights tool active for that to happen?

It allows the road to the left to turn right only (where possible).

Please elaborate. Are you referring to the left segment of the main road? And if so, does that only apply at t-junctions? Or is it something else?

@kianzarrin
Copy link
Collaborator Author

@aubergine10

I assume they need the timed traffic lights tool active for that to happen?

Isn't that implied since this is going to be in the page for timed traffic light tool?

Please elaborate. Are you referring to the left segment of the main road?

I replaced 'road' with 'entry to the junction' to avoid confusion. I didn't use the term segment because I think its to low level (computer level) of a concept which should be hidden from user. If you think I should use segment instead please tell me. Entry though might be more accurate since segments without entries to the junction do not get a traffic light

does that only apply at t-junctions? Or is it something else?

In the example pictures I have demonstrated how it works both for cross junction and T junction

The real logic is:
at each turn One entry (to the junction) gets all green light (green light to all directions) while the road whose turn is the next turn (in a clock wise direction) will only get to turn toward the right-most direction (that means turn right if there is a segment to the right, otherwise for example in a T junction go straight).

Unfortunately I did not mange to find a way to explain this in plain language to the user so I decided to show it in the pictures.

@originalfoo
Copy link
Member

originalfoo commented Nov 27, 2019

Isn't that implied since this is going to be in the page for timed traffic light tool?

Not when there's three different tools with a traffic light icon on the TM:PE menu bar. ;) It needs stating explicitly (from docs perspective). In the UI a contextual mention can be made in the button tool tip and/or the adviser text that appears when button is first clicked.

I didn't use the term segment because I think its to low level (computer level) of a concept which should be hidden from user.

Generally, I would agree, however in C:SL community it does seem that segment is a widely understood term. While it's a mid-level term, which is also used at low-level (code), remember that users build their roads segment by segment so they are already familiar with concepts such as nodes and segments.

I think where it becomes too low-level is when we have to start differentiating between different kinds of segments and, in particular, nodes. But even there we will still have to expose users to some of the more advanced terminology to comprehend functionality where necessary. To that end, I've been chipping away at a glossary of terms for nodes, segments, lanes.

Unfortunately I did not mange to find a way to explain this in plain language to the user so I decided to show it in the pictures.

Pictures are always the best choice so keep doing that 👍

Note: There aren't many images in the github wiki due to a long-standing bug with GitHub Desktop (which I just checked and is still there). I was waiting to see if they fixed it, as storing images in the wiki would be ideal (it's separate to the main code repo), and I wanted to ensure that if we started doing that users with limited knowledge of github, thus github desktop users, would be able to work with it. Sadly, bug still not fixed. Maybe we need to use imgur or have a central issue where we can dump images in the interim?

@Sipke82
Copy link

Sipke82 commented Nov 27, 2019

This is awesome!!
Shouldn't this be "default" traffic light behavior?

Would close #5 i think.

@originalfoo
Copy link
Member

I suspect this would cover a lot (if not all?) of what is in #324 as well.

Regarding making it default: Currently this is using TM:PE timed traffic lights, which are heavier than vanilla in terms of computations required. If it works well in practice, we could maybe look at hard-coding a sequence somehow so that it would be fast enough to use by default.

@Sipke82
Copy link

Sipke82 commented Nov 27, 2019

Im wondering, if i change lane connectors or lane arrows after this, will it automatically adjust? And how about segment upgrading to another type of road?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
discussion Contains debate on certain topics feature A new distinct feature TRAFFIC LIGHTS Feature: Traffic lights - toggle, timed, etc Usability Make mod easier to use
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants