10 #include <SimoxUtility/math/convert/rpy_to_mat3f.h>
19 #include <ArmarXGui/interface/RemoteGuiInterface.h>
34 namespace gui = RemoteGui;
54 RemoteGui::createRemoteGuiTab()
69 tab.targetPoseGroup.group.setLabel(
"Target pose");
73 tab.targetPoseGroup.targetPoseX.setRange(-max, max);
74 tab.targetPoseGroup.targetPoseX.setDecimals(0);
75 tab.targetPoseGroup.targetPoseX.setSteps(int(max / 10));
76 tab.targetPoseGroup.targetPoseX.setValue(0.F);
81 tab.targetPoseGroup.targetPoseY.setRange(-
max,
max);
82 tab.targetPoseGroup.targetPoseY.setDecimals(0);
83 tab.targetPoseGroup.targetPoseY.setSteps(
int(
max / 10));
84 tab.targetPoseGroup.targetPoseY.setValue(0.
F);
89 tab.targetPoseGroup.targetPoseZ.setRange(-max, max);
90 tab.targetPoseGroup.targetPoseZ.setDecimals(0);
91 tab.targetPoseGroup.targetPoseZ.setSteps(int(max / 10));
92 tab.targetPoseGroup.targetPoseZ.setValue(0.F);
97 tab.targetPoseGroup.targetPoseRoll.setRange(-max, max);
98 tab.targetPoseGroup.targetPoseRoll.setDecimals(0);
99 tab.targetPoseGroup.targetPoseRoll.setSteps(2 * max);
100 tab.targetPoseGroup.targetPoseRoll.setValue(0.F);
105 tab.targetPoseGroup.targetPosePitch.setRange(-max, max);
106 tab.targetPoseGroup.targetPosePitch.setDecimals(0);
107 tab.targetPoseGroup.targetPosePitch.setSteps(2 * max);
108 tab.targetPoseGroup.targetPosePitch.setValue(0.F);
113 tab.targetPoseGroup.targetPoseYaw.setRange(-max, max);
114 tab.targetPoseGroup.targetPoseYaw.setDecimals(0);
115 tab.targetPoseGroup.targetPoseYaw.setSteps(2 * max);
116 tab.targetPoseGroup.targetPoseYaw.setValue(0.F);
124 grid.add(Label("X"), {id, 0}).add(tab.targetPoseGroup.targetPoseX, {id, 1});
127 grid.add(Label("Y"), {id, 0}).add(tab.targetPoseGroup.targetPoseY, {id, 1});
130 grid.add(Label("Z"), {id, 0}).add(tab.targetPoseGroup.targetPoseZ, {id, 1});
133 grid.add(armarx::RemoteGui::Client::VSpacer(), {id, 1});
136 grid.add(Label("Roll"), {id, 0}).add(tab.targetPoseGroup.targetPoseRoll, {id, 1});
139 grid.add(Label("Pitch"), {id, 0}).add(tab.targetPoseGroup.targetPosePitch, {id, 1});
142 grid.add(Label("Yaw"), {id, 0}).add(tab.targetPoseGroup.targetPoseYaw, {id, 1});
146 VBoxLayout root = {grid, VSpacer()};
148 tab.targetPoseGroup.group.addChild(root);
152 tab.controlGroup.group.setLabel("Control");
154 tab.controlGroup.moveToButton.setLabel("MoveTo");
155 tab.controlGroup.continueButton.setLabel("Continue");
156 tab.controlGroup.pauseButton.setLabel("Pause");
157 tab.controlGroup.stopButton.setLabel("Stop");
158 tab.controlGroup.stopAllButton.setLabel("StopAll");
162 grid.add(tab.controlGroup.moveToButton, {id, 1});
165 grid.add(armarx::RemoteGui::Client::VSpacer(), {id, 1});
168 grid.add(tab.controlGroup.pauseButton, {id, 1});
171 grid.add(tab.controlGroup.continueButton, {id, 1});
174 grid.add(tab.controlGroup.stopButton, {id, 1});
177 grid.add(armarx::RemoteGui::Client::VSpacer(), {id, 1});
180 grid.add(tab.controlGroup.stopAllButton, {id, 1});
184 VBoxLayout root = {grid, VSpacer()};
185 tab.controlGroup.group.addChild(root);
190 tab.hbox.addChild(tab.targetPoseGroup.group);
191 tab.hbox.addChild(tab.controlGroup.group);
193 tab.create(REMOTE_GUI_TAB_MAME, remoteGui, tab.hbox);
199 constexpr int kCycleDurationMs = 100;
201 CycleUtil c(kCycleDurationMs);
202 while (!runningTask->isStopped())
207 std::lock_guard g{mtx};
210 tab.receiveUpdates();
211 tabPrx.receiveUpdates();
215 handleEvents(tabPrx);
218 std::lock_guard g{mtx};
222 tabPrx.sendUpdates();
226 c.waitForCycleDuration();
231 RemoteGui::handleEvents(::armarx::RemoteGui::TabProxy& tab3)
235 const std::string configId = "RemoteGui";
237 if (tab.controlGroup.moveToButton.wasClicked())
239 ARMARX_INFO << "MoveTo from RemoteGUI requested";
241 // const auto& scene = navigator.getScene();
243 // server::NavigationStack stack
246 // std::make_shared<global_planning::Point2Point>(global_planning::Point2PointParams(), scene),
247 // .trajectoryControl = std::make_shared<traj_ctrl::TrajectoryFollowingController>(
248 // traj_ctrl::TrajectoryFollowingControllerParams(), scene)};
250 // server::NavigationStack stack
253 // std::make_shared<global_planning::AStar>(global_planning::AStarParams(), scene),
254 // .trajectoryControl = std::make_shared<traj_ctrl::TrajectoryFollowingController>(
255 // traj_ctrl::TrajectoryFollowingControllerParams(), scene)};
257 client::NavigationStackConfig cfg;
258 cfg.globalPlanner(global_planning::SPFAParams());
259 cfg.localPlanner(local_planning::TimedElasticBandsParams());
260 cfg.trajectoryController(traj_ctrl::local::TrajectoryFollowingControllerParams());
262 const auto stackConfig = cfg.toAron();
266 navigator.createConfig(stackConfig, "RemoteGui");
268 const Eigen::Vector3f targetPos{tab.targetPoseGroup.targetPoseX.getValue(),
269 tab.targetPoseGroup.targetPoseY.getValue(),
270 tab.targetPoseGroup.targetPoseZ.getValue()};
272 const auto degToRad = [](float deg) -> float { return deg * M_PIf32 / 180.f; };
274 const Eigen::Vector3f targetOri{
275 degToRad(tab.targetPoseGroup.targetPoseRoll.getValue()),
276 degToRad(tab.targetPoseGroup.targetPosePitch.getValue()),
277 degToRad(tab.targetPoseGroup.targetPoseYaw.getValue())};
279 const core::Pose targetPose = core::Pose(Eigen::Translation3f(targetPos)) *
280 core::Pose(simox::math::rpy_to_mat3f(targetOri));
282 std::vector<Eigen::Matrix4f> waypoints;
283 waypoints.emplace_back(targetPose.matrix());
291 core::NavigationFrameNames.to_name(core::NavigationFrame::Absolute),
294 catch (const armarx::LocalException& ex)
296 ARMARX_WARNING << LogSender::eYellow
297 << "Failed moving to target. Reason: " << GetHandledExceptionString()
298 << LogSender::eReset;
302 if (tab.controlGroup.pauseButton.wasClicked())
304 ARMARX_INFO << "pauseMovement() from RemoteGUI requested";
305 navigator.pause(configId);
308 if (tab.controlGroup.continueButton.wasClicked())
310 ARMARX_INFO << "resumeMovement() from RemoteGUI requested";
311 navigator.resume(configId);
314 if (tab.controlGroup.stopButton.wasClicked())
316 ARMARX_INFO << "stop() from RemoteGUI requested";
317 navigator.stop(configId);
320 if (tab.controlGroup.stopAllButton.wasClicked())
322 ARMARX_INFO << "stop() from RemoteGUI requested";
328 RemoteGui::shutdown()
330 // std::lock_guard g{mtx};
332 if (!runningTask->isStopped())
337 ARMARX_DEBUG << "Removing tab: " << REMOTE_GUI_TAB_MAME;
338 remoteGui->removeTab(REMOTE_GUI_TAB_MAME);
346 // std::lock_guard g{mtx};
347 tabPrx.internalSetDisabled(tab.controlGroup.moveToButton.getName(), false);
348 tabPrx.internalSetDisabled(tab.controlGroup.pauseButton.getName(), false);
349 tabPrx.internalSetDisabled(tab.controlGroup.continueButton.getName(), false);
350 tabPrx.internalSetDisabled(tab.controlGroup.stopButton.getName(), false);
351 tabPrx.internalSetDisabled(tab.controlGroup.stopAllButton.getName(), false);
359 // std::unique_lock g{mtx};
361 // it might happen, that this function is triggered from handleEvents
362 // std::unique_lock ul{handleEventsMtx};
365 tabPrx.internalSetDisabled(tab.controlGroup.moveToButton.getName(), true);
366 tabPrx.internalSetDisabled(tab.controlGroup.pauseButton.getName(), true);
367 tabPrx.internalSetDisabled(tab.controlGroup.continueButton.getName(), true);
368 tabPrx.internalSetDisabled(tab.controlGroup.stopButton.getName(), true);
369 tabPrx.internalSetDisabled(tab.controlGroup.stopAllButton.getName(), true);
377 // std::lock_guard g{mtx};
379 tab.targetPoseGroup.targetPoseX.setValue(0.F);
380 tab.targetPoseGroup.targetPoseY.setValue(0.F);
381 tab.targetPoseGroup.targetPoseZ.setValue(0.F);
382 tab.targetPoseGroup.targetPoseRoll.setValue(0.F);
383 tab.targetPoseGroup.targetPosePitch.setValue(0.F);
384 tab.targetPoseGroup.targetPoseYaw.setValue(0.F);
390 } // namespace armarx::navigation::components::navigator