wsl安装ros

我是在 WSL 的 Ubuntu 18.04 LTS 上安装 ROS。

准备工作
换源
我这是Ubuntu 18.04 LTS的清华源,如果需要其他版本的源,去清华软件镜像站自己寻找。

sudo nano /etc/apt/sources.list

#把里面的内容删光,换成清华的源

deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic main restricted universe multiverse
#deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-updates main restricted universe multiverse
#deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-updates main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-backports main restricted universe multiverse
#deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-backports main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-security main restricted universe multiverse
#deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-security main restricted universe multiverse
#预发布软件源,不建议启用
#deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-proposed main restricted universe multiverse
#deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-proposed main restricted universe multiverse

更新

更新源

sudo apt-get update

更新软件

sudo apt-get upgrade

正式安装ROS

添加 ROS 的源,下面二选一就行

sudo sh -c 'echo "deb http://packages.ros.org/ros/ubuntu $(lsb_release -sc) main" > /etc/apt/sources.list.d/ros-latest.list'
sudo sh -c '. /etc/lsb-release && echo "deb http://mirrors.tuna.tsinghua.edu.cn/ros/ubuntu/ $DISTRIB_CODENAME main" > /etc/apt/sources.list.d/ros-latest.list'

设置密钥(拆分开来添加,防止报 curl 错误)

curl -O https://raw.githubusercontent.com/ros/rosdistro/master/ros.asc
sudo apt-key add ros.asc

更新

sudo apt update
sudo apt upgrade
# 安装对应的 ROS 版本(官网推荐是装full)
sudo apt install ros-melodic-desktop-full # 这里要装很久,所以尽量别出错

(我用这个命令出错了,
The following packages have unmet dependencies:
ros-melodic-desktop-full : Depends: ros-melodic-desktop but it is not going to be installed
Depends: ros-melodic-perception but it is not going to be installed
Depends: ros-melodic-simulators but it is not going to be installed
Depends: ros-melodic-urdf-sim-tutorial but it is not going to be installed
E: Unable to correct problems, you have held broken packages.
root@L5288456A005:/home/yuliang# sudo apt-get ros-melodic-desktop
E: Invalid operation ros-melodic-desktop)
然后用的这个命令:

sudo aptitude install ros-melodic-desktop-full

设置环境变量,这里我用的终端是 zsh

echo "source /opt/ros/melodic/setup.zsh" >> ~/.zshrc
source ~/.zshrc

安装依赖包

sudo apt install python-rosdep python-rosinstall python-rosinstall-generator python-wstool build-essential
sudo apt install python-rosdep

初始化

sudo rosdep init
rosdep update  # 可能需要科学上网

安装 rosinstall

sudo apt install python-rosinstall python-rosinstall-generator python-wstool build-essential

安装图形化界面 Xserver
因为这不是完整的 Ubuntu Linux 系统,所以缺少相对应的图形化界面。所以需要自己安装,我这里安装的是 VcXsrv

配置环境变量 DISPLAY

echo "export DISPLAY=localhost:0" >> ~/.bashrc  # wsl 1
echo "export DISPLAY=`cat /etc/resolv.conf | grep nameserver | awk '{print $2}'`:0" >> ~/.bashrc  # wsl 2
source  ~/.bashrc
然后打开安装的 XLaunch,Display Number 改为0。
这里先用 xeyes 测试一下,你也可以用下面几个测试。
sudo apt install x11-apps
xeyes

如果你看到一双大眼睛,就说明安装成功了。

测试 ROS 是否安装成功
一定要先打开 XLaunch!

运行 Rviz

先打开一个终端

roscore

再打开第二个终端

rosrun rviz rviz

运行小乌龟

先打开一个终端

roscore

打开第二个终端

rosrun turtlesim turtlesim_node

(如果报错[rospack] Error: package ‘turtlesim’ not found,解决方法如下)

sudo apt-get install ros-$(rosversion -d)-turtlesim

打开第三个终端

rosrun turtlesim turtle_teleop_key

这时会出现一个小乌龟,在第三个终端里控制其进行移动。

你可能感兴趣的:(ros,linux,终端,ubuntu,linux,运维)