ContactSensor Class Reference

Contact sensor. More...

#include <sensors/sensors.hh>

Inherits Sensor.

Public Member Functions

 ContactSensor ()
 Constructor. More...
 
virtual ~ContactSensor ()
 Destructor. More...
 
SensorCategory Category () const
 Get the category of the sensor. More...
 
event::ConnectionPtr ConnectUpdated (std::function< void()> _subscriber)
 Connect a signal that is triggered when the sensor is updated. More...
 
msgs::Contacts Contacts () const
 Get all the contacts for the ContactSensor. More...
 
std::map< std::string, physics::ContactContacts (const std::string &_collisionName) const
 Gets contacts of a collision. More...
 
void FillMsg (msgs::Sensor &_msg)
 fills a msgs::Sensor message. More...
 
unsigned int GetCollisionContactCount (const std::string &_collisionName) const
 Return the number of contacts for an observed collision. More...
 
unsigned int GetCollisionCount () const
 Get the number of collisions that the sensor is observing. More...
 
std::string GetCollisionName (unsigned int _index) const
 Get a collision name at index _index. More...
 
uint32_t Id () const
 Get the sensor's ID. More...
 
virtual void Init ()
 Initialize the sensor. More...
 
virtual bool IsActive () const
 Returns true if sensor generation is active. More...
 
common::Time LastMeasurementTime () const
 Return last measurement time. More...
 
common::Time LastUpdateTime () const
 Return last update time. More...
 
virtual void Load (const std::string &_worldName, sdf::ElementPtr _sdf)
 Load the sensor with SDF parameters. More...
 
virtual void Load (const std::string &_worldName)
 Load the sensor with default parameters. More...
 
std::string Name () const
 Get name. More...
 
virtual double NextRequiredTimestamp () const
 Get the next timestamp that will be used by the sensor. More...
 
NoisePtr Noise (const SensorNoiseType _type) const
 Get the sensor's noise model for a specified noise type. More...
 
uint32_t ParentId () const
 Get the sensor's parent's ID. More...
 
std::string ParentName () const
 Returns the name of the sensor parent. More...
 
virtual ignition::math::Pose3d Pose () const
 Get the current pose. More...
 
virtual void ResetLastUpdateTime ()
 Reset the lastUpdateTime to zero. More...
 
std::string ScopedName () const
 Get fully scoped name of the sensor. More...
 
virtual void SetActive (const bool _value)
 Set whether the sensor is active or not. More...
 
void SetParent (const std::string &_name, const uint32_t _id)
 Set the sensor's parent. More...
 
virtual void SetPose (const ignition::math::Pose3d &_pose)
 Set the current pose. More...
 
void SetUpdateRate (const double _hz)
 Set the update rate of the sensor. More...
 
virtual std::string Topic () const
 Returns the topic name as set in SDF. More...
 
std::string Type () const
 Get sensor type. More...
 
virtual void Update (const bool _force)
 Update the sensor. More...
 
double UpdateRate () const
 Get the update rate of the sensor. More...
 
bool Visualize () const
 Return true if user requests the sensor to be visualized via tag: <visualize>true</visualize> in SDF. More...
 
std::string WorldName () const
 Returns the name of the world the sensor is in. More...
 

Protected Member Functions

virtual void Fini ()
 Finalize the sensor. More...
 
virtual bool NeedsUpdate ()
 Return true if the sensor needs to be updated. More...
 
virtual bool UpdateImpl (const bool _force)
 This gets overwritten by derived sensor types. More...
 

Protected Attributes

bool active
 True if sensor generation is active. More...
 
std::vector< event::ConnectionPtrconnections
 All event connections. More...
 
common::Time lastMeasurementTime
 Stores last time that a sensor measurement was generated; this value must be updated within each sensor's UpdateImpl. More...
 
common::Time lastUpdateTime
 Time of the last update. More...
 
transport::NodePtr node
 Node for communication. More...
 
ignition::transport::Node nodeIgn
 Ignition transport node. More...
 
std::map< SensorNoiseType, NoisePtrnoises
 Noise added to sensor data. More...
 
uint32_t parentId
 The sensor's parent ID. More...
 
std::string parentName
 Name of the parent. More...
 
std::vector< SensorPluginPtrplugins
 All the plugins for the sensor. More...
 
ignition::math::Pose3d pose
 Pose of the sensor. More...
 
gazebo::rendering::ScenePtr scene
 Pointer to the Scene. More...
 
sdf::ElementPtr sdf
 Pointer the the SDF element for the sensor. More...
 
event::EventT< void()> updated
 Event triggered when a sensor is updated. More...
 
common::Time updatePeriod
 Desired time between updates, set indirectly by Sensor::SetUpdateRate. More...
 
gazebo::physics::WorldPtr world
 Pointer to the world. More...
 

Detailed Description

Contact sensor.

This sensor detects and reports contacts between objects

Constructor & Destructor Documentation

◆ ContactSensor()

Constructor.

◆ ~ContactSensor()

virtual ~ContactSensor ( )
virtual

Destructor.

