JeanElsner / panda-py

Python bindings for real-time control of Franka Emika robots.
https://jeanelsner.github.io/panda-py/
Apache License 2.0
77 stars 14 forks source link

UDP receive: Timeout #28

Open TommyPack opened 5 months ago

TommyPack commented 5 months ago

First of all thanks for the fast reply regarding the installation. I went ahead and installed virtualbox and Ubuntu and the installation and everything else worked but...

I made a new python file in PyCharm and copied the first couple of lines from your jupyter tutorial notebook. The connection to the desk works as you can see from the INFO:.... output. the unlock also works the the Panda robot unlocks all axes and moves them a tiny but as it is supposed to happen and as if I would press the unlock button in the Desk, but then when I want to connect to the Robot and the Hand I ran into the following error:

INFO:desk:Login succesful.
INFO:desk:Legacy desk detected.
Traceback (most recent call last):
  File "/home/vboxuser/PycharmProjects/Panda_Test/Connect2Desk_Unlock.py", line 20, in <module>
    panda = panda_py.Panda(hostname)
RuntimeError: libfranka: UDP receive: Timeout

Process finished with exit code 1

I searched for this error but there are only 2 options i found.

  1. I don't have the FCI, but I check in the Desk -> Settings -> System and I have it installed (But I don't have a "Activate FCI Mode" button - maybe thats the reason?)
  2. Some issue with iptables but I had nothing in those so i put the IP in INPUT, OUTPUT and FORWARD but with no success..

Do you think the reason is that the robot is on a too old version (4.0.2) and that this is the reason that I cannot connect? Pinging it works but your communication_test.py always ends at the if len(sys.argv) < 2: raise RuntimeError(f'Usage: python {sys.argv[0]} 172.16.0.2')

I have also added a static IP and connected to the control unit instead of the Arms base, as it is recommended in the documentation of the Panda..

JeanElsner commented 5 months ago

I don't think this issue is related to panda-py, your version is supported (requires the installation of the libfranka 0.8.0 variant). My best guess is, that you need to open the UDP ports for your virtualbox. However, I've never used virtualbox before, in Docker you'd be using the host network mode. The ports are negotiated by libfranka (Poco?) as far as I remember, so they are not fixed. It would be easiest to therefore open all the UDP ports. A quick google search reveals that there is some kind of "bridged mode" for virtualbox that sounds like it would do the right thing.

Btw., how did you call the communication test? The proper use is python communication_test.py <robot_ip> where is the host IP of your robot, as indicated in the error message.

TommyPack commented 5 months ago

Thank you, I will try and find this bridged mode, currently there are only guides to forward certain ports. Yesterday at some point not even the login and unlock of the breaks worked, today when I powered on the robot it worked again but only one time... (Edit now it seems to work almost everytime but sometimes error message below appears) Now I have the following error message:

