Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reconnection after closing leads to --> RosTimeoutError("Failed to connect to ROS") #121

Open
CristianGariboldi opened this issue Jan 15, 2024 · 0 comments

Comments

@CristianGariboldi
Copy link

Description
I am using roslibpy to connect a python simulator with ros2 environment. In the simulator there are different scenarios with the duration of 15 seconds each, with a frequency of 10 Hz. So, when you iterate over the scenarios for visualization purposes, you can understand at which point of the simulation of a scenario you are by reading the variable self._iteration.
When self._iteration == 0, I start the connection with roslibpy. When self._iteration == 148 I close the connection and I set the ros related function to None, otherwise I get some problems with the simulator.
Now, since the next scenario is going to begin, self._iteration is set again to zero and according to my script, I should start a new connection with roslibpy, but instead I get the error:

raise RosTimeoutError("Failed to connect to ROS")
roslibpy.core.RosTimeoutError: Failed to connect to ROS

To Reproduce
I cannot provide the entire code of the simulation, but the connection and disconnection script is the following:

def __init__():
    self.client_traj = None

def connection():

    if self._iteration < 148:
          if (self.client_traj is None or not self.client_traj.is_connected):
              time.sleep(1)
              self.client_traj = Ros(host='localhost', port=9090)
              self.client_traj.connect()
              self.client_traj.run()
              
    elif self._iteration >= 148:
                self.client_traj.close()
                self.client_traj = None
                time.sleep(1)

Expected behavior
It should be able to connect. Indeed, when I run the simulator, in the first scenario it can connect without any problems, but for the second scenario, it fails.

System (please complete the following information):

  • OS: Linux
  • Python version 3.9
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant