ros笔记01--初次体验ros2
- 介绍
- 安装ros2
- 测试验证ros2
- 说明
介绍
机器人操作系统(ROS)是一组用于构建机器人应用程序的软件库和工具。从驱动程序和最先进的算法到强大的开发者工具,ROS拥有我们下一个机器人项目所需的开源工具。
当前ros已经应用到各类机器人项目开发中,对机器人技术感兴趣的小伙伴非常有必要了解下ros. 本文主要从ros2的安装和测试验证这个层面来了解和体验ros2.
安装ros2
- 安装基础工具和源
sudo apt install software-properties-common sudo add-apt-repository sudo apt update && sudo apt install curl -y sudo curl -sSL https://raw.githubusercontent.com/ros/rosdistro/master/ros.key -o /usr/share/keyrings/ros-archive-keyring.gpgecho "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/ros-archive-keyring.gpg] http://packages.ros.org/ros2/ubuntu $(. /etc/os-release && echo $UBUNTU_CODENAME) main" | sudo tee /etc/apt/sources.list.d/ros2.list > /dev/null
- 安装 ros-dev-tools
sudo apt update && sudo apt install ros-dev-tools
- 安装ros2
sudo apt update sudo apt upgrade sudo apt install ros-jazzy-desktop sudo apt install ros-jazzy-ros-base
测试验证ros2
- 设置环境
# Replace ".bash" with your shell if you're not using bash # Possible values are: setup.bash, setup.sh, setup.zsh source /opt/ros/jazzy/setup.bash 可以通过 echo "source /opt/ros/jazzy/setup.bash" >>~/.bashrc 将其添加到环境变量中
- 运行demo_nodes talker/listener example
运行 C++ talker $ source /opt/ros/jazzy/setup.bash $ ros2 run demo_nodes_cpp talker 输出 [INFO] [1719704645.577174401] [talker]: Publishing: 'Hello World: 1' [INFO] [1719704646.577120788] [talker]: Publishing: 'Hello World: 2' ... 运行 Python listener $ source /opt/ros/jazzy/setup.bash $ ros2 run demo_nodes_py listener 输出 [INFO] [1719704676.604044603] [listener]: I heard: [Hello World: 32] [INFO] [1719704677.580123802] [listener]: I heard: [Hello World: 33] ...
- 运行小海龟案例
$ ros2 run turtlesim turtlesim_node
让小海龟跑起来
$ ros2 run turtlesim turtle_teleop_key
按左右键可以控制海龟方向,上下键移动海龟, 移动后的海龟如下
说明
系统:
ubuntu24.04 Desktop
ros2 jazzy
参考文档:
Ubuntu-Install-Debians.html
古月居 ros2课程