Reader.cpp
Go to the documentation of this file.
1#include "Reader.h"
2
3#include <SimoxUtility/algorithm/string/string_tools.h>
4
10
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
auto * findLatestInstance(int instanceIndex=0)
Definition EntityBase.h:356
The memory name system (MNS) client.
Reader useReader(const MemoryID &memoryID)
Use a memory server and get a reader for it.
Base class for all exceptions thrown by the armem library.
Definition ArMemError.h:19
Indicates that a query to the Memory Name System failed.
Definition mns.h:25
std::map< std::string, armarx::navigation::location::arondto::Location > getAllLocationsInGlobalFrame()
Definition Reader.cpp:73
void connect(armem::client::MemoryNameSystem &memoryNameSystem)
Definition Reader.cpp:26
std::map< std::string, armarx::navigation::location::arondto::Location > getAllLocations()
Definition Reader.cpp:48
void registerPropertyDefinitions(armarx::PropertyDefinitionsPtr &def)
Definition Reader.cpp:16
Client-side working memory entity.
static DateTime Now()
Definition DateTime.cpp:51
#define ARMARX_IMPORTANT
The logging level for always important information, but expected behaviour (in contrast to ARMARX_WAR...
Definition Logging.h:190
#define ARMARX_ERROR
The logging level for unexpected behaviour, that must be fixed.
Definition Logging.h:196
std::string const GlobalFrame
Variable of the global coordinate system.
Definition FramedPose.h:65
void toGlobal(armarx::navigation::location::arondto::Location &framedLoc, const Eigen::Matrix4f &framedToGlobal)
IceUtil::Handle< class PropertyDefinitionContainer > PropertyDefinitionsPtr
PropertyDefinitions smart pointer type.