I apparently managed to fix or "to clear" an error: "Could not contact ROS master at [http://localhost:11311], retrying..." which appeared in an X-Window message box after calling rviz.
I found that ROS_IP and ROS_MASTER_URI env.vars have to be filled in.
It appears as the error message is cleared, it doesn't pop up immediately, either if I use the WSL2 IP 172.23.224.1
or the physical machine's IP.
export ROS_IP=http://172.23.224.1
export ROS_MASTER_URI=http://172.23.224.1:11311
However the rviz window doesn't appear either:
QStandardPaths: XDG_RUNTIME_DIR not set, defaulting to '/tmp/runtime-tosh'
[ INFO] [1687111248.718796000]: rviz version 1.13.7
[ INFO] [1687111248.718875500]: compiled against Qt version 5.12.5
[ INFO] [1687111248.718932200]: compiled against OGRE version 1.9.0 (Ghadamon)
And after waiting for some time, the same error appears again with the new address:
The VcXsrvr X-server on Windows is working as it shows the error message and I use gedit, xcalc opens etc. Also if I run rviz when XLaunch is not running, the log doesn't appear either, it hangs at the prompt, so it seems it interacts with the X-server.
If ROS_MASTER_URI is set to localhost:11311 as in the message, the error reappears immediately.
I've also created .wslconfig file in Windows user directory, the outcome is the same with either:
localhostforwarding=true networkingMode=bridged vmSwitch=wsl-switch
And if it's commented: (following suggestions from other threads)
#localhostforwarding=true
#networkingMode=bridged
#vmSwitch=wsl-switch
I'm running a sample demo in another terminal:
ros2 launch dummy_robot_bringup dummy_robot_bringup.launch.py [INFO] [launch]: All log files can be found below /home/tosh/.ros/log/2023-06-18-21-22-40-977995-DESKTOP-LQSDBBS-182 [INFO] [launch]: Default logging verbosity is set to INFO [INFO] [dummy_map_server-1]: process started with pid [184] [INFO] [robot_state_publisher-2]: process started with pid [186] [INFO] [dummy_joint_states-3]: process started with pid [188] [INFO] [dummy_laser-4]: process started with pid [190] [dummy_laser-4] [INFO] [1687112562.084600500] [dummy_laser]: angle inc: 0.004363 [dummy_laser-4] [INFO] [1687112562.084768500] [dummy_laser]: scan size: 1081 [dummy_laser-4] [INFO] [1687112562.084789000] [dummy_laser]: scan time increment: 0.000028 [robot_state_publisher-2] [INFO] [1687112562.286330000] [robot_state_publisher]: got segment single_rrbot_camera_link [robot_state_publisher-2] [INFO] [1687112562.286538800] [robot_state_publisher]: got segment single_rrbot_hokuyo_link [robot_state_publisher-2] [INFO] [1687112562.286560100] [robot_state_publisher]: got segment single_rrbot_link1 [robot_state_publisher-2] [INFO] [1687112562.286569300] [robot_state_publisher]: got segment single_rrbot_link2 [robot_state_publisher-2] [INFO] [1687112562.286577000] [robot_state_publisher]: got segment single_rrbot_link3 [robot_state_publisher-2] [INFO] [1687112562.286584200] [robot_state_publisher]: got segment world
I guess rviz should display windows even without a running service either.
I also created a rule for WSL in the firewall, it doesn't help for now, and the ping passes even if the rule is off.
UPDATE:
It seems the ping from WSL to 192.168.0.101 - the host takes - a lot of time, but it's accessible.
PING 192.168.0.101 (192.168.0.101) 56(84) bytes of data.
64 bytes from 192.168.0.101: icmp_seq=1 ttl=63 time=139 ms
64 bytes from 192.168.0.101: icmp_seq=2 ttl=63 time=92.4 ms
64 bytes from 192.168.0.101: icmp_seq=3 ttl=63 time=74.8 ms
64 bytes from 192.168.0.101: icmp_seq=4 ttl=63 time=97.3 ms
Also the ping-loop to itself works, as well as ping from the host to WSL.
ping 172.23.231.154
PING 172.23.231.154 (172.23.231.154) 56(84) bytes of data.
64 bytes from 172.23.231.154: icmp_seq=1 ttl=64 time=0.021 ms
64 bytes from 172.23.231.154: icmp_seq=2 ttl=64 time=0.057 ms
ping to the WSL inet ip responds:
I was wondering if the problem is with qt5, but the log message of the beginning of rviz says "Compiled with qt..." so I guess it's fine:
tosh@DESKTOP-LQSDBBS:~/ros2-src$ rviz
QStandardPaths: XDG_RUNTIME_DIR not set, defaulting to '/tmp/runtime-tosh'
[ INFO] [1687185352.025460300]: rviz version 1.13.7
[ INFO] [1687185352.025553300]: compiled against Qt version 5.12.5
[ INFO] [1687185352.025609800]: compiled against OGRE version 1.9.0 (Ghadamon)
Also I manage to run simple Qt applications in Python and their windows appear and work.
Another test for the connection between WSL and the host, it passes, from: https://github.com/microsoft/WSL/issues/4585
PS C:\Windows\system32> $Listener = [System.Net.Sockets.TcpListener]80;
PS C:\Windows\system32> $Listener.Start();
PS C:\Windows\system32> $Listener.AcceptSocket();
Available : 0
LocalEndPoint : 172.23.224.1:80
RemoteEndPoint : 172.23.231.154:34690
Handle : 2696
Blocking : True
UseOnlyOverlappedIO : False
Connected : True
AddressFamily : InterNetwork
SocketType : Stream
ProtocolType : Tcp
IsBound : True
ExclusiveAddressUse : False
ReceiveBufferSize : 65536
SendBufferSize : 65536
ReceiveTimeout : 0
SendTimeout : 0
LingerState : System.Net.Sockets.LingerOption
NoDelay : False
Ttl : 128
DontFragment : True
MulticastLoopback :
EnableBroadcast :
DualMode :
WSL:
telnet $(cat /etc/resolv.conf | grep nameserver | cut -d' ' -f2) 80
Trying 172.23.224.1...
Connected to 172.23.224.1.
Escape character is '^]'.