Ubuntu20.04 installs ROS1 and ROS2 at the same time

Ubuntu20.04 installs ROS1 and ROS2 at the same time


Each version of the Ubuntu system version has a corresponding ROS version, and each version of ROS has its corresponding version of Ubuntu, which cannot be installed casually. ubuntu20.04 corresponds to the ROS1 noetic and ROS2 foxy versions.

1. Change source

Old rules, change the source first

1.1 Via software update

open software update

insert image description here

Select Download from->Other, find China, and select the source. Close the interface and wait for the automatic update source

1.2 By modifying the source file (recommended)

(1) Backup source files:

sudo cp /etc/apt/sources.list /etc/apt/sources.list.old

(2) Open the file:

sudo gedit /etc/apt/sources.list

(3) Change the source: recommend the source of Tsinghua or Alibaba Cloud (try according to your own network, choose the fastest one): Tsinghua source address , select the Ubuntu version (check the ubuntu version command: cat /etc/issue) and copy the source content, overwriting sources.listthe original file Content:

insert image description here

(4) After changing the source, update:

sudo apt-get update

2. Install ROS1 (noetic)

Reference Introduce in detail how to install the ROS system in ubuntu20.04. The installation is completed super fast (the latest version of the tutorial) . The explanation is very detailed. Many errors during the installation process are given solutions. Here is the general process
(1) Add ROS software source

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'

(2) Add key

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

(3) Update the software source

sudo apt update

Replace the above with the problem:

sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys F42ED6FBAB17C654

(4) Install ROS noetic

sudo apt install ros-noetic-desktop-full

(5) Initialize rosdep

sudo rosdep init
  • If command not found:
sudo apt install python-rosdep2
# 或者
sudo apt install python3-rosdep2
  • ERROR: cannot download default sources list from:https : //raw.githubusercontent.com/ros/rosdistro/master/rosdep/sources.list.d/20-default.listWebsite may be down.
udo gedit /etc/hosts

Add the following content to the opened hosts file, then save and exit

199.232.28.133 raw.githubusercontent.com

If it appears ERROR: cannot download default sources list from:
https://raw.githubusercontent.com/ros/rosdistro/master/rosdep/sources.list.d/20-default.list
Website may be down.

Visit https://www.ipaddress.com/ to query the ip address of raw.githubusercontent.com

insert image description here

Replace 199.232.28.133 raw.githubusercontent.com with:

185.199.108.133 raw.githubusercontent.com

  • ERROR: default sources list file already exists: /etc/ros /rosdep/sources.list.d/20-default.listPlease delete if you wish to re-initialize
sudo rm /etc/ros/rosdep/sources.list.d/20-default.list

Then

rosdep update

(6) Install rosinstall

sudo apt install python3-rosinstall python3-rosinstall-generator python3-wstool

(7) Configuration environment

sudo gedit ~/.bashrc
# 末尾添加
source /opt/ros/noetic/setup.bash
# 保存退出
source ~/.bashrc

(8) Verification

roscore
  • Command ‘roscore’ not found, but can be installed with:sudo apt install python3-roslaunch, follow the prompts to install:
sudo apt install python3-roslaunch
  • Resorce not found: roslaunchIndicates that the previous installation is not complete, continue to install
sudo apt install ros-noetic-desktop-full

(9) The little turtle tests ROS:

roecore
rosrun turtlesim turtlesim_node
rosrun turtlesim turtle_teleop_key

3. Install ROS2 (foxy)

Refer to ubuntu20.04 to install ros2 and coexist with ros1
(1) Set the encoding UTF-8

Terminal input: localeCheck if UTF-8 is supported

insert image description here

If not supported:

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

(2) Check if the ubuntu universe repository is enabled

apt-cache policy | grep universe
## 输出应如下:
 500 http://security.ubuntu.com/ubuntu focal-security/universe i386 Packages
     release v=20.04,o=Ubuntu,a=focal-security,n=focal,l=Ubuntu,c=universe,b=i386
 500 http://security.ubuntu.com/ubuntu focal-security/universe amd64 Packages
     release v=20.04,o=Ubuntu,a=focal-security,n=focal,l=Ubuntu,c=universe,b=amd64

Note that using 1.2 to change the source has been enabled by default, but it is not checked on the interface, don’t worry about it, if it is not enabled, there will be no output, then:

sudo apt install software-properties-common
sudo add-apt-repository universe

(3) Set the key

