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  {
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>
59  Segment::getAttachments(const armem::Time& timestamp) const
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 =
73  tryCast<armarx::armem::arondto::attachment::ObjectAttachment>(
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
armarx::armem::server::MemoryToIceAdapter::workingMemory
server::wm::Memory * workingMemory
Definition: MemoryToIceAdapter.h:65
armarx::armem::server::wm::detail::MaxHistorySizeParent::setMaxHistorySize
void setMaxHistorySize(long maxSize)
Sets the maximum history size of entities in this container.
Definition: MaxHistorySize.h:41
Writer.h
armarx::armem::attachment::ObjectAttachment
ObjectAttachment describes a fixed transformation between an agent and an object.
Definition: types.h:100
armarx::armem::wm::EntityInstance
Client-side working entity instance.
Definition: memory_definitions.h:32
armarx::armem::server::obj::attachments::Segment::~Segment
virtual ~Segment()
armarx::armem::server::MemoryToIceAdapter
Helps connecting a Memory server to the Ice interface.
Definition: MemoryToIceAdapter.h:19
armarx::armem::base::detail::GetLatestSnapshotMixin::getLatestSnapshot
auto & getLatestSnapshot(int snapshotIndex=0)
Retrieve the latest entity snapshot.
Definition: lookup_mixins.h:199
MemoryID.h
ARMARX_CHECK_NOT_NULL
#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...
Definition: ExpressionException.h:206
armarx::armem::server::obj::attachments::Segment::Segment
Segment(server::MemoryToIceAdapter &iceMemory)
Definition: Segment.cpp:24
query_fns.h
Segment.h
armarx::armem::server::wm::Entity
Definition: memory_definitions.h:27
armarx::armem::base::detail::ForEachEntityMixin::forEachEntity
bool forEachEntity(FunctionT &&func)
Definition: iteration_mixins.h:259
ARMARX_DEBUG
#define ARMARX_DEBUG
Definition: Logging.h:184
armarx::armem::base::MemoryBase::addCoreSegment
CoreSegmentT & addCoreSegment(const std::string &name, aron::type::ObjectPtr coreSegmentType=nullptr, const std::vector< PredictionEngine > &predictionEngines={})
Add an empty core segment with the given name, type and prediction engines.
Definition: MemoryBase.h:259
armarx::armem::server::obj::attachments::Segment::init
void init()
Definition: Segment.cpp:44
PluginAll.h
armarx::armem::base::detail::MemoryItem::id
MemoryID & id()
Definition: MemoryItem.h:25
armarx::armem::server::wm::CoreSegment::doLocked
auto doLocked(FunctionT &&function) const
Definition: memory_definitions.h:110
aron_conversions.h
MemoryToIceAdapter.h
aron_conversions.h
armarx::armem::server::obj::attachments::Segment::getAttachments
std::vector< armarx::armem::attachment::ObjectAttachment > getAttachments(const armem::Time &timestamp) const
Definition: Segment.cpp:59
armarx::core::time::DateTime
Represents a point in time.
Definition: DateTime.h:24
armarx::armem::fromAron
void fromAron(const arondto::MemoryID &dto, MemoryID &bo)
Definition: aron_conversions.cpp:8
armarx::armem::server::obj::attachments::Segment::defineProperties
void defineProperties(armarx::PropertyDefinitionsPtr defs, const std::string &prefix="")
Definition: Segment.cpp:33
TimeUtil.h
armarx::armem::server::obj::attachments::Segment::connect
void connect()
Definition: Segment.cpp:54
PropertyDefinitionContainer.h
IceUtil::Handle< class PropertyDefinitionContainer >
Builder.h
util.h
armarx::Logging::setTag
void setTag(const LogTag &tag)
Definition: Logging.cpp:54
Logging.h
ARMARX_WARNING
#define ARMARX_WARNING
Definition: Logging.h:193
aron_conversions.h
armarx::armem::server::obj::attachments
Definition: Segment.cpp:22
armarx::human::MemoryID
const armem::MemoryID MemoryID
Definition: memory_ids.cpp:28