Skip to content

Commit 3666a3a

Browse files
Merge pull request #21 from simulate-digital-rail/optional-flank-protection
Optional flank protection
2 parents d61eda7 + 2444e5f commit 3666a3a

File tree

4 files changed

+85
-87
lines changed

4 files changed

+85
-87
lines changed

interlocking/interlockingcontroller/pointcontroller.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,16 @@ def __init__(self, signal_controller: SignalController, infrastructure_providers
1414
self.points: dict[str, Point] = {}
1515
self.infrastructure_providers = infrastructure_providers
1616
self.settings = settings
17-
self.flank_protection_controller = FlankProtectionController(self, signal_controller)
17+
if self.settings.activate_flank_protection is True:
18+
self.flank_protection_controller = FlankProtectionController(self, signal_controller)
1819

1920
def reset(self):
2021
for point_id in self.points:
2122
self.points[point_id].orientation = "undefined"
2223
self.points[point_id].state = OccupancyState.FREE
2324
self.points[point_id].used_by = set()
24-
self.flank_protection_controller.reset()
25+
if self.settings.activate_flank_protection is True:
26+
self.flank_protection_controller.reset()
2527

2628
async def set_route(self, route, train_id: str):
2729
tasks = []
@@ -34,7 +36,8 @@ async def set_route(self, route, train_id: str):
3436
if orientation == "left" or orientation == "right":
3537
self.set_point_reserved(point, train_id)
3638
tasks.append(tg.create_task(self.turn_point(point, orientation)))
37-
tasks.append(tg.create_task(self.flank_protection_controller.add_flank_protection_for_point(point, orientation, route, train_id)))
39+
if self.settings.activate_flank_protection is True:
40+
tasks.append(tg.create_task(self.flank_protection_controller.add_flank_protection_for_point(point, orientation, route, train_id)))
3841
else:
3942
raise ValueError("Turn should happen but is not possible")
4043

@@ -89,7 +92,9 @@ def set_point_free(self, point, train_id: str):
8992
logging.info(f"--- Set point {point.point_id} to free")
9093
point.state = OccupancyState.FREE
9194
point.used_by.remove(train_id)
92-
self.flank_protection_controller.free_flank_protection_of_point(point, point.orientation)
95+
96+
if self.settings.activate_flank_protection is True:
97+
self.flank_protection_controller.free_flank_protection_of_point(point, point.orientation)
9398

9499
def reset_route(self, route, train_id: str):
95100
for point in route.get_points_of_route():

interlocking/model/helper/settings.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,12 @@ class Settings(object):
66

77
def __init__(self,
88
max_number_of_points_at_same_time: int = 5,
9-
default_interlocking_provider: Type[InfrastructureProvider] | None = LoggingInfrastructureProvider):
9+
default_interlocking_provider: Type[InfrastructureProvider] | None = LoggingInfrastructureProvider,
10+
activate_flank_protection: bool = True):
1011
self.max_number_of_points_at_same_time = max(max_number_of_points_at_same_time, 1)
1112

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

0 commit comments

Comments
 (0)