Writer.cpp
Go to the documentation of this file.
1#include "Writer.h"
2
3#include <RobotAPI/libraries/armem_vision/aron/OccupancyGrid.aron.generated.h>
5
7{
8 Writer::~Writer() = default;
9
10 bool
12 const std::string& frame,
13 const std::string& providerName,
14 const std::int64_t& timestamp)
15 {
16 std::lock_guard g{writeMutex};
17
18 const auto result = memoryWriter().addSegment(properties().coreSegmentName, providerName);
19
20 if (not result.success)
21 {
22 ARMARX_ERROR << result.errorMessage;
23
24 // TODO(fabian.reister): message
25 return false;
26 }
27
28 const auto iceTimestamp = Time(Duration::MicroSeconds(timestamp));
29
30 const auto providerId = armem::MemoryID(result.segmentID);
31 const auto entityID = providerId.withEntityName(frame).withTimestamp(iceTimestamp);
32
34 update.entityID = entityID;
35
36 arondto::OccupancyGrid aronGrid;
37 // currently only sets the header
38 toAron(aronGrid, grid);
39
40 auto dict = aronGrid.toAron();
41 dict->addElement("grid", toAron(grid.grid));
42
43 update.instancesData = {dict};
44 update.referencedTime = iceTimestamp;
45
46 ARMARX_DEBUG << "Committing " << update << " at time " << iceTimestamp;
47 armem::EntityUpdateResult updateResult = memoryWriter().commit(update);
48
49 ARMARX_DEBUG << updateResult;
50
51 if (not updateResult.success)
52 {
53 ARMARX_ERROR << updateResult.errorMessage;
54 }
55
56 return updateResult.success;
57 }
58
59 std::string
61 {
62 return "mem.vision.occupancy_grid.";
63 }
64
65 armarx::armem::client::util::SimpleWriterBase::SimpleWriterBase::Properties
67 {
68
69 return SimpleWriterBase::Properties{.memoryName = "Vision",
70 .coreSegmentName = "OccupancyGrid"};
71 }
72} // namespace armarx::armem::vision::occupancy_grid::client
std::string timestamp()
data::AddSegmentResult addSegment(const std::string &coreSegmentName, const std::string &providerSegmentName, bool clearWhenExists=false) const
Definition Writer.cpp:25
CommitResult commit(const Commit &commit) const
Writes a Commit to the memory.
Definition Writer.cpp:68
bool store(const OccupancyGrid &grid, const std::string &frame, const std::string &providerName, const std::int64_t &timestamp)
Definition Writer.cpp:11
static Duration MicroSeconds(std::int64_t microSeconds)
Constructs a duration in microseconds.
Definition Duration.cpp:24
#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
void toAron(arondto::OccupancyGrid &dto, const OccupancyGrid &bo)
armarx::core::time::DateTime Time
Result of an EntityUpdate.
Definition Commit.h:75
An update of an entity for a specific point in time.
Definition Commit.h:26