ROS Network Setup
ROS Network Setup
ROS is a distributed computing environment. This allows running compute expensive tasks such as visualization or path planning for navigation on machines with more performance and sending goals to robots operating on less performant hardware like DiffBot with its Raspberry Pi 4 B.
For detailed instructions see ROS Network Setup and the ROS Environment Variables.
The setup between the work machine that handles compute heavy tasks and DiffBot is as follows:
The work machine runs the ROS master (roscore). Every node first registers with the master and asks it where the other nodes are (1). After that, the nodes send their topics and services directly to each other, in both directions (2). So the robot must be able to reach the work machine, and the work machine the robot: ROS needs "full bi-directional connectivity, on all ports" between them (ROS NetworkSetup). Both kinds of traffic go over Wi-Fi or your LAN.
If the work machine runs the dev container, the container shares the PC's network (Network). On Windows with WSL 2, the robot can't reach it without extra setup, see Work machine on Windows (WSL 2) below.
On DiffBot we configure the ROS_MASTER_URI to be the IP address of the work machine.
1 | |
To test run the master on the work machine using the roscore command.
Then run the the listener from the roscpp_tutorials package in another terminal:
1 | |
Then switch to a terminal on DiffBot's Raspberry Pi and run the talker from roscpp_tutorials:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 | |
Looking back at the terminal on the work machine you should see the output:
1 2 3 4 5 6 7 8 | |
Note that it can take some time receiving the messages from DiffBot on the work machine, which we can see from the time stamps in the outputs above.
Work machine on Windows (WSL 2)
If your work machine runs Windows and ROS runs in WSL 2, for example in the dev container, the robot usually can't connect to it.
Why: by default, WSL 2 runs behind network address translation (NAT). The Ubuntu in WSL gets its own private IP address, often 172.x.x.x, which only Windows itself can reach (WSL networking). Connections from WSL to the robot work, but not from the robot to WSL. ROS 1 needs both directions: the robot's nodes connect to the master on your PC, and to your PC's nodes to receive their topics, for example the velocity commands from navigation. Forwarding single ports from Windows to WSL doesn't help either, because every ROS node listens on random ports.
Fix: mirrored networking. On Windows 11 22H2 or later, WSL can mirror Windows' network interfaces. The Ubuntu in WSL then has the same IP address as Windows, and devices on your network can connect to it directly (mirrored mode). The dev container uses this network too, because it shares WSL's network.
-
In Windows, create or edit the file
%UserProfile%\.wslconfig(WSL settings):1 2
[wsl2] networkingMode=mirrored -
Run
wsl --shutdownin PowerShell and open Ubuntu again.hostname -Iin Ubuntu should now show your PC's address on the network, for example192.168.0.9. -
Allow the robot through the Hyper-V firewall, which filters connections to WSL. In PowerShell as administrator, with the robot's IP address:
1 2 3
New-NetFirewallHyperVRule -Name ROS-robot -DisplayName "ROS robot" ` -Direction Inbound -Action Allow -RemoteAddresses 192.168.0.20 ` -VMCreatorId '{40E0AC32-46A5-438A-A0B2-2B479E8F2E90}'This only lets the robot in. The
-VMCreatorIdis WSL's fixed ID (Hyper-V firewall). Microsoft's mirrored mode section also shows how to allow all incoming connections to WSL. -
Tell ROS which addresses to use (ROS environment variables):
1 2 3 4 5 6 7
# On the PC, in the container export ROS_MASTER_URI=http://192.168.0.9:11311 export ROS_IP=192.168.0.9 # On the robot export ROS_MASTER_URI=http://192.168.0.9:11311 export ROS_IP=192.168.0.20 -
Run the talker and listener test from above in both directions: the talker on the robot with the listener on the PC, and the talker on the PC with the listener on the robot. In both, the robot's node has to reach the master on your PC, so behind NAT neither works. The second direction also checks that the robot can connect to a node on your PC, on the random ports ROS picks for it.
Not tested with the robot yet
Mirrored networking is Microsoft's fix for exactly this problem, but nobody has tested this setup with DiffBot or Remo yet. If you try it, please tell us in the comments below whether it works.
Comments
Comments are GitHub Discussions, shown with giscus. Loading them connects to giscus.app (hosted by Vercel, USA) and GitHub (USA); you need a GitHub account to comment.