00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 
00010 
00011 
00012 
00013 
00014 
00015 
00016 
00017 
00018 
00019 
00020 
00021 
00022 
00023 
00024 
00025 
00026 
00027 
00028 
00029 
00030 
00031 
00032 
00033 
00034 
00035 
00036 
00037 
00038 
00039 
00040 
00041 
00042 
00043 
00044 
00045 #ifndef EKF_3DMODEL_HPP_
00046 #define EKF_3DMODEL_HPP_
00047 #include <labust/navigation/SSModel.hpp>
00048 
00049 namespace labust
00050 {
00051   namespace navigation
00052   {
00056     class EKF_3D_USBLModel : public SSModel<double>
00057     {
00058         typedef SSModel<double> Base;
00059     public:
00060       typedef vector input_type;
00061       typedef vector output_type;
00062 
00063       struct ModelParams
00064       {
00065           ModelParams():
00066                   alpha(1),
00067                   beta(1),
00068                   betaa(0){};
00069 
00070           ModelParams(double alpha, double beta, double betaa):
00071                   alpha(alpha),
00072                   beta(beta),
00073                   betaa(betaa){}
00074 
00075           inline double Beta(double val)
00076           {
00077                   return beta + betaa*fabs(val);
00078           }
00079 
00080           double alpha, beta, betaa;
00081       };
00082 
00083       enum {u=0,v,w,p,q,r,xp,yp,zp,phi,theta,psi,xc,yc,b,buoyancy,roll_restore,pitch_restore,altitude,xb,yb,zb,stateNum};
00084       enum {X=0,Y,Z,Kroll,M,N,inputSize};
00085       enum {range=stateNum,bearing,elevation,measSize};
00086 
00087       
00088 
00089 
00093       EKF_3D_USBLModel();
00097       ~EKF_3D_USBLModel();
00098 
00104       void step(const input_type& input);
00110       void estimate_y(output_type& y);
00114       void initModel();
00115 
00119       const output_type& update(vector& measurements, vector& newMeas);
00120 
00124       void setParameters(const ModelParams& surge,
00125                   const ModelParams& sway,
00126                   const ModelParams& heave,
00127                   const ModelParams& roll,
00128                   const ModelParams& pitch,
00129                   const ModelParams& yaw)
00130       {
00131           this->surge = surge;
00132           this->sway = sway;
00133           this->heave = heave;
00134           this->roll = roll;
00135           this->pitch = pitch;
00136           this->yaw = yaw;
00137       }
00138 
00139       void calculateXYInovationVariance(const matrix& P, double& xin,double &yin);
00140       void calculateUVInovationVariance(const matrix& P, double& uin,double &vin);
00141       double calculateAltInovationVariance(const matrix& P);
00142 
00146       inline void getNEDSpeed(double& xdot, double& ydot)
00147       {
00148         xdot = this->xdot;
00149         ydot = this->ydot;
00150       }
00151 
00152       inline void useDvlModel(int flag){this->dvlModel = flag;};
00153 
00154     protected:
00158       void derivativeAW();
00162        void derivativeHV(int num);
00166        void derivativeH();
00170       ModelParams surge,sway,heave,roll,pitch,yaw;
00174       output_type measurement;
00178       double xdot,ydot;
00182       int dvlModel;
00186       matrix Hnl;
00190       vector ynl,y;
00191     };
00192   }
00193 }
00194 
00195 
00196 #endif