Writer.cpp
Go to the documentation of this file.
1 #include "Writer.h"
2 
3 #include <mutex>
4 #include <string>
5 
7 
11 
12 #include <armarx/navigation/core/aron/Trajectory.aron.generated.h>
18 
20 {
21  bool
22  Writer::store(const server::StackResult& result, const std::string& clientID)
23  {
24  // single ice call for all updates
25  armem::Commit commit;
26 
27  storePrepare(result.globalPlan, clientID, commit);
28  storePrepare(result.localTrajectory, clientID, commit);
29  // storePrepare(result.controlVelocity, clientID, commit);
30  // FIXME storePrepare(result.safeVelocity, clientID, commit);
31 
32  std::lock_guard g{writeMutex};
33  armem::CommitResult updateResult = memoryWriter().commit(commit);
34 
35  ARMARX_DEBUG << updateResult;
36 
37  if (not updateResult.allSuccess())
38  {
39  ARMARX_ERROR << updateResult.allErrorMessages();
40  }
41  return updateResult.allSuccess();
42  }
43 
44  bool
46  const std::string& clientID)
47  {
48  armem::Commit commit;
49  storePrepare(result, clientID, commit);
50  std::lock_guard g{writeMutex};
51  armem::CommitResult updateResult = memoryWriter().commit(commit);
52  return updateResult.allSuccess();
53  }
54 
55  bool
57  const std::string& clientID)
58  {
59  armem::Commit commit;
60  storePrepare(result, clientID, commit);
61  std::lock_guard g{writeMutex};
62  armem::CommitResult updateResult = memoryWriter().commit(commit);
63  return updateResult.allSuccess();
64  }
65 
66  bool
67  Writer::storePrepare(const armarx::navigation::global_planning::GlobalPlannerResult& result,
68  const std::string& clientID,
69  armem::Commit& commit)
70  {
71  // FIXME timestamp should be part of GlobalPlannerResult
72  armem::Time timestamp = armem::Time::Now();
73 
75  update.entityID = armem::MemoryID()
78  .withProviderSegmentName(clientID)
79  .withEntityName("trajectory")
80  .withTimestamp(timestamp);
81 
82 
83  core::arondto::GlobalTrajectory aronDto;
84  // FIXME create Aron type
85  core::toAron(aronDto, result.trajectory);
86 
87  update.referencedTime = timestamp;
88  update.instancesData = {aronDto.toAron()};
89 
90  commit.add(update);
91 
92  return true;
93  }
94 
95  bool
96  Writer::storePrepare(const local_planning::LocalPlannerResult& result,
97  const std::string& clientID,
98  armem::Commit& commit)
99  {
100  // FIXME timestamp should be part of GlobalPlannerResult
101  armem::Time timestamp = armem::Time::Now();
102 
104  update.entityID = armem::MemoryID()
107  .withProviderSegmentName(clientID)
108  .withEntityName("trajectory")
109  .withTimestamp(timestamp);
110 
111 
112  core::arondto::LocalTrajectory aronDto;
113  // FIXME create Aron type
114  toAron(aronDto, result.trajectory);
115 
116  update.referencedTime = timestamp;
117  update.instancesData = {aronDto.toAron()};
118 
119  commit.add(update);
120 
121  return true;
122  }
123 
124  std::string
126  {
127  return "mem.nav.stack_result.";
128  }
129 
132  {
133  return Properties{
134  .memoryName = "Navigation",
135  .coreSegmentName = "", // here we use multiple
136  .providerName = "" // must be set by user
137  };
138  }
139 
140 } // namespace armarx::navigation::memory::client::stack_result
armarx::navigation::server::StackResult::globalPlan
global_planning::GlobalPlannerResult globalPlan
Definition: StackResult.h:39
armarx::armem::MemoryID::withMemoryName
MemoryID withMemoryName(const std::string &name) const
Definition: MemoryID.cpp:401
StackResult.h
armarx::navigation::local_planning::LocalPlannerResult
Definition: LocalPlanner.h:40
armarx::armem::Commit
A bundle of updates to be sent to the memory.
Definition: Commit.h:84
armarx::core::time::DateTime::Now
static DateTime Now()
Definition: DateTime.cpp:51
MemoryID.h
armarx::navigation::global_planning::GlobalPlannerResult::trajectory
core::GlobalTrajectory trajectory
Definition: GlobalPlanner.h:40
forward_declarations.h
LocalPlanner.h
armarx::armem::client::util::SimpleWriterBase::Properties
Definition: SimpleWriterBase.h:47
armarx::navigation::memory::client::stack_result
This file is part of ArmarX.
Definition: Reader.cpp:19
armarx::navigation::core::toAron
void toAron(arondto::GlobalTrajectoryPoint &dto, const GlobalTrajectoryPoint &bo)
Definition: aron_conversions.cpp:24
armarx::armem::MemoryID::withProviderSegmentName
MemoryID withProviderSegmentName(const std::string &name) const
Definition: MemoryID.cpp:417
armarx::armem::client::util::SimpleWriterBase::memoryWriter
armem::client::Writer & memoryWriter()
Definition: SimpleWriterBase.cpp:52
armarx::armem::MemoryID::withCoreSegmentName
MemoryID withCoreSegmentName(const std::string &name) const
Definition: MemoryID.cpp:409
armarx::navigation::server::StackResult::localTrajectory
local_planning::LocalPlannerResult localTrajectory
Definition: StackResult.h:41
ARMARX_DEBUG
#define ARMARX_DEBUG
Definition: Logging.h:184
armarx::armem::client::util::SimpleWriterBase::Properties::memoryName
std::string memoryName
Definition: SimpleWriterBase.h:49
armarx::armem::EntityUpdate
An update of an entity for a specific point in time.
Definition: Commit.h:25
armarx::armem::CommitResult
Result of a Commit.
Definition: Commit.h:105
armarx::armem::client::Writer::commit
CommitResult commit(const Commit &commit) const
Writes a Commit to the memory.
Definition: Writer.cpp:59
GlobalPlanner.h
armarx::navigation::memory::client::stack_result::Writer::propertyPrefix
std::string propertyPrefix() const override
Definition: Writer.cpp:125
ARMARX_ERROR
#define ARMARX_ERROR
Definition: Logging.h:196
armarx::navigation::global_planning::GlobalPlannerResult
Definition: GlobalPlanner.h:38
armarx::armem::server::ltm::util::mongodb::detail::update
bool update(mongocxx::collection &coll, const nlohmann::json &query, const nlohmann::json &update)
Definition: mongodb.cpp:68
Commit.h
armarx::navigation::memory::client::stack_result::Writer::store
bool store(const server::StackResult &result, const std::string &clientID)
Definition: Writer.cpp:22
armarx::navigation::memory::client::stack_result::Writer::defaultProperties
Properties defaultProperties() const override
Definition: Writer.cpp:131
armarx::core::time::DateTime
Represents a point in time.
Definition: DateTime.h:24
armarx::armem::MemoryID::withEntityName
MemoryID withEntityName(const std::string &name) const
Definition: MemoryID.cpp:425
armarx::armem::Commit::add
EntityUpdate & add()
Definition: Commit.cpp:80
armarx::navigation::memory::toAron
void toAron(arondto::Circle &dto, const Circle &bo)
Definition: aron_conversions.cpp:25
aron_conversions.h
armarx::armem::laser_scans::constants::memoryName
const std::string memoryName
Definition: constants.h:28
armarx::navigation::memory::constants::GlobalPlannerResultCoreSegment
const std::string GlobalPlannerResultCoreSegment
Definition: constants.h:41
armarx::armem::client::util::SimpleWriterBase::properties
const Properties & properties() const
Definition: SimpleWriterBase.cpp:58
armarx::armem::MemoryID::withTimestamp
MemoryID withTimestamp(Time time) const
Definition: MemoryID.cpp:433
Writer.h
constants.h
Logging.h
armarx::navigation::memory::constants::LocalPlannerResultCoreSegment
const std::string LocalPlannerResultCoreSegment
Definition: constants.h:42
armarx::navigation::local_planning::LocalPlannerResult::trajectory
core::LocalTrajectory trajectory
Definition: LocalPlanner.h:42
armarx::armem::CommitResult::allSuccess
bool allSuccess() const
Definition: Commit.cpp:64
armarx::navigation::server::StackResult
Definition: StackResult.h:34
armarx::human::MemoryID
const armem::MemoryID MemoryID
Definition: memory_ids.cpp:28