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

A subscriber error

asked 2013-11-13 07:54:57 -0600

AdrianPeng gravatar image

updated 2013-11-14 10:39:30 -0600

tfoote gravatar image

Hi everyone,

I tried to establish a subscriber in move_action_capability in Moveit!

I established the subscriber within method "move_group::MoveGroupMoveAction::executeMoveCallback_PlanOnly" and following is my code to establish the subscriber:

ros::NodeHandle handle;
ros::Subscriber sub = handle.subscribe("r_arm_controller/state", 1000, controllerStateCB);

This is my callback signature:

void controllerStateCB(const pr2_controllers_msgs::JointTrajectoryControllerState::ConstPtr& msg)
{
    for (int joint_index = 0; joint_index < 7; joint_index++)
    {
        current_joint_position[joint_index]=msg->actual.positions[joint_index];
        current_joint_velocity[joint_index]=msg->actual.velocities[joint_index];
    }
}

However, when I compile, I got the following error:

/home/pr2/moveit/src/moveit_ros/move_group/src/default_capabilities/move_action_capability.cpp: In member function ‘void move_group::MoveGroupMoveAction::executeMoveCallback_PlanOnly(const MoveGroupGoalConstPtr&, moveit_msgs::MoveGroupResult&)’:
/home/pr2/moveit/src/moveit_ros/move_group/src/default_capabilities/move_action_capability.cpp:203:91: error: no matching function for call to ‘ros::NodeHandle::subscribe(const char [23], int, <unresolved overloaded function type>)’
/home/pr2/moveit/src/moveit_ros/move_group/src/default_capabilities/move_action_capability.cpp:203:91: note: candidates are:
/opt/ros/groovy/include/ros/node_handle.h:379:14: note: template<class M, class T> ros::Subscriber ros::NodeHandle::subscribe(const string&, uint32_t, void (T::*)(M), T*, const ros::TransportHints&)
/opt/ros/groovy/include/ros/node_handle.h:390:14: note: template<class M, class T> ros::Subscriber ros::NodeHandle::subscribe(const string&, uint32_t, void (T::*)(M)const, T*, const ros::TransportHints&)
/opt/ros/groovy/include/ros/node_handle.h:438:14: note: template<class M, class T> ros::Subscriber ros::NodeHandle::subscribe(const string&, uint32_t, void (T::*)(const boost::shared_ptr<const MReq>&), T*, const ros::TransportHints&)
/opt/ros/groovy/include/ros/node_handle.h:448:14: note: template<class M, class T> ros::Subscriber ros::NodeHandle::subscribe(const string&, uint32_t, void (T::*)(const boost::shared_ptr<const MReq>&)const, T*, const ros::TransportHints&)
/opt/ros/groovy/include/ros/node_handle.h:498:14: note: template<class M, class T> ros::Subscriber ros::NodeHandle::subscribe(const string&, uint32_t, void (T::*)(M), const boost::shared_ptr<U>&, const ros::TransportHints&)
/opt/ros/groovy/include/ros/node_handle.h:509:14: note: template<class M, class T> ros::Subscriber ros::NodeHandle::subscribe(const string&, uint32_t, void (T::*)(M)const, const boost::shared_ptr<U>&, const ros::TransportHints&)
/opt/ros/groovy/include/ros/node_handle.h:559:14: note: template<class M, class T> ros::Subscriber ros::NodeHandle::subscribe(const string&, uint32_t, void (T::*)(const boost::shared_ptr<const MReq>&), const boost::shared_ptr<U>&, const ros::TransportHints&)
/opt/ros/groovy/include/ros/node_handle.h:570:14: note: template<class M, class T> ros::Subscriber ros::NodeHandle::subscribe(const string&, uint32_t, void (T::*)(const boost::shared_ptr<const MReq>&)const, const boost::shared_ptr<U>&, const ros::TransportHints&)
/opt/ros/groovy/include/ros/node_handle.h:618:14: note: template<class M> ros::Subscriber ros::NodeHandle::subscribe(const string&, uint32_t, void (*)(M), const ros::TransportHints&)
/opt/ros/groovy/include/ros/node_handle.h:663:14: note: template<class M> ros::Subscriber ros::NodeHandle::subscribe(const string&, uint32_t, void (*)(const boost::shared_ptr<const T>&), const ros::TransportHints&)
/opt/ros/groovy/include/ros/node_handle.h:706:14: note: template<class M> ros::Subscriber ros::NodeHandle::subscribe(const string&, uint32_t, const boost::function ...
(more)
edit retag flag offensive close merge delete

Comments

Seems like your controllerStateCB has the wrong type, can you edit the question and tell us how you instantiate it?

Thomas gravatar image Thomas  ( 2013-11-13 16:53:57 -0600 )edit

Hi Thomas, I add my callback signature. I just noticed that there are three types of callback signature: functions, class methods, functor objects. I am using functions type here and I am not sure if it is appropriate to use this type here.

AdrianPeng gravatar image AdrianPeng  ( 2013-11-14 03:09:56 -0600 )edit

Hi Thomas! It works! Thank you very much! But I am wondering why in http://wiki.ros.org/ROS/Tutorials/WritingPublisherSubscriber%28c%2B%2B%29 tutorial, there is no "&" before callback function?

AdrianPeng gravatar image AdrianPeng  ( 2013-11-14 03:56:09 -0600 )edit

@AdrianPeng Please don't use # in tags.

tfoote gravatar image tfoote  ( 2013-11-14 10:39:51 -0600 )edit

I guess some gcc version may be tolerant on this point but when you set a callback you really are passing the function _address_ and not the function itself. As there is no way to do the latter in C++03 (i.e. to express it through the syntax), compilers used to be more permissible...

Thomas gravatar image Thomas  ( 2013-11-14 12:39:27 -0600 )edit

3 Answers

Sort by » oldest newest most voted
1

answered 2013-11-14 03:18:37 -0600

Thomas gravatar image

updated 2017-10-03 06:55:56 -0600

130s gravatar image

Put a "&" in front of controllerStateCB ;)

 ros::Subscriber sub = handle.subscribe("r_arm_controller/state", 1000, &controllerStateCB);
edit flag offensive delete link more
2

answered 2013-11-15 03:13:49 -0600

Philip gravatar image

updated 2017-10-03 06:48:36 -0600

130s gravatar image

To anyone reading this answer from @pelment: Callbacks can be class methods (which in many cases is preferable). You just have to put attention to setting it up in a way that the subscriber doesn't go out of scope (and use the syntax for class-callbacks from the publisher/subscriber tutorial).

edit flag offensive delete link more
0

answered 2013-11-15 01:24:17 -0600

pelment gravatar image

I had the same problem few days ago. I recognized that callback functions should be placed in global space. So they shouldn't be a class methods. Putting & in front of callback function name doesn't help. Maybe there is a way to make class method be a callback function, but I have no ideas. My solution: place all callbacks in global space in the same cpp-file with subscribing function is called.

edit flag offensive delete link more

Comments

Oh, thanks, I hoped that I'm wrong! But I don't know why I failed...

pelment gravatar image pelment  ( 2013-11-15 07:31:09 -0600 )edit
1

Philip's answer is correct refer to the following link for syntax. roscpp class callback methods

northfork gravatar image northfork  ( 2017-06-07 16:05:05 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2013-11-13 07:54:57 -0600

Seen: 1,900 times

Last updated: Oct 03 '17