71 def->defineRequiredProperty<std::string>(
"robotName");
103 PersonMemoryDebugger::run()
105 ARMARX_INFO <<
"Use 'pose [id] [x] [y] [z]' to commit a pose at location";
106 ARMARX_INFO <<
"Use 'face [profile entityName] [x] [y] [z]' to commit a face at location";
107 ARMARX_INFO <<
"Use 'profile [firstName lastName]' to commit a profile";
108 ARMARX_INFO <<
"Use 'read [firstName lastName]' to read a profile";
109 ARMARX_INFO <<
"Use 'readPreferences [firstName lastName]' to read a profiles preferences";
110 ARMARX_INFO <<
"Use 'writePreferences [firstName lastName]' to write debug values to a "
111 "profiles preferences";
112 ARMARX_INFO <<
"Use 'setCustomAttribute [firstName lastName]' to write a debug attribute "
114 ARMARX_INFO <<
"Use 'readDrinkPreference [firstName lastName]' to read the drink "
115 "preferences from a profile";
116 ARMARX_INFO <<
"Use 'setDrinkPreference [firstName lastName drink]' to set a drink as "
117 "someones favorite drink";
118 ARMARX_INFO <<
"Use 'createPersonInstance [firstName lastName]' to create a new "
119 "PersonInstance and commit it to memory";
124 if (command ==
"pose")
128 else if (command ==
"face")
130 faceRecognitionCommand();
132 else if (command ==
"profile")
136 else if (command ==
"exit")
140 else if (command ==
"read")
142 readProfileCommand();
144 else if (command ==
"readPreferences")
146 readPreferencesCommand();
148 else if (command ==
"writePreferences")
150 writeNewPreferencesCommand();
152 else if (command ==
"setCustomAttribute")
154 setCustomAttributeCommand();
156 else if (command ==
"readDrinkPreference")
158 readDrinkPreferenceCommand();
160 else if (command ==
"setDrinkPreference")
162 setDrinkPreferenceCommand();
164 else if (command ==
"createPersonInstance")
166 createPersonInstanceCommand();
179 PersonMemoryDebugger::poseCommand()
181 std::string id, x_s, y_s, z_s;
182 std::cin >>
id >> x_s >> y_s >> z_s;
183 float x = std::stof(x_s);
184 float y = std::stof(y_s);
185 float z = std::stof(z_s);
186 Eigen::Vector3f pos(x, y, z);
191 PersonMemoryDebugger::faceRecognitionCommand()
193 std::string id, x_s, y_s, z_s;
194 std::cin >>
id >> x_s >> y_s >> z_s;
196 auto profileId = findProfileId(
id);
197 if (not profileId.has_value())
202 float x = std::stof(x_s);
203 float y = std::stof(y_s);
204 float z = std::stof(z_s);
206 Eigen::Vector3f pos(x, y, z);
207 commitFaceRecognition(pos, profileId);
211 PersonMemoryDebugger::profileCommand()
213 std::string firstName;
214 std::cin >> firstName;
215 std::string lastName;
216 std::cin >> lastName;
217 armarx::armem::human::PersonID
id = armarx::armem::human::PersonID();
218 id.firstName = firstName;
219 id.lastName = lastName;
224 PersonMemoryDebugger::readProfileCommand()
226 std::string firstName;
227 std::cin >> firstName;
228 std::string lastName;
229 std::cin >> lastName;
230 this->readProfile(firstName, lastName);
234 PersonMemoryDebugger::readPreferencesCommand()
236 std::string firstName;
237 std::cin >> firstName;
238 std::string lastName;
239 std::cin >> lastName;
240 this->readPreferences(firstName, lastName);
244 PersonMemoryDebugger::readDrinkPreferenceCommand()
246 std::string firstName;
247 std::cin >> firstName;
248 std::string lastName;
249 std::cin >> lastName;
250 this->readDrinkPreference(firstName, lastName);
254 PersonMemoryDebugger::setDrinkPreferenceCommand()
256 std::string firstName;
257 std::cin >> firstName;
258 std::string lastName;
259 std::cin >> lastName;
262 this->setDrinkPreference(firstName, lastName, drink);
266 PersonMemoryDebugger::writeNewPreferencesCommand()
268 std::string firstName;
269 std::cin >> firstName;
270 std::string lastName;
271 std::cin >> lastName;
272 this->writeNewPreferences(firstName, lastName);
276 PersonMemoryDebugger::setCustomAttributeCommand()
278 std::string firstName;
279 std::cin >> firstName;
280 std::string lastName;
281 std::cin >> lastName;
282 this->setCustomAttribute(firstName, lastName);
286 PersonMemoryDebugger::createPersonInstanceCommand()
288 std::string firstName;
289 std::cin >> firstName;
290 std::string lastName;
291 std::cin >> lastName;
292 this->createPersonInstance(firstName, lastName);
296 PersonMemoryDebugger::commitProfile(armarx::armem::human::PersonID& personID)
298 armarx::armem::human::Person debugProfile;
299 debugProfile.
id = personID;
309 profileWriter.commitHumanProfile(
313 std::optional<armarx::armem::MemoryID>
314 PersonMemoryDebugger::findProfileId(std::string& entityId)
316 armarx::armem::client::Reader profileReader =
319 armarx::armem::client::QueryResult queryResult =
321 std::optional<armarx::armem::MemoryID> foundProfileId = std::nullopt;
331 [&entityId, &foundProfileId](armarx::armem::wm::EntityInstance& instance)
333 if (foundProfileId.has_value())
342 foundProfileId = instance.
id();
346 return foundProfileId;
350 PersonMemoryDebugger::commitFaceRecognition(Eigen::Vector3f& facePosition,
351 std::optional<armarx::armem::MemoryID> profileId)
353 armarx::armem::client::Writer poseWriter =
357 std::stringstream ss;
360 armarx::armem::human::FaceRecognition bo;
370 armarx::human::arondto::FaceRecognition dto;
373 armarx::armem::MemoryID entityId =
377 armarx::armem::EntityUpdate
update = {
378 .entityID = entityId,
379 .instancesData = {dto.toAron()},
388 <<
"Committing face recognition for profile: "
389 << profileId.value_or(armarx::armem::MemoryID().withEntityName(
"INVALID")).entityName;
390 poseWriter.
commit(update);
394 PersonMemoryDebugger::commitPose(Eigen::Vector3f& facePosition, std::string& humanId)
396 armarx::armem::client::Writer poseWriter =
399 armarx::armem::human::HumanPose pose;
404 armarx::FramedOrientation defaultOrientation(
407 using namespace armarx::human::pose::model::k4a_bt_body_32;
413 armarx::armem::human::PoseKeypoint key = {
417 armarx::FramedPosition(facePosition,
"camera", properties.robotName),
418 .orientationCamera = armarx::FramedOrientation(
419 Eigen::Quaternionf::UnitRandom(),
"camera", properties.robotName),
421 armarx::FramedPosition(facePosition,
"robot", properties.robotName),
422 .orientationRobot = armarx::FramedOrientation(
423 Eigen::Quaternionf::UnitRandom(),
"robot", properties.robotName),
426 .orientationGlobal = defaultOrientation,
432 armarx::armem::MemoryID entityId =
436 armarx::human::arondto::HumanPose dto;
439 armarx::armem::EntityUpdate
update = {
440 .entityID = entityId,
441 .instancesData = {dto.toAron()},
448 ARMARX_INFO <<
"Committing pose with PersonID '" << humanId <<
"'.";
449 poseWriter.
commit(update);
453 PersonMemoryDebugger::readProfile(
const std::string& firstName,
const std::string& lastName)
455 ARMARX_INFO <<
"Reading profile for " << firstName <<
" " << lastName;
457 armarx::armem::human::Person profile = profileReader.queryLatestProfileByName(
476 PersonMemoryDebugger::readPreferences(
const std::string& firstName,
const std::string& lastName)
478 ARMARX_INFO <<
"Reading preferences for " << firstName <<
" " << lastName;
480 const armarx::core::time::Duration maxAge =
482 const armarx::armem::human::Preferences preferences = profileReader.queryPreferences(
485 if (!preferences.
food.has_value())
489 ARMARX_INFO <<
"Food preferences (preferred): " << preferences.
food.value().preferred;
490 ARMARX_INFO <<
"Food preferences (disliked): " << preferences.
food.value().disliked;
494 PersonMemoryDebugger::readDrinkPreference(
const std::string& firstName,
495 const std::string& lastName)
497 ARMARX_INFO <<
"Reading preferred drinks for " << firstName <<
" " << lastName;
499 const std::vector<std::string> drinks = profileReader.getPreferredDrinks(
511 PersonMemoryDebugger::setDrinkPreference(
const std::string& firstName,
512 const std::string& lastName,
513 const std::string& drink)
517 armarx::armem::human::PersonID personID;
521 profileWriter.setPreferredDrink(personID,
531 PersonMemoryDebugger::writeNewPreferences(
const std::string& firstName,
532 const std::string& lastName)
536 armarx::armem::human::Preferences preferences;
537 preferences.
food = std::optional<armarx::armem::human::Preference>(
538 {.preferred = {
"pizza",
"chocolate"}, .disliked = {
"vegetables"}});
540 armarx::armem::human::PersonID personID;
542 personID.lastName = lastName;
543 profileWriter.commitPreferencesToProfile(personID,
547 ARMARX_INFO <<
"Committed preferences to " << personID.firstName <<
" "
548 << personID.lastName;
552 PersonMemoryDebugger::setCustomAttribute(
const std::string& firstName,
553 const std::string& lastName)
556 std::vector<armarx::armem::human::Preference> preferences;
558 armarx::armem::human::PersonID personID;
562 profileWriter.setCustomAttributeInProfile(personID,
573 PersonMemoryDebugger::createPersonInstance(
const std::string& firstName,
574 const std::string& lastName)
576 ARMARX_INFO <<
"Creating PersonInstance for " << firstName <<
" " << lastName;
579 std::string profileEntityName = firstName +
"-" + lastName;
580 auto profileId = findProfileId(profileEntityName);
582 if (!profileId.has_value())
584 ARMARX_INFO <<
"Profile not found. Creating profile first...";
585 armarx::armem::human::PersonID personID;
588 commitProfile(personID);
591 profileId = findProfileId(profileEntityName);
592 if (!profileId.has_value())
594 ARMARX_WARNING <<
"Failed to create or find profile. Cannot create PersonInstance.";
601 Eigen::Vector3f defaultPosition(0.0f, 0.0f, 1.5f);
604 armarx::armem::human::PersonInstance personInstance;
605 personInstance.
profileID = profileId.value();
609 personInstance.
poseID = armarx::armem::MemoryID();
612 personInstance.
globalPose = Eigen::Isometry3f::Identity();
613 personInstance.
globalPose.translation() = defaultPosition;
616 armarx::human::arondto::PersonInstance dto;
624 armarx::armem::EntityUpdate
update = {
625 .entityID = entityId,
626 .instancesData = {dto.toAron()},
634 armarx::armem::client::Writer personInstanceWriter =
638 personInstanceWriter.
commit(update);
640 ARMARX_INFO <<
"Successfully created PersonInstance for " << firstName <<
" " << lastName
641 <<
" with entity name '" << profileEntityName <<
"'";
653 return "PersonMemoryDebugger";