30#include <MemoryX/interface/components/KBMComponentInterface.h>
31#include <MemoryX/interface/components/LongtermMemoryInterface.h>
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");
129 Eigen::Map<memoryx::KBM::Vector>& solution,
130 bool applyLimits =
true,
132 float positionTolerance = 5.0f,
133 float minimumDelta = 0.0f,
134 bool requireImprovment =
false,
136 float stepSizeFactor = 0.2f,
137 float maxStepSize = FLT_MAX);
152 Eigen::Map<memoryx::KBM::Vector>& solution,
153 float positionTolerance = 5.0f,
154 float minimumDelta = 0.0f,
155 bool requireImprovment =
false,
157 float stepSizeFactor = 0.2f,
158 float maxStepSize = FLT_MAX);
177 return "KBMComponent";
192 Ice::Float spreadAngle,
193 const Ice::Current&
c = Ice::emptyCurrent)
override;
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,
208 const Ice::Current&
c = Ice::emptyCurrent)
override;
218 void batch(
const std::string& name,
219 const std::vector<memoryx::KBM::Real>& proprioceptionSequence,
220 const std::vector<memoryx::KBM::Real>& positionSequence,
222 Ice::Float threshold,
223 const Ice::Current&
c = Ice::emptyCurrent)
override;
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;
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;
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;
271 const std::vector<memoryx::KBM::Real>& proprioceptionSequence,
272 const std::vector<memoryx::KBM::Real>& positionSequence,
273 const Ice::Current&
c = Ice::emptyCurrent)
override;
280 const Ice::Current&
c = Ice::emptyCurrent)
override;
287 const Ice::Current&
c = Ice::emptyCurrent)
override;
294 const Ice::Current&
c = Ice::emptyCurrent)
override;
307 const Ice::Current&
c = Ice::emptyCurrent)
override;
313 const Ice::Current&
c = Ice::emptyCurrent)
override;
320 const Ice::Current&
c = Ice::emptyCurrent)
override;
326 const Ice::Current&
c = Ice::emptyCurrent)
override;
332 const std::vector<memoryx::KBM::Real>& rawJointValuesAverages,
333 const Ice::Current&
c = Ice::emptyCurrent)
override;
344 Ice::Float learningRate,
345 const Ice::Current&
c = Ice::emptyCurrent)
override;
351 Ice::Float learningRate,
352 const Ice::Current&
c = Ice::emptyCurrent)
override;
359 Ice::Float threshold,
360 const Ice::Current&
c = Ice::emptyCurrent)
override;
366 const Ice::Current&
c = Ice::emptyCurrent)
override;
372 const Ice::Current&
c = Ice::emptyCurrent)
override;
380 std::vector<memoryx::KBM::Real>
382 const std::vector<memoryx::KBM::Real>& targetPosition,
383 const Ice::Current&
c = Ice::emptyCurrent)
override;
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;
405 Ice::StringSeq
kbmNames(
const Ice::Current&
c)
override;
416 const Ice::Current&)
override;
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;
460 Eigen::Map<const memoryx::KBM::Vector>
462 const std::vector<memoryx::KBM::Real>& position);
470 Eigen::Map<const memoryx::KBM::Vector>
472 const std::vector<memoryx::KBM::Real>& proprioception);
480 Eigen::Map<const memoryx::KBM::Matrix>
482 const std::vector<memoryx::KBM::Real>& position);
487 Eigen::Map<const memoryx::KBM::Matrix>
488 mapMatrix(
int rows,
const std::vector<memoryx::KBM::Real>&
data);
496 Eigen::Map<const memoryx::KBM::Matrix>
498 const std::vector<memoryx::KBM::Real>& proprioception);
511 std::map<std::string, memoryx::KBM::Models::KBM_ptr> kbms;
516 std::map<std::string, bool> createdFromVirtualRobot;
521 std::vector<memoryx::KBM::Real> proprioceptionAccumulator;
526 std::vector<memoryx::KBM::Real> positionAccumulator;
531 std::vector<memoryx::KBM::Real> rawJointValuesAccumulator;
536 std::vector<memoryx::KBM::Real> evaluationProprioceptionAccumulator;
541 std::vector<memoryx::KBM::Real> evaluationPositionAccumulator;
546 memoryx::LongtermMemoryInterfacePrx longtermMemoryPrx;
ComponentPropertyDefinitions(std::string prefix, bool hasObjectNameParameter=true)
Baseclass for all ArmarX ManagedIceObjects requiring properties.
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 > ¤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
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.
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 ¤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.
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
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