当前位置:   article > 正文

ubunt18.04安装ROS2_ubuntu18.04安装ros2

ubuntu18.04安装ros2

本文无废话,实现了ubunt18.04 下ros2的安装,并且同时兼容ros和ros2
如果想完ros(1)的,请参考我的前一篇文章:ubunt18.04安装ROS避坑指南
参考:

https://blog.csdn.net/cau_weiyuhu/article/details/128666548
https://blog.csdn.net/ZhangRelay/article/details/114762734

得到一个重要信息ROS2的镜像这里有:

https://mirrors.tuna.tsinghua.edu.cn/ros2/ubuntu/
  • 1

搞到这个,离成功就不远了;

重要步骤:

添加ros2 软件源

注意apt-key的网址

sudo apt install curl gnupg2
curl http://repo.ros2.org/repos.key | sudo apt-key add -
sudo apt update
  • 1
  • 2
  • 3

注意ros2的网址

 sudo sh -c 'echo "deb [arch=amd64] https://mirrors.tuna.tsinghua.edu.cn/ros2/ubuntu/  bionic main" > /etc/apt/sources.list.d/ros2-latest.list'
  • 1

安装ros-eloquent和相关依赖

开始更新和安装

sudo apt update
sudo apt install ros-eloquent-desktop
  • 1
  • 2

注意:18.04下对应的ros版本是melodic,ros2是eloquent

安装python3库

sudo apt install -y libpython3-dev python3-pip
pip3 install -U argcomplete
  • 1
  • 2

这个安装了一半跳过了

sudo apt install ros-eloquent-rmw-connext-cpp
  • 1

ROS和ros2

若ros2单独存在

echo "source /opt/ros/eloquent/setup.bash" >> ~/.bashrc
source ~/.bashrc
  • 1
  • 2

ROS1和ROS2共存
在~.bashrc中添加如下代码,前提你得时ubunt18.04,且安装了两个版本

#source /opt/ros/melodic/setup.bash
#source /opt/ros/eloquent/setup.bash
 echo "ros melodic(1) or ros2 eloquent(2)?"
 read edition
 ps=$PS1
 if [ "$edition" -eq "1" ]; then
   source /opt/ros/melodic/setup.bash
   # echo "ros melodic(1) has been chosen!"
   PS1="(ros1-melodic:)$ps"
 else
   source /opt/ros/eloquent/setup.bash
   # echo "ros2 eloquent(2) has been chosen!"
   PS1="(ros2-eloquent)$ps"
 fi
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14

ROS2依赖配置

fang@fang-inspiron-5580:/etc/apt/sources.list.d$ sudo rosdepc init
您已经成功安装rosdepc,下面提示的用法中,请将rosdep替换为rosdepc使用~
欢迎使用国内版rosdep之rosdepc,我是作者小鱼!
学习机器人,就关注《鱼香ROS》(公众号|B站|CSDN)!
小鱼rosdepc正式为您服务
Wrote /etc/ros/rosdep/sources.list.d/20-default.list
Recommended: please run

	rosdep update

---------------------------------------------------------------------------
小鱼提示:恭喜你完成初始化,快点使用

 rosdepc update

