Buran Motion Planning Framework
path_finder.h
1 #pragma once
2 
3 #include <memory>
4 #include <utility>
5 #include <unordered_map>
6 #include <set>
7 #include <unordered_set>
8 #include <scene.h>
9 #include <json/json.h>
10 #include <chrono>
11 #include "base/collider.h"
12 #include "log.h"
13 #include "solid_collider.h"
14 #include "solid_sync_collider.h"
15 #include "state.h"
16 
17 namespace bmpf {
28  class PathFinder {
29  public:
30 
34  static const int NO_ERROR = -1;
38  static const int ERROR_CAN_NOT_FIND_PATH = 1;
39 
46  PathFinder(const std::shared_ptr<bmpf::Scene> &scene, bool showTrace, int threadCnt = 1);
47 
55  std::vector<std::vector<double>>
56  findPath(const std::vector<double> &startState, const std::vector<double> &endState, int &errorCode);
57 
63  virtual bool findTick(std::vector<double> &state) = 0;
64 
70  virtual void prepare(const std::vector<double> &startState, const std::vector<double> &endState) = 0;
71 
75  virtual void buildPath() = 0;
76 
80  void updateCollider();
81 
87  virtual void paint(const std::vector<double> &state, bool onlyRobot);
88 
96  bool divideCheckPathSegment(const std::vector<double> &prevPoint, std::vector<double> nextPoint, int checkCnt);
97 
104  int divideCheckPath(std::vector<std::vector<double>> path, int checkCnt);
105 
110  static void infoPath(const std::vector<std::vector<double>> &path);
111 
117  static Json::Value getJSONPath(std::vector<std::vector<double>> path);
123  static std::vector<std::vector<double>> getPathFromJSON(const Json::Value& json);
124 
130  static void savePathToFile(std::vector<std::vector<double>> path, const std::string &filename);
131 
138  static std::vector<std::vector<double>> loadPathFromFile(const std::string &filename, std::string &scenePath);
139 
146  static std::vector<std::vector<std::vector<double>>>
147  loadPathsFromFile(const std::string &filename, std::string &scenePath);
148 
155  static std::vector<std::vector<double>> splitPath(std::vector<std::vector<double>> path, unsigned long partCnt);
156 
157 
164  bool simpleCheckPath(const std::vector<std::vector<double>> &path, double maxDist);
165 
172  bool checkState(const std::vector<double> &state);
173 
178  std::vector<double> getRandomState();
179 
187  std::vector<double> getPathStateFromTM(double tm);
188 
197  static std::vector<double> getPathStateFromTM(std::vector<std::vector<double>> &path, double tm);
198 
204  bool checkCollision(const std::vector<double> &state);
205 
210  void addObjectToScene(std::string path);
211 
216  void deleteObjectFromScene(long robotNum);
217 
223  static double calculatePathLength(std::vector<std::vector<double>> path);
224 
225  protected:
226 
230  double _pathLength{};
238  std::shared_ptr<bmpf::Scene> _scene;
246  std::shared_ptr<bmpf::Collider> _collider;
253  bool _ready;
261  std::vector<double> _endState;
265  std::vector<double> _startState;
269  std::vector<std::vector<double>> _buildedPath;
273  std::chrono::time_point<std::chrono::system_clock> _startTime;
278 
279  public:
280 
285  double getPathLength() const { return _pathLength; }
286 
291  bool isReady() const { return _ready; }
292 
297  bool getThreadCnt() const { return _threadCnt; }
298 
303  void setReady(bool ready) { _ready = ready; }
304 
309  std::vector<double> &getStartState() { return _startState; }
310 
315  std::vector<double> &getEndState() { return _endState; }
316 
321  int getErrorCode() const { return _errorCode; }
322 
327  const std::vector<std::vector<double>> &getBuildedPath() const { return _buildedPath; }
328 
333  const std::shared_ptr<bmpf::Scene> &getScene() const { return _scene; }
334 
339  const std::shared_ptr<bmpf::Collider> &getCollider() const { return _collider; }
340 
346  };
347 
348 
349 }
bmpf::PathFinder::divideCheckPath
int divideCheckPath(std::vector< std::vector< double >> path, int checkCnt)
Definition: path_finder.cpp:148
bmpf::PathFinder::_startTime
std::chrono::time_point< std::chrono::system_clock > _startTime
Definition: path_finder.h:273
bmpf::PathFinder::loadPathsFromFile
static std::vector< std::vector< std::vector< double > > > loadPathsFromFile(const std::string &filename, std::string &scenePath)
Definition: path_finder.cpp:296
bmpf::PathFinder::_startState
std::vector< double > _startState
Definition: path_finder.h:265
bmpf::PathFinder::deleteObjectFromScene
void deleteObjectFromScene(long robotNum)
Definition: path_finder.cpp:94
bmpf::PathFinder::getStartState
std::vector< double > & getStartState()
Definition: path_finder.h:309
bmpf::PathFinder::calculatePathLength
static double calculatePathLength(std::vector< std::vector< double >> path)
Definition: path_finder.cpp:267
bmpf::PathFinder::getCollider
const std::shared_ptr< bmpf::Collider > & getCollider() const
Definition: path_finder.h:339
bmpf::PathFinder::checkState
bool checkState(const std::vector< double > &state)
проверяет доступность состояния Проверяет доступность углов, после проверяет состояние на коллизии
Definition: path_finder.cpp:105
bmpf::PathFinder::getErrorCode
int getErrorCode() const
Definition: path_finder.h:321
bmpf::PathFinder::savePathToFile
static void savePathToFile(std::vector< std::vector< double >> path, const std::string &filename)
Definition: path_finder.cpp:280
bmpf::PathFinder::checkCollision
bool checkCollision(const std::vector< double > &state)
Definition: path_finder.cpp:198
bmpf::PathFinder::_buildedPath
std::vector< std::vector< double > > _buildedPath
Definition: path_finder.h:269
bmpf::PathFinder::findPath
std::vector< std::vector< double > > findPath(const std::vector< double > &startState, const std::vector< double > &endState, int &errorCode)
Definition: path_finder.cpp:47
bmpf::PathFinder::_calculationTimeInSeconds
double _calculationTimeInSeconds
Definition: path_finder.h:277
bmpf::PathFinder::loadPathFromFile
static std::vector< std::vector< double > > loadPathFromFile(const std::string &filename, std::string &scenePath)
Definition: path_finder.cpp:334
bmpf::PathFinder::getRandomState
std::vector< double > getRandomState()
Definition: path_finder.cpp:185
bmpf::PathFinder::ERROR_CAN_NOT_FIND_PATH
static const int ERROR_CAN_NOT_FIND_PATH
Definition: path_finder.h:38
bmpf::PathFinder::addObjectToScene
void addObjectToScene(std::string path)
Definition: path_finder.cpp:85
bmpf::PathFinder::simpleCheckPath
bool simpleCheckPath(const std::vector< std::vector< double >> &path, double maxDist)
Definition: path_finder.cpp:164
bmpf::PathFinder::_ready
bool _ready
Definition: path_finder.h:253
bmpf::PathFinder::_pathLength
double _pathLength
Definition: path_finder.h:230
bmpf::PathFinder::getPathFromJSON
static std::vector< std::vector< double > > getPathFromJSON(const Json::Value &json)
Definition: path_finder.cpp:356
bmpf::PathFinder::divideCheckPathSegment
bool divideCheckPathSegment(const std::vector< double > &prevPoint, std::vector< double > nextPoint, int checkCnt)
Definition: path_finder.cpp:125
bmpf::PathFinder::findTick
virtual bool findTick(std::vector< double > &state)=0
bmpf::PathFinder::_collider
std::shared_ptr< bmpf::Collider > _collider
Definition: path_finder.h:246
bmpf::PathFinder::PathFinder
PathFinder(const std::shared_ptr< bmpf::Scene > &scene, bool showTrace, int threadCnt=1)
Definition: path_finder.cpp:12
bmpf::PathFinder::infoPath
static void infoPath(const std::vector< std::vector< double >> &path)
Definition: path_finder.cpp:397
bmpf::PathFinder::setReady
void setReady(bool ready)
Definition: path_finder.h:303
bmpf::PathFinder::getJSONPath
static Json::Value getJSONPath(std::vector< std::vector< double >> path)
Definition: path_finder.cpp:375
bmpf::PathFinder::getPathLength
double getPathLength() const
Definition: path_finder.h:285
bmpf::PathFinder::splitPath
static std::vector< std::vector< double > > splitPath(std::vector< std::vector< double >> path, unsigned long partCnt)
Definition: path_finder.cpp:409
bmpf::PathFinder::_errorCode
int _errorCode
Definition: path_finder.h:234
bmpf::PathFinder::_showTrace
bool _showTrace
Definition: path_finder.h:242
bmpf::PathFinder::buildPath
virtual void buildPath()=0
bmpf::PathFinder
Базовый класс для всех планировщиков
Definition: path_finder.h:28
bmpf::PathFinder::getBuildedPath
const std::vector< std::vector< double > > & getBuildedPath() const
Definition: path_finder.h:327
bmpf::PathFinder::getPathStateFromTM
std::vector< double > getPathStateFromTM(double tm)
получить состояние по времени две соседние точки считаются разделёнными единичным временным интервало...
Definition: path_finder.cpp:218
bmpf::PathFinder::prepare
virtual void prepare(const std::vector< double > &startState, const std::vector< double > &endState)=0
bmpf::PathFinder::_endState
std::vector< double > _endState
Definition: path_finder.h:261
bmpf::PathFinder::getThreadCnt
bool getThreadCnt() const
Definition: path_finder.h:297
bmpf::PathFinder::updateCollider
void updateCollider()
Definition: path_finder.cpp:114
bmpf::PathFinder::getEndState
std::vector< double > & getEndState()
Definition: path_finder.h:315
bmpf::PathFinder::_threadCnt
bool _threadCnt
Definition: path_finder.h:257
bmpf::PathFinder::paint
virtual void paint(const std::vector< double > &state, bool onlyRobot)
Definition: path_finder.cpp:207
bmpf::PathFinder::isReady
bool isReady() const
Definition: path_finder.h:291
bmpf::PathFinder::NO_ERROR
static const int NO_ERROR
Definition: path_finder.h:34
bmpf::PathFinder::getCalculationTimeInSeconds
double getCalculationTimeInSeconds() const
Definition: path_finder.h:345
bmpf::PathFinder::getScene
const std::shared_ptr< bmpf::Scene > & getScene() const
Definition: path_finder.h:333
bmpf::PathFinder::_scene
std::shared_ptr< bmpf::Scene > _scene
Definition: path_finder.h:238