HumanRobotInteractionDebugger.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 VisionX::ArmarXObjects::human_robot_interaction_debugger
17 * @author Joana Plewnia ( joana dot plewnia at kit dot edu )
18 * @date 2025
19 * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
20 * GNU General Public License
21 */
22
23
25
26#include <optional>
27#include <utility>
28
29#include <SimoxUtility/algorithm/string/string_tools.h>
30
32
34
36
38{
39
41 "human_robot_interaction_debugger";
42
45 {
48 def->defineRequiredProperty<std::string>("robotName");
49 return def;
50 }
51
52 void
56
57 void
59 {
60 running = true;
61 properties.robotName = this->getProperty<std::string>("robotName");
62
63 // Connect reader and writer
64 interactionWriter.connect(memoryNameSystem());
65 interactionReader.connect(memoryNameSystem());
66
67 while (running)
68 {
69 this->run();
70 }
71 }
72
73 void
77
78 void
82
83 void
84 HumanRobotInteractionDebugger::run()
85 {
86 ARMARX_INFO << "Use 'interaction [firstName] [lastName] [interactionType] "
87 "[interactionName] [robotName] [confidence]' to commit an interaction";
88 ARMARX_INFO << " Interaction types: HANDOVER, ANSWERING_QUESTION, SERVING_DRINK, "
89 "SERVING_FOOD, GUIDING, ASSISTING, CONVERSATION, GREETING, FAREWELL";
90 ARMARX_INFO << " Example: interaction John Doe HANDOVER HandoverBottle Armar6 0.95";
91 ARMARX_INFO << "Use 'read' to read all interactions";
92 ARMARX_INFO << "Use 'exit' to exit";
93
94 std::string command;
95 std::cin >> command;
96
97 if (command == "interaction")
98 {
99 interactionCommand();
100 }
101 else if (command == "read")
102 {
103 readInteractionCommand();
104 }
105 else if (command == "exit")
106 {
107 running = false;
108 }
109 else
110 {
111 ARMARX_WARNING << "Unrecognized command. Ignoring... "
112 << "\n"
113 << command;
114 }
115
116 std::cin.clear();
117 }
118
119 void
120 HumanRobotInteractionDebugger::interactionCommand()
121 {
122 std::string firstName, lastName, interactionTypeStr, interactionName, robotName,
123 confidenceStr;
124 std::cin >> firstName >> lastName >> interactionTypeStr >> interactionName >> robotName >>
125 confidenceStr;
126
127 float confidence = std::stof(confidenceStr);
128
129 // Parse interaction type
132
133 std::string interactionTypeUpper = simox::alg::to_upper(interactionTypeStr);
134
135 if (interactionTypeUpper == "HANDOVER")
137 else if (interactionTypeUpper == "ANSWERING_QUESTION")
139 else if (interactionTypeUpper == "SERVING_DRINK")
141 else if (interactionTypeUpper == "SERVING_FOOD")
143 else if (interactionTypeUpper == "GUIDING")
145 else if (interactionTypeUpper == "ASSISTING")
147 else if (interactionTypeUpper == "CONVERSATION")
149 else if (interactionTypeUpper == "GREETING")
151 else if (interactionTypeUpper == "FAREWELL")
153 else if (interactionTypeUpper == "CUSTOM")
155 else
156 {
157 ARMARX_WARNING << "Unknown interaction type: " << interactionTypeStr
158 << ". Using UNKNOWN.";
159 }
160
161 commitInteraction(firstName, lastName, interactionType, interactionName, robotName, confidence);
162 }
163
164 void
165 HumanRobotInteractionDebugger::readInteractionCommand()
166 {
167 // Use InteractionReader to query all interactions
168 armarx::armem::human::client::InteractionReader::Query query = {
169 .providerName = "", // Query all providers
170 .timestamp = armarx::armem::Time::Now(),
171 .maxAge = armarx::Duration::Minutes(1000)};
172
173 auto result = interactionReader.query(query, true);
174
175 if (not result)
176 {
177 ARMARX_WARNING << "Failed to read interactions from memory: " << result.errorMessage;
178 return;
179 }
180
181 if (result.interactions.empty())
182 {
183 ARMARX_INFO << "No interactions found in memory.";
184 return;
185 }
186
187 ARMARX_INFO << "Interactions in memory (" << result.interactions.size() << " total):";
188 for (const auto& interaction : result.interactions)
189 {
190 ARMARX_INFO << " Interaction: " << interaction.interactionName;
191 ARMARX_INFO << " Type: " << static_cast<int>(interaction.interactionType);
192 ARMARX_INFO << " Confidence: " << interaction.confidence;
193
194 if (interaction.personID.has_value())
195 {
196 ARMARX_INFO << " Person: " << interaction.personID.value().firstName << " "
197 << interaction.personID.value().lastName;
198 }
199 else
200 {
201 ARMARX_INFO << " Person: (none)";
202 }
203
204 if (interaction.robotName.has_value())
205 {
206 ARMARX_INFO << " Robot: " << interaction.robotName.value();
207 }
208 else
209 {
210 ARMARX_INFO << " Robot: (none)";
211 }
212
213 if (interaction.description.has_value())
214 {
215 ARMARX_INFO << " Description: " << interaction.description.value();
216 }
217
218 ARMARX_INFO << " Start time: " << interaction.startTime;
219 ARMARX_INFO << " End time: " << interaction.endTime;
220 ARMARX_INFO << ""; // Empty line for readability
221 }
222 }
223
224 void
225 HumanRobotInteractionDebugger::commitInteraction(
226 const std::string& firstName,
227 const std::string& lastName,
229 const std::string& interactionName,
230 const std::string& robotName,
231 float confidence)
232 {
233 // Create the HumanRobotInteraction business object
234 armarx::armem::human::HumanRobotInteraction interaction;
235 interaction.interactionType = interactionType;
236 interaction.interactionName = interactionName;
237 interaction.confidence = confidence;
240 interaction.robotName = robotName;
241
242 // Set person ID
243 armarx::armem::human::PersonID personID;
244 personID.firstName = firstName;
245 personID.lastName = lastName;
246 interaction.personID = personID;
247
248 interaction.description = "Debug interaction created by HumanRobotInteractionDebugger";
249
250 // Use InteractionWriter to commit
251 std::string entityName = personID.toMemoryEntityID();
252 ARMARX_INFO << "Committing interaction '" << interactionName << "' for person " << firstName
253 << " " << lastName << " with robot " << robotName << " (entity: " << entityName
254 << ") with confidence " << confidence;
255
256 bool success = interactionWriter.commitHumanRobotInteraction(
258
259 if (success)
260 {
261 ARMARX_INFO << "Successfully committed interaction.";
262 }
263 else
264 {
265 ARMARX_WARNING << "Failed to commit interaction.";
266 }
267 }
268
269 std::string
271 {
272 return "HumanRobotInteractionDebugger";
273 }
274
275} // namespace visionx::components::human_robot_interaction_debugger
Default component property definition container.
Definition Component.h:70
std::string getConfigIdentifier()
Retrieve config identifier for this component as set in constructor.
Definition Component.cpp:90
Property< PropertyType > getProperty(const std::string &name)
static DateTime Now()
Definition DateTime.cpp:51
static Duration Minutes(std::int64_t minutes)
Constructs a duration in minutes.
Definition Duration.cpp:96
static DateTime Now()
Definition DateTime.cpp:51
#define ARMARX_INFO
The normal logging level.
Definition Logging.h:181
#define ARMARX_WARNING
The logging level for unexpected behaviour, but not a serious problem.
Definition Logging.h:193
InteractionDescription interaction()
Definition ElementOps.h:109
IceUtil::Handle< class PropertyDefinitionContainer > PropertyDefinitionsPtr
PropertyDefinitions smart pointer type.
std::string toMemoryEntityID() const
Definition types.h:144