router.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2017, <copyright holder> <email>
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are met:
7  * * Redistributions of source code must retain the above copyright
8  * notice, this list of conditions and the following disclaimer.
9  * * Redistributions in binary form must reproduce the above copyright
10  * notice, this list of conditions and the following disclaimer in the
11  * documentation and/or other materials provided with the distribution.
12  * * Neither the name of the <organization> nor the
13  * names of its contributors may be used to endorse or promote products
14  * derived from this software without specific prior written permission.
15  *
16  * THIS SOFTWARE IS PROVIDED BY <copyright holder> <email> ''AS IS'' AND ANY
17  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19  * DISCLAIMED. IN NO EVENT SHALL <copyright holder> <email> BE LIABLE FOR ANY
20  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26  *
27  */
28 
29 #ifndef ROUTER_H
30 #define ROUTER_H
31 
32 #include <vector>
33 #include <memory>
34 #include <opencv/cv.h>
38 
39 namespace multi_robot_router
40 {
41 class Router
42 {
43  public:
44  Router(const uint32_t _nr_robots);
45  Router();
46 
50  void resize(const uint32_t _nr_robots);
60  bool makePlan(const std::vector<Eigen::Vector3d> &_starts, const std::vector<Eigen::Vector3d> &_goals, const std::vector<float> &_radius, const cv::Mat &_map, const float &_resolution, const Eigen::Vector2d &_origin, const std::vector<Segment> &_graph, const std::vector<std::string> &_robot_names);
69  const std::vector<Checkpoint> &getRoute(const uint32_t _robot) const;
74  uint32_t getDuration_ms() const;
79  float getOverallPathLength() const;
84  float getLongestPathLength() const;
89  uint32_t getPriorityScheduleAttemps() const;
94  uint32_t getSpeedScheduleAttemps() const;
95 
96  std::shared_ptr<float> potential_;
97 
98  private:
99  //find the right segments to start from
100  bool calculateStartPoints(const std::vector<float> &_radius, const cv::Mat &_map, const float &resolution, const Eigen::Vector2d &origin, const std::vector<Segment> &_graph);
101  //Find the segment if the graph is a voronoi one
102  int32_t getSegment(const std::vector<Segment> &_graph, const Eigen::Vector2d &_pose) const;
103  //Helper dist calculation
104  float distanceToSegment(const Segment &_s, const Eigen::Vector2d &_p) const;
105  //Checks if _seg is a leave of the graph and uses the closes neighbor as segment if the width of the leave is to small
106  bool resolveSegment(const std::vector<Segment> &_graph, const uint32_t &_segId, const Eigen::Vector2d &_originPoint, const float &_radius, uint32_t &_foundSeg) const;
107  //for every path remove the first and last "segmentOptimizations_" number of segments if possible
108  void optimizePaths(const std::vector<Segment> &_graph);
109  //adds start and endpoints to the path
111  //Preprocessing endpoints for enpoint calculation threaded
112  bool preprocessEndpoints(const std::vector<float> &_radius, const float &resolution, const Eigen::Vector2d &origin, const std::vector<Segment> &_graph);
113  //Calculate endpoints
114  bool processEndpointsExpander(const cv::Mat &_map, const std::vector<Segment> &_graph, const Eigen::Vector2d &_realStart, const Eigen::Vector2d &_realGoal, Eigen::Vector2d &_voronoiStart, Eigen::Vector2d &_voronoiGoal, uint32_t &_segmentStart, uint32_t &_segmentGoal, const uint32_t _diameter, const uint32_t _index) const;
115 
116  uint32_t robot_nr_;
117  std::vector<Eigen::Vector3d> starts_;
118  std::vector<Eigen::Vector3d> goals_;
119  std::vector<Eigen::Vector2d> realGoals_;
120  std::vector<Eigen::Vector2d> realStart_;
121  std::vector<Eigen::Vector2d> voronoiGoals_;
122  std::vector<Eigen::Vector2d> voronoiStart_;
123  std::vector<uint32_t> startSegments_;
124  std::vector<uint32_t> goalSegments_;
125  std::vector<std::string> robot_names_;
126 
131  std::vector<std::vector<Checkpoint>> routingTable_;
134  uint32_t duration_;
135 
136  protected:
137  enum class goalMode
138  {
142  };
143  enum class graphType
144  {
145  voronoi,
146  random
147  };
148  enum class routerType
149  {
150  singleThread,
151  multiThreadSrr
152  };
155  float routerTimeLimit_s_ = 10.0;
156  bool segmentOptimizations_ = false;
157  bool speedRescheduling_ = true;
159  bool collisionResolver_ = true;
160 
161  void setPlannerType(routerType _type, uint32_t _nr_threads);
162 };
163 } // namespace multi_robot_router
164 #endif // PLANNER_H
int32_t getSegment(const std::vector< Segment > &_graph, const Eigen::Vector2d &_pose) const
Definition: router.cpp:237
std::vector< Eigen::Vector2d > realStart_
Definition: router.h:120
float getOverallPathLength() const
getter
Definition: router.cpp:474
standard multi robot router without multi threading (Works best in practice)
bool preprocessEndpoints(const std::vector< float > &_radius, const float &resolution, const Eigen::Vector2d &origin, const std::vector< Segment > &_graph)
Definition: router.cpp:83
MultiRobotRouterThreadedSrr mrrTs_
Definition: router.h:130
void setPlannerType(routerType _type, uint32_t _nr_threads)
Definition: router.cpp:59
std::vector< Eigen::Vector2d > realGoals_
Definition: router.h:119
std::vector< Eigen::Vector2d > voronoiGoals_
Definition: router.h:121
void resize(const uint32_t _nr_robots)
resizes the planner to a different nr of _nr_robots
Definition: router.cpp:67
PointExpander pointExpander_
with the robot id one can access the robot name
Definition: router.h:127
const std::vector< Checkpoint > & getRoute(const uint32_t _robot) const
returns the found Routing Table
Definition: router.cpp:459
float getLongestPathLength() const
getter
Definition: router.cpp:469
void optimizePaths(const std::vector< Segment > &_graph)
Definition: router.cpp:414
bool processEndpointsExpander(const cv::Mat &_map, const std::vector< Segment > &_graph, const Eigen::Vector2d &_realStart, const Eigen::Vector2d &_realGoal, Eigen::Vector2d &_voronoiStart, Eigen::Vector2d &_voronoiGoal, uint32_t &_segmentStart, uint32_t &_segmentGoal, const uint32_t _diameter, const uint32_t _index) const
Definition: router.cpp:110
MultiRobotRouter mrr_
Definition: router.h:129
bool makePlan(const std::vector< Eigen::Vector3d > &_starts, const std::vector< Eigen::Vector3d > &_goals, const std::vector< float > &_radius, const cv::Mat &_map, const float &_resolution, const Eigen::Vector2d &_origin, const std::vector< Segment > &_graph, const std::vector< std::string > &_robot_names)
generates the plan from (Vertex[odom robotPose] to Vertex[_goals]
Definition: router.cpp:328
bool resolveSegment(const std::vector< Segment > &_graph, const uint32_t &_segId, const Eigen::Vector2d &_originPoint, const float &_radius, uint32_t &_foundSeg) const
Definition: router.cpp:280
uint32_t getPriorityScheduleAttemps() const
getter
Definition: router.cpp:479
std::vector< Eigen::Vector2d > voronoiStart_
Definition: router.h:122
std::vector< Eigen::Vector3d > starts_
Definition: router.h:117
float distanceToSegment(const Segment &_s, const Eigen::Vector2d &_p) const
Definition: router.cpp:257
void setCollisionResolutionType(const SegmentExpander::CollisionResolverType _cr)
sets the CollisionResolverType used
Definition: router.cpp:54
std::vector< uint32_t > goalSegments_
Definition: router.h:124
std::vector< uint32_t > startSegments_
Definition: router.h:123
uint32_t getSpeedScheduleAttemps() const
getter
Definition: router.cpp:484
std::vector< std::vector< Checkpoint > > routingTable_
Definition: router.h:131
std::vector< std::string > robot_names_
Definition: router.h:125
std::vector< Eigen::Vector3d > goals_
Definition: router.h:118
uint32_t getDuration_ms() const
getter
Definition: router.cpp:464
bool calculateStartPoints(const std::vector< float > &_radius, const cv::Mat &_map, const float &resolution, const Eigen::Vector2d &origin, const std::vector< Segment > &_graph)
Definition: router.cpp:192
std::shared_ptr< float > potential_
Definition: router.h:96
MultiRobotRouter * multiRobotRouter_
Definition: router.h:128


tuw_multi_robot_router
Author(s): Benjamin Binder
autogenerated on Mon Jun 10 2019 15:42:49