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