Unity-Technologies / ROS-TCP-Endpoint

ROS package used to create an endpoint to accept ROS messages sent from a Unity scene using the ROS TCP Connector scripts
Apache License 2.0
185 stars 124 forks source link

Add missing unsubscribe support #163

Open bpotokar opened 1 year ago

bpotokar commented 1 year ago

Currenlty unsubscribing from a topic is not possible. Unity side actually has unsubscribe method, but ROS side does not implement that functionality. As a result, calling unsubscribe causes the AttributeError: 'SysCommands' object has no attribute 'remove_subscriber' exception.

This PR adds the missing method remove_subscriber, which unregisters ROS subscriber so new messages are not sent to Unity anymore.

This bug is reported in this issue on Unity-Robotics-Hub repository.

Here is described the call stack, that causes the exception, in more detail:

If Unity script calls the Unsubscribe function, which calls UnsubscribeAll. This calls SendSubscriberUnregistration, which sends the remove_subscriber command. That results in the following error:

Exception in thread Thread-2:
Traceback (most recent call last):
  File "/usr/lib/python3.8/threading.py", line 932, in _bootstrap_inner
    self.run()
  File "ros_tcp_endpoint/client.py", line 225, in run
    self.tcp_server.handle_syscommand(destination, data)
  File "ros_tcp_endpoint/lib/python3.8/site-packages/ros_tcp_endpoint/server.py", line 114, in handle_syscommand
    function = getattr(self.syscommands, topic[2:])
AttributeError: 'SysCommands' object has no attribute 'remove_subscriber'
unity-cla-assistant commented 1 year ago

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.


Blaž Potokar seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please add the email address used for this commit to your account.
You have signed the CLA already but the status is still pending? Let us recheck it.