ROS2 Basics in 5 Days Humble (C++) - Example 5.2 failed

Hi

I was following the Example 5.2 of Understanding ROS2 Actions and when I compile the my_action_client appears:

  user:~/ros2_ws$ colcon build --packages-select my_action_client
  Starting >>> my_action_client
  --- stderr: my_action_client
  /home/user/ros2_ws/src/my_action_client/src/action_client.cpp: In member function 'void MyActionClient::send_goal()':
  /home/user/ros2_ws/src/my_action_client/src/action_client.cpp:61:66: error: no match for 'operator=' (operand types are 'rclcpp_action::Client<t3_action_msg::action::Move>::GoalResponseCallback' {aka 'std::function<void(std::shared_ptr<rclcpp_action::ClientGoalHandle<t3_action_msg::action::Move> >)>'} and 'std::_Bind_helper<false, void (MyActionClient::*)(std::shared_future<std::shared_ptr<rclcpp_action::ClientGoalHandle<t3_action_msg::action::Move> > >), MyActionClient*, const std::_Placeholder<1>&>::type')
     61 |       std::bind(&MyActionClient::goal_response_callback, this, _1);
        |                                                                  ^
  In file included from /usr/include/c++/11/functional:59,
                   from /usr/include/c++/11/pstl/glue_algorithm_defs.h:13,
                   from /usr/include/c++/11/algorithm:74,
                   from /home/simulations/ros2_sims_ws/install/t3_action_msg/include/t3_action_msg/t3_action_msg/action/detail/move__struct.hpp:8,
                   from /home/simulations/ros2_sims_ws/install/t3_action_msg/include/t3_action_msg/t3_action_msg/action/move.hpp:7,
                   from /home/user/ros2_ws/src/my_action_client/src/action_client.cpp:6:
  /usr/include/c++/11/bits/std_function.h:530:9: note: candidate: 'template<class _Functor> std::function<_Res(_ArgTypes ...)>::_Requires<std::function<_Res(_ArgTypes ...)>::_Callable<_Functor>, std::function<_Res(_ArgTypes ...)>&> std::function<_Res(_ArgTypes ...)>::operator=(_Functor&&) [with _Functor = _Functor; _Res = void; _ArgTypes = {std::shared_ptr<rclcpp_action::ClientGoalHandle<t3_action_msg::action::Move> >}]'
    530 |         operator=(_Functor&& __f)
        |         ^~~~~~~~
  /usr/include/c++/11/bits/std_function.h:530:9: note:   template argument deduction/substitution failed:
  In file included from /usr/include/c++/11/bits/move.h:57,
                   from /usr/include/c++/11/bits/stl_pair.h:59,
                   from /usr/include/c++/11/bits/stl_algobase.h:64,
                   from /usr/include/c++/11/memory:63,
                   from /home/user/ros2_ws/src/my_action_client/src/action_client.cpp:2:
  /usr/include/c++/11/type_traits: In substitution of 'template<bool _Cond, class _Tp> using __enable_if_t = typename std::enable_if::type [with bool _Cond = false; _Tp = std::function<void(std::shared_ptr<rclcpp_action::ClientGoalHandle<t3_action_msg::action::Move> >)>&]':
  /usr/include/c++/11/bits/std_function.h:353:8:   required by substitution of 'template<class _Res, class ... _ArgTypes> template<class _Cond, class _Tp> using _Requires = std::__enable_if_t<_Cond::value, _Tp> [with _Cond = std::function<void(std::shared_ptr<rclcpp_action::ClientGoalHandle<t3_action_msg::action::Move> >)>::_Callable<std::_Bind<void (MyActionClient::*(MyActionClient*, std::_Placeholder<1>))(std::shared_future<std::shared_ptr<rclcpp_action::ClientGoalHandle<t3_action_msg::action::Move> > >)>, std::_Bind<void (MyActionClient::*(MyActionClient*, std::_Placeholder<1>))(std::shared_future<std::shared_ptr<rclcpp_action::ClientGoalHandle<t3_action_msg::action::Move> > >)>, std::__invoke_result<std::_Bind<void (MyActionClient::*(MyActionClient*, std::_Placeholder<1>))(std::shared_future<std::shared_ptr<rclcpp_action::ClientGoalHandle<t3_action_msg::action::Move> > >)>&, std::shared_ptr<rclcpp_action::ClientGoalHandle<t3_action_msg::action::Move> > > >; _Tp = std::function<void(std::shared_ptr<rclcpp_action::ClientGoalHandle<t3_action_msg::action::Move> >)>&; _Res = void; _ArgTypes = {std::shared_ptr<rclcpp_action::ClientGoalHandle<t3_action_msg::action::Move> >}]'
  /usr/include/c++/11/bits/std_function.h:530:2:   required by substitution of 'template<class _Functor> std::function<void(std::shared_ptr<rclcpp_action::ClientGoalHandle<t3_action_msg::action::Move> >)>::_Requires<std::function<void(std::shared_ptr<rclcpp_action::ClientGoalHandle<t3_action_msg::action::Move> >)>::_Callable<_Functor, typename std::enable_if<(! std::is_same<typename std::remove_cv<typename std::remove_reference<_Tp>::type>::type, std::function<void(std::shared_ptr<rclcpp_action::ClientGoalHandle<t3_action_msg::action::Move> >)> >::value), std::decay<_Tp> >::type::type, std::__invoke_result<typename std::enable_if<(! std::is_same<typename std::remove_cv<typename std::remove_reference<_Tp>::type>::type, std::function<void(std::shared_ptr<rclcpp_action::ClientGoalHandle<t3_action_msg::action::Move> >)> >::value), std::decay<_Tp> >::type::type&, std::shared_ptr<rclcpp_action::ClientGoalHandle<t3_action_msg::action::Move> > > >, std::function<void(std::shared_ptr<rclcpp_action::ClientGoalHandle<t3_action_msg::action::Move> >)>&> std::function<void(std::shared_ptr<rclcpp_action::ClientGoalHandle<t3_action_msg::action::Move> >)>::operator=<_Functor>(_Functor&&) [with _Functor = std::_Bind<void (MyActionClient::*(MyActionClient*, std::_Placeholder<1>))(std::shared_future<std::shared_ptr<rclcpp_action::ClientGoalHandle<t3_action_msg::action::Move> > >)>]'
  /home/user/ros2_ws/src/my_action_client/src/action_client.cpp:61:66:   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(std::shared_ptr<rclcpp_action::ClientGoalHandle<t3_action_msg::action::Move> >)>&>'
   2211 |     using __enable_if_t = typename enable_if<_Cond, _Tp>::type;
        |           ^~~~~~~~~~~~~
  In file included from /usr/include/c++/11/functional:59,
                   from /usr/include/c++/11/pstl/glue_algorithm_defs.h:13,
                   from /usr/include/c++/11/algorithm:74,
                   from /home/simulations/ros2_sims_ws/install/t3_action_msg/include/t3_action_msg/t3_action_msg/action/detail/move__struct.hpp:8,
                   from /home/simulations/ros2_sims_ws/install/t3_action_msg/include/t3_action_msg/t3_action_msg/action/move.hpp:7,
                   from /home/user/ros2_ws/src/my_action_client/src/action_client.cpp:6:
  /usr/include/c++/11/bits/std_function.h:540:9: note: candidate: 'template<class _Functor> std::function<_Res(_ArgTypes ...)>& std::function<_Res(_ArgTypes ...)>::operator=(std::reference_wrapper<_Functor>) [with _Functor = _Functor; _Res = void; _ArgTypes = {std::shared_ptr<rclcpp_action::ClientGoalHandle<t3_action_msg::action::Move> >}]'
    540 |         operator=(reference_wrapper<_Functor> __f) noexcept
        |         ^~~~~~~~
  /usr/include/c++/11/bits/std_function.h:540:9: note:   template argument deduction/substitution failed:
  /home/user/ros2_ws/src/my_action_client/src/action_client.cpp:61:66: note:   'std::_Bind<void (MyActionClient::*(MyActionClient*,std::_Placeholder<1>))(std::shared_future<std::shared_ptr<rclcpp_action::ClientGoalHandle<t3_action_msg::action::Move> > >)>' is not derived from 'std::reference_wrapper<_Tp>'
     61 |       std::bind(&MyActionClient::goal_response_callback, this, _1);
        |                                                                  ^
  In file included from /usr/include/c++/11/functional:59,
                   from /usr/include/c++/11/pstl/glue_algorithm_defs.h:13,
                   from /usr/include/c++/11/algorithm:74,
                   from /home/simulations/ros2_sims_ws/install/t3_action_msg/include/t3_action_msg/t3_action_msg/action/detail/move__struct.hpp:8,
                   from /home/simulations/ros2_sims_ws/install/t3_action_msg/include/t3_action_msg/t3_action_msg/action/move.hpp:7,
                   from /home/user/ros2_ws/src/my_action_client/src/action_client.cpp:6:
  /usr/include/c++/11/bits/std_function.h:469:7: note: candidate: 'std::function<_Res(_ArgTypes ...)>& std::function<_Res(_ArgTypes...)>::operator=(const std::function<_Res(_ArgTypes ...)>&) [with _Res = void; _ArgTypes = {std::shared_ptr<rclcpp_action::ClientGoalHandle<t3_action_msg::action::Move> >}]'
    469 |       operator=(const function& __x)
        |       ^~~~~~~~
  /usr/include/c++/11/bits/std_function.h:469:33: note:   no known conversion for argument 1 from 'std::_Bind_helper<false, void (MyActionClient::*)(std::shared_future<std::shared_ptr<rclcpp_action::ClientGoalHandle<t3_action_msg::action::Move> > >), MyActionClient*, const std::_Placeholder<1>&>::type' to 'const std::function<void(std::shared_ptr<rclcpp_action::ClientGoalHandle<t3_action_msg::action::Move> >)>&'
    469 |       operator=(const function& __x)
        |                 ~~~~~~~~~~~~~~~~^~~
  /usr/include/c++/11/bits/std_function.h:487:7: note: candidate: 'std::function<_Res(_ArgTypes ...)>& std::function<_Res(_ArgTypes...)>::operator=(std::function<_Res(_ArgTypes ...)>&&) [with _Res = void; _ArgTypes = {std::shared_ptr<rclcpp_action::ClientGoalHandle<t3_action_msg::action::Move> >}]'
    487 |       operator=(function&& __x) noexcept
        |       ^~~~~~~~
  /usr/include/c++/11/bits/std_function.h:487:28: note:   no known conversion for argument 1 from 'std::_Bind_helper<false, void (MyActionClient::*)(std::shared_future<std::shared_ptr<rclcpp_action::ClientGoalHandle<t3_action_msg::action::Move> > >), MyActionClient*, const std::_Placeholder<1>&>::type' to 'std::function<void(std::shared_ptr<rclcpp_action::ClientGoalHandle<t3_action_msg::action::Move> >)>&&'
    487 |       operator=(function&& __x) noexcept
        |                 ~~~~~~~~~~~^~~
  /usr/include/c++/11/bits/std_function.h:501:7: note: candidate: 'std::function<_Res(_ArgTypes ...)>& std::function<_Res(_ArgTypes...)>::operator=(std::nullptr_t) [with _Res = void; _ArgTypes = {std::shared_ptr<rclcpp_action::ClientGoalHandle<t3_action_msg::action::Move> >}; std::nullptr_t = std::nullptr_t]'
    501 |       operator=(nullptr_t) noexcept
        |       ^~~~~~~~
  /usr/include/c++/11/bits/std_function.h:501:17: note:   no known conversion for argument 1 from 'std::_Bind_helper<false, void (MyActionClient::*)(std::shared_future<std::shared_ptr<rclcpp_action::ClientGoalHandle<t3_action_msg::action::Move> > >), MyActionClient*, const std::_Placeholder<1>&>::type' to 'std::nullptr_t'
    501 |       operator=(nullptr_t) noexcept
        |                 ^~~~~~~~~
  gmake[2]: *** [CMakeFiles/action_client_node.dir/build.make:76: CMakeFiles/action_client_node.dir/src/action_client.cpp.o] Error 1
  gmake[1]: *** [CMakeFiles/Makefile2:137: CMakeFiles/action_client_node.dir/all] Error 2
  gmake: *** [Makefile:146: all] Error 2
  ---
  Failed   <<< my_action_client [5.96s, exited with code 2]
  
  Summary: 0 packages finished [6.21s]
    1 package failed: my_action_client
    1 package had stderr output: my_action_client

I trying to solve but I can’t find the solution.
Some advice?

Hi @Voltedge ,

Please refer this link for the solution: ROS2 Basics in 5 Days Humble (C++) course - example 5.2 in Unit 5.2.2 - #10 by mosgaed

Regards,
Girish