Reader.cpp
Go to the documentation of this file.
1 #include "Reader.h"
2 
3 #include <SimoxUtility/algorithm/string/string_tools.h>
4 
10 
11 #include "../frame_conversions.h"
12 
14 {
15  void
17  {
18  const std::string prefix = propertyPrefix;
19 
20  def->optional(p.memoryName, prefix + "MemoryName");
21  objReader.registerPropertyDefinitions(def);
22  robotReader.registerPropertyDefinitions(def);
23  }
24 
25  void
27  {
28  // Wait for the memory to become available and add it as dependency.
29  ARMARX_IMPORTANT << "Waiting for memory '" << p.memoryName << "' ...";
30  try
31  {
32  // simply wait until memory is ready. Do nothing with reader but get prx
33  locationReader = memoryNameSystem.useReader(p.memoryName);
34 
35  ARMARX_IMPORTANT << "Connected to Memory '" << p.memoryName << "'";
36  }
38  {
39  ARMARX_ERROR << e.what();
40  return;
41  }
42 
43  objReader.connect(memoryNameSystem);
44  robotReader.connect(memoryNameSystem);
45  }
46 
47  std::map<std::string, armarx::navigation::location::arondto::Location>
49  {
50  auto mId = armarx::armem::MemoryID{p.memoryName, "Location"};
51  auto res = locationReader.getLatestSnapshotsIn(mId);
52 
53  if (res.success)
54  {
55  std::map<std::string, armarx::navigation::location::arondto::Location> ret;
56  res.memory.forEachEntity(
57  [&ret](const armarx::armem::wm::Entity& e)
58  {
59  auto i = e.findLatestInstance();
60  if (i)
61  {
62  auto loc = i->dataAs<armarx::navigation::location::arondto::Location>();
63  ret[i->id().providerSegmentName + "/" + i->id().entityName] = loc;
64  }
65  });
66  return ret;
67  }
68 
69  throw error::ArMemError(res.errorMessage);
70  }
71 
72  std::map<std::string, armarx::navigation::location::arondto::Location>
74  {
75  auto locations = this->getAllLocations();
76  auto objects = objReader.queryLatestObjectInstances();
77  auto robotDecs = robotReader.queryDescriptions(armarx::core::time::DateTime::Now());
78 
79  for (auto& [locName, location] : locations)
80  {
81  (void)locName;
82  if (location.framedPose.header.frame == armarx::GlobalFrame)
83  {
84  location.framedPose.header.agent = ""; //sanity set
85  continue;
86  }
87  // check if we have an object that matches the relative location
88  for (const auto& [objectInstanceId, object] : objects)
89  {
90  if (simox::alg::starts_with(objectInstanceId, location.framedPose.header.agent))
91  {
92  toGlobal(location, object);
93  }
94  }
95 
96  // TODO: check if we have an robot that matches the relative location
97  }
98 
99  return locations;
100  }
101 
102 
103 } // namespace armarx::armem::locations::client
armarx::armem::locations::client::Reader::getAllLocations
std::map< std::string, armarx::navigation::location::arondto::Location > getAllLocations()
Definition: Reader.cpp:48
armarx::aron::ret
ReaderT::InputType T & ret
Definition: rw.h:13
armarx::armem::locations::client::Reader::getAllLocationsInGlobalFrame
std::map< std::string, armarx::navigation::location::arondto::Location > getAllLocationsInGlobalFrame()
Definition: Reader.cpp:73
armarx::armem::client::Reader::getLatestSnapshotsIn
QueryResult getLatestSnapshotsIn(const MemoryID &id, armem::query::DataMode dataMode=armem::query::DataMode::WithData) const
Get the latest snapshots under the given memory ID.
Definition: Reader.cpp:340
ARMARX_IMPORTANT
#define ARMARX_IMPORTANT
Definition: Logging.h:190
armarx::armem::obj::instance::Reader::queryLatestObjectInstances
std::map< std::string, objpose::ObjectPose > queryLatestObjectInstances(const ObjectID &classId)
Definition: ObjectReader.cpp:136
armarx::core::time::DateTime::Now
static DateTime Now()
Definition: DateTime.cpp:51
armarx::armem::robot_state::RobotReader::registerPropertyDefinitions
virtual void registerPropertyDefinitions(::armarx::PropertyDefinitionsPtr &def)
Definition: RobotReader.cpp:43
armarx::GlobalFrame
const std::string GlobalFrame
Definition: FramedPose.h:65
armarx::armem::error::ArMemError
Base class for all exceptions thrown by the armem library.
Definition: ArMemError.h:18
armarx::armem::robot_state::RobotReader::connect
virtual void connect(armem::client::MemoryNameSystem &memoryNameSystem)
Definition: RobotReader.cpp:49
armarx::starts_with
bool starts_with(const std::string &haystack, const std::string &needle)
Definition: StringHelpers.cpp:47
armarx::armem::locations::client::Reader::registerPropertyDefinitions
void registerPropertyDefinitions(armarx::PropertyDefinitionsPtr &def)
Definition: Reader.cpp:16
armarx::armem::locations::client
Definition: Reader.cpp:13
armarx::armem::MemoryID
A memory ID.
Definition: MemoryID.h:47
armarx::armem::locations::toGlobal
void toGlobal(armarx::navigation::location::arondto::Location &framedLoc, const Eigen::Matrix4f &framedToGlobal)
Definition: frame_conversions.h:14
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:198
armarx::armem::obj::instance::Reader::connect
void connect(armem::client::MemoryNameSystem &memoryNameSystem)
Definition: ObjectReader.cpp:33
armarx::armem::base::EntityBase::findLatestInstance
auto * findLatestInstance(int instanceIndex=0)
Definition: EntityBase.h:355
ARMARX_ERROR
#define ARMARX_ERROR
Definition: Logging.h:196
armarx::armem::locations::client::Reader::connect
void connect(armem::client::MemoryNameSystem &memoryNameSystem)
Definition: Reader.cpp:26
memory_definitions.h
IceUtil::Handle< class PropertyDefinitionContainer >
armarx::armem::robot_state::RobotReader::queryDescriptions
std::vector< description::RobotDescription > queryDescriptions(const armem::Time &timestamp) const
Definition: RobotReader.cpp:848
Time.h
Builder.h
armarx::armem::client::MemoryNameSystem
The memory name system (MNS) client.
Definition: MemoryNameSystem.h:68
armarx::armem::error::CouldNotResolveMemoryServer
Indicates that a query to the Memory Name System failed.
Definition: mns.h:24
Reader.h
util.h
armarx::armem::wm::Entity
Client-side working memory entity.
Definition: memory_definitions.h:93
armarx::armem::locations::client::Reader::Properties::memoryName
std::string memoryName
Definition: Reader.h:23
armarx::armem::obj::instance::Reader::registerPropertyDefinitions
void registerPropertyDefinitions(armarx::PropertyDefinitionsPtr &def)
Definition: ObjectReader.cpp:25