16#include <yarp/os/Log.h>
17#include <yarp/os/Time.h>
18#include <yarp/math/SVD.h>
21#define IKINCTRL_INTARGET_TOL 5e-3
22#define IKINCTRL_WATCHDOG_TOL 1e-4
23#define IKINCTRL_WATCHDOG_MAXITER 200
26using namespace yarp::os;
27using namespace yarp::sig;
28using namespace yarp::math;
76 unsigned int n=(
unsigned int)q0.length();
79 for (
unsigned int i=0; i<
n; i++)
105 Matrix Des=axis2dcm(
x_set.subVector(3,6));
106 Vector ax=dcm2axis(Des*
H.transposed());
161 unsigned int hi=(verbose>>16) & 0xffff;
162 unsigned int lo=verbose & 0xffff;
202 Vector checked_qdot=_qdot;
203 Vector newq =
q+checked_qdot*_Ts;
205 for (
unsigned int i=0; i<
dim; i++)
206 if ((newq[i]<
chain(i).getMin()) || (newq[i]>
chain(i).getMax()))
215 const unsigned int verbose,
int *exit_code,
bool *exhalt)
256 if (max_iter>0 && (
int)
iter>=max_iter)
270SteepCtrl::SteepCtrl(
iKinChain &c,
unsigned int _type,
unsigned int _ctrlPose,
271 double _Ts,
double _Kp) : iKinCtrl(c,_ctrlPose)
279 for (
unsigned int i=0; i<
dim; i++)
281 lim(i,0)=
chain(i).getMin();
282 lim(i,1)=
chain(i).getMax();
326 if (
J.rows()>=
J.cols())
329 pinvJ=pinv(
J.transposed()).transposed();
385 printf(
"iter #%d\n",
iter);
386 printf(
"state = %s\n",strState[
state].c_str());
387 printf(
"norm(e) = %g\n",
dist());
389 printf(
"x = %s\n",
x.toString().c_str());
393 printf(
"grad = %s\n",
grad.toString().c_str());
398 printf(
"Kp = %g\n",
Kp);
413VarKpSteepCtrl::VarKpSteepCtrl(
iKinChain &c,
unsigned int _type,
unsigned int _ctrlPose,
double _Ts,
414 double _Kp0,
double _Kp_inc,
double _Kp_dec,
double _Kp_max,
415 double _max_perf_inc) : SteepCtrl(c,_ctrlPose,_type,_Ts,_Kp0)
439 Vector qdot_old=
qdot;
466LMCtrl::LMCtrl(
iKinChain &c,
unsigned int _ctrlPose,
double _Ts,
double _mu0,
467 double _mu_inc,
double _mu_dec,
double _mu_min,
double _mu_max,
468 double _sv_thres) : iKinCtrl(c,_ctrlPose)
475 for (
unsigned int i=0; i<
dim; i++)
477 lim(i,0)=
chain(i).getMin();
478 lim(i,1)=
chain(i).getMax();
518 for (
int c=0; c<
n; c++)
520 for (
int r=0; r<
n; r++)
522 if (r==c && Sdiag[c]>tol)
523 Spinv(r,c)=1.0/Sdiag[c];
530 return V*Spinv*U.transposed();
586 for (
int i=0; i<6; i++)
589 if (LM.rows()>=LM.cols())
594 if (
J.rows()>=
J.cols())
651 printf(
"iter #%d\n",
iter);
652 printf(
"state = %s\n",strState[
state].c_str());
653 printf(
"norm(e) = %g\n",
dist());
655 printf(
"x = %s\n",
x.toString().c_str());
658 printf(
"grad = %s\n",
grad.toString().c_str());
661 printf(
"mu = %g\n",
mu);
676LMCtrl_GPM::LMCtrl_GPM(
iKinChain &c,
unsigned int _ctrlPose,
double _Ts,
677 double _mu0,
double _mu_inc,
double _mu_dec,
678 double _mu_min,
double _mu_max,
double _sv_thres) :
679 LMCtrl(c,_ctrlPose,_Ts,_mu0,_mu_inc,_mu_dec,_mu_min,_mu_max,_sv_thres)
694 safeAreaRatio=_safeAreaRatio<0.0 ? 0.0 : (_safeAreaRatio>1.0 ? 1.0 : _safeAreaRatio);
696 for (
unsigned int i=0; i<
dim; i++)
714 for (
unsigned int i=0; i<
dim; i++)
716 w[i] =d_min[i]>0.0 ? 0.0 : 2.0*d_min[i]/(
span[i]*
span[i]);
717 w[i]+=d_max[i]<0.0 ? 0.0 : 2.0*d_max[i]/(
span[i]*
span[i]);
725MultiRefMinJerkCtrl::MultiRefMinJerkCtrl(
iKinChain &c,
unsigned int _ctrlPose,
double _Ts,
726 bool nonIdealPlant) :
727 iKinCtrl(c,_ctrlPose),
Ts(_Ts)
740 for (
unsigned int i=0; i<
dim; i++)
742 lim(i,0)=
chain(i).getMin();
743 lim(i,1)=
chain(i).getMax();
772 guardRatio=_guardRatio>1.0 ? 1.0 : (_guardRatio<0.0 ? 0.0 : _guardRatio);
781 for (
unsigned int i=0; i<
dim; i++)
799 for (
unsigned int i=0; i<
dim; i++)
815 const unsigned int verbose)
833 _xdot[0]=(*xdot_set)[0];
834 _xdot[1]=(*xdot_set)[1];
835 _xdot[2]=(*xdot_set)[2];
836 _xdot[3]=(*xdot_set)[3]*(*xdot_set)[6];
837 _xdot[4]=(*xdot_set)[4]*(*xdot_set)[6];
838 _xdot[5]=(*xdot_set)[5]*(*xdot_set)[6];
872 return iterate(xd,qd,NULL,verbose);
878 const unsigned int verbose)
880 return iterate(xd,qd,&xdot_set,verbose);
911 printf(
"iter #%d\n",
iter);
912 printf(
"state = %s\n",strState[
state].c_str());
913 printf(
"norm(e) = %g\n",
dist());
914 printf(
"xd = %s\n",
x_set.toString().c_str());
915 printf(
"x = %s\n",
x.toString().c_str());
922 printf(
"xdot = %s\n",
xdot.toString().c_str());
944 double lowerThres=10.0*
Ts;
946 execTime=_execTime>lowerThres ? _execTime : lowerThres;
949 yWarning(
"task execution time limited to the lower bound %g",lowerThres);
958 size_t len=std::min(comp.length(),
q.length());
959 for (
size_t i=0; i<len; i++)
966 const string &entryTag)
975 for (
unsigned int i=0; i<
chain.getN(); i++)
976 if (!
chain[i].isBlocked())
977 ordering.addInt32(i);
A class for defining a saturated integrator based on Tustin formula: .
const yarp::sig::Vector & integrate(const yarp::sig::Vector &x)
Executes one-step integration of input vector.
Implements a minimum-jerk controller with velocity commands in the assumption that the plant can be m...
Implements a minimum-jerk controller with velocity commands assuming a non ideal plant represented wi...
virtual yarp::sig::Vector computeCmd(const double _T, const yarp::sig::Vector &e)=0
Computes the velocity command.
yarp::sig::Vector alpha_max
virtual yarp::sig::Vector computeGPM()
Returns the further contribution to the qdot=pinvJ*xdot equation according to the Gradient Projection...
void set_safeAreaRatio(const double _safeAreaRatio)
Sets the safe area ratio [0-1], which is for each joint the ratio between the angle span within which...
yarp::sig::Vector alpha_min
void reset_mu()
Sets the weighting factor mu equal to the initial value.
virtual void restart(const yarp::sig::Vector &q0)
Reinitializes the algorithm's internal state and resets the starting point.
virtual ~LMCtrl()
Destructor.
virtual yarp::sig::Vector computeGPM()
Returns the further contribution to the qdot=pinvJ*xdot equation according to the Gradient Projection...
virtual void setChainConstraints(bool _constrained)
Enables/Disables joint angles constraints.
virtual yarp::sig::Matrix pinv(const yarp::sig::Matrix &A, const double tol=0.0)
virtual void deadLockRecoveryFcn()
Method called whenever the watchDog is triggered.
virtual void printIter(const unsigned int verbose)
Dumps warning or status messages.
virtual yarp::sig::Vector iterate(yarp::sig::Vector &xd, const unsigned int verbose=0)
Executes one iteration of the control algorithm.
virtual double update_mu()
virtual void inTargetFcn()
Method called whenever in target.
void setPlantParameters(const yarp::os::Property ¶meters, const std::string &entryTag="dimension")
Allows user to assign values to the parameters of plant under control (for the configuration space on...
virtual yarp::sig::Vector iterate(yarp::sig::Vector &xd, yarp::sig::Vector &qd, yarp::sig::Vector *xdot_set, const unsigned int verbose)
yarp::sig::Vector qGuardMaxCOG
virtual void deadLockRecoveryFcn()
Method called whenever the watchDog is triggered.
yarp::sig::Vector qGuardMinExt
virtual ~MultiRefMinJerkCtrl()
Destructor.
yarp::sig::Vector qGuardMinCOG
yarp::sig::Vector qGuardMinInt
yarp::sig::Vector qGuardMaxExt
virtual void computeGuard()
virtual void computeWeight()
void add_compensation(const yarp::sig::Vector &comp)
Adds to the controller input a further compensation term.
virtual void printIter(const unsigned int verbose)
Dumps warning or status messages.
double set_execTime(const double _execTime, const bool warn=false)
Sets the task execution time in seconds.
virtual void inTargetFcn()
Method called whenever in target.
yarp::sig::Vector qGuardMaxInt
ctrl::minJerkVelCtrl * mjCtrlTask
ctrl::minJerkVelCtrl * mjCtrlJoint
virtual void set_q(const yarp::sig::Vector &q0)
Sets the joint angles values.
void set_guardRatio(double _guardRatio)
Sets the guard ratio (in [0 1]).
virtual void restart(const yarp::sig::Vector &q0)
Reinitializes the algorithm's internal state and resets the starting point.
yarp::sig::Vector compensation
virtual void printIter(const unsigned int verbose)
Dumps warning or status messages.
virtual void restart(const yarp::sig::Vector &q0)
Reinitializes the algorithm's internal state and resets the starting point.
virtual void setChainConstraints(bool _constrained)
Enables/Disables joint angles constraints.
virtual ~SteepCtrl()
Destructor.
virtual yarp::sig::Vector iterate(yarp::sig::Vector &xd, const unsigned int verbose=0)
Executes one iteration of the control algorithm.
virtual void deadLockRecoveryFcn()
Method called whenever the watchDog is triggered.
virtual void inTargetFcn()
Method called whenever in target.
virtual yarp::sig::Vector computeGPM()
Returns the further contribution to the qdot=pinvJ*xdot equation according to the Gradient Projection...
virtual yarp::sig::Vector update_qdot()
virtual yarp::sig::Vector update_qdot()
A Base class for defining a Serial Link Chain.
yarp::sig::Matrix GeoJacobian(const unsigned int i)
Returns the geometric Jacobian of the ith link.
yarp::sig::Vector EndEffPose(const bool axisRep=true)
Returns the coordinates of end-effector.
yarp::sig::Vector setAng(const yarp::sig::Vector &q)
Sets the free joint angles to values of q[i].
virtual void restart(const yarp::sig::Vector &q0)
Reinitializes the algorithm's internal state and resets the starting point.
virtual yarp::sig::Vector calc_e()
Computes the error according to the current controller settings (complete pose/translational/rotation...
virtual bool isInTarget()
Checks if the End-Effector is in target.
virtual void watchDog()
Handles the watchDog.
virtual void set_q(const yarp::sig::Vector &q0)
Sets the joint angles values.
unsigned int printHandling(const unsigned int verbose=0)
Method to be called within the printIter routine inherited by children in order to handle the highest...
virtual bool test_convergence(const double tol_size)=0
Tests convergence by comparing the size of the algorithm internal structure (may be the gradient norm...
virtual void update_state()
Updates the control state.
virtual yarp::sig::Vector checkVelocity(const yarp::sig::Vector &_qdot, double _Ts)
Checks each joint velocity and sets it to zero if it steers the joint out of range.
virtual yarp::sig::Vector solve(yarp::sig::Vector &xd, const double tol_size=IKINCTRL_DISABLED, const int max_iter=IKINCTRL_DISABLED, const unsigned int verbose=0, int *exit_code=NULL, bool *exhalt=NULL)
Iterates the control algorithm trying to converge on the target.
void set_ctrlPose(unsigned int _ctrlPose)
Sets the state of Pose control settings.
virtual void setChainConstraints(bool _constrained)
Enables/Disables joint angles constraints.
virtual yarp::sig::Vector iterate(yarp::sig::Vector &xd, const unsigned int verbose=0)=0
Executes one iteration of the control algorithm.
virtual double dist() const
Returns the actual distance from the target in cartesian space (euclidean norm is used).
double norm(const yarp::sig::Matrix &M, int col)
Returns the norm of the vector given in the form: matrix(:,col).
#define IKINCTRL_WATCHDOG_TOL
#define IKINCTRL_INTARGET_TOL
#define IKINCTRL_WATCHDOG_MAXITER
#define IKINCTRL_RET_TOLSIZE
#define IKINCTRL_RET_TOLX
#define IKINCTRL_STATE_DEADLOCK
#define IKINCTRL_RET_MAXITER
#define IKINCTRL_POSE_XYZ
#define IKINCTRL_RET_EXHALT
#define IKINCTRL_STEEP_JT
#define IKINCTRL_POSE_ANG
#define IKINCTRL_STATE_INTARGET
#define IKINCTRL_STATE_RUNNING
#define IKINCTRL_RET_TOLQ