route_generator.cpp
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 
30 
31 namespace multi_robot_router
32 {
33 std::vector<std::vector<Checkpoint>> RouteGenerator::generatePath(const std::vector<std::vector<RouteVertex>> &_paths, const RouteCoordinator &routeQuerry_) const
34 {
35  std::vector<std::vector<Checkpoint>> generatedPaths;
36 
37  for (uint32_t i = 0; i < _paths.size(); i++)
38  {
39  std::vector<Checkpoint> generatedPath;
40 
41  for (uint32_t j = 0; j < _paths[i].size(); j++)
42  {
43  if (_paths[i][j].direction == RouteVertex::path_direction::none)
44  {
45  generatedPath.clear();
46  return generatedPaths;
47  }
48 
49  Checkpoint seg;
50  seg = createElement(_paths[i][j]);
51 
52  addPreconditions(seg, _paths[i][j], i, _paths, routeQuerry_);
53  generatedPath.push_back(seg);
54  }
55 
56  generatedPaths.push_back(generatedPath);
57  }
58 
59  return generatedPaths;
60 }
61 
63 {
64  Checkpoint ps;
65 
67  {
68  ps.segId = _element.getSegment().getSegmentId();
69  ps.end[0] = _element.getSegment().getStart()[0];
70  ps.end[1] = _element.getSegment().getStart()[1];
71  ps.start[0] = _element.getSegment().getEnd()[0];
72  ps.start[1] = _element.getSegment().getEnd()[1];
73 
74  float angle = atan2(ps.start[1] - ps.end[1], ps.start[0] - ps.end[0]);
75  ps.start[2] = angle;
76  ps.end[2] = angle;
77  }
78  else
79  {
80  ps.segId = _element.getSegment().getSegmentId();
81  ps.end[0] = _element.getSegment().getEnd()[0];
82  ps.end[1] = _element.getSegment().getEnd()[1];
83  ps.start[0] = _element.getSegment().getStart()[0];
84  ps.start[1] = _element.getSegment().getStart()[1];
85 
86  float angle = atan2(ps.end[1] - ps.start[1], ps.end[0] - ps.start[0]);
87  ps.start[2] = angle;
88  ps.end[2] = angle;
89  }
90 
91  return ps;
92 }
93 
94 void RouteGenerator::addPreconditions(Checkpoint &_segment, const RouteVertex &_segToFind, const uint32_t _pathNr, const std::vector<std::vector<RouteVertex>> &_paths, const RouteCoordinator &routeQuerry_) const
95 {
96  std::vector<std::pair<uint32_t, float>> list = routeQuerry_.getListOfRobotsHigherPrioritizedRobots(_pathNr, _segToFind.getSegment().getSegmentId(), _segToFind.potential);
97  _segment.preconditions.clear();
98 
99  for (const std::pair<uint32_t, float> &rob : list)
100  {
101  bool found = false;
102 
103  for (uint32_t i = 0; i < _paths[rob.first].size(); i++)
104  {
105  if (_paths[rob.first][i].potential >= rob.second)
106  {
108  p.robotId = rob.first;
109  p.stepCondition = i;
110  _segment.updatePreconditions(p);
111 
112  found = true;
113  break;
114  }
115  }
116  }
117 }
118 } // namespace multi_robot_router
uint32_t getSegmentId() const
Definition: srr_utils.cpp:60
std::vector< Precondition > preconditions
Definition: mrr_utils.h:54
void updatePreconditions(const Precondition &n_pc)
adds or updates a precondition of the checkpoint
Definition: mrr_utils.h:95
TFSIMD_FORCE_INLINE tfScalar angle(const Quaternion &q1, const Quaternion &q2)
std::vector< std::vector< Checkpoint > > generatePath(const std::vector< std::vector< RouteVertex >> &_paths, const RouteCoordinator &routeQuerry_) const
generates a final Routing Table containing Segment List and Preconditions to other robots ...
Checkpoint createElement(const RouteVertex &_element) const
const Eigen::Vector2d & getEnd() const
Definition: srr_utils.cpp:45
const Segment & getSegment() const
Definition: srr_utils.cpp:151
const Eigen::Vector2d & getStart() const
Definition: srr_utils.cpp:64
void addPreconditions(Checkpoint &_segment, const RouteVertex &_segToFind, const uint32_t _pathNr, const std::vector< std::vector< RouteVertex >> &_paths, const RouteCoordinator &routeQuerry_) const
virtual std::vector< std::pair< uint32_t, float > > getListOfRobotsHigherPrioritizedRobots(const uint32_t _robot, const uint32_t _segId, const int32_t _potential) const =0
returns all robots which pass the segment before the given robot and a given time ...


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