ShortestPathFasterAlgorithm.h
Go to the documentation of this file.
1/**
2 * This file is part of ArmarX.
3 *
4 * ArmarX is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation.
7 *
8 * ArmarX is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 * @author Fabian Reister ( fabian dot reister at kit dot edu )
17 * @date 2022
18 * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
19 * GNU General Public License
20 */
21
22#pragma once
23
24#include <optional>
25#include <vector>
26
27#include <Eigen/Core>
28
30
32{
33
35 {
36 public:
38 {
40 // float obstacleMaxDistance = 1000.F;
41
42 // float obstacleDistanceWeight = 1.3F;
44
45 /// For ARMAR-7 the following was tested:
46 float obstacleMaxDistance = 1500.F;
48 };
49
50 ShortestPathFasterAlgorithm(const Costmap& costmap, const Parameters& params);
51
52 struct Result
53 {
54 Eigen::MatrixXf distances;
55 std::vector<std::vector<Eigen::Vector2i>> parents;
56
57 // if 0, this cell is not reachable
59
61 };
62
64 {
65 std::vector<Eigen::Vector2f> path;
66
67 bool success;
68
69 operator bool() const noexcept
70 {
71 return success;
72 }
73 };
74
76 {
77 Eigen::Vector2f position;
78 Eigen::Vector2i gridIndex;
80 };
81
82 PlanningResult plan(const Eigen::Vector2f& start,
83 const Eigen::Vector2f& goal,
84 bool checkStartForCollision = true) const;
85
86 // this function can be used to create multiple paths from the same starting location
87 // without having to run the spfa planner multiple times
88 PlanningResult constructPath(const Eigen::Vector2f& start,
89 const std::vector<std::vector<Eigen::Vector2i>>& spfaParents,
90 const Eigen::Vector2f& goal) const;
91
92 Result spfa(const Eigen::Vector2f& start, bool checkStartForCollision = true) const;
93
94 // protected:
95 /**
96 * @brief Implementation highly inspired by github.com:jimmyyhwu/spatial-action-maps
97 *
98 * @param input_map
99 * @param source
100 * @return Result
101 */
102 Result spfa(const Eigen::MatrixXf& inputMap,
103 const Eigen::Vector2i& source,
104 bool checkStartForCollision = true) const;
105
106
107 private:
108 const Costmap costmap;
109
110 const Parameters params;
111 };
112
113 std::optional<ShortestPathFasterAlgorithm::ClosestReachableResult>
115 const Eigen::Vector2f& goal,
116 const Costmap& costmap);
117
118} // namespace armarx::navigation::algorithms::spfa
ShortestPathFasterAlgorithm(const Costmap &costmap, const Parameters &params)
PlanningResult constructPath(const Eigen::Vector2f &start, const std::vector< std::vector< Eigen::Vector2i > > &spfaParents, const Eigen::Vector2f &goal) const
Result spfa(const Eigen::Vector2f &start, bool checkStartForCollision=true) const
PlanningResult plan(const Eigen::Vector2f &start, const Eigen::Vector2f &goal, bool checkStartForCollision=true) const
std::optional< ShortestPathFasterAlgorithm::ClosestReachableResult > findClosestReachablePosition(const ShortestPathFasterAlgorithm::Result &spfaResult, const Eigen::Vector2f &goal, const Costmap &costmap)