ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

This calls the service I think, but I need to send a request with it. How Can I call a service without a request?

In short you cannot call a service without a request. Actually this is the same in ROS 1 as trig constitutes the request holder you are calling the service with. In ROS 2 you need to explicitly pass a request object.

You can create it like this:

auto request = std::make_shared<std_srvs::srv::Trigger::Request>();

And call your service:

auto result_future = client->async_send_request(request);

You can see https://github.com/ros2/examples/blob/35674eb17494ab3f67cc5fbe5f127c614be2220b/rclcpp/minimal_client/main.cpp for an example of a request being created and then used to call a service. The difference in your case is that the request has no fields to set as it will be "empty". So you can just create it and call the service with it.