Skip to content

tactics2d.participant

tactics2d.participant.trajectory

State

This class defines the state element of a trajectory in a 2D Cartesian coordinate system.

Note

Given that the attributes of this class are commonly utilized across various applications, their types will be verified upon assignment. Whenever feasible, they will be converted to the appropriate type.

Attributes:

Name Type Description
frame int

The time stamp. The unit is millisecond (ms).

x float

The x-axis coordinate. The unit is meter.

y float

The y-axis coordinate. The unit is meter.

heading float

The heading direction. The unit is radian.

vx float

The velocity in the x-axis. The unit is meter per second (m/s).

vy float

The velocity in the y-axis. The unit is meter per second (m/s).

speed float

The scalar speed value. The unit is meter per second (m/s). This attribute can be set while initialization or by set_speed. If it is not set while vx and vy are available, speed will be obtained by sqrt(vx$^2$+vy$^2$). Otherwise, the speed will be None.

ax float

The acceleration in the x-axis. The unit is meter per second squared (m/s$^2$).

ay float

The acceleration in the y-axis. The unit is meter per second squared (m/s$^2$).

accel float

The scalar acceleration value. The unit is meter per second squared (m/s$^2$). This attribute can be set while initialization or by set_accel. If it is not set while ax and ay are available, accel will be obtained by sqrt(ax$^2$+ay$^2$). Otherwise, the accel will be None.

location Tuple[float, float]

The location. The unit is meter. This attribute is read-only.

velocity Tuple[float, float]

The velocity vector (vx, vy). The unit is meter per second (m/s). If vx and vy are not available but speed and heading are available, the velocity will be obtained by (speed * cos(heading), speed * sin(heading)). Otherwise, the velocity will be None. This attribute is read-only.

acceleration Tuple[float, float]

The acceleration vector (ax, ay). The unit is meter per second squared (m/s$^2$). If ax and ay are not available, the acceleration will be None. This attribute is read-only.

__init__(frame, x=0, y=0, heading=0, vx=None, vy=None, speed=None, ax=None, ay=None, accel=None)

Initialize the state of a traffic participant.

Parameters:

Name Type Description Default
frame int

The time stamp. The unit is millisecond (ms).

required
x float

The x-axis coordinate. The unit is meter.

0
y float

The y-axis coordinate. The unit is meter.

0
heading float

The heading direction. The unit is radian.

0
vx float

The velocity in the x-axis. The unit is meter per second (m/s).

None
vy float

The velocity in the y-axis. The unit is meter per second (m/s).

None
speed float

The scalar speed value. The unit is meter per second (m/s).

None
ax float

The acceleration in the x-axis. The unit is meter per second squared (m/s$^2$).

None
ay float

The acceleration in the y-axis. The unit is meter per second squared (m/s$^2$).

None
accel float

The scalar acceleration value. The unit is meter per second squared (m/s$^2$).

None

Raises:

Type Description
ValueError

If the type of the input value cannot be converted to the expected type, the function will raise a ValueError.

set_accel(ax, ay)

This function sets ax, ay and calculate the scalar value of acceleration.

set_speed(speed)

This function sets the speed.

set_velocity(vx, vy)

This function sets vx, vy.

Trajectory

This class defines a trajectory data structure.

Attributes:

Name Type Description
id_ Any

The unique identifier of the trajectory.

fps float

The frequency of the trajectory.

stable_freq bool

Whether the trajectory has a stable frequency.

frames List[int]

The list of time stamps of the trajectory. This attribute is read-only.

initial_state State

The initial state of the trajectory. If the trajectory is empty, it will be None. This attribute is read-only.

history_states dict

The dictionary of the states of the trajectory. The key is the time stamp and the value is the state. This attribute is read-only.

last_state State

The last state of the trajectory. If the trajectory is empty, it will be None. This attribute is read-only.

first_frame int

The first frame of the trajectory. The unit is millisecond (ms). If the trajectory is empty, it will be None. This attribute is read-only.

last_frame int