Member Function Documentation

◆ Category()

SensorCategory Category ( ) const
inherited

Get the category of the sensor.

Returns
The category of the sensor.
See also
SensorCategory

◆ ConnectUpdated()

event::ConnectionPtr ConnectUpdated ( std::function< void()>  _subscriber)
inherited

Connect a signal that is triggered when the sensor is updated.

Parameters
[in]_subscriberCallback that receives the signal.
Returns
A pointer to the connection. This must be kept in scope.
See also
Sensor::DisconnectUpdated

◆ Contacts() [1/2]

msgs::Contacts Contacts ( ) const

Get all the contacts for the ContactSensor.

Returns
Message that contains contact information between collision pairs.

During ODEPhysics::UpdateCollisions, all collision pairs in the world are pushed into a buffer within ContactManager. Subsequently, World::Update invokes ContactManager::PublishContacts to publish all contacts generated within a timestep onto Gazebo topic ~/physics/contacts.

Each ContactSensor subscribes to the Gazebo ~/physics/contacts topic, retrieves all contact pairs in a time step and filters them wthin ContactSensor::OnContacts against <collision> body name specified by the ContactSensor SDF. All collision pairs between ContactSensor <collision> body and other bodies in the world are stored in an array inside contacts.proto.

Within each element of the contact.proto array inside contacts.proto, list of collisions between collision bodies (collision1 and collision 2) are stored in an array of elements, (position, normal, depth, wrench). A timestamp has also been added (time). Details are described below:

  • string collision1 name of the first collision object.
  • string collision2 name of the second collision object.
  • Vector3d position position of the contact joint in inertial frame.
  • Vector3d normal normal of the contact joint in inertial frame.
  • double depth intersection (penetration) depth of two collision bodies.
  • JointWrench wrench Forces and torques acting on both collision bodies. See joint_wrench.proto for details. The forces and torques are applied at the CG of perspective links for each collision body, specified in the inertial frame.
  • Time time time at which this contact happened.

◆ Contacts() [2/2]

std::map<std::string, physics::Contact> Contacts ( const std::string &  _collisionName) const

Gets contacts of a collision.

Parameters
[in]_collisionNameName of collision
Returns
Container of contacts

◆ FillMsg()

void FillMsg ( msgs::Sensor &  _msg)
inherited

fills a msgs::Sensor message.

Parameters
[out]_msgMessage to fill.

◆ Fini()

virtual void Fini ( )
protectedvirtual

Finalize the sensor.

Reimplemented from Sensor.

◆ GetCollisionContactCount()

unsigned int GetCollisionContactCount ( const std::string &  _collisionName) const

Return the number of contacts for an observed collision.

Parameters
[in]_collisionNameThe name of the observed collision.
Returns
The collision contact count.

◆ GetCollisionCount()

unsigned int GetCollisionCount ( ) const

Get the number of collisions that the sensor is observing.

Returns
Number of collisions.

◆ GetCollisionName()

std::string GetCollisionName ( unsigned int  _index) const

Get a collision name at index _index.

Parameters
[in]_indexIndex of collision in collection of collisions.
Returns
name of collision.

◆ Id()

uint32_t Id ( ) const
inherited

Get the sensor's ID.

Returns
The sensor's ID.

◆ Init()

virtual void Init ( )
virtual

Initialize the sensor.

Reimplemented from Sensor.

◆ IsActive()

virtual bool IsActive ( ) const
virtual

Returns true if sensor generation is active.

Returns
True if active, false if not.

Reimplemented from Sensor.

◆ LastMeasurementTime()

common::Time LastMeasurementTime ( ) const
inherited

Return last measurement time.

Returns
Time of last measurement.

◆ LastUpdateTime()

common::Time LastUpdateTime ( ) const
inherited

Return last update time.

Returns
Time of last update.

◆ Load() [1/2]

virtual void Load ( const std::string &  _worldName,
sdf::ElementPtr  _sdf 
)
virtual

Load the sensor with SDF parameters.

Parameters
[in]_sdfSDF Sensor parameters
[in]_worldNameName of world to load from

Reimplemented from Sensor.

◆ Load() [2/2]

virtual void Load ( const std::string &  _worldName)
virtual

Load the sensor with default parameters.

Parameters
[in]_worldNameName of world to load from.

Reimplemented from Sensor.

◆ Name()

std::string Name ( ) const
inherited

Get name.

Returns
Name of sensor.

◆ NeedsUpdate()

virtual bool NeedsUpdate ( )
protectedvirtualinherited

Return true if the sensor needs to be updated.

Returns
True when sensor should be updated.

Reimplemented in GpuRaySensor, and CameraSensor.

Referenced by Sensor::UpdateImpl().

◆ NextRequiredTimestamp()

virtual double NextRequiredTimestamp ( ) const
virtualinherited

Get the next timestamp that will be used by the sensor.

Returns
the timestamp

Reimplemented in GpuRaySensor, and CameraSensor.

◆ Noise()

NoisePtr Noise ( const SensorNoiseType  _type) const
inherited

