Ask Your Question

How to run a ROS service client within a Gazebo plugin

asked 2015-08-12 15:23:20 -0500

Eivind Froystad gravatar image

updated 2015-08-14 03:09:23 -0500

I'm having trouble getting a service client to work within a Gazebo plugin. It is a custom service called WaterCurrentLookup.

geometry_msgs/Point coordinate
geometry_msgs/Vector3 current

Inside the Update method/function of the gazebo plugin, the following code is used:

// fluid velocity / Water current service
ros::ServiceClient current_lookup_client_= rosnode_->serviceClient<freefloating_gazebo::WaterCurrentLookup>("water_current_client");

// std::cout << current_lookup_client_.exists(); -> This outputs 0       

freefloating_gazebo::WaterCurrentLookup srv;
srv.request.coordinate.x = 1;
srv.request.coordinate.y = 2;
srv.request.coordinate.z = 3;

bool success =;

if (!success)
      ROS_ERROR_STREAM_THROTTLE(1, "Failed to retrieve fluid velocity");
      fluid_velocity_.Set(srv.response.current.x, srv.response.current.y, srv.response.current.z);

The server works, which is proven by running the following command:

rosservice call /get_water_current [1,1,1]
  x: 3.0
  y: 0.0
  z: 0.0

The header file is included (#include <freefloating_gazebo/WaterCurrentLookup.h>).

Somehow this does not work. The variable success is always false. When I check if current_lookup_client_ exists it outputs 0. I've followed the tutorials and used the documentation, and cannot find out what I'm missing here. I'm using ROS Indigo.

Any help would be highly appreciated!

SOLVED (Thanks to MIG):

I didn't add the / to the service name:

ros::ServiceClient current_lookup_client_= rosnode_->serviceClient<freefloating_gazebo::WaterCurrentLookup>("/water_current_client");
edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2015-08-13 01:24:49 -0500

mgruhler gravatar image

I can see two possible problems here. I'm not sure what you actually ask, as the question is not completely precise...

  1. You don't connect to the correct server (or any server at all):

When you set up the client, you connect to the service call <node_namespace>/water_current_client. The test you provide, you call the service /get_water_current. If this is the problem, change the Service client to /get_water_current and you should be okay. Maybe also think of checking for the server existence with the exists() or waitForService()functions (see the API docs).

  1. The call to returns false:

This seems to be a problem in your Service Server, not in the client.

Check if you have a return false in the Service Server callback somewhere. The call() function basically returns what you return from the Service Server Callback (which should return a bool), except if there is any communication error (in which case it also returns 'false' ).

edit flag offensive delete link more


Thank you: The error was that I didn't add the / before the service name.

Eivind Froystad gravatar image Eivind Froystad  ( 2015-08-14 03:06:49 -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: 2015-08-12 15:23:20 -0500

Seen: 873 times

Last updated: Aug 14 '15