1. ROS2优点
语言独立性
ROS2支持多种语言,包括Python和C++。ROS2的设计目标之一就是提供语言独立性,这意味着ROS2框架可以很容易地在任何现代编程语言中实现。除了Python和C++之外,ROS2还支持Lisp、Java、Lua等语言。可以根据需求,选择合适的语言来开发ROS2应用程序。
2. 发行版测试
2.1 ROS2 Iron Official Installation:ros2/examples无法正常编译
部分输出信息如下:
...
---
Finished <<< examples_rclpy_minimal_service [10.4s]
Finished <<< examples_rclcpp_minimal_service [20.2s]
Finished <<< examples_rclcpp_minimal_client [20.7s]
Finished <<< examples_rclcpp_async_client [21.2s]
Finished <<< examples_rclcpp_multithreaded_executor [20.3s]
--- stderr: examples_rclpy_pointcloud_publisher
C:\Python38\lib\site-packages\setuptools\command\easy_install.py:156: EasyInstallDeprecationWarning: easy_install command is deprecated. Use build and pip and other standards-based tools.
warnings.warn(
C:\Python38\lib\site-packages\setuptools\command\install.py:34: SetuptoolsDeprecationWarning: setup.py install is deprecated. Use build and pip and other standards-based tools.
warnings.warn(
---
Finished <<< examples_rclpy_pointcloud_publisher [5.86s]
--- stderr: launch_testing_examples
C:\Python38\lib\site-packages\setuptools\command\easy_install.py:156: EasyInstallDeprecationWarning: easy_install command is deprecated. Use build and pip and other standards-based tools.
warnings.warn(
C:\Python38\lib\site-packages\setuptools\command\install.py:34: SetuptoolsDeprecationWarning: setup.py install is deprecated. Use build and pip and other standards-based tools.
warnings.warn(
---
Finished <<< launch_testing_examples [5.11s]
Finished <<< examples_rclcpp_minimal_timer [25.4s]
Finished <<< examples_rclcpp_minimal_action_server [27.4s]
Finished <<< examples_rclcpp_cbg_executor [36.9s]
Finished <<< examples_rclcpp_minimal_composition [37.6s]
Finished <<< examples_rclcpp_minimal_action_client [39.6s]
Finished <<< examples_rclcpp_minimal_publisher [47.0s]
--- stderr: examples_rclcpp_minimal_subscriber
CMake Error at ament_cmake_symlink_install/ament_cmake_symlink_install.cmake:267 (message):
ament_cmake_symlink_install_targets() can't find
'D:/dev/ros2_ws/build/examples_rclcpp_minimal_subscriber/Release/wait_set_subscriber_library.lib'
Call Stack (most recent call first):
ament_cmake_symlink_install_targets_3_Release.cmake:1 (ament_cmake_symlink_install_targets)
ament_cmake_symlink_install/ament_cmake_symlink_install.cmake:323 (include)
cmake_install.cmake:36 (include)
---
Failed <<< examples_rclcpp_minimal_subscriber [1min 16s, exited with code 1]
Aborted <<< examples_rclcpp_wait_set [1min 23s]
Summary: 20 packages finished [1min 25s]
1 package failed: examples_rclcpp_minimal_subscriber
1 package aborted: examples_rclcpp_wait_set
11 packages had stderr output: examples_rclcpp_minimal_subscriber examples_rclpy_executors examples_rclpy_guard_conditions examples_rclpy_minimal_action_client examples_rclpy_minimal_action_server examples_rclpy_minimal_client examples_rclpy_minimal_publisher examples_rclpy_minimal_service examples_rclpy_minimal_subscriber examples_rclpy_pointcloud_publisher launch_testing_examples
WNDPROC return value cannot be converted to LRESULT
TypeError: WPARAM is simple, so must be an int object (got NoneType)
D:\dev\ros2_ws>
尽管存在错误,但是仍然要比RoboStack要好一些,因为RoboStack目前不支持Iron;
2.2 Ros2_windows_install: 在Win11上无法正常使用
使用 ros2_windows_install 安装ROS2,无法自动安装ROS2-Iro所需的python3.8,无法正确地安装ROS2及其所需的环境,相关问题请参见#ros2_windows_install/issues/1。
3. 安装ROS2环境
3.1 环境要求:需使用Win10
Note
之前我们使用的是RoboStack提供的ros-humble,不过在进行教程的时候,我们遇到了一些问题(“无法使用colon正确编译”),而ros-humble开发者一直没有进行回复,所以我们决定转向官方提供的ROS2版本。
- python = 3.8.3
3.2 测试
3.2.1 测试turtlesim程序
测试是否安装了turtlesim
包
ros2 pkg executables turtlesim
3.3 卸载ROS2-iron [doc]
4. 从源码安装 ros2-package
(1)Cloning代码
git clone https://github.com/ros/package_name.git -b ros2
5. 常见技术
5.1 Fast DDS Discovery Server:用于减少 discovery-related network traffic
6. Tutorials学习笔记
7. 基本概念
6.1 Build
【Build system】ament:针对于ROS2的构建流程规范
5.2 Launch
Top-level launch file:一般就是 ros2 launch
命令后面指定的文件
6. 常见术语
frame:坐标系
7. 基本工作流
7.1 Sourcing setup
call C:\dev\ros2_iron\local_setup.bat
mamba activate ros_env
此命令包含了【Sourcing ROS2】的操作,它是一种在终端运行的命令,用于设置ROS2的环境变量,这些变量使得ROS2能够找到和使用其包和功能。
5.2 Installing project
Windows
call install/setup.bat
对应于Linux系统中的命令
source install/setup.bash
8. 目录结构说明
工作空间
src/
:源代码目录;其中包含所有的ROS2包(Packages)。每个包通常都有自己的目录结构,包括源代码、头文件、配置文件、启动文件(launch files)等。build/
目录:编译过程的输出目录;当你运行colcon build
命令时,所有编译生成的文件(例如库文件)都会存放在这里。install/
目录:所有安装(Install)的文件目录;通常包括可执行文件、库文件、配置文件、启动文件等。log/
目录:编译和运行过程中生成的日志文件目录;这些日志文件对于调试问题非常有用。
包(package)
ros_package_name/ # ROS包的根目录
├── ros_package_name/ # 同名源代码目录(Python)
├── src/ # 源代码文件(C++等)
├── include/ # C++头文件
├── msg/ # 自定义消息类型定义文件
├── srv/ # 自定义服务类型定义文件
├── action/ # 自定义动作类型定义文件(仅在ROS 2和ROS 1的某些版本中)
├── launch/ # 启动(launch)文件,用于启动节点和设置参数
├── config/ # 配置文件,通常用于ROS参数和动态重配置
├── CMakeLists.txt # CMake构建脚本
└── package.xml # 包描述文件,包含依赖和元信息
9. 常见工具
3.1 Rqt(ROS Qt):ROS的图形化管理器
Rqt包含了多种插件,可以用来查看和交互ROS系统的各个部分;
7. 基础概念
4.1 执行单元
1.1.1 Executable——执行程序
executable表示针对某个目标的程序执行流程,一个executable可以启动多个node;
1.1.2 Node——“进程”
node其实就是进程的意思;
ROS2允许同时启动两个相同的node,(我试过可以启动两个turtlesim_node),
然后列出当前运行的node,可以看到两个turtlesim同时存在:
/teleop_turtle
/turtlesim
/turtlesim
1.1.3 Action:“对应一个Client和一个Server”
Note
可以使用ros2 action info action_name
来查看action对应的Client和Server的名称。
1.2 信息通信
1.2.1 Topic——“一对多”
1.2.2 Service——“一对一”
1.2.3 Msg——“结构体”的定义
- 有点像C语言中的struct
- msg使用的是YAML语法
8. 教程学习
请参阅《ROS 2 Documentation - Tutorials》的学习笔记
9. 编译错误调试步骤
I. 查看错误输出
colcon build
命令会在终端中输出错误和警告信息。
II. 检查日志文件
分析
有时终端窗口可能没有显示具体的错误信息,例如:
这里就需要去查看colcon build
在log
目录下生成的日志文件;
Note:
当包编译失败时,会在当前工作空间的log
目录下生成与该包名称同名的文件夹,其中包含编译过程中错误的详细日志信息。
调试
查看每一个日志文件并分析;
10. Troubleshooting
(1)在终端执行命令后,终端好像“卡住了”,提示符一直在闪烁但没有任何输出
原因1:命令内部的操作需要管理员权限,从而无法执行
可以尝试【以管理员身份】运行终端,再次尝试执行命令;
11. 备注
11.1 Parameter Server可以使用命令动态的配置参数
可以看看下面的代码图示: