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 <condition_variable>
26#include <cstdint>
27#include <functional>
28#include <mutex>
29#include <optional>
30#include <string>
31#include <variant>
32#include <vector>
33
39
41{
42
44 {
45
46 public:
47 template <class T>
48 StopEvent(T t) : event{t}
49 {
50 }
51
52 bool
54 {
55 return std::holds_alternative<core::GoalReachedEvent>(event);
56 }
57
60 {
61 return std::get<core::GoalReachedEvent>(event);
62 }
63
64 bool
66 {
67 return std::holds_alternative<core::SafetyStopTriggeredEvent>(event);
68 }
69
72 {
73 return std::get<core::SafetyStopTriggeredEvent>(event);
74 }
75
76 bool
78 {
79 return std::holds_alternative<core::UserAbortTriggeredEvent>(event);
80 }
81
84 {
85 return std::get<core::UserAbortTriggeredEvent>(event);
86 }
87
88 bool
90 {
91 return std::holds_alternative<core::InternalErrorEvent>(event);
92 }
93
96 {
97 return std::get<core::InternalErrorEvent>(event);
98 }
99
100 bool
102 {
103 return std::holds_alternative<core::GlobalPlanningFailedEvent>(event);
104 }
105
108 {
109 return std::get<core::GlobalPlanningFailedEvent>(event);
110 }
111
112 operator bool() const
113 {
114 return isGoalReachedEvent();
115 }
116
117 private:
118 using StopEventVar = std::variant<core::GoalReachedEvent,
123 StopEventVar event;
124 };
125
126 class PathBuilder;
127
129 {
130
131 public:
137
138 Navigator(const InjectedServices& services);
139
140 void moveTo(const core::Pose& pose, core::NavigationFrame frame);
141
142 void moveTo(const std::vector<core::Pose>& waypoints, core::NavigationFrame frame);
143
144 void moveTo(const PathBuilder& builder, core::NavigationFrame frame);
145
146 void moveToAlternatives(const std::vector<core::TargetAlternative>& targets,
148
149 void moveTowards(const core::Direction& direction, core::NavigationFrame frame);
150
151 void moveToLocation(const std::string& location,
152 const std::optional<std::string>& providerName);
153
154 void update(const std::vector<core::Pose>& waypoints, core::NavigationFrame frame);
155
156 void setVelocityFactor(float velocityFactor);
157
158 void pause();
159
160 void resume();
161
162 void stop();
163
164 void onGoalReached(const std::function<void(void)>& callback);
165
166 void onGoalReached(const std::function<void(const core::GoalReachedEvent&)>& callback);
167
168 void onWaypointReached(const std::function<void(int)>& callback);
169
170 StopEvent waitForStop(std::int64_t timeoutMs = -1);
171
172 protected:
173 private:
174 void stopped(const StopEvent&);
175
176 struct
177 {
178 std::mutex m;
179 std::condition_variable cv;
180 std::optional<StopEvent> event;
181 } stoppedInfo;
182
183 InjectedServices srv;
184 };
185
186} // namespace armarx::navigation::client
void setVelocityFactor(float velocityFactor)
void update(const std::vector< core::Pose > &waypoints, core::NavigationFrame frame)
Definition Navigator.cpp:97
void moveToLocation(const std::string &location, const std::optional< std::string > &providerName)
Navigator(const InjectedServices &services)
Definition Navigator.cpp:25
std::optional< StopEvent > event
Definition Navigator.h:180
void moveTo(const core::Pose &pose, core::NavigationFrame frame)
Definition Navigator.cpp:42
void moveToAlternatives(const std::vector< core::TargetAlternative > &targets, core::NavigationFrame frame)
Definition Navigator.cpp:81
StopEvent waitForStop(std::int64_t timeoutMs=-1)
void moveTowards(const core::Direction &direction, core::NavigationFrame frame)
void onGoalReached(const std::function< void(void)> &callback)
void onWaypointReached(const std::function< void(int)> &callback)
core::InternalErrorEvent & toInternalErrorEvent()
Definition Navigator.h:95
core::UserAbortTriggeredEvent & toUserAbortTriggeredEvent()
Definition Navigator.h:83
core::GlobalPlanningFailedEvent & toGlobalPlanningFailedEvent()
Definition Navigator.h:107
core::SafetyStopTriggeredEvent & toSafetyStopTriggeredEvent()
Definition Navigator.h:71
core::GoalReachedEvent & toGoalReachedEvent()
Definition Navigator.h:59
Navigator interface for PointGoal navigation (with waypoints) and relative movement.
Brief description of class targets.
Definition targets.h:39
This file is part of ArmarX.
Eigen::Vector3f Direction
Definition basic_types.h:39
Eigen::Isometry3f Pose
Definition basic_types.h:31
This file is part of ArmarX.
Definition constants.cpp:4
Definition helper.h:35
Event describing that the targeted goal was successfully reached.
Definition events.h:53
Event describing the occurance of an internal unhandled error.
Definition events.h:105
Event describing that for security reasons, the robot was stopped completely.
Definition events.h:88
Event describing that the user aborted the current execution.
Definition events.h:97