The last frame of the trajectory. The unit is millisecond (ms). If the trajectory is empty, it will be None. This attribute is read-only.

average_speed float

The average speed of the trajectory. The unit is m/s. This attribute is read-only.

__init__(id_, fps=None, stable_freq=True)

Initialize the trajectory.

Parameters:

Name Type Description Default
id_ Any

The unique identifier of the trajectory.

required
fps float

The frequency of the trajectory.

None
stable_freq bool

The flag indicating whether the trajectory has a stable frequency.

True

add_state(state)

This function adds a state to the trajectory.

Parameters:

Name Type Description Default
state State

The state to be added to the trajectory.

required

Raises:

Type Description
ValueError

If the input state is not a valid State object.

KeyError

If the time stamp of the state is earlier than the last time stamp in the trajectory.

get_state(frame=None)

This function get the object's state at the requested frame.

Parameters:

Name Type Description Default
frame int

The time stamp of the requested state. The unit is millisecond (ms).

None

Returns:

Type Description
State

The state of the object at the requested frame. If the frame is None, the current state will be returned.

Raises:

Type Description
KeyError

If the requested frame is not found in the trajectory.

get_trace(frame_range=None)

This function gets the trace of the trajectory within the requested frame range.

Parameters:

Name Type Description Default
frame_range Tuple[int, int]

The requested frame range. The first element is the start frame, and the second element is the end frame. The unit is millisecond (ms).

None

Returns:

Name Type Description
trace list

A list of locations. If the frame range is None, the trace of the whole trajectory will be returned. If the trajectory is empty, an empty list will be returned.

reset(state=None, keep_history=False)

This function resets the trajectory.

Parameters:

Name Type Description Default
state State

The state to be set as the current state. If it is None, the history initial state will be set as the current state.

None
keep_history bool

The flag indicating whether the history states will be kept.

False

tactics2d.participant.element

ParticipantBase

Bases: ABC

This class defines the essential interfaces required to describe a dynamic traffic participant.

Please feel free to inherent this class to implement your own traffic participant.

Note

Given that the attributes of this class are commonly utilized across various applications, their types will be verified upon assignment. Whenever feasible, they will be converted to the appropriate type.

Attributes:

Name Type Description
id_ Any

The unique identifier of the traffic participant.

type_ str

The type of the traffic participant.

trajectory Trajectory

The trajectory of the traffic participant.

color Any

The color of the traffic participant. This attribute will be left to the sensor module to verify and convert to the appropriate type. You can refer to Matplotlib's way to specify validate colors. Defaults to black (0, 0, 0).

length float

The length of the traffic participant. The unit is meter. Defaults to None.

width float

The width of the traffic participant. The unit is meter. Defaults to None.

height float

The height of the traffic participant. The unit is meter. Defaults to None.

verify bool

Whether to verify the trajectory to bind or the state to add. Defaults to False.

physics_model PhysicsModelBase

The physics model of the traffic participant. Defaults to None.

geometry Any

The geometry shape of the traffic participant. It should be overridden to implement. This attribute is read-only.

current_state State

The current state of the traffic participant. This attribute is read-only.

geometry abstractmethod property

The geometry shape of the traffic participant. It should be overridden in implementation.

__init__(id_, type_, trajectory=None, **kwargs)

Initialize the traffic participant.

Parameters:

Name Type Description Default
id_ Any

The unique identifier of the traffic participant.

required
type_ str

The type of the traffic participant.

required
trajectory Trajectory

The trajectory of the traffic participant.

None

Other Parameters:

Name Type Description
color Any

The color of the traffic participant. This argument will be left to the sensor module to verify and convert to the appropriate type.

length float

The length of the traffic participant. The unit is meter.

width float

The width of the traffic participant. The unit is meter.

height float

The height of the traffic participant. The unit is meter.

verify bool

Whether to verify the trajectory to bind or the state to add. Defaults to False.

add_state(state)

This function wraps the add_state method of the trajectory. It does some class-specific checks before adding the state to the trajectory.

Parameters:

