ROS Navigation-----costmap_2d之obstacle层简介

本文深入解析了ROS中的Costmap概念,包括其如何通过处理PointClouds、LaserScans等传感器消息来更新代价地图,实现机器人路径规划中的障碍物检测与避免。文章详细介绍了配置参数及其用途,如传感器数据的管理、全局过滤参数的应用等。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1 概述

   obstacle和voxel层包含了 PointClouds 或者 LaserScans形式的传感器消息。 障碍物层用于二维追踪,体素层用于三维追踪。

1.1 标记和清除

 代价地图自动订阅传感器主题并进行相应自我更新。每个传感器既可以用于标记(插入障碍信息到代价地图),也可以用于清除(从代价地图移除障碍信息),或者两种功能都有。     如果使用的是体素层,每一列上的障碍信息需要先进行投影转化成二维之后才能放入代价地图中。

1.2 ROS API

1.2.1 订阅的主题
<point_cloud_topic> ( sensor_msgs/PointCloud)
  • For each "PointCloud" source listed in the observation_sources parameter list, information from that source is used to update the costmap.
<point_cloud2_topic> ( sensor_msgs/PointCloud2)
  • For each "PointCloud2" source listed in the observation_sources parameter list, information from that source is used to update the costmap.
<laser_scan_topic> ( sensor_msgs/LaserScan)
  • For each "LaserScan" source listed in the observation_sources parameter list, information from that source is used to update the costmap.
"map" ( nav_msgs/OccupancyGrid)
  • The costmap has the option of being initialized from a user-generated static map (see the static_map parameter). If this option is selected, the costmap makes a service call to the map_server to obtain this map.

1.2.2 传感器管理参数

~<name>/observation_sources (string, default: "")

  • 观察源列表以空格分割表示,定义了下面参数中每一个 <source_name> 命名空间

~<name>/<source_name>/topic (string, default: source_name)

  • <source_name>的传感器数据使用的topic,Defaults to the name of the source.
~<name>/<source_name>/sensor_frame ( string, default: "")
  • 指定传感器原点坐标系。 Leave empty to attempt to read the frame from sensor data. The frame can be read from both sensor_msgs/LaserScan, sensor_msgs/PointCloud, and sensor_msgs/PointCloud2 messages.
~<name>/<source_name>/observation_persistence ( double, default: 0.0)
  • 传感器读数保存多久(单位秒), A value of 0.0 will only keep the most recent reading.
~<name>/<source_name>/expected_update_rate ( double, default: 0.0)
  • 多久读取一次传感器数据(单位秒), A value of 0.0 will allow infinite time between readings. This parameter is used as a failsafe to keep the navigation stack from commanding the robot when a sensor has failed. It should be set to a value that is slightly more permissive than the actual rate of the sensor. For example, if we expect a scan from a laser every 0.05 seconds we might set this parameter to be 0.1 seconds to give a generous buffer and account for some amount of system latency.
~<name>/<source_name>/data_type ( string, default: "PointCloud")
  • 指定主题相关的数据类型, 目前可用数据类型有 "PointCloud", "PointCloud2", "LaserScan"
~<name>/<source_name>/clearing ( bool, default: false)
  • Whether or not this observation should be used to clear out freespace.
~<name>/<source_name>/marking ( bool, default: true)
  • Whether or not this observation should be used to mark obstacles.
~<name>/<source_name>/max_obstacle_height ( double, default: 2.0)
  • 传感器读数最大有效高度(单位米),This is usually set to be slightly higher than the height of the robot. Setting this parameter to a value greater than the global max_obstacle_height parameter has no effect. Setting this parameter to a value less than the global max_obstacle_height will filter out points from this sensor above that height.
~<name>/<source_name>/min_obstacle_height ( double, default: 0.0)
  • 传感器读数最小有效高度(单位米), This is usually set to be at ground height, but can be set higher or lower based on the noise model of your sensor.
~<name>/<source_name>/obstacle_range ( double, default: 2.5)
  • 指定可将多大范围空间内障碍物插入到代价地图中这个参数指定范围上限边界(单位米)
