Segment.cpp
Go to the documentation of this file.
1 #include "Segment.h"
2 
3 #include <sstream>
4 
9 
12 
19 
20 #include <RobotAPI/libraries/armem_robot_state/aron/Robot.aron.generated.h>
22 #include <RobotAPI/libraries/armem_objects/aron/Attachment.aron.generated.h>
23 
24 
26 {
28  iceMemory(memoryToIceAdapter)
29  {
30  Logging::setTag("Attachments");
31  }
32 
33  Segment::~Segment() = default;
34 
35  void Segment::defineProperties(armarx::PropertyDefinitionsPtr defs, const std::string& prefix)
36  {
37  defs->optional(p.coreSegmentName, prefix + "CoreSegmentName", "Name of the object instance core segment.");
38  defs->optional(p.maxHistorySize, prefix + "MaxHistorySize", "Maximal size of object poses history (-1 for infinite).");
39  }
40 
42  {
44 
45  coreSegment = &iceMemory.workingMemory->addCoreSegment(p.coreSegmentName, arondto::Robot::ToAronType());
46  coreSegment->setMaxHistorySize(p.maxHistorySize);
47  }
48 
50  {
51  }
52 
53  std::vector<armarx::armem::attachment::ObjectAttachment>
54  Segment::getAttachments(const armem::Time& timestamp) const
55  {
56  ARMARX_CHECK_NOT_NULL(coreSegment);
57  return coreSegment->doLocked([this]()
58  {
59  std::vector<armarx::armem::attachment::ObjectAttachment> attachments;
60  coreSegment->forEachEntity([this, &attachments](const wm::Entity & entity)
61  {
62  const wm::EntityInstance& entityInstance = entity.getLatestSnapshot().getInstance(0);
63 
64  const auto aronAttachment = tryCast<armarx::armem::arondto::attachment::ObjectAttachment>(entityInstance);
65  if (not aronAttachment)
66  {
67  ARMARX_WARNING << "Could not convert entity instance to 'ObjectAttachment'";
68  return true;
69  }
70 
71  ARMARX_DEBUG << "Key is " << armem::MemoryID(entity.id());
72 
74  fromAron(*aronAttachment, attachment);
75 
76  attachments.push_back(attachment);
77  return true;
78  });
79 
80  return attachments;
81  });
82  }
83 
84 } // 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:46
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:27
query_fns.h
Segment.h
armarx::armem::server::wm::Entity
Definition: memory_definitions.h:30
armarx::armem::base::detail::ForEachEntityMixin::forEachEntity
bool forEachEntity(FunctionT &&func)
Definition: iteration_mixins.h:258
ARMARX_DEBUG
#define ARMARX_DEBUG
Definition: Logging.h:177
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:41
PluginAll.h
armarx::armem::base::detail::MemoryItem::id
MemoryID & id()
Definition: MemoryItem.h:27
armarx::armem::server::wm::CoreSegment::doLocked
auto doLocked(FunctionT &&function) const
Definition: memory_definitions.h:120
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:54
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:35
TimeUtil.h
armarx::armem::server::obj::attachments::Segment::connect
void connect()
Definition: Segment.cpp:49
PropertyDefinitionContainer.h
IceUtil::Handle< class PropertyDefinitionContainer >
Builder.h
util.h
armarx::Logging::setTag
void setTag(const LogTag &tag)
Definition: Logging.cpp:55
Logging.h
ARMARX_WARNING
#define ARMARX_WARNING
Definition: Logging.h:186
aron_conversions.h
armarx::armem::server::obj::attachments
Definition: Segment.cpp:25
armarx::human::MemoryID
const armem::MemoryID MemoryID
Definition: memory_ids.cpp:29