SPFA.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 * @author Christian R. G. Dreher ( c dot dreher at kit dot edu )
18 * @date 2021
19 * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
20 * GNU General Public License
21 */
22
23#pragma once
24
25#include <optional>
26#include <vector>
27
29
38
39#include "GlobalPlanner.h"
40
42{
43
44 /**
45 * @brief Parameters for AStar
46 *
47 */
49 {
50
51 /**
52 * Spacing [mm] the planned path is resampled to before smoothing. Negative keeps the
53 * default below.
54 *
55 * This is not only a density knob. The path is a polyline, so the straight chord
56 * between two waypoints sags away from the route they were sampled from -- about 20 mm
57 * at 200 mm spacing around a 45 degree corner. Where the corridor is only a little
58 * wider than the clearance the checker enforces, that sag is the difference between a
59 * path that passes and one that clips the corner, and no amount of optimizing can
60 * remove it: it is a property of the spacing, not of the waypoint positions.
61 */
63
64 /// Used when `resampleDistance` is negative.
65 static constexpr float defaultResampleDistance{200.F};
66
68
70
71 /**
72 * Diagnostic switches for the post-processing stages. They are deliberately not part of
73 * the Aron (de-)serialization: they exist to bisect the pipeline from tools such as the
74 * `global_planning_analysis` application, not to be configured on the robot.
75 */
76 /// Run the SPFA position smoothing on the resampled path.
78
79 /**
80 * Re-apply the obstacle-aware velocity limit after orientation optimization.
81 *
82 * Disabling this exposes the velocities as the earlier stages left them, which is the
83 * only way to observe whether a stage produced a trajectory that violates the limit.
84 */
86
87 Algorithms algorithm() const override;
88 aron::data::DictPtr toAron() const override;
89
90 static SPFAParams FromAron(const aron::data::DictPtr& dict);
91 };
92
93 // Helper class
95 {
98 std::optional<algorithms::spfa::ShortestPathFasterAlgorithm::Result> plan;
99
100 /// Duration [s] of the SPFA grid search itself, which runs before `calculatePath`.
102 };
103
104 /**
105 * @brief Information about collision recovery
106 *
107 * When the robot starts in collision, this contains information about
108 * the recovery position and the original (collision) start pose.
109 */
111 {
112 core::Pose originalStartPose; ///< The original start pose (collision pose)
113 Eigen::Vector2f recoveryPosition; ///< The found recovery position (collision-free)
114 };
115
116 class SPFA;
117
119 {
120 public:
121 friend class SPFA;
124
125 SPFAImpl(const Params& params,
126 const core::GeneralConfig& generalParams,
127 const std::optional<navigation::algorithms::Costmap>& costmap);
128
129 void updateCostmap(const std::optional<navigation::algorithms::Costmap>& costmap);
130
131 std::optional<GlobalPlannerResult> plan(const core::Pose& start, const core::Pose& goal);
132
134 PlanningResult executePlannerFromPosition(const Eigen::Vector2f& startPosition);
135 std::optional<GlobalPlannerResult>
136 calculatePath(const PlanningResult& planner,
137 const core::Pose& goal,
138 const std::optional<RecoveryInfo>& recovery = std::nullopt);
139
140 /// The obstacle-aware velocity limit this planner applies, for the current costmap.
142
143 protected:
144 std::vector<Eigen::Vector2f> postProcessPath(const std::vector<Eigen::Vector2f>& path);
145
146 private:
147 Params params_;
148 core::GeneralConfig generalConfig_;
149 std::optional<navigation::algorithms::Costmap> costmap_;
150 };
151
152 /**
153 * @class AStar
154 * @ingroup Library-GlobalPlanner
155 *
156 * Implements the A* algorithm
157 */
158 class SPFA : public GlobalPlanner
159 {
160 public:
163
164 SPFA(const Params& params,
165 const core::GeneralConfig& generalParams,
166 const core::Scene& ctx);
167 ~SPFA() override = default;
168
169 std::optional<GlobalPlannerResult> plan(const core::Pose& goal) override;
170 std::optional<GlobalPlannerResult> plan(const core::Pose& start,
171 const core::Pose& goal) override;
172
174 std::optional<GlobalPlannerResult> calculatePath(const PlanningResult& planner,
175 const core::Pose& goal);
176
177 private:
178 SPFAImpl impl_;
179 };
180
181} // namespace armarx::navigation::global_planning
The maximum permissible linear velocity as a function of the distance to the closest obstacle.
GlobalPlanner(const core::GeneralConfig &generalConfig, const core::Scene &scene)
::armarx::navigation::global_planning::PlanningResult PlanningResult
Definition SPFA.h:123
void updateCostmap(const std::optional< navigation::algorithms::Costmap > &costmap)
Definition SPFA.cpp:228
std::optional< GlobalPlannerResult > plan(const core::Pose &start, const core::Pose &goal)
Definition SPFA.cpp:255
SPFAImpl(const Params &params, const core::GeneralConfig &generalParams, const std::optional< navigation::algorithms::Costmap > &costmap)
Definition SPFA.cpp:220
PlanningResult executePlannerFromPosition(const Eigen::Vector2f &startPosition)
Definition SPFA.cpp:384
PlanningResult executePlanner(const core::Pose &start)
Definition SPFA.cpp:340
std::vector< Eigen::Vector2f > postProcessPath(const std::vector< Eigen::Vector2f > &path)
Definition SPFA.cpp:934
std::optional< GlobalPlannerResult > calculatePath(const PlanningResult &planner, const core::Pose &goal, const std::optional< RecoveryInfo > &recovery=std::nullopt)
Definition SPFA.cpp:392
algorithms::ObstacleAwareVelocityLimit velocityLimit() const
The obstacle-aware velocity limit this planner applies, for the current costmap.
Definition SPFA.cpp:241
::armarx::navigation::global_planning::PlanningResult PlanningResult
Definition SPFA.h:162
std::optional< GlobalPlannerResult > calculatePath(const PlanningResult &planner, const core::Pose &goal)
Definition SPFA.cpp:213
std::optional< GlobalPlannerResult > plan(const core::Pose &goal) override
Definition SPFA.cpp:190
PlanningResult executePlanner(const core::Pose &start)
Definition SPFA.cpp:207
SPFA(const Params &params, const core::GeneralConfig &generalParams, const core::Scene &ctx)
Definition SPFA.cpp:178
std::shared_ptr< Dict > DictPtr
Definition Dict.h:42
Eigen::Isometry3f Pose
Definition basic_types.h:31
This file is part of ArmarX.
Definition fwd.h:30
float gridSearchDuration
Duration [s] of the SPFA grid search itself, which runs before calculatePath.
Definition SPFA.h:101
algorithms::spfa::ShortestPathFasterAlgorithm algorithm
Definition SPFA.h:97
std::optional< algorithms::spfa::ShortestPathFasterAlgorithm::Result > plan
Definition SPFA.h:98
Information about collision recovery.
Definition SPFA.h:111
Eigen::Vector2f recoveryPosition
The found recovery position (collision-free)
Definition SPFA.h:113
core::Pose originalStartPose
The original start pose (collision pose)
Definition SPFA.h:112
optimization::OrientationOptimizerParams optimizerParams
Definition SPFA.h:69
float resampleDistance
Spacing [mm] the planned path is resampled to before smoothing.
Definition SPFA.h:62
algorithms::spfa::ShortestPathFasterAlgorithm::Parameters algo
Definition SPFA.h:67
aron::data::DictPtr toAron() const override
Definition SPFA.cpp:151
static SPFAParams FromAron(const aron::data::DictPtr &dict)
Definition SPFA.cpp:161
Algorithms algorithm() const override
Definition SPFA.cpp:145
static constexpr float defaultResampleDistance
Used when resampleDistance is negative.
Definition SPFA.h:65
bool enableFinalVelocityClamp
Re-apply the obstacle-aware velocity limit after orientation optimization.
Definition SPFA.h:85
bool enablePositionSmoothing
Diagnostic switches for the post-processing stages.
Definition SPFA.h:77