sudo apt update && sudo apt install curl gnupg2 lsb-release
sudo curl -sSL https://raw.githubusercontent.com/ros/rosdistro/master/ros.key  -o /usr/share/keyrings/ros-archive-keyring.gpg
echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/ros-archive-keyring.gpg] http://packages.ros.org/ros2/ubuntu $(source /etc/os-release && echo $UBUNTU_CODENAME) main" | sudo tee /etc/apt/sources.list.d/ros2.list > /dev/null
  • If an error is reported ailed to connect to raw.githubusercontent.com port 443 after 13 ms: 拒绝连接, refer to the method in the previous section /etc/hoststo add the IP of raw.githubusercontent.com to the file;
  • If there is no response, wait a little longer

(4) Installation

sudo apt update
# 推荐桌面版,注意安装时间较长,耐心等待
sudo apt install ros-foxy-desktop

(5) Configuration environment

echo "source /opt/ros/foxy/setup.bash" >> ~/.bashrc
source .bashrc

(6) Official demo test

ros2 run demo_nodes_cpp talker
ros2 run demo_nodes_cpp listener

insert image description here
(7) The little turtle no longer needs a master

ros2 run turtlesim turtlesim_node
ros2 run turtlesim turtle_teleop_key

insert image description here

Four, ROS1 and ROS2 mixed configuration environment

Refer to Ubuntu 20.04 ROS1 and ROS2 to install and use at the same time
. If only one version of ROS is installed, this section does not need to be performed, otherwise a mixed configuration of ROS1 and ROS2 is required.

sudo gedit ~/.bashrc

Open the .bashrc file and delete the configuration content in the previous two sections:

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

Then add the following code at the end to complete the environment variable setting. During use, you can switch the ros version as needed. Remember that you need to press "1" or "2" to select the ros version every time you open a new terminal.

insert image description here

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

insert image description here

Five, ROS common commands and their differences

5.1 Common commands

(1) compile

# ROS1
catkin_make
catkin_make -DCATKIN_WHITELIST_PACKAGES=""
# ROS2
colcon build
colcon build --packages-select  PACKAGE_NAME

(2) Workspace configuration bashrc

source ~/catkin_ws/devel/setup.bash
source ~/colcon_ws/install/setup.bash

(3) terminal command

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

5.2 Other commands (my notes)

(1) Change the publishing frequency and bandwidth of the topic through topic_tools/throttle

# 参数解释:intopic: 订阅的输入话题、msgs_per_sec: 每秒允许通过的最大messages数、outtopic: 发布的输出话题 (default: intopic_throttle) 
throttle messages <intopic> <msgs_per_sec> [outtopic]
# 举例,将原来200Hz的IMU数据降低至100
rosrun topic_tools throttle messages /imu_raw 100 /imu_raw_low_freq

How to write roslaunch:

<node pkg="topic_tools" type="throttle" name="camera_throttle" args="messages /imu_raw 100 /imu_raw_low_freq" output="screen" respawn="true"/>    

(2) recording and playback of bag

# 1 录制指定话题数据并保存,-O需要大写
rosbag record -O <bagname> <topic_name1> <topic_name2> <topic_name3> ...
# 2 查看数据包中包含的话题名称,话题数量,话题消息类型等信息
rosbag info <bagname>
# 3 bag播放
rosbag play <bagname>  # 回放指定bag
rosbag play * # 回放当前目录下所有bag
rosbag play -s n <bagname> # 从指定时间(n = 指定时间s)开始回放bag
rosbag play -s n -u m <bagname> # 从指定时间(n = 开始时间s)开始播放指定时间(m = 指定播放时间s)的bag
rosbag play -r n <bagname> # 按指定倍率(n = 倍率)回放bag
rosbag play <topic_name1>:=<topic_name2> # 某个话题重命名播放
# 4 回放不成功,提示 reindex ,则:
rosbag reindex  <bagname>

(3) rostopic echo --noarr to view the detailed information of the lidar data (such as frame_id)
Use rostopic echo / lidar topic name to view the data returned by the lidar, and nothing can be displayed except the number. If you want to view the frame_id and other information of the lidar data, just add the –noarr parameter to exclude the array information in the topic data.

rostopic echo --noarr /velodyne_points

(4) Visualize the bag through the rqt_bag command

rqt_bag <bagname>

Guess you like

Origin blog.csdn.net/zardforever123/article/details/130510145