Communictaion in local area network(LAN) problem about ROS on WSL2

你说的曾经没有我的故事 提交于 2021-02-10 13:08:17

问题


I am a developer of ROS projects. Recently I am trying using ROS(melodic) on WSL2(Windows Subsystem for Linux), and all things works just great. But I got some trouble when I want to use another PC which also in the same local area network(LAN) to communicate with. Before setting the environment variables like "ROS_MASTER_URI, ROS_IP", I know that since WSL 2 work on Hyper-V so the IP show on WSL2 is not the one in the real LAN. I have to do some command like below in order to make everyone in LAN communicate with the specific host:PORT on WSL2.

netsh interface portproxy delete v4tov4 listenport=$port listenaddress=$addr

But here comes a new question:

The nodes which use TCPROS to communicate with each other have a random PORT every time I launch the file.

How can I handle this kind of problem? Or is there any information on the internet that I can have a look?

Thank you.


回答1:


The root problem is described in WSL issue #4150. To quote from that thread,

WSL 2 seems to NAT it's virtual network, instead of making it bridged to the host NIC.

Option 1 - Port forwarding script on login

There are a number of workarounds described in that issue, for which you've already figured out the first part (the port forwarding). The primary technique seems to be to create a PowerShell script to detect the IP address and create the port forwarding rules that runs upon Windows login. This particular comment near the top of the thread seems to be the canonical go-to answer, although many people have posted their tweaks or alternatives throughout the very long thread.

One downside - I believe the script that is mentioned there needs to be run at logon since the WSL subsystem seems to only want to run when a user is logged in. I've found that attempting to run a WSL service or instance through Windows OpenSSH results in that instance/service shutting down soon after the SSH session is closed, unless the user is already logged into Windows with a WSL instance opened.

Option 2 - WSL1

I would also propose that, assuming it fits your workflow and if the ROS works on it (it may not, given the device access you need, but not sure), you can simply use WSL1 instead of WSL2 to avoid this. You can try this out by:

  1. Backing up your existing distro (from PowerShell or cmd, use wsl --export <DistroName> <FileName>
  2. Import the backup into a new WSL1 instance with wsl --import <NewDistroName> <InstallLocation> <FileNameOfBackup> --version 1

It's possible to simply change versions in place, but I tend to like to have a backup anyway before doing it, and as long as you are backing up, you may as well leave the original in place.



来源:https://stackoverflow.com/questions/65275743/communictaion-in-local-area-networklan-problem-about-ros-on-wsl2

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!