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 
35 
51 
53 #include <SemanticObjectRelations/Shapes/Shape.h>
54 
56 {
57 
58  namespace scene_provider
59  {
61  }
62 
63  class Navigator : virtual public core::NavigatorInterface
64  {
65 
66  public:
67  struct Config
68  {
69  struct General
70  {
71  struct
72  {
73  int replanningUpdatePeriod{100}; // [ms]
74  } tasks;
75  };
76 
79 
81  };
82 
84  {
88 
90 
92  };
93 
94  Navigator(const Config& config, const InjectedServices& services);
95 
96  void moveTo(const std::vector<core::Pose>& waypoints,
97  core::NavigationFrame navigationFrame) override;
98 
99  void update(const std::vector<core::Pose>& waypoints,
100  core::NavigationFrame navigationFrame) override;
101 
102 
103  void moveTo(const std::vector<client::WaypointTarget>& targets,
104  core::NavigationFrame navigationFrame) override;
105 
106  void moveTowards(const core::Direction& direction,
107  core::NavigationFrame navigationFrame) override;
108 
109  void moveToLocation(const std::string& location) override;
110 
111  void pause() override;
112 
113  void resume() override;
114 
115  bool isPaused() const noexcept override;
116 
117  void stop() override;
118 
119  bool isStopped() const noexcept override;
120 
121  // Non-API
122  public:
123  Navigator(Navigator&& other) noexcept;
124 
125  ~Navigator() override;
126 
127  private:
128  using GraphPath = std::vector<semrel::ShapeID>;
129 
130  void moveToAbsolute(const std::vector<core::Pose>& waypoints);
131  void moveTowardsAbsolute(const core::Direction& direction);
132 
133  void updateAbsolute(const std::vector<core::Pose>& waypoints);
134 
135  void run();
136 
137  void updateScene(bool fullUpdate = false);
138 
139  std::optional<local_planning::LocalPlannerResult> updateLocalPlanner();
140  void updateExecutor(const std::optional<local_planning::LocalPlannerResult>& localPlan);
141  void updateExecutor(const std::optional<global_planning::GlobalPlannerResult>& localPlan);
142  void updateIntrospector(const std::optional<local_planning::LocalPlannerResult>& localPlan);
143 
144  void updateMonitor();
145 
146  safety_guard::SafetyGuardResult updateSafetyGuard();
147 
148  // const core::Trajectory& currentTrajectory() const;
149  // bool isStackResultValid() const noexcept;
150 
151  void stopAllThreads();
152 
153  void startStack();
154 
155  // helper methods
156  void setGraphEdgeCosts(core::Graph& graph) const;
157  GraphBuilder convertToGraph(const std::vector<client::WaypointTarget>& targets) const;
158 
159  core::GlobalTrajectory convertToTrajectory(const GraphPath& shortestPath,
160  const core::Graph& graph) const;
161 
162  core::Pose resolveGraphVertex(const core::Graph::ConstVertex& vertex) const;
163 
164  bool hasLocalPlanner() const noexcept;
165  bool hasSafetyGuard() const;
166 
167  Config config;
168 
169  InjectedServices srv;
170 
171  std::atomic_bool executorEnabled = true;
172 
173  PeriodicTask<Navigator>::pointer_type runningTask = nullptr;
174 
175  std::optional<GoalReachedMonitor> goalReachedMonitor;
176 
177 
178  std::optional<global_planning::GlobalPlannerResult> globalPlan;
179  std::optional<local_planning::LocalPlannerResult> localPlan;
180 
181  using Waypoints = std::vector<core::Pose>;
182 
183  std::mutex globalPlanningRequestMtx;
184  std::optional<Waypoints> globalPlanningRequest;
185 
186  std::mutex updateLocalPlannerMtx;
187 
188  std::mutex runMtx;
189  };
190 
191 } // namespace armarx::navigation::server
ice_conversions.h
armarx::navigation::server::scene_provider::SceneProviderInterface
Definition: SceneProviderInterface.h:34
armarx::navigation::server::Navigator::Config::goalReachedConfig
GoalReachedMonitorConfig goalReachedConfig
Definition: Navigator.h:80
NavigationStack.h
armarx::navigation::server::Navigator::InjectedServices::debugObserverHelper
armarx::DebugObserverHelper * debugObserverHelper
Definition: Navigator.h:89
armarx::navigation::server::Navigator::isPaused
bool isPaused() const noexcept override
Definition: Navigator.cpp:1333
armarx::navigation::server::ExecutorInterface
An executer the server navigator will use to send its control commands to.
Definition: ExecutorInterface.h:12
armarx::navigation::core::NavigationFrame
NavigationFrame
Definition: types.h:42
basic_types.h
ExecutorInterface.h
armarx::navigation::server::Navigator::InjectedServices::publisher
EventPublishingInterface * publisher
Definition: Navigator.h:86
armarx::navigation::server::Navigator::moveTowards
void moveTowards(const core::Direction &direction, core::NavigationFrame navigationFrame) override
Definition: Navigator.cpp:842
armarx::navigation::server::Navigator::InjectedServices::sceneProvider
scene_provider::SceneProviderInterface * sceneProvider
Definition: Navigator.h:91
LocalPlanner.h
GoalReachedMonitor.h
PeriodicTask.h
armarx::navigation::server::Navigator::Config
Definition: Navigator.h:67
armarx::navigation::server::NavigationStack
Definition: NavigationStack.h:36
armarx::navigation::server::Navigator::resume
void resume() override
Definition: Navigator.cpp:1299
armarx::navigation::server::Navigator::InjectedServices::introspector
IntrospectorInterface * introspector
Definition: Navigator.h:87
armarx::navigation::core::NavigatorInterface
Navigator interface for PointGoal navigation (with waypoints) and relative movement.
Definition: NavigatorInterface.h:17
armarx::navigation::server::Navigator
Definition: Navigator.h:63
armarx::navigation::server::Navigator::Config::general
General general
Definition: Navigator.h:78
armarx::navigation::server::Navigator::stop
void stop() override
Definition: Navigator.cpp:1319
IntrospectorInterface.h
GraphBuilder.h
armarx::navigation::server
This file is part of ArmarX.
Definition: EventPublishingInterface.h:6
armarx::navigation::server::GoalReachedMonitor
Definition: GoalReachedMonitor.h:45
armarx::navigation::server::Navigator::moveToLocation
void moveToLocation(const std::string &location) override
Definition: Navigator.cpp:847
armarx::navigation::server::Navigator::pause
void pause() override
Definition: Navigator.cpp:1285
armarx::navigation::server::Navigator::Config::stack
server::NavigationStack stack
Definition: Navigator.h:77
armarx::navigation::server::GraphBuilder
Definition: GraphBuilder.h:38
armarx::navigation::server::GoalReachedMonitorConfig
Definition: GoalReachedMonitor.h:34
GlobalPlanner.h
armarx::Graph
boost::subgraph< CloudGraph > Graph
Definition: Common.h:58
armarx::navigation::server::Navigator::InjectedServices
Definition: Navigator.h:83
armarx::navigation::server::Navigator::isStopped
bool isStopped() const noexcept override
Definition: Navigator.cpp:1339
armarx::navigation::server::Navigator::InjectedServices::executor
ExecutorInterface * executor
Definition: Navigator.h:85
armarx::navigation::server::Navigator::Config::General
Definition: Navigator.h:69
armarx::navigation::server::Navigator::Config::General::tasks
struct armarx::navigation::server::Navigator::Config::General::@69 tasks
armarx::navigation::server::IntrospectorInterface
Definition: IntrospectorInterface.h:38
semrel
This file is part of ArmarX.
Definition: forward_declarations.h:24
armarx::Pose
The Pose class.
Definition: Pose.h:242
DebugObserverHelper.h
Graph.h
EventPublishingInterface.h
std
Definition: Application.h:66
armarx::navigation::core::Direction
Eigen::Vector3f Direction
Definition: basic_types.h:39
armarx::navigation::server::Navigator::moveTo
void moveTo(const std::vector< core::Pose > &waypoints, core::NavigationFrame navigationFrame) override
Definition: Navigator.cpp:148
armarx::navigation::server::Navigator::update
void update(const std::vector< core::Pose > &waypoints, core::NavigationFrame navigationFrame) override
Definition: Navigator.cpp:179
armarx::PeriodicTask
Definition: ArmarXManager.h:70
NavigatorInterface.h
armarx::navigation::server::EventPublishingInterface
A publisher the server navigator will use to notify others about events.
Definition: EventPublishingInterface.h:12
armarx::navigation::server::Navigator::Navigator
Navigator(const Config &config, const InjectedServices &services)
Definition: Navigator.cpp:65
Trajectory.h
armarx::DebugObserverHelper
Brief description of class DebugObserverHelper.
Definition: DebugObserverHelper.h:51
types.h
armarx::navigation::server::Navigator::Config::General::replanningUpdatePeriod
int replanningUpdatePeriod
Definition: Navigator.h:73
SafetyGuard.h