diff --git a/include/gazebo_yarp_plugins/ControlBoard.hh b/include/gazebo_yarp_plugins/ControlBoard.hh index 14afa9426..2ad08c45f 100644 --- a/include/gazebo_yarp_plugins/ControlBoard.hh +++ b/include/gazebo_yarp_plugins/ControlBoard.hh @@ -22,9 +22,6 @@ namespace gazebo { - - - /// \class GazeboYarpControlBoard /// Gazebo Plugin emulating the yarp controlBoard device in Gazebo. ///. diff --git a/include/gazebo_yarp_plugins/ControlBoardDriver.h b/include/gazebo_yarp_plugins/ControlBoardDriver.h index c0979e494..9b42dd5ee 100644 --- a/include/gazebo_yarp_plugins/ControlBoardDriver.h +++ b/include/gazebo_yarp_plugins/ControlBoardDriver.h @@ -24,7 +24,6 @@ #include #include #include - #pragma GCC diagnostic pop #define toRad(X) (X*M_PI/180.0) @@ -51,15 +50,14 @@ class yarp::dev::GazeboYarpControlBoardDriver : public yarp::os::RateThread { public: - GazeboYarpControlBoardDriver() : RateThread(20) - {} + GazeboYarpControlBoardDriver(); - ~GazeboYarpControlBoardDriver(){} + ~GazeboYarpControlBoardDriver(); /** * Gazebo stuff */ - void gazebo_init(); + bool gazebo_init(); void onUpdate(const gazebo::common::UpdateInfo & /*_info*/); /** @@ -68,7 +66,7 @@ class yarp::dev::GazeboYarpControlBoardDriver : //DEVICE DRIVER virtual bool open(yarp::os::Searchable& config); - virtual bool close(); //NOT IMPLEMENTED + virtual bool close(); //THREAD (inside comanDeviceDriver.cpp) virtual void run(); virtual bool threadInit(); diff --git a/src/gazebo_plugins/ControlBoard.cc b/src/gazebo_plugins/ControlBoard.cc index c6d25d834..a47330451 100644 --- a/src/gazebo_plugins/ControlBoard.cc +++ b/src/gazebo_plugins/ControlBoard.cc @@ -28,6 +28,7 @@ GZ_REGISTER_MODEL_PLUGIN(GazeboYarpControlBoard) GazeboYarpControlBoard::~GazeboYarpControlBoard() { + _controlBoard.close(); _wrapper.close(); std::cout<<"Goodbye!"<SetActive(true); - - // Add my gazebo device driver to the factory. yarp::dev::Drivers::factory().add(new yarp::dev::DriverCreatorOf ("gazebo_imu", "inertial", "GazeboYarpIMUDriver")); diff --git a/src/yarp_drivers/ControlBoardDriver.cpp b/src/yarp_drivers/ControlBoardDriver.cpp index 99da3c519..ad5bc1068 100644 --- a/src/yarp_drivers/ControlBoardDriver.cpp +++ b/src/yarp_drivers/ControlBoardDriver.cpp @@ -22,11 +22,18 @@ using namespace yarp::sig::draw; using namespace yarp::sig::file; using namespace yarp::dev; -void GazeboYarpControlBoardDriver::gazebo_init() +GazeboYarpControlBoardDriver::GazeboYarpControlBoardDriver(): RateThread(20) +{} + +GazeboYarpControlBoardDriver::~GazeboYarpControlBoardDriver() {} + +bool GazeboYarpControlBoardDriver::gazebo_init() { //_robot = gazebo_pointer_wrapper::getModel(); - std::cout<<"if this message is the last one you read, _robot has not been set"<GetName() <GetJoints().size() <updateConnection = gazebo::event::Events::ConnectWorldUpdateBegin ( boost::bind ( &GazeboYarpControlBoardDriver::onUpdate, this, _1 ) ); + gazebo_node_ptr = gazebo::transport::NodePtr ( new gazebo::transport::Node ); gazebo_node_ptr->Init ( this->_robot->GetWorld()->GetName() ); jointCmdPub = gazebo_node_ptr->Advertise @@ -112,6 +120,7 @@ void GazeboYarpControlBoardDriver::gazebo_init() _robot->GetJoint(joint_name)->SetAngle(0,a); } } + return true; } void GazeboYarpControlBoardDriver::onUpdate ( const gazebo::common::UpdateInfo & /*_info*/ ) diff --git a/src/yarp_drivers/ControlBoardDriverDeviceDriver.cpp b/src/yarp_drivers/ControlBoardDriverDeviceDriver.cpp index 0475648f7..a15cdee87 100644 --- a/src/yarp_drivers/ControlBoardDriverDeviceDriver.cpp +++ b/src/yarp_drivers/ControlBoardDriverDeviceDriver.cpp @@ -28,14 +28,16 @@ bool GazeboYarpControlBoardDriver::open(yarp::os::Searchable& config) return false; } - gazebo_init(); - return RateThread::start(); + return gazebo_init() && RateThread::start(); } -bool GazeboYarpControlBoardDriver::close() //NOT IMPLEMENTED +bool GazeboYarpControlBoardDriver::close() { + //unbinding events + gazebo::event::Events::DisconnectWorldUpdateBegin (this->updateConnection); + delete [] control_mode; delete [] motion_done; return true; diff --git a/src/yarp_drivers/ForceTorqueDriver.cpp b/src/yarp_drivers/ForceTorqueDriver.cpp index 2c9bd2c8b..107a67477 100644 --- a/src/yarp_drivers/ForceTorqueDriver.cpp +++ b/src/yarp_drivers/ForceTorqueDriver.cpp @@ -13,13 +13,13 @@ using namespace yarp::dev; GazeboYarpForceTorqueDriver::GazeboYarpForceTorqueDriver() { - return; + } GazeboYarpForceTorqueDriver::~GazeboYarpForceTorqueDriver() { - return; + } @@ -88,6 +88,7 @@ bool GazeboYarpForceTorqueDriver::open(yarp::os::Searchable& config) bool GazeboYarpForceTorqueDriver::close() { + gazebo::event::Events::DisconnectWorldUpdateBegin(this->updateConnection); return true; } diff --git a/src/yarp_drivers/IMUDriver.cpp b/src/yarp_drivers/IMUDriver.cpp index 268b9026e..c360177bd 100644 --- a/src/yarp_drivers/IMUDriver.cpp +++ b/src/yarp_drivers/IMUDriver.cpp @@ -14,13 +14,12 @@ using namespace yarp::dev; GazeboYarpIMUDriver::GazeboYarpIMUDriver() { - return; } GazeboYarpIMUDriver::~GazeboYarpIMUDriver() { - return; + } @@ -100,6 +99,7 @@ bool GazeboYarpIMUDriver::open(yarp::os::Searchable& config) bool GazeboYarpIMUDriver::close() { + gazebo::event::Events::DisconnectWorldUpdateBegin(this->updateConnection); return true; }