24#include <VirtualRobot/KinematicChain.h>
25#include <VirtualRobot/Nodes/RobotNode.h>
26#include <VirtualRobot/Nodes/RobotNodeRevolute.h>
27#include <VirtualRobot/Robot.h>
28#include <VirtualRobot/VirtualRobotException.h>
31#define KBM_USE_DOUBLE_PRECISION
33#define KBM_IMPORT_EXPORT
38#ifdef KBM_USE_DOUBLE_PRECISION
46 using Matrix = Eigen::MatrixXf;
47 using Vector = Eigen::VectorXf;
48 using Matrix4 = Eigen::Matrix4f;
49 using Vector3 = Eigen::Vector3f;
134 KBM(
int nDoF,
int dim,
Real spreadAngle);
137 bool restore(std::string fileName =
"");
139 void store(std::string fileName =
"");
162 Real threshold = 0.0);
194 const Vector& newSpreadAngles);
206 Matrix& resultingControlNet)
const;
212 Matrix& resultingControlNet)
const;
235 Real tolerance = 0.0f);
261 const Vector& spreadAngles,
262 const Matrix& controlNet);
264 VirtualRobot::SceneObjectPtr FoR,
265 const Vector& spreadAngles,
266 bool useOrientation =
false);
281 bool project =
true)
const;
283 void createIndices();
291 std::vector<Matrix> partialDerivatives;
309 const Vector& _spreadAngles,
323 this->
center = kbm->getCenter();
326 kbm->getBBox(BBupper, BBlower);
327 this->
lower = BBlower;
328 this->
upper = BBupper;
364 unsigned int recursion,
418 const Vector& _spreadAngles,
std::ostream & operator<<(std::ostream &strm, const AbstractInterface &a)
virtual unsigned int recurse(unsigned int level, Models::KBM_ptr kbm)=0
void subdivideAngles(Side side, unsigned int recursion, Models::KBM_ptr kbm, Vector ¢er, Vector &spreadAngles)
Subdivides the joint angles only. Can be used to select in which direction to subdivise first.
Models::KBM_ptr subdivideKBM(GlobalIKBase::Side side, unsigned int recursion, Models::KBM_ptr kbm)
Subdivides the kbm and creates new KBM. Calls GlobalIKBase::subdivideAngles().
void solve(Models::KBM_ptr kbm, const Vector lower, const Vector upper, Real resolution=2.0f *M_PI/180.0f)
std::vector< Solution > SolutionSet
Finds all solutions to the Global IK.
unsigned int recurse(unsigned int level, Models::KBM_ptr kbm) override
Real semiBreadthRecursion
unsigned int recurse(unsigned int level, Models::KBM_ptr kbm) override
GlobalIKSemiBreadth(Real _semiBreadthRecursion, int _solutionSelect=Models::KBM::COVERED)
GlobalIKBase::SolutionSet runDijkstra(KBM::Inverse::GraphNode initial)
Matrix predict(const Matrix &proprioception, int dim=0) const
Predicts a value of the FK given a set of joint angles.
Vector getCenter() const
Return the center.
Real getOverlappingVolumeRatio(const Vector &lower, const Vector &upper, Real targetVolume)
static BBCheckType checkBBoxes(const Vector &lower, const Vector &upper, const Matrix &controlNet, Real tolerance=0.0f)
Check whether an interval overlaps the the bounding box of a given control net.
void store(std::string fileName="")
stores the current KBM as a comma-separated matrix to disk.
Matrix getJacobian(const Vector &proprioception) const
Computes the partial derivative with respect to a configuration.
ErrorValuesType getErrors(const Matrix &proprioception, const Matrix &shape)
After learning this function gives various error measures over a given test set.online Proprioception...
void getSubdivisedNet(const Vector newCenter, Vector newSpreadAngles, Matrix &resultingControlNet) const
Work in progress This method computes the control net of a subdivised KBM instance.
Vector getPartialDerivative(const Vector &proprioception, int iDoF) const
Computes a partial derivative with respect to a configuration and the specified degree of freedom.
Optimization
Enum for the preferred optimization method during batch learning.
static KBM_ptr createKBM(int nDoF, int dim, const Vector ¢er, const Vector &spreadAngles, const Matrix &controlNet)
Factory methods.
static KBM_ptr createFromVirtualRobot(VirtualRobot::KinematicChainPtr chain, VirtualRobot::SceneObjectPtr FoR, const Vector &spreadAngles, bool useOrientation=false)
void differentiate()
Prepares the calculus of the derivatives. Has to be called alwayes after learning.
void online(const Matrix &proprioception, const Matrix &shape, Real learnRate=1.0)
Implements the online learning algorithm.
Matrix getControlNet() const
BBCheckType
Cases for the check of bounding boxes (i.e., an interval ) and an interval ( )both in Cartesian coor...
@ DISJOINT
The bounding box and interval are disjoint .
@ OVERLAPPING
The interval and bounding box are partially overlapping (if none of the above applies).
@ INCLUDED
The interval is included in the bounding box .
@ COVERED
The bounding box is covered by the interval (most interesting case for inverse kinematics).
static void getBBox(Vector &lower, Vector &upper, const Matrix &controlNet)
Helper function that extracts the bounding box of a control net.
Real getOverlappingVolume(const Vector &lower, const Vector &upper)
int getNDoF() const
Get the number of degrees of freedom (DoF).
void reset()
Forgets all previously learned samples.
Vector getSpreadAngles() const
Return the spread angles.
void batch(const Matrix &proprioception, const Matrix &shape, Optimization method=KBM::STANDARD, Real threshold=0.0)
Implements the batch learning algorithm.
KBM(const KBM &other)
Copy constructor.
void subdivide(const Vector ¢er, const Vector &newSpreadAngles)
Work in progress This method subdivides the KBM representation.
BBCheckType checkBBox(const Vector &lower, const Vector &upper, Real tolerance=0.0f) const
Check whether an interval overlaps the the bounding box of the control points.
bool restore(std::string fileName="")
loads a KBM with same input/output dimensions from disk (comma-separated values).
#define KBM_IMPORT_EXPORT
Namespace for algorithms related to solving the inverse kinematics.
std::vector< Solution > SolutionSet
Return type of the global inverse kinematics solvers.
void solveGlobalIK(unsigned int recursion, int side, SolutionSet &solutionSet, Models::KBM_ptr kbm, const Vector &lower, const Vector &upper, Real resolution, Vector spreadAngles, Vector center)
Where the model representation for a Body Schema (especially the Kinematic B“ezier Maps) reside.
std::shared_ptr< KBM > KBM_ptr
Namespace where the Partial Least Squares (PLS-1) solver is defined in.
Matrix KBM_IMPORT_EXPORT solve(const Matrix &input, const Matrix output, Real threshold)
Solves a linear system of equations using the partial least squares algorithm.
double Real
Type definition of the underlying Realing point type.
Solution(Models::KBM_ptr kbm, Models::KBM::BBCheckType type)
Models::KBM::BBCheckType type
Solution(const Vector &_center, const Vector &_spreadAngles, const Vector &_upper, const Vector &_lower, const Models::KBM::BBCheckType &_type)
GraphNode(Models::KBM_ptr _model, Real _ratio, int _level, Real _volume)
Models::KBM::BBCheckType type
Solution(const Vector &_center, const Vector &_spreadAngles, const Vector &_upper, const Vector &_lower, const Models::KBM::BBCheckType &_type)
Return type of the evaluation (KBM::getErrors()) function providing insight in the statistics of the ...
Real Median
Median of the error.
Real STD
Standard deviation.
Real IQR
Inerquartile range (50% of all errors): .