Closed felipebelocreatecrobotics closed 2 years ago
Hi, thanks for the thorough report! I've created a ticket for internal tracking.
I investigated this scenario on my end, and I haven't yet been able to reproduce the issue. I have set up a simple project with publisher and subscriber MonoBehaviours, UI buttons to register each, alongside a button for publishing a simple counter.
0:00-0:26: This should be the "A first, B second" scenario--the publisher is registered, then the subscriber, then publishing begins. Note the Console window in Unity printing the registrations, publishing and receives.
0:35-1:03: This should be the "B first, A second" scenario--the subscriber is registered, then the publisher, then publishing begins.
The rest of the video just ensures that a message can't be published before the publisher is registered, to round out all three buttons trying to be run first. I've attached the simple project here--can you go ahead and test this on your end to see if the problem persists?
[Ticket#: AIRO-1655]
If I understood correctly, you have prepared it all in one application (one scene) only, that even shares the ROS Connection. I have also started by doing the same, and in that case the order in which publishers and subscribers are registered do not matter. The issue is when there are multiple ROS nodes running, which is the typical ROS use case. If you have 2 or more applications running then one can only subscribe to already published topics. The "minimum" way of reproducing the error is to create two separate applications. One with a publisher (that can be triggered by a button for example) and one with a subscriber. If you run the subscriber application first and the publisher application after, then the subscriber application will not receive the ROS message. You should be able to reproduce this scenario quickly using the code I provided. Otherwise I can prepare 2 projects, a publisher and a subscriber, and send here.
AT669, To prove the point that the issue can be reproduced with 2 ROS nodes, I've built your application and ran both the built application and another one in the Unity editor. If you do so, you are able to reproduce the issue. Try using the built application as a publisher and the editor application as a subscriber. If publisher/subscriber are not registered on the right order, you will see that the subscriber does not receive the expected messages and does not 'log' them.
Thanks for the clarification!
Using multiple Unity instances is a currently unsupported use case. https://github.com/Unity-Technologies/Unity-Robotics-Hub/issues/214 is a similar situation which you may want to check out, which was resolved by running multiple server endpoints.
Main bug description 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.
To Reproduce Steps to reproduce the behavior:
public class SimpleSender : MonoBehaviour { ROSConnection ros;
}
using System.Collections; using System.Collections.Generic; using RosMessageTypes.Std; using Unity.Robotics.ROSTCPConnector; using UnityEngine; using UnityEngine.Events;
[System.Serializable] public class SimpleReceiverEvent : UnityEvent
{
}
public class SimpleReceiver : MonoBehaviour { ROSConnection ros; public StringReceiverEvent OnChange;
}