Go to the documentation of this file.
29 #include <MemoryX/interface/components/KBMComponentInterface.h>
30 #include <MemoryX/interface/components/LongtermMemoryInterface.h>
56 defineOptionalProperty<std::string>(
"LongtermMemoryName",
"LongtermMemory",
"Name of the LongtermMemory component that should be used");
57 defineOptionalProperty<std::string>(
"RobotStateComponentName",
"RobotStateComponent",
"Name of the robot state component that should be used");
99 Eigen::Map<memoryx::KBM::Vector>& solution,
127 Eigen::Map<memoryx::KBM::Vector>& solution,
128 bool applyLimits =
true,
130 float positionTolerance = 5.0f,
131 float minimumDelta = 0.0f,
132 bool requireImprovment =
false,
134 float stepSizeFactor = 0.2f,
135 float maxStepSize = FLT_MAX);
150 Eigen::Map<memoryx::KBM::Vector>& solution,
151 float positionTolerance = 5.0f,
152 float minimumDelta = 0.0f,
153 bool requireImprovment =
false,
155 float stepSizeFactor = 0.2f,
156 float maxStepSize = FLT_MAX
169 virtual public KBMComponentInterface
177 return "KBMComponent";
191 const Ice::Current&
c = Ice::emptyCurrent)
override;
201 const Ice::StringSeq& robotNodeNames,
202 const std::vector<memoryx::KBM::Real>& jointValueAverages,
203 const std::vector<memoryx::KBM::Real>& spreadAnglesSequence,
204 const std::string& tcpName,
206 const Ice::Current&
c = Ice::emptyCurrent)
override;
216 void batch(
const std::string& name,
217 const std::vector<memoryx::KBM::Real>& proprioceptionSequence,
218 const std::vector<memoryx::KBM::Real>& positionSequence,
220 const Ice::Current&
c = Ice::emptyCurrent)
override;
229 void online(
const std::string& name,
230 const std::vector<memoryx::KBM::Real>& proprioceptionSequence,
231 const std::vector<memoryx::KBM::Real>& positionSequence,
233 const Ice::Current&
c = Ice::emptyCurrent)
override;
243 const std::vector<memoryx::KBM::Real>& proprioceptionSequence,
244 const std::vector<memoryx::KBM::Real>& positionSequence,
246 const std::vector<memoryx::KBM::Real>& evaluationProprioceptionSequence,
247 const std::vector<memoryx::KBM::Real>& evaluationPositionSequence,
248 const Ice::Current&
c = Ice::emptyCurrent)
override;
256 std::vector<memoryx::KBM::Real>
predict(
const std::string& name,
257 const std::vector<memoryx::KBM::Real>& proprioceptionSequence,
258 const Ice::Current&
c = Ice::emptyCurrent)
override;
267 const std::vector<memoryx::KBM::Real>& proprioceptionSequence,
268 const std::vector<memoryx::KBM::Real>& positionSequence,
269 const Ice::Current&
c = Ice::emptyCurrent)
override;
276 const Ice::Current&
c = Ice::emptyCurrent)
override;
283 const Ice::Current&
c = Ice::emptyCurrent)
override;
290 const Ice::Current&
c = Ice::emptyCurrent)
override;
301 Ice::DoubleSeq
getSpreadAngles(
int nDoF,
const Ice::Current&
c = Ice::emptyCurrent)
override;
307 const Ice::Current&
c = Ice::emptyCurrent)
override;
313 const Ice::Current&
c = Ice::emptyCurrent)
override;
319 const Ice::Current&
c = Ice::emptyCurrent)
override;
325 const Ice::Current&
c = Ice::emptyCurrent)
override;
337 const Ice::Current&
c = Ice::emptyCurrent)
override;
344 const Ice::Current&
c = Ice::emptyCurrent)
override;
351 const Ice::Current&
c = Ice::emptyCurrent)
override;
357 const Ice::Current&
c = Ice::emptyCurrent)
override;
363 const Ice::Current&
c = Ice::emptyCurrent)
override;
371 std::vector<memoryx::KBM::Real>
solveGlobalIK(
const std::string& name,
372 const std::vector<memoryx::KBM::Real>& targetPosition,
373 const Ice::Current&
c = Ice::emptyCurrent)
override;
384 const std::vector<memoryx::KBM::Real>& targetPosition,
385 const std::vector<memoryx::KBM::Real>& currentPosition,
386 const std::vector<memoryx::KBM::Real>& proprioceptionSequence,
387 const std::vector<memoryx::KBM::Real>& lowerProprioceptionLimitsSequence,
388 const std::vector<memoryx::KBM::Real>& upperProprioceptionLimitsSequence,
389 const Ice::Current&
c = Ice::emptyCurrent)
override;
394 Ice::StringSeq
kbmNames(
const Ice::Current&
c)
override;
401 void storeToMemory(
const std::string&,
const std::string&,
const std::string&,
const std::string&,
const Ice::Current&)
override;
402 void restoreFromMemory(
const std::string&,
const std::string&,
const std::string&,
const std::string&,
const Ice::Current&)
override;
403 bool isInMemory(
const std::string& nodeSetName,
const std::string& referenceFrameName,
const std::string& robotName,
const Ice::Current&
c)
override;
439 const std::vector<memoryx::KBM::Real>& position);
448 const std::vector<memoryx::KBM::Real>& proprioception);
457 const std::vector<memoryx::KBM::Real>& position);
462 Eigen::Map<const memoryx::KBM::Matrix>
mapMatrix(
int rows,
463 const std::vector<memoryx::KBM::Real>&
data);
472 const std::vector<memoryx::KBM::Real>& proprioception);
485 std::map<std::string, memoryx::KBM::Models::KBM_ptr> kbms;
490 std::map<std::string, bool> createdFromVirtualRobot;
495 std::vector<memoryx::KBM::Real> proprioceptionAccumulator;
500 std::vector<memoryx::KBM::Real> positionAccumulator;
505 std::vector<memoryx::KBM::Real> rawJointValuesAccumulator;
510 std::vector<memoryx::KBM::Real> evaluationProprioceptionAccumulator;
515 std::vector<memoryx::KBM::Real> evaluationPositionAccumulator;
520 memoryx::LongtermMemoryInterfacePrx longtermMemoryPrx;
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
void onExitComponent() override
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 storeToMemory(const std::string &, const std::string &, const std::string &, const std::string &, const Ice::Current &) override
const VariantTypeId Float
std::shared_ptr< KBM > KBM_ptr
void accumulateProprioceptions(const std::vector< memoryx::KBM::Real > &proprioceptions, const Ice::Current &c=Ice::emptyCurrent) override
accumualteProprioceptions accumulates proprioceptions
bool solve(const memoryx::KBM::Models::KBM &kbm, const memoryx::KBM::Vector &targetPosition, const memoryx::KBM::Vector ¤tPostion, const memoryx::KBM::Vector ¤tProprioception, 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
void onInitComponent() override
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
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
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 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
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 clearAccumulators(const Ice::Current &c) override
Clears the accumulators.
Vertex target(const detail::edge_base< Directed, Vertex > &e, const PCG &)
std::string prefix
Prefix of the properties such as namespace, domain, component name, etc.
memoryx::KBM::Vector randomProprioception(const memoryx::KBM::Vector &lowerProprioceptionLimits, const memoryx::KBM::Vector &upperProprioceptionLimits)
Creates a vector of random values between the limits.
void printAccumulatorStatistics(int nDim, int nDoF, const Ice::Current &c=Ice::emptyCurrent) override
printAccumulatorStatistics prints information about the values in the accumulators
void onDisconnectComponent() 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
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
armarx::PropertyDefinitionsPtr createPropertyDefinitions() override
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...
Ice::DoubleSeq getSpreadAngles(int nDoF, const Ice::Current &c=Ice::emptyCurrent) override
getSpreadAngles returns the spreadAngles calculated using the data in the proprioceptionAccumulator
void accumulateEvaluationProprioceptions(const std::vector< memoryx::KBM::Real > &proprioceptions, const Ice::Current &c=Ice::emptyCurrent) override
accumualteProprioceptions accumulates proprioceptions in the evaluate accumulator
bool solveMany(const memoryx::KBM::Models::KBM &kbm, const memoryx::KBM::Vector &targetPosition, const memoryx::KBM::Vector ¤tPosition, const memoryx::KBM::Vector ¤tProprioception, 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.
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
void setProprioceptionAccumulatorFromRawJointAccumulator(const std::vector< memoryx::KBM::Real > &rawJointValuesAverages, const Ice::Current &c=Ice::emptyCurrent) override
setProprioceptionAccumulatorFromRawJointAccumulator updates the proprioception accumulator
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 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 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
KBMComponentPropertyDefinitions(std::string prefix)
bool isInMemory(const std::string &nodeSetName, const std::string &referenceFrameName, const std::string &robotName, const Ice::Current &c) override
Wrapper for the KBM class.
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 restoreFromMemory(const std::string &, const std::string &, const std::string &, const std::string &, const Ice::Current &) override
float randomFloat(float LO, float HI)
randomFloat creates a random float between LO and HI
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
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
void setPositionLimits(int nDim, const Ice::Current &c=Ice::emptyCurrent) override
setPositionLimits sets the position limits using the data in the position accumulator
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
bool checkProprioceptionLimits(const memoryx::KBM::Vector &solution, const memoryx::KBM::Vector &lowerProprioceptionLimits, const memoryx::KBM::Vector &upperProprioceptionLimits)
check if solution is within the limits
void onConnectComponent() override
Baseclass for all ArmarX ManagedIceObjects requiring properties.
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
std::string getDefaultName() const override
Default component property definition container.
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::StringSeq kbmNames(const Ice::Current &c) override
Returns the names of the existing KBMs.
The Kinematic B\'ezier Maps.
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...
std::vector< memoryx::KBM::Real > solveDifferentialIK(const std::string &name, const std::vector< memoryx::KBM::Real > &targetPosition, const std::vector< memoryx::KBM::Real > ¤tPosition, 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
Eigen::Map< const memoryx::KBM::Matrix > mapMatrix(int rows, const std::vector< memoryx::KBM::Real > &data)
maps a sequence to an Eigen::Map
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
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
This file offers overloads of toIce() and fromIce() functions for STL container types.
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)