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