GCOP
1.0
|
00001 #ifndef GCOP_KINBODY3DCOST_H 00002 #define GCOP_KINBODY3DCOST_H 00003 00004 #include "kinbody3d.h" 00005 #include "kinbody3dtrack.h" 00006 #include "lqcost.h" 00007 00008 namespace gcop { 00009 00010 using namespace std; 00011 using namespace Eigen; 00012 00013 template <int _nu = 6> 00014 class Kinbody3dCost : public LqCost<Matrix4d, 6, _nu> { 00015 00016 typedef Matrix<double, 6, 1> Vector6d; 00017 typedef Matrix<double, 6, 6> Matrix6d; 00018 typedef Matrix<double, _nu, 1> Vectorud; 00019 00020 public: 00021 00022 Kinbody3dCost(Kinbody3d<_nu> &sys, double tf, const Matrix4d &xf, bool diag = true); 00023 00024 /* double L(double t, const Body3dState &x, const Vectorcd &u, 00025 Vector12d *Lx = 0, Matrix12d *Lxx = 0, 00026 Vectorcd *Lu = 0, Matrixcd *Luu = 0, 00027 Matrix12xcd *Lxu = 0); 00028 */ 00029 Kinbody3dTrack<_nu> *track; 00030 double ko; 00031 }; 00032 00033 template <int _nu> 00034 Kinbody3dCost<_nu>::Kinbody3dCost(Kinbody3d<_nu> &sys, double tf, const Matrix4d &xf, bool diag) : 00035 LqCost<Matrix4d, 6, _nu>(sys, tf, xf, diag) { 00036 00037 /* 00038 Q(0,0) = .05; 00039 Q(1,1) = .05; 00040 Q(2,2) = .05; 00041 Q(3,3) = .1; 00042 Q(4,4) = .1; 00043 Q(5,5) = .1; 00044 Q(6,6) = 0; 00045 Q(7,7) = 0; 00046 Q(8,8) = 0; 00047 Q(9,9) = 0; 00048 Q(10,10) = 0; 00049 Q(11,11) = 0; 00050 */ 00051 00052 this->Qf(0,0) = .5; 00053 this->Qf(1,1) = .5; 00054 this->Qf(2,2) = .5; 00055 this->Qf(3,3) = 5; 00056 this->Qf(4,4) = 5; 00057 this->Qf(5,5) = 5; 00058 00059 this->R.diagonal() = Matrix<double, _nu, 1>::Constant(.1); 00060 } 00061 /* 00062 template <int c> 00063 double Body3dCost<c>::L(double t, const Body3dState &x, const Matrix<double, c, 1> &u, 00064 Vector12d *Lx, Matrix12d *Lxx, 00065 Matrix<double, c, 1> *Lu, Matrix<double, c, c> *Luu, 00066 Matrix<double, 12, c> *Lxu) 00067 { 00068 Vector12d dx; 00069 this->X.Lift(dx, this->xf, x); 00070 00071 00072 // check if final state 00073 if (t > this->tf - 1e-10) { 00074 if (Lx) { 00075 if (this->diag) 00076 *Lx = this->Qf.diagonal().cwiseProduct(dx); 00077 else 00078 *Lx = this->Qf*dx; 00079 00080 // add dcayinv if this->Q(1:3,1:3) != a*Id 00081 // (*Lx).head(3) = Rt*(*Lx).head<3>(); 00082 } 00083 if (Lxx) { 00084 *Lxx = this->Qf; 00085 // (*Lxx).topLeftCorner(3,3) = Rt*(*Lxx).topLeftCorner<3,3>()*R; 00086 } 00087 00088 if (Lu) 00089 Lu->setZero(); 00090 if (Luu) 00091 Luu->setZero(); 00092 if (Lxu) 00093 Lxu->setZero(); 00094 00095 if (this->diag) 00096 return dx.dot(this->Qf.diagonal().cwiseProduct(dx))/2; 00097 else 00098 return dx.dot(this->Qf*dx)/2; 00099 00100 } else { 00101 if (Lx) { 00102 if (this->diag) 00103 *Lx = this->Q.diagonal().cwiseProduct(dx); 00104 else 00105 *Lx = this->Q*dx; 00106 // (*Lx).head<3>() = Rat*(*Lx).head<3>(); 00107 } 00108 if (Lxx) { 00109 *Lxx = this->Q; 00110 // (*Lxx).topLeftCorner<3,3>() = Rt*this->Q.topLeftCorner<3,3>()*R; 00111 } 00112 if (Lu) 00113 if (this->diag) 00114 *Lu = this->R.diagonal().cwiseProduct(u); 00115 else 00116 *Lu = this->R*u; 00117 00118 if (Luu) 00119 *Luu = this->R; 00120 00121 if (Lxu) 00122 Lxu->setZero(); 00123 00124 if (this->diag) 00125 return (dx.dot(this->Q.diagonal().cwiseProduct(dx)) + u.dot(this->R.diagonal().cwiseProduct(u)))/2; 00126 else 00127 return (dx.dot(this->Q*dx) + u.dot(this->R*u))/2; 00128 } 00129 } 00130 */ 00131 } 00132 00133 00134 #endif