gazebo-yarp-plugins
Gazebo Plugins exposing YARP interfaces.
Loading...
Searching...
No Matches
GazeboYarpPlugins::Handler Class Reference

Singleton object class. More...

#include <Handler.hh>

Public Member Functions

bool setRobot (gazebo::physics::Model *_model)
 Adds a new modelPointer to the "database".
 
gazebo::physics::Model * getRobot (const std::string &robotName) const
 Returns the pointer to the model matching the robot name.
 
void removeRobot (const std::string &robotName)
 Removes a robot from the internal database.
 
bool setSensor (gazebo::sensors::Sensor *_sensor)
 Adds a new sensorPointer to the "database".
 
gazebo::sensors::Sensor * getSensor (const std::string &sensorScopedName) const
 Returns the pointer to the sensor matching the sensor name.
 
std::vector< std::string > getSensors () const
 Returns the vector of all sensor names.
 
void removeSensor (const std::string &sensorName)
 Removes a sensor from the internal database.
 
bool setDevice (std::string deviceDatabaseKey, yarp::dev::PolyDriver *device2add)
 Adds a new yarp device pointer to the "database".
 
yarp::dev::PolyDriver * getDevice (const std::string &deviceDatabaseKey) const
 Returns the pointer to the device matching the deviceDatabaseKey.
 
void removeDevice (const std::string &deviceDatabaseKey)
 Removes a device from the internal database.
 
bool getDevicesAsPolyDriverList (const std::string &modelScopedName, yarp::dev::PolyDriverList &list, std::vector< std::string > &deviceScopedNames, const std::string &worldName)
 Returns a list of the opened devices.
 
bool getDevicesAsPolyDriverList (const std::string &modelScopedName, yarp::dev::PolyDriverList &list, std::vector< std::string > &deviceScopedNames)
 
void releaseDevicesInList (const std::vector< std::string > &deviceScopedNames)
 Decrease the usage count for the devices that are acquired with the getDevicesAsPolyDriverList.
 
template<typename T >
gazebo::event::ConnectionPtr ConnectDeviceCompletlyRemoved (T _subscriber)
 Add a callback when a device is completly removed, i.e.
 
 ~Handler ()
 Destructor.
 

Static Public Member Functions

static HandlergetHandler ()
 Returns the singleton intance of Handler class and creates it if it does not exist.
 

Detailed Description

Singleton object class.

You can use this class to save robots and sensors and retrieve it in other part of the application

Constructor & Destructor Documentation

◆ ~Handler()

GazeboYarpPlugins::Handler::~Handler ( )

Destructor.

Member Function Documentation

◆ getHandler()

Handler * GazeboYarpPlugins::Handler::getHandler ( )
static

Returns the singleton intance of Handler class and creates it if it does not exist.

Returns
the singleton handler

◆ setRobot()

bool GazeboYarpPlugins::Handler::setRobot ( gazebo::physics::Model * _model)

Adds a new modelPointer to the "database".

If it already exists and the pointer are the same return success, if pointers doesn't match returns error.

Parameters
_modelthe model to be added to the internal database
Returns
true if successfully added, or the model already exists. False otherwise.

◆ getRobot()

gazebo::physics::Model * GazeboYarpPlugins::Handler::getRobot ( const std::string & robotName) const

Returns the pointer to the model matching the robot name.

Parameters
robotNamerobot name to be looked for
Returns
the model matching the passed name

◆ removeRobot()

void GazeboYarpPlugins::Handler::removeRobot ( const std::string & robotName)

Removes a robot from the internal database.

Parameters
robotNamethe name of the robot to be removed

◆ setSensor()

bool GazeboYarpPlugins::Handler::setSensor ( gazebo::sensors::Sensor * _sensor)

Adds a new sensorPointer to the "database".

If the sensor already exists and the pointer are the same return success, if pointers doesn't match returns error.

Parameters
_sensorthe sensor to be added to the internal database
Returns
true if successfully added, or the model already exists. False otherwise.

◆ getSensor()

gazebo::sensors::Sensor * GazeboYarpPlugins::Handler::getSensor ( const std::string & sensorScopedName) const

Returns the pointer to the sensor matching the sensor name.

