Component.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 Navigation::ArmarXObjects::NavigationMemory
17  * @author Fabian Reister ( fabian dot reister at kit dot edu )
18  * @date 2021
19  * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
20  * GNU General Public License
21  */
22 
23 #include "Component.h"
24 
25 #include <filesystem>
26 #include <fstream>
27 #include <iostream>
28 #include <iterator>
29 
30 #include <SimoxUtility/algorithm/string/string_tools.h>
31 
39 
50 
52 #include <armarx/navigation/algorithms/aron/Costmap.aron.generated.h>
54 #include <armarx/navigation/core/aron/Graph.aron.generated.h>
55 #include <armarx/navigation/core/aron/Location.aron.generated.h>
56 #include <armarx/navigation/core/aron/Trajectory.aron.generated.h>
57 #include <armarx/navigation/core/aron/Twist.aron.generated.h>
59 #include <armarx/navigation/human/aron/Human.aron.generated.h>
61 #include <armarx/navigation/memory/aron/LaserScannerFeatures.aron.generated.h>
63 #include <armarx/navigation/rooms/aron/Room.aron.generated.h>
65 
66 #include "Visu.h"
67 
69 {
70 
72 
75  {
78 
79  // Publish to a topic (passing the TopicListenerPrx).
80  // def->topic(myTopicListener);
81 
82  // Subscribe to a topic (passing the topic name).
83  // def->topic<PlatformUnitListener>("MyTopic");
84 
85  // Use (and depend on) another component (passing the ComponentInterfacePrx).
86  // def->component(myComponentProxy)
87 
88 
89  def->optional(properties.snapshotToLoad,
90  "p.snapshotToLoad",
91  "Snapshot to load at start up \n"
92  "(e.g. 'R003' to load 'PriorKnowledgeData/navigation-graphs/R003').");
93 
94  def->optional(properties.packageToLoad,
95  "p.packageToLoad",
96  "Package to load snapshot at start up \n"
97  "(e.g. 'PriorKnowledgeData').");
98 
99  def->optional(properties.locationGraph.visuLocations,
100  "p.locationGraph.visuLocation",
101  "Enable visualization of locations.");
102 
103  def->optional(
104  properties.locationGraph.visuRelativeLocations,
105  "p.locationGraph.visuRelativeLocation",
106  "Enable visualization of relative locations (currently supported: robots, objects).");
107 
108  def->optional(properties.locationGraph.visuGraphEdges,
109  "p.locationGraph.visuGraphEdges",
110  "Enable visualization of navigation graph edges.");
111 
112  def->optional(
113  properties.visuCostmaps, "p.visuCostmaps", "Enable visualization of costmaps.");
114  def->optional(properties.zOffsetCostmap,
115  "p.zOffsetCostmap",
116  "Adjust the height of the visualized costmap.");
117 
118  def->optional(properties.visuHumans, "p.visuHumans", "Enable visualization of humans.");
119 
120  def->optional(properties.visuTransparent,
121  "p.visuTransparent",
122  "Enable visualization of humans a bit transparent.");
123 
124  def->optional(properties.visuHumanMaxAgeMs,
125  "p.visuHumanMaxAgeMs",
126  "The maximum age of humans to be drawn in ms.");
127 
128  def->optional(properties.visuRooms, "p.visuRooms", "Enable visualization of rooms.");
129 
130  def->optional(properties.visuFrequency,
131  "p.visuFrequency",
132  "Visualization frequeny of locations and graph edges [Hz].");
133 
134  return def;
135  }
136 
138  {
139  workingMemory().setName("Navigation");
140  }
141 
142  void
144  {
145  // Topics and properties defined above are automagically registered.
146 
147  // Keep debug observer data until calling `sendDebugObserverBatch()`.
148  // (Requies the armarx::DebugObserverComponentPluginUser.)
149  // setDebugObserverBatchModeEnabled(true);
150 
153 
155  algorithms::arondto::Costmap::ToAronType());
156 
157  workingMemory().addCoreSegment("Results_GlobalPlanner",
158  navigation::core::arondto::GlobalTrajectory::ToAronType());
159  workingMemory().addCoreSegment("Results_LocalPlanner",
160  navigation::core::arondto::LocalTrajectory::ToAronType());
161  // workingMemory().addCoreSegment("Results_TrajectoryController",
162  // navigation::core::arondto::Twist::ToAronType());
163  // workingMemory().addCoreSegment("Results_SafetyController",
164  // navigation::core::arondto::Twist::ToAronType());
165 
166  workingMemory().addCoreSegment("Events"); //, armem::example::ExampleData::ToAronType());
168  "Exceptions"); //, armem::example::ExampleData::ToAronType());
169 
170 
172  navigation::location::arondto::Location::ToAronType());
174  navigation::core::arondto::Graph::ToAronType());
175 
177  navigation::human::arondto::Human::ToAronType());
178 
179  workingMemory()
181  navigation::memory::arondto::LaserScannerFeatures::ToAronType())
182  .setMaxHistorySize(properties.laserScannerFeaturesMaxHistorySize);
183 
184  // workingMemory().addCoreSegment(memory::constants::HumanGroupCoreSegmentName,
185  // navigation::human::arondto::Human::ToAronType());
187  navigation::rooms::arondto::Room::ToAronType());
188 
189  loadSnapshot();
190  }
191 
192  void
194  {
195  // connect readers if enabled
196  if (properties.locationGraph.visuRelativeLocations)
197  {
199  }
200 
201  // Setup the remote GUI.
202  {
205  }
206 
207  tasks.visuTask = new SimpleRunningTask<>([this]() { this->visuRun(); }, "Visualization");
208  tasks.visuTask->start();
209  }
210 
211  void
213  {
214  }
215 
216  void
218  {
219  }
220 
221  std::string
223  {
224  return GetDefaultName();
225  }
226 
227  std::string
229  {
230  return "navigation_memory";
231  }
232 
233  void
235  {
236  using namespace armarx::RemoteGui::Client;
237 
238  // Setup the widgets.
239  tab.locationGraph.setup(*this);
240 
241  // Setup the layout.
242  VBoxLayout root = {tab.locationGraph.group, VSpacer()};
243  RemoteGui_createTab(getName(), root, &tab);
244  }
245 
246  void
248  {
249  tab.locationGraph.update(*this);
250  }
251 
252  void
254  {
255  using namespace armarx::RemoteGui::Client;
256  GridLayout grid;
257  int row = 0;
258  {
259  reloadSnapshot = Button();
260  reloadSnapshot.setLabel("Reload from Snapshot '" + owner.properties.snapshotToLoad +
261  "'");
262 
263  visuLocations.setValue(owner.properties.locationGraph.visuLocations);
264  visuGraphEdges.setValue(owner.properties.locationGraph.visuLocations);
265 
266  grid.add(reloadSnapshot, {row, 0}, {1, 2});
267  ++row;
268 
269  grid.add(Label("Visualize Locations"), {row, 0}).add(visuLocations, {row, 1});
270  ++row;
271 
272  grid.add(Label("Visualize Graph Edges"), {row, 0}).add(visuGraphEdges, {row, 1});
273  ++row;
274  }
275 
276  group = GroupBox({grid});
277  group.setLabel("Locations");
278  }
279 
280  void
282  {
283  if (reloadSnapshot.wasClicked())
284  {
285  owner.loadSnapshot();
286  }
287  if (visuLocations.hasValueChanged() or visuGraphEdges.hasValueChanged())
288  {
289  std::scoped_lock lock(owner.propertiesMutex);
290  owner.properties.locationGraph.visuLocations = visuLocations.getValue();
291  owner.properties.locationGraph.visuGraphEdges = visuGraphEdges.getValue();
292  }
293  }
294 
295  void
296  Component::visuRun()
297  {
298  memory::Visu visu{arviz,
304 
306  Properties p;
307  {
308  std::scoped_lock lock(propertiesMutex);
309  pp = properties.locationGraph;
310  p = properties;
311  }
312 
313  Metronome metronome(Frequency::HertzDouble(p.visuFrequency));
314  while (tasks.visuTask and not tasks.visuTask->isStopped())
315  {
316  ARMARX_TRACE;
317 
318  {
319  std::scoped_lock lock(propertiesMutex);
320  pp = properties.locationGraph;
321  }
322 
323  std::vector<viz::Layer> layers;
324 
325  // Locations
326  // TODO: @fabian.peller this is ugly!
327  if (properties.locationGraph.visuRelativeLocations)
328  {
329  visu.drawLocations(objClient, layers, pp.visuLocations);
330  }
331  else
332  {
333  visu.drawLocations(layers, pp.visuLocations);
334  }
335 
336  // Graph Edges
337  if (properties.locationGraph.visuRelativeLocations)
338  {
339  visu.drawGraphs(objClient, layers, pp.visuGraphEdges);
340  }
341  else
342  {
343  visu.drawGraphs(layers, pp.visuGraphEdges);
344  }
345 
346  // Costmaps
347  visu.drawCostmaps(layers, p.visuCostmaps, p.zOffsetCostmap);
348 
349  // Humans
350  visu.drawHumans(layers,
351  p.visuHumans,
352  p.visuTransparent,
353  Duration::MilliSeconds(p.visuHumanMaxAgeMs));
354  // Rooms
355  visu.drawRooms(layers, p.visuRooms);
356 
357  arviz.commit(layers);
358 
359  metronome.waitForNextTick();
360  }
361  }
362 
363  void
364  Component::loadSnapshot()
365  {
366  if (properties.snapshotToLoad.empty())
367  {
369  << "Not loading any predefined locations or graphs as the params was empty ...";
370  return;
371  }
372 
373  const std::vector<std::string> snapshotsToLoad =
374  simox::alg::split(properties.snapshotToLoad, ";", true);
375 
376  for (const auto& snapshotToLoad : snapshotsToLoad)
377  {
378 
379  ARMARX_INFO << "Loading snapshots from snapshot '" << snapshotToLoad
380  << "' in package '" << properties.packageToLoad << "' ...";
381 
383  properties.packageToLoad,
385  DEFAULT_DIR_TO_IDS);
386 
387  if (auto graph = f.find(snapshotToLoad); graph.has_value())
388  {
389  const std::string graphId = graph->getID();
390  ARMARX_DEBUG << "Found graph " << graphId << " with path: " << graph->getFullPath();
391 
392  // Sometimes, we use the date before the snapshotname.
393  // In this case a symlink to the real data should be used (e.g. R003 and 2022-03-01_R003)
394 
395  // This loads the location. All locations are stored in a single locations.json file
396  // The file contains json with the framed poses (frame, agent, 4x4 matrix)
397  {
398  std::filesystem::path locationsFilePath =
399  graph->getFullPath() / "locations.json";
400  if (not std::filesystem::is_regular_file(locationsFilePath))
401  {
402  ARMARX_WARNING << "Found no locations file for graph '" << graphId << "'.";
403  }
404  else
405  {
406 
407  ARMARX_DEBUG << "Found the locations file";
409  armem::MemoryID providerID = workingMemory().id();
410  providerID.coreSegmentName = "Location";
411  providerID.providerSegmentName = graphId;
412 
413  const auto now = armem::Time::Now();
414  ARMARX_DEBUG << "Loading " << locationsFilePath;
415 
416  std::ifstream ifs(locationsFilePath);
417  const std::string content((std::istreambuf_iterator<char>(ifs)),
418  (std::istreambuf_iterator<char>()));
419 
420  // parse location as json. All files in Location folder must be valid json objects!
421  nlohmann::json js = nlohmann::json::parse(content);
422 
423  auto locations =
425  js);
426 
427  for (const auto& location : locations)
428  {
429  // we assert that only framedLocations are allowed. Everything else will be rejected!
430  if (location->type !=
432  {
434  << "Navigation memory received location '" + location->id.name +
435  "' which is not of type "
436  "'armarx::priorknowledge::util::LocationType:"
437  ":FRAMED_LOCATION' (e.g. you specified a "
438  "FRAMED_BOXED_LOCATION?). Only FramedLocations (i.e. "
439  "poses in 3D space) are navigatable. Ignoring this "
440  "location "
441  "but please check the location.json file.";
442  continue;
443  }
444 
445  auto& framedLocation =
447  *location);
448 
449  navigation::location::arondto::Location loc;
450 
451  // set members of loc
452  loc.framedPose.header.frame = framedLocation.frame;
453  loc.framedPose.header.agent = framedLocation.agent;
454  loc.framedPose.pose = framedLocation.pose;
455  toAron(loc.names, framedLocation.names);
456 
457  // send commit to memory
458  auto& up = c.add();
459  up.confidence = 1.0;
460  up.referencedTime = now;
461  up.sentTime = now;
462  up.arrivedTime = now;
463  up.entityID = providerID.withEntityName(framedLocation.id.name);
464  up.instancesData = {loc.toAron()};
465  }
466 
467  ARMARX_DEBUG << "Sending locations to memory";
469  }
470  }
471 
472  {
473  // Next we load the graphs. The graph folder may contain several graphs, represented by different json files.
474  // Each of those graphs contains a list of files representing the vertices. The filename is the vertice id (ideally starting at 0).
475  // The file contains a json with the corresponding location name (as path) and the adjacent vertives (representing the directed outgoing edges).
476  std::filesystem::path graphFilesPath = graph->getFullPath() / "Graph";
477 
478  if (not std::filesystem::is_directory(graphFilesPath))
479  {
480  ARMARX_INFO << "Found no `Graph/` folder for graph '" << graphId << "'.";
481  ARMARX_INFO << "Creating empty graph.";
482 
484  armem::MemoryID providerID = workingMemory().id();
486  providerID.providerSegmentName = graphId;
487 
488  const auto now = armem::Time::Now();
489 
491 
492  auto& up = c.add();
493  up.confidence = 1.0;
494  up.referencedTime = now;
495  up.arrivedTime = now;
496  up.sentTime = now;
497  up.entityID = providerID.withEntityName(snapshotToLoad);
498  up.instancesData = {g.toAron()};
499 
500  ARMARX_DEBUG << "Sending empty graph `" << snapshotToLoad
501  << "` to memory.";
502  iceAdapter().commit(c);
503  }
504  else
505  {
506  ARMARX_DEBUG << "Loading graphs from " << graphFilesPath;
507 
509  armem::MemoryID providerID = workingMemory().id();
511  providerID.providerSegmentName = graphId;
512 
513  const auto now = armem::Time::Now();
514 
515  for (const auto& graphFile : std::filesystem::directory_iterator(
516  graphFilesPath)) // iterate over the different graphs (json files)
517  {
518  if (std::filesystem::is_regular_file(graphFile.path()) and
519  simox::alg::ends_with(graphFile.path().filename(),
520  ".json")) // assure that its a json file
521  {
522  const std::string graphName = graphFile.path().stem();
523 
524 
525  ARMARX_DEBUG << "Loading graph `" << graphName << " `from file `"
526  << graphFile.path() << "`.";
527 
529 
530  std::ifstream ifs(graphFile.path());
531  const std::string content((std::istreambuf_iterator<char>(ifs)),
532  (std::istreambuf_iterator<char>()));
533 
534  // TODO: Perhaps move to PriorKnowledge similar to locations
535  const nlohmann::json j = nlohmann::json::parse(content);
536 
537  const auto& jEdges = j.at("edges");
538  const auto& jVertices = j.at("vertices");
539 
540  for (const auto& jVertex : jVertices)
541  {
542  const armarx::armem::MemoryID vertexLocationMemoryId(
543  jVertex.at("locationID"));
544 
545  armarx::navigation::core::arondto::Vertex v;
546  v.vertexID = jVertex.at("vertexID");
547  toAron(v.locationID, vertexLocationMemoryId);
548  toAron(v.locationID.timestamp, armem::Time::Invalid());
549  v.locationID.instanceIndex = 0;
550 
551  g.vertices.push_back(v);
552  }
553 
554  for (const auto& jEdge : jEdges)
555  {
556  std::pair<std::int64_t, std::int64_t> edgeSourceTargetPair;
557  jEdge.get_to(edgeSourceTargetPair);
558 
559  armarx::navigation::core::arondto::Edge e;
560  e.sourceVertexID = edgeSourceTargetPair.first;
561  e.targetVertexID = edgeSourceTargetPair.second;
562  g.edges.push_back(e);
563  }
564 
565  auto& up = c.add();
566  up.confidence = 1.0;
567  up.referencedTime = now;
568  up.arrivedTime = now;
569  up.sentTime = now;
570  up.entityID = providerID.withEntityName(graphName);
571  up.instancesData = {g.toAron()};
572  }
573  }
574 
575  ARMARX_DEBUG << "Sending graphs to memory";
576  iceAdapter().commit(c);
577  }
578  }
579 
580  {
581  // Next we load the rooms.
582  std::filesystem::path roomsFilePath = graph->getFullPath() / "rooms.json";
583  if (not std::filesystem::is_regular_file(roomsFilePath))
584  {
585  ARMARX_INFO << "Found no rooms file for graph '" << graphId << "'.";
586  }
587  else
588  {
589  ARMARX_DEBUG << "Found the rooms file";
590 
592  armem::MemoryID providerID = workingMemory().id();
593  providerID.coreSegmentName =
595  providerID.providerSegmentName = graphId;
596 
597  const auto now = armem::Time::Now();
598  ARMARX_VERBOSE << "Loading " << roomsFilePath;
599 
600  std::ifstream ifs(roomsFilePath);
601  const std::string content((std::istreambuf_iterator<char>(ifs)),
602  (std::istreambuf_iterator<char>()));
603 
604  // parse room. TODO: Move into PriorKnowledge similar to locations
605  const nlohmann::json js = nlohmann::json::parse(content);
606 
607  const auto rooms =
608  js.at("rooms").get<std::map<std::string, nlohmann::json>>();
609  ARMARX_INFO << "Found " << rooms.size() << " rooms.";
610  for (const auto& [roomId, j] : rooms)
611  {
612  auto roomMemoryId = providerID;
613  roomMemoryId.entityName = roomId;
614 
615  const std::string roomMemoryIdStr = roomMemoryId.str();
616 
617  if (j.find("polygon") == j.end())
618  {
619  ARMARX_WARNING << "The element '" << roomMemoryIdStr
620  << "' has no 'polygon' member. Skipping "
621  "this entity.";
622  continue;
623  }
624 
625  if (j.find("height") == j.end())
626  {
627  ARMARX_WARNING << "The element '" << roomMemoryIdStr
628  << "' has no 'height' member. "
629  "Skipping this entity.";
630  continue;
631  }
632 
633  navigation::rooms::arondto::Room room;
634  j.at("polygon").get_to(room.polygon);
635  j.at("height").get_to(room.height);
636  room.name = roomId;
637 
638  // set the polygon to z=0
639  for (auto& point : room.polygon)
640  {
641  point.z() = 0;
642  }
643 
644  // send commit to memory
645  auto& up = c.add();
646  up.confidence = 1.0;
647  up.referencedTime = now;
648  up.sentTime = now;
649  up.arrivedTime = now;
650  up.entityID = armarx::armem::MemoryID(roomMemoryIdStr);
651  up.instancesData = {room.toAron()};
652  }
653 
654  ARMARX_DEBUG << "Sending rooms to memory";
655  iceAdapter().commit(c);
656  }
657  }
658  ARMARX_INFO << "Loaded NavigationMemory '" << snapshotToLoad
659  << "' --> graph: '" << graphId << "'";
660  }
661  else
662  {
663  ARMARX_WARNING << "Could not load NavigationMemory '" << snapshotToLoad
664  << "'. Continue with empty memory.";
665  }
666  }
667  }
668 
669  bool
670  store(const std::map<armem::MemoryID, core::Graph>& graphs,
671  const std::filesystem::path& baseDirectory)
672  {
673  ARMARX_INFO << "Creating export directory `" << baseDirectory << "`.";
674  std::filesystem::create_directories(baseDirectory);
675 
676  for (const auto& [memoryId, graph] : graphs)
677  {
678  const std::filesystem::path nestedSubDir =
679  std::filesystem::path(memoryId.providerSegmentName) / memoryId.coreSegmentName;
680  const std::filesystem::path dir = baseDirectory / nestedSubDir;
681 
682  std::filesystem::create_directories(dir);
683 
684  nlohmann::json j;
685 
686  // source -> target
687  std::vector<std::pair<std::size_t, std::size_t>> outgoingEdges;
688  std::transform(graph.m_edges.begin(),
689  graph.m_edges.end(),
690  std::back_inserter(outgoingEdges),
691  [](const auto& edge)
692  { return std::make_pair(edge.m_source, edge.m_target); });
693 
694  j["edges"] = outgoingEdges;
695  j["vertices"] = {};
696 
697  for (const auto& vertex : graph.m_vertices)
698  {
699 
700  armarx::armem::MemoryID locationId;
701  fromAron(vertex.m_property.aron.locationID, locationId);
702 
703  nlohmann::json jVertex;
704  jVertex["locationID"] = locationId.getEntityID().str();
705  jVertex["vertexID"] = vertex.m_property.aron.vertexID;
706 
707  j["vertices"].push_back(jVertex);
708  }
709 
710  // save to disk
711  const std::filesystem::path filename = dir / (memoryId.entityName + ".json");
712  ARMARX_VERBOSE << "Saving file `" << filename << "`.";
713  std::ofstream ofs(filename);
714  ofs << std::setw(4) << j;
715  }
716 
717  return true;
718  }
719 
720  bool
721  store(const std::map<armem::MemoryID, location::arondto::Location>& locations,
722  const std::filesystem::path& baseDirectory)
723  {
724  ARMARX_INFO << "Creating export directory `" << baseDirectory << "`.";
725  std::filesystem::create_directories(baseDirectory);
726 
727  // key: provider id
728  std::map<std::string, nlohmann::json> js;
729 
730  for (const auto& [memoryId, location] : locations)
731  {
732  auto& j = js[memoryId.providerSegmentName];
733 
734  if (j.count("locations") == 0)
735  {
736  j["locations"] = {};
737  }
738 
739  nlohmann::json jLoc;
740  nlohmann::json framedPose;
741 
742  framedPose["agent"] = location.framedPose.header.agent;
743  framedPose["frame"] = location.framedPose.header.frame;
744 
745  // utilize ice conversion of eigen
746  std::vector<std::vector<float>> poseAsVec;
747  armarx::core::eigen::toIce(location.framedPose.pose, poseAsVec);
748  framedPose["pose"] = poseAsVec;
749 
750  jLoc["framedPose"] = framedPose;
751 
752  auto entityId = memoryId.getEntityID();
753  j["locations"][entityId.entityName] = jLoc;
754  }
755 
756  // save to disk
757  for (const auto& [providerId, j] : js)
758  {
759  const std::filesystem::path subDir = std::filesystem::path(providerId);
760  const std::filesystem::path dir = baseDirectory / subDir;
761 
762  if (not std::filesystem::exists(dir))
763  {
764  std::filesystem::create_directories(dir);
765  }
766 
767  const std::filesystem::path filename = dir / "locations.json";
768  ARMARX_VERBOSE << "Saving file `" << filename << "`.";
769  std::ofstream ofs(filename);
770  ofs << std::setw(4) << j;
771  }
772 
773 
774  return true;
775  }
776 
777  bool
778  Component::storeLocationGraph(const armarx::data::PackagePath& packagePath,
779  const Ice::Current& current)
780  {
781  armem::server::wm::CoreSegment& locationCoreSegment =
783  armem::server::wm::CoreSegment& graphCoreSegment =
785 
786  // obtain locations and graphs
787 
788  const std::map<armem::MemoryID, location::arondto::Location> locations =
789  [&locationCoreSegment]()
790  {
791  std::map<armem::MemoryID, location::arondto::Location> locations;
792  locationCoreSegment.doLocked(
793  [&]()
794  {
795  locationCoreSegment.forEachEntity(
796  [&](const armarx::armem::server::wm::Entity& entity) -> bool
797  {
798  if (const armarx::armem::server::wm::EntityInstance* instance =
799  entity.findLatestInstance())
800  {
801  locations[entity.id()].fromAron(instance->data());
802  }
803 
804  return true;
805  });
806 
807  return true;
808  });
809 
810  return locations;
811  }();
812 
813  const auto graphs = [&graphCoreSegment]()
814  {
815  std::map<armem::MemoryID, core::Graph> graphs;
816  graphCoreSegment.doLocked(
817  [&]()
818  {
819  graphCoreSegment.forEachEntity(
820  [&](const armarx::armem::server::wm::Entity& entity) -> bool
821  {
822  core::Graph& graph = graphs[entity.id()];
823  if (const armarx::armem::server::wm::EntityInstance* instance =
824  entity.findLatestInstance())
825  {
827  aron.fromAron(instance->data());
828  fromAron(aron, graph);
829  }
830 
831  return true;
832  });
833  });
834 
835  return graphs;
836  }();
837 
838 
839  // store on disk
840 
841  const std::filesystem::path baseDirectory = armarx::PackagePath(packagePath).toSystemPath();
842 
843  store(locations, baseDirectory);
844 
845  // The graph is no longer relevant.
846  // store(graphs, baseDirectory);
847 
848  return true;
849  }
850 
851 
852 } // namespace armarx::navigation::components::navigation_memory
Visu.h
armarx::SimpleRunningTask
Usage:
Definition: TaskUtil.h:70
armarx::viz::Client::commit
CommitResult commit(StagedCommit const &commit)
Definition: Client.cpp:80
armarx::navigation::graph::coreSegmentID
const armem::MemoryID coreSegmentID
Definition: constants.h:30
ARMARX_VERBOSE
#define ARMARX_VERBOSE
Definition: Logging.h:180
armarx::navigation::components::navigation_memory::Component::Properties::LocationGraph
Definition: Component.h:109
armarx::navigation::components::navigation_memory::Component::storeLocationGraph
bool storeLocationGraph(const armarx::data::PackagePath &packagePath, const Ice::Current &current) override
Definition: Component.cpp:778
ARMARX_IMPORTANT
#define ARMARX_IMPORTANT
Definition: Logging.h:183
armarx::navigation::memory::constants::CostmapCoreSegmentName
const std::string CostmapCoreSegmentName
Definition: constants.h:34
armarx::armem::MemoryID::providerSegmentName
std::string providerSegmentName
Definition: MemoryID.h:52
query.h
armarx::armem::Commit
A bundle of updates to be sent to the memory.
Definition: Commit.h:89
armarx::armem::wm::EntityInstance
Client-side working entity instance.
Definition: memory_definitions.h:32
armarx::priorknowledge::util::FramedLocation::frame
std::string frame
Definition: Location.h:50
armarx::RemoteGui::Client::VBoxLayout
Definition: Widgets.h:167
armarx::core::time::DateTime::Now
static DateTime Now()
Definition: DateTime.cpp:55
armarx::navigation::components::navigation_memory::Component::createPropertyDefinitions
armarx::PropertyDefinitionsPtr createPropertyDefinitions() override
Definition: Component.cpp:74
armarx::navigation::rooms::coreSegmentID
const armem::MemoryID coreSegmentID
Definition: constants.h:10
MemoryID.h
armarx::armem::base::MemoryBase::getCoreSegment
CoreSegmentT & getCoreSegment(const std::string &name)
Definition: MemoryBase.h:132
armarx::navigation::components::navigation_memory::Component::RemoteGui_update
void RemoteGui_update() override
Definition: Component.cpp:247
armarx::RemoteGui::Client::GridLayout::add
GridLayout & add(Widget const &child, Pos pos, Span span=Span{1, 1})
Definition: Widgets.cpp:412
constants.h
ice_conversions.h
armarx::armem::MemoryID::str
std::string str(bool escapeDelimiters=true) const
Get a string representation of this memory ID.
Definition: MemoryID.cpp:102
armarx::navigation::components::navigation_memory::Component::onExitComponent
void onExitComponent() override
Definition: Component.cpp:217
armarx::navigation::components::navigation_memory::Component
Definition: Component.h:54
c
constexpr T c
Definition: UnscentedKalmanFilterTest.cpp:43
armarx::navigation::components::navigation_memory::Component::onDisconnectComponent
void onDisconnectComponent() override
Definition: Component.cpp:212
aron_conversions.h
armarx::armem::server::wm::Entity
Definition: memory_definitions.h:30
armarx::armem::server::plugins::ReadWritePluginUser::workingMemory
server::wm::Memory & workingMemory()
Definition: ReadWritePluginUser.cpp:106
armarx::armem::MemoryID::coreSegmentName
std::string coreSegmentName
Definition: MemoryID.h:51
armarx::RemoteGui::Client::VSpacer
Definition: Widgets.h:204
armarx::armem::base::detail::ForEachEntityMixin::forEachEntity
bool forEachEntity(FunctionT &&func)
Definition: iteration_mixins.h:258
armarx::navigation::components::navigation_memory::ARMARX_REGISTER_COMPONENT_EXECUTABLE
ARMARX_REGISTER_COMPONENT_EXECUTABLE(Component, Component::GetDefaultName())
constants.h
Costmap.h
armarx::navigation::components::navigation_memory::store
bool store(const std::map< armem::MemoryID, core::Graph > &graphs, const std::filesystem::path &baseDirectory)
Definition: Component.cpp:670
armarx::navigation::components::navigation_memory::Component::onInitComponent
void onInitComponent() override
Definition: Component.cpp:143
memory_definitions.h
visionx::voxelgrid::Label
uint32_t Label
Type of an object label.
Definition: types.h:7
LocationLoader.h
armarx::navigation::memory::Visu
Definition: Visu.h:45
armarx::RemoteGui::Client::GridLayout
Definition: Widgets.h:186
ARMARX_TRACE
#define ARMARX_TRACE
Definition: trace.h:69
armarx::navigation::components::navigation_memory::Component::Component
Component()
Definition: Component.cpp:137
armarx::armem::MemoryID
A memory ID.
Definition: MemoryID.h:47
armarx::PackagePath::toSystemPath
static std::filesystem::path toSystemPath(const data::PackagePath &pp)
Definition: PackagePath.cpp:54
Memory.h
ARMARX_DEBUG
#define ARMARX_DEBUG
Definition: Logging.h:177
armarx::navigation::core::Graph
Definition: Graph.h:88
armarx::core::time::Frequency::HertzDouble
static Frequency HertzDouble(double hertz)
Definition: Frequency.cpp:34
armarx::navigation::components::navigation_memory
Definition: Component.cpp:68
armarx::RemoteGui::Client::GroupBox
Definition: Widgets.h:193
armarx::navigation::components::navigation_memory::Component::getDefaultName
std::string getDefaultName() const override
Definition: Component.cpp:222
filename
std::string filename
Definition: VisualizationRobot.cpp:83
armarx::navigation::memory::constants::GraphCoreSegmentName
const std::string GraphCoreSegmentName
Definition: constants.h:32
armarx::armem::base::MemoryBase::addCoreSegment
CoreSegmentT & addCoreSegment(const std::string &name, aron::type::ObjectPtr coreSegmentType=nullptr, const std::vector< PredictionEngine > &predictionEngines={})
Add an empty core segment with the given name, type and prediction engines.
Definition: MemoryBase.h:259
Metronome.h
armarx::armem::server::plugins::ReadWritePluginUser::iceAdapter
MemoryToIceAdapter & iceAdapter()
Definition: ReadWritePluginUser.cpp:112
armarx::Graph
boost::subgraph< CloudGraph > Graph
Definition: Common.h:54
armarx::armem::base::EntityBase::findLatestInstance
auto * findLatestInstance(int instanceIndex=0)
Definition: EntityBase.h:355
operations.h
armarx::core::eigen::toIce
void toIce(const Eigen::Vector2f &e, Ice::FloatSeq &ice)
Definition: ice_conversions.cpp:17
armarx::armem::base::detail::MemoryItem::id
MemoryID & id()
Definition: MemoryItem.h:27
armarx::armem::server::wm::CoreSegment::doLocked
auto doLocked(FunctionT &&function) const
Definition: memory_definitions.h:120
armarx::armem::MemoryID::entityName
std::string entityName
Definition: MemoryID.h:53
armarx::navigation::memory::constants::HumanCoreSegmentName
const std::string HumanCoreSegmentName
Definition: constants.h:35
aron_conversions.h
forward_declarations.h
armarx::RemoteGui::Client::GroupBox::setLabel
void setLabel(std::string const &text)
Definition: Widgets.cpp:395
Component.h
aron_conversions.h
armarx::LightweightRemoteGuiComponentPluginUser::RemoteGui_startRunningTask
void RemoteGui_startRunningTask()
Definition: LightweightRemoteGuiComponentPlugin.cpp:110
CycleUtil.h
armarx::armem::server::wm::CoreSegment
base::CoreSegmentBase
Definition: memory_definitions.h:86
armarx::priorknowledge::util::FramedLocation
Definition: Location.h:48
armarx::Component::getConfigIdentifier
std::string getConfigIdentifier()
Retrieve config identifier for this component as set in constructor.
Definition: Component.cpp:74
Decoupled.h
armarx::navigation::components::navigation_memory::Component::RemoteGuiTab::LocationGraph::update
void update(Component &owner)
Definition: Component.cpp:281
armarx::armem::MemoryID::getEntityID
MemoryID getEntityID() const
Definition: MemoryID.cpp:305
Graph.h
armarx::ctrlutil::v
double v(double t, double v0, double a0, double j)
Definition: CtrlUtil.h:39
armarx::armem::MemoryID::withEntityName
MemoryID withEntityName(const std::string &name) const
Definition: MemoryID.cpp:420
armarx::navigation::components::navigation_memory::Component::onConnectComponent
void onConnectComponent() override
Definition: Component.cpp:193
armarx::priorknowledge::util::LocationLoader::LoadLocations
static std::vector< LocationPtr > LoadLocations(const std::string &dataset, const nlohmann::json &)
Definition: LocationLoader.cpp:143
armarx::ComponentPropertyDefinitions
Default component property definition container.
Definition: Component.h:70
ARMARX_INFO
#define ARMARX_INFO
Definition: Logging.h:174
armarx::ArVizComponentPluginUser::arviz
armarx::viz::Client arviz
Definition: ArVizComponentPlugin.h:43
armarx::navigation::components::navigation_memory::Component::GetDefaultName
static std::string GetDefaultName()
Definition: Component.cpp:228
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< class PropertyDefinitionContainer >
armarx::core::time::Metronome
Simple rate limiter for use in loops to maintain a certain frequency given a clock.
Definition: Metronome.h:35
armarx::transform
auto transform(const Container< InputT, Alloc > &in, OutputT(*func)(InputT const &)) -> Container< OutputT, typename std::allocator_traits< Alloc >::template rebind_alloc< OutputT > >
Convenience function (with less typing) to transform a container of type InputT into the same contain...
Definition: algorithm.h:315
NavigationGraphFinder.h
armarx::ends_with
bool ends_with(const std::string &haystack, const std::string &needle)
Definition: StringHelpers.cpp:50
armarx::fromAron
void fromAron(const arondto::PackagePath &dto, PackageFileLocation &bo)
armarx::navigation::memory::constants::ParameterizationCoreSegmentName
const std::string ParameterizationCoreSegmentName
Definition: constants.h:30
constants.h
armarx::navigation::location::coreSegmentID
const armem::MemoryID coreSegmentID
Definition: constants.h:30
armarx::ManagedIceObject::getName
std::string getName() const
Retrieve name of object.
Definition: ManagedIceObject.cpp:107
armarx::RemoteGui::Client::Button
Definition: Widgets.h:120
armarx::toAron
void toAron(arondto::PackagePath &dto, const PackageFileLocation &bo)
armarx::ObjectPoseClientPluginUser::getClient
objpose::ObjectPoseClient getClient() const
Definition: ObjectPoseClientPlugin.cpp:64
ARMARX_WARNING
#define ARMARX_WARNING
Definition: Logging.h:186
armarx::priorknowledge::navigation_graphs::NavigationGraphFinder
Definition: NavigationGraphFinder.h:7
armarx::RemoteGui::Client
Definition: EigenWidgets.cpp:8
ArmarXDataPath.h
armarx::PackagePath
Definition: PackagePath.h:55
armarx::priorknowledge::util::LocationType::FRAMED_LOCATION
@ FRAMED_LOCATION
armarx::navigation::components::navigation_memory::Component::createRemoteGuiTab
void createRemoteGuiTab()
Definition: Component.cpp:234
armarx::navigation::components::navigation_memory::Component::Properties::LocationGraph::visuGraphEdges
bool visuGraphEdges
Definition: Component.h:112
armarx::navigation::memory::constants::LaserScannerFeaturesCoreSegment
const std::string LaserScannerFeaturesCoreSegment
Definition: constants.h:36
armarx::core::time::DateTime::Invalid
static DateTime Invalid()
Definition: DateTime.cpp:60
armarx::armem::base::MemoryBase::setName
void setName(const std::string &name)
Definition: MemoryBase.h:246
armarx::armem::server::MemoryToIceAdapter::commitLocking
data::CommitResult commitLocking(const data::Commit &commitIce, Time timeArrived)
Definition: MemoryToIceAdapter.cpp:163
armarx::armem::server::MemoryToIceAdapter::commit
data::CommitResult commit(const data::Commit &commitIce, Time timeArrived)
Definition: MemoryToIceAdapter.cpp:112
armarx::core::time::Duration::MilliSeconds
static Duration MilliSeconds(std::int64_t milliSeconds)
Constructs a duration in milliseconds.
Definition: Duration.cpp:55
armarx::navigation::components::navigation_memory::Component::RemoteGuiTab::LocationGraph::setup
void setup(Component &owner)
Definition: Component.cpp:253
constants.h
armarx::navigation::components::navigation_memory::Component::Properties::LocationGraph::visuLocations
bool visuLocations
Definition: Component.h:111
armarx::split
std::vector< std::string > split(const std::string &source, const std::string &splitBy, bool trimElements=false, bool removeEmptyElements=false)
Definition: StringHelpers.cpp:36
armarx::human::MemoryID
const armem::MemoryID MemoryID
Definition: memory_ids.cpp:29