《ROS 2 Documentation - Tutorials》的学习笔记

1. 机器配置

Win11测试配置

System Version
OS Win11
ROS RoboStack/ros-humble

Win10测试配置

System Version
OS Win10
ROS Iron Official

2. 基本工作流(Windows)

(1)Build package

colcon build --merge-install --packages-select package_name

(2)Source the setup files

call install/setup.bat

3. 启动环境:Anaconda Powershell Prompt

Note
RoboStack-ros-humble目前不支持Powershell。

启动conda环境:

conda activate ros_env

4. 常见工具和命令

  • /turtle1/cmd_vel topic:控制小乌龟的移动,其消息包含线性速度和角速度

Go back to the drive root

cd\

Navigate to ros2_ws directory

cd \ros2_ws

Navigate to launch_ws directory

cd "D:\launch\launch_ws"

Source the setup files

call install/setup.bat

Enter the folder & source setup

cd \ros2_ws && call install/setup.bat

Using updated curl

set PATH=D:\Professional\ROS2\curl-8.2.1_5-win64-mingw\bin;%PATH%

Driving turtle

ros2 run turtlesim turtle_teleop_key

常见命令解释

curl -sk https://raw.githubusercontent.com/ros2/examples/iron/rclcpp/topics/minimal_publisher/member_function.cpp -o publisher_member_function.cpp

  1. curl是一个命令行工具,用于从服务器获取或发送数据;
  2. -s选项表示静默模式,不显示进度条或错误消息。

Note:所以在调试时,需要去掉 -s选项。

5. 常见术语

4.1 RPY: Roll, Pitch, Yaw

NewBing:
Roll, Pitch, Yaw是三个英语单词,它们分别表示绕x轴、y轴和z轴的旋转角度。
Roll是指绕x轴的旋转,也就是翻滚。例如,飞机在空中做一个侧翻动作,就是改变了它的roll角度;
Pitch是指绕y轴的旋转,也就是俯仰。例如,飞机在起飞或降落时,调整了它的pitch角度;
Yaw是指绕z轴的旋转,也就是偏航。例如,飞机在转向时,改变了它的yaw角度。

这里我们可以想象右手手心向上拖着一架飞机,向前手指伸展是X轴正方向,右手大拇指是Y轴正方向;

6. Beginner: CLI tools

6.1 Recording and playing back data

7. Beginner: Client libraries

Using colcon to build packages

进行到 [Build the workspace] 时遇到问题,无法正常进行构建,部分输出信息如下:

# Win10, Iron Official:
...
---
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>

Note:我们发现这个问题在Win11&10系统上都会出现,这一点说明ROS2官方对Windows的支持十分有限;我们在ros2/examples的github上咨询了开发者是否会修复这个问题,不过目前没有人回复;

Writing a simple publisher and subscriber (C++)

3 Write the subscriber node

Enter the source folder
cd "D:\ros2_ws\src\cpp_pubsub\src"

Using parameters in a class:“launch方式无法运行”

【3.2 Change via a launch file】说到使用launch方式启动节点

ros2 launch python_parameters python_parameters_launch.py

不过,运行后并没有正常看到输出,终端显示如下:

D:\ros2_ws>ros2 launch python_parameters python_parameters_launch.py
[INFO] [launch]: All log files can be found below C:\Users\songyuc\.ros\log\2023-09-01-20-51-44-132293-DESKTOP-OB91EPG-8740
[INFO] [launch]: Default logging verbosity is set to INFO
Launching node...
[INFO] [minimal_param_node.EXE-1]: process started with pid [8680]
_
# 光标在闪烁,但是终端就卡在这里了,过了10分钟左右,也一直没有输出任何信息...

而教程里面说到应该会输出类似“[INFO] [custom_minimal_param_node]: Hello earth!”的信息……
总结:此教程无法复现;

8. Intermediate

5.1 Managing Dependencies with rosdep:“rosdep不支持Windows系统”

目前rosdep没有对Windows系统提供支持;

5.2 Launch

Using event handlers

在启动示例程序时,直接执行

ros2 launch launch_tutorial example_event_handlers_launch.py turtlesim_ns:=‘turtlesim3’ use_provided_red:=‘True’ new_background_r:=200

CMD终端会报错:

D:\launch\launch_ws>call install/setup.bat
“[rti_connext_dds_cmake_module][warning] RTI Connext DDS environment script not found (\resource\scripts\rtisetenv_x64Win64VS2017.bat). RTI Connext DDS will not be available at runtime, unless you already configured PATH manually.”
“[rti_connext_dds_cmake_module][warning] RTI Connext DDS environment script not found (\resource\scripts\rtisetenv_x64Win64VS2017.bat). RTI Connext DDS will not be available at runtime, unless you already configured PATH manually.”

