Ignition Sensors

API Reference

5.0.0

a base sensor class More...

#include <Sensor.hh>

Public Member Functions

virtual ~Sensor ()
 destructor More...
 
void AddSequence (ignition::msgs::Header *_msg, const std::string &_seqKey="default")
 Add a sequence number to an ignition::msgs::Header. This function can be called by a sensor that wants to add a sequence number to a sensor message in order to have improved accountability for generated sensor data. More...
 
SensorId Id () const
 Get the sensor's ID. More...
 
virtual bool Init ()
 Initialize values in the sensor. More...
 
virtual bool Load (const sdf::Sensor &_sdf)
 Load the sensor based on data from an sdf::Sensor object. More...
 
virtual bool Load (sdf::ElementPtr _sdf)
 Load the sensor with SDF parameters. More...
 
std::string Name () const
 Get name. More...
 
std::chrono::steady_clock::duration NextDataUpdateTime () const
 Return the next time the sensor will generate data. More...
 
ignition::common::Time NextUpdateTime () const
 Return the next time the sensor will generate data. More...
 
std::string Parent () const
 Get parent link of the sensor. More...
 
ignition::math::Pose3d Pose () const
 Get the current pose. More...
 
sdf::ElementPtr SDF () const
 Get the SDF used to load this sensor. More...
 
virtual void SetParent (const std::string &_parent)
 Set the parent of the sensor. More...
 
void SetPose (const ignition::math::Pose3d &_pose)
 Update the pose of the sensor. More...
 
bool SetTopic (const std::string &_topic)
 Set topic where sensor data is published. More...
 
void SetUpdateRate (const double _hz)
 Set the update rate of the sensor. An update rate of zero means that the sensor is updated every cycle. It's zero by default. Negative rates become zero. More...
 
std::string Topic () const
 Get topic where sensor data is published. More...
 
virtual bool Update (const common::Time &_now)=0
 Force the sensor to generate data. More...
 
virtual bool Update (const std::chrono::steady_clock::duration &_now)=0
 Force the sensor to generate data. More...
 
bool Update (const ignition::common::Time &_now, const bool _force)
 Update the sensor. More...
 
bool Update (const std::chrono::steady_clock::duration &_now, const bool _force)
 Update the sensor. More...
 
double UpdateRate () const
 Get the update rate of the sensor. More...
 

Protected Member Functions

 Sensor ()
 constructor More...
 

Detailed Description

a base sensor class

This class is a base for all sensor classes. It parses some common SDF elements in the <sensor> tag and is responsible for making sure sensors update at the right time.

Constructor & Destructor Documentation

◆ Sensor()

Sensor ( )
protected

constructor

◆ ~Sensor()

virtual ~Sensor ( )
virtual

destructor

Member Function Documentation

◆ AddSequence()

void AddSequence ( ignition::msgs::Header *  _msg,
const std::string _seqKey = "default" 
)

Add a sequence number to an ignition::msgs::Header. This function can be called by a sensor that wants to add a sequence number to a sensor message in order to have improved accountability for generated sensor data.

This function will add the following key-value pair to the data field in the provided ignition::msgs::Header msg.

  • key: "seq"
  • value: sequence_number

If the "seq" key already exists, then the value will be set without adding another key-value pair.

The sequence_number starts at zero, when a sensor is created, and is incremented by one each time this function is called.

Parameters
[in,out]_msgThe header which will receive the sequence.
[in]_seqKeyName of the sequence to use.

◆ Id()

SensorId Id ( ) const

Get the sensor's ID.

Returns
The sensor's ID.

◆ Init()

◆ Load() [1/2]

virtual bool Load ( const sdf::Sensor &  _sdf)
virtual

Load the sensor based on data from an sdf::Sensor object.

Parameters
[in]_sdfSDF <sensor> or <plugin> inside of <sensor>
Returns
true if loading was successful

Reimplemented in Lidar, GpuLidarSensor, DepthCameraSensor, ThermalCameraSensor, CameraSensor, RgbdCameraSensor, ImuSensor, MagnetometerSensor, AirPressureSensor, and AltimeterSensor.

◆ Load() [2/2]

virtual bool Load ( sdf::ElementPtr  _sdf)
virtual

Load the sensor with SDF parameters.

Parameters
[in]_sdfSDF <sensor> or <plugin> inside of <sensor>
Returns
true if loading was successful

Reimplemented in Lidar, GpuLidarSensor, DepthCameraSensor, ThermalCameraSensor, CameraSensor, LogicalCameraSensor, ImuSensor, MagnetometerSensor, AirPressureSensor, and AltimeterSensor.

