21#include <yarp/math/SVD.h>
25using namespace yarp::sig;
26using namespace yarp::math;
51 const Matrix &_I,
const string &_info,
const NewEulMode _mode,
BodyPart _bodyPart,
unsigned int verb)
52:
iDynSensor(_c, sensLink, _H, _HC, _m, _I, _info, _mode, verb), bodyPart(_bodyPart){}
73 for(dynContactList::const_iterator it=contacts.begin();it!=contacts.end();it++)
101 if(
chain->NE == NULL)
104 chain->initNewtonEuler();
108 chain->computeKinematicNewtonEuler();
112 unsigned int firstContactLink, lastContactLink;
117 if(firstContactLink<
lSens)
120 fprintf(stderr,
"Contacts before the sensor link. Impossible to compute the external contacts!\n");
126 if(firstContactLink==
lSens)
132 else if(firstContactLink>
lSens+1)
133 chain->NE->ForwardWrenchFromAtoB(
lSens+1, firstContactLink-1);
137 chain->NE->BackwardWrenchFromAtoB(
chain->getN()-1, lastContactLink);
141 Matrix
A =
buildA(firstContactLink, lastContactLink);
142 Vector B =
buildB(firstContactLink, lastContactLink);
144 Vector X = pinv_A * B;
147 unsigned int unknownInd = 0;
151 if(it->isForceDirectionKnown())
152 it->setForceModule( X(unknownInd++));
156 R =
H.submatrix(0,2,0,2);
157 it->setForce( R * X.subVector(unknownInd, unknownInd+2));
159 if(!it->isMomentKnown())
161 it->setMoment(R * X.subVector(unknownInd, unknownInd+2));
168 if(firstContactLink==
lSens)
185 chain->NE->computeTorques();
191 Matrix
A(6, unknownNum);
198 unsigned int colInd = 0;
200 Matrix eye3x3 = eye(3,3);
201 Matrix zero3x3 =
zeros(3,3);
202 Vector r, temp1, temp2;
203 dynContactList::const_iterator it =
contactList.begin();
209 R =
H.submatrix(0,2,0,2);
212 if(it->isForceDirectionKnown())
214 temp1 = R*it->getForceDirection();
215 temp2 = R*it->getCoP();
217 A.setSubcol(temp1, 0, colInd);
218 A.setSubcol(
cross(temp2, temp1), 3, colInd++);
222 temp1 = R*it->getCoP();
224 A.setSubmatrix(eye3x3, 0, colInd);
225 A.setSubmatrix(crossProductMatrix(temp1), 3, colInd);
228 if(!it->isMomentKnown())
230 A.setSubmatrix(zero3x3, 0, colInd);
231 A.setSubmatrix(eye3x3, 3, colInd);
247 Matrix Hlast =
getHFromAtoB(firstContactLink-1, lastContactLink);
248 Matrix Rlast = Hlast.submatrix(0,2,0,2);
249 Vector rLast = Hlast.subcol(0,3,3);
251 Vector Bforce = Rlast *
chain->getForce(lastContactLink);
252 Bforce -=
chain->getForce(firstContactLink-1);
255 for(
unsigned int i=firstContactLink; i<=lastContactLink; i++)
258 R =
H.submatrix(0,2,0,2);
259 Bforce +=
chain->getMass(i) * R *
chain->getLinAccCOM(i);
267 Vector Bmoment = Rlast *
chain->getMoment(lastContactLink);
268 Bmoment -=
chain->getMoment(firstContactLink-1);
269 Bmoment +=
cross(rLast, Rlast*
chain->getForce(lastContactLink));
276 for(
unsigned int i=firstContactLink; i<=lastContactLink; i++)
278 link =
chain->refLink(i);
282 R =
H.submatrix(0,2,0,2);
290 return cat(Bforce, Bmoment);
301 int eeInd =
chain->getN()-1;
303 if(it->getLinkNumber() == eeInd)
304 return it->getForceMoment();
310 dynContactList::const_iterator it=
contactList.begin();
311 firstLink =
chain->getN()+1;
316 unsigned int l = it->getLinkNumber();
335 Matrix
H =
chain->refLink(a+1)->getH();
336 for(
unsigned int i=a+2; i<=b; i++)
337 H *=
chain->refLink(i)->getH();
345 Matrix H_r20 =
chain->getH0();
346 Matrix R_r2L = H_r20.submatrix(0,2,0,2) * H_02L.submatrix(0,2,0,2);
352 dynContactList::const_iterator it=
contactList.begin();
353 unsigned int unknowns=0;
357 if(it->isMomentKnown())
359 if(it->isForceDirectionKnown())
A class for setting a virtual sensor link.
A Base class for defining a Serial Link Chain, using dynamics and kinematics.
NewEulMode mode
static/dynamic/etc..
SensorLinkNewtonEuler * sens
the sensor
unsigned int lSens
the link where the sensor is attached to
unsigned int verbose
verbosity flag
iDynChain * chain
the iDynChain describing the robotic chain
A base class for defining a Link with standard Denavit-Hartenberg convention, providing kinematic and...
const yarp::sig::Matrix & getInertia() const
Get the inertia matrix.
const yarp::sig::Vector & getLinAccC() const
Get the linear acceleration of the COM.
const yarp::sig::Matrix & getCOM() const
Get the roto-translational matrix describing the COM.
double getMass() const
Get the link mass.
const yarp::sig::Vector & getW() const
Get the angular velocity of the link.
const yarp::sig::Vector & getdW() const
Get the angular acceleration of the link.
A class for computing forces and torques in a iDynChain, when a force/torque sensor is placed in the ...
bool setSensorMeasures(const yarp::sig::Vector &F, const yarp::sig::Vector &Mu)
Set the sensor measured force and moment.
iDynSensor(iDyn::iDynChain *_c, std::string _info, const NewEulMode _mode=DYNAMIC, unsigned int verb=iCub::skinDynLib::NO_VERBOSE)
Constructor without FT sensor: the sensor must be set with setSensor().
yarp::sig::Vector cross(const yarp::sig::Matrix &A, int colA, const yarp::sig::Matrix &B, int colB)
Returns the cross product between two vectors given in the form: matrix(:,col).
static double const TOLLERANCE
const std::string BodyPart_s[]