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 <functional>
26 #include <mutex>
27 #include <optional>
28 #include <string>
29 #include <variant>
30 #include <vector>
31 
36 #include <condition_variable>
37 
38 
40 {
41 
42  class StopEvent
43  {
44 
45  public:
46  template <class T>
47  StopEvent(T t) : event{t}
48  {
49  }
50 
51  bool
53  {
54  return std::holds_alternative<core::GoalReachedEvent>(event);
55  }
56 
59  {
60  return std::get<core::GoalReachedEvent>(event);
61  }
62 
63  bool
65  {
66  return std::holds_alternative<core::SafetyStopTriggeredEvent>(event);
67  }
68 
71  {
72  return std::get<core::SafetyStopTriggeredEvent>(event);
73  }
74 
75  bool
77  {
78  return std::holds_alternative<core::UserAbortTriggeredEvent>(event);
79  }
80 
83  {
84  return std::get<core::UserAbortTriggeredEvent>(event);
85  }
86 
87  bool
89  {
90  return std::holds_alternative<core::InternalErrorEvent>(event);
91  }
92 
95  {
96  return std::get<core::InternalErrorEvent>(event);
97  }
98 
99  operator bool() const
100  {
101  return isGoalReachedEvent();
102  }
103 
104  private:
105  using StopEventVar = std::variant<core::GoalReachedEvent,
110  StopEventVar event;
111  };
112 
113  class PathBuilder;
114 
115  class Navigator
116  {
117 
118  public:
120  {
123  };
124 
125  Navigator(const InjectedServices& services);
126 
127  void moveTo(const core::Pose& pose, core::NavigationFrame frame);
128 
129  void moveTo(const std::vector<core::Pose>& waypoints, core::NavigationFrame frame);
130 
131  void moveTo(const PathBuilder& builder, core::NavigationFrame frame);
132 
133  void moveTowards(const core::Direction& direction, core::NavigationFrame frame);
134 
135  void moveToLocation(const std::string& location);
136 
137  void update(const std::vector<core::Pose>& waypoints, core::NavigationFrame frame);
138 
139  void pause();
140 
141  void resume();
142 
143  void stop();
144 
145  void onGoalReached(const std::function<void(void)>& callback);
146 
147  void onGoalReached(const std::function<void(const core::GoalReachedEvent&)>& callback);
148 
149  void onWaypointReached(const std::function<void(int)>& callback);
150 
151  StopEvent waitForStop(std::int64_t timeoutMs = -1);
152 
153  protected:
154  private:
155  void stopped(const StopEvent&);
156 
157  struct
158  {
159  std::mutex m;
160  std::condition_variable cv;
161  std::optional<StopEvent> event;
162  } stoppedInfo;
163 
164  InjectedServices srv;
165  };
166 
167 } // namespace armarx::navigation::client
armarx::navigation::client::Navigator::onGoalReached
void onGoalReached(const std::function< void(void)> &callback)
Definition: Navigator.cpp:142
armarx::navigation::client::StopEvent::isGoalReachedEvent
bool isGoalReachedEvent() const
Definition: Navigator.h:52
armarx::navigation::client::Navigator::waitForStop
StopEvent waitForStop(std::int64_t timeoutMs=-1)
Definition: Navigator.cpp:162
armarx::navigation::client::Navigator
Definition: Navigator.h:115
armarx::navigation::core::NavigationFrame
NavigationFrame
Definition: types.h:43
armarx::navigation::client::Navigator::InjectedServices
Definition: Navigator.h:119
armarx::navigation::core::Pose
Eigen::Isometry3f Pose
Definition: basic_types.h:31
armarx::navigation::client::StopEvent::toSafetyStopTriggeredEvent
core::SafetyStopTriggeredEvent & toSafetyStopTriggeredEvent()
Definition: Navigator.h:70
armarx::navigation::client::PathBuilder
Definition: PathBuilder.h:41
armarx::navigation::client::StopEvent::isInternalErrorEvent
bool isInternalErrorEvent() const
Definition: Navigator.h:88
armarx::navigation::client::StopEvent::toGoalReachedEvent
core::GoalReachedEvent & toGoalReachedEvent()
Definition: Navigator.h:58
armarx::navigation::core::InternalErrorEvent
Event describing the occurance of an internal unhandled error.
Definition: events.h:101
armarx::navigation::client::StopEvent::toInternalErrorEvent
core::InternalErrorEvent & toInternalErrorEvent()
Definition: Navigator.h:94
armarx::navigation::core::NavigatorInterface
Navigator interface for PointGoal navigation (with waypoints) and relative movement.
Definition: NavigatorInterface.h:13
armarx::navigation::client
This file is part of ArmarX.
Definition: ComponentPlugin.cpp:20
EventSubscriptionInterface.h
armarx::navigation::client::Navigator::InjectedServices::navigator
core::NavigatorInterface * navigator
Definition: Navigator.h:121
armarx::navigation::client::Navigator::cv
std::condition_variable cv
Definition: Navigator.h:160
events.h
armarx::navigation::client::Navigator::update
void update(const std::vector< core::Pose > &waypoints, core::NavigationFrame frame)
Definition: Navigator.cpp:76
armarx::navigation::client::StopEvent::toUserAbortTriggeredEvent
core::UserAbortTriggeredEvent & toUserAbortTriggeredEvent()
Definition: Navigator.h:82
armarx::navigation::client::Navigator::onWaypointReached
void onWaypointReached(const std::function< void(int)> &callback)
Definition: Navigator.cpp:156
armarx::navigation::client::Navigator::event
std::optional< StopEvent > event
Definition: Navigator.h:161
armarx::navigation::client::StopEvent
Definition: Navigator.h:42
armarx::navigation::client::StopEvent::isUserAbortTriggeredEvent
bool isUserAbortTriggeredEvent() const
Definition: Navigator.h:76
armarx::navigation::client::StopEvent::isSafetyStopTriggeredEvent
bool isSafetyStopTriggeredEvent() const
Definition: Navigator.h:64
armarx::navigation::client::Navigator::Navigator
Navigator(const InjectedServices &services)
Definition: Navigator.cpp:18
armarx::navigation::core::SafetyStopTriggeredEvent
Event describing that for security reasons, the robot was stopped completely.
Definition: events.h:84
armarx::navigation::client::Navigator::resume
void resume()
Definition: Navigator.cpp:124
armarx::navigation::client::Navigator::moveToLocation
void moveToLocation(const std::string &location)
Definition: Navigator.cpp:99
armarx::navigation::client::StopEvent::StopEvent
StopEvent(T t)
Definition: Navigator.h:47
armarx::navigation::client::Navigator::moveTowards
void moveTowards(const core::Direction &direction, core::NavigationFrame frame)
Definition: Navigator.cpp:85
armarx::navigation::core::UserAbortTriggeredEvent
Event describing that the user aborted the current execution.
Definition: events.h:93
armarx::navigation::core::GlobalPlanningFailedEvent
Definition: events.h:31
armarx::navigation::core::GoalReachedEvent
Event describing that the targeted goal was successfully reached.
Definition: events.h:49
armarx::navigation::client::Navigator::pause
void pause()
Definition: Navigator.cpp:115
armarx::navigation::core::Direction
Eigen::Vector3f Direction
Definition: basic_types.h:39
armarx::navigation::client::EventSubscriptionInterface
Definition: EventSubscriptionInterface.h:36
armarx::navigation::client::Navigator::stop
void stop()
Definition: Navigator.cpp:133
armarx::navigation::client::Navigator::m
std::mutex m
Definition: Navigator.h:159
T
float T
Definition: UnscentedKalmanFilterTest.cpp:35
NavigatorInterface.h
armarx::navigation::client::Navigator::InjectedServices::subscriber
EventSubscriptionInterface * subscriber
Definition: Navigator.h:122
types.h
armarx::navigation::client::Navigator::moveTo
void moveTo(const core::Pose &pose, core::NavigationFrame frame)
Definition: Navigator.cpp:36