Name Type Description Default
state State

The state to be added to the trajectory.

required

bind_trajectory(trajectory=None) abstractmethod

This function binds a trajectory to the traffic participant. It should be overridden in implementation.

Parameters:

Name Type Description Default
trajectory Trajectory

A trajectory to be bound to the traffic participant.

None

get_pose(frame=None) abstractmethod

This function gets the pose of the traffic participant at the requested frame. It should be overridden in implementation.

Parameters:

Name Type Description Default
frame int

The requested frame. The unit is millisecond (ms).

None

get_state(frame=None)

This function returns the state of the participant at the requested frame.

Parameters:

Name Type Description Default
frame int

The requested frame. The unit is millisecond (ms). If the frame is not specified, the function will return the current state.

None

Returns:

Name Type Description
State State

The state of the participant at the requested frame.

Raises:

Type Description
KeyError

The requested frame is not found in the trajectory.

get_states(frame_range=None, frames=None)

Get the traffic participant's states within the requested frame range.

Parameters:

Name Type Description Default
frame_range Tuple[int, int]

The requested frame range. The first element is the start frame, and the second element is the end frame. The unit is millisecond (ms).

None
frames List[int]

The requested frames. The unit is millisecond (ms). If the frames are not in the ascending order, they will be sorted before the states are returned.

None

Returns:

Type Description
List[State]

List[State]: A list of the traffic participant's states. If the frame_range is specified, the function will return the states within the requested range. If the frames is specified, the function will return the states at the requested frames. If neither is specified, the function will return all states.

Raises:

Type Description
ValueError

The frame_range must be a tuple with two elements.

KeyError

Any requested frame in frames is not found in the trajectory.

get_trace(frame_range=None) abstractmethod

This function gets the trace of the traffic participant within the requested frame range. It should be overridden in implementation.

Parameters:

Name Type Description Default
frame_range Tuple[int, int]

The requested frame range. The first element is the start frame, and the second element is the end frame. The unit is millisecond (ms).

None

is_active(frame)

This function checks if the participant has state information at the requested frame.

Parameters:

Name Type Description Default
frame int

The requested frame. The unit is millisecond (ms).

required

Returns:

Name Type Description
bool bool

True if the participant has state information at the requested frame, False otherwise.

reset(state=None, keep_trajectory=False)

Reset the object to a requested state. If the initial state is not specified, the object will be reset to the same initial state as previous.

Parameters:

Name Type Description Default
state State

The initial state of the object.

None
keep_trajectory bool

Whether to keep the record of history trajectory. This argument only works when the state is not specified. When the state is not None, the trajectory will be reset to the new state. Defaults to False.

False

Vehicle

Bases: ParticipantBase

This class defines a four-wheeled vehicle with its common properties.

The definition of different driven modes of the vehicles can be found here:

The default physics model provided for the vehicles is a kinematics bicycle model with the vehicle's geometry center as the origin. This model is recommended only for the vehicles with front-wheel drive (FWD). For other driven modes, the users should better custom their own physics model.

TODO

More physics models will be added in the future based on issues and requirements. You are welcome to suggest implementation of other physics models here.

Attributes:

Name Type Description
id_ int

The unique identifier of the vehicle.

type_ str

The type of the vehicle. Defaults to "medium_car".

trajectory Trajectory

The trajectory of the vehicle. Defaults to an empty trajectory.

color tuple

The color of the vehicle. The color of the traffic participant. This attribute will be left to the sensor module to verify and convert to the appropriate type. You can refer to Matplotlib's way to specify validate colors. Defaults to light-turquoise (43, 203, 186).

length float

The length of the vehicle. The unit is meter. Defaults to None.

width float

The width of the vehicle. The unit is meter. Defaults to None.

height float

The height of the vehicle. The unit is meter. Defaults to None.

kerb_weight float

(float): The weight of the vehicle. The unit is kilogram (kg). Defaults to None.

wheel_base float

The wheel base of the vehicle. The unit is meter. Defaults to None.

front_overhang float

