Skip to content

tactics2d.participant

Participant module.

tactics2d.participant.trajectory

Trajectory module.

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:

  • 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:

  • frame (int) –

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

  • x (float, default: 0 ) –

    The x-axis coordinate. The unit is meter.

  • y (float, default: 0 ) –

    The y-axis coordinate. The unit is meter.

  • heading (float, default: 0 ) –

    The heading direction. The unit is radian.

  • vx (float, default: None ) –

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

  • vy (float, default: None ) –

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

  • speed (float, default: None ) –

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

  • ax (float, default: None ) –

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

  • ay (float, default: None ) –

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

  • accel (float, default: None ) –

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

Raises:

  • 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_heading(heading)

This function sets the heading direction (radian).

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:

  • 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:

  • id_ (Any) –

    The unique identifier of the trajectory.

  • fps (float, default: None ) –

    The frequency of the trajectory.

  • stable_freq (bool, default: True ) –

    The flag indicating whether the trajectory has a stable frequency.

add_state(state)

This function adds a state to the trajectory.

Parameters:

  • state (State) –

    The state to be added to the trajectory.

Raises:

  • 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:

  • frame (int, default: None ) –

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

Returns:

  • State

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

Raises:

  • 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:

  • frame_range (Tuple[int, int], default: None ) –

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

Returns:

  • 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.

has_state(frame)

This function checks if the trajectory has a state at the requested frame.

Parameters:

  • frame (int) –

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

Returns:

  • bool ( bool ) –

    True if the trajectory has a state at the requested frame, False otherwise.

reset(state=None, keep_history=False)

This function resets the trajectory.

Parameters:

  • state (State, default: None ) –

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

  • keep_history (bool, default: False ) –

    The flag indicating whether the history states will be kept.

tactics2d.participant.element

Element module.

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:

  • 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:

  • id_ (Any) –

    The unique identifier of the traffic participant.

  • type_ (str) –

    The type of the traffic participant.

  • trajectory (Trajectory, default: None ) –

    The trajectory of the traffic participant.

Other Parameters:

  • 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:

  • state (State) –

    The state to be added to the trajectory.

bind_trajectory(trajectory=None) abstractmethod

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

Parameters:

  • trajectory (Trajectory, default: None ) –

    A trajectory to be bound to the traffic participant.

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:

  • frame (int, default: None ) –

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

get_state(frame=None)

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

Parameters:

  • frame (int, default: None ) –

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

Returns:

  • State ( State ) –

    The state of the participant at the requested frame.

Raises:

  • 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:

  • frame_range (Tuple[int, int], default: None ) –

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

  • frames (List[int], default: None ) –

    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.

Returns:

  • 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:

  • 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:

  • frame_range (Tuple[int, int], default: None ) –

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

is_active(frame)

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

Parameters:

  • frame (int) –

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

Returns:

  • 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:

  • state (State, default: None ) –

    The initial state of the object.

  • keep_trajectory (bool, default: False ) –

    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.

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:

  • 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 "#2bcbba".

  • 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 vehicle. Defaults to SingleTrackKinematics.

  • geometry (LinearRing) –

    The geometry shape of the vehicle. 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 traffic participant. This attribute is read-only.

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

Initialize the vehicle.

Parameters:

  • id_ (int) –

    The unique identifier of the vehicle.

  • type_ (str, default: 'medium_car' ) –

    The type of the vehicle.

  • trajectory (Trajectory, default: None ) –

    The trajectory of the vehicle.

Other Parameters:

  • 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:

  • state (State) –

    The state to add.

bind_trajectory(trajectory)

This function binds a trajectory to the vehicle.

Parameters:

  • trajectory (Trajectory) –

    The trajectory to bind.

Raises:

  • 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:

  • frame (int, default: None ) –

    The frame to get the vehicle's pose.

Returns:

  • 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:

  • frame_range (Tuple[int, int], default: None ) –

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

Returns:

  • LinearRing ( LinearRing ) –

    The trace of the vehicle within the requested frame range, represented as a polygon buffer around the trajectory centerline.

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

Load the vehicle properties from the template.

Parameters:

  • type_name (str) –

    The type of the vehicle.

  • overwrite (bool, default: True ) –

    Whether to overwrite the existing properties. Defaults to False.

  • template (dict, default: None ) –

    The template of the vehicle. Defaults to VEHICLE_TEMPLATE.

Cyclist

Bases: ParticipantBase

This class defines a cyclist with its common properties.

Attributes:

  • 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 "#fd9644".

  • 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:

  • id_ (Any) –

    The unique identifier of the cyclist.

  • type_ (str, default: 'cyclist' ) –

    The type of the cyclist.

  • trajectory (Trajectory, default: None ) –

    The trajectory of the cyclist.

Other Parameters:

  • 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:

  • trajectory (Trajectory) –

    The trajectory to bind.