~<name>/<source_name>/raytrace_range ( double, default: 3.0)
  • 指定raytrace可以清除障碍物的最大范围
~<name>/<source_name>/inf_is_valid ( bool, default: false)
  • Allows for Inf values in "LaserScan" observation messages. The Inf values are converted to the laser maximun range.

1.2.3 全局过滤参数

这些参数可应用于所有传感器:

~<name>/max_obstacle_height (double, default: 2.0)

  • The maximum height of any obstacle to be inserted into the costmap in meters. This parameter should be set to be slightly higher than the height of your robot.
~<name>/obstacle_range ( double, default: 2.5)
  • The default maximum distance from the robot at which an obstacle will be inserted into the cost map in meters. This can be over-ridden on a per-sensor basis.
~<name>/raytrace_range ( double, default: 3.0)
  • The default range in meters at which to raytrace out obstacles from the map using sensor data. This can be over-ridden on a per-sensor basis.

1.2.4 障碍代价地图插件(ObstacleCostmapPlugin)

该参数只可用于ObstacleCostmapPlugin

~<name>/track_unknown_space (bool, default: false)

  • 指定是否在代价地图中track unknown空间, unknown means that no observation about a cell has been seen from any sensor source.

1.2.5 体素代价地图插件(VoxelCostmapPlugin)

下面参数仅可用于 VoxelCostmapPlugin

  • ~<name>/origin_z (double, default: 0.0)
    • The z origin of the map in meters.
    ~<name>/z_resolution (double, default: 0.2)
    • The z resolution of the map in meters/cell.
    ~<name>/z_voxels (int, default: 10)
    • The number of voxels to in each vertical column, the height of the grid is z_resolution * z_voxels.
    ~<name>/unknown_threshold (int, default: ~<name>/z_voxels)
    • The number of unknown cells allowed in a column considered to be "known"
    ~<name>/mark_threshold (int, default: 0)
    • The maximum number of marked cells allowed in a column considered to be "free".
    ~<name>/publish_voxel_map (bool, default: false)
    • Whether or not to publish the underlying voxel grid for visualization purposes.

2 观察缓冲(ObservationBuffer)

costmap_2d::ObservationBuffer 被用来吸收传感器点云,然后使用tf将它们转换到想使用的坐标系,并会一直存储直到收到这些信息被请求。大多数用户使用costmap_2d::Costmap2DROS自动创建的costmap_2d::ObservationBuffer即可满足需求,但为了某些特殊需求可能需要自己创建costmap_2d::ObservationBuffer

2.1 API Stability

  • C++ API是稳定的

2.1.1 C++ API

  有关costmap_2d::ObservationBuffer类的C++文档请参考: ObservationBuffer C++ API


