Gazebo | Ignition | Community
Ask Your Question

Problem of building ros server in Gazebo model plugin

asked 2019-07-20 16:19:02 -0500

stupid gravatar image


I am now building a ros server node in a gazebo plugin and got an error:

error: no matching function for call to ‘ros::NodeHandle::advertiseService(const char [12], bool (gazebo::JointController::*)(gazebo_tutorials::mysrv::Request&, gazebo_tutorials::mysrv::Response&))’ this->my_service = this->rosNode->advertiseService("/add_server", &JointController::addd);

I think this is because I did not set up the argument types correctly, I google for a long time and found nothing similar to my code. Any help would be a life saver for me, thanks in advanced!

here's some pieces of my code:

class JointController : public ModelPlugin
/// \brief Constructor
public: JointController() {}

public: virtual void Load(physics::ModelPtr _model, sdf::ElementPtr _sdf)
  // Store the model pointer for convenience.
  this->model = _model;

  // Initialize ros, if it has not already bee initialized.
  if (!ros::isInitialized())
    int argc = 0;
    char **argv = NULL;
    ros::init(argc, argv, "gazebo_client",

  // Create our ROS node. This acts in a similar manner to
  // the Gazebo node
  this->rosNode.reset(new ros::NodeHandle("gazebo_client"));
  //ros::NodeHandle n;

  //FITNESS publisher
  this->fitness_pub =this->rosNode->advertise<std_msgs::Float64>("/fitness", 100);

  //Service Node
  this->my_service = this->rosNode->advertiseService("/add_server", &JointController::addd);

  // Spin up the queue helper thread.
  this->rosQueueThread =
    std::thread(std::bind(&JointController::QueueThread, this));

public: bool addd(gazebo_tutorials::mysrv::Request& req,
         gazebo_tutorials::mysrv::Response& res)
  res.sum = req.a + req.b;
  ROS_INFO("request: x=%ld, y=%ld", (long int)req.a, (long int)req.b);
  ROS_INFO("sending back response: [%ld]", (long int)res.sum);
  return true;
edit retag flag offensive close merge delete

1 Answer

Sort by » oldest newest most voted

answered 2019-10-17 10:09:41 -0500

Hi. You would have to pass "this" pointer also as an argument when defining the serviceserver object like so,

//Service Node

this->my_service = this->rosNode->advertiseService("/add_server", &JointController::addd, this);

Please refer this link as it explains using member functions of classes as callback functions.

Hope this helps.

edit flag offensive delete link more
Login/Signup to Answer

Question Tools

1 follower


Asked: 2019-07-20 16:19:02 -0500

Seen: 181 times

Last updated: Jul 20 '19