Search Unity

  1. Unity Asset Manager is now available in public beta. Try it out now and join the conversation here in the forums.
    Dismiss Notice
  2. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  3. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Question [ROS TCP Connector] How to disconnect ROS properly

Discussion in 'Robotics' started by KevinYukiNTU, Nov 3, 2022.

  1. KevinYukiNTU

    KevinYukiNTU

    Joined:
    May 19, 2022
    Posts:
    5
    Hello there!

    I`m trying to disconnect from ROS and then reconnect. I`m using de Disconnect() function, but when I create a new RosConnection instance, the HUD shows two connections and log the following message:

    Code (CSharp):
    1. ROSConnection.GetOrCreateInstance().Disconnect();
    image_2022-11-03_170926462.png

    image_2022-11-03_170946720.png

    What else do I have to do to disconnect from ROS properly?
     
  2. LaurieUnity

    LaurieUnity

    Unity Technologies

    Joined:
    Oct 23, 2020
    Posts:
    77
    You shouldn't create a new RosConnection instance, just call Connect (or press the Connect button in the hud) when you want to connect again.
     
  3. KevinYukiNTU

    KevinYukiNTU

    Joined:
    May 19, 2022
    Posts:
    5
    But I`m unloading the scene that contains the RosConnection instace, so it should be destroyed right?

    Also when I call the GetOrCreateInstance method, if a RosConnection instance exists, it should be return and not create a new one, shouldn`t it?
     
    Last edited: Nov 4, 2022
  4. LaurieUnity

    LaurieUnity

    Unity Technologies

    Joined:
    Oct 23, 2020
    Posts:
    77
    Hmm. Ideally yes, that should work, but if it's causing problems I suggest you set DontDestroyOnLoad on your RosConnection and just keep the same connection from scene to scene.
     
    KevinYukiNTU likes this.
  5. KevinYukiNTU

    KevinYukiNTU

    Joined:
    May 19, 2022
    Posts:
    5
    Ok, gonna try this. Thank you!