Gazebo Sensors

API Reference

9.0.0

Camera Sensor Class. More...

#include <CameraSensor.hh>

Public Member Functions

 CameraSensor ()
 constructor
 
virtual ~CameraSensor ()
 destructor
 
double Baseline () const
 Get baseline for stereo cameras.
 
gz::common::ConnectionPtr ConnectImageCallback (std::function< void(const gz::msgs::Image &)> _callback)
 Set a callback to be called when image frame data is generated.
 
virtual bool HasConnections () const override
 Check if there are any subscribers.
 
virtual bool HasImageConnections () const
 Check if there are any image subscribers.
 
virtual bool HasInfoConnections () const
 Check if there are any info subscribers.
 
virtual unsigned int ImageHeight () const
 Get image height.
 
virtual unsigned int ImageWidth () const
 Get image width.
 
std::string InfoTopic () const
 Topic where camera info is published.
 
virtual bool Init () override
 Initialize values in the sensor.
 
virtual bool Load (const sdf::Sensor &_sdf) override
 Load the sensor based on data from an sdf::Sensor object.
 
virtual bool Load (sdf::ElementPtr _sdf) override
 Load the sensor with SDF parameters.
 
const std::stringOpticalFrameId () const
 Get the camera optical frame.
 
virtual rendering::CameraPtr RenderingCamera () const
 Get pointer to rendering camera object.
 
void SetBaseline (double _baseline)
 Set baseline for stereo cameras. This is used to populate the projection matrix in the camera info message.
 
virtual void SetScene (gz::rendering::ScenePtr _scene) override
 Set the rendering scene.
 
virtual bool Update (const std::chrono::steady_clock::duration &_now) override
 Force the sensor to generate data.
 
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.
 
void UpdateLensIntrinsicsAndProjection (rendering::CameraPtr _camera, sdf::Camera &_cameraSdf)
 Set camera lens intrinsics and projection based on values from SDF. If the camera SDF does not contain intrinsic or projection parameters, the camera will not be updated. Instead, the camera SDF will be updated with intrinsic and projection values computed manually from current camera intrinsic properties.
 
- Public Member Functions inherited from RenderingSensor
virtual ~RenderingSensor ()
 destructor
 
bool ManualSceneUpdate () const
 Get whether the scene graph is updated manually. Defaults to false.
 
void Render ()
 Render update. This performs the actual render operation.
 
rendering::ScenePtr Scene () const
 Get the rendering scene.
 
void SetManualSceneUpdate (bool _manual)
 Set whether to update the scene graph manually. If set to true, it is expected that rendering::Scene::PreRender is called manually before calling Render()
 
virtual void SetScene (rendering::ScenePtr _scene)
 Set the rendering scene.
 
- Public Member Functions inherited from Sensor
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.
 
bool HasPendingTrigger () const
 Whether the sensor has a pending trigger.
 
SensorId Id () const
 Get the sensor's ID.
 
bool IsActive () const
 Get whether the sensor is enabled or not.
 
bool IsTriggered () const
 Whether the sensor trigger mode is enabled.
 
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.
 
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

bool AdvertiseInfo ()
 Advertise camera info topic.
 
bool AdvertiseInfo (const std::string &_topic)
 Advertise camera info topic. This version takes a string that allows one to override the camera_info topic.
 
void PopulateInfo (const sdf::Camera *_cameraSdf)
 Populate camera info message.
 
void PublishInfo (const std::chrono::steady_clock::duration &_now)
 Publish camera info message.
 
- Protected Member Functions inherited from RenderingSensor
 RenderingSensor ()
 constructor
 
void AddSensor (rendering::SensorPtr _sensor)
 Add a rendering::Sensor. Its render updates will be handled by this base class.
 
- Protected Member Functions inherited from Sensor
 Sensor ()
 constructor
 

Detailed Description

Camera Sensor Class.

This class creates images from a Gazebo Rendering scene. The scene must be created in advance and given to Manager::Init(). It offers both a gz-transport interface and a direct C++ API to access the image data. The API works by setting a callback to be called with image data.

Constructor & Destructor Documentation

◆ CameraSensor()

constructor

◆ ~CameraSensor()

virtual ~CameraSensor ( )
virtual

destructor

Member Function Documentation

◆ AdvertiseInfo() [1/2]

bool AdvertiseInfo ( )
protected

Advertise camera info topic.

Returns
True if successful.

◆ AdvertiseInfo() [2/2]

bool AdvertiseInfo ( const std::string _topic)
protected

Advertise camera info topic. This version takes a string that allows one to override the camera_info topic.

Parameters
[in]_topicThe topic on which camera info is to be published.
Returns
True if successful.

◆ Baseline()

double Baseline ( ) const

Get baseline for stereo cameras.

Returns
The distance from the 1st camera, in meters.

◆ ConnectImageCallback()

gz::common::ConnectionPtr ConnectImageCallback ( std::function< void(const gz::msgs::Image &)>  _callback)

Set a callback to be called when image frame data is generated.

