本文通过Matlab ROS Toolbox实现与WSL2中ROS的通讯,并通过Topic的方式进行数据交互,以实现Matlab算法对仿真中机器人的控制(以UUV_simulator为例)。

一、WSL2相关配置

  1. 进入WSL2 linux系统,通过ifconfig命令查看当前子系统的IP地址,以172.25.120.194为例。
    ifconfig
  2. 在终端配置文件(.zshrc或者.bashrc等)中,添加语句export ROS_IP=172.25.120.194,并通过source命令更新配置文件。
    zshrc
    运行roscore,运行成功后,代表上述配置无误。
  3. 在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配置

  1. 通过链接下载configWSL2.m配置文件,注意函数中ROSPath是否需要修改。
  2. 运行函数configureWSL2(IP,root,****).其中IP代指步骤一中通过ifconfig所看到的IP地址,以本文为例,IP为172.25.120.194.root代指登陆账户为root账户,****代指步骤一中所设置的root用户密码。
  3. 在Windows Powershell中运行命令set ROS_IP=172.25.120.194(不知道有没有用)。

三、测试

后续步骤可参照博客