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
177 stars 118 forks source link

ROS2 - Can't unsubscribe #166

Open mousdahl-unity opened 1 year ago

mousdahl-unity commented 1 year ago

Describe the bug The ROS TCP endpoint throws an exception and hitches significantly when unsubscribing from topics.

To Reproduce Steps to reproduce the behavior:

  1. Subscribe to a topic
  2. Unsubscribe
  3. Look at the TCP endpoint connector log
  4. See error

Console logs / stack traces

Exception in thread Thread-4:
Traceback (most recent call last):
  File "c:\python38\lib\threading.py", line 932, in _bootstrap_inner
    self.run()
  File "C:\source\sol-proj-universal-robopose\ROS2\install\ros_tcp_endpoint\Lib\site-packages\ros_tcp_endpoint\client.py", line 213, in run
    self.tcp_server.handle_syscommand(destination, data)
  File "C:\source\sol-proj-universal-robopose\ROS2\install\ros_tcp_endpoint\Lib\site-packages\ros_tcp_endpoint\server.py", line 121, in handle_syscommand
    function = getattr(self.syscommands, topic[2:])
AttributeError: 'SysCommands' object has no attribute 'remove_subscriber'

Expected behavior The topic should be unsubscribed with no crashing.

Environment:

abreu9999 commented 1 year ago

Same problem here. Add the following definition to class SysCommands in server.py:

def remove_subscriber(self, topic):
    if topic == "":
        self.tcp_server.send_unity_error(
            "Can't unsubscribe to a blank topic name! SysCommand.remove_subscriber({}, {})".format(
                topic
            )
        )
        return

    node = self.tcp_server.subscribers_table.get(topic)
    if node is not None:
        self.tcp_server.unregister_node(node)
        self.tcp_server.loginfo("UnregisterSubscriber({}) OK".format(topic))
    else:
        self.tcp_server.send_unity_error(
            "Can't unsubscribe node if not previously subscribed! SysCommand.remove_subscriber({})".format(
                topic
            )
        )