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

how to call a service inside a node?

asked 2015-01-23 11:03:12 -0500

Robot gravatar image

I am working with summitXL. After reaching the target point I would like to set the odometry by calling the ros service "/summit_a/set_odometry". How can I call the service inside the node. Thanks in advance.

edit retag flag offensive close merge delete

3 Answers

Sort by » oldest newest most voted

answered 2015-01-23 11:11:35 -0500

Hey there,

Please check here:

Probably you are looking for: Writing a Simple Service and Client (C++)

edit flag offensive delete link more



thanks for the ans. but all I need is to call a predefined service inside my node.

Robot gravatar image Robot  ( 2015-01-23 11:13:20 -0500 )edit

Which is exactly what the service client tutorial teaches you.

gvdhoorn gravatar image gvdhoorn  ( 2015-01-23 11:15:06 -0500 )edit

but I have to call the service in the callback function where it has no nodehandle object.

Robot gravatar image Robot  ( 2015-01-23 11:26:22 -0500 )edit

You should store the NodeHandle somewhere that can be accessed inside the callback so you can use it.

tfoote gravatar image tfoote  ( 2015-03-12 13:57:19 -0500 )edit

Instead of writing all these, a simple answer would be convenient for everyone. Besides, even in that tutorial, it's not clear. There is add_two_ints variable, said to be handle, but should it have the same name when it's a function or a variable, it's vague.

Jägermeister gravatar image Jägermeister  ( 2019-08-05 07:41:59 -0500 )edit

answered 2019-10-21 06:49:02 -0500

mustafadurmus gravatar image

You can call a ros service inside a node like:

import rosservice
edit flag offensive delete link more

answered 2020-08-05 22:54:50 -0500

ParkerRobert gravatar image

updated 2021-03-08 07:51:18 -0500

To add on to the above answer. You can enter the following into a c++ script. In my example I wanted to call a service and set a bool periodically to true

#include "ros/service_client.h"
#include "ros/ros.h"
#include "std_srvs/SetBool.h"

ros::ServiceClient example_srv;
std_srvs::SetBool example_boolean_value; = true;;
edit flag offensive delete link more

Question Tools

1 follower


Asked: 2015-01-23 11:03:12 -0500

Seen: 6,893 times

Last updated: Mar 08 '21