gramaziokohler / roslibpy

Python ROS Bridge library
MIT License
273 stars 56 forks source link

Add methods to edit the reconnection parameters #59

Closed jeandeaual closed 4 years ago

jeandeaual commented 4 years ago

Since version 1.0.0, reconnection to rosbridge is working very well. Thanks very much!

However there is no direct way to edit the initial and maximum delay (which can go up to 3600 seconds with Twisted) or the maximum number of retries (no limit by default with Twisted).

In this PR, I added several class methods to CliRosBridgeClientFactory and AutobahnRosBridgeClientFactory, which allows us to set the reconnection parameters before creating a Ros instance, as follows:

from roslibpy import Ros
from roslibpy.comm import RosBridgeClientFactory

RosBridgeClientFactory.set_initial_delay(5)
RosBridgeClientFactory.set_max_delay(60)
RosBridgeClientFactory.set_max_retries(10)

ros = Ros(host='127.0.0.1', port=9090)

Implementing it as class methods seemed to be the only way, seeing how Twisted's ReconnectingClientFactory defines maxDelay, initialDelay and maxRetries as class variables (https://github.com/twisted/twisted/blob/trunk/src/twisted/internet/protocol.py#L365).

Please let me know if there's a better way to implement these settings.