Parameters
sensorScopedNamesensor name to be looked for
Returns
the sensor matching the passed name

◆ getSensors()

std::vector< std::string > GazeboYarpPlugins::Handler::getSensors ( ) const

Returns the vector of all sensor names.

Returns
vector of all sensor names

◆ removeSensor()

void GazeboYarpPlugins::Handler::removeSensor ( const std::string & sensorName)

Removes a sensor from the internal database.

Parameters
sensorNamethe name of the sensor to be removed

◆ setDevice()

bool GazeboYarpPlugins::Handler::setDevice ( std::string deviceDatabaseKey,
yarp::dev::PolyDriver * device2add )

Adds a new yarp device pointer to the "database".

The YARP devices are stored in this database using the following schema:

  • For YARP devices created by Model plugins, the deviceDatabaseKey is defined as deviceDatabaseKey = Model::GetScopedName() + "::" + yarpDeviceName
  • For YARP devices created by Sensor plugins, the deviceDatabaseKey is defined as deviceDatabaseKey = Sensor::GetScopedName() + "::" + yarpDeviceName

yarpDeviceName is a non-scoped identifier of the specific instance of the YARP device, that is tipically specified by the Gazebo plugin configuration file, and corresponds to the name attribute of the device XML element when the device is created with the robotinterface XML format.

If the device with the same deviceDatabaseKey exists and the pointer are the same return success, if pointers doesn't match returns error.

Parameters
deviceDatabaseKeythe deviceDatabaseKey of the device to be added to the internal database
device2addthe pointer of the device to be added to the internal database
Returns
true if successfully added, or the device already exists. False otherwise.

◆ getDevice()

yarp::dev::PolyDriver * GazeboYarpPlugins::Handler::getDevice ( const std::string & deviceDatabaseKey) const

Returns the pointer to the device matching the deviceDatabaseKey.

Parameters
deviceDatabaseKeydeviceDatabaseKey to be looked for
Returns
the pointer to the device

◆ removeDevice()

void GazeboYarpPlugins::Handler::removeDevice ( const std::string & deviceDatabaseKey)

Removes a device from the internal database.

Parameters
deviceDatabaseKeythe deviceDatabaseKey of the device to be removed

◆ getDevicesAsPolyDriverList() [1/2]

bool GazeboYarpPlugins::Handler::getDevicesAsPolyDriverList ( const std::string & modelScopedName,
yarp::dev::PolyDriverList & list,
std::vector< std::string > & deviceScopedNames,
const std::string & worldName )

Returns a list of the opened devices.

Note
This list acts just as a view of the available devices, and it does not transfer or share ownership of the devices. The consumer code needs to make sure that the driver lifetime is longer then the consumer lifetime.

This method returns all the YARP devices that have been created by the specified model, and by all its nested model and sensors. As the PolyDriverList is effectively a map in which the key is a string and the value is the PolyDriver pointer, in this case the key of the PolyDriverList is the yarpDeviceName without any scope, i.e. not the deviceDatabaseKey .

If after removing the scope two devices have the same yarpDeviceName, the getModelDevicesAsPolyDriverList prints an error and returns false, while true is returned if everything works as expected.

◆ getDevicesAsPolyDriverList() [2/2]

bool GazeboYarpPlugins::Handler::getDevicesAsPolyDriverList ( const std::string & modelScopedName,
yarp::dev::PolyDriverList & list,
std::vector< std::string > & deviceScopedNames )

◆ releaseDevicesInList()

void GazeboYarpPlugins::Handler::releaseDevicesInList ( const std::vector< std::string > & deviceScopedNames)

Decrease the usage count for the devices that are acquired with the getDevicesAsPolyDriverList.

As Gazebo plugins are not destructed in the same order that they are loaded, it is necessary to keep a count of the users of each device, to ensure that is only destructed when no device are still attached to it.

This function needs to be called by any plugin that has called the getDevicesAsPolyDriverList method during the unload/destruction process.

◆ ConnectDeviceCompletlyRemoved()

template<typename T >
gazebo::event::ConnectionPtr GazeboYarpPlugins::Handler::ConnectDeviceCompletlyRemoved ( T _subscriber)
inline

Add a callback when a device is completly removed, i.e.

removeDevice is called and the usage counter goes to 0.


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