-
-
Notifications
You must be signed in to change notification settings - Fork 163
Webots Ros2 program (any of the demos) running in Ubuntu (Windows WSL2) is not able to connect to Webots host simulator in Windows 11. #1031
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
Comments
Hi, pardon. I meet the same problem.I have tried the "Execute_Process" to choose the right windows ip I needed for webots_controller connection and it worked, but the problem occured then. It throwed the exception like below: |
Hello, I was having the same problem. After hours of debugging, I think I have figured out the source of the issue. WSL is configured by default to use a NAT architecture for the communication between Windows and WSL. The official Microsoft Documentation on WSL Networking explains how the WSL system its own IP address under a sub-network has, and that windows can connect to any WSL program on localhost normally. But for a WSL program to connect to a Windows one it has to use the proper IP under the WSL sub-network. The window machine is configured as the gateway within this sub-network, we can lookup it's IP by running
It's the one in the first line: The The package has the logic of determining the IP in In the following 2 functions: webots_ros2/webots_ros2_driver/webots_ros2_driver/utils.py Lines 149 to 151 in 329486a
webots_ros2/webots_ros2_driver/webots_ros2_driver/utils.py Lines 154 to 158 in 329486a
get_host_ip() if has_shared_folder() else get_wsl_ip_address()
webots_ros2/webots_ros2_driver/webots_ros2_driver/utils.py Lines 110 to 111 in 329486a
This leaves us with webots_ros2/webots_ros2_driver/webots_ros2_driver/utils.py Lines 87 to 107 in 329486a
It uses the IP address specified in Upon checking the file I have found the following: # This file was automatically generated by WSL. To stop automatic generation of this file, add the following entry to /etc/wsl.conf:
# [network]
# generateResolvConf = false
nameserver 10.255.255.254
Why? WSL has a DNS server running with in itself? Well, it's a new feature called "DNS Tunneling", and as mentioned in microsoft/WSL#12101 (comment), WSL So, using the IP address in Actually the webots_ros2/webots_ros2_driver/webots_ros2_driver/utils.py Lines 129 to 141 in 329486a
A quick hackish solution to validate the hypothesis is to modify # This file was automatically generated by WSL. To stop automatic generation of this file, add the following entry to /etc/wsl.conf:
# [network]
# generateResolvConf = false
#nameserver 10.255.255.254
namespace 172.30.32.1 Launching the Once WSL is restarted the |
Disabling the "DNS Tunneling" feature and restarting WSL solves the issue. But we lose the feature. When it's active and NAT networking is used, This leaves the mirrored networking mode to solve. |
is there any simpler solutions? i have the exact same issue |
Describe the Bug
After installing Webots on a Windows 11 host configured with a Ubuntu 22.04 on WSL2, any of the demo programs fail in trying to connect to the Windows Webot simulator.
Steps to Reproduce
Expected behavior
The expectation is that the code will start to run and pop open the Webots simulator window on the Windows host. It will them start to send commands to the robot running in the simulation to perform the demo actions.
Instead, the program starts up, but is unable to connect to the host. The screen continuously displays an error that it cannot connect and will try in a few seconds. It never is able to connect.
Affected Packages
List of affected packages:
All of the demo programs, such as epuck, universal_robot, etc.
Screenshots
Not available
System
Additional context
I spent over a full day trying to figure this out and found a solution.
In my case, the issue was that the program located in "webots_ros2_driver/lib/python3.12/site-packages/webots-driver/utils.py" has a function named "get_wsl_ip_address()" . This function gets the "nameserver" ip address from the WSL2 "/etc/resolv.conf" file and returns it incorrectly as the ip address of the Windows host. Because of this, the Ubuntu webots controller keeps trying to connect to the webots simulator running on the Windows side using the nameserver ip address as the TCP IP address. I my system, the nameserver was set to 127.0.0.53. The "webots-controller" kept trying to connect to TCP 127.0.0.53 port 1234.
To prove that this was the problem, I manually edited the "/etc/resolv.conf" file and changed the nameserver address to "127.0.0.1".
This worked: I was then able to run "ros2 launch webots_ros2_epuck robot_launch.py"" and it connected up to the webot simulator using TCP 127.0.0.1 Port 1234. Of course this only works while the terminal is open. Once I close the terminal and open it again, the /etc/resolv changes and it starts to fail again.
Changing the nameserver address is not the correct way to fix the problem, but it got me to a working demo and can move on.
I consider the code in utils.py to be an error as the nameserver ip address is not the correct value to use to connect to the Windows host webot simulator.
The text was updated successfully, but these errors were encountered: