Writer.cpp
Go to the documentation of this file.
1 #include "Writer.h"
2 
6 
8 #include <armarx/navigation/core/aron/Trajectory.aron.generated.h>
9 #include <armarx/navigation/core/aron/Twist.aron.generated.h>
12 
14 {
15  bool
16  Writer::store(const server::StackResult& result, const std::string& clientID)
17  {
18  // single ice call for all updates
19  armem::Commit commit;
20 
21  storePrepare(result.globalPlan, clientID, commit);
22  storePrepare(result.localTrajectory, clientID, commit);
23  // storePrepare(result.controlVelocity, clientID, commit);
24  // FIXME storePrepare(result.safeVelocity, clientID, commit);
25 
26  std::lock_guard g{writeMutex};
27  armem::CommitResult updateResult = memoryWriter().commit(commit);
28 
29  ARMARX_DEBUG << updateResult;
30 
31  if (not updateResult.allSuccess())
32  {
33  ARMARX_ERROR << updateResult.allErrorMessages();
34  }
35  return updateResult.allSuccess();
36  }
37 
38  bool
40  const std::string& clientID)
41  {
42  armem::Commit commit;
43  storePrepare(result, clientID, commit);
44  std::lock_guard g{writeMutex};
45  armem::CommitResult updateResult = memoryWriter().commit(commit);
46  return updateResult.allSuccess();
47  }
48 
49  bool
51  const std::string& clientID)
52  {
53  armem::Commit commit;
54  storePrepare(result, clientID, commit);
55  std::lock_guard g{writeMutex};
56  armem::CommitResult updateResult = memoryWriter().commit(commit);
57  return updateResult.allSuccess();
58  }
59 
60 
61  bool
62  Writer::storePrepare(const armarx::navigation::global_planning::GlobalPlannerResult& result,
63  const std::string& clientID,
64  armem::Commit& commit)
65  {
66  // FIXME timestamp should be part of GlobalPlannerResult
67  armem::Time timestamp = armem::Time::Now();
68 
70  update.entityID = armem::MemoryID()
73  .withProviderSegmentName(clientID)
74  .withEntityName("trajectory")
75  .withTimestamp(timestamp);
76 
77 
78  core::arondto::GlobalTrajectory aronDto;
79  // FIXME create Aron type
80  core::toAron(aronDto, result.trajectory);
81 
82  update.referencedTime = timestamp;
83  update.instancesData = {aronDto.toAron()};
84 
85  commit.add(update);
86 
87  return true;
88  }
89 
90 
91  bool
92  Writer::storePrepare(const local_planning::LocalPlannerResult& result,
93  const std::string& clientID,
94  armem::Commit& commit)
95  {
96  // FIXME timestamp should be part of GlobalPlannerResult
97  armem::Time timestamp = armem::Time::Now();
98 
100  update.entityID = armem::MemoryID()
103  .withProviderSegmentName(clientID)
104  .withEntityName("trajectory")
105  .withTimestamp(timestamp);
106 
107 
108  core::arondto::LocalTrajectory aronDto;
109  // FIXME create Aron type
110  toAron(aronDto, result.trajectory);
111 
112  update.referencedTime = timestamp;
113  update.instancesData = {aronDto.toAron()};
114 
115  commit.add(update);
116 
117  return true;
118  }
119 
120 
121  std::string
123  {
124  return "mem.nav.stack_result.";
125  }
126 
129  {
130  return Properties{
131  .memoryName = "Navigation",
132  .coreSegmentName = "", // here we use multiple
133  .providerName = "" // must be set by user
134  };
135  }
136 
137 } // namespace armarx::navigation::memory::client::stack_result
armarx::navigation::server::StackResult::globalPlan
global_planning::GlobalPlannerResult globalPlan
Definition: StackResult.h:42
armarx::armem::MemoryID::withMemoryName
MemoryID withMemoryName(const std::string &name) const
Definition: MemoryID.cpp:396
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:89
armarx::core::time::DateTime::Now
static DateTime Now()
Definition: DateTime.cpp:55
MemoryID.h
armarx::navigation::global_planning::GlobalPlannerResult::trajectory
core::GlobalTrajectory trajectory
Definition: GlobalPlanner.h:40
LocalPlanner.h
armarx::armem::client::util::SimpleWriterBase::Properties
Definition: SimpleWriterBase.h:49
armarx::navigation::memory::client::stack_result
This file is part of ArmarX.
Definition: Reader.cpp:8
armarx::navigation::core::toAron
void toAron(arondto::GlobalTrajectoryPoint &dto, const GlobalTrajectoryPoint &bo)
Definition: aron_conversions.cpp:18
armarx::armem::MemoryID::withProviderSegmentName
MemoryID withProviderSegmentName(const std::string &name) const
Definition: MemoryID.cpp:412
armarx::armem::client::util::SimpleWriterBase::memoryWriter
armem::client::Writer & memoryWriter()
Definition: SimpleWriterBase.cpp:51
armarx::armem::MemoryID::withCoreSegmentName
MemoryID withCoreSegmentName(const std::string &name) const
Definition: MemoryID.cpp:404
armarx::navigation::server::StackResult::localTrajectory
local_planning::LocalPlannerResult localTrajectory
Definition: StackResult.h:43
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::CommitResult
Result of a Commit.
Definition: Commit.h:110
armarx::armem::client::Writer::commit
CommitResult commit(const Commit &commit) const
Writes a Commit to the memory.
Definition: Writer.cpp:59
armarx::navigation::memory::client::stack_result::Writer::propertyPrefix
std::string propertyPrefix() const override
Definition: Writer.cpp:122
ARMARX_ERROR
#define ARMARX_ERROR
Definition: Logging.h:189
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:67
Commit.h
armarx::navigation::memory::client::stack_result::Writer::store
bool store(const server::StackResult &result, const std::string &clientID)
Definition: Writer.cpp:16
armarx::navigation::memory::client::stack_result::Writer::defaultProperties
Properties defaultProperties() const override
Definition: Writer.cpp:128
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:420
armarx::armem::Commit::add
EntityUpdate & add()
Definition: Commit.cpp:81
armarx::navigation::memory::toAron
void toAron(arondto::Circle &dto, const Circle &bo)
Definition: aron_conversions.cpp:29
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:38
armarx::armem::client::util::SimpleWriterBase::properties
const Properties & properties() const
Definition: SimpleWriterBase.cpp:57
Time.h
armarx::armem::MemoryID::withTimestamp
MemoryID withTimestamp(Time time) const
Definition: MemoryID.cpp:428
Writer.h
constants.h
armarx::navigation::memory::constants::LocalPlannerResultCoreSegment
const std::string LocalPlannerResultCoreSegment
Definition: constants.h:39
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:37
armarx::human::MemoryID
const armem::MemoryID MemoryID
Definition: memory_ids.cpp:29