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

Passing an argument to a subscriber callback [closed]

asked 2013-06-21 04:57:12 -0500

JML gravatar image

updated 2013-06-21 04:58:21 -0500

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

edit retag flag offensive reopen merge delete

Closed for the following reason question is not relevant or outdated by tfoote
close date 2015-05-28 22:18:18.386091

1 Answer

Sort by » oldest newest most voted
0

answered 2013-06-21 05:30:24 -0500

dornhege gravatar image

updated 2013-06-24 02:54:40 -0500

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.

edit flag offensive delete link more

Comments

Thanks for the answer. Using boost::ref(current_state) does not change anything, unfortunately. Using node.subscribe<sensor_msgs::JointState> introduces an additional error, "Symbol 'subscribe' could not be resolved".

JML gravatar image JML  ( 2013-06-25 05:05:12 -0500 )edit

Question Tools

Stats

Asked: 2013-06-21 04:57:12 -0500

Seen: 1,847 times

Last updated: Jun 24 '13