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