我最近在学习激光雷达SLAM。我安装了ubuntu22.04并且根据博主鱼香ros的一键安装了ros2 humble版本。为了运行lego loam,我在github上找到了博主鱼香ros改写的lego loam humble版,并且我已经成功编译。但是rviz中并没有轨迹,于是我下载了原作者的bag文件并将其转换成了.bd3文件,但仍然没有轨迹。第一个终端窗口:lei@leiguoguo:~/ros2_ws$ ros2 launch lego_loam_sr run.launch.py [INFO] [launch]: All log files can be found below /home/lei/.ros/log/2025-06-17-10-36-39-658661-leiguoguo-7646 [INFO] [launch]: Default logging verbosity is set to INFO [INFO] [lego_loam_sr-1]: process started with pid [7647] [INFO] [static_transform_publisher-2]: process started with pid [7649] [INFO] [static_transform_publisher-3]: process started with pid [7651] [INFO] [static_transform_publisher-4]: process started with pid [7653] [INFO] [rviz2-5]: process started with pid [7655] [static_transform_publisher-4] RCUTILS_CONSOLE_STDOUT_LINE_BUFFERED is now ignored. Please set RCUTILS_LOGGING_USE_STDOUT and RCUTILS_LOGGING_BUFFERED_STREAM to control the stream and the buffering of log messages. [static_transform_publisher-3] RCUTILS_CONSOLE_STDOUT_LINE_BUFFERED is now ignored. Please set RCUTILS_LOGGING_USE_STDOUT and RCUTILS_LOGGING_BUFFERED_STREAM to control the stream and the buffering of log messages. [static_transform_publisher-2] RCUTILS_CONSOLE_STDOUT_LINE_BUFFERED is now ignored. Please set RCUTILS_LOGGING_USE_STDOUT and RCUTILS_LOGGING_BUFFERED_STREAM to control the stream and the buffering of log messages. [static_transform_publisher-3] [WARN] [1750127799.715366258] []: Old-style arguments are deprecated; see --help for new-style arguments [static_transform_publisher-4] [WARN] [1750127799.715367461] []: Old-style arguments are deprecated; see --help for new-style arguments [static_transform_publisher-2] [WARN] [1750127799.715368389] []: Old-style arguments are deprecated; see --help for new-style arguments [rviz2-5] RCUTILS_CONSOLE_STDOUT_LINE_BUFFERED is now ignored. Please set RCUTILS_LOGGING_USE_STDOUT and RCUTILS_LOGGING_BUFFERED_STREAM to control the stream and the buffering of log messages. [rviz2-5] Warning: Ignoring XDG_SESSION_TYPE=wayland on Gnome. Use QT_QPA_PLATFORM=wayland to run on Wayland anyway. [lego_loam_sr-1] RCUTILS_CONSOLE_STDOUT_LINE_BUFFERED is now ignored. Please set RCUTILS_LOGGING_USE_STDOUT and RCUTILS_LOGGING_BUFFERED_STREAM to control the stream and the buffering of log messages. [static_transform_publisher-3] [INFO] [1750127799.736069007] [base_link_to_camera]: Spinning until stopped - publishing transform [static_transform_publisher-3] translation: ('0.000000', '0.000000', '0.000000') [static_transform_publisher-3] rotation: ('-0.499999', '-0.500000', '-0.500000', '0.500001') [static_transform_publisher-3] from 'camera' to 'base_link' [static_transform_publisher-4] [INFO] [1750127799.736074443] [velodyne_to_base_link]: Spinning until stopped - publishing transform [static_transform_publisher-4] translation: ('0.000000', '0.000000', '0.000000') [static_transform_publisher-4] rotation: ('0.000000', '0.000000', '0.000000', '1.000000') [static_transform_publisher-4] from 'base_link' to 'velodyne' [static_transform_publisher-2] [INFO] [1750127799.736076789] [camera_init_to_map]: Spinning until stopped - publishing transform [static_transform_publisher-2] translation: ('0.000000', '0.000000', '0.000000') [static_transform_publisher-2] rotation: ('0.500000', '0.499999', '0.500000', '0.500001') [static_transform_publisher-2] from 'map' to 'camera_init' [lego_loam_sr-1] [INFO] [1750127799.756201716] [image_projection]: ----> Started. [lego_loam_sr-1] [INFO] [1750127799.756278719] [feature_association]: ----> Started. [lego_loam_sr-1] [INFO] [1750127799.756287725] [map_optimization]: ----> Started. [lego_loam_sr-1] [INFO] [1750127799.756294112] [transform_fusion]: ----> Started. [rviz2-5] [INFO] [1750127801.783291447] [rviz2]: Stereo is NOT SUPPORTED [rviz2-5] [INFO] [1750127801.783409655] [rviz2]: OpenGl version: 4.6 (GLSL 4.6) [rviz2-5] [INFO] [1750127801.796149614] [rviz2]: Stereo is NOT SUPPORTED ros2 launch lego_loam /home/lei/ros2_ws/src/LeGO-LOAM-ROS2/LeGO-LOAM/launch/run.launch.py [INFO] [rviz2-5]: process has finished cleanly [pid 7655] 第二个终端创窗口:lei@leiguoguo:~/ros2_ws$ source /opt/ros/humble/setup.bash lei@leiguoguo:~/ros2_ws$ source ~/ros2_ws/install/setup.bash lei@leiguoguo:~/ros2_ws$ ros2 bag play /home/lei/ros2_bag [INFO] [1750127971.316237348] [rosbag2_storage]: Opened database '/home/lei/ros2_bag/ros2_bag.db3' for READ_ONLY. [INFO] [1750127971.316356460] [rosbag2_player]: Set rate to 1 [WARN] [1750127971.319173825] [rosbag2_player]: Ignoring a topic '/rosout', reason: Something went wrong loading the typesupport library for message type rosgraph_msgs/Log. Library could not be found.. [WARN] [1750127971.319306206] [rosbag2_player]: Ignoring a topic '/rosout_agg', reason: Something went wrong loading the typesupport library for message type rosgraph_msgs/Log. Library could not be found.. [INFO] [1750127971.328125593] [rosbag2_player]: Adding keyboard callbacks. [INFO] [1750127971.328146451] [rosbag2_player]: Press SPACE for Pause/Resume [INFO] [1750127971.328154723] [rosbag2_player]: Press CURSOR_RIGHT for Play Next Message [INFO] [1750127971.328161427] [rosbag2_player]: Press CURSOR_UP for Increase Rate 10% [INFO] [1750127971.328167456] [rosbag2_player]: Press CURSOR_DOWN for Decrease Rate 10% [INFO] [1750127971.328443036] [rosbag2_storage]: Opened database '/home/lei/ros2_bag/ros2_bag.db3' for READ_ONLY. 第三个终端窗口:lei@leiguoguo:~/ros2_ws$ sudo apt update [sudo] lei 的密码: 命中:1 http://mirrors.huaweicloud.com/repository/ubuntu jammy InRelease 获取:2 http://mirrors.tuna.tsinghua.edu.cn/ros2/ubuntu jammy InRelease [4,682 B] 命中:4 https://mirrors.tuna.tsinghua.edu.cn/docker-ce/linux/ubuntu jammy InRelease 命中:3 https://packages.microsoft.com/repos/code stable InRelease 命中:5 http://mirrors.huaweicloud.com/repository/ubuntu jammy-updates InRelease 命中:6 http://mirrors.huaweicloud.com/repository/ubuntu jammy-backports InRelease 命中:7 http://mirrors.huaweicloud.com/repository/ubuntu jammy-security InRelease 已下载 4,682 B,耗时 7秒 (653 B/s) 正在读取软件包列表... 完成 正在分析软件包的依赖关系树... 完成 正在读取状态信息... 完成 有 268 个软件包可以升级。请执行 ‘apt list --upgradable’ 来查看它们。 lei@leiguoguo:~/ros2_ws$ cd .. lei@leiguoguo:~$ sudo apt install --reinstall ros-humble-rosgraph-msgs 正在读取软件包列表... 完成 正在分析软件包的依赖关系树... 完成 正在读取状态信息... 完成 升级了 0 个软件包,新安装了 0 个软件包,重新安装了 1 个软件包,要卸载 0 个软件包,有 268 个软件包未被升级。 需要下载 36.2 kB 的归档。 解压缩后会消耗 0 B 的额外空间。 获取:1 http://mirrors.tuna.tsinghua.edu.cn/ros2/ubuntu jammy/main amd64 ros-humble-rosgraph-msgs amd64 1.2.1-1jammy.20250607.025930 [36.2 kB] 已下载 36.2 kB,耗时 1秒 (39.1 kB/s) (正在读取数据库 ... 系统当前共安装有 262567 个文件和目录。) 准备解压 .../ros-humble-rosgraph-msgs_1.2.1-1jammy.20250607.025930_amd64.deb ... 正在解压 ros-humble-rosgraph-msgs (1.2.1-1jammy.20250607.025930) 并覆盖 (1.2.1-1jammy.20250607.025930) ... 正在设置 ros-humble-rosgraph-msgs (1.2.1-1jammy.20250607.025930) ... 正在处理用于 libc-bin (2.35-0ubuntu3.8) 的触发器 ...
时间: 2025-08-01 19:35:55 浏览: 15
<think>我们正在解决两个问题:1.在ROS2Humble环境下运行lego_loam时,rviz中没有轨迹。2.rosbag播放过程中出现关于rosgraph_msgs/Log类型支持库缺失的警告。首先,我们需要明确这两个问题可能的原因。###问题1:rviz中没有轨迹在运行lego_loam时,rviz中看不到轨迹,可能的原因包括:-轨迹发布的topic没有被正确订阅。-轨迹消息类型不支持或未正确安装。-lego_loam节点没有正确发布轨迹。###问题2:rosgraph_msgs/Log类型支持库缺失的警告这个警告表明在播放rosbag时,rosbag2_player无法加载rosgraph_msgs/Log的类型支持库。可能的原因:-`rosgraph_msgs`包未安装或未正确安装。-环境变量未正确设置,导致动态库加载失败。-rosbag2在播放时没有找到对应的类型支持。由于lego_loam原本是为ROS1设计的,我们在ROS2中使用可能需要借助桥接(bridge)或者已经有人将其移植到ROS2。因此,我们假设你正在使用一个已经移植到ROS2的lego_loam版本(例如,https://github.com/facontidavide/LeGO-LOAM-BOR或类似项目)。###解决方案####步骤1:确保安装必要的ROS2包首先,确保安装了`rosgraph_msgs`,因为它是ROS2的核心消息包之一。在ROS2Humble中,它应该已经随基础安装一起安装了。但为了确保,可以运行:```bashsudoaptinstallros-humble-rosgraph-msgs```####步骤2:检查环境变量确保你的工作空间已经正确构建,并且环境变量已经设置。在运行任何节点之前,执行:```bashsource/opt/ros/humble/setup.bashsource<your_workspace>/install/setup.bash```####步骤3:解决rosgraph_msgs/Log类型支持问题如果警告仍然存在,可能是因为rosbag2在播放时没有正确加载类型支持。尝试以下方法:-明确包含`/rosout`topic进行播放。但通常`/rosout`是系统topic,可能会被自动记录。我们更关心的是类型支持库的加载。-检查类型支持库是否存在。在ROS2中,消息的类型支持库位于`/opt/ros/humble/lib`下,例如`librosgraph_msgs__rosidl_typesupport_cpp.so`。确保这些文件存在。-如果使用自己编译的`rosgraph_msgs`,请确保已经正确编译并安装到工作空间中。####步骤4:解决rviz中无轨迹的问题在rviz中显示轨迹,通常需要添加一个`Path`显示类型,并订阅相应的轨迹topic(例如`/trajectory`或`/path`)。请按照以下步骤检查:1.确保lego_loam节点正在发布轨迹。使用以下命令查看topic列表:```bashros2topiclist```查找类似`/trajectory`或`/path`的topic。2.如果存在轨迹topic,使用以下命令查看是否有数据发布:```bashros2topicecho/trajectory--no-arr```如果没有任何输出,说明lego_loam节点没有发布轨迹数据。3.在rviz中,点击`Add`按钮,选择`Path`,然后在`Path`的`Topic`栏中输入轨迹topic的名称。4.如果轨迹topic的消息类型是ROS1的类型(例如`nav_msgs/Path`),那么你需要使用`ros1_bridge`将其桥接到ROS2。因为lego_loam可能是ROS1节点,而rviz是ROS2的。确保你已经启动了相应的桥接。5.如果你使用的是已经移植到ROS2的lego_loam,那么它应该发布ROS2的`nav_msgs/msg/Path`消息。在rviz中,确保你选择的消息类型是`nav_msgs/msg/Path`。####步骤5:运行lego_loam和rosbag在播放rosbag时,确保使用正确的参数。例如,播放bag文件:```bashros2bagplay<bag_file>```如果遇到类型支持问题,可以尝试重新记录bag文件,并确保记录时包含了`/rosout`和所需的轨迹topic。####步骤6:重新编译工作空间如果进行了代码修改或安装了新的依赖,重新编译工作空间:```bashcolconbuild--symlink-install```###示例:在rviz中添加Path显示1.启动rviz:```bashros2runrviz2rviz2```2.点击`Add`按钮,选择`Bytopic`,找到轨迹topic(例如`/trajectory`),选择`Path`并点击`OK`。3.设置`FixedFrame`为轨迹的参考系(例如`map`或`odom`)。###处理警告的额外建议如果仍然遇到`rosgraph_msgs/Log`类型支持的问题,可以尝试以下方法:-检查`LD_LIBRARY_PATH`是否包含ROS2的库路径:```bashecho$LD_LIBRARY_PATH```应该包含`/opt/ros/humble/lib`。-尝试显式加载类型支持库,但通常这是自动完成的。-如果问题持续,考虑重新安装ROS2Humble的基础包。###相关问题1.如何在ROS2中桥接ROS1的topic?2.如何调试ROS2中rviz不显示消息的问题?3.如何解决ROS2rosbag2播放时的类型支持错误?</think>### 解决 ROS2 Humble 环境下 lego_loam 的轨迹显示和类型支持问题
#### 一、解决 rviz 无轨迹问题(核心步骤)
1. **检查轨迹发布状态**
```bash
# 查看轨迹话题是否存在
ros2 topic list | grep path
# 检查轨迹数据发布(替换实际话题名)
ros2 topic echo /lego_loam/trajectory
```
2. **验证坐标系设置**
```bash
# 检查TF树完整性
ros2 run tf2_tools view_frames
```
- 在生成的 `frames.pdf` 中确认 `map->odom->base_link` 的坐标系链完整
- 在 rviz 中设置 `Fixed Frame` 为 `map` 坐标系
3. **添加 Path 显示**
```bash
# 在 rviz 中:
Add > By Topic > 选择 /lego_loam/trajectory > Path
```
- 设置 `Color` 为醒目颜色(如红色)
- 确认 `Buffer` 值 > 100(保留足够轨迹点)
4. **检查节点配置**
修改 lego_loam 启动文件(示例):
```xml
<!-- 确保发布轨迹的配置存在 -->
<node pkg="lego_loam" exec="transformMaintenance" output="screen">
<param name="publish_trajectory" value="true"/> <!-- 关键参数 -->
</node>
```
#### 二、解决 rosgraph_msgs/Log 类型支持缺失问题
1. **安装缺失的核心消息包**
```bash
sudo apt install ros-humble-rosgraph-msgs
```
2. **重建类型支持库**
```bash
# 重新生成消息类型支持
ros2 run rosidl_typesupport_c rosidl_typesupport_c --generate
# 验证类型支持
ros2 interface show rosgraph_msgs/msg/Log
```
应显示类似输出:
```plaintext
std_msgs/Header header
uint8 level
string name
string msg
...
```
3. **显式加载类型库(临时方案)**
```bash
export LD_LIBRARY_PATH=/opt/ros/humble/lib:$LD_LIBRARY_PATH
ros2 bag play your_bag.db3 --remap /rosout:=/rosout_ignored
```
4. **永久修复包依赖**
在 `package.xml` 中添加:
```xml
<depend>rosgraph_msgs</depend>
```
重新编译:
```bash
colcon build --symlink-install
source install/setup.bash
```
#### 三、完整验证流程
1. **启动 lego_loam**
```bash
ros2 launch lego_loam run.launch.py
```
2. **播放 bag 文件**
```bash
ros2 bag play your_bag.db3 \
--topics /points_raw /imu/data \
--remap /rosout:=/rosout_ignored
```
3. **rviz 显示检查**
```bash
ros2 run rviz2 rviz2 -d src/LeGO-LOAM-ROS2/rviz/lego_loam.rviz
```
- 确认 `Path` 显示已启用
- 检查 `TF` 显示无断裂
> **注意**:lego_loam 作为 ROS1 移植项目,需确保使用兼容 ROS2 的分支(如 [facontidavide/LeGO-LOAM-BOR](https://github.com/facontidavide/LeGO-LOAM-BOR))[^1]。
#### 四、调试技巧
1. **检查类型注册**
```bash
ros2 topic info /rosout --verbose
```
应包含:
```plaintext
Type: rosgraph_msgs/msg/Log
```
2. **强制重新生成类型支持**
```bash
sudo rm -rf ~/.ros/rosidl_typesupport_c/*
ros2 daemon stop
```
3. **查看动态库加载**
```bash
ldd /opt/ros/humble/lib/rosbag2_player/ros2bag | grep rosgraph
```
应有类似输出:
```plaintext
librosgraph_msgs__rosidl_typesupport_c.so => /opt/ros/humble/lib/librosgraph_msgs__rosidl_typesupport_c.so
```
#### 五、备选方案
若问题持续,尝试:
```bash
# 完全重建工作空间
rm -rf build install log
colcon build --symlink-install
# 使用桥接方案(ROS1/ROS2混合环境)
ros2 run ros1_bridge dynamic_bridge --bridge-all-topics
```
---
阅读全文
相关推荐




















