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