ros / ros_tutorials

Code used in tutorials found on ROS wiki
http://wiki.ros.org/ros_tutorials
787 stars 537 forks source link

Calling a service causes error - "failed to send response" #155

Closed KlaudiuszSoltysik closed 1 year ago

KlaudiuszSoltysik commented 1 year ago

A couple days ago I was using turtlesim without any issues with code like that:

rclcpp::Client<turtlesim::srv::SetPen>::SharedPtr set_pen_ball_cli;

set_pen_ball_cli = this->create_client<turtlesim::srv::SetPen>("turtle1/set_pen");

while(!set_pen_ball_cli->wait_for_service(std::chrono::seconds(1))) {
    RCLCPP_INFO(rclcpp::get_logger("rclcpp"), "service not available, waiting again...");
}

auto request = std::make_shared<turtlesim::srv::SetPen::Request>();
request->off = 1;
auto res = set_pen_ball_cli->async_send_request(request);

Now running this code causes error:

terminate called after throwing an instance of 'rclcpp::exceptions::RCLError'
  what():  failed to send response: client will not receive response, at ./src/rmw_response.cpp:149, at ./src/rcl/service.c:314
[ros2run]: Aborted

There is problem with other services, like spawn service, where:

int index = 0;
req->name = "turtle" + std::to_str(index);

iscausing error, but:

req->name = "turtle0";

is ok. I'm working on ROS2 Humble and Ubuntu 22.04.