ros-sharp Service call
I created sample ros service to add 2 numbers. I put the code on git
I can test service with:
rosservice call /add_numbers [1,2]
and get response
sum: 3.0
what is OK,
But don't know how to do the same call with ros-sharp over rosbridge.
I try the only sample from here and it work OK but only for GetParamRequest
// Service Call:
rosSocket.CallService<rosapi.GetParamRequest, rosapi.GetParamResponse>("/rosapi/get_param", ServiceCallHandler, new rosapi.GetParamRequest("/rosdistro", "default"));
How to change this line to call my add_numbers
???
Asked by jernejp on 2019-08-01 14:38:51 UTC
Answers
Hello @jernejp,
I'm not an expert on ROS#, but I found an example in their repository using a console socket:
Launching a node, consuming a topic and calling a service
Line 58: service is called
rosSocket.CallService<rosapi.GetParamRequest, rosapi.GetParamResponse>("/rosapi/get_param", ServiceCallHandler, new rosapi.GetParamRequest("/rosdistro", "default"));
Line 78: handling service response
private static void ServiceCallHandler(rosapi.GetParamResponse message)
{
Console.WriteLine("ROS distro: " + message.value);
}
I hope it can help you.
Asked by marcoarruda on 2019-08-02 11:10:00 UTC
Comments
IIUC, the code you show tests whether the JsonConvert.SerializeObject(..)
function correctly transforms ServiceCall
instances to json fragments. It does not show how to invoke a service call.
as far as I know, ROS services are asynchronous
services are not asynchronous. They are synchronous. Actions can be both.
Asked by gvdhoorn on 2019-08-02 11:39:20 UTC
Thanks for the observation! As I said, not an expert on ROS#, but thought it could give a clue. Let me fix the wrong guesses on the answer :) The confusion about services.. we handle the response on a callback, like a subscriber, but indeed they are synchronous. Thanks
Asked by marcoarruda on 2019-08-02 12:45:33 UTC
This still seems incorrect:
Then, you must have a response
string json = JsonConvert.SerializeObject(comm);
json
is not the response, it's the json-ified version of the request ..
Edit: thanks for the edit. This seems like something the OP could use.
Asked by gvdhoorn on 2019-08-02 12:51:26 UTC
Comments