D:\launch\launch_ws>ros2 launch launch_tutorial example_event_handlers_launch.py turtlesim_ns:=‘turtlesim3’ use_provided_red:=‘True’ new_background_r:=200
[INFO] [launch]: All log files can be found below C:\Users\songyuc.ros\log\2023-09-09-22-27-39-222206-DESKTOP-OB91EPG-5328
[INFO] [launch]: Default logging verbosity is set to INFO
[ERROR] [launch_ros.actions.node]: Error while expanding or validating node name or namespace for ‘package=turtlesim, executable=turtlesim_node, name=sim, namespace=’:
[ERROR] [launch]: Caught exception in launch (see debug for traceback): Invalid namespace: namespace must not contain characters other than alphanumerics, ‘_’, or ‘/’:
‘/‘turtlesim3’’
^

咨询了一下ChatGPT

ChatGPT:错误信息表明turtlesim_ns参数的值'turtlesim3'是无效的。这可能是因为你使用了错误的引号。在Windows命令行中,应该使用双引号而不是单引号。

修改后适用于Win10的命令如下:

ros2 launch launch_tutorial example_event_handlers_launch.py turtlesim_ns:="turtlesim3" use_provided_red:="True" new_background_r:=200

Managing large projects::“没有提供完整代码,无法复现(2023.9.30)”

I. 进入工作目录
cd "D:\launch\launch_ws"
II. Build type ament_python
ros2 pkg create --build-type ament_python --node-name my_node launch_tutorial --license Apache-2.0
III. Project files
[2.3 Using wildcards in YAML files]:“没有提供turtlesim_world_3_launch.py完整代码”

这里我们截图来说明这个问题,
《ROS 2 Documentation - Tutorials》的学习笔记_第1张图片
可以看到,这里用了一个模糊的描述词“similar”,我们想请问一下,什么叫做“similar”呢?
这里我们咨询了Claude和ChatGPT,两位教授竟然给出了两份差异明显的代码,我们不太懂官方团队竟然还说什么“What is in the tutorial is the complete project code.”;我们感觉 Ros2_documentation 的团队在编写教程时缺乏审慎的思考,which is frustrating.

编译目录下所有包代码(Win)
colcon build --merge-install
引入本地项目设置
call install/setup.bat

5.3 Tf2

5.3.1 Introducing tf2 (revised)

I. 进入工作目录
cd "D:\ros2_ws"
II. Installing the tf2 demo
Entering src\
Cloning source repo
Returning to workspace root
Building all packages
colcon build --merge-install

接下来使用Rviz查看turble的移动;
这时,如果直接运行教程给出的命令ros2 run rviz2 rviz2 -d $(ros2 pkg prefix --share turtle_tf2_py)/rviz/turtle_rviz.rviz则会有问题:

D:\ros2_ws>ros2 run rviz2 rviz2 -d $(ros2 pkg prefix --share turtle_tf2_py)/rviz/turtle_rviz.rviz
Unknown option 'share'.
[ros2run]: Process exited with failure 1

我们咨询了 Poe-GPT4:

  • “根据你提供的错误信息,看起来问题可能在于你在Windows系统上运行这个命令,而这个命令中的$(…)语法是Unix shell(比如bash或者zsh)中的命令替换语法,Windows的命令行解析器可能不能正确处理这种语法。
  • 解决这个问题,你需要找到正确的路径,然后直接在命令行中指定。”

因此,我们首先需要获得turtle_tf2_py包的绝对路径;

Getting path of turtle_tf2_py
ros2 pkg prefix turtle_tf2_py
Launchinging the demo
ros2 run rviz2 rviz2 -d D:\ros2_ws\install\rviz\turtle_rviz.rviz
Setting [Fixed Frame]

可以按照以下步骤更改Fixed Frame:

  1. 在rviz界面上找到左侧的"Global Options"部分。
  2. 在"Fixed Frame"的下拉菜单中,选择world;
Adding “TF” Display:
  1. 在rviz的左侧面板中找到"Displays"部分。
  2. 点击"Add"按钮,这将打开一个新的窗口。
  3. 在新窗口中,选择"TF"作为你希望添加的Display类型,然后点击"OK"。

5.3.2 Writing a static broadcaster (C++) (revised)

