ROS2 是一个非常庞大和复杂的开源项目,ROS2 jazzy版本就有108个子项目(git仓库)组成。ROS2采用vcstool工具来管理仓库,vcstool是一个Python脚本,可以用来管理多个git仓库,通常与.repos
文件配合使用。
1.2. .repos
.repos
文件用于管理多个 Git 仓库,它是一个 YAML 格式的清单文件,用于批量定义仓库的克隆路径、URL、分支等信息。
【举例】:ros2.repos
的代码片段
1 2 3 4 5 6 7 8 9
| repositories: ament/ament_cmake: type: git url: https://github.com/ament/ament_cmake.git version: jazzy ament/ament_index: type: git url: https://github.com/ament/ament_index.git version: jazzy
|
vcstool工具是一个Python的库,在安装ROS2时,默认会安装此工具。可以通过以下命令来检查是否安装。
如果有显示对应的版本,则说明安装成功,否则表示未安装。
可以通过以下命令手动安装:
2. 创建工作空间并下载源码
2.1. 下载ros2.repos
文件
方法一:
1 2 3 4 5 6 7
| git clone git@github.com:ros2/ros2.git
git checkout jazzy
cd ros2 cat ros2.repos
|
方法二:
1 2 3 4 5 6 7
| mkdir -p ~/ros2/src cd ~/ros2
wget https://raw.githubusercontent.com/ros2/ros2/jazzy/ros2.repos
cat ros2.repos
|
2.2. 下载所有子仓库源码
1 2 3 4
| vcs import src < ros2.repos
vcs pull src
|
说明:如果仓库下载和更新失败,可能是Github访问受限或网络部稳定,可以使用外网VPN然后再尝试。
检查是否包含关键仓库:
1 2
| cd ~/ros2_ws/src ls -d ros2/rcl* ros2/rmw ros2/rosidl eProsima/Fast-DDS
|
3. ROS2源码目录结构
3.1. 完整目录结构
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121
| .ros2 └── src ├── ament │ ├── ament_cmake │ ├── ament_index │ ├── ament_lint │ ├── ament_package │ ├── google_benchmark_vendor │ ├── googletest │ └── uncrustify_vendor ├── eProsima │ ├── Fast-CDR │ ├── Fast-DDS │ └── foonathan_memory_vendor ├── eclipse-cyclonedds │ └── cyclonedds ├── eclipse-iceoryx │ └── iceoryx ├── gazebo-release │ ├── gz_cmake_vendor │ ├── gz_math_vendor │ └── gz_utils_vendor ├── osrf │ ├── osrf_pycommon │ └── osrf_testing_tools_cpp ├── ros │ ├── class_loader │ ├── kdl_parser │ ├── pluginlib │ ├── resource_retriever │ ├── robot_state_publisher │ ├── ros_environment │ ├── ros_tutorials │ ├── urdfdom │ └── urdfdom_headers ├── ros-perception │ ├── image_common │ ├── laser_geometry │ └── point_cloud_transport ├── ros-planning │ └── navigation_msgs ├── ros-tooling │ ├── keyboard_handler │ └── libstatistics_collector ├── ros-visualization │ ├── interactive_markers │ ├── python_qt_binding │ ├── qt_gui_core │ ├── rqt │ ├── rqt_action │ ├── rqt_bag │ ├── rqt_console │ ├── rqt_graph │ ├── rqt_msg │ ├── rqt_plot │ ├── rqt_publisher │ ├── rqt_py_console │ ├── rqt_reconfigure │ ├── rqt_service_caller │ ├── rqt_shell │ ├── rqt_srv │ ├── rqt_topic │ └── tango_icons_vendor └── ros2 ├── ament_cmake_ros ├── common_interfaces ├── console_bridge_vendor ├── demos ├── eigen3_cmake_module ├── example_interfaces ├── examples ├── geometry2 ├── launch ├── launch_ros ├── libyaml_vendor ├── message_filters ├── mimick_vendor ├── orocos_kdl_vendor ├── performance_test_fixture ├── pybind11_vendor ├── python_cmake_module ├── rcl ├── rcl_interfaces ├── rcl_logging ├── rclcpp ├── rclpy ├── rcpputils ├── rcutils ├── realtime_support ├── rmw ├── rmw_connextdds ├── rmw_cyclonedds ├── rmw_dds_common ├── rmw_fastrtps ├── rmw_implementation ├── ros2_tracing ├── ros2cli ├── ros2cli_common_extensions ├── ros_testing ├── rosbag2 ├── rosidl ├── rosidl_core ├── rosidl_dds ├── rosidl_defaults ├── rosidl_dynamic_typesupport ├── rosidl_dynamic_typesupport_fastrtps ├── rosidl_python ├── rosidl_runtime_py ├── rosidl_typesupport ├── rosidl_typesupport_fastrtps ├── rpyutils ├── rviz ├── spdlog_vendor ├── sros2 ├── system_tests ├── test_interface_files ├── tinyxml2_vendor ├── tlsf ├── unique_identifier_msgs ├── urdf └── yaml_cpp_vendor
|
3.2. 核心模块(子仓库)
仓库 |
描述 |
克隆命令 |
ros2/ros2 |
元仓库 |
git clone -b jazzy https://github.com/ros2/ros2.git |
ros2/rcl |
ROS Client Library(C语言实现层) |
git clone -b jazzy https://github.com/ros2/rcl.git |
ros2/rclcpp |
ROS Client Library(C++接口层) |
git clone -b jazzy https://github.com/ros2/rclcpp.git |
ros2/rclpy |
ROS Client Library(Python接口层) |
git clone -b jazzy https://github.com/ros2/rclpy.git |
ros2/rmw |
(通信)中间件接口 |
git clone -b jazzy https://github.com/ros2/rmw.git |
eProsima/Fast-DDS |
Fast-DDS实现库 |
git clone -b jazzy https://github.com/eProsima/Fast-DDS.git |
eclipse-cyclonedds/cyclonedds |
CyCloneDDS实现库 |
git clone -b jazzy https://github.com/eclipse-cyclonedds/cyclonedds.git |
ros2/rosidl |
ROS接口定义 |
git clone -b jazzy https://github.com/ros2/rosidl.git |
ros2/ros2cli |
命令行工具 |
git clone -b jazzy https://github.com/ros2/ros2cli.git |
说明: ros2/rosidl
负责统一管理ROS 2的接口定义(如.msg、.srv、.action),并通过代码生成工具将这些接口转换为多语言支持的代码(如C++、Python)和DDS兼容的IDL文件。
4. 其他操作
4.1. 编译源码
1 2 3 4
| cd ~/ros2
colcon build --symlink-install
|
4.2. 提取.repos文件
将当前的所有子仓库提取.repos
文件,方便多仓库管理及与其他项目成员协作。
1 2
| cd ~/ros2 vcs export src > my_ros2.repos
|
5. 参考文档
https://docs.ros.org/en/jazzy/Installation/Maintaining-a-Source-Checkout.html#download-the-new-source-code