Ask Your Question
0

std::bind in function callback for subscription or service on ros 2

asked 2019-04-02 03:11:29 -0500

Amel--E gravatar image

updated 2019-04-03 03:25:14 -0500

gvdhoorn gravatar image

Edit:

Ok so I tried adding this request_header variable and add a std::placeholders but it's not working either. This time I get the same kind of error :

In file included from /opt/ros/crystal/include/rclcpp/node_impl.hpp:42:0,
                 from /opt/ros/crystal/include/rclcpp/node.hpp:524,
                 from /opt/ros/crystal/include/rclcpp/executors/single_threaded_executor.hpp:28,
                 from /opt/ros/crystal/include/rclcpp/executors.hpp:22,
                 from /opt/ros/crystal/include/rclcpp/rclcpp.hpp:144,
                 from /home/innovation/ros2_ws/src/balyo_utils_ros/src/ping.cpp:1: /opt/ros/crystal/include/rclcpp/create_service.hpp: In instantiation of ‘typename rclcpp::Service<ServiceT>::SharedPtr rclcpp::create_service(std::shared_ptr<rclcpp::node_interfaces::NodeBaseInterface>, std::shared_ptr<rclcpp::node_interfaces::NodeServicesInterface>, const string&, CallbackT&&, const rmw_qos_profile_t&, rclcpp::callback_group::CallbackGroup::SharedPtr) [with ServiceT = balyo_msgs::srv::GetBool; CallbackT = std::_Bind<bool (Ping::*(Ping*, std::_Placeholder<1>, std::_Placeholder<2>, std::_Placeholder<3>))(std::shared_ptr<rmw_request_id_t>, balyo_msgs::srv::GetBool_Request_<std::allocator<void>
>&, balyo_msgs::srv::GetBool_Response_<std::allocator<void>
>&)>; typename rclcpp::Service<ServiceT>::SharedPtr = std::shared_ptr<rclcpp::Service<balyo_msgs::srv::GetBool>
>; std::__cxx11::string = std::__cxx11::basic_string<char>; rmw_qos_profile_t = rmw_qos_profile_t; rclcpp::callback_group::CallbackGroup::SharedPtr
= std::shared_ptr<rclcpp::callback_group::CallbackGroup>]’: /opt/ros/crystal/include/rclcpp/node_impl.hpp:201:53: required from ‘typename rclcpp::Service<ServiceT>::SharedPtr rclcpp::Node::create_service(const string&, CallbackT&&, const rmw_qos_profile_t&, rclcpp::callback_group::CallbackGroup::SharedPtr) [with ServiceT = balyo_msgs::srv::GetBool; CallbackT = std::_Bind<bool (Ping::*(Ping*, std::_Placeholder<1>, std::_Placeholder<2>, std::_Placeholder<3>))(std::shared_ptr<rmw_request_id_t>, balyo_msgs::srv::GetBool_Request_<std::allocator<void>
>&, balyo_msgs::srv::GetBool_Response_<std::allocator<void>
>&)>; typename rclcpp::Service<ServiceT>::SharedPtr = std::shared_ptr<rclcpp::Service<balyo_msgs::srv::GetBool>
>; std::__cxx11::string = std::__cxx11::basic_string<char>; rmw_qos_profile_t = rmw_qos_profile_t; rclcpp::callback_group::CallbackGroup::SharedPtr
= std::shared_ptr<rclcpp::callback_group::CallbackGroup>]’ /home/innovation/ros2_ws/src/balyo_utils_ros/src/ping.cpp:97:182: required from here /opt/ros/crystal/include/rclcpp/create_service.hpp:43:3: error: no matching function for call to ‘rclcpp::AnyServiceCallback<balyo_msgs::srv::GetBool>::set(std::_Bind<bool (Ping::*(Ping*, std::_Placeholder<1>, std::_Placeholder<2>, std::_Placeholder<3>))(std::shared_ptr<rmw_request_id_t>, balyo_msgs::srv::GetBool_Request_<std::allocator<void>
>&, balyo_msgs::srv::GetBool_Response_<std::allocator<void>
>&)>)’    any_service_callback.set(std::forward<CallbackT>(callback)); ^~~~~~~~~~~~~~~~~~~~ In file included from /opt/ros/crystal/include/rclcpp/service.hpp:27:0,
                 from /opt/ros/crystal/include/rclcpp/callback_group.hpp:24,
                 from /opt/ros/crystal/include/rclcpp/any_executable.hpp:20,
                 from /opt/ros/crystal/include/rclcpp/memory_strategy.hpp:24,
                 from /opt/ros/crystal/include/rclcpp/memory_strategies.hpp:18,
                 from /opt/ros/crystal/include/rclcpp/executor.hpp:32,
                 from /opt/ros/crystal/include/rclcpp/executors/multi_threaded_executor.hpp:24,
                 from /opt/ros/crystal/include/rclcpp/executors.hpp:21,
                 from /opt/ros/crystal/include/rclcpp/rclcpp.hpp:144,
                 from /home/innovation/ros2_ws/src/balyo_utils_ros/src/ping.cpp:1: /opt/ros/crystal/include/rclcpp/any_service_callback.hpp:65:8: note: candidate: template<class CallbackT, typename std::enable_if<rclcpp::function_traits::same_arguments<CallbackT, std::function<void(std::shared_ptr<balyo_msgs::srv::GetBool_Request_<std::allocator<void>
> >, std::shared_ptr<balyo_msgs::srv::GetBool_Response_<std::allocator<void>
> >)> >::value, void>::type* <anonymous> > void rclcpp::AnyServiceCallback<ServiceT>::set(CallbackT) [with ...
(more)
edit retag flag offensive close merge delete

Comments

@Amel--E: please don't post answers to provide more information. Only post answers to actually answer your own question. For everything else: short -> comments. More code or error messages: edit your original post (add a section).

gvdhoorn gravatar imagegvdhoorn ( 2019-04-03 03:26:31 -0500 )edit

1 Answer

Sort by » oldest newest most voted
0

answered 2019-04-02 10:57:50 -0500

Karsten gravatar image

You might want to double check your callback signature. I believe two placeholders are not enough, you'd need three. See the examples here: https://github.com/ros2/examples/blob...

void handle_service( const std::shared_ptr<rmw_request_id_t> request_header, const std::shared_ptr<AddTwoInts::Request> request, const std::shared_ptr<AddTwoInts::Response> response)

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

2 followers

Stats

Asked: 2019-04-02 03:11:29 -0500

Seen: 78 times

Last updated: Apr 03