Problems setting a ROS Service

Hello everyone,

I'm trying to implement a service in Unity but I found some problems (some already solved). First of all I started this project some months ago so I'm still using version 0.4.0 of ROS TCP Connector and URDF Importer.

First bug I found was while Generating ROS Service messages. I have my messages and services in a package called haru-unity. Normal messages are inside a folder /msg and services in a folder /srv. When I build msg the button changes to 'Rebuild msg' and the generated C# classes appear in a folder of name HaruUnity and they use namespace RosMessageTypes.HaruUnity . I have no problems with these generated classes. But when I try to build a service, first when clicking 'Build srv' button it never changes to 'Rebuild srv'. But it generates C# classes in a folder Haru-unity, and they use:
namespace RosMessageTypes.Haru-unity With this I get a bunch of errors in the console when compiling including error CS0116: A namespace cannot directly contain members such as fields or methods So I have to change those classes by hand for removing the hyphen. Is this bug due to version 0.4.0 of the packages?

Second problem I found (already solved) was following the tutorial https://github.com/Unity-Technologies/Unity-Robotics-Hub/blob/main/tutorials/ros_unity_integration/service_call.md as in my version of ROS TCP Connector, ImplementService<> takes just one argument. I found it changes with a new release of the version 0.6.0 a week ago. So this one is solved but was a bit confusing while following the tutorial.

The last problem I had (also solved) was while declaring the service in my custom server endpoint. I was using something like this:

topicsDict = {}


# Subscriber example
topicsDict['ball_color'] = RosSubscriber('ball/color', UnityColor, tcp_server)


# Publisher example
topicsDict['ball_pose'] = RosPublisher('ball/pose', Pose, queue_size=1)


# Service example
topicsDict['video_srv'] = RosService('play_video_service', PlayVideoService)

#Start TCP using topics from dictionary
tcp_server.start(
    topicsDict
)

Finally i found I have to use the following instead:

topicsDict['video_srv'] = UnityService('play_video_service', PlayVideoService, tcp_server)

When I started following these Unity Robotics tutorials many months ago I saw that it was necessary to declare your publishers/subscribers/services and its topics in a dictionary that tcp_server.start() takes. But I don't see any of this in the current tutorials https://github.com/Unity-Technologies/Unity-Robotics-Hub/tree/main/tutorials/ros_unity_integration . I don't see any mention in current tutorials on how to include your publishers/subscribers/services in a custom server endpoint. Is it not necessary anymore? Where can I find an example of how to create a custom server endpoint?

My last question, should I update ROS TCP Connector and URDF Importer? I see these have changed but I'm worried about the integrity of my project. I'm new working with Unity and would like to know how is the better way of updating these packages in my project.

Thank you.

Hi Domi.

Thanks for the message generation bug report. As far as I know this has not been reported before; I've filed it in our bug tracking system.

As of the latest version, the intent is that you no longer write a custom server endpoint - everyone just runs the same default_server_endpoint.py. Publishers, subscribers and services are just registered in Unity, and the endpoint gets notified about them.

However, one advantage of our tutorials being in GitHub is that you can view older versions. I believe this is the equivalent of the ROS service call tutorial for version 0.4.0. Hope that's useful.
https://github.com/Unity-Technologies/Unity-Robotics-Hub/blob/28a6bc409ab3d1944a58510c98b1c29b3909b137/tutorials/ros_unity_integration/service.md

I'm a little confused by your code involving the video_srv service. The UnityService class represents a service implemented in Unity, that other ROS nodes can call into. The RosService class represents a service implemented as a ROS node outside Unity, that Unity can call out to. Which of these are you trying to do?

Finally, yes, in a vacuum we would definitely recommend updating to the latest ROS TCP Connector. Version 0.5.0 in particular was a big leap forward in performance and stability. But you're right, there have been many changes since 0.4.0. Migrating your project to the new version may be a lot of work - sorry about that. The package is not yet a year old and it is still quite experimental. The API does seem to be stabilizing though.
Maybe give it a try and see how it goes?

1 Like

Hello Laurie,

Thank you for you answers. I was trying to use a service implemented in Unity. The thing is when I started there was only a tutorial about a service called out from unity, that used RosService class, and I didn't know how to declare a Unity Service in my custom server endpoint. That's what I was trying to point out in my question. I don't see any tutorial on how to use the classes from ros-tcp-endpoint for declaring publishers, subscribers and both type of services in a custom server endpoint. I think even old tutorial versions don't say anything about UnityService class.

Now, thanks to your answer I understand that with new packages it's not necessary anymore to create a custom server endpoint. But I don't see in what released version it stopped being necessary https://github.com/Unity-Technologies/ROS-TCP-Connector/releases .

I understand these packages are still quite experimental, I will try to update them. Should I just remove them from my Package Manager and then install them again? Can I update them directly from Package Manager? I see that option with other Unity packages (such as Visual Studio Code Editor) but seems they don't search for newer versions automatically.

Thank you.

Hi, I understand now. I think in version 0.4.0 the Unity Service feature had just been added, and if I remember right some of the other docs hadn't yet been updated to link to the tutorial, so it was not easy to find. But it did exist.
https://github.com/Unity-Technologies/Unity-Robotics-Hub/blob/28a6bc409ab3d1944a58510c98b1c29b3909b137/tutorials/ros_unity_integration/unity_service.md

In the latest version the Unity Service tutorial is listed along with the other tutorials, and the Ros Service tutorial is called "service call" to make the distinction clearer.
https://github.com/Unity-Technologies/Unity-Robotics-Hub/blob/main/tutorials/ros_unity_integration/README.md

We've been taking small steps towards making custom endpoints unnecessary for a while now, but 0.6.0 is the first version where we've recommended that as the default workflow.

And yes, you can update the package directly from the package manager. You don't even need to remove the old version - just open package manager, select the ROS TCP Connector package, and it will show the string that was used to download it. Copy that text, click the plus button to add a new Git URL, paste, change the version number to #v0.6.0, then click Add.

Or just paste this:

https://github.com/Unity-Technologies/ROS-TCP-Connector.git?path=/com.unity.robotics.ros-tcp-connector#v0.6.0

FYI, using hyphens in a ROS package name is forbidden by their standard naming conventions:
https://www.ros.org/reps/rep-0144.html

Thank you Laurie. In my project we actually use underscores for package project name, declared in the CMakeList. For example in my example it is haru_unity. But we use dashes for package folder names, so it is haru-unity. That convention was already used before I arrived to the project 4 years ago and I was told to follow it. And we generate deb files using dashes too. But I think you follow this same convention in package ROS-TCP-Endpoint https://github.com/Unity-Technologies/ROS-TCP-Endpoint , right? You use dashes for the folder and underscore for the project name

I have updated the packages to their last versions and after changing messages names and some namespaces, all things seem to work well with the default server endpoint. Thank you for your help.

I have a last question somehow related to services. Are you planning to add ROS actions too?

Great, and there was indeed a bug in how our service message generation code was picking a namespace, so thanks for pointing that out.

Implementing proper support for ROS actions is in our backlog, but as I understand it they're not very widely used, so it's not been a priority for us so far. (Your request has been noted.)