Graphical Sensor

Author: Marcelo Jacinto (marcelo.jacinto@tecnico.ulisboa.pt)
License: BSD-3-Clause. Copyright (c) 2024, Marcelo Jacinto. All rights reserved.
Description: Definition of the Sensor class which is used as the base for all the sensors.

Classes:

GraphicalSensor

The base class for implementing a graphical sensor (such as a camera)

class pegasus.simulator.logic.graphical_sensors.graphical_sensor.GraphicalSensor

Bases: object

The base class for implementing a graphical sensor (such as a camera)

update_period

The period for each sensor update: update_period = 1 / update_rate (in s).

Type:

float

Methods:

__init__(sensor_type, update_rate)

param sensor_type:

A name that describes the type of sensor

config_from_dict(config_dict)

Method that should be implemented by the class that inherits Sensor.

initialize(vehicle)

A method that can be invoked when the simulation is starting to give access to the control backend to the entire vehicle object.

reset()

Method that when implemented, should handle the reset of the vehicle simulation to its original state

start()

Method that when implemented should handle the begining of the simulation of vehicle

stop()

Method that when implemented should handle the stopping of the simulation of vehicle

update(state, dt)

Method that should be implemented by the class that inherits Sensor.

update_at_rate()

Decorator function used to check if the time elapsed between the last sensor update call and the current sensor update call is higher than the defined update_rate of the sensor.

Attributes:

sensor_type

(str) A name that describes the type of sensor.

state

(dict) A dictionary which contains the data produced by the sensor at any given time.

update_rate

(float) The rate at which the data in the sensor should be refreshed (in Hz).

vehicle

A reference to the vehicle associated with this backend.

__init__(sensor_type, update_rate)
Parameters:
  • sensor_type (str) – A name that describes the type of sensor

  • update_rate (float) – The rate at which the data in the sensor should be refreshed (in Hz)

config_from_dict(config_dict)

Method that should be implemented by the class that inherits Sensor. This is where the configuration of the sensor based on a dictionary input should be performed.

Parameters:

config_dict (dict) – A dictionary containing the configurations of the sensor

initialize(vehicle)

A method that can be invoked when the simulation is starting to give access to the control backend to the entire vehicle object. Even though we provide update_sensor and update_state callbacks that are called at every physics step with the latest vehicle state and its sensor data, having access to the full vehicle object may prove usefull under some circumstances. This is nice to give users the possibility of overiding default vehicle behaviour via this control backend structure.

Parameters:

vehicle (Vehicle) – A reference to the vehicle that this sensor is associated with

reset()

Method that when implemented, should handle the reset of the vehicle simulation to its original state

start()

Method that when implemented should handle the begining of the simulation of vehicle

stop()

Method that when implemented should handle the stopping of the simulation of vehicle

update(state, dt)

Method that should be implemented by the class that inherits Sensor. This is where the actual implementation of the sensor should be performed.

Parameters:
  • state (State) – The current state of the vehicle.

  • dt (float) – The time elapsed between the previous and current function calls (s).

Returns:

(dict) A dictionary containing the current state of the sensor (the data produced by the sensor)

update_at_rate()

Decorator function used to check if the time elapsed between the last sensor update call and the current sensor update call is higher than the defined update_rate of the sensor. If so, we need to actually compute new values to simulate a measurement of the sensor at a given rate.

Parameters:

fnc (function) – The function that we want to enforce a specific update rate.

Examples

>>> class Camera(GraphicalSensor):
>>>    @GraphicalSensor.update_at_rate
>>>    def update(self):
>>>        (do some logic here)
Returns:

This decorator function returns None if there was no data to be produced by the sensor at the specified timestamp or a dict with the current state of the sensor otherwise.

Return type:

[None, Dict]

property sensor_type

(str) A name that describes the type of sensor.

property state

(dict) A dictionary which contains the data produced by the sensor at any given time.

property update_rate

(float) The rate at which the data in the sensor should be refreshed (in Hz).

property vehicle

A reference to the vehicle associated with this backend.

Returns:

A reference to the vehicle associated with this backend.

Return type:

Vehicle