43 #include <gtest/gtest.h> 46 using geometry_msgs::Point;
50 std::vector<Point> polygon;
67 nh.
setParam(
"/inflation_tests/inflation/inflation_radius", inflation_radius);
77 std::map<double, std::vector<CellData> > m;
79 m[0].push_back(initial);
80 for (std::map<
double, std::vector<CellData> >::iterator bin = m.begin(); bin != m.end(); ++bin)
82 for (
int i = 0; i < bin->second.size(); ++i)
84 const CellData& cell = bin->second[i];
90 double dist =
hypot(dx, dy);
92 unsigned char expected_cost = ilayer->
computeCost(dist);
93 ASSERT_TRUE(costmap->
getCost(cell.
x_, cell.
y_) >= expected_cost);
95 if (dist > inflation_radius)
100 if (dist == bin->first)
111 m[dist].push_back(data);
117 m[dist].push_back(data);
123 m[dist].push_back(data);
129 m[dist].push_back(data);
137 TEST(costmap, testAdjacentToObstacleCanStillMove){
144 std::vector<Point> polygon =
setRadii(layers, 2.1, 2.3, 4.1);
163 TEST(costmap, testInflationShouldNotCreateUnknowns){
170 std::vector<Point> polygon =
setRadii(layers, 2.1, 2.3, 4.1);
188 TEST(costmap, testCostFunctionCorrectness){
195 std::vector<Point> polygon =
setRadii(layers, 5.0, 6.25, 10.5);
210 for(
unsigned int i = 0; i <= (
unsigned int)ceil(5.0); i++){
226 for(
unsigned int i = (
unsigned int)(ceil(5.0) + 1); i <= (
unsigned int)ceil(10.5); i++){
227 unsigned char expectedValue = ilayer->
computeCost(i/1.0);
228 ASSERT_EQ(map->
getCost(50 + i, 50), expectedValue);
256 TEST(costmap, testInflationOrderCorrectness){
263 const double inflation_radius = 4.1;
264 std::vector<Point> polygon =
setRadii(layers, 2.1, 2.3, inflation_radius);
291 std::vector<Point> polygon =
setRadii(layers, 1, 1, 1);
355 std::vector<Point> polygon =
setRadii(layers, 1, 1, 1);
383 std::vector<Point> polygon =
setRadii(layers, 1, 1.75, 3);
413 int main(
int argc,
char** argv){
414 ros::init(argc, argv,
"inflation_tests");
415 testing::InitGoogleTest(&argc, argv);
416 return RUN_ALL_TESTS();
unsigned int countValues(costmap_2d::Costmap2D &costmap, unsigned char value, bool equal=true)
unsigned int getSizeInCellsX() const
Accessor for the x size of the costmap in cells.
costmap_2d::InflationLayer * addInflationLayer(costmap_2d::LayeredCostmap &layers, tf2_ros::Buffer &tf)
void resizeMap(unsigned int size_x, unsigned int size_y, double resolution, double origin_x, double origin_y, bool size_locked=false)
unsigned int getSizeInCellsY() const
Accessor for the y size of the costmap in cells.
costmap_2d::ObstacleLayer * addObstacleLayer(costmap_2d::LayeredCostmap &layers, tf2_ros::Buffer &tf)
int main(int argc, char **argv)
ROSCPP_DECL void init(int &argc, char **argv, const std::string &name, uint32_t options=0)
unsigned int getIndex(unsigned int mx, unsigned int my) const
Given two map coordinates... compute the associated index.
INLINE Rall1d< T, V, S > hypot(const Rall1d< T, V, S > &y, const Rall1d< T, V, S > &x)
void setFootprint(const std::vector< geometry_msgs::Point > &footprint_spec)
Updates the stored footprint, updates the circumscribed and inscribed radii, and calls onFootprintCha...
static const unsigned char FREE_SPACE
virtual unsigned char computeCost(double distance) const
Given a distance, compute a cost.
static const unsigned char INSCRIBED_INFLATED_OBSTACLE
TEST(costmap, testAdjacentToObstacleCanStillMove)
void validatePointInflation(unsigned int mx, unsigned int my, Costmap2D *costmap, InflationLayer *ilayer, double inflation_radius)
Storage for cell information used during obstacle inflation.
std::vector< Point > setRadii(LayeredCostmap &layers, double length, double width, double inflation_radius)
static const unsigned char LETHAL_OBSTACLE
void setParam(const std::string &key, const XmlRpc::XmlRpcValue &v) const
static const unsigned char NO_INFORMATION
void addObservation(costmap_2d::ObstacleLayer *olayer, double x, double y, double z=0.0, double ox=0.0, double oy=0.0, double oz=MAX_Z)
A 2D costmap provides a mapping between points in the world and their associated "costs".
void printMap(costmap_2d::Costmap2D &costmap)
Instantiates different layer plugins and aggregates them into one score.
void updateMap(double robot_x, double robot_y, double robot_yaw)
Update the underlying costmap with new data. If you want to update the map outside of the update loop...
void addStaticLayer(costmap_2d::LayeredCostmap &layers, tf2_ros::Buffer &tf)
unsigned char getCost(unsigned int mx, unsigned int my) const
Get the cost of a cell in the costmap.