/home/vboxuser/PycharmProjects/Panda_Test/.venv/bin/python /home/vboxuser/PycharmProjects/Panda_Test/Connect2Desk_Unlock.py 
Traceback (most recent call last):
  File "/home/vboxuser/PycharmProjects/Panda_Test/.venv/lib/python3.10/site-packages/urllib3/connection.py", line 198, in _new_conn
    sock = connection.create_connection(
  File "/home/vboxuser/PycharmProjects/Panda_Test/.venv/lib/python3.10/site-packages/urllib3/util/connection.py", line 85, in create_connection
    raise err
  File "/home/vboxuser/PycharmProjects/Panda_Test/.venv/lib/python3.10/site-packages/urllib3/util/connection.py", line 73, in create_connection
    sock.connect(sa)
OSError: [Errno 113] No route to host

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/home/vboxuser/PycharmProjects/Panda_Test/.venv/lib/python3.10/site-packages/urllib3/connectionpool.py", line 793, in urlopen
    response = self._make_request(
  File "/home/vboxuser/PycharmProjects/Panda_Test/.venv/lib/python3.10/site-packages/urllib3/connectionpool.py", line 491, in _make_request
    raise new_e
  File "/home/vboxuser/PycharmProjects/Panda_Test/.venv/lib/python3.10/site-packages/urllib3/connectionpool.py", line 467, in _make_request
    self._validate_conn(conn)
  File "/home/vboxuser/PycharmProjects/Panda_Test/.venv/lib/python3.10/site-packages/urllib3/connectionpool.py", line 1099, in _validate_conn
    conn.connect()
  File "/home/vboxuser/PycharmProjects/Panda_Test/.venv/lib/python3.10/site-packages/urllib3/connection.py", line 616, in connect
    self.sock = sock = self._new_conn()
  File "/home/vboxuser/PycharmProjects/Panda_Test/.venv/lib/python3.10/site-packages/urllib3/connection.py", line 213, in _new_conn
    raise NewConnectionError(
urllib3.exceptions.NewConnectionError: <urllib3.connection.HTTPSConnection object at 0x78a8f748a500>: Failed to establish a new connection: [Errno 113] No route to host

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/home/vboxuser/PycharmProjects/Panda_Test/.venv/lib/python3.10/site-packages/requests/adapters.py", line 486, in send
    resp = conn.urlopen(
  File "/home/vboxuser/PycharmProjects/Panda_Test/.venv/lib/python3.10/site-packages/urllib3/connectionpool.py", line 847, in urlopen
    retries = retries.increment(
  File "/home/vboxuser/PycharmProjects/Panda_Test/.venv/lib/python3.10/site-packages/urllib3/util/retry.py", line 515, in increment
    raise MaxRetryError(_pool, url, reason) from reason  # type: ignore[arg-type]
urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='172.16.0.2', port=443): Max retries exceeded with url: /admin/api/login (Caused by NewConnectionError('<urllib3.connection.HTTPSConnection object at 0x78a8f748a500>: Failed to establish a new connection: [Errno 113] No route to host'))

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/vboxuser/PycharmProjects/Panda_Test/Connect2Desk_Unlock.py", line 13, in <module>
    desk = panda_py.Desk(hostname , username , password)
  File "/home/vboxuser/PycharmProjects/Panda_Test/.venv/lib/python3.10/site-packages/panda_py/__init__.py", line 94, in __init__
    self.login()
  File "/home/vboxuser/PycharmProjects/Panda_Test/.venv/lib/python3.10/site-packages/panda_py/__init__.py", line 281, in login
    login = self._request(
  File "/home/vboxuser/PycharmProjects/Panda_Test/.venv/lib/python3.10/site-packages/panda_py/__init__.py", line 328, in _request
    response: requests.Response = fun(parse.urljoin(f'https://{self._hostname}',
  File "/home/vboxuser/PycharmProjects/Panda_Test/.venv/lib/python3.10/site-packages/requests/sessions.py", line 637, in post
    return self.request("POST", url, data=data, json=json, **kwargs)
  File "/home/vboxuser/PycharmProjects/Panda_Test/.venv/lib/python3.10/site-packages/requests/sessions.py", line 589, in request
    resp = self.send(prep, **send_kwargs)
  File "/home/vboxuser/PycharmProjects/Panda_Test/.venv/lib/python3.10/site-packages/requests/sessions.py", line 703, in send
    r = adapter.send(request, **kwargs)
  File "/home/vboxuser/PycharmProjects/Panda_Test/.venv/lib/python3.10/site-packages/requests/adapters.py", line 519, in send
    raise ConnectionError(e, request=request)
requests.exceptions.ConnectionError: HTTPSConnectionPool(host='172.16.0.2', port=443): Max retries exceeded with url: /admin/api/login (Caused by NewConnectionError('<urllib3.connection.HTTPSConnection object at 0x78a8f748a500>: Failed to establish a new connection: [Errno 113] No route to host'))

Process finished with exit code 1

Do i need to establish a port forwarding using this guide? https://www.activecountermeasures.com/port-forwarding-with-virtualbox/

Also for the communication_test.py I used the command you mentioned and it works until i get the UDP Timeout message so I gotta work on that. The Bridged adapter in the network settings of the VM does not seem to do the trick unfortunately.