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

ROS msgs not received in a topic if publisher starts after subscriber

Discussion in 'Robotics' started by felipebelocreatecrobotics, Jan 4, 2022.

  1. felipebelocreatecrobotics

    felipebelocreatecrobotics

    Joined:
    Apr 29, 2021
    Posts:
    1
    If I subscribe to a topic before a publisher was registered at that topic, no ROS msgs are received by the subscriber callback once the publisher is registered.

    For the sake of simplicity let's call A the machine that is publishing and B the machine that is subscribing to the topic.

    If I run 'rostopic echo NAME_OF_TOPIC', I can see that the messages are indeed being published by A. However, the 'subscriber' in B does not seem to be able to receive them if B is run after A.

    I came up with a couple of "hacks" to handle the issue. If I set a timeout in B when listening for msgs on a subscriber and either: disconnect/reconnect to RosConnection; or, unsubscribe/resubscribe to the topic; then, the topic is properly subscribed (in B) and receives messages (from A).

    However, I've verified that these solutions have the side-effect that publishers in B lose "connection" to their related subscribers in other machines (e.g., in A). I also verified that to unsubscribe/resubscribe to the topic takes a long time (in the order of seconds), which means that messages get lost during that time, and B may not receive a message from A within time, failing the timeout check again.

    For completeness, I'm using the following to register a publisher:
    Code (CSharp):
    1. ros = ROSConnection.GetOrCreateInstance(); ros.RegisterPublisher<SOME_ROS_MSG>(topicName);
    2.  
    And the following to subscribe to the publisher:

    Code (CSharp):
    1. ros = ROSConnection.GetOrCreateInstance();
    2. ros.Subscribe<SOME_ROS_MSG>topicName, CallbackFunction);
    3.  
    I'm following the tutorial presented in the Unity Robotics Hub: https://github.com/Unity-Technologies/Unity-Robotics-Hub/tree/main/tutorials/ros_unity_integration.
     
  2. amanda-unity

    amanda-unity

    Unity Technologies

    Joined:
    May 29, 2020
    Posts:
    19
    Thanks for the report! I'm responding on your Github issue in order to consolidate discussion on this topic.