ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
0

Using shapeshifter MessageEvent and boost bind together to pass arguments to callback

asked 2017-10-24 10:51:04 -0500

griffbot gravatar image

I'm trying to add a parameter to a callback for a subscriber that I don't know the type or topic name at compile time. I've failed to get it to compile saying that there is not a matching function for the call to subscribe. I've simplified the example to below and am trying to figure out what's going on. In the end, I need to pass the topic name as a string to the callback. Anyone have any ideas?

class Class1
{
  private:
  ros::NodeHandle node_;

  void MemberCallback(const ros::MessageEvent<topic_tools::ShapeShifter>& msg_event)
  {
    ...
  }

  public:
  Class1()
  {
      node_.subscribe("test", 10, boost::bind(&Class1::MemberCallback, this, _1));
  }
};
edit retag flag offensive close merge delete

1 Answer

Sort by » oldest newest most voted
1

answered 2017-11-02 17:36:02 -0500

griffbot gravatar image

updated 2017-11-02 17:42:47 -0500

Well in my initial search, I missed out on a resource that did exactly what I'm trying to do. In case anybody else stumbles upon this question, please follow this tutorial:

http://wiki.ros.org/ROS/Tutorials/Wri...

Basically it would end up looking like this:

class Class1
{
  private:
  ros::NodeHandle node_;

  void MemberCallback(topic_tools::ShapeShifter::ConstPtr& msg)
  {
    ...
  }

  public:
  Class1()
  {
      boost::function<void(const topic_tools::ShapeShifter::ConstPtr&)> callback = boost::bind(&Class1::MemberCallback, this, _1);
      node_.subscribe("test", 10, callback);
  }
};

I think my issue before was using the ros::MessageEvent class when I didn't need it. This is a simplified example just to compile, but you can now add arguments to the callback as you need them.

edit flag offensive delete link more

Question Tools

2 followers

Stats

Asked: 2017-10-24 10:51:04 -0500

Seen: 477 times

Last updated: Nov 02 '17