1# pyright: reportUnusedImport=information, reportInvalidStringEscapeSequence=false
2"""
3In this module defines enums and constants that are used throughout the project.
4
5.. Comment "#: :meta hide-value:" hides the value in the documentation.
6"""
7
8import operator
9import os
10from enum import Enum, Flag, IntEnum, auto
11from functools import lru_cache, reduce
12from typing import TYPE_CHECKING, ClassVar, Dict, Union
13
14import carla
15from typing_extensions import Self, TypeAlias
16
17AD_RSS_AVAILABLE: bool
18"""
19Indicator if the :py:mod:`carla.ad` module is available, i.e. if the current carla version was build
20with RSS support. As a rule of thumb: On Windows this will be always false.
21If this is false some objects will be missing in the :py:mod:`carla` module, for example
22the :py:class:`carla.RssSensor`, likewise are some utilities of this project involving RSS not be
23available.
24
25See Also:
26 - https://carla.readthedocs.io/en/latest/adv_rss/
27 - https://github.com/intel/ad-rss-lib
28
29:meta hide-value:
30"""
31try:
32 from carla import ad # pyright: ignore # noqa
33
34 AD_RSS_AVAILABLE = True
35except ImportError:
36 AD_RSS_AVAILABLE = False # pyright: ignore[reportConstantRedefinition]
37
38
39READTHEDOCS = os.environ.get("READTHEDOCS", False)
40"""
41Whether the code is currently used to build the docs:
42
43Values:
44 - False: Normal Runtime
45 - 'local' : Local build
46 - other: ReadTheDocs build
47
48:meta hide-value:
49:meta private:
50"""
51
52
[docs]
53class AgentState(Flag):
54 """
55 High-level states that the agent currently can be in.
56
57 Used with :py:attr:`.LunaticAgent.current_states`
58 and :py:attr:`.InformationManager.state_counter`.
59 """
60
61 DRIVING = auto() #: :meta hide-value:
62 STOPPED = auto() #: :meta hide-value:
63 _parked = auto() # hidden it to avoid confusion, used further down for PARKED
64
65 BLOCKED_BY_VEHICLE = auto() #: :meta hide-value:
66 BLOCKED_RED_LIGHT = auto() #: :meta hide-value:
67 BLOCKED_BY_STATIC = auto()
68 """
69 Static obstacle.
70
71 Attention:
72 Not updated by the information manager
73 but in the :py:attr:`Phase.DETECT_STATIC_OBSTACLES` phase.
74
75 :meta hide-value:
76 """
77
78 BLOCKED_OTHER = auto() #: :meta hide-value:
79
80 REVERSE = auto() #: :meta hide-value:
81
82 OVERTAKING = auto() #: :meta hide-value:
83
84 AGAINST_LANE_DIRECTION = auto() #: :meta hide-value:
85
86 PARKED = _parked | STOPPED # we want this to be a combination of the two
87 """Includes :py:attr:`STOPPED`"""
88
89 BLOCKED = BLOCKED_OTHER | BLOCKED_BY_VEHICLE | BLOCKED_RED_LIGHT | BLOCKED_BY_STATIC
90 """
91 Combination of :python:`BLOCKED_OTHER | BLOCKED_BY_VEHICLE | BLOCKED_RED_LIGHT | BLOCKED_BY_STATIC`
92
93 :meta hide-value:
94 """
95
96 # Maybe more states like CAR_IN_FRONT <- detection matrix
97
98
[docs]
99class RulePriority(IntEnum):
100 """
101 Priority of a :py:class:`Rule <classes.rule.Rule>`.
102 The higher a value, the higher the priority.
103 Rules are sorted by their priority before being applied.
104 """
105
106 NULL = 0
107 LOWEST = 1
108 LOW = 2
109 NORMAL = 4
110 HIGH = 8
111 HIGHEST = 16
112
113
[docs]
114class Phase(Flag):
115 """
116 A rough order of the looped through states of the agent is:
117
118 .. code-block:: python
119
120 <Phases.NONE: 0>,
121 <Phases.UPDATE_INFORMATION|BEGIN: 5>,
122 <Phases.UPDATE_INFORMATION|END: 6>,
123 <Phases.PLAN_PATH|BEGIN: 9>,
124 <Phases.PLAN_PATH|END: 10>,
125 <Phases.DETECT_TRAFFIC_LIGHTS|BEGIN: 17>,
126 <Phases.DETECT_TRAFFIC_LIGHTS|END: 18>,
127 <Phases.DETECT_PEDESTRIANS|BEGIN: 33>,
128 <Phases.DETECT_PEDESTRIANS|END: 34>,
129 <Phases.DETECT_CARS|BEGIN: 65>,
130 <Phases.DETECT_CARS|END: 66>,
131 <Phases.POST_DETECTION_PHASE|BEGIN: 129>,
132 <Phases.POST_DETECTION_PHASE|END: 130>,
133 <Phases.EXECUTION|BEGIN: 1025>,
134 <Phases.EXECUTION|END: 1026>
135
136 Note:
137 The above cycle list is not up to date.
138
139 A complete list of all the main phases can be obtained by calling
140 - :py:func:`Phase.get_main_phases`
141 - :py:func:`Phase.get_phases`
142 """
143
144 # NOTE: # CRITICAL : Alias creation should be done >after< all the phases are created.
145 # see https://github.com/python/cpython/issues/91456
146 # Before python version (3.12+?) auto() DOES NOT WORK AS EXPECTED when using ALIASES
147
148 NONE = 0
149
150 # These can be combined with any of the other Phases
151 BEGIN = auto()
152 """
153 Indicates the beginning of a phase. Should always
154 be combined with another phase.
155
156 :meta hide-value:
157 """
158
159 END = auto()
160 """
161 Indicates the end of a phase. Should always
162 be combined with another phase.
163
164 :meta hide-value:
165 """
166
167 UPDATE_INFORMATION = auto()
168 """
169 Indicates the execution of the agents
170 :py:meth:`~.LunaticAgent.update_information` method
171
172 This is the first Phase of the agent and executed every
173 step.
174
175 :meta hide-value:
176 """
177
178 PLAN_PATH = auto()
179 """
180 Indicates that the planning of a new path has started.
181
182 Attention:
183 If the the path is replanned a :py:exc:`UpdatedPathException`
184 should be raised.
185
186 :meta hide-value:
187 """
188
189 DETECT_TRAFFIC_LIGHTS = auto()
190 """
191 Executed during the agents :py:meth:`~.LunaticAgent.detect_hazard`
192 method. Can add :py:attr:`.Hazard.TRAFFIC_LIGHT_RED` or
193 :py:attr:`.Hazard.TRAFFIC_LIGHT_YELLOW` to the agents
194 `.LunaticAgent.detected_hazards`:py:attr:.
195
196 :meta hide-value:
197 """
198
199 DETECT_PEDESTRIANS = auto()
200 """
201 Executed during the agents :py:meth:`~.LunaticAgent.detect_hazard`
202 method. Can add :py:attr:`.Hazard.PEDESTRIAN` to the agents
203 `.LunaticAgent.detected_hazards`:py:attr:.
204
205 :meta hide-value:
206 """
207
208 DETECT_STATIC_OBSTACLES = auto()
209 """
210 | Checks for static obstacles in the agents path with
211 | :py:attr:`.detect_obstacles_in_path` (:py:attr:`.LunaticAgent.static_obstacles_nearby`)
212
213 :meta hide-value:
214 """
215 # TODO: exchange LunaticAgent -> InformationManager when documented
216
217 DETECT_CARS = auto()
218 """
219 | Checks for vehicles in the agents path with
220 | :py:attr:`.detect_obstacles_in_path` (:py:attr:`.LunaticAgent.vehicles_nearby`)
221
222 Note:
223 If a car was detected executes :python:`Phase.CAR_DETECTED | BEGIN`,
224 :python:`Phase.DETECT_CARS | BEGIN` is **only** executed if no car was detected.
225
226 :meta hide-value:
227 """
228
229 TAKE_NORMAL_STEP = auto()
230 r"""
231 During this phase the :external-icon-parse:`:py:class:\`carla.VehicleControl\``
232 is calculated by the local planner.
233
234 :meta hide-value:
235 """
236
237 RSS_EVALUATION = auto()
238 """
239
240 See Also:
241 - :py:meth:`agents.lunatic_agent.LunaticAgent.parse_keyboard_input`
242 - :py:meth:`classes.ui.keyboard_controls.RssKeyboardControls.parse_events`
243
244 :meta hide-value:
245 """
246
247 APPLY_MANUAL_CONTROLS = auto()
248 """Applied manually via human user interface.
249
250 :meta hide-value:
251 """
252
253 EXECUTION = auto()
254 """
255 Executed when the control is applied to the agent.
256
257 See Also:
258 :py:meth:`LunaticAgent.apply_control() <agents.lunatic_agent.LunaticAgent.parse_keyboard_input>`
259
260 :meta hide-value:
261 """
262
263 # --- Special situations ---
264 CAR_DETECTED = auto()
265 """
266 The :python:`Phase.CAR_DETECTED | BEGIN` is executed when a car is detected
267 and follows the :python:`Phase.DETECT_CARS | BEGIN` phase. If no car is detected
268 the :python:`Phase.DETECT_CARS | END` phase is executed.
269
270 :meta hide-value:
271 """
272
273 TURNING_AT_JUNCTION = auto()
274 """
275 Indicates that the agent is turning at a junction.
276
277 Warning:
278 This Phase might become obsolete.
279
280 :meta hide-value:
281 """
282
283 HAZARD = auto()
284 """
285 Not implemented. Refer to EMERGENCY | BEGIN
286
287 :meta hide-value:
288 """
289
290 EMERGENCY = auto()
291 """
292 Special Phase
293
294 See Also:
295 - `Emergency Phases`__
296
297 __ docs/Rules.html#emergency-phase
298 """
299
300 COLLISION = auto()
301 r"""
302 Special phase that is executed out-of-order when a
303 :external-icon-parse:`:py:class:\`carla.Sensor\`` detects a collision.
304
305 See Also:
306 - :external-icon-parse:`:py:class:\`carla.CollisionEvent\``
307 - https://carla.readthedocs.io/en/latest/ref_sensors/#collision-detector
308
309 :meta hide-value:
310 """
311
312 DONE = auto()
313 """
314 Indicates that the agent is at the end of its path and
315 :py:meth:`agent.done() <.LunaticAgent.done>` is :python:`True`.
316
317 :meta hide-value:
318 """
319
320 TERMINATING = auto()
321 """
322 Can be called when the agent is terminating. Must be executed by the user.
323
324 :meta hide-value:
325 """
326
327 CUSTOM_CYCLE = auto()
328 """
329 **experimental**
330
331 Can be used to indicate that the phase change is currently handled by the user.
332
333 Warning:
334 :py:meth:`.LunaticAgent.execute_phase` checks for exact match,
335 i.e. a phase :python:`UPDATE_INFORMATION | BEGIN | END`
336 will not be executed in the normal loop.
337
338 See Also:
339 Executed in :py:meth:`BlockingRule.loop_agent <classes.rule.BlockingRule.loop_agent>`
340
341 :meta hide-value:
342 """
343 # States which the agent can be in outside of a normal Phase0-5 loop
344
345 # --- Aliases & Combination Phases ---
346 # NOTE: # CRITICAL : Alias creation should be done after all the phases are created.!!!
347
348 DETECT_NON_CARS = DETECT_STATIC_OBSTACLES | DETECT_TRAFFIC_LIGHTS | DETECT_PEDESTRIANS
349 """
350 Combination of :python:`DETECT_STATIC_OBSTACLES | DETECT_TRAFFIC_LIGHTS | DETECT_PEDESTRIANS`
351
352 :meta hide-value:
353 """
354
355 DETECTION_PHASE = DETECT_NON_CARS | DETECT_CARS
356 """
357 Combination of :python:`DETECT_STATIC_OBSTACLES | DETECT_TRAFFIC_LIGHTS | DETECT_PEDESTRIANS | DETECT_CARS`
358
359 :meta hide-value:
360 """
361
362 EXCEPTIONS = HAZARD | EMERGENCY | COLLISION | TURNING_AT_JUNCTION | CAR_DETECTED | DONE | TERMINATING
363 """
364 Combination of :python:`HAZARD | EMERGENCY | COLLISION | TURNING_AT_JUNCTION | CAR_DETECTED | DONE | TERMINATING`
365
366 :meta hide-value:
367 """
368
369 USER_CONTROLLED = APPLY_MANUAL_CONTROLS | EXECUTION | TERMINATING | CUSTOM_CYCLE
370 """
371 Phases that might or not be went through as they must be implemented manually by the user.
372
373 Combination of :python:`APPLY_MANUAL_CONTROLS | EXECUTION | TERMINATING | CUSTOM_CYCLE`
374
375 :meta hide-value:
376 """
377
378 NORMAL_LOOP = UPDATE_INFORMATION | PLAN_PATH | DETECTION_PHASE | TAKE_NORMAL_STEP
379 """
380 Combination of :python:`UPDATE_INFORMATION | PLAN_PATH | DETECTION_PHASE | TAKE_NORMAL_STEP`
381
382 :meta hide-value:
383 """
384
385 IN_LOOP = NORMAL_LOOP | EMERGENCY | COLLISION
386 """
387 Phases that are executed in or before the inner step, EMERGENCY is executed,
388 right after the inner step.
389
390 Combination of :python:`NORMAL_LOOP | EMERGENCY | COLLISION`
391
392 See Also:
393 - :py:meth:`LunaticAgent.run_step <agents.lunatic_agent.LunaticAgent.run_step>`
394 - :py:mod:`agents.substep_managers.collision_manager`
395
396 :meta hide-value:
397 """
398
399 """
400 def __eq__(self, other):
401 # Makes sure that we can use current_phase == Phases.UPDATE_INFORMATION
402 if not isinstance(other, Phase):
403 return False
404 # Check None
405 if self is Phase.NONE or other is Phase.NONE:
406 return self is other
407 return self in other or other in self
408 """
409
410 def next_phase(self):
411 """
412 Note:
413 This function is more for >>debugging<< and testing purposes,
414 because of different control flows in the agent, the next phase
415 might not be accurate.
416
417 :meta private:
418 """
419 # Hardcoded transitions
420 if self in (Phase.NONE, Phase.EXECUTION | Phase.END): # Begin loop
421 return Phase.BEGIN | Phase.UPDATE_INFORMATION
422 # if self in (Phase.EXECUTION|Phase.END, Phase.DONE| Phase.END) : # End loop
423 # return Phase.NONE
424 if self == Phase.EXECUTION | Phase.BEGIN:
425 return Phase.USER_CONTROLLED # Cannot know what the next phase is
426 if Phase.BEGIN in self:
427 return (self & ~Phase.BEGIN) | Phase.END
428 # Note these should all be END phases
429 if Phase.DONE in self:
430 return Phase.BEGIN | Phase.UPDATE_INFORMATION
431 if Phase.EXCEPTIONS & self:
432 # return Phase.EXECUTION | Phase.BEGIN
433 return Phase.RSS_EVALUATION | Phase.BEGIN
434 if Phase.USER_CONTROLLED & self:
435 # cannot know what the next phase is
436 return Phase.USER_CONTROLLED | Phase.BEGIN # assure that is a BEGIN or END phase
437 if Phase.TERMINATING in self:
438 return Phase.NONE
439 if Phase.END in self: # Safeguard
440 return Phase.BEGIN | Phase((self & ~Phase.END).value * 2)
441 msg = f"Phase {self} is not a valid phase"
442 raise ValueError(msg)
443 return Phase(self.value * 2)
444
445 def validate_next_phase(current_phase, next_phase: "Phase") -> None: # type: ignore
446 """
447 :meta private:
448 """
449 ...
450 # assumed_next = current_phase.next_phase()
451 # NotImplemented # Currently done in agent.execute_phase
452
453 @classmethod
454 def get_user_controlled_phases(cls):
455 """
456 :meta private:
457 """
458 user_phases = cls.APPLY_MANUAL_CONTROLS, cls.EXECUTION, cls.TERMINATING, cls.CUSTOM_CYCLE
459 assert all(p & cls.USER_CONTROLLED for p in user_phases)
460 return user_phases
461
[docs]
462 @classmethod
463 def get_phases(cls):
464 """Get all BEGIN and END phases combination."""
465 return (
466 cls.get_main_phases()
467 + cls.get_exceptions()
468 + [p for phase in cls.get_user_controlled_phases() for p in (phase | cls.BEGIN, phase | cls.END)]
469 + [cls.TERMINATING | cls.BEGIN, cls.TERMINATING | cls.END]
470 )
471
472 @classmethod
473 @lru_cache(1) # < Python3.8
474 def get_main_phases(cls):
475 """
476 Phases which are not exceptions or user controlled.
477
478 :meta private:
479 """
480 main_phases = [cls.NONE, cls.UPDATE_INFORMATION | cls.BEGIN]
481 p = main_phases[1].next_phase()
482 while p != main_phases[1] and not (p & cls.USER_CONTROLLED):
483 if p & cls.USER_CONTROLLED:
484 msg = f"User controlled phase should not be in main phases {p}"
485 raise ValueError(msg)
486 main_phases.append(p)
487 p = p.next_phase()
488 return main_phases
489
490 @classmethod
491 @lru_cache(1) # < Python3.8
492 def get_exceptions(cls) -> "list[Phase]":
493 """
494 Returns the :py:attr:`BEGIN` and :py:attr:`END` combinations of the exceptions that
495 do not follow the normal loop.
496
497 :meta private:
498 """
499 # TODO: Get this from EXCEPTIONS
500 exceptions = [cls.TURNING_AT_JUNCTION, cls.HAZARD, cls.EMERGENCY, cls.COLLISION, cls.CAR_DETECTED, cls.DONE]
501 exception_phases: "list[Phase]" = []
502 for e in exceptions: # improve with itertools
503 exception_phases.append(e | cls.BEGIN)
504 exception_phases.append(e | cls.END)
505 return exception_phases
506
[docs]
507 @classmethod
508 def from_string(cls, string: str) -> "Phase":
509 """
510 Utility method that turns a string like :code:`Phase.NAME | BEGIN | ...` into a Phase.
511
512 Note:
513 Only supports the operator :code:`|`. :code:`NAME` must be a valid Phase name.
514 """
515 elements = string.split("|") # Phase.NAME
516 elements = [cls[e.split(".")[-1].strip()] for e in elements]
517 return reduce(operator.or_, elements) # build union -> Phase
518
519
[docs]
520class Hazard(Flag):
521 """
522 Values currently stored in the agent's :py:attr:`~.LunaticAgent.detected_hazards`.
523 attribute.
524 """
525
526 # Type
527 TRAFFIC_LIGHT_RED = auto() #: :meta hide-value:
528 TRAFFIC_LIGHT_YELLOW = auto() #: :meta hide-value:
529
530 PEDESTRIAN = auto() #: :meta hide-value:
531 CAR = auto() #: :meta hide-value:
532 STATIC_OBSTACLE = auto()
533 """
534 Note:
535 These refer to actors and not the environment barriers.
536
537 :meta hide-value:
538 """
539
540 OTHER = auto() #: :meta hide-value:
541
542 JUNCTION = auto() #: :meta hide-value:
543
544 OBSTACLE = PEDESTRIAN | CAR | STATIC_OBSTACLE
545 """
546 Combination of :python:`PEDESTRIAN | CAR | STATIC_OBSTACLE`
547
548 :meta hide-value:
549 """
550
551 TRAFFIC_LIGHT = TRAFFIC_LIGHT_RED | TRAFFIC_LIGHT_YELLOW
552 """
553 Combination of :python:`TRAFFIC_LIGHT_RED | TRAFFIC_LIGHT_YELLOW`
554
555 :meta hide-value:
556 """
557
558
[docs]
559class HazardSeverity(Flag):
560 """
561 High level descriptions to further weight :py:class:`Hazard`.
562 The :py:class:`HazardSeverity` flags are stored in :py:attr:`~.LunaticAgent.detected_hazards_info`.
563 """
564
565 UNKNOWN = -1
566
567 NONE = 0
568 """
569 Initial values for :py:attr:`.LunaticAgent.detected_hazards_info`
570 """
571
572 # Severity
573 WARNING = auto() # Level 1
574 CRITICAL_ONLY = auto() #: :meta private:
575 EMERGENCY_ONLY = auto() #: :meta private:
576
577 COLLISION = auto()
578 """
579 Special case for collision.
580
581 :meta hide-value:
582 """
583
584 # Aliases - Always register at the end!
585 CRITICAL = WARNING | CRITICAL_ONLY # Level 2
586 """
587 Includes :py:attr:`WARNING`
588 """
589
590 EMERGENCY = CRITICAL | EMERGENCY_ONLY # Level 3
591 """
592 Includes :py:attr:`WARNING` and :py:attr:`CRITICAL`
593 """
594
595
596# ----------------- RoadOptions -----------------
597
598
599if TYPE_CHECKING:
600 # For type-checkers these classes should be the same.
601 # Prevent circular imports
602 from agents.navigation.local_planner import RoadOption
603else:
604
[docs]
605 class RoadOption(IntEnum):
606 """
607 RoadOption represents the possible topological configurations when moving from a segment of lane to other.
608
609 See Also:
610 :py:class:`RoadOptionColor` for the color representation of the road options.
611 """
612
613 VOID = -1
614 """
615 Indicated by green
616 """
617
618 LEFT = 1
619 """
620 Indicated by yellow
621
622 :meta hide-value:
623 """
624
625 RIGHT = 2
626 """
627 Indicated by cyan
628
629 :meta hide-value:
630 """
631
632 STRAIGHT = 3
633 """
634 Indicated by gray
635
636 :meta hide-value:
637 """
638
639 LANEFOLLOW = 4
640 """
641 Indicated by green
642
643 :meta hide-value:
644 """
645
646 CHANGELANELEFT = 5
647 """
648 Indicated by orange
649
650 :meta hide-value:
651 """
652
653 CHANGELANERIGHT = 6
654 """
655 Indicated by dark cyan
656
657 :meta hide-value:
658 """
659
660
661class __ItemAccessMeta(type):
662 """Class that allows item access on the class."""
663
664 def __getitem__(cls, key: str) -> carla.Color:
665 return getattr(cls, key)
666
667 def __call__(cls, option: "RoadOption") -> carla.Color:
668 return getattr(cls, option.name)
669
670
[docs]
671class RoadOptionColor(metaclass=__ItemAccessMeta):
672 """
673 Points to a :py:class:`carla.Color` object that represents the color of the road option.
674
675 Supports :python:`__getitem__(name)` and :python:`__call__(RoadOption)` for easy access.
676 """
677
678 VOID = carla.Color(0, 128, 0) # Green
679 """
680 Green
681
682 :meta hide-value:
683 """
684
685 LEFT = carla.Color(128, 128, 0) # Yellow
686 """
687 Yellow
688
689 :meta hide-value:
690 """
691
692 RIGHT = carla.Color(0, 128, 128) # Cyan
693 """
694 Cyan
695
696 :meta hide-value:
697 """
698
699 STRAIGHT = carla.Color(64, 64, 64) # Gray
700 """
701 Gray
702
703 :meta hide-value:
704 """
705
706 LANEFOLLOW = carla.Color(0, 128, 0) # Green
707 """
708 Green
709
710 :meta hide-value:
711 """
712
713 CHANGELANELEFT = carla.Color(128, 32, 0) # Orange
714 """
715 Orange
716
717 :meta hide-value:
718 """
719
720 CHANGELANERIGHT = carla.Color(0, 32, 128) # Dark Cyan
721 """
722 Dark Cyan
723
724 :meta hide-value:
725 """
726
727
728# ----------------- RSS -----------------
729# depending on availability of the carla.ad module
730
731
732# Stub classes that are alike
733class _CarlaIntEnum(IntEnum):
734 """
735 CARLA's Enums have a `values` entry that is not part of the python enum.Enum class.
736 This abstract class adds this method.
737 """
738
739 values: ClassVar[Dict[int, Self]]
740 names: ClassVar[Dict[str, Self]]
741
742 def __init_subclass__(cls, *args, **kwargs):
743 # TODO: as this is runtime create it correctly. Note: members are created after this function!
744 cls.values: dict[int, Self] # noqa: B032
745 cls.names: dict[str, Self] # noqa: B032
746
747
758
759
770
771
772# assert that the stubs are correct
773if AD_RSS_AVAILABLE:
774 for value, name in carla.RssRoadBoundariesMode.values.items():
775 assert RssRoadBoundariesModeStub[str(name)] == value
776
777 for value, name in carla.RssLogLevel.values.items():
778 assert RssLogLevelStub[str(name)] == value
779
780if TYPE_CHECKING:
781 RssLogLevelAlias: TypeAlias = Union[carla.RssLogLevel, RssLogLevelStub]
782 RssRoadBoundariesModeAlias: TypeAlias = Union[carla.RssRoadBoundariesMode, RssRoadBoundariesModeStub]
783# Correct at Runtime, correct time needed for OmegaConf
784elif AD_RSS_AVAILABLE:
785 RssLogLevelAlias = carla.RssLogLevel
786 RssRoadBoundariesModeAlias = carla.RssRoadBoundariesMode
787else:
788 RssLogLevelAlias = RssLogLevelStub
789 RssRoadBoundariesModeAlias = RssRoadBoundariesModeStub
790
791# Non type variant
792if AD_RSS_AVAILABLE:
793 RssLogLevel = carla.RssLogLevel
794 RssRoadBoundariesMode = carla.RssRoadBoundariesMode
795else:
796 RssLogLevel = RssLogLevelStub
797 RssRoadBoundariesMode = RssRoadBoundariesModeStub
798
799# ----------------- RuleResult -----------------
800
801
[docs]
802class RuleResult(Enum):
803 """Special :python:`objects` that indicate special return values a :py:class:`.Rule`"""
804
805 NO_RESULT = object()
806 """
807 Indicates the the rule returned no result, e.g. because an exception was raised.
808
809 :meta hide-value:
810 """
811
812 NOT_APPLICABLE = object() # noqa: PIE796
813 """
814 Object that indicates that no action was executed, e.g. because the rule is on cooldown or blocked.
815
816 :meta hide-value:
817 """
818
819
820# ----------------- DetectionMatrix -----------------
821
822
[docs]
823class StreetType(str, Enum):
824 """Used by the :py:class:`.DetectionMatrix` to interpret the street type."""
825
826 ON_HIGHWAY = "On highway"
827 NON_HIGHWAY_STREET = "Non highway street"
828 ON_JUNCTION = "On junction"
829 ON_HIGHWAY_ENTRY = "On highway entry"
830 ON_HIGHWAY_EXIT = "On highway exit"
831 JUNCTION_AHEAD = "Junction ahead"
832 HIGHWAY_TRAFFIC_LIGHT = "Highway traffic light"
833 HIGHWAY_WITH_ENTRY_AND_EXIT = "Highway with entry/exit"
834
835
[docs]
836class StreetOccupation(IntEnum):
837 """
838 Enum to interpret the results of the :py:class:`DetectionMatrix`
839 """
840
841 NO_CAR = 0
842 EGO = 1
843 CAR = 2
844 NO_ROAD = 3
845
846 def __str__(self) -> str:
847 s = super().__str__()
848 return f"{s:^7}" # center the word