std::bind in create_service error

asked 2022-04-26 03:19:57 -0500

mrbh gravatar image

I am currently making a school assignment. With this assignment I am creating a node that has a subscription to battery_state and a service.

The subscription callback sets a variable to the lastest batterypercentage and when the service is called, the service responds with the latest batterypercentage. This is done to prevent flooding of our behaviourtree. However, I am getting an error while colcon building.

It looks like the error comes up with the std::bind to bind our function to the service.

Error

--- stderr: cpp_srvcli                                    
/home/student/GitRepo/durable-case-3/src/Turtle_WS/src/cpp_srvcli/src/batterystate.cpp: In constructor ‘BatteryState::BatteryState()’:
/home/student/GitRepo/durable-case-3/src/Turtle_WS/src/cpp_srvcli/src/batterystate.cpp:13:31: error: no matching function for call to ‘BatteryState::create_service<tutorial_interfaces::srv::AddThreeInts>(const char [15], int, std::_Bind_helper<false, void (BatteryState::*)(std::shared_ptr<rmw_request_id_t>, std::shared_ptr<tutorial_interfaces::srv::AddThreeInts_Request_<std::allocator<void> > >, std::shared_ptr<tutorial_interfaces::srv::AddThreeInts_Response_<std::allocator<void> > >), BatteryState*, const std::_Placeholder<1>&, const std::_Placeholder<2>&, const std::_Placeholder<3>&>::type)’
   13 |         std::placeholders::_3)); //respondse
      |                               ^
In file included from /opt/ros/foxy/include/rclcpp/executors/single_threaded_executor.hpp:28,
                 from /opt/ros/foxy/include/rclcpp/executors.hpp:22,
                 from /opt/ros/foxy/include/rclcpp/rclcpp.hpp:146,
                 from /home/student/GitRepo/durable-case-3/src/Turtle_WS/src/cpp_srvcli/src/batterystate.hpp:6,
                 from /home/student/GitRepo/durable-case-3/src/Turtle_WS/src/cpp_srvcli/src/batterystate.cpp:1:
/opt/ros/foxy/include/rclcpp/node.hpp:261:3: note: candidate: ‘template<class ServiceT, class CallbackT> typename rclcpp::Service<ServiceT>::SharedPtr rclcpp::Node::create_service(const string&, CallbackT&&, const rmw_qos_profile_t&, rclcpp::CallbackGroup::SharedPtr)’
  261 |   create_service(
      |   ^~~~~~~~~~~~~~
/opt/ros/foxy/include/rclcpp/node.hpp:261:3: note:   template argument deduction/substitution failed:
/home/student/GitRepo/durable-case-3/src/Turtle_WS/src/cpp_srvcli/src/batterystate.cpp:10:22: note:   cannot convert ‘std::bind(_Func&&, _BoundArgs&& ...) [with _Func = void (BatteryState::*)(std::shared_ptr<rmw_request_id_t>, std::shared_ptr<tutorial_interfaces::srv::AddThreeInts_Request_<std::allocator<void> > >, std::shared_ptr<tutorial_interfaces::srv::AddThreeInts_Response_<std::allocator<void> > >); _BoundArgs = {BatteryState*, const std::_Placeholder<1>&, const std::_Placeholder<2>&, const std::_Placeholder<3>&}; typename std::_Bind_helper<std::__is_socketlike<_Func>::value, _Func, _BoundArgs ...>::type = std::_Bind<void (BatteryState::*(BatteryState*, std::_Placeholder<1>, std::_Placeholder<2>, std::_Placeholder<3>))(std::shared_ptr<rmw_request_id_t>, std::shared_ptr<tutorial_interfaces::srv::AddThreeInts_Request_<std::allocator<void> > >, std::shared_ptr<tutorial_interfaces::srv::AddThreeInts_Response_<std::allocator<void> > >)>](((BatteryState*)this), std::placeholders::_1, std::placeholders::_2, std::placeholders::_3)’ (type ‘std::_Bind_helper<false, void (BatteryState::*)(std::shared_ptr<rmw_request_id_t>, std::shared_ptr<tutorial_interfaces::srv::AddThreeInts_Request_<std::allocator<void> > >, std::shared_ptr<tutorial_interfaces::srv::AddThreeInts_Response_<std::allocator<void> > >), BatteryState*, const std::_Placeholder<1>&, const std::_Placeholder<2>&, const std::_Placeholder<3>&>::type’ {aka ‘std::_Bind<void (BatteryState::*(BatteryState*, std::_Placeholder<1>, std::_Placeholder<2>, std::_Placeholder<3>))(std::shared_ptr<rmw_request_id_t>, std::shared_ptr<tutorial_interfaces::srv::AddThreeInts_Request_<std::allocator<void> > >, std::shared_ptr<tutorial_interfaces::srv::AddThreeInts_Response_<std::allocator<void> > >)>’}) to type ‘const rmw_qos_profile_t&’
   10 |         10, std::bind(&BatteryState::RespondBatteryState,this,
      |             ~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   11 |         std::placeholders::_1, //header
      |         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   12 |         std::placeholders::_2, //request
      |         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   13 |         std::placeholders::_3)); //respondse
      |         ~~~~~~~~~~~~~~~~~~~~~~
make[2]: *** [CMakeFiles/batterypercentage.dir/build.make:63: CMakeFiles/batterypercentage.dir/src/batterystate.cpp.o] Error 1
make[1]: *** [CMakeFiles/Makefile2:107: CMakeFiles/batterypercentage.dir/all] Error 2
make: *** [Makefile:141: all] Error 2
---
Failed   <<< cpp_srvcli [35.0s, exited with code 2]

Summary: 2 packages finished ...
(more)
edit retag flag offensive close merge delete