The front overhang of the vehicle. The unit is meter. Defaults to None.

rear_overhang float

The rear overhang of the vehicle. The unit is meter. Defaults to None.

driven_mode

(str): The driven way of the vehicle. The available options are ["FWD", "RWD", "4WD", "AWD"]. Defaults to "FWD".

max_steer float

The maximum approach angle of the vehicle. The unit is radian. Defaults to $\pi$/6.

max_speed float

The maximum speed of the vehicle. The unit is meter per second. Defaults to 55.56 (= 200 km/h).

max_accel float

The maximum acceleration of the vehicle. The unit is meter per second squared. Defaults to 3.0.

max_decel float

The maximum deceleration of the vehicle. The unit is meter per second squared. Defaults to 10.

steer_range Tuple[float, float]

The range of the vehicle steering angle. The unit is radian. Defaults to (-$\pi$/6, $\pi$/6).

speed_range Tuple[float, float]

The range of the vehicle speed. The unit is meter per second (m/s). Defaults to (-16.67, 55.56) (= -60~200 km/h).

accel_range Tuple[float, float]

The range of the vehicle acceleration. The unit is meter per second squared. Defaults to (-10, 3).

verify bool

Whether to verify the trajectory to bind or the state to add. Defaults to False.

physics_model PhysicsModelBase

The physics model of the cyclist. Defaults to SingleTrackKinematics.

shape float

The shape of the cyclist. It is represented as a bounding box with its original point located at the mass center. This attribute is read-only.

current_state State

The current state of the traffic participant. This attribute is read-only.

__init__(id_, type_='medium_car', trajectory=None, **kwargs)

Initialize the vehicle.

Parameters:

Name Type Description Default
id_ int

The unique identifier of the vehicle.

required
type_ str

The type of the vehicle.

'medium_car'
trajectory Trajectory

The trajectory of the vehicle.

None

Other Parameters:

Name Type Description
length float

The length of the vehicle. The unit is meter. Defaults to None.

width float

The width of the vehicle. The unit is meter. Defaults to None.

height float

The height of the vehicle. The unit is meter. Defaults to None.

color tuple

The color of the vehicle. Defaults to None.

kerb_weight float

The kerb weight of the vehicle. The unit is kilogram (kg). Defaults to None.

wheel_base float

The wheel base of the vehicle. The unit is meter. Defaults to None.

front_overhang float

The front overhang of the vehicle. The unit is meter. Defaults to None.

rear_overhang float

The rear overhang of the vehicle. The unit is meter. Defaults to None.

max_steer float

The maximum steering angle of the vehicle. The unit is radian. Defaults to $\pi$ / 6.

max_speed float

The maximum speed of the vehicle. The unit is meter per second. Defaults to 55.56 (=200 km/h).

max_accel float

The maximum acceleration of the vehicle. The unit is meter per second squared. Defaults to 3.0.

max_decel float

The maximum deceleration of the vehicle. The unit is meter per second squared. Defaults to 10.0.

verify bool

Whether to verify the trajectory to bind or the state to add.

physics_model PhysicsModelBase

The physics model of the cyclist. Defaults to None. If the physics model is a custom model, it should be an instance of the PhysicsModelBase class.

driven_mode str

The driven way of the vehicle. The available options are ["FWD", "RWD", "4WD", "AWD"]. Defaults to "FWD".

add_state(state)

This function adds a state to the vehicle.

Parameters:

Name Type Description Default
state State

The state to add.

required

bind_trajectory(trajectory)

This function binds a trajectory to the vehicle.

Parameters:

Name Type Description Default
trajectory Trajectory

The trajectory to bind.

required

Raises:

Type Description
TypeError

If the input trajectory is not of type Trajectory.

get_pose(frame=None)

This function gets the pose of the vehicle at the requested frame.

Parameters:

Name Type Description Default
frame int

The frame to get the vehicle's pose.

None

Returns:

Name Type Description
pose LinearRing

The vehicle's bounding box which is rotated and moved based on the current state.

get_trace(frame_range=None)

