DMPComponent.h
Go to the documentation of this file.
1/*
2 * This file is part of ArmarX.
3 *
4 * Copyright (C) 2015-2016, High Performance Humanoid Technologies (H2T), Karlsruhe Institute of Technology (KIT), all rights reserved.
5 *
6 * ArmarX is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation.
9 *
10 * ArmarX is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 *
18 * @package RobotAPI::ArmarXObjects::DMPComponent
19 * @author Mirko Waechter ( mirko dot waechter at kit dot edu )
20 * @date 2015
21 * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
22 * GNU General Public License
23 */
24
25#pragma once
26
27
28#include <boost/archive/binary_iarchive.hpp>
29#include <boost/archive/binary_oarchive.hpp>
30#include <boost/archive/text_iarchive.hpp>
31#include <boost/archive/text_oarchive.hpp>
32#include <boost/archive/xml_iarchive.hpp>
33#include <boost/archive/xml_oarchive.hpp>
34#include <boost/variant/get.hpp>
35#include <boost/variant/variant.hpp>
36
37#include <RobotComponents/interface/components/DMPComponentBase.h>
38
39#include <MemoryX/interface/components/LongtermMemoryInterface.h>
40#include <MemoryX/interface/components/WorkingMemoryInterface.h>
41#include <MemoryX/interface/memorytypes/MemoryEntities.h>
42#include <MemoryX/interface/memorytypes/MemorySegments.h>
44
45
46#pragma GCC diagnostic ignored "-Wunknown-pragmas"
47#pragma GCC diagnostic ignored "-Wunused-but-set-variable"
48#include <dmp/representation/dmp/dmpregistration.h>
49#include <dmp/representation/dmpfactory.h>
50#pragma GCC diagnostic pop
51#pragma GCC diagnostic pop
52
53#include <filesystem>
54
56//#include "dmp/representation/dmp/dmpinterface.h"
57//#include "dmp/representation/dmp/basicdmp.h"
58//#include "dmp/representation/dmp/dmp3rdorder.h"
59//#include "dmp/representation/dmp/quaterniondmp.h"
60//#include "dmp/representation/dmp/endvelodmp.h"
61//#include "dmp/representation/dmp/dmp3rdorderforcefield.h"
62//#include "dmp/representation/dmp/forcefielddmp.h"
63//#include "dmp/representation/dmp/adaptive3rdorderdmp.h"
64//#include "dmp/representation/dmp/simpleendvelodmp.h"
65////#include "dmp/representation/dmp/endveloforcefielddmp.h"
66////#include "dmp/representation/dmp/endveloforcefieldwithobjrepulsiondmp.h"
67//#include "dmp/representation/dmp/periodictransientdmp.h"
68
69#include "DMPInstance.h"
70
71namespace armarx
72{
73 /**
74 * @class DMPComponentPropertyDefinitions
75 * @brief
76 */
77
78
80 {
81 public:
84 {
85 // defineRequiredProperty<std::string>("LongtermMemoryName", "Description");
87 "LongtermMemoryName", "LongtermMemory", "Name of the LongtermMemory component");
88 }
89 };
90
91 /**
92 * @defgroup Component-DMPComponent DMPComponent
93 * @ingroup RobotComponents-Components
94 * @brief A brief description
95 *
96 *
97 * Detailed Description
98 */
99
100 using DMPInstancePair = std::pair<DMPInstancePtr, DMPInstanceBasePrx>;
101 using DMPPair = std::pair<std::string, std::pair<DMPInstancePtr, DMPInstanceBasePrx>>;
102 using DMPMap = std::map<std::string, std::pair<DMPInstancePtr, DMPInstanceBasePrx>>;
103
104 /**
105 * @ingroup Component-DMPComponent
106 * @brief The DMPComponent class
107 */
108 class DMPComponent : virtual public Component, virtual public DMPComponentBase
109 {
110 public:
111 DMPComponent() : ctime(0.0), timestep(0.001)
112 {
113 }
114
115 /**
116 * @see armarx::ManagedIceObject::getDefaultName()
117 */
118 std::string
119 getDefaultName() const override
120 {
121 return "DMPComponent";
122 }
123
124 /**
125 * @see PropertyUser::createPropertyDefinitions()
126 */
133
134 DMPInstanceBasePrx getDMP(const std::string& dmpName,
135 const Ice::Current& = Ice::emptyCurrent) override;
136
137 // DMP Database related
138 DMPInstanceBasePrx getDMPFromDatabase(const std::string& dmpEntityName,
139 const std::string& dmpName = "UNKNOWN",
140 const Ice::Current& = Ice::emptyCurrent) override;
141 DMPInstanceBasePrx getDMPFromDatabaseById(const std::string& dbId,
142 const Ice::Current&) override;
143 DMPInstanceBasePrx getDMPFromFile(const std::string& fileName,
144 const std::string& dmpName = "UNKNOWN",
145 const Ice::Current& = Ice::emptyCurrent) override;
146
147 void storeDMPInFile(const std::string& fileName,
148 const std::string& dmpName,
149 const Ice::Current&) override;
150 void storeDMPInDatabase(const std::string& dmpName,
151 const std::string& name,
152 const ::Ice::Current& = Ice::emptyCurrent) override;
153 void removeDMPFromDatabase(const std::string& name,
154 const ::Ice::Current& = Ice::emptyCurrent) override;
155 void removeDMPFromDatabaseById(const std::string& dbId, const Ice::Current&) override;
156
157
158 //transmit data from client to server (using ice)
159 DMPInstanceBasePrx instantiateDMP(const std::string& dmpName,
160 const std::string& DMPType,
161 int kernelSize,
162 const ::Ice::Current& = Ice::emptyCurrent) override;
163
164 void setDMPState(const std::string& dmpName,
165 const ::armarx::cStateVec& state,
166 const ::Ice::Current& = Ice::emptyCurrent) override;
167 void setGoal(const std::string& dmpName,
168 const Ice::DoubleSeq& value,
169 const Ice::Current& = Ice::emptyCurrent) override;
170 void setStartPosition(const std::string& dmpName,
171 const Ice::DoubleSeq& value,
172 const Ice::Current& = Ice::emptyCurrent) override;
173 void setCanonicalValues(const std::string& dmpName,
174 const Ice::DoubleSeq& value,
175 const Ice::Current& = Ice::emptyCurrent) override;
176
177 void readTrajectoryFromFile(const std::string& dmpName,
178 const std::string& file,
179 double times = 1,
180 const ::Ice::Current& = Ice::emptyCurrent) override;
181
182 void trainDMP(const std::string& dmpName,
183 const ::Ice::Current& = Ice::emptyCurrent) override;
184 void setAmpl(const std::string& dmpName,
185 int dim,
186 double value,
187 const ::Ice::Current& = Ice::emptyCurrent) override;
188 double getAmpl(const std::string& dmpName,
189 int dim,
190 const ::Ice::Current& = Ice::emptyCurrent) override;
191
192
193 double getTemporalFactor(const std::string& dmpName,
194 const ::Ice::Current& = Ice::emptyCurrent) override;
195 void setTemporalFactor(const std::string& dmpName,
196 double tau,
197 const ::Ice::Current& = Ice::emptyCurrent) override;
198
199
200 Vec2D calcTrajectory(const std::string& dmpName,
201 double startTime,
202 double timeStep,
203 double endTime,
204 const ::Ice::DoubleSeq& goal,
205 const cStateVec& states,
206 const ::Ice::DoubleSeq& canonicalValues,
207 double temporalFactor,
208 const ::Ice::Current& = Ice::emptyCurrent) override;
209
210 // time manager
211 double
212 getTimeStep(const ::Ice::Current& = Ice::emptyCurrent) override
213 {
214 return timestep;
215 }
216
217 void setTimeStep(double ts, const ::Ice::Current& = Ice::emptyCurrent) override;
218
219 double getCurrentTime(const ::Ice::Current& = Ice::emptyCurrent) override;
220
221 void resetTime(const ::Ice::Current& = Ice::emptyCurrent) override;
222
223 void resetCanonicalValues(const ::Ice::Current& = Ice::emptyCurrent) override;
224
225
226 double getDampingFactor(const std::string& dmpName,
227 const ::Ice::Current& = Ice::emptyCurrent) override;
228
229 double getSpringFactor(const std::string& dmpName,
230 const ::Ice::Current& = Ice::emptyCurrent) override;
231
232 double getForceTerm(const std::string& dmpName,
233 const Ice::DoubleSeq& canonicalValues,
234 int dim,
235 const Ice::Current& = Ice::emptyCurrent) override;
236
237 //transmit data from server to client (using ice)
238 cStateVec getNextState(const std::string& dmpName,
239 const cStateVec& states,
240 const ::Ice::Current& = Ice::emptyCurrent) override;
241 cStateVec getCurrentState(const std::string& dmpName,
242 const ::Ice::Current& = Ice::emptyCurrent) override;
243 Ice::DoubleSeq getCanonicalValues(const std::string& dmpName,
244 const ::Ice::Current& = Ice::emptyCurrent) override;
245 Ice::DoubleSeq getTrajGoal(const std::string& dmpName,
246 const ::Ice::Current& = Ice::emptyCurrent) override;
247 ::armarx::cStateVec getTrajStartState(const std::string& dmpName,
248 const ::Ice::Current& = Ice::emptyCurrent) override;
249
250 std::string getDMPType(const std::string& dmpName,
251 const ::Ice::Current& = Ice::emptyCurrent) override;
252
253 Ice::DoubleSeq getStartPosition(const std::string& dmpName,
254 const ::Ice::Current& = Ice::emptyCurrent) override;
255
256 SVector getDMPNameList(const ::Ice::Current& = Ice::emptyCurrent) override;
257
258 void eraseDMP(const std::string& dmpName,
259 const ::Ice::Current& = Ice::emptyCurrent) override;
260 bool isDMPExist(const std::string& dmpName,
261 const ::Ice::Current& = Ice::emptyCurrent) override;
262 int getDMPDim(const std::string& dmpName,
263 const ::Ice::Current& = Ice::emptyCurrent) override;
264
265
266 double ctime;
267 double timestep;
268 std::vector<int> usedDimensions;
269
270 private:
271 DMPInstanceBasePrx findInstancePrx(std::string name);
272 DMPInstancePtr findInstancePtr(std::string name);
273 DMPInstanceBasePrx createDMPInstancePrx(DMPInstancePtr dmpPtr);
274
275 protected:
277
278 memoryx::LongtermMemoryInterfacePrx longtermMemoryPrx;
279 memoryx::PersistentDMPDataSegmentBasePrx dmpDataMemoryPrx;
280
281 /**
282 * @see armarx::ManagedIceObject::onInitComponent()
283 */
284 void onInitComponent() override;
285
286 /**
287 * @see armarx::ManagedIceObject::onConnectComponent()
288 */
289 void onConnectComponent() override;
290
291 /**
292 * @see armarx::ManagedIceObject::onDisconnectComponent()
293 */
294 void onDisconnectComponent() override;
295
296 /**
297 * @see armarx::ManagedIceObject::onExitComponent()
298 */
299 void onExitComponent() override;
300
301 /**
302 * @see PropertyUser::createPropertyDefinitions()
303 */
304 // virtual armarx::PropertyDefinitionsPtr createPropertyDefinitions();
305 };
306
308} // namespace armarx
Default component property definition container.
Definition Component.h:70
ComponentPropertyDefinitions(std::string prefix, bool hasObjectNameParameter=true)
Definition Component.cpp:46
Component()
Protected default constructor. Used for virtual inheritance. Use createManagedIceObject() instead.
Definition Component.cpp:66
std::string getConfigIdentifier()
Retrieve config identifier for this component as set in constructor.
Definition Component.cpp:90
DMPComponentPropertyDefinitions(std::string prefix)
memoryx::LongtermMemoryInterfacePrx longtermMemoryPrx
void setAmpl(const std::string &dmpName, int dim, double value, const ::Ice::Current &=Ice::emptyCurrent) override
void onInitComponent() override
cStateVec getNextState(const std::string &dmpName, const cStateVec &states, const ::Ice::Current &=Ice::emptyCurrent) override
cStateVec getCurrentState(const std::string &dmpName, const ::Ice::Current &=Ice::emptyCurrent) override
std::vector< int > usedDimensions
double getCurrentTime(const ::Ice::Current &=Ice::emptyCurrent) override
double getSpringFactor(const std::string &dmpName, const ::Ice::Current &=Ice::emptyCurrent) override
void setTemporalFactor(const std::string &dmpName, double tau, const ::Ice::Current &=Ice::emptyCurrent) override
DMPInstanceBasePrx getDMPFromFile(const std::string &fileName, const std::string &dmpName="UNKNOWN", const Ice::Current &=Ice::emptyCurrent) override
Ice::DoubleSeq getStartPosition(const std::string &dmpName, const ::Ice::Current &=Ice::emptyCurrent) override
DMPInstanceBasePrx getDMP(const std::string &dmpName, const Ice::Current &=Ice::emptyCurrent) override
void onDisconnectComponent() override
double getForceTerm(const std::string &dmpName, const Ice::DoubleSeq &canonicalValues, int dim, const Ice::Current &=Ice::emptyCurrent) override
void removeDMPFromDatabaseById(const std::string &dbId, const Ice::Current &) override
void removeDMPFromDatabase(const std::string &name, const ::Ice::Current &=Ice::emptyCurrent) override
int getDMPDim(const std::string &dmpName, const ::Ice::Current &=Ice::emptyCurrent) override
double getTemporalFactor(const std::string &dmpName, const ::Ice::Current &=Ice::emptyCurrent) override
double getAmpl(const std::string &dmpName, int dim, const ::Ice::Current &=Ice::emptyCurrent) override
void setTimeStep(double ts, const ::Ice::Current &=Ice::emptyCurrent) override
void setGoal(const std::string &dmpName, const Ice::DoubleSeq &value, const Ice::Current &=Ice::emptyCurrent) override
armarx::PropertyDefinitionsPtr createPropertyDefinitions() override
DMPInstanceBasePrx getDMPFromDatabase(const std::string &dmpEntityName, const std::string &dmpName="UNKNOWN", const Ice::Current &=Ice::emptyCurrent) override
void setStartPosition(const std::string &dmpName, const Ice::DoubleSeq &value, const Ice::Current &=Ice::emptyCurrent) override
DMPInstanceBasePrx getDMPFromDatabaseById(const std::string &dbId, const Ice::Current &) override
double getDampingFactor(const std::string &dmpName, const ::Ice::Current &=Ice::emptyCurrent) override
bool isDMPExist(const std::string &dmpName, const ::Ice::Current &=Ice::emptyCurrent) override
::armarx::cStateVec getTrajStartState(const std::string &dmpName, const ::Ice::Current &=Ice::emptyCurrent) override
void setCanonicalValues(const std::string &dmpName, const Ice::DoubleSeq &value, const Ice::Current &=Ice::emptyCurrent) override
void resetTime(const ::Ice::Current &=Ice::emptyCurrent) override
Vec2D calcTrajectory(const std::string &dmpName, double startTime, double timeStep, double endTime, const ::Ice::DoubleSeq &goal, const cStateVec &states, const ::Ice::DoubleSeq &canonicalValues, double temporalFactor, const ::Ice::Current &=Ice::emptyCurrent) override
void resetCanonicalValues(const ::Ice::Current &=Ice::emptyCurrent) override
Ice::DoubleSeq getTrajGoal(const std::string &dmpName, const ::Ice::Current &=Ice::emptyCurrent) override
DMPInstanceBasePrx instantiateDMP(const std::string &dmpName, const std::string &DMPType, int kernelSize, const ::Ice::Current &=Ice::emptyCurrent) override
std::string getDMPType(const std::string &dmpName, const ::Ice::Current &=Ice::emptyCurrent) override
void onConnectComponent() override
void trainDMP(const std::string &dmpName, const ::Ice::Current &=Ice::emptyCurrent) override
void readTrajectoryFromFile(const std::string &dmpName, const std::string &file, double times=1, const ::Ice::Current &=Ice::emptyCurrent) override
void eraseDMP(const std::string &dmpName, const ::Ice::Current &=Ice::emptyCurrent) override
void storeDMPInFile(const std::string &fileName, const std::string &dmpName, const Ice::Current &) override
Ice::DoubleSeq getCanonicalValues(const std::string &dmpName, const ::Ice::Current &=Ice::emptyCurrent) override
void onExitComponent() override
memoryx::PersistentDMPDataSegmentBasePrx dmpDataMemoryPrx
SVector getDMPNameList(const ::Ice::Current &=Ice::emptyCurrent) override
void storeDMPInDatabase(const std::string &dmpName, const std::string &name, const ::Ice::Current &=Ice::emptyCurrent) override
void setDMPState(const std::string &dmpName, const ::armarx::cStateVec &state, const ::Ice::Current &=Ice::emptyCurrent) override
double getTimeStep(const ::Ice::Current &=Ice::emptyCurrent) override
std::string getDefaultName() const override
std::string prefix
Prefix of the properties such as namespace, domain, component name, etc.
PropertyDefinition< PropertyType > & defineOptionalProperty(const std::string &name, PropertyType defaultValue, const std::string &description="", PropertyDefinitionBase::PropertyConstness constness=PropertyDefinitionBase::eConstant)
This file offers overloads of toIce() and fromIce() functions for STL container types.
std::map< std::string, std::pair< DMPInstancePtr, DMPInstanceBasePrx > > DMPMap
IceUtil::Handle< class PropertyDefinitionContainer > PropertyDefinitionsPtr
PropertyDefinitions smart pointer type.
::IceInternal::Handle<::armarx::DMPComponent > DMPComponentPtr
std::pair< std::string, std::pair< DMPInstancePtr, DMPInstanceBasePrx > > DMPPair
IceInternal::Handle< DMPInstance > DMPInstancePtr
std::pair< DMPInstancePtr, DMPInstanceBasePrx > DMPInstancePair