本文无废话,实现了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/
搞到这个,离成功就不远了;
重要步骤:
添加ros2 软件源
注意apt-key的网址
sudo apt install curl gnupg2
curl http://repo.ros2.org/repos.key | sudo apt-key add -
sudo apt update
注意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'
安装ros-eloquent和相关依赖
开始更新和安装
sudo apt update
sudo apt install ros-eloquent-desktop
注意:18.04下对应的ros版本是melodic,ros2是eloquent
安装python3库
sudo apt install -y libpython3-dev python3-pip
pip3 install -U argcomplete
这个安装了一半跳过了
sudo apt install ros-eloquent-rmw-connext-cpp
ROS和ros2
若ros2单独存在
echo "source /opt/ros/eloquent/setup.bash" >> ~/.bashrc
source ~/.bashrc
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
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)
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)
安装colcon编译工具
sudo apt-get install python3-colcon-ros
运行经典小乌龟
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"
在切出来另外一个终端,会让选择使用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.
这样就可以控制ROS2的小龟了