Parameters
[in]_callbackThis callback will be called every time the camera produces image data. The Update function will be blocked while the callbacks are executed.
Remarks
Do not block inside of the callback.
Returns
A connection pointer that must remain in scope. When the connection pointer falls out of scope, the connection is broken.

◆ HasConnections()

virtual bool HasConnections ( ) const
overridevirtual

Check if there are any subscribers.

Returns
True if there are subscribers, false otherwise

Reimplemented from Sensor.

Reimplemented in BoundingBoxCameraSensor, DepthCameraSensor, RgbdCameraSensor, SegmentationCameraSensor, ThermalCameraSensor, and WideAngleCameraSensor.

◆ HasImageConnections()

virtual bool HasImageConnections ( ) const
virtual

Check if there are any image subscribers.

Returns
True if there are image subscribers, false otherwise

◆ HasInfoConnections()

virtual bool HasInfoConnections ( ) const
virtual

Check if there are any info subscribers.

Returns
True if there are info subscribers, false otherwise

◆ ImageHeight()

virtual unsigned int ImageHeight ( ) const
virtual

◆ ImageWidth()

virtual unsigned int ImageWidth ( ) const
virtual

◆ InfoTopic()

std::string InfoTopic ( ) const

Topic where camera info is published.

Returns
Camera info topic.

◆ Init()

virtual bool Init ( )
overridevirtual

Initialize values in the sensor.

Returns
True on success

Reimplemented from Sensor.

Reimplemented in BoundingBoxCameraSensor, DepthCameraSensor, RgbdCameraSensor, SegmentationCameraSensor, ThermalCameraSensor, and WideAngleCameraSensor.

◆ Load() [1/2]

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

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

Parameters
[in]_sdfSDF Sensor parameters.
Returns
true if loading was successful

Reimplemented from Sensor.

Reimplemented in BoundingBoxCameraSensor, DepthCameraSensor, RgbdCameraSensor, SegmentationCameraSensor, ThermalCameraSensor, and WideAngleCameraSensor.

◆ Load() [2/2]

virtual bool Load ( sdf::ElementPtr  _sdf)
overridevirtual

Load the sensor with SDF parameters.

Parameters
[in]_sdfSDF Sensor parameters.
Returns
true if loading was successful

Reimplemented from Sensor.

Reimplemented in BoundingBoxCameraSensor, DepthCameraSensor, RgbdCameraSensor, SegmentationCameraSensor, ThermalCameraSensor, and WideAngleCameraSensor.

◆ OpticalFrameId()

const std::string & OpticalFrameId ( ) const

Get the camera optical frame.

Returns
The camera optical frame

◆ PopulateInfo()

void PopulateInfo ( const sdf::Camera *  _cameraSdf)
protected

Populate camera info message.

Parameters
[in]_cameraSdfPointer to SDF object containing camera information.

◆ PublishInfo()

void PublishInfo ( const std::chrono::steady_clock::duration &  _now)
protected

Publish camera info message.

Parameters
[in]_nowThe current time

◆ RenderingCamera()

virtual rendering::CameraPtr RenderingCamera ( ) const
virtual

Get pointer to rendering camera object.

Returns
Camera in Gazebo Rendering.

Reimplemented in WideAngleCameraSensor.

◆ SetBaseline()

void SetBaseline ( double  _baseline)

Set baseline for stereo cameras. This is used to populate the projection matrix in the camera info message.

Parameters
[in]_baselineThe distance from the 1st camera, in meters.

◆ SetScene()

virtual void SetScene ( gz::rendering::ScenePtr  _scene)
overridevirtual

Set the rendering scene.

Parameters
[in]_scenePointer to the scene

Reimplemented in DepthCameraSensor, RgbdCameraSensor, SegmentationCameraSensor, ThermalCameraSensor, and WideAngleCameraSensor.

◆ Update() [1/3]

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

Force the sensor to generate data.

Parameters
[in]_nowThe current time
Returns
true if the update was successfull

Implements Sensor.

Reimplemented in BoundingBoxCameraSensor, DepthCameraSensor, RgbdCameraSensor, SegmentationCameraSensor, ThermalCameraSensor, and WideAngleCameraSensor.

◆ Update() [2/3]

virtual bool Update ( const std::chrono::steady_clock::duration &  _now)
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()

Implements Sensor.

Reimplemented in DepthCameraSensor, RgbdCameraSensor, SegmentationCameraSensor, ThermalCameraSensor, and WideAngleCameraSensor.

◆ Update() [3/3]

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.

◆ UpdateLensIntrinsicsAndProjection()

void UpdateLensIntrinsicsAndProjection ( rendering::CameraPtr  _camera,
sdf::Camera &  _cameraSdf 
)

Set camera lens intrinsics and projection based on values from SDF. If the camera SDF does not contain intrinsic or projection parameters, the camera will not be updated. Instead, the camera SDF will be updated with intrinsic and projection values computed manually from current camera intrinsic properties.

Parameters
[in]_cameraCamera to set intrinsic and projection params.
[in,out]_cameraSdfCamera sdf with intrinisc and projection parameters.

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