Navigator.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 <atomic>
26#include <mutex>
27#include <optional>
28#include <string>
29#include <vector>
30
31#include <Eigen/Core>
32
36
53
55#include <SemanticObjectRelations/Shapes/Shape.h>
56
58{
59
61 {
63 }
64
65 // Allow global path to be subdivided into segments that are executed independently
66 // each segment can be executed by the global or local planner
68 {
69 // A segment from index [s,t)
71 {
72 std::size_t s;
73 std::size_t t;
75 };
76
78 std::vector<Subdivision> subdivision;
79 std::size_t currentSegment;
81
82 bool useLocalPlanner(bool hasLocalPlanner);
85
87 };
88
89 class Navigator : virtual public core::NavigatorInterface
90 {
91
92 public:
93 struct Config
94 {
95 struct General
96 {
97 struct
98 {
99 int replanningUpdatePeriod{100}; // [ms]
101
102 // Whether to subdivide the global trajectory into segments that are executed independently.
103 // Requires local planner
104
105 // The global plan is divided into segments that can be executed by the local planner and those
106 // where the global planner should be used:
107 // - a part of the trajectory is ineligible for the local planner if the corresponding costmap
108 // entry has a value less than the localPlannerCostmapThreshold parameter
109 // Then, each segment of continuous trajectory points where the global planner should be used is expanded
110 // by globalPlanExpansionDistance into both directions.
111 // Then, each segment of continuous trajectory points where the local planner should be used that is less
112 // than minSegmentDistance long will be remove and joined with the neighboring globalPlanner segments.
113 struct
114 {
115 bool enable{false};
116 // the minimum distance in the costmap to enable the local planner [mm]
118 float globalPlanExpansionDistance = 300; // [mm]
119 float minSegmentDistance = 500; // [mm]
121
122 // numer of seconds to wait before replanning alternatives after all
123 // alternatives where impossible [s]
125 };
126
129
131 };
132
144
145 Navigator(const Config& config, const InjectedServices& services);
146
147 void moveTo(const std::vector<core::Pose>& waypoints,
148 core::NavigationFrame navigationFrame) override;
149
150 void moveToAlternatives(const std::vector<core::TargetAlternative>& targets,
151 core::NavigationFrame navigationFrame) override;
152
153 void update(const std::vector<core::Pose>& waypoints,
154 core::NavigationFrame navigationFrame) override;
155
156
157 void moveTo(const std::vector<client::WaypointTarget>& targets,
158 core::NavigationFrame navigationFrame) override;
159
160 void moveTowards(const core::Direction& direction,
161 core::NavigationFrame navigationFrame) override;
162
163 void moveToLocation(const std::string& location,
164 const std::optional<std::string>& providerName) override;
165
166 void setVelocityFactor(float velocityFactor) override;
167
168 void pause() override;
169
170 void resume() override;
171
172 bool isPaused() const noexcept override;
173
174 void stop() override;
175
176 bool isStopped() const noexcept override;
177
178 // Non-API
179 public:
180 Navigator(Navigator&& other) noexcept;
181
182 ~Navigator() override;
183
184 private:
185 using GraphPath = std::vector<semrel::ShapeID>;
186
187 void moveToAbsolute(const std::vector<core::Pose>& waypoints, bool = true);
188 void moveTowardsAbsolute(const core::Direction& direction);
189
190 void updateAbsolute(const std::vector<core::Pose>& waypoints);
191
192 void moveToAbsoluteAlternatives(const std::vector<core::TargetAlternative>& targets);
193 bool setupTargetAlternatives();
194
195 void setupGlobalPlanSubvidision();
196
197 // return true iff globalPath was already executed fully
198 bool startGlobalPathSegment(bool incrementSegment, bool rampFromCurrentVelocity);
199
200 void run();
201
202 void updateScene(bool fullUpdate = false);
203
204 void checkGlobalPathAlternatives();
205 bool verifyGlobalPathPossible(const core::GlobalTrajectory& plan);
206
207 std::optional<local_planning::LocalPlannerResult> updateLocalPlanner();
208 void updateExecutor(const std::optional<local_planning::LocalPlannerResult>& localPlan);
209 void updateExecutor(const core::GlobalTrajectory& globalTrajectory);
210 void updateIntrospector(const std::optional<local_planning::LocalPlannerResult>& localPlan);
211
212 void updateMonitor();
213
214 safety_guard::SafetyGuardResult updateSafetyGuard();
215
216 // const core::Trajectory& currentTrajectory() const;
217 // bool isStackResultValid() const noexcept;
218
219 void stopAllThreads();
220
221 void startStack();
222
223 // helper methods
224 void setGraphEdgeCosts(core::Graph& graph) const;
225 GraphBuilder convertToGraph(const std::vector<client::WaypointTarget>& targets) const;
226
227 core::GlobalTrajectory convertToTrajectory(const GraphPath& shortestPath,
228 const core::Graph& graph) const;
229
230 core::Pose resolveGraphVertex(const core::Graph::ConstVertex& vertex) const;
231
232 void setupRamping(core::GlobalTrajectory& trajectory, float startVelocity) const;
233
234 bool hasLocalPlanner() const noexcept;
235 bool hasSafetyGuard() const;
236
237 Config config;
238
240
241 std::atomic_bool executorEnabled = true;
242 std::atomic_bool shouldRun = false;
243
244 PeriodicTask<Navigator>::pointer_type runningTask = nullptr;
245
246 std::optional<GoalReachedMonitor> goalReachedMonitor;
247
248 std::vector<core::TargetAlternative> targetAlternatives;
249 std::optional<armarx::DateTime> lastAllAlternativesImpossible;
250
251 std::optional<GlobalPathSubdivision> globalPlan;
252 std::optional<local_planning::LocalPlannerResult> localPlan;
253
254 using Waypoints = std::vector<core::Pose>;
255
256 std::mutex globalPlanningRequestMtx;
257 std::optional<Waypoints> globalPlanningRequest;
258
259 std::atomic<float> velocityFactor = 1.F;
260
261 std::mutex updateLocalPlannerMtx;
262
263 std::mutex runMtx;
264
265 std::mutex runningTaskMtx;
266 };
267
268} // namespace armarx::navigation::server
Brief description of class DebugObserverHelper.
The periodic task executes one thread method repeatedly using the time period specified in the constr...
The Pose class.
Definition Pose.h:243
Represents a point in time.
Definition DateTime.h:25
Navigator interface for PointGoal navigation (with waypoints) and relative movement.
A publisher the server navigator will use to notify others about events.
An executer the server navigator will use to send its control commands to.
void moveToAlternatives(const std::vector< core::TargetAlternative > &targets, core::NavigationFrame navigationFrame) override
void moveTowards(const core::Direction &direction, core::NavigationFrame navigationFrame) override
void update(const std::vector< core::Pose > &waypoints, core::NavigationFrame navigationFrame) override
Navigator(const Config &config, const InjectedServices &services)
void setVelocityFactor(float velocityFactor) override
void moveToLocation(const std::string &location, const std::optional< std::string > &providerName) override
bool isPaused() const noexcept override
void moveTo(const std::vector< core::Pose > &waypoints, core::NavigationFrame navigationFrame) override
bool isStopped() const noexcept override
Brief description of class targets.
Definition targets.h:39
This file is part of ArmarX.
This file is part of ArmarX.
Eigen::Vector3f Direction
Definition basic_types.h:39
This file is part of ArmarX.
Definition Visu.h:48
This file is part of ArmarX.
Definition fwd.h:36
This file is part of ArmarX.
Definition constants.cpp:4
This file is part of ArmarX.
Definition fwd.h:55
This file is part of ArmarX.
core::GoalReachedConfig GoalReachedMonitorConfig
This file offers overloads of toIce() and fromIce() functions for STL container types.
boost::subgraph< CloudGraph > Graph
Definition Common.h:58
This file is part of ArmarX.
GlobalPathSubdivision(const global_planning::GlobalPlannerResult &globalPlan)
Definition Navigator.cpp:68
global_planning::GlobalPlannerResult plan
Definition Navigator.h:77
const core::GlobalTrajectory & currentGlobalSegment() const
Definition Navigator.cpp:90
struct armarx::navigation::server::Navigator::Config::General::@344222376127045226032312110301072212057201156307 subdivision
struct armarx::navigation::server::Navigator::Config::General::@344207070160307005105315017266073311106207125254 tasks
GoalReachedMonitorConfig goalReachedConfig
Definition Navigator.h:130
scene_provider::SceneProviderInterface * sceneProvider
Definition Navigator.h:142