ROS(6)ROS2安装及运行

ROS2安装与遇到的问题

1、确保系统要支持 UTF-8

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

设置清华源

sudo cp /etc/apt/sources.list /etc/apt/sources.list.bak
sudo apt-get install vim
sudo vim /etc/apt/sources.list

 #添加清华源
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-updates main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-updates main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-backports main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-backports main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-security main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-security main restricted universe multiverse multiverse

粘贴完之后,按“Esc”进入命令模式,输入“:wq”,回车键退出。是冒号和w和q,不要漏了冒号。

sudo apt-get update
sudo apt-get upgrade

参考网址

ubuntu20.04更换清华源_ubuntu20.04更换清华源 pisayu_PisaYu的博客-CSDN博客

2、设置软件源

安装curl gnupg2 lsb-release并添加源

sudo apt update
sudo apt install curl gnupg2 lsb-release

# 下面这条语句,我的输出错误: gpg: no valid OpenPGP data found
# curl -s https://raw.githubusercontent.com/ros/rosdistro/master/ros.asc | sudo apt-key add -
# 解决上面的问题,可以换成下面这条语句:
$ curl http://repo.ros2.org/repos.key | sudo apt-key add - 

# 之后再添加源:
sudo sh -c 'echo "deb http://mirrors.tuna.tsinghua.edu.cn/ros2/ubuntu/ `lsb_release -cs` main" > /etc/apt/sources.list.d/ros2-latest.list'
或
sudo sh -c 'echo "deb http://packages.ros.org/ros2/ubuntu `lsb_release -cs` main" > /etc/apt/sources.list.d/ros2-latest.list'

 执行更新

sudo apt update

执行更新报错:

E: 无法下载 http://mirrors.tuna.tsinghua.edu.cn/ros2/ubuntu/dists/focal/main/binary-i386/Packages  404  Not Found [IP: 101.6.15.130 80]
E: 部分索引文件下载失败。如果忽略它们,那将转而使用旧的索引文件。

原因:此处是因为在安装ros时,在 /etc/apt/sources.list.d中添加的ros2-latest.list对应的是binary i386,需要更改为amd64

解决:执行以下命令

sudo gedit /etc/apt/sources.list.d/ros2-latest.list

deb http://mirrors.tuna.tsinghua.edu.cn/ros2/ubuntu/ focal或bionic main

中间增加内容

deb [arch=amd64] http://mirrors.tuna.tsinghua.edu.cn/ros2/ubuntu/ focal或bionic main

 保存后再次执行sudo apt update,完成更新

3、安装ROS2桌面完整版

安装ROS2命令

sudo apt install ros-foxy-desktop

报错:无法修正错误,因为您要求某些软件包保持现状,就是它们破坏了软件包间的依赖关系

解决:使用sudo aptitude install xxx代替sudo apt-get install xxx

sudo aptitude install ros-foxy-desktop

问题:安装后没有foxy文件夹

解决:重新设置清华源

安装colcon-common-extensions

sudo apt install python3-colcon-common-extensions

环境测试

source /opt/ros/foxy/setup.bash

报错:警告:ROS_DISTRO was set to ‘noetic’ before. Please make sure that the environment does not mix paths from different distributions.

原因:Ubuntu20.04同时安装了ROS1和ROS2,但是不能同时使用ROS1和ROS2。

解决:home/用户文件夹/ -> ctrl+h > .bashrc

当使用ROS1时,打开~/.bashrcsource /opt/ros/foxy/setup.bash和ROS2的工作空间注释掉

  • # 注释掉ROS1的环境变量
  • #source /opt/ros/noetic/setup.bash
  • #source ~/catkin_ws/devel/setup.bash --extend

再次执行环境测试

source /opt/ros/foxy/setup.bash

自动补全工具 

sudo apt update
sudo apt install python3-argcomplete
sudo apt update
sudo apt install ros-foxy-rmw-connext-cpp

***注意:安装foxy rmw connext时,卡在10%

解决:需要多次按enter,然后在Do you accept the terms of this license agreement?: 输入yes

问题:当卡在10%后直接关闭Terminal时,再次执行install ros-foxy-rmw-connext-cpp报错

解决:sudo apt-get install --reinstall rti-connext-dds-5.3.1

安装ros1转换bridge

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

ROS1和ROS2混合配置

sudo gedit ~/.bashrc

 完成环境变量设置

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

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

ROS1和ROS2差异

编译

catkin_make --> colcon build

catkin_make -DCATKIN_WHITELIST_PACKAGES="" --> colcon build --packages-select  PACKAGE_NAME

bashrc存入

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

terminal 命令

rosrun --> ros2 run
rosnode --> ros2 node
roslaunch --> ros2 launch
rosparam --> ros2 param
rospkg --> ros2 pkg
rosservice --> ros2 service 
rossrv --> ros2 srv
rostopic --> ros2 topic
rosaction --> ros2 action

卸载ROS2 foxy

卸载命令

sudo apt remove ~nros-foxy-* && sudo apt autoremove

重新安装某个包命令

sudo apt-get install --reinstall

缺少包配置命令

sudo dpkg --configure printer-driver-pxljr

你可能感兴趣的:(机器人,linux)