机器人操作系统ROS—ROS2探索

简单点说,ROS2与ROS最大的区别就是:

  • 去掉了master改为节点自动发现(支持多机器人控制);
  • 数据分发从TCPROS/UDPROS改为DDS(支持QoS);
  • 增加了windows、Mac、RTOS支持;
  • 性能(ROS2尚未稳定,总体性能目前暂无明显优势);

ROS1/ROS2架构图对比

ROS1/ROS2订阅/发布模型对比

安装ROS2

ROS2可以和ROS1共存在同一台电脑上(通过.bashrc控制用哪个),安装方法和ROS1类似:

参考:Installing ROS 2 Dashing via Debian Packages (Foxy需要Ubuntu20,Eloquent支持时间太短,Ubuntu18.04还是选Dashing发行版)

# 设置local
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

# 添加 sources.list
sudo apt update && sudo apt install curl gnupg2 lsb-release
curl -s https://raw.githubusercontent.com/ros/rosdistro/master/ros.asc | sudo apt-key add -
sudo sh -c 'echo "deb [arch=$(dpkg --print-architecture)] http://packages.ros.org/ros2/ubuntu $(lsb_release -cs) main" > /etc/apt/sources.list.d/ros2-latest.list'

# 安装ros2 dashing
sudo apt update
sudo apt install ros-dashing-desktop
echo "source /opt/ros/dashing/setup.bash" >> ~/.bashrc
source ~/.bashrc
sudo apt install -y python3-argcomplete ros-dashing-ros1-bridge python3-colcon-common-extensions


# 测试demo
mkdir -p ~/ros2_ws/src
cd ~/ros2_ws/src
git clone https://github.com/ros2/demos.git
cd ~/ros2_ws
colcon build   #ros2不用catkin_make改用colcon了
source install/setup.bash
ros2 run demo_nodes_cpp talker #源码参考~/ros2_ws/src/demos/demo_nodes_cpp   [INFO] [talker]: Publishing: 'Hello World: 1'   [INFO] [talker]: Publishing: 'Hello World: 2' [INFO] [talker]: Publishing: 'Hello World: 3' ros2 run demo_nodes_py listener #源码参考~/ros2_ws/src/demos/demo_nodes_py [INFO] [listener]: I heard: [Hello World: 1] [INFO] [listener]: I heard: [Hello World: 2] [INFO] [listener]: I heard: [Hello World: 3]
# 创建功能包 #ros2 pkg create learning_ros2

SLAM建图与导航仿真测试

安装gazebo、turtlebot3仿真:

# 安装gazebo
curl -sSL http://get.gazebosim.org | sh

# 下载turtlebot3源码(后边学习和gazebo models用) cd ~/project git clone https://github.com/ROBOTIS-GIT/turtlebot3 -b dashing-devel #-b选择dashing-devel的分支 git clone https://github.com/ROBOTIS-GIT/turtlebot3_msgs -b dashing-devel git clone https://github.com/ROBOTIS-GIT/turtlebot3_simulations -b dashing-devel # 安装turtlebot3及依赖 (源码https://github.com/ROBOTIS-GIT/turtlebot3*) sudo apt install ros-dashing-turtlebot3* ros-dashing-gazebo-* ros-dashing-cartographer* ros-dashing-navigation2 ros-dashing-nav2-* python3-vcstool ros-dashing-lifecycle* ros-dashing-composition* # 配置 echo "export TURTLEBOT3_MODEL=burger" >> ~/.bashrc source ~/.bashrc
# 复制turtlebot3模型到gazebo目录 mkdir ~/.gazebo/models cp -r ~/ros2_ws/src/turtlebot3_gazebo/models/* ~/.gazebo/models/

建图&导航仿真测试:

# 打开第一个终端,运行gazebo环境
ros2 launch turtlebot3_gazebo turtlebot3_world.launch.py

# 打开第二个终端,使用Cartographer进行建图
ros2 launch turtlebot3_cartographer cartographer.launch.py use_sim_time:=True

# 打开第三个终端运行键盘控制节点(w/a/s/d)
ros2 run turtlebot3_teleop teleop_keyboard

# 然后你就能愉快的控制仿真turtlebot3在仿真环境里建图了

# 保存地图
mkdir ~/ros2_ws/map
ros2 run nav2_map_server map_saver -f ~/ros2_ws/map/test
ll ~/ros2_ws/map/
    -rw-r--r-- 1 work work 41220 Jun 19 18:51 test.pgm
    -rw-r--r-- 1 work work   145 Jun 19 18:51 test.yaml

# 关闭cartographer和键盘程序,打开navigation2导航程序
ros2 launch turtlebot3_navigation2 navigation2.launch.py use_sim_time:=True  map:=/home/work/ros2_ws/map/test.yaml

#之后和ROS1中的操作一致,先使用2D Pose Estimate对机器人的位置进行初始化,之后就可以用2D New Goal指定目标进行导航了。

参考:

ROS2初体验之SLAM与导航仿真

[译] Fast RTPS与Cyclone DDS与OpenSplice DDS对比测试

发表评论

电子邮件地址不会被公开。