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;
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
armarx::armem::vision::toAron
void toAron(arondto::OccupancyGrid &dto, const OccupancyGrid &bo)
Definition: aron_conversions.cpp:20
armarx::armem::vision::OccupancyGrid
Definition: types.h:36
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::armem::EntityUpdateResult
Result of an EntityUpdate.
Definition: Commit.h:72
armarx::armem::vision::occupancy_grid::client::Writer::~Writer
~Writer() override
Writer.h
armarx::armem::vision::occupancy_grid::client::Writer::defaultProperties
Properties defaultProperties() const override
Definition: Writer.cpp:66
armarx::armem::vision::occupancy_grid::client
Definition: Reader.cpp:47
aron_conversions.h
armarx::armem::client::util::SimpleWriterBase::memoryWriter
armem::client::Writer & memoryWriter()
Definition: SimpleWriterBase.cpp:51
ARMARX_DEBUG
#define ARMARX_DEBUG
Definition: Logging.h:177
armarx::armem::client::util::SimpleWriterBase::Properties::memoryName
std::string memoryName
Definition: SimpleWriterBase.h:51
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_ERROR
#define ARMARX_ERROR
Definition: Logging.h:189
armarx::armem::Time
armarx::core::time::DateTime Time
Definition: forward_declarations.h:13
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::vision::occupancy_grid::client::Writer::store
bool store(const OccupancyGrid &grid, const std::string &frame, const std::string &providerName, const std::int64_t &timestamp)
Definition: Writer.cpp:11
armarx::armem::vision::occupancy_grid::client::Writer::propertyPrefix
std::string propertyPrefix() const override
Definition: Writer.cpp:60
armarx::armem::vision::OccupancyGrid::grid
Grid grid
Definition: types.h:47
armarx::armem::client::util::SimpleWriterBase::properties
const Properties & properties() const
Definition: SimpleWriterBase.cpp:57
armarx::core::time::Duration::MicroSeconds
static Duration MicroSeconds(std::int64_t microSeconds)
Constructs a duration in microseconds.
Definition: Duration.cpp:27
armarx::human::MemoryID
const armem::MemoryID MemoryID
Definition: memory_ids.cpp:29