Skip to content

tactics2d.sensor

Sensor module.

BEVCamera

Bases: SensorBase

This class defines the render paradigm of a BEV camera.

Attributes:

  • id_ (int) –

    The unique identifier of the sensor. This attribute is read-only once the instance is initialized.

  • map_ (Map) –

    The map that the sensor is attached to. This attribute is read-only once the instance is initialized.

  • perception_range (Union[float, Tuple[float]]) –

    The distance from the sensor to its maximum detection range in (left, right, front, back). When this value is undefined, the sensor is assumed to detect the whole map. Defaults to None.

  • position (Point) –

    The position of the sensor in the global 2D coordinate system.

  • bind_id (Any) –

    The unique identifier of object that the sensor is bound to. This attribute is read-only and can only be set using the bind_with method.

  • is_bound (bool) –

    Whether the sensor is bound to an object. This attribute is read-only once the instance is initialized.

__init__(id_, map_, perception_range=None)

Initialize the BEV camera.

Parameters:

  • id_ (int) –

    The unique identifier of the camera.

  • map_ (Map) –

    The map that the camera is attached to.

  • perception_range (Union[float, Tuple[float]], default: None ) –

    The distance from the camera to its maximum detection range in (left, right, front, back). When this value is undefined, the sensor is assumed to detect the whole map. This can be a single float value or a tuple of four values representing the perception range in each direction (left, right, front, back). Defaults to None.

update(frame, participants, participant_ids, prev_road_id_set=None, prev_participant_id_set=None, position=None, heading=None)

Update the camera and return geometry data.

SensorBase

Bases: ABC

This class defines a base interface for sensors.

Attributes:

  • id_ (int) –

    The unique identifier of the sensor. This attribute is read-only once the instance is initialized.

  • map_ (Map) –

    The map that the sensor is attached to. This attribute is read-only once the instance is initialized.

  • perception_range (Union[float, Tuple[float]]) –

    The distance from the sensor to its maximum detection range in (left, right, front, back). When this value is undefined, the sensor is assumed to detect the whole map. Defaults to None. This attribute is read-only once the instance is initialized.

  • position (Point) –

    The position of the sensor in the global 2D coordinate system.

  • bind_id (Any) –

    The unique identifier of object that the sensor is bound to. This attribute is read-only and can only be set using the bind_with method.

  • is_bound (bool) –

    Whether the sensor is bound to an object. This attribute is read-only once the instance is initialized.

__init__(id_, map_, perception_range=None)

Initialize the sensor.

Parameters:

  • id_ (int) –

    The unique identifier of the sensor.

  • map_ (Map) –

    The map that the sensor is attached to.

  • perception_range (Union[float, Tuple[float]], default: None ) –

    The distance from the sensor to its maximum detection range in (left, right, front, back). When this value is undefined, the sensor is assumed to detect the whole map. This can be a single float value or a tuple of four values representing the perception range in each direction (left, right, front, back). Defaults to None.

bind_with(bind_id)

Bind the sensor to a participant with the given ID.

Parameters:

  • bind_id (int) –

    ID of the participant to bind to.

update(frame, participants, participant_ids, prev_road_id_set=None, prev_participant_id_set=None, position=None, heading=None) abstractmethod

This function is used to update the sensor's position and observation.

Parameters:

  • frame (int) –

    The frame number of the observation.

  • participants (Dict[int, Participant]) –

    The participants in the scenario.

  • participant_ids (List[int]) –

    The list of participant IDs to be considered.

  • prev_road_id_set (Set, default: None ) –

    The set of road IDs that were rendered in the previous frame. Used for incremental updates. Defaults to None.

  • prev_participant_id_set (Set, default: None ) –

    The set of participant IDs that were rendered in the previous frame. Used for incremental updates. Defaults to None.

  • position (Point, default: None ) –

    The position of the sensor. Defaults to None.

  • heading (float, default: None ) –

    The heading of the sensor in radians. Defaults to None.

Returns:

  • Tuple[Dict, Set, Set]

    Tuple[Dict, Set, Set]: (geometry_data, road_id_set, participant_id_set) - geometry_data: A dictionary containing the geometry data for rendering - road_id_set: The set of road IDs that were rendered in the current frame - participant_id_set: The set of participant IDs that were rendered in the current frame

SingleLineLidar

Bases: SensorBase

This class defines the render paradigm for a single line lidar.

The default parameters refer to LiDAR STL-06P. This LiDAR sensor has only one scan line. Its documentation is here.

Attributes:

  • id_ (int) –

    The unique identifier of the sensor. This attribute is read-only once the instance is initialized.

  • map_ (Map) –

    The map that the sensor is attached to. This attribute is read-only once the instance is initialized.

  • perception_range (Union[float, Tuple[float]]) –

    The distance from the sensor to its maximum detection range in (left, right, front, back). When this value is undefined, the sensor is assumed to detect the whole map. Defaults to None.

  • position (Point) –

    The position of the sensor in the global 2D coordinate system.

  • bind_id (Any) –

    The unique identifier of object that the sensor is bound to. This attribute is read-only and can only be set using the bind_with method.

  • is_bound (bool) –

    Whether the sensor is bound to an object. This attribute is read-only once the instance is initialized.

__init__(id_, map_, perception_range=12.0, freq_scan=10.0, freq_detect=5000.0)

Initialize the single line lidar.

Parameters:

  • id_ (int) –

    The unique identifier of the LiDAR.

  • map_ (Map) –

    The map that the LiDAR is attached to.

  • perception_range (float, default: 12.0 ) –

    The distance from the LiDAR to its maximum detection range.

  • freq_scan (float, default: 10.0 ) –

    The frequency of the LiDAR scanning a full round.

  • freq_detect (float, default: 5000.0 ) –

    The frequency of the LiDAR sending and receiving the signal.

update(frame, participants, participant_ids, prev_road_id_set=None, prev_participant_id_set=None, position=None, heading=None)

This function is used to update the lidar's position and obtain the geometry data under specific rendering paradigm.

Parameters:

  • frame (int) –

    The frame of the observation.

  • participants (Dict) –

    The participants in the scenario.

  • participant_ids (List) –

    The list of participant IDs to be rendered.

  • prev_road_id_set (Set, default: None ) –

    The set of road IDs that were rendered in the previous frame. Defaults to None.

  • prev_participant_id_set (Set, default: None ) –

    The set of participant IDs that were rendered in the previous frame. Defaults to None.

  • position (Point, default: None ) –

    The position of the lidar. Defaults to None.

  • heading (float, default: None ) –

    The heading of the object that the lidar is attached to. Defaults to None.

Returns:

  • geometry_data ( Dict ) –

    The geometry data to be rendered in unified format.

  • road_id_set ( Set ) –

    The set of road IDs that were rendered in the current frame. Always an empty set for lidar.

  • participant_id_set ( Set ) –

    The set of participant IDs that were rendered in the current frame. Always an empty set for lidar.