ROS2之assert False, "Failed to find '// Generated: ' line"

本文介绍了解决在使用colcon build编译turtlesim2时遇到的错误的方法,涉及修改/rosidl_typesupport_opensplice_cpp/__init__.py文件的具体步骤,通过更新依赖路径和模板路径设置,确保编译过程顺利进行。

使用colcon build编译turtlesim2,可能会出现如下错误:

需要修改,/opt/ros/dashing/lib/python3.6/site-packages/rosidl_typesupport_opensplice_cpp/__init__.py

使用如下代码进行替换,2019-08-05。

# Copyright 2014-2018 Open Source Robotics Foundation, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import os
import subprocess

from rosidl_cmake import generate_files


def generate_dds_opensplice_cpp(
    pkg_name, dds_interface_files, dds_interface_base_path, deps, output_basepath, idl_pp
):
    include_dirs = [dds_interface_base_path]
    for dep in deps:
        # only take the first : for separation, as Windows follows with a C:\
        dep_parts = dep.split(':', 1)
        assert len(dep_parts) == 2, "The dependency '%s' must contain a double colon" % dep
        idl_path = dep_parts[1]
        idl_base_path = os.path.dirname(
            os.path.dirname(os.path.dirname(os.path.normpath(idl_path))))
        if idl_base_path not in include_dirs:
            include_dirs.append(idl_base_path)
    if 'OSPL_TMPL_PATH' in os.environ:
        include_dirs.append(os.environ['OSPL_TMPL_PATH'])

    for idl_file in dds_interface_files:
        assert os.path.exists(idl_file), 'Could not find IDL file: ' + idl_file

        # get two level of parent folders for idl file
        folder = os.path.dirname(idl_file)
        parent_folder = os.path.dirname(folder)
        output_path = os.path.join(
            output_basepath,
            os.path.basename(parent_folder),
            os.path.basename(folder))

        try:
            os.makedirs(output_path)
        except FileExistsError:
            pass

        # idlpp doesn't like long path arguments over 256 chars, get just the filename
        filename = os.path.basename(idl_file)

        cmd = [idl_pp]
        for include_dir in include_dirs:
            cmd += ['-I', include_dir]
        cmd += [
            '-S',
            '-l', 'cpp',
            '-N',
            '-d', output_path,
            '-o', 'maintain-include-namespace',
            filename
        ]
        if os.name == 'nt':
            cmd[-1:-1] = [
                '-P',
                'ROSIDL_TYPESUPPORT_OPENSPLICE_CPP_PUBLIC_%s,%s' % (
                    pkg_name,
                    '%s/msg/rosidl_typesupport_opensplice_cpp__visibility_control.h' % pkg_name)]

        subprocess.check_call(cmd, cwd=folder)

        # modify generated code to
        # remove path information of the building machine as well as timestamps
        msg_name = os.path.splitext(filename)[0]
        idl_path = os.path.join(
            pkg_name, os.path.basename(parent_folder), filename)
        h_filename = os.path.join(output_path, '%s.h' % msg_name)
        _modify(h_filename, msg_name, _replace_path_and_timestamp, idl_path=idl_path)
        cpp_filename = os.path.join(output_path, '%s.cpp' % msg_name)
        _modify(cpp_filename, msg_name, _replace_path_and_timestamp, idl_path=idl_path)
        dcps_h_filename = os.path.join(output_path, '%sDcps.h' % msg_name)
        _modify(dcps_h_filename, msg_name, _replace_path_and_timestamp, idl_path=idl_path)
        dcps_cpp_filename = os.path.join(output_path, '%sDcps.cpp' % msg_name)
        _modify(dcps_cpp_filename, msg_name, _replace_path_and_timestamp, idl_path=idl_path)

    return 0


def _modify(filename, msg_name, callback, idl_path=None):
    with open(filename, 'r') as h:
        lines = h.read().split('\n')
    modified = callback(lines, msg_name, idl_path=idl_path)
    if modified:
        with open(filename, 'w') as h:
            h.write('\n'.join(lines))