◆ Name()

std::string Name ( ) const

Get name.

Returns
Name of sensor.

◆ NextDataUpdateTime()

std::chrono::steady_clock::duration NextDataUpdateTime ( ) const

Return the next time the sensor will generate data.

◆ NextUpdateTime()

ignition::common::Time NextUpdateTime ( ) const

Return the next time the sensor will generate data.

◆ Parent()

std::string Parent ( ) const

Get parent link of the sensor.

Returns
Parent link of sensor.

◆ Pose()

ignition::math::Pose3d Pose ( ) const

Get the current pose.

Returns
Current pose of the sensor.

◆ SDF()

sdf::ElementPtr SDF ( ) const

Get the SDF used to load this sensor.

Returns
Pointer to an SDF element that contains initialization information for this sensor.

◆ SetParent()

virtual void SetParent ( const std::string _parent)
virtual

Set the parent of the sensor.

Reimplemented in Lidar.

◆ SetPose()

void SetPose ( const ignition::math::Pose3d &  _pose)

Update the pose of the sensor.

◆ SetTopic()

bool SetTopic ( const std::string _topic)

Set topic where sensor data is published.

Parameters
[in]_topicTopic sensor publishes data to.
Returns
True if a valid topic was set.

◆ SetUpdateRate()

void SetUpdateRate ( const double  _hz)

Set the update rate of the sensor. An update rate of zero means that the sensor is updated every cycle. It's zero by default. Negative rates become zero.

Parameters
[in]_hzUpdate rate of sensor in Hertz.

◆ Topic()

std::string Topic ( ) const

Get topic where sensor data is published.

Returns
Topic sensor publishes data to

◆ Update() [1/4]

virtual bool Update ( const common::Time &  _now)
pure virtual

Force the sensor to generate data.

This method must be overridden by sensors. Subclasses should not not make a decision about whether or not they need to update. The Sensor class will make sure Update() is called at the correct time.

If a subclass wants to have a variable update rate it should call SetUpdateRate().

A subclass should return false if there was an error while updating

Parameters
[in]_nowThe current time
Returns
true if the update was successfull
See also
SetUpdateRate()

◆ Update() [2/4]

virtual bool Update ( const std::chrono::steady_clock::duration &  _now)
pure virtual

Force the sensor to generate data.

This method must be overridden by sensors. Subclasses should not not make a decision about whether or not they need to update. The Sensor class will make sure Update() is called at the correct time.

If a subclass wants to have a variable update rate it should call SetUpdateRate().

A subclass should return false if there was an error while updating

Parameters
[in]_nowThe current time
Returns
true if the update was successfull
See also
SetUpdateRate()

Implemented in DepthCameraSensor, ThermalCameraSensor, CameraSensor, LogicalCameraSensor, RgbdCameraSensor, GpuLidarSensor, ImuSensor, MagnetometerSensor, AirPressureSensor, AltimeterSensor, and Lidar.

◆ Update() [3/4]

bool Update ( const ignition::common::Time &  _now,
const bool  _force 
)

Update the sensor.

This is called by the manager, and is responsible for determining if this sensor needs to generate data at this time. If so, the subclasses' Update() method will be called.

Parameters
[in]_nowThe current time
[in]_forceForce the update to happen even if it's not time
Returns
True if the update was triggered (_force was true or _now >= next_update_time) and the sensor's bool Sensor::Update(std::chrono::steady_clock::time_point) function returned true. False otherwise.
Remarks
If forced the NextUpdateTime() will be unchanged.
See also
virtual bool Update(const common::Time &_name) = 0

◆ Update() [4/4]

bool Update ( const std::chrono::steady_clock::duration &  _now,
const bool  _force 
)

Update the sensor.

This is called by the manager, and is responsible for determining if this sensor needs to generate data at this time. If so, the subclasses' Update() method will be called.

Parameters
[in]_nowThe current time
[in]_forceForce the update to happen even if it's not time
Returns
True if the update was triggered (_force was true or _now >= next_update_time) and the sensor's bool Sensor::Update(std::chrono::steady_clock::time_point) function returned true. False otherwise.
Remarks
If forced the NextUpdateTime() will be unchanged.
See also
virtual bool Update(const common::Time &_name) = 0

◆ UpdateRate()

double UpdateRate ( ) const

Get the update rate of the sensor.

The update rate is the number of times per second a sensor should generate and output data.

Returns
_hz update rate of sensor.

The documentation for this class was generated from the following file: