MotionSegment.cpp
Go to the documentation of this file.
1 // BaseClass
2 #include "MotionSegment.h"
3 
4 // ArmarX
5 #include "mdb_conversions.h"
6 
11 
14 
15 // STD / STL
16 #include <iostream>
17 #include <fstream>
18 #include <sstream>
19 
20 
22 {
24  Base(memoryToIceAdapter, "MotionDatabase", "Motion", armarx::motion::mdb::arondto::MDBReference::ToAronType())
25  {
26  }
27 
29  {
30  Base::defineProperties(defs, prefix);
31 
32  defs->optional(properties.motionsPackage, prefix + "MotionsPackage", "Name of the prior knowledge package to load from.");
33  defs->optional(properties.loadFromMotionsPackage, prefix + "LoadFromMotionsPackage", "If true, load the motions from the motions package on startup.");
34  }
35 
37  {
38  Base::init();
39 
40  if (properties.loadFromMotionsPackage)
41  {
42  loadByMotionFinder(properties.motionsPackage);
43  }
44  }
45 
47  {
48 
49  }
50 
51  int MDBMotionSegment::loadByMotionFinder(const std::string& packageName)
52  {
53  priorknowledge::motions::MotionFinder motionFinder(packageName, "motions/");
54  int loadedMotions = 0;
55 
56  ARMARX_INFO << "Load Motions from package" << std::endl;
57  {
58  // Load MDB Motions
59  auto allMotions = motionFinder.findAll("mdb");
60  for (const auto& motionFinderInfo : allMotions)
61  {
62  auto pathToInfoJson = motionFinderInfo.getFullPath() / motionFinderInfo.getID() / (motionFinderInfo.getID() + ".json");
63  if (auto op = conversion::createFromFile(pathToInfoJson); op.has_value())
64  {
65  std::stringstream ss;
66  ss << "Found valid instance at: " << pathToInfoJson << ". The motionID is: ";
67  for (const auto& [key, attachedFiles] : op->attachedFiles)
68  {
69  for (const auto& attachedFile : attachedFiles)
70  {
71  ss << "\n" << attachedFile.fileName << " (" << key << ")";
72  }
73  }
74  ARMARX_INFO << ss.str(); // ToDo @Fabian PK: Remove
75  auto& entity = this->segmentPtr->addEntity(std::to_string(op->id));
76  auto& snapshot = entity.addSnapshot(op->createdDate);
77 
78  armem::wm::EntityInstance& instance = snapshot.addInstance();
79  instance.metadata().referencedTime = op->createdDate;
80  instance.metadata().sentTime = Time::Now();
81  instance.metadata().arrivedTime = Time::Now();
82  instance.metadata().confidence = 1.0;
83  instance.data() = op->toAron();
84  }
85  else
86  {
87  ARMARX_WARNING << "Found an invalid path to a motion file: " << pathToInfoJson;
88  }
89  }
90 
91  loadedMotions += allMotions.size();
92  }
93 
94  return loadedMotions;
95  }
96 }
MotionFinder.h
armarx::armem::server::motions::mdb::segment::MDBMotionSegment::onConnect
virtual void onConnect()
Definition: MotionSegment.cpp:46
MotionSegment.h
armarx::armem::server::motions::mdb::segment::MDBMotionSegment::defineProperties
virtual void defineProperties(armarx::PropertyDefinitionsPtr defs, const std::string &prefix="") override
Definition: MotionSegment.cpp:28
armarx::armem::wm::EntityInstance
Client-side working entity instance.
Definition: memory_definitions.h:32
armarx::armem::server::MemoryToIceAdapter
Helps connecting a Memory server to the Ice interface.
Definition: MemoryToIceAdapter.h:19
armarx::core::time::DateTime::Now
static DateTime Now()
Definition: DateTime.cpp:55
armarx::armem::server::motions::mdb::conversion::createFromFile
std::optional< armarx::motion::mdb::arondto::MDBReference > createFromFile(const std::filesystem::path &pathToInfoJson)
Definition: mdb_conversions.cpp:9
mdb_conversions.h
armarx::armem::base::EntityBase::addSnapshot
EntitySnapshotT & addSnapshot(const Time &timestamp)
Add a snapshot at the given time.
Definition: EntityBase.h:629
memory_definitions.h
armarx::armem::server::segment::detail::SegmentBase< server::wm::ProviderSegment >::segmentPtr
server::wm::ProviderSegment * segmentPtr
Definition: SpecializedSegment.h:54
armarx::armem::base::EntityInstanceMetadata::sentTime
Time sentTime
Time when this value was sent to the memory.
Definition: EntityInstanceBase.h:49
armarx::armem::server::segment::detail::SegmentBase< server::wm::ProviderSegment >
armarx::armem::server::motions::mdb::segment
Definition: MotionSegment.cpp:21
armarx::armem::server::wm::ProviderSegment::addEntity
Entity & addEntity(const std::string &name, Args... args)
Definition: memory_definitions.h:74
armarx::armem::server::motions::mdb::segment::MDBMotionSegment::init
virtual void init() override
Definition: MotionSegment.cpp:36
armarx::priorknowledge::motions::MotionFinder
Definition: MotionFinder.h:7
armarx::armem::base::EntityInstanceMetadata::arrivedTime
Time arrivedTime
Time when this value has arrived at the memory.
Definition: EntityInstanceBase.h:51
armarx::armem::server::segment::SpecializedProviderSegment::init
virtual void init() override
Definition: SpecializedProviderSegment.cpp:56
armarx::to_string
const std::string & to_string(const std::string &s)
Definition: StringHelpers.h:40
memory_definitions.h
aron_conversions.h
armarx::armem::base::EntityInstanceMetadata::referencedTime
Time referencedTime
Time this instance refers to.
Definition: EntityInstanceBase.h:46
ARMARX_INFO
#define ARMARX_INFO
Definition: Logging.h:174
PropertyDefinitionContainer.h
IceUtil::Handle< class PropertyDefinitionContainer >
armarx::armem::server::motions::mdb::segment::MDBMotionSegment::MDBMotionSegment
MDBMotionSegment(armem::server::MemoryToIceAdapter &iceMemory)
Definition: MotionSegment.cpp:23
ProxyPropertyDefinition.h
armarx::armem::base::EntityInstanceMetadata::confidence
float confidence
An optional confidence, may be used for things like decay.
Definition: EntityInstanceBase.h:54
armarx::armem::base::EntityInstanceBase::metadata
MetadataT & metadata()
Definition: EntityInstanceBase.h:117
ARMARX_WARNING
#define ARMARX_WARNING
Definition: Logging.h:186
armarx::armem::base::EntityInstanceBase::data
const DataT & data() const
Definition: EntityInstanceBase.h:129
armarx::armem::server::segment::SpecializedProviderSegment::defineProperties
virtual void defineProperties(armarx::PropertyDefinitionsPtr defs, const std::string &prefix="") override
Definition: SpecializedProviderSegment.cpp:40
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:28