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

[ROS2] Error in binding a callback to action client

asked 2022-06-23 11:59:35 -0600

AndyZe gravatar image

updated 2022-06-23 12:49:44 -0600

I'm trying to follow the C++ action tutorial here:

I have an action server that is a member of a class, like the tutorial. Here is the initialization:

using TrajectoryAction = control_msgs::action::FollowJointTrajectory;
using TrajectoryGoalHandle = rclcpp_action::ClientGoalHandle<control_msgs::action::FollowJointTrajectory>;
auto cb_group = node->create_callback_group(rclcpp::CallbackGroupType::MutuallyExclusive);
joint_trajectory_client_ = rclcpp_action::create_client<TrajectoryAction>(node, trajectory_topic, cb_group);

I try to make a request with goal options:

auto send_goal_options = rclcpp_action::Client<TrajectoryAction>::SendGoalOptions();
send_goal_options.result_callback = std::bind(&TaskExecutionImpl::TrajectoryResultCallback, this, std::placeholders::_1);  // trouble at this line -- it compiles if commented

The function which I'm trying to use as a callback is:

void TaskExecutionImpl::TrajectoryResultCallback(const TrajectoryGoalHandle::WrappedResult& result)

The compiler errors:

error: no match for ‘operator=’ (operand types are ‘rclcpp_action::Client<control_msgs::action::FollowJointTrajectory>::ResultCallback’ {aka ‘std::function<void(const rclcpp_action::ClientGoalHandle<control_msgs::action::FollowJointTrajectory>::WrappedResult&)>’} and ‘std::_Bind_helper<false, void (my_robot::task_planning::TaskExecutionImpl::*)(const rclcpp_action::ClientGoalHandle<control_msgs::action::FollowJointTrajectory>::WrappedResult&), const my_robot::task_planning::TaskExecutionImpl*>::type’)
   54 |   send_goal_options.result_callback = std::bind(&TaskExecutionImpl::TrajectoryResultCallback, this);

. .

/workspaces/ws_ros2/src/my_robot_moveit/task_planning/src/task_execution_impl.cpp:54:99:   required from here
/usr/include/c++/11/type_traits:2211:11: error: no type named ‘type’ in ‘struct std::enable_if<false, std::function<void(const rclcpp_action::ClientGoalHandle<control_msgs::action::FollowJointTrajectory>::WrappedResult&)>&>’
edit retag flag offensive close merge delete


Unlike the tutorial, my class doesn't inherit from rclcpp::Node. But I don't think that matters...

AndyZe gravatar image AndyZe  ( 2022-06-23 12:41:57 -0600 )edit

Maybe try as a lambda ?, I think I came across something similar when I was porting portion of my code from foxy to rolling.

  send_goal_options.result_callback = [this](const typename rclcpp_action::ClientGoalHandle<TrajectoryAction>::WrappedResult & result) {
Fetullah Atas gravatar image Fetullah Atas  ( 2022-06-23 18:09:05 -0600 )edit

1 Answer

Sort by » oldest newest most voted

answered 2022-06-23 18:25:33 -0600

If you provided the code, I'd play with it. I think you may just be missing the typename. I'm looking at examples in Nav2 and what you provide looks correct.

edit flag offensive delete link more

Question Tools



Asked: 2022-06-23 11:59:35 -0600

Seen: 271 times

Last updated: Jun 23 '22