Writer.cpp
Go to the documentation of this file.
1#include "Writer.h"
2
6#include <RobotAPI/libraries/armem_laser_scans/aron/LaserScan.aron.generated.h>
8
10{
11
13 {
14 }
15
16 Writer::~Writer() = default;
17
18 void
20 {
21 ARMARX_DEBUG << "LaserScansWriter: registerPropertyDefinitions";
22
23 const std::string prefix = propertyPrefix;
24 }
25
26 void
28 {
29 // Wait for the memory to become available and add it as dependency.
30 ARMARX_IMPORTANT << "LaserScansWriter: Waiting for memory '" << constants::memoryName
31 << "' ...";
32 try
33 {
34 memoryWriter =
35 memoryNameSystem.useWriter(MemoryID().withMemoryName(constants::memoryName));
36 ARMARX_IMPORTANT << "MappingDataWriter: Connected to memory '" << constants::memoryName
37 << "'";
38 }
40 {
41 ARMARX_ERROR << e.what();
42 return;
43 }
44
45 ARMARX_IMPORTANT << "LaserScansWriter: Connected to memory '" << constants::memoryName;
46 }
47
48 bool
49 Writer::storeSensorData(const LaserScan& laserScan,
50 const std::string& frame,
51 const std::string& agentName,
53 {
54 std::lock_guard g{memoryWriterMutex};
55
56 const auto result = memoryWriter.addSegment(constants::memoryName, agentName);
57
58 ARMARX_VERBOSE << "Storing scan with " << laserScan.size() << " elements";
59
60 if (not result.success)
61 {
62 ARMARX_ERROR << result.errorMessage;
63
64 // TODO(fabian.reister): message
65 return false;
66 }
67
68
69 const auto providerId = armem::MemoryID(result.segmentID);
70 const auto entityID = providerId.withEntityName(frame).withTimestamp(timestamp);
71
73 update.entityID = entityID;
74
75 arondto::LaserScanStamped aronSensorData;
76 // currently only sets the header
77 toAron(laserScan, timestamp, frame, agentName, aronSensorData);
78
79 auto dict = aronSensorData.toAron();
80 dict->addElementCopy("scan", toAron(laserScan));
81
82 update.instancesData = {dict};
83 update.referencedTime = timestamp;
84
85 ARMARX_DEBUG << "Committing " << update << " at time " << timestamp;
86 armem::EntityUpdateResult updateResult = memoryWriter.commit(update);
87
88 ARMARX_DEBUG << updateResult;
89
90 if (not updateResult.success)
91 {
92 ARMARX_ERROR << updateResult.errorMessage;
93 }
94
95 return updateResult.success;
96 }
97
98} // namespace armarx::armem::laser_scans::client
std::string timestamp()
The memory name system (MNS) client.
Writer useWriter(const MemoryID &memoryID)
Use a memory server and get a writer for it.
Indicates that a query to the Memory Name System failed.
Definition mns.h:25
bool storeSensorData(const LaserScan &laserScan, const std::string &frame, const std::string &agentName, const armem::Time &timestamp)
Definition Writer.cpp:49
void connect(armem::client::MemoryNameSystem &memoryNameSystem)
Definition Writer.cpp:27
void registerPropertyDefinitions(armarx::PropertyDefinitionsPtr &def)
to be called in Component::onConnectComponent
Definition Writer.cpp:19
#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
#define ARMARX_DEBUG
The logging level for output that is only interesting while debugging.
Definition Logging.h:184
#define ARMARX_VERBOSE
The logging level for verbose information.
Definition Logging.h:187
int64_t toAron(const armem::Time &timestamp)
armarx::core::time::DateTime Time
IceUtil::Handle< class PropertyDefinitionContainer > PropertyDefinitionsPtr
PropertyDefinitions smart pointer type.
Result of an EntityUpdate.
Definition Commit.h:75
An update of an entity for a specific point in time.
Definition Commit.h:26