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

Allow multiple compatible reservation #114

Open
gfgit opened this issue Apr 19, 2024 · 8 comments
Open

Allow multiple compatible reservation #114

gfgit opened this issue Apr 19, 2024 · 8 comments
Labels
bug Something isn't working

Comments

@gfgit
Copy link
Contributor

gfgit commented Apr 19, 2024

Describe the bug
Some path reservation are compatible to each other, meaning they both can be active at same time.
But they could share some tiles like a bridge which can allow both trains to pass above and below, as opposed to a crossing which allows only one train at a time (and so only one reserved path).

So for bridges we to allow multiple reservations otherwise when releasing first path, the bridge will look as released (reserve state is zero) but the other path reservation is still active.
I suggest a system similar to reference-counting. When it's zero the object is free (es. a turnout can be switched) otherwise if reference count is greater than zero the object is locked (es turnout locked in reserved position).

Future expansion
In the future this could be expanded to allow moving turnouts not directly traveled by train in path but needed to ensure no other train would collide with it.

Screenshot_20240419_155607

At least for Italian railways the situation in the picture above would be wrong.
The upper turnout which currently is in "Left" position should be in "Right" position (straight).
This ensures that if a train accidentally departs from "block_13" it will not collide with our train entering (or exiting) the station trough the reserved path.
Instead a train coming from "block_13" would go to the dead track ("block_16" in this case).

EDIT: to be precise, in Italy the 2 turnouts would have been switched by the same command together so the picture above is an impossible situation. But there are other cases where "independence" of 2 paths is achieved by additionally moving other turnouts to dead tracks.

@gfgit gfgit added the bug Something isn't working label Apr 19, 2024
@gfgit
Copy link
Contributor Author

gfgit commented Apr 19, 2024

Currently I've implemented:

  • Cancelling a reserved path by pressing on same NX buttons which were used to reserve it. (Currently works but bypasses some checks which need to be reworked)
  • Prevent 2 paths to reserve same turnout for different positions (this was a bug in reserve() method).
  • Locking turnout position if it's in a reserved path.
  • React to turnout external changes and revert them if in reserved path.

@reinder
Copy link
Member

reinder commented Apr 19, 2024

Bridge reservation currently works with a bit mask, both paths have their own bit, see: https://github.com/traintastic/traintastic/blob/master/server/src/board/tile/rail/bridgerailtile.cpp

Regarding the "Italian" way of turnout control, easiest would be to just use the same address for both turnouts. (Or somehow link them if the both have a different address,) Then the user can easily decide how they want it to work.

Other option could be to do it automagically based on the used signaling system.

@gfgit
Copy link
Contributor Author

gfgit commented Apr 19, 2024

Bridge reservation currently works with a bit mask, both paths have their own bit

Hm, it didn't work when I've tested it. I'll test again later

@reinder
Copy link
Member

reinder commented Apr 19, 2024

We should add some tests to check that, also the other things you mentioned for turnout control while it is reserved.

@reinder
Copy link
Member

reinder commented Apr 21, 2024

I've added a test to check if two paths can be reserved on a bridge, see af41429

@gfgit
Copy link
Contributor Author

gfgit commented Apr 22, 2024

I've added a test to check if two paths can be reserved on a bridge, see af41429

It was working indeed, I had confused the colors. This commit is a good example to learn how to cover coded with tests. Thanks!

@reinder
Copy link
Member

reinder commented Apr 22, 2024

The tests really help, apart from the hardware most Traintastic code can be tested. Makes it much easier to do changes later. When adding this test I also discovered that the BlockTrainStatus object weren't freed properly causing much more objects to stay alive while the world was deleted. That's why there are many REQUIRE(xxx.expired()); at the end of each test.

@reinder
Copy link
Member

reinder commented May 24, 2024

@gfgit we can close this one I think, as the bridge reservation works as expected right?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants