Add null space task for IK.

This commit is contained in:
yunfeibai
2016-09-29 17:12:51 -07:00
parent 0ee12475af
commit 94c7bbe8e3
3 changed files with 39 additions and 15 deletions

View File

@@ -337,24 +337,31 @@ void Jacobian::CalcDeltaThetasDLSwithNullspace()
U.Solve( dS, &dT1 ); U.Solve( dS, &dT1 );
J.MultiplyTranspose( dT1, dTheta ); J.MultiplyTranspose( dT1, dTheta );
VectorRn nullV(7); // Desired velocity
nullV.SetZero(); VectorRn desiredV(J.GetNumColumns());
nullV.Set(1, 2.0); desiredV.SetZero();
MatrixRmn I(U.GetNumRows(),U.GetNumColumns()); desiredV.Set(3, -0.2);
I.SetIdentity();
// Compute JInv in damped least square form
MatrixRmn UInv(U.GetNumRows(),U.GetNumColumns()); MatrixRmn UInv(U.GetNumRows(),U.GetNumColumns());
U.ComputeInverse(UInv); U.ComputeInverse(UInv);
MatrixRmn Res(U.GetNumRows(),U.GetNumColumns()); assert(U.DebugCheckInverse(UInv));
MatrixRmn::Multiply(U, UInv, Res); MatrixRmn JInv(J.GetNumColumns(), J.GetNumRows());
for (int i = 0; i < Res.GetNumRows(); ++i) MatrixRmn::TransposeMultiply(J, UInv, JInv);
{
for (int j = 0; j < Res.GetNumColumns(); ++j)
{
printf("i%d j%d: %f\n", i, j, Res.Get(i, j));
}
}
// Compute null space projection
MatrixRmn JInvJ(J.GetNumColumns(), J.GetNumColumns());
MatrixRmn::Multiply(JInv, J, JInvJ);
MatrixRmn P(J.GetNumColumns(), J.GetNumColumns());
P.SetIdentity();
P -= JInvJ;
// Compute null space velocity
VectorRn nullV(J.GetNumColumns());
P.Multiply(desiredV, nullV);
// Add null space velocity
dTheta += nullV;
// Scale back to not exceed maximum angle changes // Scale back to not exceed maximum angle changes
double maxChange = dTheta.MaxAbs(); double maxChange = dTheta.MaxAbs();

View File

@@ -973,6 +973,21 @@ bool MatrixRmn::DebugCheckSVD( const MatrixRmn& U, const VectorRn& w, const Matr
return ret; return ret;
} }
bool MatrixRmn::DebugCheckInverse( const MatrixRmn& MInv ) const
{
assert ( this->NumRows==this->NumCols );
assert ( MInv.NumRows==MInv.NumCols );
MatrixRmn I(this->NumRows, this->NumCols);
I.SetIdentity();
MatrixRmn MMInv(this->NumRows, this->NumCols);
Multiply(*this, MInv, MMInv);
I -= MMInv;
double error = I.FrobeniusNorm();
bool ret = ( fabs(error)<=1.0e-13 );
assert ( ret );
return ret;
}
bool MatrixRmn::DebugCalcBidiagCheck( const MatrixRmn& U, const VectorRn& w, const VectorRn& superDiag, const MatrixRmn& V ) const bool MatrixRmn::DebugCalcBidiagCheck( const MatrixRmn& U, const VectorRn& w, const VectorRn& superDiag, const MatrixRmn& V ) const
{ {
// Special SVD test code // Special SVD test code

View File

@@ -131,6 +131,8 @@ public:
bool DebugCheckSVD( const MatrixRmn& U, const VectorRn& w, const MatrixRmn& V ) const; bool DebugCheckSVD( const MatrixRmn& U, const VectorRn& w, const MatrixRmn& V ) const;
// Compute inverse of a matrix, the result is written in R // Compute inverse of a matrix, the result is written in R
void ComputeInverse( MatrixRmn& R) const; void ComputeInverse( MatrixRmn& R) const;
// Debug matrix inverse computation
bool DebugCheckInverse( const MatrixRmn& MInv ) const;
// Some useful routines for experts who understand the inner workings of these classes. // Some useful routines for experts who understand the inner workings of these classes.
inline static double DotArray( long length, const double* ptrA, long strideA, const double* ptrB, long strideB ); inline static double DotArray( long length, const double* ptrA, long strideA, const double* ptrB, long strideB );