Sensor
Classes:
The base class for implementing a sensor |
- class pegasus.simulator.logic.sensors.sensor.Sensor
Bases:
object
The base class for implementing a sensor
- update_period
The period for each sensor update: update_period = 1 / update_rate (in s).
- Type:
- origin_lat
The latitude of the origin of the world in degrees (might get used by some sensors).
- Type:
- origin_lon
The longitude of the origin of the world in degrees (might get used by some sensors).
- Type:
- origin_alt
The altitude of the origin of the world relative to sea water level (might get used by some sensors)
- Type:
Methods:
__init__
(sensor_type, update_rate)Initialize the Sensor class
config_from_dict
(config_dict)Method that should be implemented by the class that inherits Sensor.
initialize
(vehicle, origin_lat, origin_lon, ...)Method that initializes the sensor latitude, longitude and altitude attributes.
reset
()Method that when implemented, should handle the reset of the vehicle simulation to its original state
set_update_rate
(update_rate)Method that changes the update rate and period of the sensor
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.
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:
(str) A name that describes the type of sensor.
(dict) A dictionary which contains the data produced by the sensor at any given time.
(float) The rate at which the data in the sensor should be refreshed (in Hz).
- __init__(sensor_type, update_rate)
Initialize the Sensor class
- 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, origin_lat, origin_lon, origin_alt)
Method that initializes the sensor latitude, longitude and altitude attributes.
Note
Given that some sensors require the knowledge of the latitude, longitude and altitude of the [0, 0, 0] coordinate of the world, then we might as well just save this information for whatever sensor that comes
- Parameters:
vehicle (Vehicle) – A reference to the vehicle that this sensor is associated with
origin_lat (float) – The latitude of the origin of the world in degrees (might get used by some sensors).
origin_lon (float) – The longitude of the origin of the world in degrees (might get used by some sensors).
origin_alt (float) – The altitude of the origin of the world relative to sea water level (might get used by some sensors).
- reset()
Method that when implemented, should handle the reset of the vehicle simulation to its original state
- set_update_rate(update_rate)
Method that changes the update rate and period of the sensor
- Parameters:
update_rate (float) – The new rate at which the data in the sensor should be refreshed (in Hz)
- 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.
- 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 GPS(Sensor): >>> @Sensor.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).