ami-iit / yarp-openmct

Repo for YARP and OpenMCT integration.
BSD 3-Clause "New" or "Revised" License
6 stars 1 forks source link

5: Add the capability to refresh the Yarp port connections (e.g. in the control console) #68

Closed nunoguedelha closed 2 years ago

nunoguedelha commented 2 years ago

It is needed to have a refresh mechanism of the connections with the Yarp port without having to restart the telemetry server.

Implemented in #80 .

traversaro commented 2 years ago

Not sure that we need to use it, but we may be interested in http://www.yarp.it/latest/persistent_connections.html .

nunoguedelha commented 2 years ago

we shall try using the approaches suggested by @traversaro (http://www.yarp.it/latest/persistent_connections.html), creating persistent connections programmatically:

The code snippets above are in C++. We don't know if the style option is supported by the yarp::os::Network class bindings, nor if the bindings to the class yarp::os::ContactStyle exist at all...

nunoguedelha commented 2 years ago

Preliminary checks

Other tests and obsevations:

Conclusion

Having this in mind and the fact that Bindings to the class yarp::os::ContactStyle are not implemented, it seems easier to use topics for creating persistent connections, although the approach using the style option would be simpler if yarp::os::ContactStyle was available.

The drawback is that we won't be able to cleanup the topics once we don't need them anymore (unless we run a child process just for that of course, which we should avoid).

It might be worth trying to create the bindings for the class yarp::os::ContactStyle. If it's not straightforward enough, we'll go for the topics solutions.

nunoguedelha commented 2 years ago

It might be worth trying to create the bindings for the class yarp::os::ContactStyle. If it's not straightforward enough, we'll go for the topics solutions.

This is probably a bit tricky... although it's worth trying, I'll do it for the next iteration. For a faster closure of the iteration getting the application ready for use by anyone in the team, I'll go with the topic approach (a few lines change in yarp-openmct.

nunoguedelha commented 2 years ago

This is probably a bit tricky... although it's worth trying, I'll do it for the next iteration. For a faster closure of the iteration getting the application ready for use by anyone in the team, I'll go with the topic approach (a few lines change in yarp-openmct.

Opened https://github.com/robotology/yarp.js/issues/26 for "persistence" option and related bindings implementation.

Opened https://github.com/ami-iit/yarp-openmct/issues/79 for using the option in the telemetry server.

nunoguedelha commented 2 years ago

Persistent connection using topics

The disconnection fails for some ports, as well as the subsequent port closure (telemetry server ports). The failure occurs in the yarp.js module and is reproducible with a minimal Node.js script using yarp.js functions. As a result, the telemetry server process closure hangs, and the process has to be killed manually.

This seems to be the same issue as #59 . In order to break down the steps leading to the failure, we proceed as follows:

Note

Unlike the case of a connection between two real Yarp ports, the connection/disconnection to or from a virtual topic is executed asynchronously on Javascript. Inhibiting the exit event trigger in yarp.js and applying the other steps mentioned above should let the disconnection to be completed without any closure attempt to interfere.

Result

None of the port connections is closed, which is unexpected at first. Actually, the same behavior is observed when running the commands on the terminal. yarp disconnect --persist /write /read removes the persistence, but not the connection itself as it keeps active until we explicitly stop it with yarp disconnect /write /read. Note that running only yarp disconnect /write /read won't get rid of the persistence.

So when disconnecting a port, we need to do:

yarp.Network.disconnect('/write','topic://aTopic');
yarp.Network.disconnect('topic://aTopic','/read');
yarp.Network.disconnect('/write','/read');