map_grid_test.cpp
Go to the documentation of this file.
00001 /*
00002  * map_grid_test.cpp
00003  *
00004  *  Created on: May 2, 2012
00005  *      Author: tkruse
00006  */
00007 #include <queue>
00008 
00009 #include <gtest/gtest.h>
00010 
00011 #include <base_local_planner/map_grid.h>
00012 #include <base_local_planner/map_cell.h>
00013 
00014 #include "wavefront_map_accessor.h"
00015 
00016 namespace base_local_planner {
00017 
00018 TEST(MapGridTest, initNull){
00019   MapGrid map_grid;
00020   EXPECT_EQ(0, map_grid.size_x_);
00021   EXPECT_EQ(0, map_grid.size_y_);
00022 }
00023 
00024 TEST(MapGridTest, operatorBrackets){
00025   MapGrid map_grid(10, 10);
00026   map_grid(3, 5).target_dist = 5;
00027   EXPECT_EQ(5, map_grid.getCell(3, 5).target_dist);
00028 }
00029 
00030 TEST(MapGridTest, copyConstructor){
00031   MapGrid map_grid(10, 10);
00032   map_grid(3, 5).target_dist = 5;
00033   MapGrid map_grid2;
00034   map_grid2 = map_grid;
00035   EXPECT_EQ(5, map_grid(3, 5).target_dist);
00036 }
00037 
00038 TEST(MapGridTest, getIndex){
00039   MapGrid map_grid(10, 10);
00040   EXPECT_EQ(53, map_grid.getIndex(3, 5));
00041 }
00042 
00043 TEST(MapGridTest, reset){
00044   MapGrid map_grid(10, 10);
00045   map_grid(0, 0).target_dist = 1;
00046   map_grid(0, 0).target_mark = true;
00047   map_grid(0, 0).within_robot = true;
00048   map_grid(3, 5).target_dist = 1;
00049   map_grid(3, 5).target_mark = true;
00050   map_grid(3, 5).within_robot = true;
00051   map_grid(9, 9).target_dist = 1;
00052   map_grid(9, 9).target_mark = true;
00053   map_grid(9, 9).within_robot = true;
00054   EXPECT_EQ(1, map_grid(0, 0).target_dist);
00055   EXPECT_EQ(true, map_grid(0, 0).target_mark);
00056   EXPECT_EQ(true, map_grid(0, 0).within_robot);
00057   EXPECT_EQ(1, map_grid(3, 5).target_dist);
00058   EXPECT_EQ(true, map_grid(3, 5).target_mark);
00059   EXPECT_EQ(true, map_grid(3, 5).within_robot);
00060   EXPECT_EQ(1, map_grid(9, 9).target_dist);
00061   EXPECT_EQ(true, map_grid(9, 9).target_mark);
00062   EXPECT_EQ(true, map_grid(9, 9).within_robot);
00063 
00064   map_grid.resetPathDist();
00065 
00066   EXPECT_EQ(map_grid.unreachableCellCosts(), map_grid(9, 9).target_dist);
00067   EXPECT_EQ(false, map_grid(9, 9).target_mark);
00068   EXPECT_EQ(false, map_grid(9, 9).within_robot);
00069   EXPECT_EQ(map_grid.unreachableCellCosts(), map_grid(3, 5).target_dist);
00070   EXPECT_EQ(false, map_grid(3, 5).target_mark);
00071   EXPECT_EQ(false, map_grid(3, 5).within_robot);
00072   EXPECT_EQ(map_grid.unreachableCellCosts(), map_grid(0, 0).target_dist);
00073   EXPECT_EQ(false, map_grid(0, 0).target_mark);
00074   EXPECT_EQ(false, map_grid(0, 0).within_robot);
00075 }
00076 
00077 
00078 TEST(MapGridTest, properGridConstruction){
00079   MapGrid mg(10, 10);
00080   MapCell mc;
00081 
00082   for(int i = 0; i < 10; ++i){
00083     for(int j = 0; j < 10; ++j){
00084       EXPECT_FLOAT_EQ(mg(i, j).cx, i);
00085       EXPECT_FLOAT_EQ(mg(i, j).cy, j);
00086     }
00087   }
00088 }
00089 
00090 TEST(MapGridTest, sizeCheck){
00091   MapGrid mg(10, 10);
00092   MapCell mc;
00093 
00094   mg.sizeCheck(20, 25);
00095 
00096   for(int i = 0; i < 20; ++i){
00097     for(int j = 0; j < 25; ++j){
00098       EXPECT_FLOAT_EQ(mg(i, j).cx, i);
00099       EXPECT_FLOAT_EQ(mg(i, j).cy, j);
00100     }
00101   }
00102 }
00103 
00104 TEST(MapGridTest, adjustPlanEmpty){
00105   MapGrid mg(10, 10);
00106   const std::vector<geometry_msgs::PoseStamped> global_plan_in;
00107   std::vector<geometry_msgs::PoseStamped> global_plan_out;
00108   double resolution = 0;
00109   mg.adjustPlanResolution(global_plan_in, global_plan_out, resolution);
00110   EXPECT_EQ(0, global_plan_out.size());
00111 }
00112 
00113 TEST(MapGridTest, adjustPlan){
00114   MapGrid mg(10, 10);
00115   std::vector<geometry_msgs::PoseStamped> global_plan_in;
00116   std::vector<geometry_msgs::PoseStamped> global_plan_out;
00117   double resolution = 1;
00118   geometry_msgs::PoseStamped start;
00119   start.pose.position.x = 1;
00120   start.pose.position.y = 1;
00121   geometry_msgs::PoseStamped end;
00122   end.pose.position.x = 5;
00123   end.pose.position.y = 5;
00124   global_plan_in.push_back(start);
00125   global_plan_in.push_back(end);
00126   mg.adjustPlanResolution(global_plan_in, global_plan_out, resolution);
00127   
00128   EXPECT_EQ(1, global_plan_out[0].pose.position.x);
00129   EXPECT_EQ(1, global_plan_out[0].pose.position.y);
00130   EXPECT_EQ(5, global_plan_out.back().pose.position.x);
00131   EXPECT_EQ(5, global_plan_out.back().pose.position.y);
00132 
00133   for (unsigned int i = 1; i < global_plan_out.size(); ++i)
00134   {
00135     geometry_msgs::Point& p0 = global_plan_out[i - 1].pose.position;
00136     geometry_msgs::Point& p1 = global_plan_out[i].pose.position;
00137     double d = hypot(p0.x - p1.x, p0.y - p1.y);
00138     EXPECT_LT(d, resolution);
00139   }
00140 }
00141 
00142 TEST(MapGridTest, adjustPlan2){
00143   std::vector<geometry_msgs::PoseStamped> base_plan, result;
00144 
00145   // Push two points, at (0,0) and (0,1). Gap is 1 meter
00146   base_plan.push_back(geometry_msgs::PoseStamped());
00147   base_plan.push_back(geometry_msgs::PoseStamped());
00148   base_plan.back().pose.position.y = 1.0;
00149 
00150   // resolution >= 1, path won't change
00151   MapGrid::adjustPlanResolution(base_plan, result, 2.0);
00152   EXPECT_EQ(2, result.size());
00153   result.clear();
00154   MapGrid::adjustPlanResolution(base_plan, result, 1.0);
00155   EXPECT_EQ(2, result.size());
00156   result.clear();
00157 
00158   // 0.5 <= resolution < 1.0, one point should be added in the middle
00159   MapGrid::adjustPlanResolution(base_plan, result, 0.8);
00160   EXPECT_EQ(3, result.size());
00161   result.clear();
00162   MapGrid::adjustPlanResolution(base_plan, result, 0.5);
00163   EXPECT_EQ(3, result.size());
00164   result.clear();
00165 
00166   // 0.333 <= resolution < 0.5, two points should be added in the middle
00167   MapGrid::adjustPlanResolution(base_plan, result, 0.34);
00168   EXPECT_EQ(4, result.size());
00169   result.clear();
00170 
00171   // 0.25 <= resolution < 0.333, three points should be added in the middle
00172   MapGrid::adjustPlanResolution(base_plan, result, 0.32);
00173   EXPECT_EQ(5, result.size());
00174   result.clear();
00175 
00176   MapGrid::adjustPlanResolution(base_plan, result, 0.1);
00177   EXPECT_EQ(11, result.size());
00178   result.clear();
00179 }
00180 
00181 TEST(MapGridTest, distancePropagation){
00182   MapGrid mg(10, 10);
00183 
00184   WavefrontMapAccessor* wa = new WavefrontMapAccessor(&mg, .25);
00185   std::queue<MapCell*> dist_queue;
00186   mg.computeTargetDistance(dist_queue, *wa);
00187   EXPECT_EQ(false, mg(0, 0).target_mark);
00188 
00189   MapCell& mc = mg.getCell(0, 0);
00190   mc.target_dist = 0.0;
00191   mc.target_mark = true;
00192   dist_queue.push(&mc);
00193   mg.computeTargetDistance(dist_queue, *wa);
00194   EXPECT_EQ(true, mg(0, 0).target_mark);
00195   EXPECT_EQ(0.0,  mg(0, 0).target_dist);
00196   EXPECT_EQ(true, mg(1, 1).target_mark);
00197   EXPECT_EQ(2.0,  mg(1, 1).target_dist);
00198   EXPECT_EQ(true, mg(0, 4).target_mark);
00199   EXPECT_EQ(4.0,  mg(0, 4).target_dist);
00200   EXPECT_EQ(true, mg(4, 0).target_mark);
00201   EXPECT_EQ(4.0,  mg(4, 0).target_dist);
00202   EXPECT_EQ(true, mg(9, 9).target_mark);
00203   EXPECT_EQ(18.0, mg(9, 9).target_dist);
00204 }
00205 
00206 }


base_local_planner
Author(s): Eitan Marder-Eppstein, Eric Perko, contradict@gmail.com
autogenerated on Sun Mar 3 2019 03:46:30