Ask Your Question
0

ros-sharp Service call

asked 2019-08-01 14:38:51 -0600

jernejp gravatar image

updated 2019-08-02 11:43:02 -0600

jayess gravatar image

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???

edit retag flag offensive close merge delete

1 Answer

Sort by » oldest newest most voted
0

answered 2019-08-02 11:10:00 -0600

updated 2019-08-02 13:27:01 -0600

gvdhoorn gravatar image

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

https://github.com/siemens/ros-sharp/...

Line 58: service is called

https://github.com/siemens/ros-sharp/...

rosSocket.CallService<rosapi.GetParamRequest, rosapi.GetParamResponse>("/rosapi/get_param", ServiceCallHandler, new rosapi.GetParamRequest("/rosdistro", "default"));

Line 78: handling service response

https://github.com/siemens/ros-sharp/...

private static void ServiceCallHandler(rosapi.GetParamResponse message)
{
        Console.WriteLine("ROS distro: " + message.value);
}

I hope it can help you.

edit flag offensive delete link more

Comments

1

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.

gvdhoorn gravatar imagegvdhoorn ( 2019-08-02 11:39:20 -0600 )edit

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

marcoarruda gravatar imagemarcoarruda ( 2019-08-02 12:45:33 -0600 )edit

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.

gvdhoorn gravatar imagegvdhoorn ( 2019-08-02 12:51:26 -0600 )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

2 followers

Stats

Asked: 2019-08-01 14:38:51 -0600

Seen: 79 times

Last updated: Aug 02