<think>我们正在解决机器人路径规划问题,特别是关于局部代价地图(local_costmap)的配置。根据引用[1],costmap_2d是存储和访问二维代价地图的基本数据结构。在ROS导航堆栈中,局部代价地图用于局部路径规划和实时避障。 用户的问题集中在配置local_costmap参数以解决机器人路径规划问题。根据之前的对话历史,我们知道机器人存在乱走、不前往目标点的问题,可能与局部避障和全局规划的协同失效有关。 以下我们将提供详细的local_costmap配置指南,重点解决避障与目标点到达的平衡问题。 --- ### 一、核心参数配置原则 1. **代价地图配置** 局部代价地图通常包含以下(引用[1]): - `static_layer`:静态地图(来自全局地图) - `obstacle_layer`:动态障碍物(实时传感器数据) - `inflation_layer`:膨胀(用于安全距离) ```yaml # local_costmap_params.yaml 示例 local_costmap: global_frame: odom # 使用里程计坐标系[^2][^5] robot_base_frame: base_link # 机器人基坐标系[^2] update_frequency: 5.0 # 地图更新频率(Hz) publish_frequency: 2.0 # 发布频率 width: 3.0 # 地图宽度(米) height: 3.0 # 地图高度(米) resolution: 0.05 # 分辨率(米/格) plugins: - {name: static_layer, type: "costmap_2d::StaticLayer"} - {name: obstacle_layer, type: "costmap_2d::ObstacleLayer"} - {name: inflation_layer,type: "costmap_2d::InflationLayer"} ``` 2. **障碍物关键参数** ```yaml obstacle_layer: max_obstacle_height: 0.6 # 最大障碍高度(避免误检)[^1] combination_method: 1 # 1=最大值融合(确保障碍可见) track_unknown_space: true # 跟踪未知区域 observation_sources: laser_scan # 传感器源 laser_scan: data_type: LaserScan topic: /scan # 激光雷达话题 marking: true # 用于标记障碍 clearing: true # 用于清除障碍 ``` 3. **膨胀参数优化** 膨胀控制安全距离和代价衰减: ```yaml inflation_layer: cost_scaling_factor: 5.0 # 代价衰减系数(值越大衰减越快) inflation_radius: 0.5 # 膨胀半径(米) enabled: true ``` --- ### 二、避障-目标点平衡策略 针对机器人避障时远离目标点的问题,采用**动态代价调整**: 1. **基于目标距离的代价衰减** 在靠近目标时降低障碍物代价权重,避免过度避障(引用[3]优化): $$ \text{cost}_{\text{effective}} = \text{cost}_{\text{raw}} \times \max(0.3, \ 1 - e^{-k \cdot d_{\text{goal}}}) $$ 其中: - $d_{\text{goal}}$:机器人到目标点的距离 - $k$:调整系数(推荐0.8-1.2) 2. **参数动态调整实现** 在局部规划器(如TEB或DWA)中配置: ```yaml # teb_local_planner_params.yaml 示例 TEBLocalPlannerROS: max_vel_x: 0.4 # 动态权重配置 weight_obstacle: 50 # 基础障碍物代价权重 weight_goal: 10 # 目标点吸引力权重 # 距离相关调整 obstacle_cost_decay_rate: 0.8 # 代价衰减系数k ``` --- ### 三、坐标系与传感器同步 根据引用[2][5],确保坐标系正确: | 参数 | 推荐值 | 说明 | |------|--------|------| | `global_frame` | `odom` | 使用里程计坐标系,避免地图漂移 | | `robot_base_frame` | `base_link` | 机器人基坐标系 | | `map_frame` | `map` | 全局规划器使用地图坐标系[^5] | > **重要**:检查TF树是否完整,确保`map`→`odom`→`base_link`的变换可用。 --- ### 四、验证与调试方法 1. **可视化代价地图** ```bash roslaunch navigation_stage move_base_amcl.launch rviz -d $(rospack find navigation_stage)/move_base.rviz ``` 在RViz中查看`/local_costmap`话题。 2. **实时参数调整** 使用`dynamic_reconfigure`在运行时调整参数: ```bash rosrun rqt_reconfigure rqt_reconfigure ``` 3. **避障性能测试** ```bash # 添加测试障碍物 rosrun gazebo_ros spawn_model -database coke_can -gazebo -model movable_obs -x 2.0 -y 0.0 # 监控规划状态 rostopic echo /move_base/status ``` --- ### 五、常见问题解决 | 问题现象 | 解决方案 | |----------|----------| | 机器人绕行过远 | 降低`inflation_radius`(0.3-0.5m) | | 靠近目标时震荡 | 增大`xy_goal_tolerance`(0.1-0.3m)[^3] | | 忽略动态障碍 | 检查`sensor`话题是否正常发布 | | 坐标系错误 | 确认`global_frame`与`map_frame`一致性[^5] | > **紧急重置**:当机器人卡死时,清除代价地图: > ```bash > rosservice call /move_base/clear_costmaps > ``` §§相关问题§§ 1. 如何调整膨胀参数以平衡安全性与路径效率? 2. 机器人坐标系配置错误会导致哪些导航问题? 3. 如何验证局部代价地图是否正常更新? 4. 动态障碍物追踪失败时应检查哪些参数?</think>### ROS局部代价地图(local_costmap)配置指南 针对机器人路径规划问题,以下是优化`local_costmap`参数的关键配置方案,结合引用[1][2][3][5]的核心原理: --- #### 一、基础框架配置 ```yaml # local_costmap_params.yaml local_costmap: global_frame: odom # 使用里程计坐标系[^2][^5] robot_base_frame: base_link # 机器人基坐标系[^2] update_frequency: 5.0 # 地图更新频率(Hz) publish_frequency: 2.0 # 可视化发布频率 width: 3.0 # 地图宽度(米) height: 3.0 # 地图高度(米) resolution: 0.05 # 分辨率(米/格) plugins: - {name: static_layer, type: "costmap_2d::StaticLayer"} - {name: obstacle_layer, type: "costmap_2d::ObstacleLayer"} - {name: inflation_layer,type: "costmap_2d::InflationLayer"} ``` > **关键说明**: > - `global_frame`必须与规划器坐标系一致(通常为`odom`)[^5] > - `update_frequency`需高于机器人运动速度(如1m/s时≥5Hz) --- #### 二、障碍物核心优化 ```yaml obstacle_layer: max_obstacle_height: 0.6 # 降低高障碍误检[^1] combination_method: 1 # 1=最大值融合(确保障碍可见) track_unknown_space: true # 跟踪未知区域 observation_sources: laser_scan # 传感器源 laser_scan: data_type: LaserScan topic: /scan # 激光雷达话题 marking: true # 用于标记障碍 clearing: true # 用于清除障碍 ``` **障碍物检测数学模型**: $$ \text{有效障碍} = \begin{cases} 1 & \text{if } z_{\text{obs}} \leq h_{\text{max}} \\ 0 & \text{otherwise} \end{cases} $$ 其中$h_{\text{max}}$为`max_obstacle_height`,$z_{\text{obs}}$为障碍高度[^1] --- #### 三、膨胀安全策略 ```yaml inflation_layer: cost_scaling_factor: 5.0 # 代价衰减系数(值越大衰减越快) inflation_radius: 0.5 # 膨胀半径(米) enabled: true ``` **膨胀代价计算**(引用[1]): $$ \text{cost}(d) = \begin{cases} 254 & d \leq r_{\text{robot}} \\ 254 \times e^{-\lambda (d - r_{\text{robot}})} & d > r_{\text{robot}} \end{cases} $$ 其中: - $d$:到障碍物距离 - $\lambda$:`cost_scaling_factor` - $r_{\text{robot}}$:机器人半径 --- #### 四、与局部规划器协同 在TEB/DWA规划器中配置协同参数(引用[5]): ```yaml TEBLocalPlannerROS: costmap_converter_plugin: "costmap_converter::CostmapToPolygonsDBSMCCH" costmap_topic: /local_costmap/costmap max_vel_x: 0.4 # 最大线速度 acc_lim_x: 0.5 # 线加速度限制 footprint_model: type: "circular" # 机器人轮廓模型 radius: 0.3 # 圆形半径 ``` > **动态调参策略**(靠近目标时降低避障权重): > ```python > if distance_to_goal < 1.0: > set_parameter("inflation_radius", 0.3) # 减小安全距离 > set_parameter("cost_scaling_factor", 3.0) # 降低代价衰减 > ``` --- #### 五、验证与调试命令 1. **可视化代价地图**: ```bash roslaunch navigation_stage move_base_amcl.launch rviz -d $(rospack find navigation_stage)/move_base.rviz ``` 2. **实时参数调整**: ```bash rosrun rqt_reconfigure rqt_reconfigure # 动态修改参数 ``` 3. **避障测试**: ```bash # 添加测试障碍物 rosrun gazebo_ros spawn_model -database coke_can -gazebo -model movable_obs -x 2.0 -y 0.0 ``` --- #### 六、常见问题解决表 | 问题现象 | 关键参数调整 | |------------------------|----------------------------------| | 机器人绕行过远 | 降低`inflation_radius` (0.3-0.5m) | | 靠近目标时震荡 | 增大`xy_goal_tolerance` (0.1-0.3m)[^3] | | 忽略动态障碍 | 检查`sensor`话题是否正常发布 | | 路径频繁重规划 | 提高`update_frequency` (≥10Hz) | > **紧急恢复命令**(当机器人卡死时): > ```bash > rosservice call /move_base/clear_costmaps # 清除代价地图 > ```
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值