def _replace_path_and_timestamp(lines, msg_name, idl_path):
    found_source = False
    for i, line in enumerate(lines):
        if line.startswith('//  Source: '):
            assert not found_source, "More than one '// Source: ' line was found"
            found_source = True
            lines[i] = '//  Source: ' + idl_path
            continue
        if line.startswith('//  Generated: '):
            assert found_source, "No '// Source: ' line was found before"
            lines[i] = '//  Generated: timestamp removed to make the build reproducible'
            break
    return lines


def generate_typesupport_opensplice_cpp(arguments_file):
    mapping = {
       'idl__rosidl_typesupport_opensplice_cpp.hpp.em':  # noqa
           '%s__rosidl_typesupport_opensplice_cpp.hpp',
       'idl__dds_opensplice__type_support.cpp.em': 'dds_opensplice/%s__type_support.cpp',
    }

    generate_files(arguments_file, mapping)

https://github.com/ros2/rosidl_typesupport_opensplice/blob/master/rosidl_typesupport_opensplice_cpp/rosidl_typesupport_opensplice_cpp/__init__.py

具体原因分析参考:

1. https://github.com/ADLINK-IST/opensplice/issues/92

2. https://github.com/ros2/rosidl_typesupport_opensplice/pull/33

 

WARNING: disk usage in log directory [/home/sx/.ros/log] is over 1GB. It's recommended that you use the 'rosclean' command. started roslaunch server http://sx-NUC8i5BEH:34675/ SUMMARY ======== PARAMETERS * /common/imu_topic: /livox/imu * /common/lid_topic: /livox/lidar * /common/time_offset_lidar_to_imu: 0.0 * /common/time_sync_en: False * /cube_side_length: 1000.0 * /feature_extract_enable: False * /filter_size_map: 0.5 * /filter_size_surf: 0.5 * /mapping/acc_cov: 0.1 * /mapping/b_acc_cov: 0.0001 * /mapping/b_gyr_cov: 0.0001 * /mapping/det_range: 100.0 * /mapping/extrinsic_R: [1, 0, 0, 0, 1, 0... * /mapping/extrinsic_T: [-0.011, -0.02329... * /mapping/extrinsic_est_en: False * /mapping/fov_degree: 360 * /mapping/gyr_cov: 0.1 * /max_iteration: 3 * /pcd_save/interval: -1 * /pcd_save/pcd_save_en: False * /pcd_save_en: False * /point_filter_num: 3 * /pointcloud_to_laserscan/angle_increment: 0.0087 * /pointcloud_to_laserscan/angle_max: 3.14159 * /pointcloud_to_laserscan/angle_min: -3.14159 * /pointcloud_to_laserscan/concurrency_level: 1 * /pointcloud_to_laserscan/inf_epsilon: 1.0 * /pointcloud_to_laserscan/max_height: 1.0 * /pointcloud_to_laserscan/min_height: 0.0 * /pointcloud_to_laserscan/range_max: 30.0 * /pointcloud_to_laserscan/range_min: 0.05 * /pointcloud_to_laserscan/scan_time: 10 * /pointcloud_to_laserscan/transform_tolerance: 0.01 * /pointcloud_to_laserscan/use_inf: True * /preprocess/blind: 0.5 * /preprocess/lidar_type: 1 * /preprocess/scan_line: 4 * /publish/dense_publish_en: True * /publish/path_en: False * /publish/scan_bodyframe_pub_en: True * /publish/scan_publish_en: True * /rosdistro: noetic * /rosversion: 1.17.0 * /runtime_pos_log_enable: False NODES / global_localization (fast_lio_localization/global_localization.py) laserMapping (fast_lio/fastlio_mapping) map_publishe (pcl_ros/pcd_to_pointcloud) map_server (map_server/map_server) pointcloud_to_laserscan (pointcloud_to_laserscan/po
最新发布
03-31
<think>好的,用户的问题是关于如何清理ROS日志目录以释放磁盘空间,以及解析FAST_LIO相关的参数配置。首先,我需要回忆一下ROS的日志管理机制。ROS默认会在~/.ros/log目录下存储日志文件,长时间运行可能导致磁盘空间不足。用户可能遇到了这个问题,所以需要清理方法。 接下来,清理ROS日志的方法,我记得有rosclean命令。rosclean check可以检查日志大小,rosclean purge则删除所有日志。需要确认这些命令的具体用法和注意事项,比如是否需要权限,是否会删除所有日志等。另外,用户可能希望自动清理,可以考虑设置定时任务或者修改环境变量改变日志存储位置。 然后是FAST_LIO的参数配置部分。用户提到想了解相关参数,可能需要解析常见的参数文件,比如YAML配置文件中的参数,如激光雷达话题、IMU话题、地图分辨率等。此外,用户提到的错误中涉及Pose6D.h头文件缺失,可能需要检查依赖安装,特别是fast_lio包是否安装正确,或者CMakeLists.txt中的设置是否正确,比如C++标准设置是否如引用[4]提到的C++14。 还需要考虑用户的环境,比如是否使用ROS Noetic,因为引用[3]提到项目地址是针对ROS Noetic的。可能存在的依赖问题,如引用[2]提到的python 2.7和ros_numpy,需要确认用户的环境是否满足这些依赖。 另外,用户的问题中引用了几个错误信息,比如Pose6D.h找不到,这可能和依赖安装或编译配置有关。可能需要指导用户检查include路径是否正确,或者重新安装相关依赖包。 最后,总结步骤:清理日志的方法,参数配置的解析,以及可能的依赖问题解决。需要确保回答清晰,分步骤说明,并引用提供的参考资料来支持建议。</think>### ROS日志清理与参数配置指南 #### 一、清理ROS日志目录 1. **手动清理日志** ```bash rosclean check # 检查日志目录大小 rosclean purge # 删除所有日志文件 ``` 执行`rosclean purge`会删除`~/.ros/log`下所有日志文件,建议先备份重要日志[^1][^2]。 2. **自动清理配置** ```bash export ROS_LOG_DIR=/tmp/ros_log # 修改日志存储路径 ``` 在`~/.bashrc`添加上述命令,可避免默认路径空间不足问题。 3. **定时清理脚本** ```bash # 每周清理一次日志 0 0 * * 0 rosclean purge -y ``` 通过`crontab -e`添加定时任务[^2]。 --- #### 二、FAST_LIO参数配置解析 1. **核心参数文件** ```yaml # params_lidar.yaml lidar_topic: "/points_raw" # 激光雷达话题 imu_topic: "/imu/data" # IMU话题 map_resolution: 0.05 # 地图分辨率(单位:米) ``` 参数路径通常位于`FAST_LIO/config`目录[^3]。 2. **编译参数修正** ```cmake # CMakeLists.txt关键配置 set(CMAKE_CXX_STANDARD 14) # 强制使用C++14标准[^4] find_package(fast_lio REQUIRED) include_directories(${fast_lio_INCLUDE_DIRS}) ``` 3. **依赖验证** ```bash sudo apt-get install ros-noetic-ros-numpy # 安装python2.7依赖 ``` 需确保`fast_lio/Pose6D.h`头文件存在于ROS包路径中[^1]。 --- #### 三、关键问题解决方案 1. **Pose6D.h缺失错误** ```bash cd ~/catkin_ws/src git clone https://github.com/hku-mars/FAST_LIO --recursive catkin_make -DCMAKE_BUILD_TYPE=Release ``` 完整克隆仓库可解决头文件缺失问题[^1]。 2. **磁盘空间监控** ```bash watch -n 60 df -h /home # 每分钟监控磁盘使用 ``` 建议对日志目录设置磁盘配额。 ---
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

zhangrelay

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值