tactics2d.traffic
ScenarioDisplay
This class implements a matplotlib-based scenario visualizer.
display_map(map_, ax)
This function plots the map on the given axis.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
map_ |
Map
|
The map to be displayed. |
required |
ax |
Axes
|
The axis to display the map on. |
required |
ScenarioManager
Bases: ABC
This class implements an abstract scenario manager.
The scenario manager is used to reset a scenario (including the map, agent, and participants), manage the state update the traffic participants, and check the traffic events.
Attributes:
Name | Type | Description |
---|---|---|
max_step |
int
|
The maximum time step of the scenario. Defaults to None. If not specified, the scenario will not be terminated by the time step. |
step_size |
int
|
The time interval to update a physical step. The unit is millisecond (ms). Defaults to int(1000 / render_fps). |
render_fps |
int
|
The frame rate of the rendering. The unit is Hz. Defaults to 60. |
off_screen |
bool
|
Whether to display the rendering result on the screen. Defaults to False. |
cnt_step |
int
|
The current time step of the scenario. Initialized as 0. |
scenario_status |
ScenarioStatus
|
The high-level status of the scenario. Defaults to ScenarioStatus.NORMAL. |
traffic_status |
TrafficStatus
|
The low-level status of the traffic. Defaults to TrafficStatus.NORMAL. |
map_ |
Map
|
The map of the scenario. Defaults to None. |
participants |
List[Participant]
|
The list of traffic participants. Defaults to None. |
render_manager |
RenderManager
|
The render manager of the scenario. Defaults to None. |
agent |
Agent
|
The agent vehicle in the scenario. Defaults to None. |
__init__(max_step=None, step_size=None, render_fps=60, off_screen=False)
Initialize the scenario manager.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
max_step |
int
|
The maximum time step of the scenario. |
None
|
step_size |
int
|
The time interval to update a physical step. The unit is millisecond (ms). If not specified, the step size will be set to int(1000 / render_fps). |
None
|
render_fps |
int
|
The frame rate of the rendering. The unit is Hz. |
60
|
off_screen |
bool
|
Whether to display the rendering result on the screen. |
False
|
check_status()
abstractmethod
This function checks both the high-level scenario status and the low-level traffic status. It should be overridden in implementation.
Returns:
Type | Description |
---|---|
Tuple[ScenarioStatus, TrafficStatus]
|
The high-level scenario status and the low-level traffic status. |
get_active_participants(frame)
This function obtains the list of active participants at the given frame.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
frame |
int
|
The frame number. The unit is millisecond (ms). |
required |
Returns:
Type | Description |
---|---|
list
|
The list of active participant IDs. |
get_observation()
This function gets the observation of the current state.
render()
abstractmethod
This function renders the current state with the render manager. It should be overridden in implementation.
reset()
abstractmethod
This function resets the scenario. It should be overridden in implementation.
update(action)
abstractmethod
This function updates the states of the traffic participants (including the agent and other participants). It should be overridden in implementation.
ScenarioStatus
Bases: IntEnum
This class defines the high-level status of a traffic scenario.
The possible status are as follows:
NORMAL
: The scenario is running normally.COMPLETED
: The scenario is completed.TIME_EXCEEDED
: The scenario is not completed within the time limit.OUT_BOUND
: The ego vehicle is out of the boundary of the map.NO_ACTION
: The ego vehicle does not take any action for a given time period.FAILED
: The scenario is failed. The reasons for the failure are various and should be specified by TrafficStatus or user defined status.
TrafficStatus
Bases: IntEnum
This class provides a sample for describing the low-level status of a traffic scenario. The user can custom their own status class.
The preliminaries of the status description are as follows
- This class is used by the ego vehicle controlled by an driving policy-maker in the scenario.
- All the other agents are either controlled by humans or other policy-makers.
The possible status are as follows:
NORMAL
: The ego vehicle behaves normally.UNKNOWN
: The traffic status of the ego vehicle is unchecked and unknown for some reasons.COLLISION_STATIC
: The ego vehicle collides into a static object, such as a building.COLLISION_DYNAMIC
: The ego vehicle collides with a movable traffic participant, such as a vehicle or pedestrian.OFF_ROUTE
: The ego vehicle is deviated from the arbitrary route.OFF_LANE
: The ego vehicle is out of the lane.VIOLATION_RETROGRADE
: The ego vehicle violates the traffic rule because it is on the reversed direction of the lane.VIOLATION_NON_DRIVABLE
: The ego vehicle violates the traffic rule because it is in a non-drivable region, such as the bicycle lane, side walk, and traffic island.VIOLATION_TRAFFIC_LIGHT
: The ego vehicle violates the traffic rule because it does not obey the traffic light.VIOLATION_TRAFFIC_SIGN
: The ego vehicle violates the traffic rule because it does not obey the traffic sign.