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,
52  const armem::Time& timestamp)
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
ARMARX_VERBOSE
#define ARMARX_VERBOSE
Definition: Logging.h:180
armarx::armem::client::Writer::addSegment
data::AddSegmentResult addSegment(const std::string &coreSegmentName, const std::string &providerSegmentName, bool clearWhenExists=false) const
Definition: Writer.cpp:16
ARMARX_IMPORTANT
#define ARMARX_IMPORTANT
Definition: Logging.h:183
armarx::armem::laser_scans::client::Writer::connect
void connect(armem::client::MemoryNameSystem &memoryNameSystem)
Definition: Writer.cpp:27
armarx::armem::EntityUpdateResult
Result of an EntityUpdate.
Definition: Commit.h:72
armarx::armem::laser_scans::client::Writer::registerPropertyDefinitions
void registerPropertyDefinitions(armarx::PropertyDefinitionsPtr &def)
to be called in Component::onConnectComponent
Definition: Writer.cpp:19
aron_conversions.h
forward_declarations.h
armarx::armem::client::MemoryNameSystem::useWriter
Writer useWriter(const MemoryID &memoryID)
Use a memory server and get a writer for it.
Definition: MemoryNameSystem.cpp:276
armarx::armem::laser_scans::client::Writer::storeSensorData
bool storeSensorData(const LaserScan &laserScan, const std::string &frame, const std::string &agentName, const armem::Time &timestamp)
Definition: Writer.cpp:49
Writer.h
constants.h
ARMARX_DEBUG
#define ARMARX_DEBUG
Definition: Logging.h:177
error.h
armarx::armem::EntityUpdate
An update of an entity for a specific point in time.
Definition: Commit.h:27
armarx::armem::client::Writer::commit
CommitResult commit(const Commit &commit) const
Writes a Commit to the memory.
Definition: Writer.cpp:59
armarx::armem::laser_scans::client
Definition: Reader.cpp:47
ARMARX_ERROR
#define ARMARX_ERROR
Definition: Logging.h:189
armarx::armem::laser_scans::toAron
int64_t toAron(const armem::Time &timestamp)
Definition: aron_conversions.cpp:59
armarx::armem::server::ltm::util::mongodb::detail::update
bool update(mongocxx::collection &coll, const nlohmann::json &query, const nlohmann::json &update)
Definition: mongodb.cpp:67
armarx::armem::laser_scans::client::Writer::~Writer
virtual ~Writer()
armarx::core::time::DateTime
Represents a point in time.
Definition: DateTime.h:24
armarx::armem::laser_scans::constants::memoryName
const std::string memoryName
Definition: constants.h:28
IceUtil::Handle< class PropertyDefinitionContainer >
armarx::armem::client::MemoryNameSystem
The memory name system (MNS) client.
Definition: MemoryNameSystem.h:69
armarx::armem::error::CouldNotResolveMemoryServer
Indicates that a query to the Memory Name System failed.
Definition: mns.h:26
armarx::armem::laser_scans::client::Writer::Writer
Writer()
Definition: Writer.cpp:12
armarx::human::MemoryID
const armem::MemoryID MemoryID
Definition: memory_ids.cpp:29