Gazebo | Ignition | Community
Ask Your Question

How to use boost::bind to pass more than one input arguments to callback?

asked 2017-06-30 04:16:29 -0500

Angelos gravatar image

Hi all,

It's a newbie question but I'm stuck to this one and I need a gently push to move forward.

So I need to pass 2 input arguments in a local callback of subscriber node.

My header file looks like:


#include <string>
#include <gazebo/gazebo.hh>
#include "gazebo/transport/transport.hh"
#include "ignition/math/Vector3.hh"

#include <ros/ros.h>

namespace gazebo
  class NetForceCalcPlugin : public WorldPlugin
    // Constactor
    public: NetForceCalcPlugin();

    // Destructor
    public: virtual ~NetForceCalcPlugin();

    //  Load the sensor plugin.
    // \param[in] _sensor Pointer to the sensor that loaded this plugin.
    // \param[in] _sdf SDF element that describes the plugin.
    public: virtual void Load(physics::WorldPtr _parent, sdf::ElementPtr /*_sdf*/);

    private: transport::NodePtr node;

    private: transport::SubscriberPtr normalSub1;

    private: ignition::math::Vector3d normal_wheel1;


and my cc

#include "net_normalForce_calc.hh"

using namespace gazebo;

NetForceCalcPlugin::NetForceCalcPlugin() : WorldPlugin()


void cb1(ConstVector3dPtr &_msg, ignition::math::Vector3d normal)
  normal = ignition::math::Vector3d(_msg->x(), _msg->y(), _msg->z());
  ROS_INFO("Normal front_left: [%f, %f, %f]", _msg->x(), _msg->y(), _msg->z());

void NetForceCalcPlugin::Load(physics::WorldPtr _parent, sdf::ElementPtr /*_sdf*/)
  node = transport::NodePtr(new transport::Node());

  // Initiaize the node

  // Listen to Gazebo world_stats topic
  normalSub1 = node->Subscribe("/gazebo/default/contact-surface/front_left_normal", boost::bind(&cb1, _1, normal_wheel1));
  ROS_INFO("Net normal stage1 completed succesfully");

// Register this plugin with the simulator

I know that I probably miss many things but I cannot make it work. From my understanding the compiler waits for a different argument in the boost::bind placeholder and I give something else.

So I get back something looking like:

/home/angelos/catkin_ws/src/innoclimber/innoclimber_simulation/innoclimber_gazebo/plugins/ In member function ‘virtual void gazebo::NetForceCalcPlugin::Load(gazebo::physics::WorldPtr, sdf::ElementPtr)’:
/home/angelos/catkin_ws/src/innoclimber/innoclimber_simulation/innoclimber_gazebo/plugins/ error: no matching function for call to ‘gazebo::transport::Node::Subscribe(const char [50], boost::_bi::bind_t<void, void (*)(const boost::shared_ptr<const gazebo::msgs::Vector3d>&, ignition::math::Vector3<double>), boost::_bi::list2<boost::arg<1>, boost::_bi::value<ignition::math::Vector3<double> > > >)’
 ault/contact-surface/front_left_normal", boost::bind(&cb1, _1, normal_wheel1));
In file included from /usr/include/gazebo-7/gazebo/transport/transport.hh:6:0,
                 from /usr/include/gazebo-7/gazebo/gazebo_core.hh:22,
                 from /usr/include/gazebo-7/gazebo/gazebo.hh:20,
                 from /home/angelos/catkin_ws/src/innoclimber/innoclimber_simulation/innoclimber_gazebo/plugins/net_normalForce_calc.hh:5,
                 from /home/angelos/catkin_ws/src/innoclimber/innoclimber_simulation/innoclimber_gazebo/plugins/
/usr/include/gazebo-7/gazebo/transport/Node.hh:177:21: note: candidate: template<class M, class T> gazebo::transport::SubscriberPtr gazebo::transport::Node::Subscribe(const string&, void (T::*)(const boost::shared_ptr<const T>&), T*, bool)
       SubscriberPtr Subscribe(const std::string &_topic,
/usr/include/gazebo-7/gazebo/transport/Node.hh:177:21: note:   template argument deduction/substitution failed:
/home/angelos/catkin_ws/src/innoclimber/innoclimber_simulation/innoclimber_gazebo/plugins/ note:   mismatched types ‘void (T::*)(const boost::shared_ptr<const T>&)’ and ‘boost::_bi::bind_t<void, void (*)(const boost::shared_ptr<const gazebo::msgs::Vector3d>&, ignition::math::Vector3<double>), boost::_bi::list2 ...
edit retag flag offensive close merge delete

1 Answer

Sort by » oldest newest most voted

answered 2017-06-30 11:51:37 -0500

chapulina gravatar image

Try using _2:

 normalSub1 = node->Subscribe("/gazebo/default/contact-surface/front_left_normal", boost::bind(&cb1, _1, _2));
edit flag offensive delete link more


Unfortunately didn't work. I still trying to solve it. For the time being, I just declare the callback in the class header file and since my second argument is a class variable I can access it without passing it as argument. Anyway, thanks for your help Louise!

Angelos gravatar imageAngelos ( 2017-07-02 08:53:40 -0500 )edit
Login/Signup to Answer

Question Tools

1 follower


Asked: 2017-06-30 04:16:29 -0500

Seen: 3,383 times

Last updated: Jun 30 '17