Downloading source cpp-file
D:\Professional\ROS2\curl-8.2.1_5-win64-mingw\bin\curl.exe -k https://raw.githubusercontent.com/ros/geometry_tutorials/ros2/turtle_tf2_cpp/src/static_turtle_tf2_broadcaster.cpp -o static_turtle_tf2_broadcaster.cpp

5.3.3 Writing a broadcaster (Python) (revised)

Running turtle_tf2_demo_launch.py

在运行turtle_tf2_demo_launch.py启动文件时,如果以普通方式开启终端会提示:

D:\ros2_ws>ros2 launch learning_tf2_py turtle_tf2_demo_launch.py
C:\dev\ros2_iron\Lib\site-packages\launch\logging\__init__.py:149: UserWarning: Cannot create a
symlink to latest log directory: [WinError 1314] 客户端没有所需的特权。: 'C:\\Users\\songyuc\\.ros\\log
\\2023-10-02-16-49-31-697632-DESKTOP-OB91EPG-15356' -> 'C:\\Users\\songyuc\\.ros\\log\\latest'

  warnings.warn(
# ...

这里为了消除这个警告,我们以管理员身份运行新的终端来运行launch文件;

Note:
这里launch文件会启动一个turtlesim程序,不过由于这里使用管理员权限启动的turtlesim程序,所以接下来如果要用turtle_teleop_key控制turtle的移动,其控制台也需要以管理员身份运行,否则会出现“键盘按键而turtle没有任何反应”的情况。

5.3.4 Writing a broadcaster (C++) (revised)

Entering src\
cd "D:\ros2_ws\src\learning_tf2_cpp\src"
Downloading source cpp-file
curl -k https://raw.githubusercontent.com/ros/geometry_tutorials/ros2/turtle_tf2_cpp/src/turtle_tf2_broadcaster.cpp -o turtle_tf2_broadcaster.cpp

5.3.5 Writing a listener (Python) (revised)

Downloading source py-file
curl -k https://raw.githubusercontent.com/ros/geometry_tutorials/ros2/turtle_tf2_py/turtle_tf2_py/turtle_tf2_listener.py -o turtle_tf2_listener.py

5.3.6 Writing a listener (C++) (revised)

Entering src\
cd "D:\ros2_ws\src\learning_tf2_cpp\src"

5.3.7 Using time (Python):“教程代码跟下载代码不一致”

在【1 Update the listener node】提到,需要使用如下代码:
《ROS 2 Documentation - Tutorials》的学习笔记_第2张图片
不过,之前在下载的代码中,并没有【now】这个变量;
于是,我们认为这是教程没有及时更新的问题,于是在[ros2/ros2_documentation]上提出了issue,目前在等待官方团队的回复;

5.3.8 Using time (C++) (revised)

Building package
colcon build --merge-install --packages-select learning_tf2_cpp

5.3.9 Traveling in time (Python) (revised)

(1) Entering workspace
cd "D:\ros2_ws"
(2) Building package
colcon build --merge-install --packages-select learning_tf2_py
(3) Source the setup files
call install/setup.bat

5.3.10 Traveling in time (C++) (revised)

(1)Building package
colcon build --merge-install --packages-select learning_tf2_cpp

5.3.11 Debugging:“编译错误”

在复现到【1 Setting and starting the example】时,教程提到:

Don’t forget to add the turtle_tf2_listener_debug executable to the CMakeLists.txt and build the package.

不过,在修改了CMakeLists.txt之后,我们进行了Building,不过出现如下错误:

D:\ros2_ws>colcon build --merge-install --packages-select learning_tf2_cpp
Starting >>> learning_tf2_cpp
Failed   <<< learning_tf2_cpp [9.11s, exited with code 1]

Summary: 0 packages finished [9.41s]
  1 package failed: learning_tf2_cpp
WNDPROC return value cannot be converted to LRESULT
TypeError: WPARAM is simple, so must be an int object (got NoneType)

于是,我们在【ros2/ros2_documentation】上提出了issue,暂时没有得到回复;

5.3.12 Using stamped datatypes with tf2_ros::MessageFilter (revised)

Downloading file turtle_tf2_message_filter.cpp
curl -sk https://raw.githubusercontent.com/ros/geometry_tutorials/ros2/turtle_tf2_cpp/src/turtle_tf2_message_filter.cpp -o turtle_tf2_message_filter.cpp

Note:此项目会用到turtle_tf2_py包,在Windows系统中需要手动进行编译。

Rebuilding the package
colcon build --merge-install --packages-select turtle_tf2_py learning_tf2_cpp
Skip echoing the topic

因为执行“ros2 topic echo /turtle3/turtle_point_stamped”命令之后,后面的 ros2-run命令就无法输出信息;

Note:
由于Win10和Linux在系统级别的进程和线程同步机制方面存在差异,这可能影响ROS2中消息传递的时序和同步。具体来说,当在Win10上执行ros2-topic-echo和ros2-run命令时,可能由于系统的同步或调度机制的差异性,导致ros2的消息传递通道被阻塞,无法正常进行通信,从而导致在终端中没有输出。这种问题可能是与操作系统底层的进程调度、消息队列处理或网络通信机制有关。

实验日志

教程在【3 Run】中提到需要分别执行“ros2 topic echo /turtle3/turtle_point_stamped”和“ros2 run learning_tf2_cpp turtle_tf2_message_filter”这两个命令;不过,我们发现一个奇怪的现象:

  • 如果现在一个终端A中执行“ros2 topic echo /turtle3/turtle_point_stamped”,再在另一个终端B中执行“ros2 run learning_tf2_cpp turtle_tf2_message_filter”命令,之后会发现,终端B中的提示符处于闪烁状态,但是一直没有任何输出;
  • 如果不执行“ros2 topic echo /turtle3/turtle_point_stamped”,而直接在终端C中执行“ros2 run learning_tf2_cpp turtle_tf2_message_filter”命令,则可以看到终端C输出的信息与该网页教程中的描述一致。
  • 而且一旦出现某个ros2命令阻塞,那么,会造成整个环境的通讯阻塞,只有重启系统才能恢复;

Troubleshooting of tf2 & turtle-sim

(1)使用launch文件运行启动多个turtle的项目时,只出现一只turtle
原因一:设置了“HTTP_PROXY / HTTPS_PROXY”环境变量,导致ROS2的通讯出现问题

尽量避免在运行ROS2项目时,设置“HTTP_PROXY / HTTPS_PROXY”环境变量;

(2)[ERROR] [launch]: Caught exception in launch (see debug for traceback): “package ‘turtle_tf2_py’ not found, searching: [‘D:\\ros2_ws\\install’, ‘C:\\dev\\ros2_iron’]”

需要编译geometry_tutorials仓库;

5.4 URDF

5.4.1 Building a visual robot model from scratch:执行“ros2 launch urdf_tutorial display.launch.py model:=ros2 pkg prefix --share urdf_tutorial/urdf/01-myfirst.urdf”命令报错

Checking the joint_state_publisher package
ros2 pkg list | findstr joint_state_publisher

如果已安装joint_state_publisher包,命令将返回包的名称;如果未安装,命令不会返回任何内容。

Cloning urdf_tutorial
git clone https://github.com/ros/urdf_tutorial.git -b ros2
Cloning urdf_launch
git clone https://github.com/ros/urdf_launch.git -b main
Entering workspace
cd "D:\second_ros2_ws"
Building all packages
colcon build --merge-install
Source the setup files
call install/setup.bat
实验日志
(1)Bard:“Make sure that the URDF file is in the correct directory. The URDF file should be in the share/urdf_tutorial/urdf directory of your ROS 2 installation.”

Bard提到 URDF file 应该是在【ROS 2 installation】目录中,但是这一点很奇怪,在项目开发的时候,如何保证将 URDF file 放在ROS2安装目录中呢?这一点是很奇怪的,无法进行确认。

(2)通义千问:“如果你已经确定了文件存在并且路径也正确,那么这里可能存在一个bug,即该教程没有考虑到Windows系统的文件路径格式差异。为了调试这个问题,请在你的display.launch.py文件中添加调试代码”

如果你已经确定了文件存在并且路径也正确,那么这里可能存在一个bug,即该教程没有考虑到Windows系统的文件路径格式差异。为了调试这个问题,请在你的display.launch.py文件中添加以下两行代码:

from rosidl_runtime_cpp import get_message_type_support_handle

print(get_message_type_support_handle('urdf_msgs/msg/Urdf').fullname)

然后重新运行ros2 launch urdf_tutorial display.launch.py model:=D:/second_ros2_ws/src/urdf_tutorial/urdf/01-myfirst.urdf并查看打印出的内容。这可能会告诉你Urdf消息类型支持是否被正确加载。如果返回的是一个非None值,则说明Urdf消息类型支持已经被正确加载。如果没有返回任何内容,那么你需要确认你已经安装了所有的依赖项并进行了构建。如果是None,则可能是未正确安装或配置Urdf的消息类型支持。

我感觉,通义的意思是教程给出的源代码有问题;我们觉得,这部分还是需要ROS2的官方团队进行调试,我们已经在【ros2/ros2_documentation】的GitHub主页上提出了issue,不过目前没有得到回复;

(3)文心大模型3.5:“看起来你在运行ROS2命令时遇到了一些问题。错误信息显示ros2: error: unrecognized arguments: --share urdf_tutorial’/urdf/01-myfirst.urdf,这表明ros2命令不认可–share参数;请确认你正在使用的ROS2版本是否支持–share参数。你可以通过运行ros2 --help来查看所有可用的命令行选项。”

看起来你在运行ROS2命令时遇到了一些问题。错误信息显示ros2: error: unrecognized arguments: --share urdf_tutorial'/urdf/01-myfirst.urdf,这表明ros2命令不认可--share参数。
首先,请确认你正在使用的ROS2版本是否支持--share参数。你可以通过运行ros2 --help来查看所有可用的命令行选项。
其次,对于指定模型路径的问题,你应该使用绝对路径而不是相对路径。在你的情况下,你的模型文件01-myfirst.urdf位于D:\second_ros2_ws\urdf_tutorial\urdf目录下,所以你应该直接使用这个路径,而不是通过ros2 pkg prefix --share获取。
所以,你应该这样指定模型路径:

ros2 launch urdf_tutorial display.launch.py model:=D:\second_ros2_ws\urdf_tutorial\urdf\01-myfirst.urdf

如果仍然有问题,可能是因为环境变量设置不正确或缺失。根据你提供的错误信息,RTI Connext DDS环境脚本没有找到,这可能会导致一些问题。你需要确保已经正确安装了RTI Connext DDS,并且其相关环境变量已经设置好。具体的安装和设置步骤可能会根据你使用的具体版本和操作系统有所不同。

于是,我们尝试使用ros2 --help查看参数信息,在终端获得如下提示信息:

D:\second_ros2_ws\src\urdf_tutorial\urdf>ros2 --help
lttng module version >=2.10.7 required, found None
usage: ros2 [-h] [--use-python-default-buffering]
            Call `ros2 <command> -h` for more detailed usage. ...

ros2 is an extensible command-line tool for ROS 2.

optional arguments:
  -h, --help            show this help message and exit
  --use-python-default-buffering
                        Do not force line buffering in stdout and instead use the python default
                        buffering, which might be affected by PYTHONUNBUFFERED/-u and depends on
                        whatever stdout is interactive or not

Commands:
  action     Various action related sub-commands
  bag        Various rosbag related sub-commands
  component  Various component related sub-commands
  daemon     Various daemon related sub-commands
  doctor     Check ROS setup and other potential issues
  interface  Show information about ROS interfaces
  launch     Run a launch file
  lifecycle  Various lifecycle related sub-commands
  multicast  Various multicast related sub-commands
  node       Various node related sub-commands
  param      Various param related sub-commands
  pkg        Various package related sub-commands
  run        Run a package specific executable
  security   Various security related sub-commands
  service    Various service related sub-commands
  test       Run a ROS2 launch test
  topic      Various topic related sub-commands
  trace      Trace ROS nodes to get information on their execution
  wtf        Use `wtf` as alias to `doctor`

  Call `ros2 <command> -h` for more detailed usage.

可以看到当前安装的ros2版本并不支持--share参数,我们继续咨询了文心大模型3.5,

你的问题与代码和程序运行相关。
从你给出的错误信息来看,你遇到的问题是lttng module version >=2.10.7 required, found None。这表明你的系统需要一个名为lttng的模块,且其版本应大于或等于2.10.7,但当前没有找到这个模块。
LTTng(Linux Trace Toolkit Next Generation)是一个强大的、低开销的、跨平台的开源系统、内核和应用程序的跟踪工具集。你可能需要在你的系统中安装这个工具来满足ROS 2的要求。
对于Windows系统,你可以尝试使用以下命令来安装LTTng:

  1. 首先,你需要打开“控制面板”并搜索“程序和功能”,然后点击“启用或关闭Windows功能”。
  2. 在“Windows功能”窗口中,找到并勾选“适用于Linux的Windows子系统”,然后点击“确定”。
  3. 重新启动电脑后,打开命令提示符并输入以下命令来安装LTTng:
choco install lttng-tools

请注意,这需要你的电脑已经安装了Chocolatey(一个Windows的包管理器)。如果没有,你需要首先安装它。
安装完成后,你应该能够运行ros2命令了。如果仍然有问题,你可能需要检查你的ROS 2和LTTng的配置是否正确。

终端在输出信息提到“lttng module version >=2.10.7 required, found None”,文心大模型3.5也说到要安装LTTng,但是,他还说要打开“适用于Linux的Windows子系统”,这很奇怪,为什么ROS2需要依赖于WSL呢,无法理解;

5.4.2 Building a movable robot model

Visualizing and controlling model
(1)跟上一个教程类似,无法运行

当前教程给出命令ros2 launch urdf_tutorial display.launch.py model:=urdf/06-flexible.urdf来启动可视化程序;不过跟上一个教程的情况类似,无法正常运行;

(2)360智脑:“根据你提供的终端提示信息,我们可以看到D:\second_ros2_ws\src\urdf_tutorial\urdf目录中存在多个urdf文件,但是ros2 launch urdf_tutorial display.launch.py模型指定的urdf/06-flexible.urdf文件是否存在以及是否位于正确的位置并未明确说明。因此,无法确定urdf文件是否存在以及是否位于正确的位置。”

我们向其发送了终端中的提示信息:

D:\second_ros2_ws\src\urdf_tutorial\urdf>dir
 驱动器 D 中的卷是 文档
 卷的序列号是 A009-7878

 D:\second_ros2_ws\src\urdf_tutorial\urdf 的目录

2023/10/27  15:45              .
2023/10/27  15:45              ..
2023/10/27  15:45               208 01-myfirst.urdf
2023/10/27  15:45               484 02-multipleshapes.urdf
2023/10/27  15:45               561 03-origins.urdf
2023/10/27  15:45             1,156 04-materials.urdf
2023/10/27  15:45             6,146 05-visual.urdf
2023/10/27  15:45             6,616 06-flexible.urdf
2023/10/27  15:45            11,397 07-physics.urdf
2023/10/27  15:45             7,054 08-macroed.urdf.xacro
               8 个文件         33,622 字节
               2 个目录 467,697,455,104 可用字节

D:\second_ros2_ws\src\urdf_tutorial\urdf>ros2 launch urdf_tutorial display.launch.py model:=urdf/06-flexible.urdf
[INFO] [launch]: All log files can be found below C:\Users\songyuc\.ros\log\2023-11-04-18-18-08-875486-DESKTOP-OB91EPG-26588
[INFO] [launch]: Default logging verbosity is set to INFO
[ERROR] [launch]: Caught exception in launch (see debug for traceback): file not found: [WinError 2] 系 统找不到指定的文件。

而360智脑却表示:

根据你提供的终端提示信息,我们可以看到D:\second_ros2_ws\src\urdf_tutorial\urdf目录中存在多个urdf文件,但是ros2 launch urdf_tutorial display.launch.py模型指定的urdf/06-flexible.urdf文件是否存在以及是否位于正确的位置并未明确说明。因此,无法确定urdf文件是否存在以及是否位于正确的位置。

提示信息中已经明确显示urdf/06-flexible.urdf文件位于D:\second_ros2_ws\src\urdf_tutorial\urdf目录中,而它却说“未明确说明”,感觉360智脑的逻辑能力 is very poor;

5.4.3 Using URDF with robot_state_publisher (revised)

[6 Install the package]
Source the setup files
call install/setup.bat
不清楚这个教程是否适合于Windows系统

我们已经在【ros2/ros2_documentation】上提出了issue,不过暂时没有获得回复;

执行“colcon build --symlink-install --packages-select urdf_tutorial_r2d2”命令报错

在Win10上编译出现错误,相关提示信息如下:

D:\second_ros2_ws>colcon build --symlink-install --packages-select urdf_tutorial_r2d2
Starting >>> urdf_tutorial_r2d2
--- stderr: urdf_tutorial_r2d2
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 <<< urdf_tutorial_r2d2 [3.30s]

Summary: 1 package finished [3.56s]
  1 package had stderr output: urdf_tutorial_r2d2
WNDPROC return value cannot be converted to LRESULT
TypeError: WPARAM is simple, so must be an int object (got NoneType)

于是等待开发者对issue进行回复;

rviz2
rviz2 -d "D:\second_ros2_ws\install\urdf_tutorial_r2d2\share\urdf_tutorial_r2d2\r2d2.rviz"

9. Intermediate

8.1 Enabling topic statistics (C++) (revised)

2 Build and run

cd "D:\ros2_ws"

3 Observe published statistic data

Source the setup files
cd "D:\ros2_ws" && call install/setup.bat

Note:只有执行sourcing操作后再运行ros2 topic list,才会看到教程里面展示的四个topics信息。

10. Advanced

10.1 Using Fast DDS Discovery Server as discovery protocol [community-contributed]:未提供Windows平台脚本

10.1.1 Launch listener node

set ROS_DISCOVERY_SERVER=127.0.0.1:11811

10.1.2 Compare Fast DDS Discovery Server with Simple Discovery Protocol

此节中提到,

Tutorial: Run the bash script with the path to setup.bash file to source ROS 2 as an argument.

.bash文件无法直接在CMD终端中运行;
此外,教程中也没有提供Windows平台脚本;
我们已经提出issue#4037,不过尚未收到回复;

10.2 Unlocking the potential of Fast DDS middleware [community-contributed] (revised)

9.2.1 Create the node with the publishers

(1)Build the package
ros2 pkg create --build-type ament_cmake --dependencies rclcpp std_msgs -- sync_async_node_example_cpp

9.2.2 Build the package

colcon build --merge-install --packages-select sync_async_node_example_cpp

9.2.3 Set environment variables

SET FASTRTPS_DEFAULT_PROFILES_FILE=D:\ros2_ws\src\sync_async_node_example_cpp\SyncAsync.xml

9.2.2 Source the setup files

call install/setup.bat

9.2.3 Run publishers nodes

ros2 run sync_async_node_example_cpp SyncAsyncWriter

10.3 Reading from a bag file (C++) (revised)

【3 Build and run】

【Revised】:这里提到的“setup bag”,实际上是“subset bag”。

Note:此教程的开头提到subset bag 来自于教程《Recording and playing back data》。

执行以下命令输出bag中记录的turtle的坐标:

ros2 run bag_reading_cpp simple_bag_reader "D:\ros2_ws\bag_files\subset"

执行完毕后,命令提示符会闪烁,程序不会自动结束,需要手动Ctrl+C进行结束。

10.4 Simulators

10.4.1 Webots

Installation (Windows)

该教程说到,

[1 Install WSL2]: On Windows, WSL (Windows Subsystem for Linux) improves the user experience with ROS 2 compared to native Windows installation, as it runs on a Linux platform. Install WSL with an Ubuntu version which is compatible with your ROS distribution and upgrade to WSL2 following the official Microsoft tutorial.

但是我们的ROS2是原生安装在Windows系统上的,所以我们不会通过WSL2进行安装;
值得注意的是,该教程并没有提供如何在Windows系统上natively安装webots_ros2 package,对此,我们在【cyberbotics/webots_ros2】的GitHub主页上提出issue询问:“webots_ros2是否支持原生Windows安装”;目前还没有收到回复;

10.4.2 Gazebo

关于Gazebo是否原生支持Windows,我们在【ros2/ros2_documentation】上提出了issue;
Gazebo的开发者在issue中回复:

Addisu Z. Taddese: Running Gazebo on Windows is not fully supported yet (see gazebosim/gz-sim#2089)

也就是说,Gazebo目前不支持在Windows上原生运行;

10.5 Security

10.5.1 Setting up security:Windows上需要降级cryptography的python包才能运行

除非“downgrading the python module to “cryptography==38.0.4””,否则在【2. Generate a keystore】中运行命令ros2 security create_keystore demo_keystore时,Windows-PS终端就会出现如下错误:

D:\dev\ros\sros2_demo>ros2 security create_keystore demo_keystore
Traceback (most recent call last):
  File "C:\dev\ros2_iron\Scripts\ros2-script.py", line 33, in <module>
    sys.exit(load_entry_point('ros2cli==0.25.2', 'console_scripts', 'ros2')())
  File "C:\dev\ros2_iron\Lib\site-packages\ros2cli\cli.py", line 89, in main
    rc = extension.main(parser=parser, args=args)
  File "C:\dev\ros2_iron\Lib\site-packages\sros2\command\security.py", line 36, in main
    return extension.main(args=args)
  File "C:\dev\ros2_iron\Lib\site-packages\sros2\verb\create_keystore.py", line 38, in main
    sros2.keystore.create_keystore(args.ROOT)
  File "C:\dev\ros2_iron\Lib\site-packages\sros2\keystore\_keystore.py", line 82, in create_keystore
    _utilities.create_smime_signed_file(
  File "C:\dev\ros2_iron\Lib\site-packages\sros2\_utilities.py", line 67, in create_smime_signed_file
    f.write(_sign_bytes(cert, private_key, content))
  File "C:\dev\ros2_iron\Lib\site-packages\sros2\_utilities.py", line 140, in _sign_bytes
    flags = SSLBinding.lib.PKCS7_DETACHED
AttributeError: module 'lib' has no attribute 'PKCS7_DETACHED'

此问题已经在[ros2/sros2#285]中进行了讨论,目前还需要进一步的解决方案。

10.5.2 Understanding the security keystore:依赖上一教程【Setting up security】的复现结果

此教程在开头提到:
“Before proceeding ensure you have completed the Setting up security tutorial.”
但是 Setting up security tutorial 目前在Windows上无法正常复现。

此教程在"validate the S/MIME signature of the governance file"时也会出现如下错误:

D:\dev\ros\sros2_demo\demo_keystore\private>openssl smime -verify -in governance.p7s -CAfile …/public/permissions_ca.cert.pem
Can’t open governance.p7s for reading, No such file or directory
16928:error:02001002:system library:fopen:No such file or directory:crypto\bio\bss_file.c:69:fopen(‘governance.p7s’,‘r’)
16928:error:2006D080:BIO routines:BIO_new_file:no such file:crypto\bio\bss_file.c:76:

经查看工作空间发现,目前D:\dev\ros\sros2_demo\demo_keystore\private目录中没有governance.p7s文件;
于是,我们决定先等待教程【Setting up security】以确认其执行效果完成后,再复现此教程;

10.5.3 Ensuring security across machines:依赖基本教程【Setting up security】的复现结果

此教程在开头提到:
“Before proceeding ensure you have completed the Setting up security tutorial.”
但是 Setting up security tutorial 目前在Windows上无法正常复现。

10.5.4 Examining network traffic:目前不支持Windows

我们在【ros2/ros2_documentation】上针对此问题提出了issue,不过目前没有收到回复;

10.5.5 Setting access controls:依赖基本教程【Setting up security】的复现结果

此教程在开头提到:
“Before proceeding ensure you have completed the Setting up security tutorial.”
但是 Setting up security tutorial 目前在Windows上无法正常复现。

10.5.6 Deployment Guidelines:此教程依赖于Docker的使用

Docker在Windows上是推荐使用 WSL 2 backend 后端,而我们目前的计划尚未包含对WSL2的支持;所以我们准备在需要进行Deployment部署测试的时候再来复现此教程;

11. Contributing to ROS 2 Documentation [doc]

11.1 Environment

查看python路径

Get-Command python | Select-Object -ExpandProperty Path
conda create --name ros_doc python=3.8.3

11.2 PR workflow

(1)Cloning the repo

git clone --branch iron https://github.com/songyuc/ros2_documentation.git

(2)Viewing the changes

make html

(3)Local test [doc]

make test

6.3 Source codes

6.3.1 Makefile

Set Python Based on the System
PYTHON := python3
ifeq ($(OS),Windows_NT)
    PYTHON := python
endif
BUILD      = $(PYTHON) -m sphinx

6.4 reStructuredText学习笔记

代码块

.. code-block::

    Here four spaces are used as the indent.

Note
在reStructuredText中,.. code-block:: 指令后的空行通常应该是完全空白的,不包含任何字符,包括空格。这是因为reStructuredText的解析器可能会将包含空格的“空行”视为内容的一部分,从而影响代码块的正确解析。在【ros2/ros2_documentation】的 [Test / build] 中也会引发报错。

Troubleshooting of doc codes

(1).. code-block:: console后面要加入空行

8. Troubleshooting

(1)“D:…\curl.exe … curl: (6) Could not resolve host: raw.githubusercontent.com”

在使用curl.exe下载文件时,遇到这样的问题:

D:\ros2_ws\src\learning_tf2_py\learning_tf2_py>D:\Professional\ROS2\curl-8.2.1_5-win64-mingw\bin\curl.exe -k
https://raw.githubusercontent.com/ros/geometry_tutorials/ros2/turtle_tf2_py/turtle_tf2_py/
static_turtle_tf2_broadcaster.py -o static_turtle_tf2_broadcaster.py
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0
  curl: (6) Could not resolve host: raw.githubusercontent.com

根据提示信息可知,终端目前无法正常连接raw.githubusercontent.com,感觉应该是GFW的原因,所以需要在终端中手动设置代理;

(2)输入命令ros2 run turtlesim turtle_teleop_key之后,在终端中使用方向键操作turtle没有反应

原因一:turtle-sim使用管理员模式开启的,当“turtle_teleop_key”没有使用管理员权限运行,则无法操作管理员模式的turtle-sim

所以,在使用管理员模式开启了turtle-sim之后,“turtle_teleop_key”对应的终端也需要以管理员身份运行才能正常使用方向键操作turtle;

你可能感兴趣的:(学习)