@@ -185,6 +185,67 @@ void FullCoveragePathPlanner::parsePointlist2Plan(const geometry_msgs::PoseStamp
185
185
ROS_INFO (" Plan ready containing %lu goals!" , plan.size ());
186
186
}
187
187
188
+ bool FullCoveragePathPlanner::parseCostmap (costmap_2d::Costmap2D* costmap_grid_,
189
+ std::vector<std::vector<bool > >& grid,
190
+ float robotRadius,
191
+ float toolRadius,
192
+ geometry_msgs::PoseStamped const & realStart,
193
+ Point_t& scaledStart)
194
+ {
195
+ int ix, iy, nodeRow, nodeCol;
196
+ uint32_t nodeSize = dmax (floor (toolRadius / costmap_grid_->getResolution ()), 1 ); // Size of node in pixels/units
197
+ uint32_t nRows = costmap_grid_->getSizeInCellsY (), nCols = costmap_grid_->getSizeInCellsX ();
198
+ ROS_INFO (" nRows: %u nCols: %u nodeSize: %d" , nRows, nCols, nodeSize);
199
+
200
+ if (nRows == 0 || nCols == 0 )
201
+ {
202
+ return false ;
203
+ }
204
+
205
+ // Save map origin and scaling
206
+ tile_size_ = nodeSize * costmap_grid_->getResolution (); // Size of a tile in meters
207
+ grid_origin_.x = costmap_grid_->getOriginX (); // x-origin in meters
208
+ grid_origin_.y = costmap_grid_->getOriginY (); // y-origin in meters
209
+ ROS_INFO (" costmap resolution: %g" , costmap_grid_->getResolution ());
210
+ ROS_INFO (" tile size: %g" , tile_size_);
211
+ ROS_INFO (" grid origin: (%g, %g)" , grid_origin_.x , grid_origin_.y );
212
+
213
+ // Scale starting point
214
+ scaledStart.x = static_cast <unsigned int >(clamp ((realStart.pose .position .x - grid_origin_.x ) / tile_size_, 0.0 ,
215
+ floor (nCols / tile_size_)));
216
+ scaledStart.y = static_cast <unsigned int >(clamp ((realStart.pose .position .y - grid_origin_.y ) / tile_size_, 0.0 ,
217
+ floor (nRows / tile_size_)));
218
+ ROS_INFO (" real start: (%g, %g)" , realStart.pose .position .x , realStart.pose .position .y );
219
+ ROS_INFO (" scaled start: (%u, %u)" , scaledStart.x , scaledStart.y );
220
+
221
+ // Scale grid
222
+ for (iy = 0 ; iy < nRows; iy = iy + nodeSize)
223
+ {
224
+ std::vector<bool > gridRow;
225
+ for (ix = 0 ; ix < nCols; ix = ix + nodeSize)
226
+ {
227
+ bool nodeOccupied = false ;
228
+ for (nodeRow = 0 ; (nodeRow < nodeSize) && ((iy + nodeRow) < nRows) && (nodeOccupied == false ); ++nodeRow)
229
+ {
230
+ for (nodeCol = 0 ; (nodeCol < nodeSize) && ((ix + nodeCol) < nCols); ++nodeCol)
231
+ {
232
+ double mx = grid_origin_.x + ix + nodeCol;
233
+ double my = grid_origin_.y + iy + nodeRow;
234
+ if (costmap_grid_->getCost (mx, my) > costmap_2d::INSCRIBED_INFLATED_OBSTACLE)
235
+ {
236
+ nodeOccupied = true ;
237
+ ROS_INFO (" (%f, %f) marked occupied" , mx, my);
238
+ break ;
239
+ }
240
+ }
241
+ }
242
+ gridRow.push_back (nodeOccupied);
243
+ }
244
+ grid.push_back (gridRow);
245
+ }
246
+ return true ;
247
+ }
248
+
188
249
bool FullCoveragePathPlanner::parseGrid (nav_msgs::OccupancyGrid const & cpp_grid_,
189
250
std::vector<std::vector<bool > >& grid,
190
251
float robotRadius,
@@ -207,12 +268,17 @@ bool FullCoveragePathPlanner::parseGrid(nav_msgs::OccupancyGrid const& cpp_grid_
207
268
tile_size_ = nodeSize * cpp_grid_.info .resolution ; // Size of a tile in meters
208
269
grid_origin_.x = cpp_grid_.info .origin .position .x ; // x-origin in meters
209
270
grid_origin_.y = cpp_grid_.info .origin .position .y ; // y-origin in meters
271
+ ROS_INFO (" costmap resolution: %g" , cpp_grid_.info .resolution );
272
+ ROS_INFO (" tile size: %g" , tile_size_);
273
+ ROS_INFO (" grid origin: (%g, %g)" , grid_origin_.x , grid_origin_.y );
210
274
211
275
// Scale starting point
212
276
scaledStart.x = static_cast <unsigned int >(clamp ((realStart.pose .position .x - grid_origin_.x ) / tile_size_, 0.0 ,
213
277
floor (cpp_grid_.info .width / tile_size_)));
214
278
scaledStart.y = static_cast <unsigned int >(clamp ((realStart.pose .position .y - grid_origin_.y ) / tile_size_, 0.0 ,
215
279
floor (cpp_grid_.info .height / tile_size_)));
280
+ ROS_INFO (" real start: (%g, %g)" , realStart.pose .position .x , realStart.pose .position .y );
281
+ ROS_INFO (" scaled start: (%u, %u)" , scaledStart.x , scaledStart.y );
216
282
217
283
// Scale grid
218
284
for (iy = 0 ; iy < nRows; iy = iy + nodeSize)
0 commit comments