agents.rules.obstacles package

Submodules

agents.rules.obstacles.traffic_light_rules module

class agents.rules.obstacles.traffic_light_rules.DriveSlowTowardsTrafficLight(phases: Phase | Iterable[Phase] | 'type[Any]' | Self | str | None | None = None, bases: tuple[type[Any], ...] | None = None, clsdict: dict[str, Any] | None = None, **kwargs: Any)[source]

Bases: BlockingRule

When the agent is at a red traffic light and it is red drive forward slowly.

Parameters:
  • phases (Union[Phase, Iterable[Phase]])

  • condition (Optional[ConditionFunctionLikeT])

  • action (Optional[Union[CallableAction[Self, []], Dict[Any, CallableAction[Self, []]]]])

  • false_action (Optional[CallableAction[Self, []]])

  • gameframework (Optional[GameFramework])

  • actions (Optional[Dict[Any, CallableAction[Rule, []]]])

  • description (str)

  • overwrite_settings (Optional[Dict[str, Any]])

  • self_config (Optional[Dict[str, Any]])

  • priority (RulePriority)

  • cooldown_reset_value (Optional[int])

  • group (Optional[str])

  • enabled (bool)

priority: float | int | RulePriority = 2

Rules are executed in order of their priority, from high to low.

phase: Phase = 32769

For the Class API the phase attribute be set to a single Phase object.

MAX_TICKS = 2000

The amount of ticks that can be performed by this rule before it is automatically disabled. If the rule has looped for this amount of ticks if will then call max_tick_callback and raise an UnblockRuleException afterwards.

As a hack max_tick_callback can change ticks_passed to prevent the exception and continue the rule.

DEFAULT_COOLDOWN_RESET: ClassVar[int] = 500

Value the cooldown is reset to when reset_cooldown() is called without a value.

Used only when cooldown_reset_value is not set.

condition()[source]

Executes if a traffic light is the only hazard

overwrite_settings: dict[str, Any] = {'speed': {'follow_speed_limits': False}}

Settings that should overwrite the agent’s settings for this rule.

Note

The overwrite settings are primitive dict objects, omegaconf.DictConfig objects are converted.

class self_config(instance: 'object' = MISSING, max_brake: float = '${divide:${controls.max_brake},8}', max_throttle: float = '${divide:${controls.max_throttle},4}')[source]

Bases: RuleConfig

Parameters:
max_brake: float = '${divide:${controls.max_brake},8}'

Max break that should be applied when above the target speed.

__init__(instance: object = MISSING, max_brake: float = '${divide:${controls.max_brake},8}', max_throttle: float = '${divide:${controls.max_throttle},4}') None
Parameters:
Return type:

None

max_throttle: float = '${divide:${controls.max_throttle},4}'

Max throttle that should be applied when below the target speed.

__init__(phases: Phase | Iterable[Phase], condition: ConditionFunctionLikeT | None = None, action: CallableActionT | Dict[Any, CallableActionT] | None = None, false_action: CallableActionT | None = None, *, gameframework: GameFramework | None, actions: Dict[Any, CallableActionT] | None = None, description: str = 'What does this rule do?', overwrite_settings: Dict[str, Any] | None = None, self_config: Dict[str, Any] | None = None, priority: RulePriority = RulePriority.NORMAL, cooldown_reset_value: int | None = None, group: str | None = None, enabled: bool = True)

Initializes a Rule object.

Parameters:
  • phases (Union[Phase, Iterable[Phase]]) – The phase(s) when the rule should be evaluated. An iterable of Phase objects or a single Phase object.

  • condition (Optional[ConditionFunctionLikeT]) – A function that takes a Context object as input and returns a Hashable value. If not provided, the class must implement a condition function.

  • action (Optional[Union[CallableActionT, Dict[Any, CallableActionT]]]) – A function or a dictionary of functions that take a Context object as input. If action behaves like actions. Only one of action and actions can be set.

  • false_action (Optional[CallableActionT]) – A function that takes a Context object as input and returns any value. It is used when action is a single function and represents the action to be taken when the condition is False.

  • actions (Optional[Dict[Any, CallableActionT]]) – A dictionary of action functions It should map the return values of condition to the corresponding action function. If action is None, actions must be provided.

  • description (str) – A string that describes what this rule does.

  • overwrite_settings (Optional[Dict[str, Any]]) – A dictionary of settings that will overwrite the agent’s setting for this Rule.

  • priority (RulePriority) – The priority of the rule. It can be a float, an integer, or a RulePriority enum value.

  • cooldown_reset_value (Optional[int]) – An optional integer value that represents the cooldown reset value for the rule. If not provided falls back to the class attribute Rule.DEFAULT_COOLDOWN_RESET.

  • group (Optional[str]) – An optional string that specifies the group to which this rule belongs.

  • enabled (bool) – A boolean value indicating whether the rule is enabled or not.

  • gameframework (Optional[GameFramework])

  • self_config (Optional[Dict[str, Any]])

