Gazebo Sensors

API Reference

3.6.0

a base sensor class More...

#include <Sensor.hh>

Public Member Functions

virtual ~Sensor ()
 destructor More...
 
void AddSequence (gz::msgs::Header *_msg, const std::string &_seqKey="default")
 Add a sequence number to an gz::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...
 
bool EnableMetrics () const
 Get flag state for enabling performance metrics publication. More...
 
std::string FrameId () const
 FrameId. 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...
 
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...
 
gz::math::Pose3d Pose () const
 Get the current pose. More...
 
void PublishMetrics (const std::chrono::duration< double > &_now)
 Publishes information about the performance of the sensor. This method is called by Update(). More...
 
sdf::ElementPtr SDF () const
 Get the SDF used to load this sensor. More...
 
void SetEnableMetrics (bool _enableMetrics)
 Set flag to enable publishing performance metrics. More...
 
void SetFrameId (const std::string &_frameId)
 Set Frame ID of the sensor. More...
 
virtual void SetParent (const std::string &_parent)
 Set the parent of the sensor. More...
 
void SetPose (const gz::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. \detail 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...
 
bool Update (const common::Time &_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 ( gz::msgs::Header *  _msg,
const std::string _seqKey = "default" 
)

Add a sequence number to an gz::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 gz::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.

◆ EnableMetrics()

bool EnableMetrics ( ) const

Get flag state for enabling performance metrics publication.

Returns
True if performance metrics are enabled, false otherwise.

◆ FrameId()

std::string FrameId ( ) const

FrameId.

Returns
FrameId of sensor.

◆ 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 DepthCameraSensor, ThermalCameraSensor, CameraSensor, GpuLidarSensor, Lidar, 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 DepthCameraSensor, ThermalCameraSensor, CameraSensor, GpuLidarSensor, Lidar, LogicalCameraSensor, ImuSensor, MagnetometerSensor, AirPressureSensor, and AltimeterSensor.

◆ Name()

std::string Name ( ) const

Get name.

Returns
Name of sensor.

◆ NextUpdateTime()

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

gz::math::Pose3d Pose ( ) const

Get the current pose.

Returns
Current pose of the sensor.

◆ PublishMetrics()

void PublishMetrics ( const std::chrono::duration< double > &  _now)

Publishes information about the performance of the sensor. This method is called by Update().

Parameters
[in]_nowCurrent time.

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

◆ SetEnableMetrics()

void SetEnableMetrics ( bool  _enableMetrics)

Set flag to enable publishing performance metrics.

Parameters
[in]_enableMetricsTrue to enable.

◆ SetFrameId()

void SetFrameId ( const std::string _frameId)

Set Frame ID of the sensor.

Parameters
[in]_frameIdFrame ID of the sensor

◆ SetParent()

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

Set the parent of the sensor.

Reimplemented in Lidar.

◆ SetPose()

void SetPose ( const gz::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. \detail 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/2]

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

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

◆ Update() [2/2]

bool Update ( const 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(const common::Time &_now) 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: