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

Resolved Multiple ROS-TCP-Connectors in a single simulation

Discussion in 'Robotics' started by antsa123, Jan 31, 2022.

  1. antsa123

    antsa123

    Joined:
    May 10, 2021
    Posts:
    4
    Hi! I'd like to create a simulation where I have one to N AGVs publishing messages on different DDS domains. Is this possible using the ROS-TCP-Connectors. I'm having trouble creating multiple connectors as the connector is a static instance.

    I have no trouble with only one AGV publishing the messages.

    Current setup:

    I have AGV control software running on two different VMs both of these VMs are also running the ROS-TCP-Endpoint. The endpoints and the AGV control software on the two VMs are running on different DDS domains so that they don't interfere with each other.

    Now I'd like to simulate the two AGVs in Unity but it seems like it's not possible with the ROS-TCP-Connector
     
  2. LaurieUnity

    LaurieUnity

    Unity Technologies

    Joined:
    Oct 23, 2020
    Posts:
    77
    Hi, although we make it easy to create a RosConnection as a static instance, you can also just place them in your scene and make other objects refer to them, like any other Unity component. By setting it up this way you can have multiple RosConnections, each with their own IP and/or port.
     
  3. antsa123

    antsa123

    Joined:
    May 10, 2021
    Posts:
    4
    Thanks for your response! I'll try what you suggested again.

    I'm still a bit confused how would that work since the awake in ROSConnection.cs will always initialize all scripts to point into the static instance that is created first. Also the TFSystem and many other scripts always refer to the GetOrCreateInstance method that points to the static instance. Below a screenshot from the source code in GitHub.

    upload_2022-2-2_10-20-18.png
     
  4. LaurieUnity

    LaurieUnity

    Unity Technologies

    Joined:
    Oct 23, 2020
    Posts:
    77
    Hi - yes, _instance will point to whichever ROSConnection awakes first, but you can manually refer to the other one - e.g. you can make a MonoBehaviour with fields "public ROSConnection rosA" and "public ROSConnection rosB", so that the properties are visible in the Unity inspector, and drag your two connections into those slots.

    Your point about TFSystem is valid, that's not ideal... I will take a look at it.
     
    ActiveSim likes this.
  5. antsa123

    antsa123

    Joined:
    May 10, 2021
    Posts:
    4
    Thanks again! I got this working okay now as long as I don't tick the listen to TF messages checkbox. Also the HUD shows meaningful information only for a single connection but that's okay I think.
     
  6. FGJoseMiguel1

    FGJoseMiguel1

    Joined:
    Aug 23, 2023
    Posts:
    1
    Hi!, I'm trying to do the same, do you think you can share how you do that?. I don't have a lot of experience with this, so you would help me a lot.
     
  7. weiyuan1996

    weiyuan1996

    Joined:
    Aug 3, 2022
    Posts:
    2
    I tried making two objectives with different IP addresses attached to the rosconnector. My other two different scripts have public ROSConnection rosA and public ROSConnection rosB separately. I dragged two connections into those slots. In the script, I start the link with m_Ros = ROSConnection.GetOrCreateInstance(). It didn't work, both objects published topics on the same IP. I want them to publish on separate IP addresses (ros2 in different domain IDs).

    I'm not sure if I do it correctly. Could you provide how to fix it in detail? I appreciate it.