Raises:
  • ValueError – If phases is empty or None, or if phases contains an object that is not of type Phase.

  • TypeError – If condition is None and the class does not implement a condition() function, or if both action and actions are None and the class does not have an actions attribute or an action() function.

  • TypeError – if actions is not a Mapping object.

  • ValueError – If both action and actions are provided.

  • ValueError – If action is a Mapping and either false_action or actions is not None.

  • ValueError – If an action function is not callable.

  • ValueError – If description is not a string.

description: str = '\n    When the agent is at a red traffic light and it is red drive forward slowly.\n    '

Description of what this rule should do

action(ctx: Context)[source]
Parameters:

ctx (Context)

max_tick_callback(ctx: Context) NoReturn[source]
Parameters:

ctx (Context)

Return type:

NoReturn

class agents.rules.obstacles.traffic_light_rules.PassYellowTrafficLightRule(phases: Phase | Iterable[Phase] | 'type[Any]' | Self | str | None | None = None, bases: tuple[type[Any], ...] | None = None, clsdict: dict[str, Any] | None = None, **kwargs: Any)[source]

Bases: Rule

Parameters:
priority: float | int | RulePriority = 8

Rules are executed in order of their priority, from high to low.

phase: Phase = 18

For the Class API the phase attribute be set to a single Phase object.

class self_config(instance: 'object' = MISSING, try_to_pass: bool = False, passing_speed: float = '${max:${mul:${live_info.current_speed_limit},1.33},${speed.target_speed}}')[source]

Bases: RuleConfig

Parameters:
try_to_pass: bool = False

If the agent should try to pass the yellow light.

passing_speed: float = '${max:${mul:${live_info.current_speed_limit},1.33},${speed.target_speed}}'

The speed the agent should try to pass the yellow light.

__init__(instance: object = MISSING, try_to_pass: bool = False, passing_speed: float = '${max:${mul:${live_info.current_speed_limit},1.33},${speed.target_speed}}') None
Parameters:
Return type:

None

condition()[source]

Executes if a traffic light is the only hazard

yellow_action(ctx: Context)
Parameters:

ctx (Context)

__init__(phases: Phase | Iterable[Phase], condition: ConditionFunctionLikeT | None = None, action: CallableActionT | Dict[Any, CallableActionT] | None = None, false_action: CallableActionT | None = None, *, actions: Dict[Any, CallableActionT] | None = None, description: str = 'What does this rule do?', overwrite_settings: Dict[str, Any] | None = None, self_config: Dict[str, Any] | None = None, priority: RulePriority = RulePriority.NORMAL, cooldown_reset_value: int | None = None, group: str | None = None, enabled: bool = True)

Initializes a Rule object.

Parameters:
  • phases (Union[Phase, Iterable[Phase]]) – The phase(s) when the rule should be evaluated. An iterable of Phase objects or a single Phase object.

  • condition (Optional[ConditionFunctionLikeT]) – A function that takes a Context object as input and returns a Hashable value. If not provided, the class must implement a condition function.

  • action (Optional[Union[CallableActionT, Dict[Any, CallableActionT]]]) – A function or a dictionary of functions that take a Context object as input. If action behaves like actions. Only one of action and actions can be set.

  • false_action (Optional[CallableActionT]) – A function that takes a Context object as input and returns any value. It is used when action is a single function and represents the action to be taken when the condition is False.

  • actions (Optional[Dict[Any, CallableActionT]]) – A dictionary of action functions It should map the return values of condition to the corresponding action function. If action is None, actions must be provided.

  • description (str) – A string that describes what this rule does.

  • overwrite_settings (Optional[Dict[str, Any]]) – A dictionary of settings that will overwrite the agent’s setting for this Rule.

  • priority (RulePriority) – The priority of the rule. It can be a float, an integer, or a RulePriority enum value.

  • cooldown_reset_value (Optional[int]) – An optional integer value that represents the cooldown reset value for the rule. If not provided falls back to the class attribute Rule.DEFAULT_COOLDOWN_RESET.

  • group (Optional[str]) – An optional string that specifies the group to which this rule belongs.

  • enabled (bool) – A boolean value indicating whether the rule is enabled or not.

  • self_config (Optional[Dict[str, Any]])

Raises:
  • ValueError – If phases is empty or None, or if phases contains an object that is not of type Phase.

  • TypeError – If condition is None and the class does not implement a condition() function, or if both action and actions are None and the class does not have an actions attribute or an action() function.

  • TypeError – if actions is not a Mapping object.

  • ValueError – If both action and actions are provided.

  • ValueError – If action is a Mapping and either false_action or actions is not None.

  • ValueError – If an action function is not callable.

  • ValueError – If description is not a string.

actions: dict[Any, CallableActionT] = {True: carla.TrafficLightState.Yellow}

Dictionary that maps rule results to the action that should be executed.

description: str = 'No description provided.'

Description of what this rule should do