This function gets the trace of the vehicle within the requested frame range.

Parameters:

Name Type Description Default
frame_range Tuple[int, int]

The requested frame range. The first element is the start frame, and the second element is the end frame. The unit is millisecond (ms).

None

Returns:

Type Description
LinearRing

The trace of the cyclist within the requested frame range.

load_from_template(type_name, overwrite=True, template=None)

Load the vehicle properties from the template.

Parameters:

Name Type Description Default
type_name str

The type of the vehicle.

required
overwrite bool

Whether to overwrite the existing properties. Defaults to False.

True
template dict

The template of the vehicle. Defaults to VEHICLE_TEMPLATE.

None

Cyclist

Bases: ParticipantBase

This class defines a cyclist with its common properties.

Attributes:

Name Type Description
id_ Any

The unique identifier of the cyclist.

type_ str

The type of the cyclist. Defaults to "cyclist".

trajectory Trajectory

The trajectory of the cyclist. Defaults to an empty trajectory.

color Any

The color of the cyclist. This attribute will be left to the sensor module to verify and convert to the appropriate type. You can refer to Matplotlib's way to specify validate colors. Defaults to light-orange (253, 150, 68).

length float

The length of the cyclist. The unit is meter. Defaults to None.

width float

The width of the cyclist. The unit is meter. Defaults to None.

height float

The height of the cyclist. The unit is meter. Defaults to None.

max_steer float

The maximum steering angle of the cyclist. The unit is radian. Defaults to 1.05.

max_speed float

The maximum speed of the cyclist. The unit is meter per second. Defaults to 22.78.

max_accel float

The maximum acceleration of the cyclist. The unit is meter per second squared. Defaults to 5.8.

max_decel float

The maximum deceleration of the cyclist. The unit is meter per second squared. Defaults to 7.8.

steer_range Tuple[float, float]

The steering angle range of the cyclist. The unit is radian. Defaults to (-1.05, 1.05).

speed_range Tuple[float, float]

The speed range of the cyclist. The unit is meter per second. Defaults to (0, 22.78).

accel_range Tuple[float, float]

The acceleration range of the cyclist. The unit is meter per second squared. Defaults to (-7.8, 5.8).

verify bool

Whether to verify the trajectory to bind or the state to add. Defaults to False.

physics_model PhysicsModelBase

The physics model of the cyclist. Defaults to SingleTrackKinematics.

geometry float

The geometry shape of the cyclist. It is represented as a bounding box with its original point located at the center. This attribute is read-only.

current_state State

The current state of the cyclist. This attribute is read-only.

__init__(id_, type_='cyclist', trajectory=None, **kwargs)

Initialize a cyclist participant. tactics2d treat motorcyclists as cyclists by default.

Parameters:

Name Type Description Default
id_ Any

The unique identifier of the cyclist.

required
type_ str

The type of the cyclist.

'cyclist'
trajectory Trajectory

The trajectory of the cyclist.

None

Other Parameters:

Name Type Description
color Any

The color of the cyclist. This argument will be left to the sensor module to verify and convert to the appropriate type.

length float

The length of the cyclist. The unit is meter.

width float

The width of the cyclist. The unit is meter.

height float

The height of the cyclist. The unit is meter.

max_steer float

The maximum steering angle of the cyclist. The unit is radian.

max_speed float

The maximum speed of the cyclist. The unit is meter per second.

max_accel float

The maximum acceleration of the cyclist. The unit is meter per second squared.

verify bool

Whether to verify the trajectory to bind or the state to add.

physics_model PhysicsModelBase

The physics model of the cyclist. Defaults to None. If the physics model is a custom model, it should be an instance of the PhysicsModelBase class.

bind_trajectory(trajectory)

This function binds a trajectory to the cyclist.

Parameters:

Name Type Description Default
trajectory Trajectory

The trajectory to bind.

required

Raises:

Type Description
TypeError

If the input trajectory is not of type Trajectory.

get_pose(frame=None)

This function gets the pose of the cyclist at the requested frame.

