0
$\begingroup$

Rosanswers logo

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<void(const boost::shared_ptr<const T>&)>&, const VoidConstPtr&, const ros::TransportHints&)
/opt/ros/groovy/include/ros/node_handle.h:752:14: note: template<class M, class C> ros::Subscriber ros::NodeHandle::subscribe(const string&, uint32_t, const boost::function<void(C)>&, const VoidConstPtr&, const ros::TransportHints&)
/opt/ros/groovy/include/ros/node_handle.h:785:14: note: ros::Subscriber ros::NodeHandle::subscribe(ros::SubscribeOptions&)
/opt/ros/groovy/include/ros/node_handle.h:785:14: note:   candidate expects 1 argument, 3 provided

I have no idea what's wrong with my code to establish the subscriber.

Thanks for any help in advance!


Originally posted by AdrianPeng on ROS Answers with karma: 441 on 2013-11-13

Post score: 0


Original comments

Comment by Thomas on 2013-11-13:
Seems like your controllerStateCB has the wrong type, can you edit the question and tell us how you instantiate it?

Comment by AdrianPeng on 2013-11-14:
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.

Comment by AdrianPeng on 2013-11-14:
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?

Comment by tfoote on 2013-11-14:
@AdrianPeng Please don't use # in tags.

Comment by Thomas on 2013-11-14:
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...

$\endgroup$

2 Answers 2

0
$\begingroup$

Rosanswers logo

Put a "&" in front of controllerStateCB ;)

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

Originally posted by Thomas with karma: 4478 on 2013-11-14

This answer was ACCEPTED on the original site

Post score: 1

$\endgroup$
0
$\begingroup$

Rosanswers logo

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).


Originally posted by Philip with karma: 990 on 2013-11-15

This answer was NOT ACCEPTED on the original site

Post score: 2

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.