00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 namespace KDL {
00021
00022
00024
00025 VectorAcc operator + (const VectorAcc& r1,const VectorAcc& r2) {
00026 return VectorAcc(r1.p+r2.p,r1.v+r2.v,r1.dv+r2.dv);
00027 }
00028
00029 VectorAcc operator - (const VectorAcc& r1,const VectorAcc& r2) {
00030 return VectorAcc(r1.p-r2.p, r1.v-r2.v, r1.dv-r2.dv);
00031 }
00032 VectorAcc operator + (const Vector& r1,const VectorAcc& r2) {
00033 return VectorAcc(r1+r2.p,r2.v,r2.dv);
00034 }
00035
00036 VectorAcc operator - (const Vector& r1,const VectorAcc& r2) {
00037 return VectorAcc(r1-r2.p, -r2.v, -r2.dv);
00038 }
00039 VectorAcc operator + (const VectorAcc& r1,const Vector& r2) {
00040 return VectorAcc(r1.p+r2,r1.v,r1.dv);
00041 }
00042
00043 VectorAcc operator - (const VectorAcc& r1,const Vector& r2) {
00044 return VectorAcc(r1.p-r2, r1.v, r1.dv);
00045 }
00046
00047
00048 VectorAcc operator - (const VectorAcc& r) {
00049 return VectorAcc(-r.p,-r.v,-r.dv);
00050 }
00051
00052
00053 VectorAcc operator * (const VectorAcc& r1,const VectorAcc& r2) {
00054 return VectorAcc(r1.p*r2.p,
00055 r1.p*r2.v+r1.v*r2.p,
00056 r1.dv*r2.p+2*r1.v*r2.v+r1.p*r2.dv
00057 );
00058 }
00059
00060 VectorAcc operator * (const VectorAcc& r1,const Vector& r2) {
00061 return VectorAcc(r1.p*r2, r1.v*r2, r1.dv*r2 );
00062 }
00063
00064 VectorAcc operator * (const Vector& r1,const VectorAcc& r2) {
00065 return VectorAcc(r1*r2.p, r1*r2.v, r1*r2.dv );
00066 }
00067
00068
00069
00070
00071 VectorAcc operator * (double r1,const VectorAcc& r2) {
00072 return VectorAcc(r1*r2.p, r1*r2.v, r1*r2.dv );
00073 }
00074
00075 VectorAcc operator * (const VectorAcc& r1,double r2) {
00076 return VectorAcc(r1.p*r2, r1.v*r2, r1.dv*r2 );
00077 }
00078
00079 VectorAcc operator * (const doubleAcc& r1,const VectorAcc& r2) {
00080 return VectorAcc(r1.t*r2.p,
00081 r1.t*r2.v + r1.d*r2.p,
00082 r1.t*r2.dv + 2*r1.d*r2.v + r1.dd*r2.p
00083 );
00084 }
00085
00086 VectorAcc operator * (const VectorAcc& r2,const doubleAcc& r1) {
00087 return VectorAcc(r1.t*r2.p,
00088 r1.t*r2.v + r1.d*r2.p,
00089 r1.t*r2.dv + 2*r1.d*r2.v + r1.dd*r2.p
00090 );
00091 }
00092
00093 VectorAcc& VectorAcc::operator = (const VectorAcc& arg) {
00094 p=arg.p;
00095 v=arg.v;
00096 dv=arg.dv;
00097 return *this;
00098 }
00099
00100 VectorAcc& VectorAcc::operator = (const Vector& arg) {
00101 p=arg;
00102 v=Vector::Zero();
00103 dv=Vector::Zero();
00104 return *this;
00105 }
00106
00107 VectorAcc& VectorAcc::operator += (const VectorAcc& arg) {
00108 p+=arg.p;
00109 v+=arg.v;
00110 dv+= arg.dv;
00111 return *this;
00112 }
00113 VectorAcc& VectorAcc::operator -= (const VectorAcc& arg) {
00114 p-=arg.p;
00115 v-=arg.v;
00116 dv-=arg.dv;
00117 return *this;
00118 }
00119
00120 VectorAcc VectorAcc::Zero() {
00121 return VectorAcc(Vector::Zero(),Vector::Zero(),Vector::Zero());
00122 }
00123
00124 void VectorAcc::ReverseSign() {
00125 p.ReverseSign();
00126 v.ReverseSign();
00127 dv.ReverseSign();
00128 }
00129
00130 doubleAcc VectorAcc::Norm() {
00131 doubleAcc res;
00132 res.t = p.Norm();
00133 res.d = dot(p,v)/res.t;
00134 res.dd = (dot(p,dv)+dot(v,v)-res.d*res.d)/res.t;
00135 return res;
00136 }
00137
00138 doubleAcc dot(const VectorAcc& lhs,const VectorAcc& rhs) {
00139 return doubleAcc( dot(lhs.p,rhs.p),
00140 dot(lhs.p,rhs.v)+dot(lhs.v,rhs.p),
00141 dot(lhs.p,rhs.dv)+2*dot(lhs.v,rhs.v)+dot(lhs.dv,rhs.p)
00142 );
00143 }
00144
00145 doubleAcc dot(const VectorAcc& lhs,const Vector& rhs) {
00146 return doubleAcc( dot(lhs.p,rhs),
00147 dot(lhs.v,rhs),
00148 dot(lhs.dv,rhs)
00149 );
00150 }
00151
00152 doubleAcc dot(const Vector& lhs,const VectorAcc& rhs) {
00153 return doubleAcc( dot(lhs,rhs.p),
00154 dot(lhs,rhs.v),
00155 dot(lhs,rhs.dv)
00156 );
00157 }
00158
00159
00160 bool Equal(const VectorAcc& r1,const VectorAcc& r2,double eps) {
00161 return (Equal(r1.p,r2.p,eps)
00162 && Equal(r1.v,r2.v,eps)
00163 && Equal(r1.dv,r2.dv,eps)
00164 );
00165 }
00166
00167 bool Equal(const Vector& r1,const VectorAcc& r2,double eps) {
00168 return (Equal(r1,r2.p,eps)
00169 && Equal(Vector::Zero(),r2.v,eps)
00170 && Equal(Vector::Zero(),r2.dv,eps)
00171 );
00172 }
00173
00174 bool Equal(const VectorAcc& r1,const Vector& r2,double eps) {
00175 return (Equal(r1.p,r2,eps)
00176 && Equal(r1.v,Vector::Zero(),eps)
00177 && Equal(r1.dv,Vector::Zero(),eps)
00178 );
00179 }
00180
00181 VectorAcc operator / (const VectorAcc& r1,double r2) {
00182 return r1*(1.0/r2);
00183 }
00184
00185 VectorAcc operator / (const VectorAcc& r2,const doubleAcc& r1) {
00186 return r2*(1.0/r1);
00187 }
00188
00189
00190
00192
00193 RotationAcc operator* (const RotationAcc& r1,const RotationAcc& r2) {
00194 return RotationAcc( r1.R * r2.R,
00195 r1.w + r1.R*r2.w,
00196 r1.dw + r1.w*(r1.R*r2.w) + r1.R*r2.dw
00197 );
00198 }
00199
00200 RotationAcc operator* (const Rotation& r1,const RotationAcc& r2) {
00201 return RotationAcc( r1*r2.R, r1*r2.w, r1*r2.dw);
00202 }
00203
00204 RotationAcc operator* (const RotationAcc& r1,const Rotation& r2) {
00205 return RotationAcc( r1.R*r2, r1.w, r1.dw );
00206 }
00207
00208 RotationAcc& RotationAcc::operator = (const RotationAcc& arg) {
00209 R=arg.R;
00210 w=arg.w;
00211 dw=arg.dw;
00212 return *this;
00213 }
00214 RotationAcc& RotationAcc::operator = (const Rotation& arg) {
00215 R = arg;
00216 w = Vector::Zero();
00217 dw = Vector::Zero();
00218 return *this;
00219 }
00220
00221 RotationAcc RotationAcc::Identity() {
00222 return RotationAcc(Rotation::Identity(),Vector::Zero(),Vector::Zero());
00223 }
00224
00225 RotationAcc RotationAcc::Inverse() const {
00226 return RotationAcc(R.Inverse(),-R.Inverse(w),-R.Inverse(dw));
00227 }
00228
00229 VectorAcc RotationAcc::Inverse(const VectorAcc& arg) const {
00230 VectorAcc tmp;
00231 tmp.p = R.Inverse(arg.p);
00232 tmp.v = R.Inverse(arg.v - w * arg.p);
00233 tmp.dv = R.Inverse(arg.dv - dw*arg.p - w*(arg.v+R*tmp.v));
00234 return tmp;
00235 }
00236
00237 VectorAcc RotationAcc::Inverse(const Vector& arg) const {
00238 VectorAcc tmp;
00239 tmp.p = R.Inverse(arg);
00240 tmp.v = R.Inverse(-w*arg);
00241 tmp.dv = R.Inverse(-dw*arg - w*(R*tmp.v));
00242 return tmp;
00243 }
00244
00245
00246 VectorAcc RotationAcc::operator*(const VectorAcc& arg) const {
00247 VectorAcc tmp;
00248 tmp.p = R*arg.p;
00249 tmp.dv = R*arg.v;
00250 tmp.v = w*tmp.p + tmp.dv;
00251 tmp.dv = dw*tmp.p + w*(tmp.v + tmp.dv) + R*arg.dv;
00252 return tmp;
00253 }
00254
00255 VectorAcc operator*(const Rotation& R,const VectorAcc& x) {
00256 return VectorAcc(R*x.p,R*x.v,R*x.dv);
00257 }
00258
00259 VectorAcc RotationAcc::operator*(const Vector& arg) const {
00260 VectorAcc tmp;
00261 tmp.p = R*arg;
00262 tmp.v = w*tmp.p;
00263 tmp.dv = dw*tmp.p + w*tmp.v;
00264 return tmp;
00265 }
00266
00267
00268
00269
00270
00271
00272
00273
00274
00275
00276
00277
00278
00279
00280
00281
00282
00283
00284
00285
00286
00287
00288
00289
00290
00291
00292
00293
00294
00295
00296
00297
00298
00299
00300
00301
00302
00303
00304
00305
00306
00307
00308
00309
00310
00311
00312
00313
00314
00315
00316
00317
00318
00319
00320
00321
00322
00323
00324 bool Equal(const RotationAcc& r1,const RotationAcc& r2,double eps) {
00325 return (Equal(r1.w,r2.w,eps) && Equal(r1.R,r2.R,eps) && Equal(r1.dw,r2.dw,eps) );
00326 }
00327 bool Equal(const Rotation& r1,const RotationAcc& r2,double eps) {
00328 return (Equal(Vector::Zero(),r2.w,eps) && Equal(r1,r2.R,eps) &&
00329 Equal(Vector::Zero(),r2.dw,eps) );
00330 }
00331 bool Equal(const RotationAcc& r1,const Rotation& r2,double eps) {
00332 return (Equal(r1.w,Vector::Zero(),eps) && Equal(r1.R,r2,eps) &&
00333 Equal(r1.dw,Vector::Zero(),eps) );
00334 }
00335
00336
00337
00338
00339 FrameAcc& FrameAcc::operator = (const FrameAcc& arg) {
00340 M=arg.M;
00341 p=arg.p;
00342 return *this;
00343 }
00344
00345 FrameAcc FrameAcc::Identity() {
00346 return FrameAcc(RotationAcc::Identity(),VectorAcc::Zero());
00347 }
00348
00349
00350 FrameAcc operator *(const FrameAcc& lhs,const FrameAcc& rhs)
00351 {
00352 return FrameAcc(lhs.M*rhs.M,lhs.M*rhs.p+lhs.p);
00353 }
00354 FrameAcc operator *(const FrameAcc& lhs,const Frame& rhs)
00355 {
00356 return FrameAcc(lhs.M*rhs.M,lhs.M*rhs.p+lhs.p);
00357 }
00358 FrameAcc operator *(const Frame& lhs,const FrameAcc& rhs)
00359 {
00360 return FrameAcc(lhs.M*rhs.M,lhs.M*rhs.p+lhs.p);
00361 }
00362
00363 VectorAcc FrameAcc::operator *(const VectorAcc & arg) const
00364 {
00365 return M*arg+p;
00366 }
00367 VectorAcc FrameAcc::operator *(const Vector & arg) const
00368 {
00369 return M*arg+p;
00370 }
00371
00372 VectorAcc FrameAcc::Inverse(const VectorAcc& arg) const
00373 {
00374 return M.Inverse(arg-p);
00375 }
00376
00377 VectorAcc FrameAcc::Inverse(const Vector& arg) const
00378 {
00379 return M.Inverse(arg-p);
00380 }
00381
00382 FrameAcc FrameAcc::Inverse() const
00383 {
00384 return FrameAcc(M.Inverse(),-M.Inverse(p));
00385 }
00386
00387 FrameAcc& FrameAcc::operator =(const Frame & arg)
00388 {
00389 M = arg.M;
00390 p = arg.p;
00391 return *this;
00392 }
00393
00394 bool Equal(const FrameAcc& r1,const FrameAcc& r2,double eps) {
00395 return (Equal(r1.M,r2.M,eps) && Equal(r1.p,r2.p,eps));
00396 }
00397 bool Equal(const Frame& r1,const FrameAcc& r2,double eps) {
00398 return (Equal(r1.M,r2.M,eps) && Equal(r1.p,r2.p,eps));
00399 }
00400 bool Equal(const FrameAcc& r1,const Frame& r2,double eps) {
00401 return (Equal(r1.M,r2.M,eps) && Equal(r1.p,r2.p,eps));
00402 }
00403
00404
00405 Frame FrameAcc::GetFrame() const {
00406 return Frame(M.R,p.p);
00407 }
00408
00409
00410 Twist FrameAcc::GetTwist() const {
00411 return Twist(p.v,M.w);
00412 }
00413
00414
00415 Twist FrameAcc::GetAccTwist() const {
00416 return Twist(p.dv,M.dw);
00417 }
00418
00419
00420
00421
00422
00423
00424
00425
00426
00427
00428
00429
00430
00431
00432
00433
00434 TwistAcc TwistAcc::Zero()
00435 {
00436 return TwistAcc(VectorAcc::Zero(),VectorAcc::Zero());
00437 }
00438
00439
00440 void TwistAcc::ReverseSign()
00441 {
00442 vel.ReverseSign();
00443 rot.ReverseSign();
00444 }
00445
00446 TwistAcc TwistAcc::RefPoint(const VectorAcc& v_base_AB)
00447
00448
00449
00450
00451
00452 {
00453 return TwistAcc(this->vel+this->rot*v_base_AB,this->rot);
00454 }
00455
00456 TwistAcc& TwistAcc::operator-=(const TwistAcc& arg)
00457 {
00458 vel-=arg.vel;
00459 rot -=arg.rot;
00460 return *this;
00461 }
00462
00463 TwistAcc& TwistAcc::operator+=(const TwistAcc& arg)
00464 {
00465 vel+=arg.vel;
00466 rot +=arg.rot;
00467 return *this;
00468 }
00469
00470
00471 TwistAcc operator*(const TwistAcc& lhs,double rhs)
00472 {
00473 return TwistAcc(lhs.vel*rhs,lhs.rot*rhs);
00474 }
00475
00476 TwistAcc operator*(double lhs,const TwistAcc& rhs)
00477 {
00478 return TwistAcc(lhs*rhs.vel,lhs*rhs.rot);
00479 }
00480
00481 TwistAcc operator/(const TwistAcc& lhs,double rhs)
00482 {
00483 return TwistAcc(lhs.vel/rhs,lhs.rot/rhs);
00484 }
00485
00486
00487 TwistAcc operator*(const TwistAcc& lhs,const doubleAcc& rhs)
00488 {
00489 return TwistAcc(lhs.vel*rhs,lhs.rot*rhs);
00490 }
00491
00492 TwistAcc operator*(const doubleAcc& lhs,const TwistAcc& rhs)
00493 {
00494 return TwistAcc(lhs*rhs.vel,lhs*rhs.rot);
00495 }
00496
00497 TwistAcc operator/(const TwistAcc& lhs,const doubleAcc& rhs)
00498 {
00499 return TwistAcc(lhs.vel/rhs,lhs.rot/rhs);
00500 }
00501
00502
00503
00504
00505 TwistAcc operator+(const TwistAcc& lhs,const TwistAcc& rhs)
00506 {
00507 return TwistAcc(lhs.vel+rhs.vel,lhs.rot+rhs.rot);
00508 }
00509
00510 TwistAcc operator-(const TwistAcc& lhs,const TwistAcc& rhs)
00511 {
00512 return TwistAcc(lhs.vel-rhs.vel,lhs.rot-rhs.rot);
00513 }
00514
00515
00516 TwistAcc operator-(const TwistAcc& arg)
00517 {
00518 return TwistAcc(-arg.vel,-arg.rot);
00519 }
00520
00521
00522
00523
00524
00525 TwistAcc RotationAcc::Inverse(const TwistAcc& arg) const
00526 {
00527 return TwistAcc(Inverse(arg.vel),Inverse(arg.rot));
00528 }
00529
00530 TwistAcc RotationAcc::operator * (const TwistAcc& arg) const
00531 {
00532 return TwistAcc((*this)*arg.vel,(*this)*arg.rot);
00533 }
00534
00535 TwistAcc RotationAcc::Inverse(const Twist& arg) const
00536 {
00537 return TwistAcc(Inverse(arg.vel),Inverse(arg.rot));
00538 }
00539
00540 TwistAcc RotationAcc::operator * (const Twist& arg) const
00541 {
00542 return TwistAcc((*this)*arg.vel,(*this)*arg.rot);
00543 }
00544
00545
00546 TwistAcc FrameAcc::operator * (const TwistAcc& arg) const
00547 {
00548 TwistAcc tmp;
00549 tmp.rot = M*arg.rot;
00550 tmp.vel = M*arg.vel+p*tmp.rot;
00551 return tmp;
00552 }
00553
00554 TwistAcc FrameAcc::operator * (const Twist& arg) const
00555 {
00556 TwistAcc tmp;
00557 tmp.rot = M*arg.rot;
00558 tmp.vel = M*arg.vel+p*tmp.rot;
00559 return tmp;
00560 }
00561
00562 TwistAcc FrameAcc::Inverse(const TwistAcc& arg) const
00563 {
00564 TwistAcc tmp;
00565 tmp.rot = M.Inverse(arg.rot);
00566 tmp.vel = M.Inverse(arg.vel-p*arg.rot);
00567 return tmp;
00568 }
00569
00570 TwistAcc FrameAcc::Inverse(const Twist& arg) const
00571 {
00572 TwistAcc tmp;
00573 tmp.rot = M.Inverse(arg.rot);
00574 tmp.vel = M.Inverse(arg.vel-p*arg.rot);
00575 return tmp;
00576 }
00577
00578 Twist TwistAcc::GetTwist() const {
00579 return Twist(vel.p,rot.p);
00580 }
00581
00582 Twist TwistAcc::GetTwistDot() const {
00583 return Twist(vel.v,rot.v);
00584 }
00585
00586 bool Equal(const TwistAcc& a,const TwistAcc& b,double eps) {
00587 return (Equal(a.rot,b.rot,eps)&&
00588 Equal(a.vel,b.vel,eps) );
00589 }
00590 bool Equal(const Twist& a,const TwistAcc& b,double eps) {
00591 return (Equal(a.rot,b.rot,eps)&&
00592 Equal(a.vel,b.vel,eps) );
00593 }
00594 bool Equal(const TwistAcc& a,const Twist& b,double eps) {
00595 return (Equal(a.rot,b.rot,eps)&&
00596 Equal(a.vel,b.vel,eps) );
00597 }
00598
00599 }