11#include <ArmarXGui/interface/RemoteGuiInterface.h>
22 const Eigen::Isometry3f& initialWorldToMap) :
26 initialWorldToMap(initialWorldToMap),
27 lastSentValues(
Eigen::Vector3f::Zero())
36 if (runningTask->isRunning())
43 LocalizationRemoteGui::createRemoteGuiTab()
48 const float x0 = initialWorldToMap.translation().x();
49 const float y0 = initialWorldToMap.translation().y();
51 std::atan2(initialWorldToMap.linear()(1, 0), initialWorldToMap.linear()(0, 0));
53 lastSentValues = {x0, y0, yaw0};
55 guiTab.worldToMap.group.
setLabel(
"World to map registration");
57 constexpr float posMax = 1e6F;
58 guiTab.worldToMap.x.
setName(
"x");
59 guiTab.worldToMap.x.
setRange(-posMax, posMax);
61 guiTab.worldToMap.x.
setSteps(
static_cast<int>(posMax / 10));
64 guiTab.worldToMap.y.
setName(
"y");
65 guiTab.worldToMap.y.
setRange(-posMax, posMax);
67 guiTab.worldToMap.y.
setSteps(
static_cast<int>(posMax / 10));
70 guiTab.worldToMap.yaw.
setName(
"yaw");
71 guiTab.worldToMap.yaw.
setRange(-
static_cast<float>(
M_PI),
static_cast<float>(
M_PI));
73 guiTab.worldToMap.yaw.
setSteps(3600);
74 guiTab.worldToMap.yaw.
setValue(yaw0);
76 guiTab.worldToMap.applyImmediately.
setName(
"applyImmediately");
78 guiTab.worldToMap.applyImmediately.
setValue(
false);
80 guiTab.worldToMap.applyButton.
setLabel(
"Apply");
86 .add(guiTab.worldToMap.x, {.row = row, .column = 1});
90 .add(guiTab.worldToMap.y, {.row = row, .column = 1});
94 .add(guiTab.worldToMap.yaw, {.row = row, .column = 1});
98 .add(guiTab.worldToMap.applyImmediately, {.row = row, .column = 1});
102 guiTab.worldToMap.applyButton, {.row = row, .column = 0}, {.rows = 1, .columns = 2});
105 armarx::RemoteGui::Client::VBoxLayout root = {grid, armarx::RemoteGui::Client::VSpacer()};
106 guiTab.worldToMap.group.addChild(root);
107 guiTab.hbox.addChild(guiTab.worldToMap.group);
109 guiTab.create(REMOTE_GUI_TAB_NAME, remoteGui, guiTab.hbox);
113 LocalizationRemoteGui::run()
115 constexpr int kCycleDurationMs = 100;
116 CycleUtil
c(kCycleDurationMs);
118 while (!runningTask->isStopped())
121 std::lock_guard g{mtx};
122 tab.receiveUpdates();
123 guiTab.receiveUpdates();
129 std::lock_guard g{mtx};
131 guiTab.sendUpdates();
134 c.waitForCycleDuration();
139 LocalizationRemoteGui::handleEvents(RemoteGui::TabProxy& )
142 std::lock_guard g{handleEventsMtx};
144 const Eigen::Vector3f current{guiTab.worldToMap.x.getValue(),
145 guiTab.worldToMap.y.getValue(),
146 guiTab.worldToMap.yaw.getValue()};
148 const bool valuesChanged = (current - lastSentValues).cwiseAbs().maxCoeff() > 1e-5F;
150 const auto buildTransform = [&]() -> Eigen::Isometry3f
152 Eigen::Isometry3f t = Eigen::Isometry3f::Identity();
153 t.translation().x() = current.x();
154 t.translation().y() = current.y();
156 Eigen::AngleAxisf(current.z(), Eigen::Vector3f::UnitZ()).toRotationMatrix();
160 if (valuesChanged and guiTab.worldToMap.applyImmediately.getValue())
162 lastSentValues = current;
163 callee.onWorldToMapTransformUpdate(buildTransform());
166 bool wasButtonClicked =
false;
169 wasButtonClicked = guiTab.worldToMap.applyButton.wasClicked();
171 catch (armarx::LocalException&)
176 if (wasButtonClicked)
178 lastSentValues = current;
179 callee.onWorldToMapTransformUpdate(buildTransform());
186 if (!runningTask->isStopped())
190 ARMARX_DEBUG <<
"Removing tab: " << REMOTE_GUI_TAB_NAME;
191 remoteGui->removeTab(REMOTE_GUI_TAB_NAME);
198 tab.internalSetDisabled(guiTab.worldToMap.applyButton.getName(),
false);
199 tab.internalSetDisabled(guiTab.worldToMap.applyImmediately.getName(),
false);
206 tab.internalSetDisabled(guiTab.worldToMap.applyButton.getName(),
true);
207 tab.internalSetDisabled(guiTab.worldToMap.applyImmediately.getName(),
true);
LocalizationRemoteGui(const RemoteGuiInterfacePrx &remoteGui, LocalizationRemoteGuiCallee &callee, const Eigen::Isometry3f &initialWorldToMap)
#define ARMARX_CHECK_NOT_NULL(ptr)
This macro evaluates whether ptr is not null and if it turns out to be false it will throw an Express...
#define ARMARX_INFO
The normal logging level.
#define ARMARX_DEBUG
The logging level for output that is only interesting while debugging.
std::string GetHandledExceptionString()
void setValue(bool newValue)
void setDecimals(int decimals)
void setRange(float min, float max)
void setValue(float newValue)
GridLayout & add(Widget const &child, Pos pos, Span span=Span{1, 1})
void setLabel(std::string const &text)