[亲测有效]Ubuntu20.04安装ROS1和ROS2

[亲测有效]Ubuntu20.04安装ROS1和ROS2

 

参考链接:https://www.guyuehome.com/35421

https://blog.csdn.net/qq_41276366/article/details/108810777#commentBox

 

在Ubuntu中打开“软件更新”,选择前四个。

配置网络,选择最佳服务器。

安装预备环境

1 sudo apt-get install python
2 sudo apt-get install  g++

 

1. ROS1安装

添加sources.list

1  sudo sh -c 'echo "deb http://packages.ros.org/ros/ubuntu $(lsb_release -sc) main" > /etc/apt/sources.list.d/ros-latest.list'

国内中国科技大学的源

1   sudo sh -c '. /etc/lsb-release && echo "deb http://mirrors.ustc.edu.cn/ros/ubuntu/ $DISTRIB_CODENAME main" > /etc/apt/sources.list.d/ros-latest.list'

添加Keys

1 sudo apt-key adv --keyserver 'hkp://keyserver.ubuntu.com:80' --recv-key C1CF6E31E6BADE8868B172B4F42ED6FBAB17C654

安装ROS1桌面完整版

1 sudo apt update
2 sudo apt install ros-noetic-desktop-full

注意:在安装源的选择上,可以选择最佳的服务器或者usta源都可以,亲测有效。

环境测试

1 source /opt/ros/noetic/setup.bash

补全rosdep

1 sudo apt install python3-rosdep python3-rosinstall python3-rosinstall-generator python3-wstool build-essential
2 sudo apt install python3-rosdep
3 sudo rosdep init
4 rosdep update

2. ROS2安装

确保系统要支持 UTF-8:

1 sudo locale-gen en_US en_US.UTF-8
2 sudo update-locale LC_ALL=en_US.UTF-8 LANG=en_US.UTF-8 export LANG=en_US.UTF-8

设置软件源

 1 sudo apt update
 2 sudo apt install curl gnupg2 lsb-release
 3 
 4 # 下面这条语句,我的输出错误: gpg: no valid OpenPGP data found
 5 # curl -s https://raw.githubusercontent.com/ros/rosdistro/master/ros.asc | sudo apt-key add -
 6 # 解决上面的问题,可以换成下面这条语句:
 7 $ curl http://repo.ros2.org/repos.key | sudo apt-key add - 
 8 
 9 # 之后再添加源(自己电系统里选择的源):
 
sudo sh -c 'echo "deb http://packages.ros.org/ros2/ubuntu `lsb_release -cs` main" > /etc/apt/sources.list.d/ros2-latest.list'

安装ROS2 package

 1 # 进入文件夹并修改ros2-latest.list文件
 2 cd /etc/apt/sources.list.d
 3 sudo vim ros2-latest.list
 4 
 5 # 打开文本后出现
 6 deb http://packages.ros.org/ros2/ubuntu bionic main
 7 # 在deb后插入[arch=amd64]
 8 deb [arch=amd64] http://packages.ros.org/ros2/ubuntu bionic main
 9 
10 # 保存并关闭,然后更新
11 sudo apt update
12 # 最后就可以进行安装了
13 sudo apt install ros-foxy-desktop
sudo apt install python3-colcon-common-extensions

注意:解决:dpkg: 错误: 另外一个进程已经为 dpkg frontend lock 加锁

1 $ ps -e | grep apt
2    8925 pts/0    00:00:01 apt-get
3 
4 $ sudo kill 8925

*(非必须)注意:如果ROS2缺失很多依赖,可以考虑卸载重新安装,卸载ROS2

1 sudo apt-get remove ros-foxy-*
2 sudo apt autoremove

安装rosdep和相关依赖:

1 rosdep install --from-path /opt/ros/foxy/src --ignore-src -r -y

环境测试

1 ource /opt/ros/foxy/setup.bash

自动补全工具

1 sudo apt update
2 sudo apt install python3-argcomplete
3 sudo apt update
4 sudo apt install ros-foxy-rmw-connext-cpp  #(这句命令FQ后重新安装好ros2后,就可以运行成功了)

安装ros1转换bridge

1 sudo apt update
2 sudo apt install ros-foxy-ros1-bridge 

3.ROS1和ROS2混合配置

1 sudo gedit ~/.bashrc

 

打开.bashrc文本文件后在末尾加上如下代码,完成环境变量设置。

1 #source /opt/ros/noetic/setup.bash
2 echo "ros noetic(1) or ros2 foxy(2)?"
3 read edition
4 if [ "$edition" -eq "1" ];then
5   source /opt/ros/noetic/setup.bash
6 else
7   source /opt/ros/foxy/setup.bash
8 fi

4.ROS1和ROS2差异

编译

1 catkin_make --> colcon build
2 
3 catkin_make -DCATKIN_WHITELIST_PACKAGES="" --> colcon build --packages-select  PACKAGE_NAME

bashrc存入

1 echo "source ~/catkin_ws/devel/setup.bash" >> ~/.bashrc --> echo "source ~/colcon_ws/install/setup.bash" >> ~/.bashrc

terminal 命令

1 rosrun --> ros2 run
2 rosnode --> ros2 node
3 roslaunch --> ros2 launch
4 rosparam --> ros2 param
5 rospkg --> ros2 pkg
6 rosservice --> ros2 service 
7 rossrv --> ros2 srv
8 rostopic --> ros2 topic
9 rosaction --> ros2 action

注意:ROS2相比ROS1在语法上有了很大的改变,在编程思路还是一样。

 

参考链接:https://www.guyuehome.com/35421

https://blog.csdn.net/qq_41276366/article/details/108810777#commentBox

https://blog.csdn.net/weixin_48370221/article/details/115876753#commentBox

 

posted @ 2022-03-19 16:29  白雪儿  Views(3785)  Comments(0Edit  收藏  举报