Passing an argument to a subscriber callback
Hello,
I need to pass an argument to a subscriber callback function. Following the answer at (http://answers.ros.org/question/12045/how-to-deliver-arguments-to-a-callback-function/), I'm using the syntax below:
ros::Subscriber subscriber = node.subscribe("joint_states", 1000, boost::bind(selfcollisionCallback, _1, current_state));
The argument is a reference to a MoveIt! class member:
robot_state::RobotState& current_state = planning_scene.getCurrentStateNonConst();
and the callback function definition is
void selfcollisionCallback(const sensor_msgs::JointState& msg, robot_state::RobotState& current_state)
I get the following errors at compilation:
/home/jml/catkin_ws/src/jaco_collision/collision_subs.cpp: In function ‘void selfcollisionCallback(const JointState&, robot_state::RobotState&)’:
/home/jml/catkin_ws/src/jaco_collision/collision_subs.cpp:47:18: error: expected primary-expression before ‘.’ token
/home/jml/catkin_ws/src/jaco_collision/collision_subs.cpp: In function ‘int main(int, char**)’:
/home/jml/catkin_ws/src/jaco_collision/collision_subs.cpp:76:123: error: no matching function for call to ‘ros::NodeHandle::subscribe(const char [13], int, boost::_bi::bind_t<void, void (*)(const sensor_msgs::JointState_<std::allocator<void> >&, robot_state::RobotState&), boost::_bi::list2<boost::arg<1>, boost::_bi::value<robot_state::RobotState> > >)’
Any clues?
Many thanks, JML
Asked by JML on 2013-06-21 04:57:12 UTC
Answers
Use boost::ref()
around current_state in the subscribe call.
Maybe also try node.subscribe<sensor_msgs::JointState>(...
if it can't resolve the specialization automatically.
Asked by dornhege on 2013-06-21 05:30:24 UTC
Comments
Thanks for the answer. Using boost::ref(current_state) does not change anything, unfortunately. Using node.subscribe
Asked by JML on 2013-06-25 05:05:12 UTC
Comments