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