GCOP  1.0
body2dforce.h
Go to the documentation of this file.
00001 #ifndef GCOP_BODY2DFORCE_H
00002 #define GCOP_BODY2DFORCE_H
00003 
00004 #include "force.h"
00005 #include <utility>
00006 
00007 namespace gcop {
00008   
00009   using namespace std;
00010   using namespace Eigen;
00011 
00012   typedef pair<Matrix3d, Vector3d> Body2dState;
00013   typedef Matrix<double, 3, 6> Matrix36d;
00014 
00015   template<int c = 3>
00016     class Body2dForce : public Force<Body2dState, 3, 6, c> {
00017   public:
00018 
00019   typedef Matrix<double, c, 1> Vectorcd;
00020   typedef Matrix<double, 6, c> Matrix6cd;
00021   typedef Matrix<double, 3, c> Matrix3cd;
00022 
00023   Body2dForce(bool fextParam = false);
00024   
00025   virtual void Set(Vector3d &f, const Body2dState &x, double t, 
00026                    const Vector3d &u, double h, const VectorXd *p = 0,
00027                    Matrix36d *A = 0, Matrix3cd *B = 0, Matrix<double, 3, Dynamic> *C = 0);
00028   
00029   Vector3d D;      
00030   Matrix3cd B;     
00031   Vector3d fext;   
00032   bool fextParam;  
00033   };
00034 
00035   template<int c>
00036     Body2dForce<c>::Body2dForce(bool fextParam) : D(0, 0, 0), fext(0, 0, 0), fextParam(fextParam)
00037     {
00038       B.setIdentity();
00039     }
00040   
00041   
00042   template<int c>
00043     void Body2dForce<c>::Set(Vector3d &f, const Body2dState &x, double t, 
00044                              const Vector3d &u, double h,  const VectorXd *p,
00045                              Matrix36d *A, Matrix3cd *B, Matrix<double, 3, Dynamic> *C)
00046     {
00047       if (fextParam && p) {
00048         fext.tail<2>() = *p;
00049         assert(p->size() == 2);
00050       }
00051       
00052       Vector3d fb; // body-fixed external force
00053       fb[0] = fext[0];
00054       fb.tail<2>() = x.first.topLeftCorner<2,2>().transpose()*fext.tail<2>();    
00055       f = this->B*u - D.cwiseProduct(x.second) + fb;
00056       
00057       if (A) {
00058         A->leftCols<3>().setZero();    
00059         (*A)(1,0) = -fb[2]; (*A)(2,0)= fb[1]; //SE2::r2hat(fb.tail<2>()).tanspose();    
00060         A->rightCols<3>() = Matrix3d((-D).asDiagonal());
00061       }
00062       
00063       if (B) {
00064         *B = this->B;
00065       }
00066       
00067       if (C) {
00068         if (fextParam && p) {
00069           C->topRows<1>().setZero();
00070           C->bottomRows<2>() = x.first.topLeftCorner<2, 2>().transpose();
00071         } else {
00072           C->setZero();
00073         }
00074       }
00075     }
00076 
00077 }
00078 
00079 
00080 #endif