Ask Your Question
0

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

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

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
1

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

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 (client.call(srv))
  {
    ROS_INFO("Success!");
  }
  else
  {
    ROS_ERROR("Failed to call service move_base_node/clear_costmaps");
    return 1;
  }
edit flag offensive delete link more

Comments

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 -0600 )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

2 followers

Stats

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

Seen: 819 times

Last updated: Aug 06 '20