Skip to content

Commit

Permalink
Removed onUpdate event callbacks when device driver closes
Browse files Browse the repository at this point in the history
  • Loading branch information
francesco-romano committed Feb 13, 2014
1 parent cbacfef commit cda7722
Show file tree
Hide file tree
Showing 9 changed files with 29 additions and 21 deletions.
3 changes: 0 additions & 3 deletions include/gazebo_yarp_plugins/ControlBoard.hh
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,6 @@

namespace gazebo
{



/// \class GazeboYarpControlBoard
/// Gazebo Plugin emulating the yarp controlBoard device in Gazebo.
///.
Expand Down
10 changes: 4 additions & 6 deletions include/gazebo_yarp_plugins/ControlBoardDriver.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
#include <gazebo/gazebo.hh>
#include <gazebo/physics/physics.hh>
#include <gazebo/transport/transport.hh>

#pragma GCC diagnostic pop

#define toRad(X) (X*M_PI/180.0)
Expand All @@ -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*/);

/**
Expand All @@ -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();
Expand Down
3 changes: 2 additions & 1 deletion src/gazebo_plugins/ControlBoard.cc
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ GZ_REGISTER_MODEL_PLUGIN(GazeboYarpControlBoard)

GazeboYarpControlBoard::~GazeboYarpControlBoard()
{
_controlBoard.close();
_wrapper.close();
std::cout<<"Goodbye!"<<std::endl;
}
Expand Down Expand Up @@ -98,7 +99,7 @@ GZ_REGISTER_MODEL_PLUGIN(GazeboYarpControlBoard)
{
printf("GazeboYarpControlBoard ERROR, net list to attach to was not found, exiting\n");
_wrapper.close();
_controlBoard.close();
// _controlBoard.close();
return;
}

Expand Down
1 change: 1 addition & 0 deletions src/gazebo_plugins/ForceTorque.cc
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ void GazeboYarpForceTorque::Init()
GazeboYarpForceTorque::~GazeboYarpForceTorque()
{
std::cout<<"*** GazeboYarpForceTorque closing ***"<<std::endl;
_forcetorque_driver.close();
}

void GazeboYarpForceTorque::Load(sensors::SensorPtr _sensor, sdf::ElementPtr _sdf)
Expand Down
3 changes: 1 addition & 2 deletions src/gazebo_plugins/IMU.cc
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ void GazeboYarpIMU::Init()
GazeboYarpIMU::~GazeboYarpIMU()
{
std::cout<<"*** GazeboYarpIMU closing ***"<<std::endl;
_imu_driver.close();
}

void GazeboYarpIMU::Load(sensors::SensorPtr _sensor, sdf::ElementPtr _sdf)
Expand All @@ -49,8 +50,6 @@ void GazeboYarpIMU::Load(sensors::SensorPtr _sensor, sdf::ElementPtr _sdf)

_sensor->SetActive(true);



// Add my gazebo device driver to the factory.
yarp::dev::Drivers::factory().add(new yarp::dev::DriverCreatorOf<yarp::dev::GazeboYarpIMUDriver>
("gazebo_imu", "inertial", "GazeboYarpIMUDriver"));
Expand Down
13 changes: 11 additions & 2 deletions src/yarp_drivers/ControlBoardDriver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"<<std::endl;
// std::cout<<"if this message is the last one you read, _robot has not been set"<<std::endl;
//assert is a NOP in release mode. We should change the error handling either with an exception or something else
assert ( _robot );
if (!_robot) return false;

std::cout<<"Robot Name: "<<_robot->GetName() <<std::endl;
std::cout<<"# Joints: "<<_robot->GetJoints().size() <<std::endl;
Expand Down Expand Up @@ -77,6 +84,7 @@ void GazeboYarpControlBoardDriver::gazebo_init()

this->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<gazebo::msgs::JointCmd>
Expand Down Expand Up @@ -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*/ )
Expand Down
8 changes: 5 additions & 3 deletions src/yarp_drivers/ControlBoardDriverDeviceDriver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
5 changes: 3 additions & 2 deletions src/yarp_drivers/ForceTorqueDriver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@ using namespace yarp::dev;

GazeboYarpForceTorqueDriver::GazeboYarpForceTorqueDriver()
{
return;

}


GazeboYarpForceTorqueDriver::~GazeboYarpForceTorqueDriver()
{
return;

}


Expand Down Expand Up @@ -88,6 +88,7 @@ bool GazeboYarpForceTorqueDriver::open(yarp::os::Searchable& config)

bool GazeboYarpForceTorqueDriver::close()
{
gazebo::event::Events::DisconnectWorldUpdateBegin(this->updateConnection);
return true;
}

Expand Down
4 changes: 2 additions & 2 deletions src/yarp_drivers/IMUDriver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,12 @@ using namespace yarp::dev;

GazeboYarpIMUDriver::GazeboYarpIMUDriver()
{
return;
}


GazeboYarpIMUDriver::~GazeboYarpIMUDriver()
{
return;

}


Expand Down Expand Up @@ -100,6 +99,7 @@ bool GazeboYarpIMUDriver::open(yarp::os::Searchable& config)

bool GazeboYarpIMUDriver::close()
{
gazebo::event::Events::DisconnectWorldUpdateBegin(this->updateConnection);
return true;
}

Expand Down

0 comments on commit cda7722

Please sign in to comment.