void StaticLayer::incomingMap(const navmsgs::OccupancyGridConstPtr& newmap) { unsigned…
- User
void StaticLayer::incomingMap(const nav_msgs::OccupancyGridConstPtr& new_map) { unsigned int size_x = new_map->info.width, size_y = new_map->info.height;
ROS_DEBUG("Received a %d X %d map at %f m/pix", size_x, size_y, new_map->info.resolution);
// resize costmap if size, resolution or origin do not match Costmap2D* master = layered_costmap_->getCostmap(); if (!layered_costmap_->isRolling() && (master->getSizeInCellsX() != size_x || master->getSizeInCellsY() != size_y || master->getResolution() != new_map->info.resolution || master->getOriginX() != new_map->info.origin.position.x || master->getOriginY() != new_map->info.origin.position.y)) { // Update the size of the layered costmap (and all layers, including this one) ROS_INFO("Resizing costmap to %d X %d at %f m/pix", size_x, size_y, new_map->info.resolution); layered_costmap_->resizeMap(size_x, size_y, new_map->info.resolution, new_map->info.origin.position.x, new_map->info.origin.position.y, true /* set size_locked to true, prevents reconfigureCb from overriding map size*/); } else if (size_x_ != size_x || size_y_ != size_y || resolution_ != new_map->info.resolution || origin_x_ != new_map->info.origin.position.x || origin_y_ != new_map->info.origin.position.y) { // only update the size of the costmap stored locally in this layer ROS_INFO("Resizing static layer to %d X %d at %f m/pix", size_x, size_y, new_map->info.resolution); resizeMap(size_x, size_y, new_map->info.resolution, new_map->info.origin.position.x, new_map->info.origin.position.y); }
unsigned int index = 0;
// initialize the costmap with static data for (unsigned int i = 0; i < size_y; ++i) { for (unsigned int j = 0; j < size_x; ++j) { unsigned char value = new_map->data[index]; costmap_[index] = interpretValue(value); ++index; } } map_frame_ = new_map->header.frame_id;
// we have a new map, update full size of map x_ = y_ = 0; width_ = size_x_; height_ = size_y_; map_received_ = true; has_updated_data_ = true;
// shutdown the map subscrber if firt_map_only_ flag is on if (first_map_only_) { ROS_INFO("Shutting down the map subscriber. first_map_only flag is on"); map_sub_.shutdown(); } } 为我详细解释 move_base static_layer
- Assistant
在ROS(Robot Operating System)的导航堆栈中,
move_base节点提供了一个功能强大的路径规划和运动执行平台,可以让机器人在环境中安全地移动到目标位置。特别是在这种框架中,static_layer是costmap_2d包中的一个组件,它用于处理那些不太可能改变的环境元素,比如墙壁、障碍物等。在
static_layer的代码实现中,其主要的职责是从一个2D地图话题(如"map")接收到的nav_msgs/OccupancyGrid消息,并根据这些消息来更新内部的成本图(costmap)。这个成本图随后被move_base用于路径规划和避障。下面我们将详细解释提供的incomingMap函数:incomingMap函数解析-
接收到的地图信息:
- 函数首先定义了新地图的大小和分辨率:
size_x,size_y,new_map->info.resolution。 - 然后打印接收到的地图尺寸和分辨率的调试信息。
- 函数首先定义了新地图的大小和分辨率:
-
比较和调整成本图尺寸:
- 函数首先获取主成本图(由
move_base中的其他层如obstacle_layer等共用)的引用 (Costmap2D* master)。 - 判断是否需要调整主成本图尺寸:
- 如果成本图尺寸、分辨率或者原点与接收到的地图不一致,并且成本图不是rolling类型的,则调整整个
layered_costmap的维度。
- 如果成本图尺寸、分辨率或者原点与接收到的地图不一致,并且成本图不是rolling类型的,则调整整个
- 函数首先获取主成本图(由
-
- User
void LayeredCostmap::resizeMap(unsigned int size_x, unsigned int size_y, double resolution, double origin_x, double origin_y, bool size_locked) { boost::unique_lockCostmap2D::mutex_t lock(*(costmap_.getMutex())); size_locked_ = size_locked; costmap_.resizeMap(size_x, size_y, resolution, origin_x, origin_y); for (vector<boost::shared_ptr >::iterator plugin = plugins_.begin(); plugin != plugins_.end(); ++plugin) { (*plugin)->matchSize(); } }
- Assistant
- User
nh.param("trinary_costmap", trinary_costmap_, true); 这个在move_base的参数中 用于什么
- Assistant
在 ROS(Robot Operating System)的导航堆栈中,特别是与
move_base节点相关的costmap_2d包内,参数trinary_costmap属于成本地图(costmap)的配置参数之一。该参数用于决定成本地图中障碍物数据的表示方法。参数功能:
trinary_costmap参数控制成本地图的障碍物值是使用三值逻辑(trinary logic)还是连续值来表达。该参数的可能值有:true(默认值): 表示使用三值逻辑。在这种模式下,成本地图的格子只有三种可能的状态:障碍物(通常表示为254),自由空间(表示为 0),以及不可知区域(表示为255)。这种方法简化了数据,但足以用于大多数导航和避障任务。false: 表示使用原始概率(原始的 occupancy probabilities)。这个模式会利用更详细的占用概率信息,将环境中的每个单元格设置成更细分的值范围,从而可能提供更精细的导航决策依据。
使用场景:
当您需要在成本地图的格子中精确表示障碍物的概率信息时,您可能会设置
trinary_costmap为false。这在环境比较复杂或者障碍物识别对任务非常关键时特别有用,比如在冗杂环境中的精密操作或高级避障策略中。反之,如果您的机器人运行在相对简单或者标准化的环境中,或者对系统资源(内存或计算资源)有限制,使用默认的
true,即三值逻辑可能已经足够满足避障和路径规划的需求,同时还能提高整体的系统效率。实现代码:
在
costmap_2d的参数配置中,通过如下方式设置trinary_costmap:cppbool trinary_costmap_; ros::NodeHandle nh; // 从参数服务器读取trinary_costmap的值,默认设定为true nh.param("trinary_costmap", trinary_costmap_, true); - User
double scale = (double) value / lethal_threshold_; return scale * LETHAL_OBSTACLE;
- Assistant