00001 /** 00002 * @file ConstantSpeedModel.h 00003 * Contains a KalmanBallLocator process model for balls with constant speed 00004 * 00005 * @author <a href="mailto:stefanuhrig@gmx.net">Stefan Uhrig</a> 00006 */ 00007 //------------------------------------------------------------------------------ 00008 #ifndef CONSTANTSPEEDMODEL_H_INCLUDED 00009 #define CONSTANTSPEEDMODEL_H_INCLUDED 00010 //------------------------------------------------------------------------------ 00011 #include "BaseModel.h" 00012 #include "Tools/Math/Vector_n.h" 00013 #include "Tools/Math/Matrix_nxn.h" 00014 #include "Tools/Math/Matrix2x2.h" 00015 #include "Tools/Math/Geometry.h" 00016 #include "Tools/Debugging/DebugDrawings.h" 00017 //------------------------------------------------------------------------------ 00018 /** 00019 * @class KalmanConstantSpeedModel 00020 * Contains a KalmanBallLocator process model for balls with constant speed 00021 */ 00022 class KalmanConstantSpeedModel : public KalmanProcessModelBase 00023 { 00024 public: 00025 KalmanConstantSpeedModel(); 00026 virtual ~KalmanConstantSpeedModel(); 00027 00028 public: 00029 virtual const char* getModelName() const { return "ConstantSpeedModel"; } 00030 00031 virtual int getStateDim() const { return 4; } 00032 virtual void getP(double* pDest) const { P.copyTo(pDest); } 00033 virtual void getQ(double* pDest) const { globQ.copyTo(pDest); } 00034 virtual void setQ(const double* pSource) { globQ = pSource; } 00035 virtual void getR(double* pDest) const { globR.copyTo(pDest); } 00036 virtual void setR(double* pSource) { globR = pSource; } 00037 00038 virtual void reset(); 00039 virtual KalmanUpdateResult update(double time, double x, double y, 00040 const RobotPose& pose, 00041 double panningVelocity); 00042 virtual KalmanPredictResult predict(double time); 00043 00044 virtual void adapt(const OdometryData& lastOdometry, 00045 const OdometryData& actualOdometry); 00046 00047 private: 00048 /** 00049 * Calculates the coefficients for the variance adpation Polynom. 00050 * @param x The x values to take 00051 * @param fx The f(x) values at the x positions 00052 * @param result The resultung coefficients 00053 */ 00054 void calculateVarianceAdaptionPolynom(double x[2], double fx[2], 00055 double result[2]); 00056 00057 const double panningVelocityThreshold; 00058 00059 /** 00060 * Actual state: 00061 * x_act[0] is x-position in meters relative to robot 00062 * x_act[1] is y-position in meters relative to robot 00063 * x_act[2] is x-direction speed in meters per second 00064 * x_act[3] is y-direction speed in meters per second 00065 */ 00066 Vector_n<double, 4> x_act; 00067 Vector_n<double, 4> z; ///< measured state 00068 Matrix_nxn<double, 4> A; ///< linear process model matrix 00069 Matrix_nxn<double, 4> P; ///< internal covariance matrix 00070 Matrix_nxn<double, 4> Q; ///< process model error covariance matrix 00071 Matrix_nxn<double, 4> R; ///< measurement error covariance matrix 00072 00073 enum InitState 00074 { 00075 NotInited, 00076 PositionInited, 00077 Ready 00078 }; 00079 InitState initState; ///< initialization state of the filter 00080 double lastLiklihood; ///< last liklihood of model (for predict function) 00081 double lastTime; ///< last time update permormed 00082 00083 // Temporary variables for permorming updates und predictions 00084 Vector_n<double, 4> x_minus; 00085 Matrix_nxn<double, 4> P_minus; 00086 Matrix_nxn<double, 4> K; 00087 Vector_n<double, 4> x_predict; 00088 Matrix_nxn<double, 4> C; 00089 Matrix_nxn<double, 4> C_inv; 00090 00091 /// global process covariance matrix that is adapted with dt 00092 Matrix_nxn<double, 4> globQ; 00093 /// global measurement covariance matrix 00094 Matrix_nxn<double, 4> globR; 00095 00096 /** 00097 * Coefficients of polynom of degree 2 for variance adaption 00098 * Constant coefficient is the last one 00099 */ 00100 double varianceAdaptionPosition[3]; 00101 double varianceAdaptionSpeed[3]; 00102 00103 static double defaultA[16]; ///< default linear process model matrix 00104 static double defaultP[16]; ///< default internal covariance matrix 00105 static double defaultQ[16]; ///< default process error covariance matrix 00106 static double defaultR[16]; ///< default measurement error covariance matrix 00107 }; 00108 //------------------------------------------------------------------------------ 00109 #endif 00110 //------------------------------------------------------------------------------ 00111 00112 /* 00113 * Change log : 00114 * $Log: ConstantSpeedModel.h,v $ 00115 * Revision 1.1 2004/07/14 21:40:15 spranger 00116 * moved kalmanprocessmodel to gt2004processmodel 00117 * 00118 * Revision 1.7 2004/07/07 10:15:39 uhrig 00119 * Fixed doucmentation (for doxygen) 00120 * 00121 * Revision 1.6 2004/06/22 09:43:17 nistico 00122 * The radial component of the measurement variance is 00123 * also affected by panning velocity now 00124 * 00125 * Revision 1.5 2004/06/18 10:24:51 nistico 00126 * Kalman measurement covariance matrix now adjusted also based on 00127 * head panning angular velocity 00128 * 00129 * Revision 1.4 2004/06/16 17:57:00 nistico 00130 * Speed covariance submatrix dynamically calculated 00131 * based on distance from ball 00132 * More detailed identification of exception 00133 * Bug fixes 00134 * 00135 * Revision 1.3 2004/06/15 22:14:10 uhrig 00136 * Tidied up a little bit 00137 * 00138 * Revision 1.2 2004/06/15 17:33:00 nistico 00139 * Measurement model for position now depends on distance, retuned speed 00140 * component variance. 00141 * The code needs to be cleaned up and beautified. 00142 * 00143 * Revision 1.1.1.1 2004/05/22 17:15:25 cvsadm 00144 * created new repository GT2004_WM 00145 * 00146 * Revision 1.3 2004/04/20 14:12:16 uhrig 00147 * - odometry processing corrected 00148 * - fixed position model disabled 00149 * - covariance matrices tuned 00150 * 00151 * Revision 1.2 2004/03/15 12:28:52 risler 00152 * change log added 00153 * 00154 * 00155 */