Skip to content

Commit

Permalink
Added proper wrapper detaching for solving issue #58
Browse files Browse the repository at this point in the history
  • Loading branch information
traversaro committed Apr 1, 2014
1 parent fb8b11d commit fa39668
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 6 deletions.
2 changes: 2 additions & 0 deletions include/gazebo_yarp_plugins/ForceTorque.hh
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

#include <gazebo/gazebo.hh>
#include <yarp/os/Network.h>
#include <yarp/dev/Wrapper.h>
#include <yarp/dev/PolyDriver.h>
#include <string>

Expand All @@ -31,6 +32,7 @@ namespace gazebo
sensors::ForceTorqueSensor* parentSensor;
yarp::os::Network _yarp;
yarp::dev::PolyDriver _forcetorque_wrapper;
yarp::dev::IMultipleWrapper *_iWrap;
yarp::dev::PolyDriver _forcetorque_driver;

std::string _sensorName;
Expand Down
1 change: 1 addition & 0 deletions include/gazebo_yarp_plugins/JointSensors.hh
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ private:

yarp::os::Network _yarp;
yarp::dev::PolyDriver _jointsensors_wrapper;
yarp::dev::IMultipleWrapper *_iWrap;
yarp::dev::PolyDriver _jointsensors_driver;
yarp::os::Property _parameters;

Expand Down
1 change: 1 addition & 0 deletions src/gazebo_plugins/ControlBoard.cc
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ GZ_REGISTER_MODEL_PLUGIN(GazeboYarpControlBoard)

GazeboYarpControlBoard::~GazeboYarpControlBoard()
{
_iWrap->detachAll();
_wrapper.close();
_controlBoard.close();
GazeboYarpPlugins::Handler::getHandler()->removeRobot(_robotName);
Expand Down
6 changes: 3 additions & 3 deletions src/gazebo_plugins/ForceTorque.cc
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ void GazeboYarpForceTorque::Init()
GazeboYarpForceTorque::~GazeboYarpForceTorque()
{
std::cout<<"*** GazeboYarpForceTorque closing ***"<<std::endl;
_iWrap->detachAll();
_forcetorque_wrapper.close();
_forcetorque_driver.close();
GazeboYarpPlugins::Handler::getHandler()->removeSensor(_sensorName);
Expand Down Expand Up @@ -108,17 +109,16 @@ void GazeboYarpForceTorque::Load(sensors::SensorPtr _sensor, sdf::ElementPtr _sd
}

//Attach the driver to the wrapper
::yarp::dev::IMultipleWrapper * iWrap;
::yarp::dev::PolyDriverList driver_list;

if( !_forcetorque_wrapper.view(iWrap) ) {
if( !_forcetorque_wrapper.view(_iWrap) ) {
std::cerr << "GazeboYarpForceTorque : error in loading wrapper" << std::endl;
return;
}

driver_list.push(&_forcetorque_driver,"dummy");

if( iWrap->attachAll(driver_list) ) {
if( _iWrap->attachAll(driver_list) ) {
std::cerr << "GazeboYarpForceTorque : wrapper was connected with driver " << std::endl;
} else {
std::cerr << "GazeboYarpForceTorque : error in connecting wrapper and device " << std::endl;
Expand Down
6 changes: 3 additions & 3 deletions src/gazebo_plugins/JointSensors.cc
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ void GazeboYarpJointSensors::Init()
GazeboYarpJointSensors::~GazeboYarpJointSensors()
{
std::cout<<"*** GazeboYarpJointSensors closing ***"<<std::endl;
_iWrap->detachAll();
_jointsensors_wrapper.close();
_jointsensors_driver.close();
GazeboYarpPlugins::Handler::getHandler()->removeRobot(_robotName);
Expand Down Expand Up @@ -105,17 +106,16 @@ void GazeboYarpJointSensors::Load(physics::ModelPtr _parent, sdf::ElementPtr _sd
}

//Attach the driver to the wrapper
::yarp::dev::IMultipleWrapper * iWrap;
::yarp::dev::PolyDriverList driver_list;

if( !_jointsensors_wrapper.view(iWrap) ) {
if( !_jointsensors_wrapper.view(_iWrap) ) {
std::cerr << "GazeboYarpJointSensors : error in loading wrapper" << std::endl;
return;
}

driver_list.push(&_jointsensors_driver,"dummy");

if( iWrap->attachAll(driver_list) ) {
if( _iWrap->attachAll(driver_list) ) {
std::cerr << "GazeboYarpJointSensors : wrapper was connected with driver " << std::endl;
} else {
std::cerr << "GazeboYarpJointSensors : error in connecting wrapper and device " << std::endl;
Expand Down

0 comments on commit fa39668

Please sign in to comment.