OMPL Plannification
Path planning with OMPL
StateChecker.cpp
Go to the documentation of this file.
1 
9 #include "StateChecker.hpp"
10 
11 StateChecker::StateChecker(const ob::SpaceInformationPtr &si): ob::StateValidityChecker(si)
12 {
13  planningDimension = si->getStateDimension();
14 }
15 
17 {
18  if(_map !=nullptr)
19  {
20  delete _map;
21  _map = nullptr;
22  }
23 
24 }
25 
26 void StateChecker::loadMap(const std::string mapFile) //Take a look to memory mangaement for map
27 {
28  /*
29  if(_map !=nullptr)
30  {
31  delete _map;
32  _map = nullptr;
33  }
34  */
35  _map = (new octomap::OcTree(mapFile));
36  _map_res = _map->getResolution();
37 }
38 
39 void StateChecker::loadMap(octomap::OcTree* octree)
40 {
41  /*
42  if(_map !=nullptr)
43  {
44  delete _map;
45  _map = nullptr;
46  }
47  */
48  _map = octree;
49  _map_res = _map->getResolution();
50 }
51 
52 void StateChecker::setCollisionMask(double x, double y, double z)
53 {
54  _check_box.x=x;
55  _check_box.y=y;
56  _check_box.z=z;
57 }
58 
59 void StateChecker::setDepthLimit(double depth_limit)
60 {
61  _depth_limit = depth_limit;
62 }
63 
64 bool StateChecker::isValid(const ob::State *state) const
65 {
66  OcTreeNode* result;
67  point3d query; //Octomap
68  bool collision(false);
69  double node_occupancy;
70 
71  // extract the component of the state and cast it to what we expect
72  const ob::RealVectorStateSpace::StateType *pos = state->as<ob::RealVectorStateSpace::StateType>();
73 
74  //Constant depth for 2D planning (There might be a better way to implement this)
75 
76  if(planningDimension==2)
77  {
78  pos->values[2]=_depth_limit;
79  }
80 
81  //Recherche dans le collision mask autour de pos
82  for(double xi = pos->values[0]-(_check_box.x/2.0);xi <= pos->values[0]+(_check_box.x/2.0);xi=xi+_map_res)
83  for(double yi = pos->values[1]-(_check_box.y/2.0);yi <= pos->values[1]+(_check_box.y/2.0);yi=yi+_map_res)
84  for(double zi = pos->values[2]-(_check_box.z/2.0);zi <= pos->values[2]+(_check_box.z/2.0);zi=zi+_map_res){ //Trop sensible sur z
85  query.x() = xi;
86  query.y() = yi;
87  query.z() = zi;
88  result = _map->search (query); //Retourne le pointeur de la node à la position query, NULL si elle n'existe pas (terrain inconnu)
89 
90  if(result != NULL){ // Node connue
91 
92  node_occupancy = result->getOccupancy();
93 
94  if (node_occupancy > 0.4)
95  {
96  collision = true;
97  break;
98  }
99  }
100  }
101 
102  return !collision;
103 }
StateChecker(const ob::SpaceInformationPtr &si)
Constructor.
void setDepthLimit(double depth_limit)
Set the depth limit (constant for 2D checking)
void setCollisionMask(double x, double y, double z=0.2)
Set the area around every state considered for state checking.
virtual bool isValid(const ob::State *state) const
State validator.
void loadMap(const std::string mapFile)
Load the octomap where the states are checked.
~StateChecker()
Destructor.