InterventionDebugger.cpp
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 * @package RobotAPI::ArmarXObjects::InterventionDebugger
17 * @date 2026
18 * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
19 * GNU General Public License
20 */
21
23
27
28namespace armarx
29{
33
40
41 void
43 {
44 deviceName = getProperty<std::string>("DeviceName").getValue();
45 gamepadName = getProperty<std::string>("GamepadName").getValue();
46
47 offeringTopic(getProperty<std::string>("GamepadTopicName").getValue());
48 offeringTopic(getProperty<std::string>("EmergencyStopTopicName").getValue());
49 }
50
51 void
53 {
54 gamepadTopicPrx =
55 getTopic<GamepadUnitListenerPrx>(getProperty<std::string>("GamepadTopicName").getValue());
56 emergencyStopTopicPrx = getTopic<EmergencyStopListenerPrx>(
57 getProperty<std::string>("EmergencyStopTopicName").getValue());
58
59 createGamepadTab();
60 createEmergencyStopTab();
61
63 }
64
65 void
67 {
68 gamepadTab.remove();
69 estopTab.remove();
70 }
71
72 void
76
77 void
78 InterventionDebugger::RemoteGui_update()
79 {
80 updateGamepadTab();
81 updateEmergencyStopTab();
82 }
83
84 // ---- Gamepad Tab ----
85
86 void
87 InterventionDebugger::createGamepadTab()
88 {
89 VBoxLayout root;
90
91 // --- Analog sticks ---
92 {
93 GroupBox group;
94 group.setLabel("Analog Sticks");
95
96 VBoxLayout layout;
97
98 gamepadTab.leftStickX.setRange(-1.0f, 1.0f);
99 gamepadTab.leftStickX.setSteps(200);
100 gamepadTab.leftStickX.setValue(0.0f);
101 layout.addChild(HBoxLayout{Label("Left Stick X:"), gamepadTab.leftStickX});
102
103 gamepadTab.leftStickY.setRange(-1.0f, 1.0f);
104 gamepadTab.leftStickY.setSteps(200);
105 gamepadTab.leftStickY.setValue(0.0f);
106 layout.addChild(HBoxLayout{Label("Left Stick Y:"), gamepadTab.leftStickY});
107
108 gamepadTab.rightStickX.setRange(-1.0f, 1.0f);
109 gamepadTab.rightStickX.setSteps(200);
110 gamepadTab.rightStickX.setValue(0.0f);
111 layout.addChild(HBoxLayout{Label("Right Stick X:"), gamepadTab.rightStickX});
112
113 gamepadTab.rightStickY.setRange(-1.0f, 1.0f);
114 gamepadTab.rightStickY.setSteps(200);
115 gamepadTab.rightStickY.setValue(0.0f);
116 layout.addChild(HBoxLayout{Label("Right Stick Y:"), gamepadTab.rightStickY});
117
118 group.addChild(layout);
119 root.addChild(group);
120 }
121
122 // --- D-Pad ---
123 {
124 GroupBox group;
125 group.setLabel("D-Pad");
126
127 VBoxLayout layout;
128
129 gamepadTab.dPadX.setRange(-1.0f, 1.0f);
130 gamepadTab.dPadX.setSteps(200);
131 gamepadTab.dPadX.setValue(0.0f);
132 layout.addChild(HBoxLayout{Label("D-Pad X:"), gamepadTab.dPadX});
133
134 gamepadTab.dPadY.setRange(-1.0f, 1.0f);
135 gamepadTab.dPadY.setSteps(200);
136 gamepadTab.dPadY.setValue(0.0f);
137 layout.addChild(HBoxLayout{Label("D-Pad Y:"), gamepadTab.dPadY});
138
139 group.addChild(layout);
140 root.addChild(group);
141 }
142
143 // --- Triggers ---
144 {
145 GroupBox group;
146 group.setLabel("Triggers");
147
148 VBoxLayout layout;
149
150 gamepadTab.leftTrigger.setRange(0.0f, 1.0f);
151 gamepadTab.leftTrigger.setSteps(100);
152 gamepadTab.leftTrigger.setValue(0.0f);
153 layout.addChild(HBoxLayout{Label("Left Trigger:"), gamepadTab.leftTrigger});
154
155 gamepadTab.rightTrigger.setRange(0.0f, 1.0f);
156 gamepadTab.rightTrigger.setSteps(100);
157 gamepadTab.rightTrigger.setValue(0.0f);
158 layout.addChild(HBoxLayout{Label("Right Trigger:"), gamepadTab.rightTrigger});
159
160 group.addChild(layout);
161 root.addChild(group);
162 }
163
164 // --- Buttons ---
165 {
166 GroupBox group;
167 group.setLabel("Buttons");
168
169 VBoxLayout layout;
170
171 gamepadTab.aButton.setLabel("A");
172 gamepadTab.aButton.setValue(false);
173 gamepadTab.bButton.setLabel("B");
174 gamepadTab.bButton.setValue(false);
175 gamepadTab.xButton.setLabel("X");
176 gamepadTab.xButton.setValue(false);
177 gamepadTab.yButton.setLabel("Y");
178 gamepadTab.yButton.setValue(false);
179 layout.addChild(HBoxLayout{
180 Label("Face:"),
181 gamepadTab.aButton,
182 gamepadTab.bButton,
183 gamepadTab.xButton,
184 gamepadTab.yButton});
185
186 gamepadTab.leftButton.setLabel("LB");
187 gamepadTab.leftButton.setValue(false);
188 gamepadTab.rightButton.setLabel("RB");
189 gamepadTab.rightButton.setValue(false);
190 layout.addChild(
191 HBoxLayout{Label("Bumpers:"), gamepadTab.leftButton, gamepadTab.rightButton});
192
193 gamepadTab.backButton.setLabel("Back");
194 gamepadTab.backButton.setValue(false);
195 gamepadTab.startButton.setLabel("Start");
196 gamepadTab.startButton.setValue(false);
197 gamepadTab.theMiddleButton.setLabel("Middle");
198 gamepadTab.theMiddleButton.setValue(false);
199 layout.addChild(HBoxLayout{Label("System:"),
200 gamepadTab.backButton,
201 gamepadTab.startButton,
202 gamepadTab.theMiddleButton});
203
204 gamepadTab.leftStickButton.setLabel("L3");
205 gamepadTab.leftStickButton.setValue(false);
206 gamepadTab.rightStickButton.setLabel("R3");
207 gamepadTab.rightStickButton.setValue(false);
208 layout.addChild(HBoxLayout{
209 Label("Stick Buttons:"), gamepadTab.leftStickButton, gamepadTab.rightStickButton});
210
211 group.addChild(layout);
212 root.addChild(group);
213 }
214
215 // --- Reset ---
216 {
217 gamepadTab.resetAll.setLabel("Reset All to Zero");
218 root.addChild(HBoxLayout{gamepadTab.resetAll, HSpacer()});
219 }
220
221 root.addChild(VSpacer());
222
223 RemoteGui_createTab("Gamepad", root, &gamepadTab);
224 }
225
226 void
227 InterventionDebugger::updateGamepadTab()
228 {
229 // Note: receiveUpdates()/sendUpdates() are called automatically by the
230 // LightweightRemoteGui framework around RemoteGui_update().
231
232 if (gamepadTab.resetAll.wasClicked())
233 {
234 gamepadTab.leftStickX.setValue(0.0f);
235 gamepadTab.leftStickY.setValue(0.0f);
236 gamepadTab.rightStickX.setValue(0.0f);
237 gamepadTab.rightStickY.setValue(0.0f);
238 gamepadTab.dPadX.setValue(0.0f);
239 gamepadTab.dPadY.setValue(0.0f);
240 gamepadTab.leftTrigger.setValue(0.0f);
241 gamepadTab.rightTrigger.setValue(0.0f);
242
243 gamepadTab.aButton.setValue(false);
244 gamepadTab.bButton.setValue(false);
245 gamepadTab.xButton.setValue(false);
246 gamepadTab.yButton.setValue(false);
247 gamepadTab.leftButton.setValue(false);
248 gamepadTab.rightButton.setValue(false);
249 gamepadTab.backButton.setValue(false);
250 gamepadTab.startButton.setValue(false);
251 gamepadTab.theMiddleButton.setValue(false);
252 gamepadTab.leftStickButton.setValue(false);
253 gamepadTab.rightStickButton.setValue(false);
254 }
255
256 publishGamepadState();
257 }
258
259 void
260 InterventionDebugger::publishGamepadState()
261 {
262 GamepadData data;
263 data.leftStickX = gamepadTab.leftStickX.getValue();
264 data.leftStickY = gamepadTab.leftStickY.getValue();
265 data.rightStickX = gamepadTab.rightStickX.getValue();
266 data.rightStickY = gamepadTab.rightStickY.getValue();
267 data.dPadX = gamepadTab.dPadX.getValue();
268 data.dPadY = gamepadTab.dPadY.getValue();
269 data.leftTrigger = gamepadTab.leftTrigger.getValue();
270 data.rightTrigger = gamepadTab.rightTrigger.getValue();
271
272 data.aButton = gamepadTab.aButton.getValue();
273 data.bButton = gamepadTab.bButton.getValue();
274 data.xButton = gamepadTab.xButton.getValue();
275 data.yButton = gamepadTab.yButton.getValue();
276 data.leftButton = gamepadTab.leftButton.getValue();
277 data.rightButton = gamepadTab.rightButton.getValue();
278 data.backButton = gamepadTab.backButton.getValue();
279 data.startButton = gamepadTab.startButton.getValue();
280 data.theMiddleButton = gamepadTab.theMiddleButton.getValue();
281 data.leftStickButton = gamepadTab.leftStickButton.getValue();
282 data.rightStickButton = gamepadTab.rightStickButton.getValue();
283
284 auto timestamp = new TimestampVariant(IceUtil::Time::now());
285
286 gamepadTopicPrx->reportGamepadState(deviceName, gamepadName, data, timestamp);
287 }
288
289 // ---- Emergency Stop Tab ----
290
291 void
292 InterventionDebugger::createEmergencyStopTab()
293 {
294 VBoxLayout root;
295
296 GroupBox group;
297 group.setLabel("Emergency Stop");
298
299 estopTab.emergencyStopActive.setLabel("Emergency Stop Active");
300 estopTab.emergencyStopActive.setValue(false);
301
302 VBoxLayout layout;
303 layout.addChild(estopTab.emergencyStopActive);
304 layout.addChild(VSpacer());
305
306 group.addChild(layout);
307 root.addChild(group);
308 root.addChild(VSpacer());
309
310 RemoteGui_createTab("EmergencyStop", root, &estopTab);
311 }
312
313 void
314 InterventionDebugger::updateEmergencyStopTab()
315 {
316 if (estopTab.emergencyStopActive.hasValueChanged())
317 {
318 const bool active = estopTab.emergencyStopActive.getValue();
319 const auto state = active ? EmergencyStopState::eEmergencyStopActive
320 : EmergencyStopState::eEmergencyStopInactive;
321
322 publishEmergencyStopState(state);
323 lastPublishedEstopState = state;
324 }
325 }
326
327 void
328 InterventionDebugger::publishEmergencyStopState(EmergencyStopState state)
329 {
330 ARMARX_INFO << "Publishing emergency stop state: "
331 << (state == EmergencyStopState::eEmergencyStopActive ? "ACTIVE" : "INACTIVE");
332
333 emergencyStopTopicPrx->reportEmergencyStopState(state);
334 }
335
338} // namespace armarx
int Label(int n[], int size, int *curLabel, MiscLib::Vector< std::pair< int, size_t > > *labels)
Definition Bitmap.cpp:801
std::string timestamp()
#define ARMARX_REGISTER_COMPONENT_EXECUTABLE(ComponentT, applicationName)
Definition Decoupled.h:29
uint8_t data[1]
std::string getConfigIdentifier()
Retrieve config identifier for this component as set in constructor.
Definition Component.cpp:90
Property< PropertyType > getProperty(const std::string &name)
Debug component for InterventionObserver.
void onInitComponent() override
Pure virtual hook for the subclass.
void onDisconnectComponent() override
Hook for subclass.
armarx::PropertyDefinitionsPtr createPropertyDefinitions() override
void onConnectComponent() override
Pure virtual hook for the subclass.
void onExitComponent() override
Hook for subclass.
void offeringTopic(const std::string &name)
Registers a topic for retrival after initialization.
TopicProxyType getTopic(const std::string &name)
Returns a proxy of the specified topic.
#define ARMARX_INFO
The normal logging level.
Definition Logging.h:181
This file offers overloads of toIce() and fromIce() functions for STL container types.
IceUtil::Handle< class PropertyDefinitionContainer > PropertyDefinitionsPtr
PropertyDefinitions smart pointer type.
void RemoteGui_createTab(std::string const &name, RemoteGui::Client::Widget const &rootWidget, RemoteGui::Client::Tab *tab)
void setRange(float min, float max)
Definition Widgets.cpp:375