通过局域网 (LAN) 与 WSL2 上的 ROS 通信时出现问题 [英] Problem communicating over a local area network (LAN) with ROS on WSL2

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

问题描述

我是 ROS 项目的开发人员.最近我尝试在 WSL2(Linux 的 Windows 子系统)上使用 ROS(melodic),一切都很好.但是当我想使用另一台同样位于同一局域网 (LAN) 中的 PC 进行通信时,我遇到了一些麻烦.在设置ROS_MASTER_URI,ROS_IP"等环境变量之前,我知道由于WSL 2在Hyper-V上工作,所以WSL2上的IP显示不是真实局域网中的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

但是这里出现了一个新问题:

But here comes a new question:

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

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.

一个缺点 - 我相信那里提到的脚本需要在 登录 时运行,因为 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 将备份导入到新的 WSL1 实例中;<安装位置><FileNameOfBackup>--版本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.

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

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