Parameters:

Name Type Description Default
frame int

The frame to get the cyclist's pose.

None

Returns:

Name Type Description
pose LinearRing

The cyclist's bounding box which is rotated and moved based on the current state.

get_trace(frame_range=None)

This function gets the trace of the cyclist within the requested frame range.

Parameters:

Name Type Description Default
frame_range Tuple[int, int]

The requested frame range. The first element is the start frame, and the second element is the end frame. The unit is millisecond (ms).

None

Returns:

Type Description
LinearRing

The trace of the cyclist within the requested frame range.

load_from_template(type_name, overwrite=True, template=None)

This function automatically complete the missing attributes of the instance based on the template.

Parameters:

Name Type Description Default
type_name str

The name of the template parameter set to load.

required
overwrite bool

Whether to overwrite attributes that are not None with the template's value.

True
template (dict, CYCLIST_TEMPLATE)

The template to load from. The available template names are ["cyclist", "moped", "motorcycle"]. You can check the details by calling tactics2d.participant.element.list_cyclist_templates().

None

Pedestrian

Bases: ParticipantBase

This class defines a pedestrian with its common properties.

Attributes:

Name Type Description
id_ Any

The unique identifier of the pedestrian.

type_ str

The type of the pedestrian. Defaults to "adult_male".

trajectory Trajectory

The trajectory of the pedestrian. Defaults to an empty trajectory.

color Any

The color of the pedestrian. This attribute will be left to the sensor module to verify and convert to the appropriate type. You can refer to Matplotlib's way to specify validate colors. Defaults to light-blue (69, 170, 242).

length float

The length of the pedestrian. The unit is meter. Defaults to None.

width float

The width of the pedestrian. The unit is meter. Defaults to 0.4.

height float

The height of the pedestrian. The unit is meter. Defaults to None.

max_speed float

The maximum speed of the pedestrian. The unit is meter per second. Defaults to 7.0.

max_accel float

The maximum acceleration of the pedestrian. The unit is meter per second squared. Defaults to 1.5.

speed_range Tuple[float, float]

The speed range of the pedestrian. The unit is meter per second. Defaults to (-7.0, 7.0).

accel_range Tuple[float, float]

The acceleration range of the pedestrian. The unit is meter per second squared. Defaults to (-1.5, 1.5).

verify bool

Whether to verify the trajectory to bind or the state to add. Defaults to False.

physics_model PhysicsModelBase

The physics model of the pedestrian. Defaults to PointMass.

geometry float

The geometry shape of the pedestrian. It is represented as the radius of a circle. This attribute is read-only.

current_state State

The current state of the pedestrian. This attribute is read-only.

__init__(id_, type_='adult_male', trajectory=None, **kwargs)

Initialize the pedestrian.

Parameters:

Name Type Description Default
id_ Any

The unique identifier of the pedestrian.

required
type_ str

The type of the pedestrian.

'adult_male'
trajectory Trajectory

The trajectory of the pedestrian.

None

Other Parameters:

Name Type Description
color Any

The color of the pedestrian. This attribute will be left to the sensor module to verify and convert to the appropriate type.

length float

The length of the pedestrian. The unit is meter.

width float

The width of the pedestrian. The unit is meter.

height float

The height of the pedestrian. The unit is meter.

max_speed float

The maximum speed of the pedestrian. The unit is meter per second.

max_accel float

The maximum acceleration of the pedestrian. The unit is meter per second squared.

verify bool

Whether to verify the trajectory to bind or the state to add.

physics_model PhysicsModelBase

The physics model of the pedestrian. Defaults to PointMass. If the physics model is a custom model, it should be an instance of the PhysicsModelBase class.

bind_trajectory(trajectory)

This function binds a trajectory to the pedestrian.

Parameters:

Name Type Description Default
trajectory Trajectory

The trajectory to bind.

required

Raises:

Type Description
TypeError

If the input trajectory is not of type Trajectory.

get_pose(frame=None)

This function gets the pose of the pedestrian at the requested frame.

