--- stderr: learning_action_cpp
/userdata/dev_ws/src/ros2_21_tutorials/learning_action_cpp/src/action_move_client.cpp: In member function ‘void MoveCircleActionClient::send_goal(bool)’:
/userdata/dev_ws/src/ros2_21_tutorials/learning_action_cpp/src/action_move_client.cpp:48:84: error: no match for ‘operator=’ (operand types are ‘rclcpp_action::Client<learning_interface::action::MoveCircle>::GoalResponseCallback’ {aka ‘std::function<void(std::shared_future<std::shared_ptr<rclcpp_action::ClientGoalHandle<learning_interface::action::MoveCircle> > >)>’} and ‘std::_Bind_helper<false, void (MoveCircleActionClient::*)(std::shared_ptr<rclcpp_action::ClientGoalHandle<learning_interface::action::MoveCircle> >), MoveCircleActionClient*, const std::_Placeholder<1>&>::type’ {aka ‘std::_Bind<void (MoveCircleActionClient::*(MoveCircleActionClient*, std::_Placeholder<1>))(std::shared_ptr<rclcpp_action::ClientGoalHandle<learning_interface::action::MoveCircle> >)>’})
48 | std::bind(&MoveCircleActionClient::goal_response_callback, this, _1);
| ^
In file included from /usr/include/c++/9/future:48,
from /opt/ros/foxy/include/rclcpp/executors.hpp:18,
from /opt/ros/foxy/include/rclcpp/rclcpp.hpp:146,
from /userdata/dev_ws/src/ros2_21_tutorials/learning_action_cpp/src/action_move_client.cpp:8:
/usr/include/c++/9/bits/std_function.h:462:7: note: candidate: ‘std::function<_Res(_ArgTypes ...)>& std::function<_Res(_ArgTypes ...)>::operator=(const std::function<_Res(_ArgTypes ...)>&) [with _Res = void; _ArgTypes = {std::shared_future<std::shared_ptr<rclcpp_action::ClientGoalHandle<learning_interface::action::MoveCircle> > >}]’
462 | operator=(const function& __x)
| ^~~~~~~~
/usr/include/c++/9/bits/std_function.h:462:33: note: no known conversion for argument 1 from ‘std::_Bind_helper<false, void (MoveCircleActionClient::*)(std::shared_ptr<rclcpp_action::ClientGoalHandle<learning_interface::action::MoveCircle> >), MoveCircleActionClient*, const std::_Placeholder<1>&>::type’ {aka ‘std::_Bind<void (MoveCircleActionClient::*(MoveCircleActionClient*, std::_Placeholder<1>))(std::shared_ptr<rclcpp_action::ClientGoalHandle<learning_interface::action::MoveCircle> >)>’} to ‘const std::function<void(std::shared_future<std::shared_ptr<rclcpp_action::ClientGoalHandle<learning_interface::action::MoveCircle> > >)>&’
462 | operator=(const function& __x)
| ~~~~~~~~~~~~~~~~^~~
/usr/include/c++/9/bits/std_function.h:480:7: note: candidate: ‘std::function<_Res(_ArgTypes ...)>& std::function<_Res(_ArgTypes ...)>::operator=(std::function<_Res(_ArgTypes ...)>&&) [with _Res = void; _ArgTypes = {std::shared_future<std::shared_ptr<rclcpp_action::ClientGoalHandle<learning_interface::action::MoveCircle> > >}]’
480 | operator=(function&& __x) noexcept
| ^~~~~~~~
/usr/include/c++/9/bits/std_function.h:480:28: note: no known conversion for argument 1 from ‘std::_Bind_helper<false, void (MoveCircleActionClient::*)(std::shared_ptr<rclcpp_action::ClientGoalHandle<learning_interface::action::MoveCircle> >), MoveCircleActionClient*, const std::_Placeholder<1>&>::type’ {aka ‘std::_Bind<void (MoveCircleActionClient::*(MoveCircleActionClient*, std::_Placeholder<1>))(std::shared_ptr<rclcpp_action::ClientGoalHandle<learning_interface::action::MoveCircle> >)>’} to ‘std::function<void(std::shared_future<std::shared_ptr<rclcpp_action::ClientGoalHandle<learning_interface::action::MoveCircle> > >)>&&’
480 | operator=(function&& __x) noexcept
| ~~~~~~~~~~~^~~
/usr/include/c++/9/bits/std_function.h:494:7: note: candidate: ‘std::function<_Res(_ArgTypes ...)>& std::function<_Res(_ArgTypes ...)>::operator=(std::nullptr_t) [with _Res = void; _ArgTypes = {std::shared_future<std::shared_ptr<rclcpp_action::ClientGoalHandle<learning_interface::action::MoveCircle> > >}; std::nullptr_t = std::nullptr_t]’
494 | operator=(nullptr_t) noexcept
| ^~~~~~~~
/usr/include/c++/9/bits/std_function.h:494:17: note: no known conversion for argument 1 from ‘std::_Bind_helper<false, void (MoveCircleActionClient::*)(std::shared_ptr<rclcpp_action::ClientGoalHandle<learning_interface::action::MoveCircle> >), MoveCircleActionClient*, const std::_Placeholder<1>&>::type’ {aka ‘std::_Bind<void (MoveCircleActionClient::*(MoveCircleActionClient*, std::_Placeholder<1>))(std::shared_ptr<rclcpp_action::ClientGoalHandle<learning_interface::action::MoveCircle> >)>’} to ‘std::nullptr_t’
494 | operator=(nullptr_t) noexcept
| ^~~~~~~~~
/usr/include/c++/9/bits/std_function.h:523:2: note: candidate: ‘template<class _Functor> std::function<_Res(_ArgTypes ...)>::_Requires<std::function<_Res(_ArgTypes ...)>::_Callable<typename std::decay<_Functor>::type>, std::function<_Res(_ArgTypes ...)>&> std::function<_Res(_ArgTypes ...)>::operator=(_Functor&&) [with _Functor = _Functor; _Res = void; _ArgTypes = {std::shared_future<std::shared_ptr<rclcpp_action::ClientGoalHandle<learning_interface::action::MoveCircle> > >}]’
523 | operator=(_Functor&& __f)
| ^~~~~~~~
/usr/include/c++/9/bits/std_function.h:523:2: note: template argument deduction/substitution failed:
/usr/include/c++/9/bits/std_function.h: In substitution of ‘template<class _Res, class ... _ArgTypes> template<class _Cond, class _Tp> using _Requires = typename std::enable_if<_Cond::value, _Tp>::type [with _Cond = std::function<void(std::shared_future<std::shared_ptr<rclcpp_action::ClientGoalHandle<learning_interface::action::MoveCircle> > >)>::_Callable<std::_Bind<void (MoveCircleActionClient::*(MoveCircleActionClient*, std::_Placeholder<1>))(std::shared_ptr<rclcpp_action::ClientGoalHandle<learning_interface::action::MoveCircle> >)>, std::__invoke_result<std::_Bind<void (MoveCircleActionClient::*(MoveCircleActionClient*, std::_Placeholder<1>))(std::shared_ptr<rclcpp_action::ClientGoalHandle<learning_interface::action::MoveCircle> >)>&, std::shared_future<std::shared_ptr<rclcpp_action::ClientGoalHandle<learning_interface::action::MoveCircle> > > > >; _Tp = std::function<void(std::shared_future<std::shared_ptr<rclcpp_action::ClientGoalHandle<learning_interface::action::MoveCircle> > >)>&; _Res = void; _ArgTypes = {std::shared_future<std::shared_ptr<rclcpp_action::ClientGoalHandle<learning_interface::action::MoveCircle> > >}]’:
/usr/include/c++/9/bits/std_function.h:523:2: required by substitution of ‘template<class _Functor> std::function<void(std::shared_future<std::shared_ptr<rclcpp_action::ClientGoalHandle<learning_interface::action::MoveCircle> > >)>::_Requires<std::function<void(std::shared_future<std::shared_ptr<rclcpp_action::ClientGoalHandle<learning_interface::action::MoveCircle> > >)>::_Callable<typename std::decay<_Tp>::type, std::__invoke_result<typename std::decay<_Tp>::type&, std::shared_future<std::shared_ptr<rclcpp_action::ClientGoalHandle<learning_interface::action::MoveCircle> > > > >, std::function<void(std::shared_future<std::shared_ptr<rclcpp_action::ClientGoalHandle<learning_interface::action::MoveCircle> > >)>&> std::function<void(std::shared_future<std::shared_ptr<rclcpp_action::ClientGoalHandle<learning_interface::action::MoveCircle> > >)>::operator=<_Functor>(_Functor&&) [with _Functor = std::_Bind<void (MoveCircleActionClient::*(MoveCircleActionClient*, std::_Placeholder<1>))(std::shared_ptr<rclcpp_action::ClientGoalHandle<learning_interface::action::MoveCircle> >)>]’
/userdata/dev_ws/src/ros2_21_tutorials/learning_action_cpp/src/action_move_client.cpp:48:84: required from here
/usr/include/c++/9/bits/std_function.h:385:8: error: no type named ‘type’ in ‘struct std::enable_if<false, std::function<void(std::shared_future<std::shared_ptr<rclcpp_action::ClientGoalHandle<learning_interface::action::MoveCircle> > >)>&>’
385 | using _Requires = typename enable_if<_Cond::value, _Tp>::type;
| ^~~~~~~~~
/usr/include/c++/9/bits/std_function.h:532:2: 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_future<std::shared_ptr<rclcpp_action::ClientGoalHandle<learning_interface::action::MoveCircle> > >}]’
532 | operator=(reference_wrapper<_Functor> __f) noexcept
| ^~~~~~~~
/usr/include/c++/9/bits/std_function.h:532:2: note: template argument deduction/substitution failed:
/userdata/dev_ws/src/ros2_21_tutorials/learning_action_cpp/src/action_move_client.cpp:48:84: note: ‘std::_Bind<void (MoveCircleActionClient::*(MoveCircleActionClient*, std::_Placeholder<1>))(std::shared_ptr<rclcpp_action::ClientGoalHandle<learning_interface::action::MoveCircle> >)>’ is not derived from ‘std::reference_wrapper<_Tp>’
48 | std::bind(&MoveCircleActionClient::goal_response_callback, this, _1);
| ^
make[2]: *** [CMakeFiles/action_move_client.dir/build.make:63: CMakeFiles/action_move_client.dir/src/action_move_client.cpp.o] Error 1
make[1]: *** [CMakeFiles/Makefile2:80: CMakeFiles/action_move_client.dir/all] Error 2
make: *** [Makefile:141: all] Error 2
---
Failed <<< learning_action_cpp [9.24s, exited with code 2]
Summary: 20 packages finished [42.0s]
1 package failed: learning_action_cpp
1 package had stderr output: learning_action_cpp
thomas@ubuntu:/userdata/dev_ws$
=====================================
# Humble与Foxy版本兼容性说明
本代码仓库测试环境为:Ubuntu22.04+ROS Humble
如使用Ubuntu20.04+ROS Foxy,由于部分API接口不完全兼容,需要做一下代码修改:
## learning_action_cpp功能包
![build_error](docs\images\build_error.png)
原始代码:
// 创建一个服务器收到目标之后反馈时的回调函数
void goal_response_callback(GoalHandle::SharedPtr goal_message)
{
if (!goal_message)
{
RCLCPP_ERROR(this->get_logger(), "Client: Goal was rejected by server");
rclcpp::shutdown(); // Shut down client node
}
else
{
RCLCPP_INFO(this->get_logger(), "Client: Goal accepted by server, waiting for result");
}
}
需要更改为:
// 创建一个服务器收到目标之后反馈时的回调函数
void goal_response_callback(std::shared_future<GoalHandle::SharedPtr> goal_message)
{
if (!goal_message.get())
{
RCLCPP_ERROR(this->get_logger(), "Client: Goal was rejected by server");
rclcpp::shutdown(); // Shut down client node
}
else
{
RCLCPP_INFO(this->get_logger(), "Client: Goal accepted by server, waiting for result");
}
}