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)
398 armarx::armem::human::HumanPose pose;
403 armarx::FramedOrientation defaultOrientation(
406 using namespace armarx::human::pose::model::k4a_bt_body_32;
412 armarx::armem::human::PoseKeypoint key = {
416 armarx::FramedPosition(facePosition,
"camera", properties.robotName),
417 .orientationCamera = armarx::FramedOrientation(
418 Eigen::Quaternionf::UnitRandom(),
"camera", properties.robotName),
420 armarx::FramedPosition(facePosition,
"robot", properties.robotName),
421 .orientationRobot = armarx::FramedOrientation(
422 Eigen::Quaternionf::UnitRandom(),
"robot", properties.robotName),
425 .orientationGlobal = defaultOrientation,
431 armarx::armem::MemoryID entityId =
435 armarx::human::arondto::HumanPose dto;
438 armarx::armem::EntityUpdate
update = {
439 .entityID = entityId,
440 .instancesData = {dto.toAron()},
447 ARMARX_INFO <<
"Committing pose with PersonID '" << humanId <<
"'.";
448 poseWriter.
commit(update);
452 PersonMemoryDebugger::readProfile(
const std::string& firstName,
const std::string& lastName)
454 ARMARX_INFO <<
"Reading profile for " << firstName <<
" " << lastName;
456 armarx::armem::human::Person profile = profileReader.queryLatestProfileByName(
475 PersonMemoryDebugger::readPreferences(
const std::string& firstName,
const std::string& lastName)
477 ARMARX_INFO <<
"Reading preferences for " << firstName <<
" " << lastName;
479 const armarx::core::time::Duration maxAge =
481 const armarx::armem::human::Preferences preferences = profileReader.queryPreferences(
484 if (!preferences.
food.has_value())
488 ARMARX_INFO <<
"Food preferences (preferred): " << preferences.
food.value().preferred;
489 ARMARX_INFO <<
"Food preferences (disliked): " << preferences.
food.value().disliked;
493 PersonMemoryDebugger::readDrinkPreference(
const std::string& firstName,
494 const std::string& lastName)
496 ARMARX_INFO <<
"Reading preferred drinks for " << firstName <<
" " << lastName;
498 const std::vector<std::string> drinks = profileReader.getPreferredDrinks(
510 PersonMemoryDebugger::setDrinkPreference(
const std::string& firstName,
511 const std::string& lastName,
512 const std::string& drink)
516 armarx::armem::human::PersonID personID;
520 profileWriter.setPreferredDrink(personID,
529 PersonMemoryDebugger::writeNewPreferences(
const std::string& firstName,
530 const std::string& lastName)
534 armarx::armem::human::Preferences preferences;
535 preferences.
food = std::optional<armarx::armem::human::Preference>(
536 {.preferred = {
"pizza",
"chocolate"}, .disliked = {
"vegetables"}});
538 armarx::armem::human::PersonID personID;
540 personID.lastName = lastName;
541 profileWriter.commitPreferencesToProfile(personID,
545 ARMARX_INFO <<
"Committed preferences to " << personID.firstName <<
" " << personID.lastName;
549 PersonMemoryDebugger::setCustomAttribute(
const std::string& firstName,
550 const std::string& lastName)
553 std::vector<armarx::armem::human::Preference> preferences;
555 armarx::armem::human::PersonID personID;
559 profileWriter.setCustomAttributeInProfile(personID,
569 PersonMemoryDebugger::createPersonInstance(
const std::string& firstName,
570 const std::string& lastName)
572 ARMARX_INFO <<
"Creating PersonInstance for " << firstName <<
" " << lastName;
575 std::string profileEntityName = firstName +
"-" + lastName;
576 auto profileId = findProfileId(profileEntityName);
578 if (!profileId.has_value())
580 ARMARX_INFO <<
"Profile not found. Creating profile first...";
581 armarx::armem::human::PersonID personID;
584 commitProfile(personID);
587 profileId = findProfileId(profileEntityName);
588 if (!profileId.has_value())
590 ARMARX_WARNING <<
"Failed to create or find profile. Cannot create PersonInstance.";
597 Eigen::Vector3f defaultPosition(0.0f, 0.0f, 1.5f);
600 armarx::armem::human::PersonInstance personInstance;
601 personInstance.
profileID = profileId.value();
605 personInstance.
poseID = armarx::armem::MemoryID();
608 personInstance.
globalPose = Eigen::Isometry3f::Identity();
609 personInstance.
globalPose.translation() = defaultPosition;
612 armarx::human::arondto::PersonInstance dto;
616 armarx::armem::MemoryID entityId =
621 armarx::armem::EntityUpdate
update = {
622 .entityID = entityId,
623 .instancesData = {dto.toAron()},
631 armarx::armem::client::Writer personInstanceWriter =
635 personInstanceWriter.
commit(update);
637 ARMARX_INFO <<
"Successfully created PersonInstance for " << firstName <<
" " << lastName
638 <<
" with entity name '" << profileEntityName <<
"'";
644 return "PersonMemoryDebugger";