Raises:

  • 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:

  • frame (int, default: None ) –

    The frame to get the cyclist's pose.

Returns:

  • 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:

  • frame_range (Tuple[int, int], default: None ) –

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

Returns:

  • 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:

  • type_name (str) –

    The name of the template parameter set to load.

  • overwrite (bool, default: True ) –

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

  • template ((dict, CYCLIST_TEMPLATE), default: None ) –

    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().

Pedestrian

Bases: ParticipantBase

This class defines a pedestrian with its common properties.

Attributes:

  • 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 "#45aaf2".

  • 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:

  • id_ (Any) –

    The unique identifier of the pedestrian.

  • type_ (str, default: 'adult_male' ) –

    The type of the pedestrian.

  • trajectory (Trajectory, default: None ) –

    The trajectory of the pedestrian.

Other Parameters:

  • 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:

  • trajectory (Trajectory) –

    The trajectory to bind.

Raises:

  • 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:

  • frame (int, default: None ) –

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

Returns:

  • 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:

  • frame_range (Tuple[int, int], default: None ) –

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

Returns:

  • 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:

  • type_name (str) –

    The name of the template parameter set to load.

  • overwrite (bool, default: True ) –

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

  • template (dict, default: None ) –

    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().

Other

Bases: ParticipantBase

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

Attributes:

  • 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.

  • 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:

  • id_ (Any) –

    The unique identifier of the traffic participant.

  • type_ (str, default: 'unknown' ) –

    The type of the traffic participant.

  • trajectory (Trajectory, default: None ) –

    The trajectory of the traffic participant.

Other Parameters:

  • 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:

  • trajectory (Trajectory, default: None ) –

    The trajectory of the traffic participant.

Raises:

  • 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:

  • frame (int, default: None ) –

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

Returns:

  • 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:

  • frame_range (Tuple[int, int], default: None ) –

    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.

Returns:

  • 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.

交通参与者模板

四轮车辆模型

我们对车辆类型的分类遵循欧洲排放标准(EEC),因其分类清晰明了。为了确定参数,我们基于常见销售型号和在线可获取的数据,为每个类型选择了一款代表性车辆。这些选择经过仔细考虑,以确保所使用的数据既具有代表性又准确。

由于获取每种车辆类型的精确最大转向值具有挑战性,我们假设所有车辆的统一最大转向值为 \(\pi/6\) 弧度。这一假设基于以下理解:由于我们的车辆物理模型基于自行车模型,转向范围的细微变化不太可能对仿真结果产生显著影响。

默认车辆参数可通过调用 tactics2d.participant.element.list_vehicle_templates() 查看。

EEC 类别 原型 长度 (m) 宽度 (m) 高度 (m) 轴距 (m) 前悬 (m) 后悬 (m) 整备质量 (kg) 最高速度 (m/s) 0-100 km/h (s) 驱动模式
A: 微型车 Volkswagen Up 3.540 1.641 1.489 2.420 0.585 0.535 1070 44.44 14.4 FWD
B: 小型车 Volkswagen Polo 4.053 1.751 1.461 2.548 0.824 0.681 1565 52.78 11.2 FWD
C: 中型车 Volkswagen Golf 4.284 1.799 1.452 2.637 0.880 0.767 1620 69.44 8.9 FWD
D: 大型车 Volkswagen Passat 4.866 1.832 1.477 2.871 0.955 1.040 1735 58.33 8.4 FWD
E: 行政级车 Audi A6 5.050 1.886 1.475 3.024 0.921 1.105 2175 63.89 8.1 FWD
F: 豪华车 Audi A8 5.302 1.945 1.488 3.128 0.989 1.185 2520 69.44 6.7 AWD
S: 运动轿跑 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

骑行者模型

骑行者模型基于平均参数设计。要访问默认骑行者参数,您可以调用 tactics2d.participant.element.list_cyclist_templates()

名称 长度 (m) 宽度 (m) 高度 (m) 最大转向 (rad) 最高速度 (m/s) 最大加速度 (m/s\(^2\)) 最大减速度 (m/s\(^2\))
骑行者 1.80 0.65 1.70 1.05 22.78 5.8 7.8
轻便摩托车 2.00 0.70 1.70 0.35 13.89 3.5 7.0
摩托车 2.40 0.80 1.70 0.44 75.00 5.0 10.0

行人模型

行人模型基于平均参数设计。要访问默认行人参数,您可以调用 tactics2d.participant.element.list_pedestrian_templates()

名称 长度 (m) 宽度 (m) 高度 (m) 最高速度 (m/s) 最大加速度 (m/s\(^2\))
成人/男性 0.24 0.40 1.75 7.0 1.5
成人/女性 0.22 0.37 1.65 6.0 1.5
儿童 (六岁) 0.18 0.25 1.16 3.5 1.0
儿童 (十岁) 0.20 0.35 1.42 4.5 1.0