KBMComponent.h
Go to the documentation of this file.
1/*
2 * This file is part of ArmarX.
3 *
4 * Copyright (C) 2012-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 MemoryX::ArmarXObjects::KBMComponent
19 * @author Jonas Rauber ( kit at jonasrauber dot de )
20 * @date 2014
21 * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
22 * GNU General Public License
23 */
24
25#pragma once
26
29
30#include <MemoryX/interface/components/KBMComponentInterface.h>
31#include <MemoryX/interface/components/LongtermMemoryInterface.h>
32
33/*
34 * using these #define's here isn't nice, but it works
35 */
36//#define KBM_NO_ARMAR_X
37//#define KBM_USE_SINGLE_PRECISION
38#include <cfloat>
39
41
43
44namespace armarx
45{
46 /**
47 * @class KBMComponentPropertyDefinitions
48 * @brief
49 */
51 {
52 public:
54 {
56 "LongtermMemoryName",
57 "LongtermMemory",
58 "Name of the LongtermMemory component that should be used");
60 "RobotStateComponentName",
61 "RobotStateComponent",
62 "Name of the robot state component that should be used");
63 }
64 };
65} // namespace armarx
66
68{
69 /**
70 * @brief calculateJointDeltas is in internal function called by solve
71 */
73 const memoryx::KBM::Vector& target,
74 const memoryx::KBM::Vector& position,
75 const memoryx::KBM::Vector& proprioception,
76 float stepSizeFactor,
77 float maxStepSize);
78
79 /**
80 * @brief randomFloat creates a random float between LO and HI
81 */
82 float randomFloat(float LO, float HI);
83
84 /**
85 * @brief Creates a vector of random values between the limits
86 */
88 randomProprioception(const memoryx::KBM::Vector& lowerProprioceptionLimits,
89 const memoryx::KBM::Vector& upperProprioceptionLimits);
90
91 /**
92 * @brief check if solution is within the limits
93 */
95 const memoryx::KBM::Vector& lowerProprioceptionLimits,
96 const memoryx::KBM::Vector& upperProprioceptionLimits);
97
98 /**
99 * @brief apply limits to solution and return true,
100 * if solution has been changed = solution was not in limits
101 */
102 bool applyProprioceptionLimits(Eigen::Map<memoryx::KBM::Vector>& solution,
103 const memoryx::KBM::Vector& lowerProprioceptionLimits,
104 const memoryx::KBM::Vector& upperProprioceptionLimits);
105
106 /**
107 * @brief KBMDifferentialIK::solveMany runs solve many times
108 * @param kbm
109 * @param targetPosition
110 * @param currentProprioception
111 * @param lowerProprioceptionLimits
112 * @param upperProprioceptionLimits
113 * @param solution
114 * @param maxSolves maximum number of times solve() should be called
115 * @param positionTolerance
116 * @param minimumDelta
117 * @param requireImprovment
118 * @param maxSteps
119 * @param stepSizeFactor
120 * @param maxStepSize
121 * @return
122 */
123 bool solveMany(const memoryx::KBM::Models::KBM& kbm,
124 const memoryx::KBM::Vector& targetPosition,
125 const memoryx::KBM::Vector& currentPosition,
126 const memoryx::KBM::Vector& currentProprioception,
127 const memoryx::KBM::Vector& lowerProprioceptionLimits,
128 const memoryx::KBM::Vector& upperProprioceptionLimits,
129 Eigen::Map<memoryx::KBM::Vector>& solution,
130 bool applyLimits = true,
131 int maxSolves = 25,
132 float positionTolerance = 5.0f,
133 float minimumDelta = 0.0f,
134 bool requireImprovment = false,
135 int maxSteps = 50,
136 float stepSizeFactor = 0.2f,
137 float maxStepSize = FLT_MAX);
138
139 /**
140 * @brief solves the inverse kinematics
141 * @param kbm: the learned KBM
142 * @param targetPosition: the target position
143 * @param currentPosition: the current position
144 * @param currentProprioception: the current proprioception
145 * @param solution: will contain the joint values that solve the inverse kinematics
146 * @return true, if a good approximation has been found, false otherwise
147 */
148 bool solve(const memoryx::KBM::Models::KBM& kbm,
149 const memoryx::KBM::Vector& targetPosition,
150 const memoryx::KBM::Vector& currentPostion,
151 const memoryx::KBM::Vector& currentProprioception,
152 Eigen::Map<memoryx::KBM::Vector>& solution,
153 float positionTolerance = 5.0f,
154 float minimumDelta = 0.0f,
155 bool requireImprovment = false,
156 int maxSteps = 50,
157 float stepSizeFactor = 0.2f,
158 float maxStepSize = FLT_MAX);
159} // namespace armarx::KBMDifferentialIK
160
161namespace armarx
162{
163 /**
164 * @class KBMComponent
165 * @ingroup Memoryx-Components
166 * @brief Wrapper for the KBM class
167 */
168 class KBMComponent : virtual public armarx::Component, virtual public KBMComponentInterface
169 {
170 public:
171 /**
172 * @see armarx::ManagedIceObject::getDefaultName()
173 */
174 std::string
175 getDefaultName() const override
176 {
177 return "KBMComponent";
178 }
179
180 static std::string GetDefaultName();
181
182 /**
183 * @brief createKBM creates a new KBM and makes it available under the given name
184 * @param name the name of the KBM
185 * @param nDoF degrees of freedom
186 * @param dim dimensions
187 * @param spreadAngle the common spreadAngle for joints
188 */
189 void createKBM(const std::string& name,
190 Ice::Int nDoF,
191 Ice::Int dim,
192 Ice::Float spreadAngle,
193 const Ice::Current& c = Ice::emptyCurrent) override;
194
195 /**
196 * @brief createArmar3KBM creates a KBM from a VirtualRobot model
197 * @param name the KBM will be available under this name
198 * @param activeJoints the names of the joints that are used
199 * @param tcpName name of the joint that corresponds best to the tool center point
200 * @param useOrientation use only the position (3 dimensions) or position and orientation (9 dimensions in total)
201 */
202 void createArmar3KBM(const std::string& name,
203 const Ice::StringSeq& robotNodeNames,
204 const std::vector<memoryx::KBM::Real>& jointValueAverages,
205 const std::vector<memoryx::KBM::Real>& spreadAnglesSequence,
206 const std::string& tcpName,
207 bool useOrientation,
208 const Ice::Current& c = Ice::emptyCurrent) override;
209
210 /**
211 * @brief batch learning of n training samples
212 * @param name the name of the KBM
213 * @param proprioception length must be DoF * n
214 * @param position length must be Dim * n
215 * @param method will be mapped to the Enum in the KBM class, currently 0 = STANDARD, 1 = PLS
216 * @param threshold should equal the expected mean positioning error
217 */
218 void batch(const std::string& name,
219 const std::vector<memoryx::KBM::Real>& proprioceptionSequence,
220 const std::vector<memoryx::KBM::Real>& positionSequence,
221 Ice::Int method,
222 Ice::Float threshold,
223 const Ice::Current& c = Ice::emptyCurrent) override;
224
225 /**
226 * @brief online learning of n training samples
227 * @param name the name of the KBM
228 * @param proprioception length must be DoF * n
229 * @param position length must be Dim * n
230 * @param learnRate learning rate between 0 and 1
231 */
232 void online(const std::string& name,
233 const std::vector<memoryx::KBM::Real>& proprioceptionSequence,
234 const std::vector<memoryx::KBM::Real>& positionSequence,
235 Ice::Float learningRate,
236 const Ice::Current& c = Ice::emptyCurrent) override;
237
238 /**
239 * @brief same as online, but evaluates after each learning iteration
240 * @param name the name of the KBM
241 * @param proprioception length must be DoF * n
242 * @param position length must be Dim * n
243 * @param learnRate learning rate between 0 and 1
244 */
245 void onlineVerbose(const std::string& name,
246 const std::vector<memoryx::KBM::Real>& proprioceptionSequence,
247 const std::vector<memoryx::KBM::Real>& positionSequence,
248 Ice::Float learningRate,
249 const std::vector<memoryx::KBM::Real>& evaluationProprioceptionSequence,
250 const std::vector<memoryx::KBM::Real>& evaluationPositionSequence,
251 const Ice::Current& c = Ice::emptyCurrent) override;
252
253 /**
254 * @brief predict the position for n samples of proprioception (forward kinematics)
255 * @param name the name of the KBM
256 * @param proprioception length must be DoF * n
257 * @return the predicted position with length Dim * n
258 */
259 std::vector<memoryx::KBM::Real>
260 predict(const std::string& name,
261 const std::vector<memoryx::KBM::Real>& proprioceptionSequence,
262 const Ice::Current& c = Ice::emptyCurrent) override;
263
264 /**
265 * @brief calls getErrors on the KBM and prints the result
266 * @param name the name of the KBM
267 * @param proprioception the proprioception to pass to getErrors
268 * @param position the position to pass to getErrors
269 */
270 void printErrors(const std::string& name,
271 const std::vector<memoryx::KBM::Real>& proprioceptionSequence,
272 const std::vector<memoryx::KBM::Real>& positionSequence,
273 const Ice::Current& c = Ice::emptyCurrent) override;
274
275 /**
276 * @brief printAccumulatorStatistics prints information about the values in the accumulators
277 */
278 void printAccumulatorStatistics(int nDim,
279 int nDoF,
280 const Ice::Current& c = Ice::emptyCurrent) override;
281
282 /**
283 * @brief accumulate adds the given position to the accumulator to use it later
284 * @param position length must be Dim * n
285 */
286 void accumulatePositions(const std::vector<memoryx::KBM::Real>& positionSequence,
287 const Ice::Current& c = Ice::emptyCurrent) override;
288
289 /**
290 * @brief accumulates the given position in the evaluation accumulator
291 * @param position length must be Dim * n
292 */
293 void accumulateEvaluationPositions(const std::vector<memoryx::KBM::Real>& positionSequence,
294 const Ice::Current& c = Ice::emptyCurrent) override;
295
296 /**
297 * @brief getRawJointValuesAverages calculates the average raw joint values for each joint
298 * from the data stored in the raw joint values accumulator.
299 */
300 Ice::DoubleSeq
301 getRawJointValuesAverages(int nDoF, const Ice::Current& c = Ice::emptyCurrent) override;
302
303 /**
304 * @brief getSpreadAngles returns the spreadAngles calculated using the data in the proprioceptionAccumulator
305 */
306 Ice::DoubleSeq getSpreadAngles(int nDoF,
307 const Ice::Current& c = Ice::emptyCurrent) override;
308
309 /**
310 * @brief accumualteProprioceptions accumulates proprioceptions
311 */
312 void accumulateProprioceptions(const std::vector<memoryx::KBM::Real>& proprioceptions,
313 const Ice::Current& c = Ice::emptyCurrent) override;
314
315 /**
316 * @brief accumualteProprioceptions accumulates proprioceptions in the evaluate accumulator
317 */
318 void
319 accumulateEvaluationProprioceptions(const std::vector<memoryx::KBM::Real>& proprioceptions,
320 const Ice::Current& c = Ice::emptyCurrent) override;
321
322 /**
323 * @brief accumualteRawJointValues accumulates raw joint values that will be transformed to proprioceptions later
324 */
325 void accumulateRawJointValues(const std::vector<memoryx::KBM::Real>& rawJointValuesSequence,
326 const Ice::Current& c = Ice::emptyCurrent) override;
327
328 /**
329 * @brief setProprioceptionAccumulatorFromRawJointAccumulator updates the proprioception accumulator
330 */
332 const std::vector<memoryx::KBM::Real>& rawJointValuesAverages,
333 const Ice::Current& c = Ice::emptyCurrent) override;
334
335 /**
336 * @brief setPositionLimits sets the position limits using the data in the position accumulator
337 */
338 void setPositionLimits(int nDim, const Ice::Current& c = Ice::emptyCurrent) override;
339
340 /**
341 * @brief onlineAccumulator calls online after transforming the raw joint accumulator to proprioceptions
342 */
343 void onlineAccumulator(const std::string& name,
344 Ice::Float learningRate,
345 const Ice::Current& c = Ice::emptyCurrent) override;
346
347 /**
348 * @brief onlineAccumulatorVerbose same as onlineAccumulator, but evaluates after each learning step
349 */
350 void onlineAccumulatorVerbose(const std::string& name,
351 Ice::Float learningRate,
352 const Ice::Current& c = Ice::emptyCurrent) override;
353
354 /**
355 * @brief the same as batch but with the data from the accumulator
356 */
357 void batchAccumulator(const std::string& name,
358 Ice::Int method,
359 Ice::Float threshold,
360 const Ice::Current& c = Ice::emptyCurrent) override;
361
362 /**
363 * @brief the same as printErrors but with the data from the accumulator
364 */
365 void printErrorsAccumulator(const std::string& name,
366 const Ice::Current& c = Ice::emptyCurrent) override;
367
368 /**
369 * @brief the same as predict but with the data from the accumulator, however the results are currently just printed and not returned
370 */
371 void predictAccumulator(const std::string& name,
372 const Ice::Current& c = Ice::emptyCurrent) override;
373
374 /**
375 * @brief solveGlobalIK solves the global inverse kinematics for the given position
376 * @param name the name of the KBM
377 * @param targetPosition
378 * @return the proprioception
379 */
380 std::vector<memoryx::KBM::Real>
381 solveGlobalIK(const std::string& name,
382 const std::vector<memoryx::KBM::Real>& targetPosition,
383 const Ice::Current& c = Ice::emptyCurrent) override;
384
385 /**
386 * @brief solveDifferentialIK solves the differential inverse kinematics for the given position
387 * @param name the name of the KBM
388 * @param targetPosition
389 * @param currentPosition
390 * @param currentProprioception
391 * @return the proprioception
392 */
393 std::vector<memoryx::KBM::Real> solveDifferentialIK(
394 const std::string& name,
395 const std::vector<memoryx::KBM::Real>& targetPosition,
396 const std::vector<memoryx::KBM::Real>& currentPosition,
397 const std::vector<memoryx::KBM::Real>& proprioceptionSequence,
398 const std::vector<memoryx::KBM::Real>& lowerProprioceptionLimitsSequence,
399 const std::vector<memoryx::KBM::Real>& upperProprioceptionLimitsSequence,
400 const Ice::Current& c = Ice::emptyCurrent) override;
401
402 /**
403 * Returns the names of the existing KBMs
404 */
405 Ice::StringSeq kbmNames(const Ice::Current& c) override;
406
407 /**
408 * Clears the accumulators
409 */
410 void clearAccumulators(const Ice::Current& c) override;
411
412 void storeToMemory(const std::string&,
413 const std::string&,
414 const std::string&,
415 const std::string&,
416 const Ice::Current&) override;
417 void restoreFromMemory(const std::string&,
418 const std::string&,
419 const std::string&,
420 const std::string&,
421 const Ice::Current&) override;
422 bool isInMemory(const std::string& nodeSetName,
423 const std::string& referenceFrameName,
424 const std::string& robotName,
425 const Ice::Current& c) override;
426
427
428 protected:
429 /**
430 * @see armarx::ManagedIceObject::onInitComponent()
431 */
432 void onInitComponent() override;
433
434 /**
435 * @see armarx::ManagedIceObject::onConnectComponent()
436 */
437 void onConnectComponent() override;
438
439 /**
440 * @see armarx::ManagedIceObject::onDisconnectComponent()
441 */
442 void onDisconnectComponent() override;
443
444 /**
445 * @see armarx::ManagedIceObject::onExitComponent()
446 */
447 void onExitComponent() override;
448
449 /**
450 * @see PropertyUser::createPropertyDefinitions()
451 */
453
454 /**
455 * @brief mapPosition converts the position sequence into an Eigen::Map of a Vector
456 * @param kbm the dimension of this KBM will be used
457 * @param position the position sequence
458 * @return the map
459 */
460 Eigen::Map<const memoryx::KBM::Vector>
462 const std::vector<memoryx::KBM::Real>& position);
463
464 /**
465 * @brief mapProprioception converts the proprioception sequence into an Eigen::Map of a Vector
466 * @param kbm the DoF of this KBM will be used
467 * @param proprioception the proprioception sequence
468 * @return the map
469 */
470 Eigen::Map<const memoryx::KBM::Vector>
472 const std::vector<memoryx::KBM::Real>& proprioception);
473
474 /**
475 * @brief mapPositions converts the position sequence into an Eigen::Map of a Matrix
476 * @param kbm the dimension of this KBM will be used
477 * @param position the position sequence
478 * @return the map
479 */
480 Eigen::Map<const memoryx::KBM::Matrix>
482 const std::vector<memoryx::KBM::Real>& position);
483
484 /**
485 * maps a sequence to an Eigen::Map
486 */
487 Eigen::Map<const memoryx::KBM::Matrix>
488 mapMatrix(int rows, const std::vector<memoryx::KBM::Real>& data);
489
490 /**
491 * @brief mapProprioceptions converts the proprioception sequence into an Eigen::Map of a Matrix
492 * @param kbm the DoF of this KBM will be used
493 * @param proprioception the proprioception sequence
494 * @return the map
495 */
496 Eigen::Map<const memoryx::KBM::Matrix>
498 const std::vector<memoryx::KBM::Real>& proprioception);
499
500 /**
501 * @brief returns a pointer to the KBM with the given name if it exists or a nullptr if it doesn't
502 * @param name the name of the KBM
503 * @return pointer to the KBM or nullptr
504 */
505 memoryx::KBM::Models::KBM_ptr getKBM(const std::string& name);
506
507 private:
508 /**
509 * @brief kbms maps KBM names to KBMs
510 */
511 std::map<std::string, memoryx::KBM::Models::KBM_ptr> kbms;
512
513 /**
514 * @brief createdFromVirtualRobot maps KBM names to a bool indicating whether they have been created from a VirtualRobot or not
515 */
516 std::map<std::string, bool> createdFromVirtualRobot;
517
518 /**
519 * @brief proprioceptionAccumulator is used to accumulate proprioceptions
520 */
521 std::vector<memoryx::KBM::Real> proprioceptionAccumulator;
522
523 /**
524 * @brief positionAccumulator is used to accumulate positions
525 */
526 std::vector<memoryx::KBM::Real> positionAccumulator;
527
528 /**
529 * @brief rawJointValuesAccumulator is used to accumulate raw joint values
530 */
531 std::vector<memoryx::KBM::Real> rawJointValuesAccumulator;
532
533 /**
534 * @brief evaluationProprioceptionAccumulator is used to accumulate proprioceptions for evaluation
535 */
536 std::vector<memoryx::KBM::Real> evaluationProprioceptionAccumulator;
537
538 /**
539 * @brief evaluationPositionAccumulator is used to accumulate positions for evaluation
540 */
541 std::vector<memoryx::KBM::Real> evaluationPositionAccumulator;
542
545
546 memoryx::LongtermMemoryInterfacePrx longtermMemoryPrx;
547 armarx::RobotStateComponentInterfacePrx robotStateComponentPrx;
548 };
549} // namespace armarx
constexpr T c
ComponentPropertyDefinitions(std::string prefix, bool hasObjectNameParameter=true)
Definition Component.cpp:46
Baseclass for all ArmarX ManagedIceObjects requiring properties.
Definition Component.h:94
KBMComponentPropertyDefinitions(std::string prefix)
Wrapper for the KBM class.
void onlineAccumulatorVerbose(const std::string &name, Ice::Float learningRate, const Ice::Current &c=Ice::emptyCurrent) override
onlineAccumulatorVerbose same as onlineAccumulator, but evaluates after each learning step
void predictAccumulator(const std::string &name, const Ice::Current &c=Ice::emptyCurrent) override
the same as predict but with the data from the accumulator, however the results are currently just pr...
void onInitComponent() override
Eigen::Map< const memoryx::KBM::Matrix > mapPositions(const memoryx::KBM::Models::KBM &kbm, const std::vector< memoryx::KBM::Real > &position)
mapPositions converts the position sequence into an Eigen::Map of a Matrix
void accumulateEvaluationPositions(const std::vector< memoryx::KBM::Real > &positionSequence, const Ice::Current &c=Ice::emptyCurrent) override
accumulates the given position in the evaluation accumulator
void setProprioceptionAccumulatorFromRawJointAccumulator(const std::vector< memoryx::KBM::Real > &rawJointValuesAverages, const Ice::Current &c=Ice::emptyCurrent) override
setProprioceptionAccumulatorFromRawJointAccumulator updates the proprioception accumulator
void printAccumulatorStatistics(int nDim, int nDoF, const Ice::Current &c=Ice::emptyCurrent) override
printAccumulatorStatistics prints information about the values in the accumulators
void accumulateEvaluationProprioceptions(const std::vector< memoryx::KBM::Real > &proprioceptions, const Ice::Current &c=Ice::emptyCurrent) override
accumualteProprioceptions accumulates proprioceptions in the evaluate accumulator
void onDisconnectComponent() override
Eigen::Map< const memoryx::KBM::Vector > mapPosition(const memoryx::KBM::Models::KBM &kbm, const std::vector< memoryx::KBM::Real > &position)
mapPosition converts the position sequence into an Eigen::Map of a Vector
void onlineVerbose(const std::string &name, const std::vector< memoryx::KBM::Real > &proprioceptionSequence, const std::vector< memoryx::KBM::Real > &positionSequence, Ice::Float learningRate, const std::vector< memoryx::KBM::Real > &evaluationProprioceptionSequence, const std::vector< memoryx::KBM::Real > &evaluationPositionSequence, const Ice::Current &c=Ice::emptyCurrent) override
same as online, but evaluates after each learning iteration
std::vector< memoryx::KBM::Real > solveGlobalIK(const std::string &name, const std::vector< memoryx::KBM::Real > &targetPosition, const Ice::Current &c=Ice::emptyCurrent) override
solveGlobalIK solves the global inverse kinematics for the given position
std::vector< memoryx::KBM::Real > solveDifferentialIK(const std::string &name, const std::vector< memoryx::KBM::Real > &targetPosition, const std::vector< memoryx::KBM::Real > &currentPosition, const std::vector< memoryx::KBM::Real > &proprioceptionSequence, const std::vector< memoryx::KBM::Real > &lowerProprioceptionLimitsSequence, const std::vector< memoryx::KBM::Real > &upperProprioceptionLimitsSequence, const Ice::Current &c=Ice::emptyCurrent) override
solveDifferentialIK solves the differential inverse kinematics for the given position
bool isInMemory(const std::string &nodeSetName, const std::string &referenceFrameName, const std::string &robotName, const Ice::Current &c) override
Ice::StringSeq kbmNames(const Ice::Current &c) override
Returns the names of the existing KBMs.
void onlineAccumulator(const std::string &name, Ice::Float learningRate, const Ice::Current &c=Ice::emptyCurrent) override
onlineAccumulator calls online after transforming the raw joint accumulator to proprioceptions
Ice::DoubleSeq getRawJointValuesAverages(int nDoF, const Ice::Current &c=Ice::emptyCurrent) override
getRawJointValuesAverages calculates the average raw joint values for each joint from the data stored...
void createArmar3KBM(const std::string &name, const Ice::StringSeq &robotNodeNames, const std::vector< memoryx::KBM::Real > &jointValueAverages, const std::vector< memoryx::KBM::Real > &spreadAnglesSequence, const std::string &tcpName, bool useOrientation, const Ice::Current &c=Ice::emptyCurrent) override
createArmar3KBM creates a KBM from a VirtualRobot model
armarx::PropertyDefinitionsPtr createPropertyDefinitions() override
void clearAccumulators(const Ice::Current &c) override
Clears the accumulators.
std::vector< memoryx::KBM::Real > predict(const std::string &name, const std::vector< memoryx::KBM::Real > &proprioceptionSequence, const Ice::Current &c=Ice::emptyCurrent) override
predict the position for n samples of proprioception (forward kinematics)
void printErrors(const std::string &name, const std::vector< memoryx::KBM::Real > &proprioceptionSequence, const std::vector< memoryx::KBM::Real > &positionSequence, const Ice::Current &c=Ice::emptyCurrent) override
calls getErrors on the KBM and prints the result
void accumulateProprioceptions(const std::vector< memoryx::KBM::Real > &proprioceptions, const Ice::Current &c=Ice::emptyCurrent) override
accumualteProprioceptions accumulates proprioceptions
Ice::DoubleSeq getSpreadAngles(int nDoF, const Ice::Current &c=Ice::emptyCurrent) override
getSpreadAngles returns the spreadAngles calculated using the data in the proprioceptionAccumulator
void online(const std::string &name, const std::vector< memoryx::KBM::Real > &proprioceptionSequence, const std::vector< memoryx::KBM::Real > &positionSequence, Ice::Float learningRate, const Ice::Current &c=Ice::emptyCurrent) override
online learning of n training samples
void accumulateRawJointValues(const std::vector< memoryx::KBM::Real > &rawJointValuesSequence, const Ice::Current &c=Ice::emptyCurrent) override
accumualteRawJointValues accumulates raw joint values that will be transformed to proprioceptions lat...
void createKBM(const std::string &name, Ice::Int nDoF, Ice::Int dim, Ice::Float spreadAngle, const Ice::Current &c=Ice::emptyCurrent) override
createKBM creates a new KBM and makes it available under the given name
void batchAccumulator(const std::string &name, Ice::Int method, Ice::Float threshold, const Ice::Current &c=Ice::emptyCurrent) override
the same as batch but with the data from the accumulator
memoryx::KBM::Models::KBM_ptr getKBM(const std::string &name)
returns a pointer to the KBM with the given name if it exists or a nullptr if it doesn't
void onConnectComponent() override
static std::string GetDefaultName()
void storeToMemory(const std::string &, const std::string &, const std::string &, const std::string &, const Ice::Current &) override
void printErrorsAccumulator(const std::string &name, const Ice::Current &c=Ice::emptyCurrent) override
the same as printErrors but with the data from the accumulator
void restoreFromMemory(const std::string &, const std::string &, const std::string &, const std::string &, const Ice::Current &) override
Eigen::Map< const memoryx::KBM::Matrix > mapProprioceptions(const memoryx::KBM::Models::KBM &kbm, const std::vector< memoryx::KBM::Real > &proprioception)
mapProprioceptions converts the proprioception sequence into an Eigen::Map of a Matrix
void accumulatePositions(const std::vector< memoryx::KBM::Real > &positionSequence, const Ice::Current &c=Ice::emptyCurrent) override
accumulate adds the given position to the accumulator to use it later
Eigen::Map< const memoryx::KBM::Vector > mapProprioception(const memoryx::KBM::Models::KBM &kbm, const std::vector< memoryx::KBM::Real > &proprioception)
mapProprioception converts the proprioception sequence into an Eigen::Map of a Vector
void batch(const std::string &name, const std::vector< memoryx::KBM::Real > &proprioceptionSequence, const std::vector< memoryx::KBM::Real > &positionSequence, Ice::Int method, Ice::Float threshold, const Ice::Current &c=Ice::emptyCurrent) override
batch learning of n training samples
void onExitComponent() override
void setPositionLimits(int nDim, const Ice::Current &c=Ice::emptyCurrent) override
setPositionLimits sets the position limits using the data in the position accumulator
std::string getDefaultName() const override
Eigen::Map< const memoryx::KBM::Matrix > mapMatrix(int rows, const std::vector< memoryx::KBM::Real > &data)
maps a sequence to an Eigen::Map
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)
The Kinematic B\'ezier Maps.
Definition kbm.h:82
bool applyProprioceptionLimits(Eigen::Map< memoryx::KBM::Vector > &solution, const memoryx::KBM::Vector &lowerProprioceptionLimits, const memoryx::KBM::Vector &upperProprioceptionLimits)
apply limits to solution and return true, if solution has been changed = solution was not in limits
bool solveMany(const memoryx::KBM::Models::KBM &kbm, const memoryx::KBM::Vector &targetPosition, const memoryx::KBM::Vector &currentPosition, const memoryx::KBM::Vector &currentProprioception, const memoryx::KBM::Vector &lowerProprioceptionLimits, const memoryx::KBM::Vector &upperProprioceptionLimits, Eigen::Map< memoryx::KBM::Vector > &solution, bool applyLimits=true, int maxSolves=25, float positionTolerance=5.0f, float minimumDelta=0.0f, bool requireImprovment=false, int maxSteps=50, float stepSizeFactor=0.2f, float maxStepSize=FLT_MAX)
KBMDifferentialIK::solveMany runs solve many times.
bool solve(const memoryx::KBM::Models::KBM &kbm, const memoryx::KBM::Vector &targetPosition, const memoryx::KBM::Vector &currentPostion, const memoryx::KBM::Vector &currentProprioception, Eigen::Map< memoryx::KBM::Vector > &solution, float positionTolerance=5.0f, float minimumDelta=0.0f, bool requireImprovment=false, int maxSteps=50, float stepSizeFactor=0.2f, float maxStepSize=FLT_MAX)
solves the inverse kinematics
bool checkProprioceptionLimits(const memoryx::KBM::Vector &solution, const memoryx::KBM::Vector &lowerProprioceptionLimits, const memoryx::KBM::Vector &upperProprioceptionLimits)
check if solution is within the limits
memoryx::KBM::Vector calculateJointDeltas(const memoryx::KBM::Models::KBM &kbm, const memoryx::KBM::Vector &target, const memoryx::KBM::Vector &position, const memoryx::KBM::Vector &proprioception, float stepSizeFactor, float maxStepSize)
calculateJointDeltas is in internal function called by solve
float randomFloat(float LO, float HI)
randomFloat creates a random float between LO and HI
memoryx::KBM::Vector randomProprioception(const memoryx::KBM::Vector &lowerProprioceptionLimits, const memoryx::KBM::Vector &upperProprioceptionLimits)
Creates a vector of random values between the limits.
This file offers overloads of toIce() and fromIce() functions for STL container types.
IceUtil::Handle< class PropertyDefinitionContainer > PropertyDefinitionsPtr
PropertyDefinitions smart pointer type.
::IceInternal::ProxyHandle<::IceProxy::armarx::RobotStateComponentInterface > RobotStateComponentInterfacePrx
std::shared_ptr< KBM > KBM_ptr
Definition kbm.h:71
Eigen::VectorXd Vector
Definition kbm.h:41