How to run a ROS service client within a Gazebo plugin
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 = current_lookup_client_.call(srv);
if (!success)
{
ROS_ERROR_STREAM_THROTTLE(1, "Failed to retrieve fluid velocity");
}
else
{
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]
current:
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");