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

Optional flank protection #21

Merged
merged 2 commits into from
Oct 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions interlocking/interlockingcontroller/pointcontroller.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,16 @@ def __init__(self, signal_controller: SignalController, infrastructure_providers
self.points: dict[str, Point] = {}
self.infrastructure_providers = infrastructure_providers
self.settings = settings
self.flank_protection_controller = FlankProtectionController(self, signal_controller)
if self.settings.activate_flank_protection is True:
self.flank_protection_controller = FlankProtectionController(self, signal_controller)

def reset(self):
for point_id in self.points:
self.points[point_id].orientation = "undefined"
self.points[point_id].state = OccupancyState.FREE
self.points[point_id].used_by = set()
self.flank_protection_controller.reset()
if self.settings.activate_flank_protection is True:
self.flank_protection_controller.reset()

async def set_route(self, route, train_id: str):
tasks = []
Expand All @@ -34,7 +36,8 @@ async def set_route(self, route, train_id: str):
if orientation == "left" or orientation == "right":
self.set_point_reserved(point, train_id)
tasks.append(tg.create_task(self.turn_point(point, orientation)))
tasks.append(tg.create_task(self.flank_protection_controller.add_flank_protection_for_point(point, orientation, route, train_id)))
if self.settings.activate_flank_protection is True:
tasks.append(tg.create_task(self.flank_protection_controller.add_flank_protection_for_point(point, orientation, route, train_id)))
else:
raise ValueError("Turn should happen but is not possible")

Expand Down Expand Up @@ -89,7 +92,9 @@ def set_point_free(self, point, train_id: str):
logging.info(f"--- Set point {point.point_id} to free")
point.state = OccupancyState.FREE
point.used_by.remove(train_id)
self.flank_protection_controller.free_flank_protection_of_point(point, point.orientation)

if self.settings.activate_flank_protection is True:
self.flank_protection_controller.free_flank_protection_of_point(point, point.orientation)

def reset_route(self, route, train_id: str):
for point in route.get_points_of_route():
Expand Down
5 changes: 4 additions & 1 deletion interlocking/model/helper/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,12 @@ class Settings(object):

def __init__(self,
max_number_of_points_at_same_time: int = 5,
default_interlocking_provider: Type[InfrastructureProvider] | None = LoggingInfrastructureProvider):
default_interlocking_provider: Type[InfrastructureProvider] | None = LoggingInfrastructureProvider,
activate_flank_protection: bool = True):
self.max_number_of_points_at_same_time = max(max_number_of_points_at_same_time, 1)

# For all elements that are not covered by an infrastructure provider, an instance of this default provider will
# be created. This default provider can be None.
self.default_interlocking_provider: Type[InfrastructureProvider] | None = default_interlocking_provider

self.activate_flank_protection: bool = activate_flank_protection
Loading
Loading