ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
0

ros-sharp Service call

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

jernejp gravatar image

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

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

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

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 image gvdhoorn  ( 2019-08-02 11:39:20 -0500 )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 image marcoarruda  ( 2019-08-02 12:45:33 -0500 )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 image gvdhoorn  ( 2019-08-02 12:51:26 -0500 )edit

Question Tools

2 followers

Stats

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

Seen: 1,349 times

Last updated: Aug 02 '19