map_grid.h
Go to the documentation of this file.
1 /*********************************************************************
2  * Software License Agreement (BSD License)
3  *
4  * Copyright (c) 2008, Willow Garage, Inc.
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  *
11  * * Redistributions of source code must retain the above copyright
12  * notice, this list of conditions and the following disclaimer.
13  * * Redistributions in binary form must reproduce the above
14  * copyright notice, this list of conditions and the following
15  * disclaimer in the documentation and/or other materials provided
16  * with the distribution.
17  * * Neither the name of the Willow Garage nor the names of its
18  * contributors may be used to endorse or promote products derived
19  * from this software without specific prior written permission.
20  *
21  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
27  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
31  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32  * POSSIBILITY OF SUCH DAMAGE.
33  *********************************************************************/
34 #ifndef TRAJECTORY_ROLLOUT_MAP_GRID_H_
35 #define TRAJECTORY_ROLLOUT_MAP_GRID_H_
36 
37 #include <vector>
38 #include <iostream>
40 #include <ros/console.h>
41 #include <ros/ros.h>
42 
44 #include <costmap_2d/costmap_2d.h>
45 #include <geometry_msgs/PoseStamped.h>
46 
47 namespace base_local_planner{
52  class MapGrid{
53  public:
57  MapGrid();
58 
64  MapGrid(unsigned int size_x, unsigned int size_y);
65 
66 
73  inline MapCell& operator() (unsigned int x, unsigned int y){
74  return map_[size_x_ * y + x];
75  }
76 
83  inline MapCell operator() (unsigned int x, unsigned int y) const {
84  return map_[size_x_ * y + x];
85  }
86 
87  inline MapCell& getCell(unsigned int x, unsigned int y){
88  return map_[size_x_ * y + x];
89  }
90 
94  ~MapGrid(){}
95 
100  MapGrid(const MapGrid& mg);
101 
106  MapGrid& operator= (const MapGrid& mg);
107 
111  void resetPathDist();
112 
118  void sizeCheck(unsigned int size_x, unsigned int size_y);
119 
123  void commonInit();
124 
131  size_t getIndex(int x, int y);
132 
136  inline double obstacleCosts() {
137  return map_.size();
138  }
139 
144  inline double unreachableCellCosts() {
145  return map_.size() + 1;
146  }
147 
153  inline bool updatePathCell(MapCell* current_cell, MapCell* check_cell,
154  const costmap_2d::Costmap2D& costmap);
155 
163  static void adjustPlanResolution(const std::vector<geometry_msgs::PoseStamped>& global_plan_in,
164  std::vector<geometry_msgs::PoseStamped>& global_plan_out, double resolution);
165 
170  void computeTargetDistance(std::queue<MapCell*>& dist_queue, const costmap_2d::Costmap2D& costmap);
171 
176  void computeGoalDistance(std::queue<MapCell*>& dist_queue, const costmap_2d::Costmap2D& costmap);
177 
181  void setTargetCells(const costmap_2d::Costmap2D& costmap, const std::vector<geometry_msgs::PoseStamped>& global_plan);
182 
186  void setLocalGoal(const costmap_2d::Costmap2D& costmap,
187  const std::vector<geometry_msgs::PoseStamped>& global_plan);
188 
189  double goal_x_, goal_y_;
191  unsigned int size_x_, size_y_;
192 
193  private:
194 
195  std::vector<MapCell> map_;
196 
197  };
198 };
199 
200 #endif
base_local_planner::MapGrid::commonInit
void commonInit()
Utility to share initialization code across constructors.
Definition: map_grid.cpp:57
base_local_planner::MapGrid::unreachableCellCosts
double unreachableCellCosts()
Definition: map_grid.h:176
base_local_planner::MapGrid::size_y_
unsigned int size_y_
The dimensions of the grid.
Definition: map_grid.h:223
base_local_planner::MapGrid::MapGrid
MapGrid()
Creates a 0x0 map by default.
Definition: map_grid.cpp:40
base_local_planner::MapGrid::goal_x_
double goal_x_
Definition: map_grid.h:221
ros.h
costmap_2d.h
base_local_planner::MapGrid::adjustPlanResolution
static void adjustPlanResolution(const std::vector< geometry_msgs::PoseStamped > &global_plan_in, std::vector< geometry_msgs::PoseStamped > &global_plan_out, double resolution)
Definition: map_grid.cpp:133
base_local_planner::MapGrid::map_
std::vector< MapCell > map_
Storage for the MapCells.
Definition: map_grid.h:227
base_local_planner::MapGrid::~MapGrid
~MapGrid()
Destructor for a MapGrid.
Definition: map_grid.h:126
costmap_2d::Costmap2D
base_local_planner::MapGrid::size_x_
unsigned int size_x_
Definition: map_grid.h:223
base_local_planner::MapGrid::operator()
MapCell & operator()(unsigned int x, unsigned int y)
Returns a map cell accessed by (col, row)
Definition: map_grid.h:105
console.h
base_local_planner::MapGrid::obstacleCosts
double obstacleCosts()
Definition: map_grid.h:168
base_local_planner::MapGrid::setLocalGoal
void setLocalGoal(const costmap_2d::Costmap2D &costmap, const std::vector< geometry_msgs::PoseStamped > &global_plan)
Update what cell is considered the next local goal.
Definition: map_grid.cpp:210
base_local_planner::MapGrid::updatePathCell
bool updatePathCell(MapCell *current_cell, MapCell *check_cell, const costmap_2d::Costmap2D &costmap)
Used to update the distance of a cell in path distance computation.
Definition: map_grid.cpp:103
base_local_planner::MapGrid::resetPathDist
void resetPathDist()
reset path distance fields for all cells
Definition: map_grid.cpp:125
base_local_planner::MapGrid::computeTargetDistance
void computeTargetDistance(std::queue< MapCell * > &dist_queue, const costmap_2d::Costmap2D &costmap)
Compute the distance from each cell in the local map grid to the planned path.
Definition: map_grid.cpp:255
map_cell.h
base_local_planner::MapGrid::computeGoalDistance
void computeGoalDistance(std::queue< MapCell * > &dist_queue, const costmap_2d::Costmap2D &costmap)
Compute the distance from each cell in the local map grid to the local goal point.
base_local_planner::MapGrid::getCell
MapCell & getCell(unsigned int x, unsigned int y)
Definition: map_grid.h:119
base_local_planner::MapGrid::operator=
MapGrid & operator=(const MapGrid &mg)
Assignment operator for a MapGrid.
Definition: map_grid.cpp:77
base_local_planner::MapGrid::sizeCheck
void sizeCheck(unsigned int size_x, unsigned int size_y)
check if we need to resize
Definition: map_grid.cpp:84
base_local_planner::MapGrid::goal_y_
double goal_y_
The goal distance was last computed from.
Definition: map_grid.h:221
base_local_planner::MapGrid::setTargetCells
void setTargetCells(const costmap_2d::Costmap2D &costmap, const std::vector< geometry_msgs::PoseStamped > &global_plan)
Update what cells are considered path based on the global plan.
Definition: map_grid.cpp:171
base_local_planner
Definition: costmap_model.h:44
base_local_planner::MapGrid::getIndex
size_t getIndex(int x, int y)
Returns a 1D index into the MapCell array for a 2D index.
Definition: map_grid.cpp:73
trajectory_inc.h
base_local_planner::MapCell
Stores path distance and goal distance information used for scoring trajectories.
Definition: map_cell.h:76


base_local_planner
Author(s): Eitan Marder-Eppstein, Eric Perko, contradict@gmail.com
autogenerated on Mon Mar 6 2023 03:50:24