Segment.cpp
Go to the documentation of this file.
1#include "Segment.h"
2
3#include <sstream>
4
9
17#include <RobotAPI/libraries/armem_objects/aron/Attachment.aron.generated.h>
19#include <RobotAPI/libraries/armem_robot_state/aron/Robot.aron.generated.h>
21
23{
25 iceMemory(memoryToIceAdapter)
26 {
27 Logging::setTag("Attachments");
28 }
29
30 Segment::~Segment() = default;
31
32 void
34 {
35 defs->optional(p.coreSegmentName,
36 prefix + "CoreSegmentName",
37 "Name of the object instance core segment.");
38 defs->optional(p.maxHistorySize,
39 prefix + "MaxHistorySize",
40 "Maximal size of object poses history (-1 for infinite).");
41 }
42
43 void
45 {
46 ARMARX_CHECK_NOT_NULL(iceMemory.workingMemory);
47
48 coreSegment = &iceMemory.workingMemory->addCoreSegment(p.coreSegmentName,
49 arondto::Robot::ToAronType());
50 coreSegment->setMaxHistorySize(p.maxHistorySize);
51 }
52
53 void
55 {
56 }
57
58 std::vector<armarx::armem::attachment::ObjectAttachment>
60 {
61 ARMARX_CHECK_NOT_NULL(coreSegment);
62 return coreSegment->doLocked(
63 [this]()
64 {
65 std::vector<armarx::armem::attachment::ObjectAttachment> attachments;
66 coreSegment->forEachEntity(
67 [this, &attachments](const wm::Entity& entity)
68 {
69 const wm::EntityInstance& entityInstance =
70 entity.getLatestSnapshot().getInstance(0);
71
72 const auto aronAttachment =
74 entityInstance);
75 if (not aronAttachment)
76 {
78 << "Could not convert entity instance to 'ObjectAttachment'";
79 return true;
80 }
81
82 ARMARX_DEBUG << "Key is " << armem::MemoryID(entity.id());
83
85 fromAron(*aronAttachment, attachment);
86
87 attachments.push_back(attachment);
88 return true;
89 });
90
91 return attachments;
92 });
93 }
94
95} // namespace armarx::armem::server::obj::attachments
std::string timestamp()
void setTag(const LogTag &tag)
Definition Logging.cpp:54
Helps connecting a Memory server to the Ice interface.
std::vector< armarx::armem::attachment::ObjectAttachment > getAttachments(const armem::Time &timestamp) const
Definition Segment.cpp:59
Segment(server::MemoryToIceAdapter &iceMemory)
Definition Segment.cpp:24
void defineProperties(armarx::PropertyDefinitionsPtr defs, const std::string &prefix="")
Definition Segment.cpp:33
#define ARMARX_CHECK_NOT_NULL(ptr)
This macro evaluates whether ptr is not null and if it turns out to be false it will throw an Express...
#define ARMARX_DEBUG
The logging level for output that is only interesting while debugging.
Definition Logging.h:184
#define ARMARX_WARNING
The logging level for unexpected behaviour, but not a serious problem.
Definition Logging.h:193
armem::wm::EntityInstance EntityInstance
void fromAron(const arondto::MemoryID &dto, MemoryID &bo)
armarx::core::time::DateTime Time
std::optional< AronClass > tryCast(const wm::EntityInstance &item)
Tries to cast a armem::EntityInstance to AronClass.
Definition util.h:45
IceUtil::Handle< class PropertyDefinitionContainer > PropertyDefinitionsPtr
PropertyDefinitions smart pointer type.
ObjectAttachment describes a fixed transformation between an agent and an object.
Definition types.h:101
auto & getLatestSnapshot(int snapshotIndex=0)
Retrieve the latest entity snapshot.