Get the sensor's noise model for a specified noise type.

Parameters
[in]_typeIndex of the noise type. Refer to SensorNoiseType enumeration for possible indices
Returns
The sensor's noise model for the given noise type

◆ ParentId()

uint32_t ParentId ( ) const
inherited

Get the sensor's parent's ID.

Returns
The sensor's parent's ID.

◆ ParentName()

std::string ParentName ( ) const
inherited

Returns the name of the sensor parent.

The parent name is set by Sensor::SetParent.

Returns
Name of Parent.

◆ Pose()

virtual ignition::math::Pose3d Pose ( ) const
virtualinherited

Get the current pose.

Returns
Current pose of the sensor.
See also
SetPose()

◆ ResetLastUpdateTime()

virtual void ResetLastUpdateTime ( )
virtualinherited

Reset the lastUpdateTime to zero.

Reimplemented in GpuRaySensor, and CameraSensor.

◆ ScopedName()

std::string ScopedName ( ) const
inherited

Get fully scoped name of the sensor.

Returns
world_name::model_name::link_name::sensor_name.

◆ SetActive()

virtual void SetActive ( const bool  _value)
virtualinherited

Set whether the sensor is active or not.

Parameters
[in]_valueTrue if active, false if not.

Reimplemented in GpuRaySensor, and CameraSensor.

◆ SetParent()

void SetParent ( const std::string &  _name,
const uint32_t  _id 
)
inherited

Set the sensor's parent.

Parameters
[in]_nameThe sensor's parent's name.
[in]_idThe sensor's parent's ID.

◆ SetPose()

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

Set the current pose.

Parameters
[in]_poseNew pose of the sensor.
See also
Pose()

◆ SetUpdateRate()

void SetUpdateRate ( const double  _hz)
inherited

Set the update rate of the sensor.

Parameters
[in]_hzupdate rate of sensor.

◆ Topic()

virtual std::string Topic ( ) const
virtualinherited

Returns the topic name as set in SDF.

Returns
Topic name.

Reimplemented in GpuRaySensor, CameraSensor, RaySensor, ForceTorqueSensor, LogicalCameraSensor, MultiCameraSensor, SonarSensor, and WirelessTransceiver.

◆ Type()

std::string Type ( ) const
inherited

Get sensor type.

Returns
Type of sensor.

◆ Update()

virtual void Update ( const bool  _force)
virtualinherited

Update the sensor.

Parameters
[in]_forceTrue to force update, false otherwise.

Reimplemented in GpuRaySensor, and CameraSensor.

◆ UpdateImpl()

virtual bool UpdateImpl ( const bool  )
protectedvirtual

This gets overwritten by derived sensor types.

This function is called during Sensor::Update. And in turn, Sensor::Update is called by SensorManager::Update

Parameters
[in]_forceTrue if update is forced, false if not
Returns
True if the sensor was updated.

Reimplemented from Sensor.

◆ UpdateRate()

double UpdateRate ( ) const
inherited

Get the update rate of the sensor.

Returns
_hz update rate of sensor. Returns 0 if unthrottled.

◆ Visualize()

bool Visualize ( ) const
inherited

Return true if user requests the sensor to be visualized via tag: <visualize>true</visualize> in SDF.

Returns
True if visualized, false if not.

◆ WorldName()

std::string WorldName ( ) const
inherited

Returns the name of the world the sensor is in.

Returns
Name of the world.

Member Data Documentation

◆ active

bool active
protectedinherited

True if sensor generation is active.

◆ connections

std::vector<event::ConnectionPtr> connections
protectedinherited

All event connections.

◆ lastMeasurementTime

common::Time lastMeasurementTime
protectedinherited

Stores last time that a sensor measurement was generated; this value must be updated within each sensor's UpdateImpl.

◆ lastUpdateTime

common::Time lastUpdateTime
protectedinherited

Time of the last update.

◆ node

transport::NodePtr node
protectedinherited

Node for communication.

◆ nodeIgn

ignition::transport::Node nodeIgn
protectedinherited

Ignition transport node.

◆ noises

std::map<SensorNoiseType, NoisePtr> noises
protectedinherited

Noise added to sensor data.

◆ parentId

uint32_t parentId
protectedinherited

The sensor's parent ID.

◆ parentName

std::string parentName
protectedinherited

Name of the parent.

◆ plugins

std::vector<SensorPluginPtr> plugins
protectedinherited

All the plugins for the sensor.

◆ pose

ignition::math::Pose3d pose
protectedinherited

Pose of the sensor.

◆ scene

gazebo::rendering::ScenePtr scene
protectedinherited

Pointer to the Scene.

◆ sdf

sdf::ElementPtr sdf
protectedinherited

Pointer the the SDF element for the sensor.

◆ updated

event::EventT<void()> updated
protectedinherited

Event triggered when a sensor is updated.

◆ updatePeriod

common::Time updatePeriod
protectedinherited

Desired time between updates, set indirectly by Sensor::SetUpdateRate.

◆ world

gazebo::physics::WorldPtr world
protectedinherited

Pointer to the world.


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