0
$\begingroup$

Rosanswers logo

I want to call a service in code. The command line form is "rosservice call /move_base_node/clear_costmaps".

It has type std_srvs/Empty

There is function ros::service::call(const std::string &service_name, Service &service ) (documentation can be found here)

I am unsure what to put in the Service arg field

ros::service::call("/move_base_node/clear_costmaps", ??)


Originally posted by bevilllmen23 on ROS Answers with karma: 3 on 2020-08-05

Post score: 0

$\endgroup$

1 Answer 1

0
$\begingroup$

Rosanswers logo

Take a look at this rosservice tutorial.

  ros::NodeHandle n;
  ros::ServiceClient client = n.serviceClient<std_srvs::Empty>("/move_base_node/clear_costmaps");
  std_srvs::Empty srv;
  if (client.call(srv))
  {
    ROS_INFO("Success!");
  }
  else
  {
    ROS_ERROR("Failed to call service move_base_node/clear_costmaps");
    return 1;
  }

Originally posted by praskot with karma: 257 on 2020-08-06

This answer was ACCEPTED on the original site

Post score: 1


Original comments

Comment by bevilllmen23 on 2020-08-06:
Thank you, from this I was able to do std_srvs::Empty srv; ros::service::call("/move_base_node/clear_costmaps", srv);

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.