-
Notifications
You must be signed in to change notification settings - Fork 114
/
test_planner_3d.cpp
53 lines (44 loc) · 1.94 KB
/
test_planner_3d.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#include "timer.hpp"
#include "read_map.hpp"
#include <jps_basis/data_utils.h>
#include <jps_planner/jps_planner/jps_planner.h>
using namespace JPS;
int main(int argc, char ** argv){
if(argc != 2) {
printf(ANSI_COLOR_RED "Input yaml required!\n" ANSI_COLOR_RESET);
return -1;
}
// Read the map from yaml
MapReader<Vec3i, Vec3f> reader(argv[1], true); // Map read from a given file
if(!reader.exist()) {
printf(ANSI_COLOR_RED "Cannot read input file [%s]!\n" ANSI_COLOR_RESET, argv[1]);
return -1;
}
// store map in map_util
std::shared_ptr<VoxelMapUtil> map_util = std::make_shared<VoxelMapUtil>();
map_util->setMap(reader.origin(), reader.dim(), reader.data(), reader.resolution());
const Vec3f start(reader.start(0), reader.start(1), reader.start(2));
const Vec3f goal(reader.goal(0), reader.goal(1), reader.goal(2));
std::unique_ptr<JPSPlanner3D> planner_ptr(new JPSPlanner3D(true)); // Declare a planner
planner_ptr->setMapUtil(map_util); // Set collision checking function
planner_ptr->updateMap();
Timer time_jps(true);
bool valid_jps = planner_ptr->plan(start, goal, 1, true); // Plan from start to goal using JPS
double dt_jps = time_jps.Elapsed().count();
printf("JPS Planner takes: %f ms\n", dt_jps);
printf("JPS Path Distance: %f\n", total_distance3f(planner_ptr->getRawPath()));
printf("JPS Path: \n");
auto path_jps = planner_ptr->getRawPath();
for(const auto& it: path_jps)
std::cout << it.transpose() << std::endl;
Timer time_astar(true);
bool valid_astar = planner_ptr->plan(start, goal, 1, false); // Plan from start to goal using A*
double dt_astar = time_astar.Elapsed().count();
printf("AStar Planner takes: %f ms\n", dt_astar);
printf("AStar Path Distance: %f\n", total_distance3f(planner_ptr->getRawPath()));
printf("AStar Path: \n");
auto path_astar = planner_ptr->getRawPath();
for(const auto& it: path_astar)
std::cout << it.transpose() << std::endl;
return 0;
}