ExampleMemoryClient.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::ExampleMemoryClient
17 * @author Rainer Kartmann ( rainer dot kartmann at kit dot edu )
18 * @date 2020
19 * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
20 * GNU General Public License
21 */
22
23#include "ExampleMemoryClient.h"
24
25#include <algorithm>
26#include <random>
27
28#include <Eigen/Geometry>
29
30#include <opencv2/imgcodecs.hpp>
31#include <opencv2/imgproc.hpp>
32#include <opencv2/opencv.hpp>
33
34#include <SimoxUtility/algorithm/string/string_tools.h>
35#include <SimoxUtility/color/cmaps.h>
36#include <SimoxUtility/math/pose/pose.h>
37
40
41#include <RobotAPI/components/armem/server/ExampleMemory/aron/ExampleData.aron.generated.h>
53
54namespace armarx
55{
56
59 {
62
63 defs->topic(debugObserver);
64
65 defs->optional(p.usedMemoryName, "mem.UsedMemoryName", "Name of the memory to use.");
66 defs->optional(p.commitFrequency,
67 "ex.CommitFrequency",
68 "Frequency in which example data is commited. (max = 50Hz)");
69
70 return defs;
71 }
72
73 std::string
75 {
76 return "ExampleMemoryClient";
77 }
78
79 void
83
84 void
86 {
87 p.commitFrequency = std::min(p.commitFrequency, 50.f);
88
91
92 // Wait for the memory to become available and add it as dependency.
93 ARMARX_IMPORTANT << "Waiting for memory '" << p.usedMemoryName << "' ...";
94 try
95 {
96 memoryReader = memoryNameSystem().useReader(p.usedMemoryName);
97 memoryWriter = memoryNameSystem().useWriter(p.usedMemoryName);
98 memoryLoader = memoryNameSystem().useLoader(p.usedMemoryName);
99 }
101 {
102 ARMARX_ERROR << e.what();
103 return;
104 }
105
106 // Add a provider segment to commit to.
107 exampleProviderID = addProviderSegment();
108 // Construct the entity ID.
109 exampleEntityID = exampleProviderID.withEntityName("example_entity");
110
111
112 // Subscribe to example_entity updates
113 // Using a lambda:
114 memoryNameSystem().subscribe(exampleEntityID,
115 [&](const armem::MemoryID& exampleEntityID,
116 const std::vector<armem::MemoryID>& snapshotIDs)
117 {
118 ARMARX_INFO << "Entity " << exampleEntityID
119 << " was updated by " << snapshotIDs.size()
120 << " snapshots.";
121 });
122 // Using a member function:
124 exampleEntityID, this, &ExampleMemoryClient::processExampleEntityUpdate);
125
127 task->start();
128 }
129
130 void
132 {
133 task->stop();
134 }
135
136 void
140
141 void
143 {
144 ARMARX_IMPORTANT << "Running example.";
145 runStarted = armem::Time::Now();
146
147 armem::MemoryID snapshotID = commitSingleSnapshot(exampleEntityID);
148 if (true)
149 {
150 commitMultipleSnapshots(exampleEntityID, 3);
151 }
152 if (true)
153 {
154 queryLatestSnapshot(snapshotID.getEntityID());
155 }
156 if (true)
157 {
158 queryExactSnapshot(snapshotID);
159 }
160 if (true)
161 {
162 commitExampleData();
163 queryExampleData();
164 }
165 if (true)
166 {
167 commitExamplesWithIDs();
168 }
169 if (true)
170 {
171 commitExamplesWithLinks();
172 }
173 if (true)
174 {
175 //commitExampleImages();
176 }
177 if (true)
178 {
179 commitExamplesWithUntypedData();
180 }
181 if (true)
182 {
183 queryPredictionEngines();
184 }
185 if (false)
186 {
187 //provide your own path and export in the method to test this!
188 loadDataFromLTMExport();
189 }
190
191 CycleUtil c(static_cast<int>(1000 / p.commitFrequency));
192 while (!task->isStopped())
193 {
194 commitSingleSnapshot(exampleEntityID);
195
196 c.waitForCycleDuration();
197 }
198 }
199
201 ExampleMemoryClient::addProviderSegment()
202 {
203 armem::data::AddSegmentInput input;
204 input.coreSegmentName = "ExampleModality";
205 input.providerSegmentName = "FancyMethodModality";
206
207 ARMARX_IMPORTANT << input;
208 armem::data::AddSegmentResult result = memoryWriter.addSegment(input);
209 ARMARX_INFO << result;
210
211 return armem::MemoryID(result.segmentID);
212 }
213
214 // COMMIT
215
217 ExampleMemoryClient::commitSingleSnapshot(const armem::MemoryID& entityID)
218 {
219 std::default_random_engine gen(std::random_device{}());
220 std::uniform_int_distribution<int> distrib(-20, 20);
221
222 // Prepare the update with some empty instances.
223 armem::EntityUpdate update;
224 update.entityID = entityID;
225 update.referencedTime = armem::Time::Now();
226
227 double diff = (update.referencedTime - runStarted).toMilliSecondsDouble() / 1000;
228
229 auto dict1 = std::make_shared<aron::data::Dict>();
230 auto dict2 = std::make_shared<aron::data::Dict>();
231
232 auto sin = std::make_shared<aron::data::Float>(std::sin(diff));
233 auto cos = std::make_shared<aron::data::Float>(std::cos(diff));
234
235 auto sqrt = std::make_shared<aron::data::Double>(std::sqrt(diff));
236 auto lin = std::make_shared<aron::data::Long>(static_cast<long>(diff * 1000));
237 auto rand = std::make_shared<aron::data::Int>(distrib(gen));
238
239 dict1->addElement("sin", sin);
240 dict1->addElement("cos", cos);
241
242 dict2->addElement("sqrt", sqrt);
243 dict2->addElement("lin", lin);
244 dict2->addElement("rand", rand);
245
246 update.instancesData = {dict1, dict2};
247
248 ARMARX_IMPORTANT << "Committing " << update;
249 armem::EntityUpdateResult updateResult = memoryWriter.commit(update);
250 ARMARX_INFO << updateResult;
251 if (!updateResult.success)
252 {
253 ARMARX_ERROR << updateResult.errorMessage;
254 }
255
256 return updateResult.snapshotID;
257 }
258
259 void
260 ExampleMemoryClient::commitMultipleSnapshots(const armem::MemoryID& entityID, int num)
261 {
262 // Commit a number of updates with different timestamps and number of instances.
263 armem::Commit commit;
264 for (int i = 0; i < num; ++i)
265 {
266 armem::EntityUpdate& update = commit.add();
267 update.entityID = entityID;
268 update.referencedTime = armem::Time::Now() + armem::Duration::Seconds(i);
269 for (int j = 0; j < i; ++j)
270 {
271 update.instancesData.push_back(std::make_shared<aron::data::Dict>());
272 }
273 }
274 ARMARX_IMPORTANT << "Committing " << commit;
275 armem::CommitResult commitResult = memoryWriter.commit(commit);
276 ARMARX_INFO << commitResult;
277 if (!commitResult.allSuccess())
278 {
279 ARMARX_ERROR << commitResult.allErrorMessages();
280 }
281 }
282
283 // QUERY
284
285 void
286 ExampleMemoryClient::queryLatestSnapshot(const armem::MemoryID& entityID)
287 {
288 ARMARX_IMPORTANT << "Querying latest snapshot in entity: "
289 << "\n- entityID: \t'" << entityID << "'";
290
291 armem::client::query::Builder builder;
292 builder.coreSegments()
293 .withID(entityID)
295 .withID(entityID)
296 .entities()
297 .withID(entityID)
298 .snapshots()
299 .latest();
300
301 armem::client::QueryResult qResult = memoryReader.query(builder.buildQueryInput());
302 ARMARX_INFO << qResult;
303 if (qResult.success)
304 {
305 ARMARX_IMPORTANT << "Getting entity via ID";
306
307 armem::wm::Memory& memory = qResult.memory;
308 ARMARX_CHECK(memory.hasInstances());
309
310 ARMARX_CHECK_GREATER_EQUAL(memory.size(), 1);
311
312 const armem::wm::Entity* entity = memory.findEntity(entityID);
314 << "Entity " << entityID << " was not found in " << armem::print(memory);
315 ARMARX_CHECK_GREATER_EQUAL(entity->size(), 1);
316
317 const armem::wm::EntitySnapshot& snapshot = entity->getLatestSnapshot();
318 ARMARX_CHECK_GREATER_EQUAL(snapshot.size(), 1);
319
320 ARMARX_INFO << "Result: "
321 << "\n- entity: \t" << entity->name() << "\n- snapshot: \t"
322 << snapshot.time() << "\n- #instances: \t" << snapshot.size();
323
324 // Show memory contents in remote gui.
325 tab.queryResult = std::move(memory);
326 tab.rebuild = true;
327 }
328 else
329 {
330 ARMARX_ERROR << qResult.errorMessage;
331 }
332 }
333
334 void
335 ExampleMemoryClient::queryExactSnapshot(const armem::MemoryID& snapshotID)
336 {
337 ARMARX_IMPORTANT << "Querying exact snapshot: "
338 << "\n- snapshotID: \t'" << snapshotID << "'";
339
340 namespace qf = armem::client::query_fns;
341 armem::client::query::Builder qb;
342 qb.singleEntitySnapshot(snapshotID);
343
344 armem::client::QueryResult qResult = memoryReader.query(qb.buildQueryInput());
345 ARMARX_INFO << qResult;
346
347 if (qResult.success)
348 {
349 armem::wm::Memory memory = std::move(qResult.memory);
350 {
351 const armem::wm::EntitySnapshot& entitySnapshot = memory.getLatestSnapshot();
352
353 ARMARX_INFO << "Result snapshot: "
354 << "\n- time: \t" << entitySnapshot.time()
355 << "\n- # instances: \t" << entitySnapshot.size();
356 }
357 {
358 const armem::wm::EntitySnapshot& entitySnapshot =
359 memory.getEntity(snapshotID).getLatestSnapshot();
360
361 ARMARX_INFO << "Result snapshot: "
362 << "\n- time: \t" << entitySnapshot.time()
363 << "\n- # instances: \t" << entitySnapshot.size();
364 }
365 }
366
367 else
368 {
369 ARMARX_ERROR << qResult.errorMessage;
370 }
371 }
372
373 void
374 ExampleMemoryClient::commitExampleData()
375 {
376 ARMARX_IMPORTANT << "Adding segment "
377 << "ExampleData"
378 << "/" << getName();
379
380 auto addSegmentResult = memoryWriter.addSegment("ExampleData", getName());
381 if (!addSegmentResult.success)
382 {
383 ARMARX_ERROR << addSegmentResult.errorMessage;
384 return;
385 }
386 exampleDataProviderID = armem::MemoryID(addSegmentResult.segmentID);
387
388 addSegmentResult = memoryWriter.addSegment("LinkedData", getName());
389 if (!addSegmentResult.success)
390 {
391 ARMARX_ERROR << addSegmentResult.errorMessage;
392 return;
393 }
394 linkedDataProviderID = armem::MemoryID(addSegmentResult.segmentID);
395
396 const armem::Time time = armem::Time::Now();
397 armem::Commit commit;
398
399 //commit to default
400 {
401 armem::EntityUpdate& update = commit.add();
402 update.entityID = exampleDataProviderID.withEntityName("default");
403 update.referencedTime = time;
404
405 armem::example::ExampleData data_example;
406 toAron(data_example.memoryID, armem::MemoryID());
407 toAron(data_example.memoryLink.memoryID, armem::MemoryID());
408 auto instance = data_example.toAron();
409 ARMARX_CHECK_NOT_NULL(instance);
410 update.instancesData = {instance};
411 }
412
413 ARMARX_INFO << "Constructed default example data";
414
415 //commit to default
416 {
417 armem::EntityUpdate& update_default = commit.add();
418 update_default.entityID = exampleDataProviderID.withEntityName("default");
419 update_default.referencedTime = time;
420
421 armem::example::ExampleData data_default;
422 toAron(data_default.memoryID, armem::MemoryID());
423 toAron(data_default.memoryLink.memoryID, armem::MemoryID());
424 ARMARX_CHECK_NOT_NULL(data_default.toAron());
425 update_default.instancesData = {data_default.toAron()};
426 }
427
428
429 //commit to the answer
430 {
431 armem::EntityUpdate& update_answer = commit.add();
432 update_answer.entityID = exampleDataProviderID.withEntityName("the answer");
433 update_answer.referencedTime = time;
434
435 armem::example::ExampleData data;
436 data.the_bool = true;
437 data.the_double = std::sin(time.toDurationSinceEpoch().toSecondsDouble());
438 data.the_float = 21.5;
439 data.the_int = 42;
440 data.the_long = 424242;
441 data.the_string = "fourty two";
442 data.the_float_list = {21, 42, 84};
443 data.the_int_list = {21, 42, 84};
444 data.the_string_list = simox::alg::multi_to_string(data.the_int_list);
445 data.the_object_list.emplace_back();
446
447 data.the_float_dict = {
448 {"one", 1.0},
449 {"two", 2.0},
450 {"three", 3.0},
451 };
452 data.the_int_dict = {
453 {"one", 1},
454 {"two", 2},
455 {"three", 3},
456 };
457
458 data.the_position = {42, 24, 4224};
459 data.the_orientation = Eigen::AngleAxisf(1.57f, Eigen::Vector3f(1, 1, 1).normalized());
460 data.the_pose = simox::math::pose(data.the_position, data.the_orientation);
461
462 data.the_3x1_vector = {24, 42, 2442};
463 data.the_4x4_matrix = 42 * Eigen::Matrix4f::Identity();
464
465 toAron(data.memoryID, armem::MemoryID()); // ////1/1
466 toAron(data.memoryLink.memoryID, armem::MemoryID());
467 ARMARX_CHECK_NOT_NULL(data.toAron());
468 update_answer.instancesData = {data.toAron()};
469 }
470
471 // commit to linked data
472 {
473 armem::EntityUpdate& update_linked = commit.add();
474 update_linked.entityID = linkedDataProviderID.withEntityName("yet_more_data");
475 update_linked.referencedTime = time;
476
477 armem::example::LinkedData data_linked;
478 data_linked.yet_another_int = 42;
479 data_linked.yet_another_string = "Hi! I'm from another core segment!";
480 data_linked.yet_another_object.element_int = 8349;
481 data_linked.yet_another_object.element_float = -1e3;
482 data_linked.yet_another_object.element_string =
483 "I'm a nested object in some linked data.";
484 ARMARX_CHECK_NOT_NULL(data_linked.toAron());
485 update_linked.instancesData = {data_linked.toAron()};
486 }
487
488 armem::CommitResult commitResult = memoryWriter.commit(commit);
489 if (commitResult.allSuccess())
490 {
491 try
492 {
493 auto results_size = commitResult.results.size();
494 ARMARX_INFO << "size(commitResults): " << results_size;
495 auto commitResults = commitResult.results;
496 if (results_size > 2)
497 {
498 theAnswerSnapshotID = commitResults.at(1).snapshotID;
499 yetMoreDataSnapshotID = commitResults.at(2).snapshotID;
500 }
501 else
502 {
503 ARMARX_INFO << "Only " << results_size << " committed elements, instaed of "
504 << "3";
505 }
506 }
507 catch (const std::exception& e)
508 {
509 ARMARX_WARNING << "Cannot access commit result";
510 }
511 }
512 else
513 {
514 ARMARX_WARNING << commitResult.allErrorMessages();
515 }
516 }
517
518 void
519 ExampleMemoryClient::queryExampleData()
520 {
521 // Query all entities from provider.
522 armem::client::query::Builder qb;
523 qb.coreSegments()
524 .withID(exampleProviderID)
526 .withID(exampleProviderID)
527 .entities()
528 .all()
529 .snapshots()
530 .all();
531
532 armem::client::QueryResult result = memoryReader.query(qb.buildQueryInput());
533 if (result.success)
534 {
535 tab.queryResult = std::move(result.memory);
536 tab.rebuild = true;
537 }
538 else
539 {
540 ARMARX_ERROR << result.errorMessage;
541 }
542 }
543
544 void
545 ExampleMemoryClient::commitExamplesWithIDs()
546 {
547 ARMARX_IMPORTANT << "Committing multiple entity updates with links ...";
548 const armem::Time time = armem::Time::Now();
549
550 armem::Commit commit;
551 {
552 armem::EntityUpdate& update = commit.add();
553 update.entityID = exampleDataProviderID.withEntityName("id to the_answer");
554 update.referencedTime = time;
555
556 armem::example::ExampleData data;
557 armem::toAron(data.memoryID, theAnswerSnapshotID);
558 armem::toAron(data.memoryLink.memoryID, armem::MemoryID());
559
560 update.instancesData = {data.toAron()};
561 }
562 {
563 armem::EntityUpdate& update = commit.add();
564 update.entityID = exampleDataProviderID.withEntityName("id to self");
565 update.referencedTime = time;
566
567 armem::example::ExampleData data;
568 armem::toAron(data.memoryID, update.entityID.withTimestamp(time));
569 armem::toAron(data.memoryLink.memoryID, armem::MemoryID());
570
571 update.instancesData = {data.toAron()};
572 }
573
574 {
575 armem::EntityUpdate& update = commit.add();
576 update.entityID = exampleDataProviderID.withEntityName("id to previous snapshot");
577 update.referencedTime = time - armem::Duration::Seconds(1); // 1 sec in the past
578
579 armem::example::ExampleData data;
580 armem::toAron(data.memoryID, armem::MemoryID()); // First entry - invalid link
581 armem::toAron(data.memoryLink.memoryID, armem::MemoryID());
582
583 update.instancesData = {data.toAron()};
584 }
585 {
586 armem::EntityUpdate& update = commit.add();
587 update.entityID = exampleDataProviderID.withEntityName("id to previous snapshot");
588 update.referencedTime = time;
589
590 armem::example::ExampleData data;
591 armem::toAron(data.memoryID,
592 update.entityID.withTimestamp(time - armem::Duration::Seconds(1)));
593 armem::toAron(data.memoryLink.memoryID, armem::MemoryID());
594
595 update.instancesData = {data.toAron()};
596 }
597
598 ARMARX_CHECK_EQUAL(commit.updates.size(), 4);
599 armem::CommitResult commitResult = memoryWriter.commit(commit);
600
601 if (!commitResult.allSuccess() || commitResult.results.size() != commit.updates.size())
602 {
603 ARMARX_WARNING << commitResult.allErrorMessages();
604 }
605
606
607 // Resolve memory IDs via memory name system (works for IDs from different servers).
608 ARMARX_IMPORTANT << "Resolving multiple memory IDs via Memory Name System:";
609 {
610 std::vector<armem::MemoryID> ids;
611 for (armem::EntityUpdateResult& result : commitResult.results)
612 {
613 ids.push_back(result.snapshotID);
614 }
615 ARMARX_CHECK_EQUAL(ids.size(), commit.updates.size());
616
617 std::map<armem::MemoryID, armem::wm::EntityInstance> instances =
619 ARMARX_CHECK_EQUAL(instances.size(), commit.updates.size());
620
621 std::stringstream ss;
622 for (const auto& [id, instance] : instances)
623 {
624 ss << "- Snapshot " << id << " "
625 << "\n--> Instance" << instance.id()
626 << " (# keys in data: " << instance.data()->childrenSize() << ")"
627 << "\n";
628 }
629 ARMARX_INFO << ss.str();
630 }
631 }
632
633 void
634 ExampleMemoryClient::commitExamplesWithLinks()
635 {
636 ARMARX_IMPORTANT << "Committing an entity update with a link...";
637
638 const armem::Time time = armem::Time::Now();
639
640 armem::Commit commit;
641 {
642 armem::EntityUpdate& update = commit.add();
643 update.entityID = exampleDataProviderID.withEntityName("link to yet_more_data");
644 update.referencedTime = time;
645
646 armem::example::ExampleData data;
647 armem::toAron(data.memoryID, armem::MemoryID());
648 armem::toAron(data.memoryLink.memoryID, yetMoreDataSnapshotID);
649
650 update.instancesData = {data.toAron()};
651 }
652
653 ARMARX_CHECK_EQUAL(commit.updates.size(), 1);
654 armem::CommitResult commitResult = memoryWriter.commit(commit);
655
656 if (!commitResult.allSuccess() || commitResult.results.size() != commit.updates.size())
657 {
658 ARMARX_WARNING << commitResult.allErrorMessages();
659 }
660
661
662 // Resolve memory IDs via memory name system (works for IDs from different servers).
663 ARMARX_IMPORTANT << "Resolving multiple memory IDs via Memory Name System:";
664 {
665 std::vector<armem::MemoryID> ids;
666 for (armem::EntityUpdateResult& result : commitResult.results)
667 {
668 ids.push_back(result.snapshotID);
669 }
670 ARMARX_CHECK_EQUAL(ids.size(), commit.updates.size());
671
672 std::map<armem::MemoryID, armem::wm::EntityInstance> instances =
674 ARMARX_CHECK_EQUAL(instances.size(), commit.updates.size());
675
676 std::stringstream ss;
677 for (const auto& [id, instance] : instances)
678 {
679 ss << "- Snapshot " << id << " "
680 << "\n--> Instance" << instance.id()
681 << " (# keys in data: " << instance.data()->childrenSize() << ")"
682 << "\n";
683 }
684 ARMARX_INFO << ss.str();
685 }
686 }
687
688 void
689 ExampleMemoryClient::commitExampleImages()
690 {
691 const armem::Time time = armem::Time::Now();
692
693 armem::Commit commit;
694 {
695 armem::EntityUpdate& update = commit.add();
696 update.entityID = exampleDataProviderID.withEntityName("some_new_fancy_entity_id");
697 update.referencedTime = time;
698
699 auto currentFolder = std::filesystem::current_path();
700 auto opencv_img = cv::imread(
701 (currentFolder / "images" / (std::to_string(imageCounter + 1) + ".jpg")).string());
702 imageCounter++;
703 imageCounter %= 10;
704
705 auto data = std::make_shared<aron::data::Dict>();
706 data->addElement(
707 "opencv_image",
709
710 update.instancesData = {data};
711 }
712 }
713
714 void
715 ExampleMemoryClient::commitExamplesWithUntypedData()
716 {
717 const armem::Time time = armem::Time::Now();
718
719 armem::Commit commit;
720 {
721 armem::EntityUpdate& update = commit.add();
722 update.entityID = exampleDataProviderID.withEntityName("unexpected_data");
723 update.referencedTime = time;
724
725 armem::example::ExampleData data;
726 toAron(data.memoryID, armem::MemoryID()); // ////1/1
727 toAron(data.memoryLink.memoryID, armem::MemoryID());
728
729 aron::data::DictPtr aron = data.toAron();
730 aron->addElement("unexpectedString",
731 std::make_shared<aron::data::String>("unexpected value"));
732 aron->addElement(
733 "unexpectedDict",
734 std::make_shared<aron::data::Dict>(std::map<std::string, aron::data::VariantPtr>{
735 {"key43", std::make_shared<aron::data::Int>(43)},
736 {"keyABC", std::make_shared<aron::data::String>("ABC")},
737 }));
738 update.instancesData = {aron};
739 }
740
741 armem::CommitResult commitResult = memoryWriter.commit(commit);
742 if (!commitResult.allSuccess())
743 {
744 ARMARX_WARNING << commitResult.allErrorMessages();
745 }
746 }
747
748 void
749 ExampleMemoryClient::queryPredictionEngines()
750 {
751 const std::map<armem::MemoryID, std::vector<armem::PredictionEngine>> predictionEngines =
752 memoryReader.getAvailablePredictionEngines();
753
754 std::stringstream ss;
755 ss << "Prediction engines available in the server:" << std::endl;
756 for (const auto& [id, engines] : predictionEngines)
757 {
758 ss << " - " << id << ": ";
759 for (const armem::PredictionEngine& engine : engines)
760 {
761 ss << engine.engineID << ", ";
762 }
763 ss << std::endl;
764 }
765
766 ARMARX_INFO << ss.str();
767 }
768
769 void
770 ExampleMemoryClient::loadDataFromLTMExport()
771 {
772
773 std::string export_path = "$HOME"; //put this as wherever your export is
774 std::string memoryName = "Example";
775 std::vector<std::string> coreSegmentNames = {"ExampleData"};
776 bool addNonExistingCoreSegments = false;
777 int amountOfSnapshotsPerSegmentToLoad = -1;
778 ARMARX_INFO << "Loading all data from " << export_path << "into core segment "
779 << coreSegmentNames[0];
780 memoryLoader.loadExportIntoWM(export_path,
781 memoryName,
782 coreSegmentNames,
783 addNonExistingCoreSegments,
784 amountOfSnapshotsPerSegmentToLoad);
785 }
786
787 void
788 ExampleMemoryClient::processExampleEntityUpdate(const armem::MemoryID& subscriptionID,
789 const std::vector<armem::MemoryID>& snapshotIDs)
790 {
791 std::stringstream ss;
792 ss << "example_entity got updated: " << subscriptionID << "\n";
793 ss << "Updated snapshots: \n";
794 for (const auto& id : snapshotIDs)
795 {
796 ss << "- " << id << "\n";
797 }
798 ARMARX_IMPORTANT << ss.str();
799 // Fetch new data of example_entity and do something with it.
800 }
801
802 void
804 {
805 using namespace armarx::RemoteGui::Client;
806
807 if (tab.queryResult)
808 {
809 }
810
811 VBoxLayout root = {tab.queryResultGroup, VSpacer()};
812 RemoteGui_createTab(getName(), root, &tab);
813 }
814
815 void
817 {
818 if (tab.rebuild.exchange(false))
819 {
821 }
822 }
823
824} // namespace armarx
uint8_t data[1]
constexpr T c
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
This util class helps with keeping a cycle time during a control cycle.
Definition CycleUtil.h:41
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.
std::string getDefaultName() const override
std::string getName() const
Retrieve name of object.
std::string coreSegmentName
Definition MemoryID.h:51
std::string str(bool escapeDelimiters=true) const
Get a string representation of this memory ID.
Definition MemoryID.cpp:102
MemoryID withEntityName(const std::string &name) const
Definition MemoryID.cpp:425
MemoryID getEntityID() const
Definition MemoryID.cpp:310
Loader useLoader(const MemoryID &memoryID)
Use a memory server and get a configurator for it.
Writer useWriter(const MemoryID &memoryID)
Use a memory server and get a writer for it.
Reader useReader(const MemoryID &memoryID)
Use a memory server and get a reader for it.
std::map< MemoryID, wm::EntityInstance > resolveEntityInstances(const std::vector< MemoryID > &ids)
data::AddSegmentResult addSegment(const std::string &coreSegmentName, const std::string &providerSegmentName, bool clearWhenExists=false) const
Definition Writer.cpp:25
void singleEntitySnapshot(const MemoryID &snapshotID)
Definition Builder.cpp:144
CoreSegmentSelector & coreSegments()
Start specifying core segments.
Definition Builder.cpp:42
CoreSegmentSelector & withID(const MemoryID &id) override
Definition selectors.h:141
ProviderSegmentSelector & providerSegments()
Start specifying provider segments.
EntitySelector & withID(const MemoryID &id) override
Definition selectors.h:63
SnapshotSelector & snapshots()
Start specifying entity snapshots.
Definition selectors.cpp:92
ProviderSegmentSelector & withID(const MemoryID &id) override
Definition selectors.h:102
EntitySelector & entities()
Start specifying entities.
SubscriptionHandle subscribe(const MemoryID &subscriptionID, Callback Callback)
Indicates that a query to the Memory Name System failed.
Definition mns.h:25
static data::NDArrayPtr ConvertFromMat(const cv::Mat &, const armarx::aron::Path &={})
static DateTime Now()
Definition DateTime.cpp:51
Duration toDurationSinceEpoch() const
Definition DateTime.cpp:105
static Duration Seconds(std::int64_t seconds)
Constructs a duration in seconds.
Definition Duration.cpp:72
double toSecondsDouble() const
Returns the amount of seconds.
Definition Duration.cpp:90
#define ARMARX_CHECK(expression)
Shortcut for ARMARX_CHECK_EXPRESSION.
#define ARMARX_CHECK_GREATER_EQUAL(lhs, rhs)
This macro evaluates whether lhs is greater or equal (>=) rhs and if it turns out to be false it will...
#define ARMARX_CHECK_NOT_NULL(ptr)
This macro evaluates whether ptr is not null and if it turns out to be false it will throw an Express...
#define ARMARX_CHECK_EQUAL(lhs, rhs)
This macro evaluates whether lhs is equal (==) rhs and if it turns out to be false it will throw an E...
#define ARMARX_INFO
The normal logging level.
Definition Logging.h:181
#define ARMARX_IMPORTANT
The logging level for always important information, but expected behaviour (in contrast to ARMARX_WAR...
Definition Logging.h:190
#define ARMARX_ERROR
The logging level for unexpected behaviour, that must be fixed.
Definition Logging.h:196
#define ARMARX_WARNING
The logging level for unexpected behaviour, but not a serious problem.
Definition Logging.h:193
VectorXD< D, T > sqrt(const VectorXD< D, T > &a)
Definition VectorXD.h:704
bool update(mongocxx::collection &coll, const nlohmann::json &query, const nlohmann::json &update)
Definition mongodb.cpp:68
std::string print(const wm::Memory &data, int maxDepth=-1, int depth=0)
armarx::core::time::DateTime Time
void toAron(arondto::MemoryID &dto, const MemoryID &bo)
std::shared_ptr< Dict > DictPtr
Definition Dict.h:42
This file offers overloads of toIce() and fromIce() functions for STL container types.
void toAron(arondto::PackagePath &dto, const PackageFileLocation &bo)
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)
std::vector< std::string > allErrorMessages() const
Definition Commit.cpp:73
std::vector< EntityUpdateResult > results
Definition Commit.h:112
EntityUpdate & add()
Definition Commit.cpp:80
std::vector< EntityUpdate > updates
The entity updates.
Definition Commit.h:97
MemoryID entityID
The entity's ID.
Definition Commit.h:28
Time referencedTime
Time when this entity update was created (e.g.
Definition Commit.h:37
std::vector< aron::data::DictPtr > instancesData
The entity data.
Definition Commit.h:31
auto & getEntity(const MemoryID &entityID)
Retrieve an entity.
auto * findEntity(const MemoryID &entityID)
Find an entity.
bool hasInstances() const
Indicate whether this container contains at least one entity instance.
auto & getLatestSnapshot(int snapshotIndex=0)
Retrieve the latest entity snapshot.
wm::Memory memory
The slice of the memory that matched the query.
Definition Query.h:58