gazebo-yarp-plugins
Gazebo Plugins exposing YARP interfaces.
|
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 Handler * | getHandler () |
Returns the singleton intance of Handler class and creates it if it does not exist. | |
Singleton object class.
You can use this class to save robots and sensors and retrieve it in other part of the application
GazeboYarpPlugins::Handler::~Handler | ( | ) |
Destructor.
|
static |
Returns the singleton intance of Handler class and creates it if it does not exist.
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.
_model | the model to be added to the internal database |
gazebo::physics::Model * GazeboYarpPlugins::Handler::getRobot | ( | const std::string & | robotName | ) | const |
Returns the pointer to the model matching the robot name.
robotName | robot name to be looked for |
void GazeboYarpPlugins::Handler::removeRobot | ( | const std::string & | robotName | ) |
Removes a robot from the internal database.
robotName | the name of the robot to be removed |
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.
_sensor | the sensor to be added to the internal database |
gazebo::sensors::Sensor * GazeboYarpPlugins::Handler::getSensor | ( | const std::string & | sensorScopedName | ) | const |
Returns the pointer to the sensor matching the sensor name.
sensorScopedName | sensor name to be looked for |
std::vector< std::string > GazeboYarpPlugins::Handler::getSensors | ( | ) | const |
Returns the vector of all sensor names.
void GazeboYarpPlugins::Handler::removeSensor | ( | const std::string & | sensorName | ) |
Removes a sensor from the internal database.
sensorName | the name of the sensor to be removed |
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:
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.
deviceDatabaseKey | the deviceDatabaseKey of the device to be added to the internal database |
device2add | the pointer of the device to be added to the internal database |
yarp::dev::PolyDriver * GazeboYarpPlugins::Handler::getDevice | ( | const std::string & | deviceDatabaseKey | ) | const |
Returns the pointer to the device matching the deviceDatabaseKey.
deviceDatabaseKey | deviceDatabaseKey to be looked for |
void GazeboYarpPlugins::Handler::removeDevice | ( | const std::string & | deviceDatabaseKey | ) |
Removes a device from the internal database.
deviceDatabaseKey | the deviceDatabaseKey of the device to be removed |
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.
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.
bool GazeboYarpPlugins::Handler::getDevicesAsPolyDriverList | ( | const std::string & | modelScopedName, |
yarp::dev::PolyDriverList & | list, | ||
std::vector< std::string > & | deviceScopedNames ) |
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.
|
inline |
Add a callback when a device is completly removed, i.e.
removeDevice is called and the usage counter goes to 0.