IceNavigatorHandle.cpp
Go to the documentation of this file.
2
3#include <algorithm>
4#include <iterator>
5#include <optional>
6#include <string>
7#include <vector>
8
9#include <Ice/Exception.h>
10#include <IceUtil/Optional.h>
11
15
17#include <armarx/navigation/client/ice/NavigatorInterface.h>
21
23{
24 namespace
25 {
26 std::vector<Eigen::Matrix4f>
27 convert(const std::vector<armarx::navigation::core::Pose>& ps)
28 {
29 using namespace armarx::navigation;
30 std::vector<Eigen::Matrix4f> ms;
31 ms.reserve(ps.size());
32 std::transform(ps.begin(),
33 ps.end(),
34 std::back_inserter(ms),
35 [](const auto& p) { return p.matrix(); });
36 return ms;
37 }
38 } // namespace
39
40 IceNavigatorHandle::IceNavigatorHandle(const NavigatorInterfacePrx& navigator,
41 const std::string& configId_) :
42 navigator_(navigator), configId_(configId_)
43 {
44 // pass
45 }
46
48 {
50 try
51 {
52 navigator_->removeConfig(configId_);
53 }
54 catch (const Ice::LocalException& e)
55 {
56 ARMARX_WARNING << "Failed to remove navigation config '" << configId_
57 << "' on navigator: " << e.what();
58 }
59 }
60
61 void
62 IceNavigatorHandle::moveTo(const std::vector<core::Pose>& waypoints,
63 core::NavigationFrame navigationFrame)
64 {
66
67 try
68 {
69 navigator_->begin_moveTo(
70 convert(waypoints), core::NavigationFrameNames.to_name(navigationFrame), configId_);
71 }
72 catch (const Ice::LocalException& e)
73 {
74 ARMARX_WARNING << deactivateSpam(1) << "Failed to call moveTo on navigator: " << e.what();
75 throw;
76 }
77 }
78
79 void
80 IceNavigatorHandle::moveTo(const std::vector<client::WaypointTarget>& targets,
81 core::NavigationFrame navigationFrame)
82 {
84
85 try
86 {
87 navigator_->moveTo2(
88 freeze(targets), core::NavigationFrameNames.to_name(navigationFrame), configId_);
89 }
90 catch (const Ice::LocalException& e)
91 {
92 ARMARX_WARNING << deactivateSpam(1) << "Failed to call moveTo on navigator: " << e.what();
93 throw;
94 }
95 }
96
97 void
98 IceNavigatorHandle::moveToAlternatives(const std::vector<core::TargetAlternative>& targets,
99 core::NavigationFrame navigationFrame)
100 {
102
103 try
104 {
105 navigator_->moveToAlternatives(
106 freeze(targets), core::NavigationFrameNames.to_name(navigationFrame), configId_);
107 }
108 catch (const Ice::LocalException& e)
109 {
110 ARMARX_WARNING << deactivateSpam(1) << "Failed to call moveToAlternatives on navigator: " << e.what();
111 throw;
112 }
113 }
114
115 void
117 const std::optional<std::string>& providerName)
118 {
120 IceUtil::Optional<std::string> providerNameIce = IceUtil::None;
121 if (providerName.has_value())
122 {
123 providerNameIce = providerName.value();
124 }
125
126 try
127 {
128 navigator_->moveToLocation(location, providerNameIce, configId_);
129 }
130 catch (const Ice::LocalException& e)
131 {
132 ARMARX_WARNING << deactivateSpam(1) << "Failed to call moveToLocation on navigator: " << e.what();
133 throw;
134 }
135 }
136
137 void
139 core::NavigationFrame navigationFrame)
140 {
142
143 try
144 {
145 navigator_->moveTowards(
146 direction, core::NavigationFrameNames.to_name(navigationFrame), configId_);
147 }
148 catch (const Ice::LocalException& e)
149 {
150 ARMARX_WARNING << deactivateSpam(1) << "Failed to call moveTowards on navigator: " << e.what();
151 throw;
152 }
153 }
154
155 void
156 IceNavigatorHandle::update(const std::vector<core::Pose>& waypoints,
157 core::NavigationFrame navigationFrame)
158 {
160
161 try
162 {
163 navigator_->updateMoveTo(
164 convert(waypoints), core::NavigationFrameNames.to_name(navigationFrame), configId_);
165 }
166 catch (const Ice::LocalException& e)
167 {
168 ARMARX_WARNING << deactivateSpam(1) << "Failed to call update on navigator: " << e.what();
169 throw;
170 }
171 }
172
173 void
175 {
177
178 try
179 {
180 navigator_->setVelocityFactor(velocityFactor, configId_);
181 }
182 catch (const Ice::LocalException& e)
183 {
184 ARMARX_WARNING << deactivateSpam(1) << "Failed to call setVelocityFactor on navigator: " << e.what();
185 }
186 }
187
188 void
190 {
191 try
192 {
193 navigator_->pause(configId_);
194 }
195 catch (const Ice::LocalException& e)
196 {
197 ARMARX_WARNING << deactivateSpam(1) << "Failed to call pause on navigator: " << e.what();
198 }
199 }
200
201 void
203 {
204 try
205 {
206 navigator_->resume(configId_);
207 }
208 catch (const Ice::LocalException& e)
209 {
210 ARMARX_WARNING << deactivateSpam(1) << "Failed to call resume on navigator: " << e.what();
211 }
212 }
213
214 void
216 {
217 try
218 {
219 navigator_->stop(configId_);
220 }
221 catch (const Ice::LocalException& e)
222 {
223 ARMARX_WARNING << deactivateSpam(1) << "Failed to call stop on navigator: " << e.what();
224 throw;
225 }
226 }
227
228 bool
230 {
231 try
232 {
233 return navigator_->isPaused(configId_);
234 }
235 catch (const Ice::LocalException& e)
236 {
237 ARMARX_WARNING << deactivateSpam(1) << "Failed to call isPaused on navigator: " << e.what();
238 return false;
239 }
240 }
241
242 bool
244 {
245 try
246 {
247 return navigator_->isStopped(configId_);
248 }
249 catch (const Ice::LocalException& e)
250 {
251 ARMARX_WARNING << deactivateSpam(1) << "Failed to call isStopped on navigator: " << e.what();
252 return false;
253 }
254 }
255
256
257} // namespace armarx::navigation::client
SpamFilterDataPtr deactivateSpam(SpamFilterDataPtr const &spamFilter, float deactivationDurationSec, const std::string &identifier, bool deactivate)
Definition Logging.cpp:75
void convert(const std::filesystem::path &in, const std::filesystem::path &out, bool print_progress)
Performs the actual conversion.
Definition main.cpp:170
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
void setVelocityFactor(float velocityFactor) override
void moveToLocation(const std::string &location, const std::optional< std::string > &providerName) override
void moveTo(const std::vector< core::Pose > &waypoints, core::NavigationFrame navigationFrame) override
Brief description of class targets.
Definition targets.h:39
#define ARMARX_WARNING
The logging level for unexpected behaviour, but not a serious problem.
Definition Logging.h:191
This file is part of ArmarX.
client::detail::GlobalPlanningStrategy freeze(const client::GlobalPlanningStrategy &strategy)
Eigen::Vector3f Direction
Definition basic_types.h:39
const simox::meta::EnumNames< NavigationFrame > NavigationFrameNames
Definition types.h:54
This file is part of ArmarX.
Definition constants.cpp:4
std::vector< core::Pose > convert(const std::vector< Eigen::Matrix4f > &wps)
Definition Component.cpp:93
#define ARMARX_TRACE
Definition trace.h:75