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 }
76 }
77
78 void
79 IceNavigatorHandle::moveTo(const std::vector<client::WaypointTarget>& targets,
80 core::NavigationFrame navigationFrame)
81 {
83
84 try
85 {
86 navigator_->moveTo2(
87 freeze(targets), core::NavigationFrameNames.to_name(navigationFrame), configId_);
88 }
89 catch (const Ice::LocalException& e)
90 {
91 ARMARX_WARNING << deactivateSpam(1) << "Failed to call moveTo on navigator: " << e.what();
92 }
93 }
94
95 void
96 IceNavigatorHandle::moveToAlternatives(const std::vector<core::TargetAlternative>& targets,
97 core::NavigationFrame navigationFrame)
98 {
100
101 try
102 {
103 navigator_->moveToAlternatives(
104 freeze(targets), core::NavigationFrameNames.to_name(navigationFrame), configId_);
105 }
106 catch (const Ice::LocalException& e)
107 {
108 ARMARX_WARNING << deactivateSpam(1) << "Failed to call moveToAlternatives on navigator: " << e.what();
109 }
110 }
111
112 void
114 const std::optional<std::string>& providerName)
115 {
117 IceUtil::Optional<std::string> providerNameIce = IceUtil::None;
118 if (providerName.has_value())
119 {
120 providerNameIce = providerName.value();
121 }
122
123 try
124 {
125 navigator_->moveToLocation(location, providerNameIce, configId_);
126 }
127 catch (const Ice::LocalException& e)
128 {
129 ARMARX_WARNING << deactivateSpam(1) << "Failed to call moveToLocation on navigator: " << e.what();
130 }
131 }
132
133 void
135 core::NavigationFrame navigationFrame)
136 {
138
139 try
140 {
141 navigator_->moveTowards(
142 direction, core::NavigationFrameNames.to_name(navigationFrame), configId_);
143 }
144 catch (const Ice::LocalException& e)
145 {
146 ARMARX_WARNING << deactivateSpam(1) << "Failed to call moveTowards on navigator: " << e.what();
147 }
148 }
149
150 void
151 IceNavigatorHandle::update(const std::vector<core::Pose>& waypoints,
152 core::NavigationFrame navigationFrame)
153 {
155
156 try
157 {
158 navigator_->updateMoveTo(
159 convert(waypoints), core::NavigationFrameNames.to_name(navigationFrame), configId_);
160 }
161 catch (const Ice::LocalException& e)
162 {
163 ARMARX_WARNING << deactivateSpam(1) << "Failed to call update on navigator: " << e.what();
164 }
165 }
166
167 void
169 {
171
172 try
173 {
174 navigator_->setVelocityFactor(velocityFactor, configId_);
175 }
176 catch (const Ice::LocalException& e)
177 {
178 ARMARX_WARNING << deactivateSpam(1) << "Failed to call setVelocityFactor on navigator: " << e.what();
179 }
180 }
181
182 void
184 {
185 try
186 {
187 navigator_->pause(configId_);
188 }
189 catch (const Ice::LocalException& e)
190 {
191 ARMARX_WARNING << deactivateSpam(1) << "Failed to call pause on navigator: " << e.what();
192 }
193 }
194
195 void
197 {
198 try
199 {
200 navigator_->resume(configId_);
201 }
202 catch (const Ice::LocalException& e)
203 {
204 ARMARX_WARNING << deactivateSpam(1) << "Failed to call resume on navigator: " << e.what();
205 }
206 }
207
208 void
210 {
211 try
212 {
213 navigator_->stop(configId_);
214 }
215 catch (const Ice::LocalException& e)
216 {
217 ARMARX_WARNING << deactivateSpam(1) << "Failed to call stop on navigator: " << e.what();
218 }
219 }
220
221 bool
223 {
224 try
225 {
226 return navigator_->isPaused(configId_);
227 }
228 catch (const Ice::LocalException& e)
229 {
230 ARMARX_WARNING << deactivateSpam(1) << "Failed to call isPaused on navigator: " << e.what();
231 return false;
232 }
233 }
234
235 bool
237 {
238 try
239 {
240 return navigator_->isStopped(configId_);
241 }
242 catch (const Ice::LocalException& e)
243 {
244 ARMARX_WARNING << deactivateSpam(1) << "Failed to call isStopped on navigator: " << e.what();
245 return false;
246 }
247 }
248
249
250} // 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:193
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:77