00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035 #include <ros/ros.h>
00036 #include <nav_core2/exceptions.h>
00037 #include <global_planner_tests/easy_costmap.h>
00038 #include <global_planner_tests/global_planner_tests.h>
00039 #include <dlux_global_planner/dlux_global_planner.h>
00040 #include <nav_grid/coordinate_conversion.h>
00041 #include <gtest/gtest.h>
00042 #include <string>
00043 #include <vector>
00044
00045 const std::string map_path = "package://dlux_plugins/test/robert_frost.png";
00046
00047 int barrier_x = 5;
00048 int barrier_y0 = 1;
00049 int barrier_y1 = 4;
00050
00051 void setBarrier(nav_core2::Costmap& costmap, const unsigned char value)
00052 {
00053 for (int y=barrier_y0; y <= barrier_y1; y++)
00054 {
00055 costmap.setCost(barrier_x, y, value);
00056 }
00057 }
00058
00059 bool pathsEqual(const nav_2d_msgs::Path2D& path_a, const nav_2d_msgs::Path2D& path_b)
00060 {
00061 if (path_a.header.frame_id != path_b.header.frame_id || path_a.poses.size() != path_b.poses.size())
00062 {
00063 return false;
00064 }
00065 for (unsigned int i=0; i < path_a.poses.size(); i++)
00066 {
00067 if (path_a.poses[i].x != path_b.poses[i].x || path_a.poses[i].y != path_b.poses[i].y
00068 || path_a.poses[i].theta != path_b.poses[i].theta)
00069 {
00070 return false;
00071 }
00072 }
00073 return true;
00074 }
00075
00084 void replanning_test(const std::string& ns, bool expect_different,
00085 bool path_caching = false, double improvement_threshold = -1.0)
00086 {
00087 TFListenerPtr tf = std::make_shared<tf::TransformListener>(ros::Duration(10));
00088 std::shared_ptr<global_planner_tests::EasyCostmap> easy_costmap =
00089 std::make_shared<global_planner_tests::EasyCostmap>(map_path, 1.0);
00090
00091 dlux_global_planner::DluxGlobalPlanner global_planner;
00092 ros::NodeHandle nh("~"), private_nh("~/" + ns);
00093 private_nh.setParam("path_caching", path_caching);
00094 private_nh.setParam("improvement_threshold", improvement_threshold);
00095 private_nh.setParam("potential_calculator", "dlux_plugins::Dijkstra");
00096 private_nh.setParam("traceback", "dlux_plugins::GridPath");
00097 private_nh.setParam("print_statistics", true);
00098 global_planner.initialize(nh, ns, tf, easy_costmap);
00099
00100 nav_core2::Costmap& costmap = *easy_costmap;
00101 const nav_grid::NavGridInfo& info = costmap.getInfo();
00102
00103 nav_2d_msgs::Pose2DStamped start;
00104 nav_2d_msgs::Pose2DStamped goal;
00105
00106 start.header.frame_id = info.frame_id;
00107 gridToWorld(info, 2, 5, start.pose.x, start.pose.y);
00108 goal.header.frame_id = info.frame_id;
00109 gridToWorld(info, 17, 5, goal.pose.x, goal.pose.y);
00110
00111
00112 setBarrier(costmap, 254);
00113
00114
00115 nav_2d_msgs::Path2D first_path = global_planner.makePlan(start, goal);
00116
00117
00118 setBarrier(costmap, 0);
00119
00120
00121 nav_2d_msgs::Path2D second_path = global_planner.makePlan(start, goal);
00122
00123 if (expect_different)
00124 {
00125 EXPECT_FALSE(pathsEqual(first_path, second_path));
00126 }
00127 else
00128 {
00129 EXPECT_TRUE(pathsEqual(first_path, second_path));
00130 }
00131 }
00132
00133 TEST(GlobalPlannerReplanning, no_cache)
00134 {
00135
00136 replanning_test("no_cache", true);
00137 }
00138
00139 TEST(GlobalPlannerReplanning, any_cache)
00140 {
00141
00142 replanning_test("any_cache", false, true);
00143 }
00144
00145 TEST(GlobalPlannerReplanning, improve_cache)
00146 {
00147
00148 replanning_test("improve_cache", true, true, 0.0);
00149 }
00150
00151 TEST(GlobalPlannerReplanning, big_improve)
00152 {
00153
00154 replanning_test("big_improve", false, true, 1000.0);
00155 }
00156
00157 int main(int argc, char **argv)
00158 {
00159 ros::init(argc, argv, "global_oscillation_test");
00160 testing::InitGoogleTest(&argc, argv);
00161 return RUN_ALL_TESTS();
00162 }