Hi Paulo
The following code worked for me in implementing a ServiceClient in Android. Note that HMMv2/get_Joint_State.srv is a custom service of mine.
In the OnStart(ConnectedNode node) method (but before you implement a cancellable loop:
final ServiceClient<HMMv2.get_Joint_StateRequest, HMMv2.get_Joint_StateResponse> client;
try
{
client = node.newServiceClient("HMMv2Cont/JointState", HMMv2.get_Joint_State._TYPE);
}
catch (ServiceNotFoundException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
throw new RosRuntimeException(e);
}
final HMMv2.get_Joint_StateRequest request=client.newMessage();
request.setJointName("joints");
Then in the Cancellable loop, loop() function the code to call the service is:
client.call(request, new ServiceResponseListener<HMMv2.get_Joint_StateResponse>() {
@Override
public void onFailure(RemoteException arg0)
{
Log.d("Jointrequest Client", "failed to call service");
throw new RosRuntimeException(arg0);
// TODO Auto-generated method stub
}
@Override
public void onSuccess(HMMv2.get_Joint_StateResponse message)
{
//do something with the response
hPos.set(0, 0, (message.getJointState().getPosition()[0]-512)*Math.PI/512);
}
});
hope this example helps you. I think the main issue I found in implementing this was the declaration of a final ServiceClient types. But I've used this format a couple of times and it works.
cheers
Peter