HumanActivityDebugger.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_activity_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
40 const std::string HumanActivityDebugger::activity_provider_name = "human_activity_debugger";
41
44 {
47 def->defineRequiredProperty<std::string>("robotName");
48 return def;
49 }
50
51 void
55
56 void
58 {
59 running = true;
60 properties.robotName = this->getProperty<std::string>("robotName");
61
62 // Connect reader and writer
63 activityWriter.connect(memoryNameSystem());
64 activityReader.connect(memoryNameSystem());
65
66 while (running)
67 {
68 this->run();
69 }
70 }
71
72 void
76
77 void
81
82 void
83 HumanActivityDebugger::run()
84 {
85 ARMARX_INFO << "Use 'activity [firstName] [lastName] [activityType] [activityName] "
86 "[confidence]' to commit an activity";
87 ARMARX_INFO << " Activity types: WALKING, STANDING, SITTING, REACHING, GRASPING, "
88 "POINTING, WAVING, TALKING, LISTENING, WORKING, EATING, DRINKING";
89 ARMARX_INFO << " Example: activity John Doe WALKING walking 0.95";
90 ARMARX_INFO << "Use 'read' to read all activities";
91 ARMARX_INFO << "Use 'exit' to exit";
92
93 std::string command;
94 std::cin >> command;
95
96 if (command == "activity")
97 {
98 activityCommand();
99 }
100 else if (command == "read")
101 {
102 readActivityCommand();
103 }
104 else if (command == "exit")
105 {
106 running = false;
107 }
108 else
109 {
110 ARMARX_WARNING << "Unrecognized command. Ignoring... "
111 << "\n"
112 << command;
113 }
114
115 std::cin.clear();
116 }
117
118 void
119 HumanActivityDebugger::activityCommand()
120 {
121 std::string firstName, lastName, activityTypeStr, activityName, confidenceStr;
122 std::cin >> firstName >> lastName >> activityTypeStr >> activityName >> confidenceStr;
123
124 float confidence = std::stof(confidenceStr);
125
126 // Parse activity type
129
130 std::string activityTypeUpper = simox::alg::to_upper(activityTypeStr);
131
132 if (activityTypeUpper == "WALKING")
134 else if (activityTypeUpper == "STANDING")
136 else if (activityTypeUpper == "SITTING")
138 else if (activityTypeUpper == "REACHING")
140 else if (activityTypeUpper == "GRASPING")
142 else if (activityTypeUpper == "POINTING")
144 else if (activityTypeUpper == "WAVING")
146 else if (activityTypeUpper == "TALKING")
148 else if (activityTypeUpper == "LISTENING")
150 else if (activityTypeUpper == "WORKING")
152 else if (activityTypeUpper == "EATING")
154 else if (activityTypeUpper == "DRINKING")
156 else if (activityTypeUpper == "CUSTOM")
158 else
159 {
160 ARMARX_WARNING << "Unknown activity type: " << activityTypeStr << ". Using UNKNOWN.";
161 }
162
163 commitActivity(firstName, lastName, activityType, activityName, confidence);
164 }
165
166 void
167 HumanActivityDebugger::readActivityCommand()
168 {
169 // Use ActivityReader to query all activities
170 armarx::armem::human::client::ActivityReader::Query query = {
171 .providerName = "", // Query all providers
172 .timestamp = armarx::armem::Time::Now(),
173 .maxAge = armarx::Duration::Minutes(1000)};
174
175 auto result = activityReader.query(query, true);
176
177 if (not result)
178 {
179 ARMARX_WARNING << "Failed to read activities from memory: " << result.errorMessage;
180 return;
181 }
182
183 if (result.activities.empty())
184 {
185 ARMARX_INFO << "No activities found in memory.";
186 return;
187 }
188
189 ARMARX_INFO << "Activities in memory (" << result.activities.size() << " total):";
190 for (const auto& activity : result.activities)
191 {
192 ARMARX_INFO << " Activity: " << activity.activityName;
193 ARMARX_INFO << " Type: " << static_cast<int>(activity.activityType);
194 ARMARX_INFO << " Confidence: " << activity.confidence;
195
196 if (activity.personID.has_value())
197 {
198 ARMARX_INFO << " Person: " << activity.personID.value().firstName << " "
199 << activity.personID.value().lastName;
200 }
201 else
202 {
203 ARMARX_INFO << " Person: (none)";
204 }
205
206 if (activity.description.has_value())
207 {
208 ARMARX_INFO << " Description: " << activity.description.value();
209 }
210
211 ARMARX_INFO << " Start time: " << activity.startTime;
212 ARMARX_INFO << " End time: " << activity.endTime;
213 ARMARX_INFO << ""; // Empty line for readability
214 }
215 }
216
217 void
218 HumanActivityDebugger::commitActivity(const std::string& firstName,
219 const std::string& lastName,
221 const std::string& activityName,
222 float confidence)
223 {
224 // Create the HumanActivity business object
225 armarx::armem::human::HumanActivity activity;
226 activity.activityType = activityType;
227 activity.activityName = activityName;
228 activity.confidence = confidence;
229 activity.startTime = armarx::DateTime::Now();
230 activity.endTime = armarx::DateTime::Now();
231
232 // Set person ID
233 armarx::armem::human::PersonID personID;
234 personID.firstName = firstName;
235 personID.lastName = lastName;
236 activity.personID = personID;
237
238 activity.description = "Debug activity created by HumanActivityDebugger";
239
240 // Use ActivityWriter to commit
241 std::string entityName = personID.toMemoryEntityID();
242 ARMARX_INFO << "Committing activity '" << activityName << "' for person " << firstName
243 << " " << lastName << " (entity: " << entityName << ") with confidence "
244 << confidence;
245
246 bool success = activityWriter.commitHumanActivity(
248
249 if (success)
250 {
251 ARMARX_INFO << "Successfully committed activity.";
252 }
253 else
254 {
255 ARMARX_WARNING << "Failed to commit activity.";
256 }
257 }
258
259 std::string
261 {
262 return "HumanActivityDebugger";
263 }
264
265} // namespace visionx::components::human_activity_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
IceUtil::Handle< class PropertyDefinitionContainer > PropertyDefinitionsPtr
PropertyDefinitions smart pointer type.
armarx::core::time::DateTime startTime
Definition types.h:302
armarx::core::time::DateTime endTime
Definition types.h:303
std::optional< std::string > description
Definition types.h:305
std::optional< PersonID > personID
Definition types.h:304
std::string toMemoryEntityID() const
Definition types.h:144