| 92 | } |
| 93 | |
| 94 | void CostmapLayers::UpdateMap(double robot_x, double robot_y, double robot_yaw) { |
| 95 | static int count = 0; |
| 96 | std::unique_lock<Costmap2D::mutex_t> lock(*(costmap_.GetMutex())); |
| 97 | if (is_rolling_window_) { |
| 98 | double new_origin_x = robot_x - costmap_.GetSizeXWorld() / 2; |
| 99 | double new_origin_y = robot_y - costmap_.GetSizeYWorld() / 2; |
| 100 | costmap_.UpdateOrigin(new_origin_x, new_origin_y); |
| 101 | } |
| 102 | if (plugins_.size() == 0) { |
| 103 | ROS_WARN("No Layer"); |
| 104 | return; |
| 105 | } |
| 106 | |
| 107 | minx_ = miny_ = 1e30; |
| 108 | maxx_ = maxy_ = -1e30; |
| 109 | for (auto plugin = plugins_.begin(); plugin != plugins_.end(); ++plugin) { |
| 110 | double prev_minx = minx_; |
| 111 | double prev_miny = miny_; |
| 112 | double prev_maxx = maxx_; |
| 113 | double prev_maxy = maxy_; |
| 114 | (*plugin)->UpdateBounds(robot_x, robot_y, robot_yaw, &minx_, &miny_, &maxx_, &maxy_); |
| 115 | count++; |
| 116 | if (minx_ > prev_minx || miny_ > prev_miny || maxx_ < prev_maxx || maxy_ < prev_maxy) { |
| 117 | ROS_WARN("Illegal bounds change. The offending layer is %s", (*plugin)->GetName().c_str()); |
| 118 | } |
| 119 | } |
| 120 | int x0, xn, y0, yn; |
| 121 | costmap_.World2MapWithBoundary(minx_, miny_, x0, y0); |
| 122 | costmap_.World2MapWithBoundary(maxx_, maxy_, xn, yn); |
| 123 | x0 = std::max(0, x0); |
| 124 | xn = std::min(int(costmap_.GetSizeXCell()), xn + 1); |
| 125 | y0 = std::max(0, y0); |
| 126 | yn = std::min(int(costmap_.GetSizeYCell()), yn + 1); |
| 127 | if (xn < x0 || yn < y0) { |
| 128 | return; |
| 129 | } |
| 130 | costmap_.ResetPartMap(x0, y0, xn, yn); |
| 131 | for (auto plugin = plugins_.begin(); plugin != plugins_.end(); ++plugin) { |
| 132 | (*plugin)->UpdateCosts(costmap_, x0, y0, xn, yn); |
| 133 | } |
| 134 | |
| 135 | bx0_ = x0; |
| 136 | bxn_ = xn; |
| 137 | by0_ = y0; |
| 138 | byn_ = yn; |
| 139 | is_initialized_ = true; |
| 140 | } |
| 141 | |
| 142 | void CostmapLayers::SetFootprint(const std::vector<geometry_msgs::Point> &footprint_spec) { |
| 143 | footprint_ = footprint_spec; |
nothing calls this directly
no test coverage detected