Gazebo Sensors

API Reference

9.0.0

a base sensor class More...

#include <Sensor.hh>

Public Member Functions

virtual ~Sensor ()
 destructor
 
void AddSequence (gz::msgs::Header *_msg, const std::string &_seqKey="default")
 Add a sequence number to a 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.
 
bool EnableMetrics () const
 Get flag state for enabling performance metrics publication.
 
std::string FrameId () const
 FrameId.
 
virtual bool HasConnections () const
 Check if there are any subscribers.
 
bool HasPendingTrigger () const
 Whether the sensor has a pending trigger.
 
SensorId Id () const
 Get the sensor's ID.
 
virtual bool Init ()
 Initialize values in the sensor This will set the next update time to zero. This is particularly useful if simulation time has jumped backward, for example during a seek backward in a log file.
 
bool IsActive () const
 Get whether the sensor is enabled or not.
 
bool IsTriggered () const
 Whether the sensor trigger mode is enabled.
 
virtual bool Load (const sdf::Sensor &_sdf)
 Load the sensor based on data from an sdf::Sensor object.
 
virtual bool Load (sdf::ElementPtr _sdf)
 Load the sensor with SDF parameters.
 
std::string Name () const
 Get name.
 
std::chrono::steady_clock::duration NextDataUpdateTime () const
 Return the next time the sensor will generate data.
 
std::string Parent () const
 Get parent link of the sensor.
 
gz::math::Pose3d Pose () const
 Get the current pose.
 
void PublishMetrics (const std::chrono::duration< double > &_now)
 Publishes information about the performance of the sensor. This method is called by Update().
 
sdf::ElementPtr SDF () const
 Get the SDF used to load this sensor.
 
void SetActive (bool _active)
 Enable or disable the sensor. Disabled sensors will not generate or publish data unless Update is called with the '_force' argument set to true.
 
void SetEnableMetrics (bool _enableMetrics)
 Set flag to enable publishing performance metrics.
 
void SetFrameId (const std::string &_frameId)
 Set Frame ID of the sensor.
 
void SetNextDataUpdateTime (const std::chrono::steady_clock::duration &_time)
 Manually set the next time the sensor will generate data Useful for accomodating jumps backwards in time as well as specifying updates for non-uniformly updating sensors.
 
virtual void SetParent (const std::string &_parent)
 Set the parent of the sensor.
 
void SetPose (const gz::math::Pose3d &_pose)
 Update the pose of the sensor.
 
bool SetTopic (const std::string &_topic)
 Set topic where sensor data is published.
 
bool SetTriggered (bool _triggered, const std::string &_triggerTopic="")
 Enable or disable triggered mode. In this mode,.
 
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.
 
std::string Topic () const
 Get topic where sensor data is published.
 
virtual bool Update (const std::chrono::steady_clock::duration &_now)=0
 Force the sensor to generate data.
 
bool Update (const std::chrono::steady_clock::duration &_now, const bool _force)
 Update the sensor.
 
double UpdateRate () const
 Get the update rate of the sensor.
 

Protected Member Functions

 Sensor ()
 constructor
 

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

◆ HasConnections()

virtual bool HasConnections ( ) const
virtual

◆ HasPendingTrigger()

bool HasPendingTrigger ( ) const

Whether the sensor has a pending trigger.

Returns
True if the sensor is in trigger mode and has a pending trigger.

◆ Id()

SensorId Id ( ) const

Get the sensor's ID.

Returns
The sensor's ID.

◆ Init()

virtual bool Init ( )
virtual

Initialize values in the sensor This will set the next update time to zero. This is particularly useful if simulation time has jumped backward, for example during a seek backward in a log file.

Reimplemented in AirPressureSensor, AirSpeedSensor, AltimeterSensor, BoundingBoxCameraSensor, CameraSensor, DepthCameraSensor, ForceTorqueSensor, GpuLidarSensor, ImuSensor, Lidar, LogicalCameraSensor, MagnetometerSensor, NavSatSensor, RgbdCameraSensor, SegmentationCameraSensor, ThermalCameraSensor, and WideAngleCameraSensor.

◆ IsActive()

bool IsActive ( ) const

Get whether the sensor is enabled or not.

Returns
True if the sensor is active, false otherwise.
See also
SetActive

◆ IsTriggered()

bool IsTriggered ( ) const

Whether the sensor trigger mode is enabled.

Returns
True if the sensor is in trigger mode, false otherwise

◆ 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 AirPressureSensor, AirSpeedSensor, AltimeterSensor, BoundingBoxCameraSensor, CameraSensor, DepthCameraSensor, DopplerVelocityLog, ForceTorqueSensor, GpuLidarSensor, ImuSensor, Lidar, MagnetometerSensor, NavSatSensor, RgbdCameraSensor, SegmentationCameraSensor, ThermalCameraSensor, and WideAngleCameraSensor.

◆ 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 AirPressureSensor, AirSpeedSensor, AltimeterSensor, BoundingBoxCameraSensor, CameraSensor, DepthCameraSensor, DopplerVelocityLog, ForceTorqueSensor, GpuLidarSensor, ImuSensor, Lidar, LogicalCameraSensor, MagnetometerSensor, NavSatSensor, RgbdCameraSensor, SegmentationCameraSensor, ThermalCameraSensor, and WideAngleCameraSensor.

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

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

◆ SetActive()

void SetActive ( bool  _active)

Enable or disable the sensor. Disabled sensors will not generate or publish data unless Update is called with the '_force' argument set to true.

Parameters
[in]_activeTrue to set the sensor to be active, false to disable the sensor.
See also
IsActive

◆ 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

◆ SetNextDataUpdateTime()

void SetNextDataUpdateTime ( const std::chrono::steady_clock::duration &  _time)

Manually set the next time the sensor will generate data Useful for accomodating jumps backwards in time as well as specifying updates for non-uniformly updating sensors.

Parameters
[in]_timeThe next update time

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

◆ SetTriggered()

bool SetTriggered ( bool  _triggered,
const std::string _triggerTopic = "" 
)

Enable or disable triggered mode. In this mode,.

  • the sensor will only update if a new message has been published to the passed _triggerTopic since the last update,
  • until the next message is published on _triggerTopic, all Update calls will return false, and
  • if the sensor has a pending trigger, the next Update call will ignore the sensor's update rate and try generate data immediately.
    Parameters
    [in]_triggeredSets triggered mode if true and disables it if false.
    [in]_triggerTopicThe topic on which the sensor will listen for trigger messages in triggered mode. If _triggered is true, this value should not be empty. If _triggered is false, this value is ignored.
    Returns
    True if the operation succeeded.

◆ 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/2]

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 AirPressureSensor, AirSpeedSensor, AltimeterSensor, BoundingBoxCameraSensor, CameraSensor, DepthCameraSensor, DopplerVelocityLog, ForceTorqueSensor, GpuLidarSensor, ImuSensor, Lidar, LogicalCameraSensor, MagnetometerSensor, NavSatSensor, RgbdCameraSensor, SegmentationCameraSensor, ThermalCameraSensor, WideAngleCameraSensor, AirPressureSensor, AirSpeedSensor, AltimeterSensor, CameraSensor, ForceTorqueSensor, ImuSensor, LogicalCameraSensor, and MagnetometerSensor.

◆ Update() [2/2]

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 performed (_force was true or _now >= next_update_time or sensor had a pending trigger) 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.

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