Parameters:

Name Type Description Default
frame int

The requested frame. The unit is millisecond (ms).

None

Returns:

Name Type Description
location Tuple[float, float]

The location of the pedestrian.

radius float

The radius of the pedestrian.

get_trace(frame_range=None)

This function gets the trace of the pedestrian within the requested frame range.

Parameters:

Name Type Description Default
frame_range Tuple[int, int]

The requested frame range. The first element is the start frame, and the second element is the end frame. The unit is millisecond (ms).

None

Returns:

Type Description
LinearRing

The trace of the pedestrian within the requested frame range.

load_from_template(type_name, overwrite=True, template=None)

This function automatically complete the missing attributes of the instance based on the template.

Parameters:

Name Type Description Default
type_name str

The name of the template parameter set to load.

required
overwrite bool

Whether to overwrite attributes that are not None with the template's value.

True
template dict

The template to load from. The available template names are ["adult_male", "adult_female", "children_six_year_old", "children_ten_year_old"]. You can check the details by calling tactics2d.participant.element.list_pedestrian_templates().

None

Other

Bases: ParticipantBase

This class defines a dynamic traffic participant of an other type.

Attributes:

Name Type Description
id_ Any

The unique identifier of the traffic participant.

type_ str

The type of the traffic participant. Defaults to "unknown".

trajectory Trajectory

The trajectory of the traffic participant. Defaults to an empty trajectory.

color Any

The color of the traffic participant. This attribute will be left to the sensor module to verify and convert to the appropriate type. You can refer to Matplotlib's way to specify validate colors. Defaults to black (0, 0, 0).

length float

The length of the traffic participant. The unit is meter. Defaults to None.

width float

The width of the traffic participant. The unit is meter. Defaults to None.

height float

The height of the traffic participant. The unit is meter. Defaults to None.

physics_model PhysicsModelBase

The physics model of the traffic participant. Defaults to None.

geometry LinearRing

The geometry shape of the traffic participant. This attribute is read-only. If both length and width are available, the geometry shape will be a rectangle. If only length or width is available, the geometry shape will be a square. Otherwise, the geometry shape will be None.

current_state State

The current state of the traffic participant. This attribute is read-only.

__init__(id_, type_='unknown', trajectory=None, **kwargs)

Initialize the traffic participant of an other type.

Parameters:

Name Type Description Default
id_ Any

The unique identifier of the traffic participant.

required
type_ str

The type of the traffic participant.

'unknown'
trajectory Trajectory

The trajectory of the traffic participant.

None

Other Parameters:

Name Type Description
color Any

The color of the traffic participant. This argument will be left to the sensor module to verify and convert to the appropriate type.

length float

The length of the traffic participant. The unit is meter.

width float

The width of the traffic participant. The unit is meter.

height float

The height of the traffic participant. The unit is meter.

bind_trajectory(trajectory=None)

This function is used to bind a trajectory to the traffic participant.

Parameters:

Name Type Description Default
trajectory Trajectory

The trajectory of the traffic participant.

None

Raises:

Type Description
TypeError

If the input trajectory is not of type Trajectory.

get_pose(frame=None)

This function gets the outfigure of the traffic participant at the requested frame.

Parameters:

Name Type Description Default
frame int

The time stamp of the requested pose. The unit is millisecond (ms).

None

Returns:

Name Type Description
pose Union[Point, LinearRing]

The outfigure of the traffic participant at the requested frame. If the geometry shape of the traffic participant is available, the pose will be a LinearRing that describe the outfigure of the traffic participant at the requested frame. Otherwise, the pose will be a Point that describe the location of the traffic participant at the requested frame.

get_trace(frame_range=None)

This function gets the trace of the traffic participant within the requested frame range.

Parameters:

Name Type Description Default
frame_range Tuple[int, int]

The requested frame range. The first element is the start frame, and the second element is the end frame. The unit is millisecond (ms). If the frame range is None, the trace of the whole trajectory will be returned.

None

Returns:

Name Type Description
trace Union[LineString, LinearRing]

