siemens / ros-sharp

ROS# is a set of open source software libraries and tools in C# for communicating with ROS from .NET applications, in particular Unity3D
Apache License 2.0
945 stars 364 forks source link

Not able to call service from Unity #416

Closed gianmarco96 closed 5 months ago

gianmarco96 commented 2 years ago

I have a question!

Here is my question:

Hello, thank you for the fantastic work you did with library!

I'm really struggling to call services from Unity. I have checked the wiki and the examples, but they do not seem to work for me. I'm sure I'm being thick and don't think it's necessarily a ROS# issue. I don't really understand the example of call service shown below:

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

Or better I tried doing the same exact thing to no result. The server is running on the ROS side and when I call it from unity nothing seems to happen. I have created the ServiceCallHandler and generated the service request and response as per instruction. I could provide the example of my application, but I thought that would be very specific to my use case, while instead a more generic example could be useful to everyone.

Let's say I wanted to call the /spawn service from turtlesim node, which everyone has access to, from Unity using this library. What would I need to do? Possibly step by step?

I have used this library for over a year now, but never managed to use a service properly (I always had to find a work around using topics), I reckon I'm not the only one so I'm sure a more generic guide would be useful to others as well.

Thank you so much for your help,

gianmarco96 commented 2 years ago

So ok I sorted it by using RosSocket rosSocket = new RosSocket(new RosBridgeClient.Protocols.WebSocketSharpProtocol(uri)); rather than WebSocketNetProtocol, is there a reason why the latter would not work?

MartinBischoff commented 5 months ago

outdated / closing due to inactivity