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

本文介绍了如何在机器人导航系统中使用静态地图作为代价地图的初始化数据。文章详细解释了如何通过参数设置来控制地图的读取方式,包括代价阈值设定、未知空间跟踪等,并说明了不同订阅主题及更新订阅的重要性。

1 概述

  静态地图中包含的大多数是来自外部源的不变数据(see the map_server package for documentation on building a map)。

1.1 Subscribed Topics
"map" ( nav_msgs/OccupancyGrid)
  • 代价地图可以选择使用用户定义的静态地图来初始化它(see the static_map parameter)。 如果该选项被选择,代价地图将使用service call从 map_server 获取静态地图
1.2 Parameters
unknown_cost_value ( int, default: -1)
  • 从map server提供地图中读到这个值,其代价将被按unknown看待。 If the costmap is not tracking unknown space, costs of this value will be considered occupied. A value of zero also results in this parameter being unused.
lethal_cost_threshold ( int, default: 100)
  • The threshold value at which to consider a cost lethal when reading in a map from the map server.
map_topic ( string, default: "map")
  • 指定代价地图用来订阅静态地图的主题。 This parameter is useful when you have multiple costmap instances within a single node that you want to use different static maps. - New in navigation 1.3.1
first_map_only ( bool, default: false)
  • Only subscribe to the first message on the map topic, ignoring all subsequent messages
subscribe_to_updates ( bool, default: false)
  • In addition to map_topic, also subscribe to map_topic + "_updates"
track_unknown_space ( bool, default: true)
  • If true, unknown values in the map messages are translated directly to the layer. Otherwise, unknown values in the map message are translated as FREE_SPACE in the layer.
use_maximum ( bool, default: false)
  • Only matters if the static layer is not the bottom layer. If true, only the maximum value will be written to the master costmap.

trinary_costmap (bool, default: true)

如果是true, 所有地图消息都将被转义成3个值:NO_INFORMATION/FREE_SPACE/LETHAL_OBSTACLE (three values);如果是false,地图消息可能会转义成一系列值


### 正确安装 `costmap_2d` 插件及依赖配置 #### 1. 安装 `costmap_2d` 包 `costmap_2d` 是 ROS 导航栈中的核心组件之一,用于生成代价地图。可以通过以下方法安装: 对于二进制安装,确保已安装 ROS 的导航包: ```bash sudo apt-get install ros-<ros_distro>-navigation ``` 其中 `<ros_distro>` 是 ROS 的版本名称,例如 `noetic` 或 `melodic`[^5]。 对于源码安装,克隆导航仓库到工作空间并编译: ```bash cd ~/catkin_ws/src git clone https://github.com/ros-planning/navigation.git -b <ros_distro> cd ~/catkin_ws catkin_make source devel/setup.bash ``` #### 2. 配置插件 `costmap_2d` 支持多种插件,如 `static_layer`、`obstacle_layer` 和 `inflation_layer`。这些插件通过 YAML 文件配置。以下是典型的配置文件示例: ```yaml plugins: - {name: static_layer, type: "costmap_2d::StaticLayer"} - {name: obstacle_layer, type: "costmap_2d::ObstacleLayer"} - {name: inflation_layer, type: "costmap_2d::InflationLayer"} ``` 注意插件加载顺序,通常将 `inflation_layer` 放在最后,因为它会膨胀前面所有的障碍物信息[^3]。 #### 3. 配置传感器数据源 `costmap_2d` 可以订阅多种传感器数据源,如激光雷达和摄像头。以下是一个配置传感器数据源的示例: ```yaml obstacle_layer: observation_sources: laser_scan point_cloud laser_scan: data_type: LaserScan topic: /scan marking: true clearing: true point_cloud: data_type: PointCloud2 topic: /camera/depth/points marking: true clearing: true ``` 确保传感器主题与实际发布的主题一致,并调整 `marking` 和 `clearing` 参数以适应具体需求[^4]。 #### 4. 配置全局和局部代价地图 `costmap_2d` 支持全局和局部代价地图。以下是一个完整的配置示例: ```yaml global_costmap: global_frame: map robot_base_frame: base_link update_frequency: 5.0 publish_frequency: 2.0 static_map: true rolling_window: false plugins: - {name: static_layer, type: "costmap_2d::StaticLayer"} - {name: inflation_layer, type: "costmap_2d::InflationLayer"} local_costmap: global_frame: odom robot_base_frame: base_link update_frequency: 5.0 publish_frequency: 2.0 static_map: false rolling_window: true width: 3.0 height: 3.0 resolution: 0.05 plugins: - {name: obstacle_layer, type: "costmap_2d::ObstacleLayer"} - {name: inflation_layer, type: "costmap_2d::InflationLayer"} ``` #### 5. 调试与验证 启动节点后,可以使用 `rostopic echo` 或 `rviz` 查看代价地图的生成情况。例如: ```bash rostopic echo /move_base/global_costmap/costmap ``` 在 `rviz` 中添加 `Costmap` 显示类型,并设置相应的主题。 #### 6. 常见问题及解决方法 - **错误:参数未正确加载** 确保 YAML 文件路径正确,并在启动文件中加载参数。例如: ```xml <param name="costmap_common_params" command="$(find my_package)/cfg/costmap_common_params.yaml" /> ``` - **错误:传感器数据未更新** 检查 `tf` 树是否正确,以及 `transform_tolerance` 参数是否合理[^4]。 - **错误:插件未生效** 确保插件名称和类型正确匹配,并检查加载顺序[^3]。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值