当前位置:   article > 正文

【ROS2学习笔记】ROS2安装

ros2安装

在这里插入图片描述

系统安装版本选择

ROS 目前主要支持 Ubuntu、OSX、Android、Arch、Debian 等系统,ROS 也针对 ARM 处理器编译了核心库和部分功能包。新发布的 ROS2 也支持 Windows 系统。

对ROS兼容性最好的当属Ubuntu系统。从ROS发布以来,每版的Ubuntu系统版本都有与之对应ROS版本的。

每一版ROS都有其对应版本的Ubuntu版本,切记不可随便装。

ROS 、Gazebo和Ubuntu之间的版本对应关系:

UbuntuROS 1.0ROS 2.0Gazebo
ROS2Go 1.016.04 LTSKinetic LTSArdent7.+
ROS2Go 2.018.04 LTSMelodic LTSDashing LTS9.+
ROS2Go 3.020.04 LTSNoetic LTSFoxy LTS11.+

Gazebo是一款物理仿真引擎,与ROS有较好的对接接口。同时Gazebo内置了很多机器人模型,可以直接使用。

ROS官网的一些版本说明如下:
请添加图片描述
y

这里由于我使用的是Ubuntu20.04系统,所以这里准备安装ROS2.0 的Foxy LTS.

安装步骤

修改源

Ubuntu系统自带的源都是国外的网址,国内用户在使用的时候网速比较慢。

这里我们使用国内的源:mirrors.aliyun.com

保存下 原来的/etc/apt/sources.list,然后替换 /etc/apt/sources.list 文件中的内容为(针对 ubuntu 20.04):

deb http://mirrors.aliyun.com/ubuntu/ focal main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ focal main restricted universe multiverse

deb http://mirrors.aliyun.com/ubuntu/ focal-security main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ focal-security main restricted universe multiverse

deb http://mirrors.aliyun.com/ubuntu/ focal-updates main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ focal-updates main restricted universe multiverse

deb http://mirrors.aliyun.com/ubuntu/ focal-proposed main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ focal-proposed main restricted universe multiverse

deb http://mirrors.aliyun.com/ubuntu/ focal-backports main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ focal-backports main restricted universe multiverse
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
设置编码

这是完后,系统会从中文改成英文.(目前直接在中文版安装是否会报错,我没有尝试,后续尝试下在修改这里)

sudo locale-gen en_US en_US.UTF-8
sudo update-locale LC_ALL=en_US.UTF-8 LANG=en_US.UTF-8
export LANG=en_US.UTF-8
  • 1
  • 2
  • 3
设置源

设置ROS的地址:

sudo apt update && sudo apt install curl gnupg2 lsb-release
curl -s https://raw.githubusercontent.com/ros/rosdistro/master/ros.asc | sudo apt-key add -
 
sudo sh -c 'echo "deb [arch=$(dpkg --print-architecture)] http://packages.ros.org/ros2/ubuntu $(lsb_release -cs) main" > /etc/apt/sources.list.d/ros2-latest.list'
  • 1
  • 2
  • 3
  • 4
开始安装ROS2
sudo apt update
sudo apt install ros-foxy-desktop
  • 1
  • 2

这里下载时间比较长, 耐心等待下载完成.

设置环境变量

下载完成后,设置好环境变量:

source /opt/ros/foxy/setup.bash
  • 1

如果有安装ROS1,会提示一个警告.

安装自动补全工具
sudo apt install python3-argcomplete
 
  • 1
  • 2
运行Hello World

程序运行,需要运行一个talker和一个listener.

首先来运行talker:

source /opt/ros/foxy/setup.bash
ros2 run demo_nodes_cpp talker
  • 1
  • 2

请添加图片描述
再运行一个Listener:

source /opt/ros/foxy/setup.bash
ros2 run demo_nodes_py listener
  • 1
  • 2

请添加图片描述
安装完毕,下课O(∩_∩)O~

后话

最近自己安装新的环境,发现外网资源特别慢,找了个国内源安装的博文:
传送门
在这里插入图片描述

声明:本文内容由网友自发贡献,转载请注明出处:【wpsshop博客】
推荐阅读
相关标签
  

闽ICP备14008679号