[ROS2] services C++
Hi,
I'm trying to use services to work with a ROS2 canopen node. In ROS1 I was able to use this code:
ros::ServiceClient init = n.serviceClient< std_srvs::Trigger>("/driver/init");
std_srvs::Trigger trig;
init.call(trig)
If I follow the migration guide, I have following code:
rclcpp::Client< std_srvs::srv::Trigger>::SharedPtr client = node->create_client< std_srvs::srv::Trigger>("/driver/init");
std_srvs::srv::Trigger trig;
How do I call the service ?
init.call(trig)
This doesn't work
Edit: (tutorial services)
auto result = client->async_send_request(request);
// Wait for the result.
if (rclcpp::spin_until_future_complete(node, result) ==
rclcpp::executor::FutureReturnCode::SUCCESS)
{
RCLCPP_INFO(rclcpp::get_logger("rclcpp"), "Sum: %ld", result.get()->sum);
} else {
RCLCPP_ERROR(rclcpp::get_logger("rclcpp"), "Failed to call service add_two_ints");
}
This calls the service I think, but I need to send a request with it. How Can I call a service without a request? The Service file can only respond with some variables.
Thanks