本文通过Matlab ROS Toolbox实现与WSL2中ROS的通讯,并通过Topic的方式进行数据交互,以实现Matlab算法对仿真中机器人的控制(以UUV_simulator为例)。
一、WSL2相关配置
- 进入WSL2 linux系统,通过
ifconfig
命令查看当前子系统的IP地址,以172.25.120.194
为例。
- 在终端配置文件(
.zshrc
或者.bashrc
等)中,添加语句export ROS_IP=172.25.120.194
,并通过source
命令更新配置文件。
运行roscore
,运行成功后,代表上述配置无误。 - 在WSL2中安装并配置SSH
sudo apt-get update
sudo apt-get install openssh-server
sudo vim /etc/ssh/sshd_config
在配置文件中做出如下改动:
- 将
PasswordAuthentication no
改动为PasswordAuthentication yes
- 将
PermitRootLogin no
改动为PermitRootLogin yes
- 完成后,通过
sudo passwd root ****
设置root账户密码,并通过sudo service ssh restart
重启SSH服务。
二、Matlab配置
- 通过链接下载configWSL2.m配置文件,注意函数中
ROSPath
是否需要修改。 - 运行函数
configureWSL2(IP,root,****)
.其中IP
代指步骤一中通过ifconfig
所看到的IP地址,以本文为例,IP为172.25.120.194
.root
代指登陆账户为root账户,****
代指步骤一中所设置的root用户密码。 - 在Windows Powershell中运行命令
set ROS_IP=172.25.120.194
(不知道有没有用)。
三、测试
后续步骤可参照博客