更新吧
---------------------------------------------------------------------------
小鱼科普:rosdep干什么用的?可以跳过吗?https://fishros.org.cn/forum/topic/2124
如果再使用过程中遇到任何问题,欢迎通过fishros.org.cn反馈,或者加入QQ交流群(139707339)
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
fang@fang-inspiron-5580:/etc/apt/sources.list.d$ rosdepc update
您已经成功安装rosdepc,下面提示的用法中,请将rosdep替换为rosdepc使用~
欢迎使用国内版rosdep之rosdepc,我是作者小鱼!
学习机器人,就关注《鱼香ROS》(公众号|B站|CSDN)!
小鱼rosdepc正式为您服务
reading in sources list data from /etc/ros/rosdep/sources.list.d
Hit https://mirrors.tuna.tsinghua.edu.cn/github-raw/ros/rosdistro/master/rosdep/osx-homebrew.yaml
Hit https://mirrors.tuna.tsinghua.edu.cn/github-raw/ros/rosdistro/master/rosdep/base.yaml
Hit https://mirrors.tuna.tsinghua.edu.cn/github-raw/ros/rosdistro/master/rosdep/python.yaml
Hit https://mirrors.tuna.tsinghua.edu.cn/github-raw/ros/rosdistro/master/rosdep/ruby.yaml
Query rosdistro index https://mirrors.tuna.tsinghua.edu.cn/rosdistro/index-v4.yaml
Skip end-of-life distro "ardent"
Skip end-of-life distro "bouncy"
Skip end-of-life distro "crystal"
Skip end-of-life distro "dashing"
Skip end-of-life distro "eloquent"
Skip end-of-life distro "foxy"
Skip end-of-life distro "galactic"
Skip end-of-life distro "groovy"
Add distro "humble"
Skip end-of-life distro "hydro"
Skip end-of-life distro "indigo"
Add distro "iron"
Skip end-of-life distro "jade"
Skip end-of-life distro "kinetic"
Skip end-of-life distro "lunar"
Skip end-of-life distro "melodic"
Add distro "noetic"
Add distro "rolling"
updated cache in /home/fang/.ros/rosdep/sources.cache
---------------------------------------------------------------------------
小鱼恭喜:rosdepc已为您完成更新!!
---------------------------------------------------------------------------
小鱼科普:rosdep干什么用的?可以跳过吗?https://fishros.org.cn/forum/topic/2124
如果再使用过程中遇到任何问题,欢迎通过fishros.org.cn反馈,或者加入QQ交流群(139707339)
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35

安装colcon编译工具

sudo apt-get install python3-colcon-ros
  • 1

运行经典小乌龟

fang@fang-inspiron-5580:~$ sudo apt install ros-eloquent-turtlesim
Reading package lists... Done
Building dependency tree       
Reading state information... Done
ros-eloquent-turtlesim is already the newest version (1.1.2-1bionic.20201207.164444).
ros-eloquent-turtlesim set to manually installed.
0 upgraded, 0 newly installed, 0 to remove and 3 not upgraded.


fang@fang-inspiron-5580:~$ ros2 pkg executables turtlesim
turtlesim draw_square
turtlesim mimic
turtlesim turtle_teleop_key
turtlesim turtlesim_node


fang@fang-inspiron-5580:~$ ros2 run turtlesim turtlesim_node
QFactoryLoader::QFactoryLoader() checking directory path "/usr/lib/x86_64-linux-gnu/qt5/plugins/platforms" ...
QFactoryLoader::QFactoryLoader() looking at "/usr/lib/x86_64-linux-gnu/qt5/plugins/platforms/libqeglfs.so"
Found metadata in lib /usr/lib/x86_64-linux-gnu/qt5/plugins/platforms/libqeglfs.so, metadata=
{
    "IID": "org.qt-project.Qt.QPA.QPlatformIntegrationFactoryInterface.5.3",
    "MetaData": {
        "Keys": [
            "eglfs"
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25

在切出来另外一个终端,会让选择使用ros还是ros2

ros melodic(1) or ros2 eloquent(2)?
2
(ros2-eloquent)fang@fang-inspiron-5580:~$ 
(ros2-eloquent)fang@fang-inspiron-5580:~$ 
(ros2-eloquent)fang@fang-inspiron-5580:~$ 
(ros2-eloquent)fang@fang-inspiron-5580:~$ 
(ros2-eloquent)fang@fang-inspiron-5580:~$ ros2 run turtlesim turtle_teleop_key
Reading from keyboard
---------------------------
Use arrow keys to move the turtle.
Use G|B|V|C|D|E|R|T keys to rotate to absolute orientations. 'F' to cancel a rotation.
'Q' to quit.
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12

这样就可以控制ROS2的小龟了
在这里插入图片描述

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/小惠珠哦/article/detail/1011330
推荐阅读
相关标签
  

闽ICP备14008679号