A subscriber error
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 ...
Seems like your controllerStateCB has the wrong type, can you edit the question and tell us how you instantiate it?
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.
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 Please don't use # in tags.
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...