ROS2
- 一.ROS2 IRON环境搭建
- 1.设置系统字符集为UTF-8
- 2.将RO2 apt 库添加到系统中
- 3.添加ROS2 GPG key
- 4.添加ROS 2 的软件源
- 安装开发工具
- 二.下载ROS2sh源代码
- 编译
一.ROS2 IRON环境搭建
虚拟机系统:Ubuntu22.04
虚拟机:VMware-player-full-16.2.5-20904516 (这个是非商用就可以免费使用的哦)
电脑系统:WIN10
以下操作都是在虚拟机下的Ubuntu22.04环境中。
详细步骤参考ROS2官网:
1.设置系统字符集为UTF-8
locale # check for UTF-8sudo apt update && sudo apt install locales
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-8locale # verify settings
2.将RO2 apt 库添加到系统中
sudo apt install software-properties-common
sudo add-apt-repository universe
3.添加ROS2 GPG key
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.gpg
4.添加ROS 2 的软件源
这个命令的作用是将 ROS 2 的软件源添加到/etc/apt/sources.list.d/ros2.list 文件中。这样系统就可以从这个源中获取 ROS 2 相关的软件包。
echo "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
安装开发工具
sudo apt update && sudo apt install -y \python3-flake8-docstrings \python3-pip \python3-pytest-cov \python3-flake8-blind-except \python3-flake8-builtins \python3-flake8-class-newline \python3-flake8-comprehensions \python3-flake8-deprecated \python3-flake8-import-order \python3-flake8-quotes \python3-pytest-repeat \python3-pytest-rerunfailures \ros-dev-tools
二.下载ROS2sh源代码
创建ros2_iron/src目录,并下载相关源码。
mkdir -p ~/ros2_iron/src
cd ~/ros2_iron
vcs import --input https://raw.githubusercontent.com/ros2/ros2/iron/ros2.repos src
这一步我尝试了很多方法,各种换源。但是因为电脑不能翻墙的原因,一直下失败。我的解决方法是在浏览器中访问
https://raw.githubusercontent.com/ros2/ros2/iron/ros2.repos
可以看到以下信息:
repositories:ament/ament_cmake:type: giturl: https://github.com/ament/ament_cmake.gitversion: ironament/ament_index:type: giturl: https://github.com/ament/ament_index.gitversion: ironament/ament_lint:type: giturl: https://github.com/ament/ament_lint.gitversion: ironament/ament_package:type: giturl: https://github.com/ament/ament_package.gitversion: ironament/google_benchmark_vendor:type: giturl: https://github.com/ament/google_benchmark_vendor.gitversion: ironament/googletest:type: giturl: https://github.com/ament/googletest.gitversion: ironament/uncrustify_vendor:type: giturl: https://github.com/ament/uncrustify_vendor.gitversion: ironeProsima/Fast-CDR:type: giturl: https://github.com/eProsima/Fast-CDR.gitversion: v1.0.27eProsima/Fast-DDS:type: giturl: https://github.com/eProsima/Fast-DDS.gitversion: 2.10.xeProsima/foonathan_memory_vendor:type: giturl: https://github.com/eProsima/foonathan_memory_vendor.gitversion: mastereclipse-cyclonedds/cyclonedds:type: giturl: https://github.com/eclipse-cyclonedds/cyclonedds.gitversion: releases/0.10.xeclipse-iceoryx/iceoryx:type: giturl: https://github.com/eclipse-iceoryx/iceoryx.gitversion: release_2.0gazebo-release/gz_cmake2_vendor:type: giturl: https://github.com/gazebo-release/gz_cmake2_vendor.gitversion: irongazebo-release/gz_math6_vendor:type: giturl: https://github.com/gazebo-release/gz_math6_vendor.gitversion: ironosrf/osrf_pycommon:type: giturl: https://github.com/osrf/osrf_pycommon.gitversion: masterosrf/osrf_testing_tools_cpp:type: giturl: https://github.com/osrf/osrf_testing_tools_cpp.gitversion: ironros-perception/image_common:type: giturl: https://github.com/ros-perception/image_common.gitversion: ironros-perception/laser_geometry:type: giturl: https://github.com/ros-perception/laser_geometry.gitversion: ironros-planning/navigation_msgs:type: giturl: https://github.com/ros-planning/navigation_msgs.gitversion: ironros-tooling/keyboard_handler:type: giturl: https://github.com/ros-tooling/keyboard_handler.gitversion: ironros-tooling/libstatistics_collector:type: giturl: https://github.com/ros-tooling/libstatistics_collector.gitversion: ironros-visualization/interactive_markers:type: giturl: https://github.com/ros-visualization/interactive_markers.gitversion: ironros-visualization/python_qt_binding:type: giturl: https://github.com/ros-visualization/python_qt_binding.gitversion: ironros-visualization/qt_gui_core:type: giturl: https://github.com/ros-visualization/qt_gui_core.gitversion: ironros-visualization/rqt:type: giturl: https://github.com/ros-visualization/rqt.gitversion: ironros-visualization/rqt_action:type: giturl: https://github.com/ros-visualization/rqt_action.gitversion: ironros-visualization/rqt_bag:type: giturl: https://github.com/ros-visualization/rqt_bag.gitversion: ironros-visualization/rqt_console:type: giturl: https://github.com/ros-visualization/rqt_console.gitversion: ironros-visualization/rqt_graph:type: giturl: https://github.com/ros-visualization/rqt_graph.gitversion: ironros-visualization/rqt_msg:type: giturl: https://github.com/ros-visualization/rqt_msg.gitversion: ironros-visualization/rqt_plot:type: giturl: https://github.com/ros-visualization/rqt_plot.gitversion: ironros-visualization/rqt_publisher:type: giturl: https://github.com/ros-visualization/rqt_publisher.gitversion: ironros-visualization/rqt_py_console:type: giturl: https://github.com/ros-visualization/rqt_py_console.gitversion: ironros-visualization/rqt_reconfigure:type: giturl: https://github.com/ros-visualization/rqt_reconfigure.gitversion: ironros-visualization/rqt_service_caller:type: giturl: https://github.com/ros-visualization/rqt_service_caller.gitversion: ironros-visualization/rqt_shell:type: giturl: https://github.com/ros-visualization/rqt_shell.gitversion: ironros-visualization/rqt_srv:type: giturl: https://github.com/ros-visualization/rqt_srv.gitversion: ironros-visualization/rqt_topic:type: giturl: https://github.com/ros-visualization/rqt_topic.gitversion: ironros-visualization/tango_icons_vendor:type: giturl: https://github.com/ros-visualization/tango_icons_vendor.gitversion: ironros/class_loader:type: giturl: https://github.com/ros/class_loader.gitversion: ironros/kdl_parser:type: giturl: https://github.com/ros/kdl_parser.gitversion: ironros/pluginlib:type: giturl: https://github.com/ros/pluginlib.gitversion: ironros/resource_retriever:type: giturl: https://github.com/ros/resource_retriever.gitversion: ironros/robot_state_publisher:type: giturl: https://github.com/ros/robot_state_publisher.gitversion: ironros/ros_environment:type: giturl: https://github.com/ros/ros_environment.gitversion: ironros/ros_tutorials:type: giturl: https://github.com/ros/ros_tutorials.gitversion: ironros/urdfdom:type: giturl: https://github.com/ros/urdfdom.gitversion: ironros/urdfdom_headers:type: giturl: https://github.com/ros/urdfdom_headers.gitversion: ironros2/ament_cmake_ros:type: giturl: https://github.com/ros2/ament_cmake_ros.gitversion: ironros2/common_interfaces:type: giturl: https://github.com/ros2/common_interfaces.gitversion: ironros2/console_bridge_vendor:type: giturl: https://github.com/ros2/console_bridge_vendor.gitversion: ironros2/demos:type: giturl: https://github.com/ros2/demos.gitversion: ironros2/eigen3_cmake_module:type: giturl: https://github.com/ros2/eigen3_cmake_module.gitversion: ironros2/example_interfaces:type: giturl: https://github.com/ros2/example_interfaces.gitversion: ironros2/examples:type: giturl: https://github.com/ros2/examples.gitversion: ironros2/geometry2:type: giturl: https://github.com/ros2/geometry2.gitversion: ironros2/launch:type: giturl: https://github.com/ros2/launch.gitversion: ironros2/launch_ros:type: giturl: https://github.com/ros2/launch_ros.gitversion: ironros2/libyaml_vendor:type: giturl: https://github.com/ros2/libyaml_vendor.gitversion: ironros2/message_filters:type: giturl: https://github.com/ros2/message_filters.gitversion: ironros2/mimick_vendor:type: giturl: https://github.com/ros2/mimick_vendor.gitversion: ironros2/orocos_kdl_vendor:type: giturl: https://github.com/ros2/orocos_kdl_vendor.gitversion: ironros2/performance_test_fixture:type: giturl: https://github.com/ros2/performance_test_fixture.gitversion: ironros2/pybind11_vendor:type: giturl: https://github.com/ros2/pybind11_vendor.gitversion: ironros2/python_cmake_module:type: giturl: https://github.com/ros2/python_cmake_module.gitversion: ironros2/rcl:type: giturl: https://github.com/ros2/rcl.gitversion: ironros2/rcl_interfaces:type: giturl: https://github.com/ros2/rcl_interfaces.gitversion: ironros2/rcl_logging:type: giturl: https://github.com/ros2/rcl_logging.gitversion: ironros2/rclcpp:type: giturl: https://github.com/ros2/rclcpp.gitversion: ironros2/rclpy:type: giturl: https://github.com/ros2/rclpy.gitversion: ironros2/rcpputils:type: giturl: https://github.com/ros2/rcpputils.gitversion: ironros2/rcutils:type: giturl: https://github.com/ros2/rcutils.gitversion: ironros2/realtime_support:type: giturl: https://github.com/ros2/realtime_support.gitversion: ironros2/rmw:type: giturl: https://github.com/ros2/rmw.gitversion: ironros2/rmw_connextdds:type: giturl: https://github.com/ros2/rmw_connextdds.gitversion: ironros2/rmw_cyclonedds:type: giturl: https://github.com/ros2/rmw_cyclonedds.gitversion: ironros2/rmw_dds_common:type: giturl: https://github.com/ros2/rmw_dds_common.gitversion: ironros2/rmw_fastrtps:type: giturl: https://github.com/ros2/rmw_fastrtps.gitversion: ironros2/rmw_implementation:type: giturl: https://github.com/ros2/rmw_implementation.gitversion: ironros2/ros2_tracing:type: giturl: https://github.com/ros2/ros2_tracing.gitversion: ironros2/ros2cli:type: giturl: https://github.com/ros2/ros2cli.gitversion: ironros2/ros2cli_common_extensions:type: giturl: https://github.com/ros2/ros2cli_common_extensions.gitversion: ironros2/ros_testing:type: giturl: https://github.com/ros2/ros_testing.gitversion: ironros2/rosbag2:type: giturl: https://github.com/ros2/rosbag2.gitversion: ironros2/rosidl:type: giturl: https://github.com/ros2/rosidl.gitversion: ironros2/rosidl_core:type: giturl: https://github.com/ros2/rosidl_core.gitversion: ironros2/rosidl_dds:type: giturl: https://github.com/ros2/rosidl_dds.gitversion: ironros2/rosidl_defaults:type: giturl: https://github.com/ros2/rosidl_defaults.gitversion: ironros2/rosidl_dynamic_typesupport:type: giturl: https://github.com/ros2/rosidl_dynamic_typesupportversion: ironros2/rosidl_dynamic_typesupport_fastrtps:type: giturl: https://github.com/ros2/rosidl_dynamic_typesupport_fastrtpsversion: ironros2/rosidl_python:type: giturl: https://github.com/ros2/rosidl_python.gitversion: ironros2/rosidl_runtime_py:type: giturl: https://github.com/ros2/rosidl_runtime_py.gitversion: ironros2/rosidl_typesupport:type: giturl: https://github.com/ros2/rosidl_typesupport.gitversion: ironros2/rosidl_typesupport_fastrtps:type: giturl: https://github.com/ros2/rosidl_typesupport_fastrtps.gitversion: ironros2/rpyutils:type: giturl: https://github.com/ros2/rpyutils.gitversion: ironros2/rviz:type: giturl: https://github.com/ros2/rviz.gitversion: ironros2/spdlog_vendor:type: giturl: https://github.com/ros2/spdlog_vendor.gitversion: ironros2/sros2:type: giturl: https://github.com/ros2/sros2.gitversion: ironros2/system_tests:type: giturl: https://github.com/ros2/system_tests.gitversion: ironros2/test_interface_files:type: giturl: https://github.com/ros2/test_interface_files.gitversion: ironros2/tinyxml2_vendor:type: giturl: https://github.com/ros2/tinyxml2_vendor.gitversion: ironros2/tinyxml_vendor:type: giturl: https://github.com/ros2/tinyxml_vendor.gitversion: ironros2/tlsf:type: giturl: https://github.com/ros2/tlsf.gitversion: ironros2/unique_identifier_msgs:type: giturl: https://github.com/ros2/unique_identifier_msgs.gitversion: ironros2/urdf:type: giturl: https://github.com/ros2/urdf.gitversion: ironros2/yaml_cpp_vendor:type: giturl: https://github.com/ros2/yaml_cpp_vendor.gitversion: iron
url对应的就是github上所在的源代码。把github上的这些源代码仓库转移到gitee上,这个gitee提供了这一部分的功能。
在ros2_iron路径下,用vim新建ros2.repos文件。
vim ros2.repos
vim 在normal模式下,输入"+p将https://raw.githubusercontent.com/ros2/ros2/iron/ros2.repos中的内容复制到本地(前提是已经复制到系统内存中了,才能使用这个命令)。用vim查找替换url地址。
:%s/https\/\/github.com\/\(.*\)\//gitee.com:makuswork\//g
这样本地中ros2.repos中的url中的内容全部修改成我自己的gitee仓库中了。我把地址改成了ssh的通信。下载源代码时就不用一直的输入帐号和密码了。保存关闭。
在ros2_iron路径下
vcs import --input ros2.repos src
编译
sudo apt upgrade
sudo rosdep init
rosdep update
rosdep install --from-paths src --ignore-src -y --skip-keys "fastcdr rti-connext-dds-6.0.1 urdfdom_headers"
colcon build --symlink-install
如果编译报错,EasyInstallDeprecationWarning,可以参考colcon build --symlink-install ,编译失败解决方法