The trace of the traffic participant.

  • If the width of the traffic participant is available, the trace will be a LinearRing that describe the area that the traffic participant occupied during the requested frame range with width/2 as the trace's width.
  • If the width is absent while the length is available, the trace will be a LinearRing that describe the area that the traffic participant occupied during the requested frame range with length/2 as the trace's width.
  • If the geometry shape of the traffic participant is unavailable, the trace will be a LineString that describe the center line of the traffic participant during the requested frame range.

list_vehicle_templates()

This function prints the default vehicle templates in a table.

list_cyclist_templates()

This function prints the default cyclist templates in a table.

list_pedestrian_templates()

This function prints the default pedestrian templates in a table.

Templates for Traffic Participants

Four-wheel Vehicle Models

Our classification of vehicle types adheres to the European Emissions Standards (EEC) due to its clear and straightforward categorization. To establish the parameters, we select a specific vehicle representing each type based on commonly sold models and accessible data sourced online. These selections are carefully made to ensure the data utilized is both representative and accurate.

Due to the challenge of obtaining precise maximum steering values for each vehicle type, we assume a uniform maximum steering value of $\pi/6$ radians for all vehicles. This assumption is based on the understanding that, as our vehicle physics model operates on the bicycle model, subtle variations in steering range are unlikely to significantly impact the simulation's outcomes.

The default vehicle parameters can be visited by calling tactics2d.participant.element.list_vehicle_templates().

EEE Category Prototype Length (m) Width (m) Height (m) Wheelbase (m) Front overhang (m) Rear overhang (m) Kerb Weight (kg) Max speed (m/s) 0-100 km/h (s) Driven mode
A: Mini car Volkswagen Up 3.540 1.641 1.489 2.420 0.585 0.535 1070 44.44 14.4 FWD
B: Small car Volkswagen Polo 4.053 1.751 1.461 2.548 0.824 0.681 1565 52.78 11.2 FWD
C: Medium car Volkswagen Golf 4.284 1.799 1.452 2.637 0.880 0.767 1620 69.44 8.9 FWD
D: Large car Volkswagen Passat 4.866 1.832 1.477 2.871 0.955 1.040 1735 58.33 8.4 FWD
E: Executive car Audi A6 5.050 1.886 1.475 3.024 0.921 1.105 2175 63.89 8.1 FWD
F: Luxury car Audi A8 5.302 1.945 1.488 3.128 0.989 1.185 2520 69.44 6.7 AWD
S: Sports coupe Ford Mustang 4.788 1.916 1.381 2.720 0.830 1.238 1740 63.89 5.3 AWD
M: MPV Kia Carnival 5.155 1.995 1.740 3.090 0.935 1.130 2095 66.67 9.4 4WD
J: SUV Jeep Grand Cherokee 4.828 1.943 1.792 2.915 0.959 0.954 2200 88.89 3.8 4WD

Cyclist Models

The cyclist model is designed around average parameters. To access the default cyclist parameters, you can call tactics2d.participant.element.list_cyclist_templates().

Name Length (m) Width (m) Height (m) Max steer (rad) Max speed (m/s) Max acceleration (m/s$^2$) Max deceleration (m/s$^2$)
Cyclist 1.80 0.65 1.70 1.05 22.78 5.8 7.8
Moped 2.00 0.70 1.70 0.35 13.89 3.5 7.0
Motorcycle 2.40 0.80 1.70 0.44 75.00 5.0 10.0

Pedestrian Models

The pedestrian model is designed around average parameters. To access the default pedestrian parameters, you can call tactics2d.participant.element.list_pedestrian_templates().

Name Length (m) Width (m) Height (m) Max speed (m/s) Max acceleration (m/s$^2$)
Adult/male 0.24 0.40 1.75 7.0 1.5
Adult/female 0.22 0.37 1.65 6.0 1.5
Child (six-year old) 0.18 0.25 1.16 3.5 1.0
Child (ten-year old) 0.20 0.35 1.42 4.5 1.0