WSL2上有关ROS的局域网(LAN)通信问题 [英] Communictaion in local area network(LAN) problem about ROS on WSL2

查看:545
本文介绍了WSL2上有关ROS的局域网(LAN)通信问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是ROS项目的开发人员.最近,我正在尝试在WSL2(Linux的Windows子系统)上使用ROS(旋律),并且一切正常.但是,当我想使用另一台也位于同一局域网(LAN)进行通信的PC时遇到了麻烦.在设置诸如"ROS_MASTER_URI,ROS_IP"之类的环境变量之前,我知道由于WSL 2在Hyper-V上工作,因此WSL2上的IP显示不是真实LAN中的IP.为了使LAN中的每个人都与WSL2上的特定主机:PORT通信,我必须执行以下命令.

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

但这是一个新问题:

每次启动文件时,使用TCPROS相互通信的节点都有一个随机的PORT.

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?

谢谢.

推荐答案

WSL问题#4150 .要引用该线程,

WSL 2似乎将其虚拟网络NAT,而不是将其桥接 到主机NIC.

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

选项1-登录时使用端口转发脚本

该问题中描述了许多变通办法,您已经找到了第一部分(端口转发).主要技术似乎是创建一个PowerShell脚本来检测IP地址并创建在Windows登录时运行的端口转发规则.在线程顶部附近的此特定评论答案,尽管很多人在很长的篇幅中都发表了自己的调整或替代方案.

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.

一个缺点-我认为那里提到的脚本需要在 login 上运行,因为WSL子系统似乎只想在用户登录时运行.我发现尝试通过Windows OpenSSH运行WSL服务或实例会导致该实例/服务在SSH会话关闭后立即关闭,除非用户已经在打开WSL实例的情况下登录到Windows.

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.

我还建议,假设它适合您的工作流程并且如果ROS可以在上面工作(鉴于您需要但不确定的设备访问权限,它可能不起作用),则可以简单地使用WSL1而不是WSL2来避免这种情况.您可以通过以下方法进行尝试:

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. 备份现有发行版(从PowerShell或cmd,使用wsl --export <DistroName> <FileName>
  2. 使用wsl --import <NewDistroName> <InstallLocation> <FileNameOfBackup> --version 1
  3. 将备份导入到新的WSL1实例中
  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.

这篇关于WSL2上有关ROS的局域网(LAN)通信问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