Ask Your Question

How to use ros::service::call()

asked 2020-08-05 14:15:43 -0500

bevilllmen23 gravatar image

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", ??)

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2020-08-06 03:52:53 -0500

praskot gravatar image

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 (
    ROS_ERROR("Failed to call service move_base_node/clear_costmaps");
    return 1;
edit flag offensive delete link more


Thank you, from this I was able to do std_srvs::Empty srv;ros::service::call("/move_base_node/clear_costmaps", srv);

bevilllmen23 gravatar image bevilllmen23  ( 2020-08-06 18:25:52 -0500 )edit

Your Answer

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

Add Answer

Question Tools



Asked: 2020-08-05 14:15:43 -0500

Seen: 1,064 times

Last updated: Aug 06 '20