Main MRPT website > C++ reference
MRPT logo
CKalmanFilterCapable.h
Go to the documentation of this file.
1 /* +---------------------------------------------------------------------------+
2  | Mobile Robot Programming Toolkit (MRPT) |
3  | http://www.mrpt.org/ |
4  | |
5  | Copyright (c) 2005-2014, Individual contributors, see AUTHORS file |
6  | See: http://www.mrpt.org/Authors - All rights reserved. |
7  | Released under BSD License. See details in http://www.mrpt.org/License |
8  +---------------------------------------------------------------------------+ */
9 #ifndef CKalmanFilterCapable_H
10 #define CKalmanFilterCapable_H
11 
15 #include <mrpt/math/num_jacobian.h>
16 #include <mrpt/math/utils.h>
17 #include <mrpt/math/num_jacobian.h>
19 #include <mrpt/utils/CTimeLogger.h>
24 #include <mrpt/utils/stl_containers_utils.h> // find_in_vector
25 #include <mrpt/utils/CTicTac.h>
27 #include <mrpt/utils/TEnumType.h>
29 
30 
31 namespace mrpt
32 {
33  namespace bayes
34  {
35  using namespace mrpt::utils;
36  using namespace mrpt::math;
37  using namespace mrpt;
38  using namespace std;
39 
40  /** The Kalman Filter algorithm to employ in bayes::CKalmanFilterCapable
41  * For further details on each algorithm see the tutorial: http://www.mrpt.org/Kalman_Filters
42  * \sa bayes::CKalmanFilterCapable::KF_options
43  * \ingroup mrpt_bayes_grp
44  */
45  enum TKFMethod {
50  };
51 
52  // Forward declaration:
53  template <size_t VEH_SIZE, size_t OBS_SIZE, size_t FEAT_SIZE, size_t ACT_SIZE, typename KFTYPE> class CKalmanFilterCapable;
54 
55  /** Generic options for the Kalman Filter algorithm in itself.
56  * \ingroup mrpt_bayes_grp
57  */
59  {
61  method ( kfEKFNaive),
62  verbose ( false ),
63  IKF_iterations ( 5 ),
64  enable_profiler (false),
65  use_analytic_transition_jacobian (true),
66  use_analytic_observation_jacobian (true),
67  debug_verify_analytic_jacobians (false),
68  debug_verify_analytic_jacobians_threshold (1e-2)
69  {
70  }
71 
73  const mrpt::utils::CConfigFileBase &iniFile,
74  const std::string &section)
75  {
76  method = iniFile.read_enum<TKFMethod>(section,"method", method );
77  MRPT_LOAD_CONFIG_VAR( verbose, bool , iniFile, section );
78  MRPT_LOAD_CONFIG_VAR( IKF_iterations, int , iniFile, section );
79  MRPT_LOAD_CONFIG_VAR( enable_profiler, bool , iniFile, section );
80  MRPT_LOAD_CONFIG_VAR( use_analytic_transition_jacobian, bool , iniFile, section );
81  MRPT_LOAD_CONFIG_VAR( use_analytic_observation_jacobian, bool , iniFile, section );
82  MRPT_LOAD_CONFIG_VAR( debug_verify_analytic_jacobians, bool , iniFile, section );
83  MRPT_LOAD_CONFIG_VAR( debug_verify_analytic_jacobians_threshold, double, iniFile, section );
84  }
85 
86  /** This method must display clearly all the contents of the structure in textual form, sending it to a CStream. */
87  void dumpToTextStream(CStream &out) const
88  {
89  out.printf("\n----------- [TKF_options] ------------ \n\n");
90  out.printf("method = %s\n", mrpt::utils::TEnumType<TKFMethod>::value2name(method).c_str() );
91  out.printf("verbose = %c\n", verbose ? 'Y':'N');
92  out.printf("IKF_iterations = %i\n", IKF_iterations);
93  out.printf("enable_profiler = %c\n", enable_profiler ? 'Y':'N');
94  out.printf("\n");
95  }
96 
97 
98  TKFMethod method; //!< The method to employ (default: kfEKFNaive)
99  bool verbose; //!< If set to true timing and other information will be dumped during the execution (default=false)
100  int IKF_iterations; //!< Number of refinement iterations, only for the IKF method.
101  bool enable_profiler;//!< If enabled (default=false), detailed timing information will be dumped to the console thru a CTimerLog at the end of the execution.
102  bool use_analytic_transition_jacobian; //!< (default=true) If true, OnTransitionJacobian will be called; otherwise, the Jacobian will be estimated from a numeric approximation by calling several times to OnTransitionModel.
103  bool use_analytic_observation_jacobian; //!< (default=true) If true, OnObservationJacobians will be called; otherwise, the Jacobian will be estimated from a numeric approximation by calling several times to OnObservationModel.
104  bool debug_verify_analytic_jacobians; //!< (default=false) If true, will compute all the Jacobians numerically and compare them to the analytical ones, throwing an exception on mismatch.
105  double debug_verify_analytic_jacobians_threshold; //!< (default-1e-2) Sets the threshold for the difference between the analytic and the numerical jacobians
106  };
107 
108  /** Auxiliary functions, for internal usage of MRPT classes */
109  namespace detail
110  {
111  // Auxiliary functions.
112  template <size_t VEH_SIZE, size_t OBS_SIZE, size_t FEAT_SIZE, size_t ACT_SIZE, typename KFTYPE>
114  // Specialization:
115  template <size_t VEH_SIZE, size_t OBS_SIZE, size_t ACT_SIZE, typename KFTYPE>
117 
118  template <size_t VEH_SIZE, size_t OBS_SIZE, size_t FEAT_SIZE, size_t ACT_SIZE, typename KFTYPE>
120  // Specialization:
121  template <size_t VEH_SIZE, size_t OBS_SIZE, size_t ACT_SIZE, typename KFTYPE>
123 
124  template <size_t VEH_SIZE, size_t OBS_SIZE, size_t FEAT_SIZE, size_t ACT_SIZE, typename KFTYPE>
125  void addNewLandmarks(
128  const vector_int &data_association,
130  template <size_t VEH_SIZE, size_t OBS_SIZE, size_t ACT_SIZE, typename KFTYPE>
131  void addNewLandmarks(
134  const vector_int &data_association,
136  }
137 
138 
139  /** Virtual base for Kalman Filter (EKF,IEKF,UKF) implementations.
140  * This base class stores the state vector and covariance matrix of the system. It has virtual methods that must be completed
141  * by derived classes to address a given filtering problem. The main entry point of the algorithm is CKalmanFilterCapable::runOneKalmanIteration, which
142  * should be called AFTER setting the desired filter options in KF_options, as well as any options in the derived class.
143  * Note that the main entry point is protected, so derived classes must offer another method more specific to a given problem which, internally, calls runOneKalmanIteration.
144  *
145  * For further details and examples, check out the tutorial: http://www.mrpt.org/Kalman_Filters
146  *
147  * The Kalman filter algorithms are generic, but this implementation is biased to ease the implementation
148  * of SLAM-like problems. However, it can be also applied to many generic problems not related to robotics or SLAM.
149  *
150  * The meaning of the template parameters is:
151  * - VEH_SIZE: The dimension of the "vehicle state": either the full state vector or the "vehicle" part if applicable.
152  * - OBS_SIZE: The dimension of each observation (eg, 2 for pixel coordinates, 3 for 3D coordinates,etc).
153  * - FEAT_SIZE: The dimension of the features in the system state (the "map"), or 0 if not applicable (the default if not implemented).
154  * - ACT_SIZE: The dimension of each "action" u_k (or 0 if not applicable).
155  * - KFTYPE: The numeric type of the matrices (default: double)
156  *
157  * Revisions:
158  * - 2007: Antonio J. Ortiz de Galisteo (AJOGD)
159  * - 2008/FEB: All KF classes corrected, reorganized, and rewritten (JLBC).
160  * - 2008/MAR: Implemented IKF (JLBC).
161  * - 2009/DEC: Totally rewritten as a generic template using fixed-size matrices where possible (JLBC).
162  *
163  * \sa mrpt::slam::CRangeBearingKFSLAM, mrpt::slam::CRangeBearingKFSLAM2D
164  * \ingroup mrpt_bayes_grp
165  */
166  template <size_t VEH_SIZE, size_t OBS_SIZE, size_t FEAT_SIZE, size_t ACT_SIZE, typename KFTYPE = double>
168  {
169  public:
170  static inline size_t get_vehicle_size() { return VEH_SIZE; }
171  static inline size_t get_observation_size() { return OBS_SIZE; }
172  static inline size_t get_feature_size() { return FEAT_SIZE; }
173  static inline size_t get_action_size() { return ACT_SIZE; }
174  inline size_t getNumberOfLandmarksInTheMap() const { return detail::getNumberOfLandmarksInMap(*this); }
175  inline bool isMapEmpty() const { return detail::isMapEmpty(*this); }
176 
177 
178  typedef KFTYPE kftype; //!< The numeric type used in the Kalman Filter (default=double)
180 
181  // ---------- Many useful typedefs to short the notation a bit... --------
182  typedef Eigen::Matrix<KFTYPE,Eigen::Dynamic,1> KFVector;
184 
189 
192 
195 
198 
204 
205  inline size_t getStateVectorLength() const { return m_xkk.size(); }
206 
207  inline KFVector& internal_getXkk() { return m_xkk; }
208  inline KFMatrix& internal_getPkk() { return m_pkk; }
209 
210  /** Returns the mean of the estimated value of the idx'th landmark (not applicable to non-SLAM problems).
211  * \exception std::exception On idx>= getNumberOfLandmarksInTheMap()
212  */
213  inline void getLandmarkMean(size_t idx, KFArray_FEAT &feat ) const {
214  ASSERT_(idx<getNumberOfLandmarksInTheMap())
215  ::memcpy(&feat[0], &m_xkk[VEH_SIZE+idx*FEAT_SIZE], FEAT_SIZE*sizeof(m_xkk[0]));
216  }
217  /** Returns the covariance of the idx'th landmark (not applicable to non-SLAM problems).
218  * \exception std::exception On idx>= getNumberOfLandmarksInTheMap()
219  */
220  inline void getLandmarkCov(size_t idx, KFMatrix_FxF &feat_cov ) const {
221  m_pkk.extractMatrix(VEH_SIZE+idx*FEAT_SIZE,VEH_SIZE+idx*FEAT_SIZE,feat_cov);
222  }
223 
224  protected:
225  /** @name Kalman filter state
226  @{ */
227 
228  KFVector m_xkk; //!< The system state vector.
229  KFMatrix m_pkk; //!< The system full covariance matrix.
230 
231  /** @} */
232 
234 
235  /** @name Virtual methods for Kalman Filter implementation
236  @{
237  */
238 
239  /** Must return the action vector u.
240  * \param out_u The action vector which will be passed to OnTransitionModel
241  */
242  virtual void OnGetAction( KFArray_ACT &out_u ) const = 0;
243 
244  /** Implements the transition model \f$ \hat{x}_{k|k-1} = f( \hat{x}_{k-1|k-1}, u_k ) \f$
245  * \param in_u The vector returned by OnGetAction.
246  * \param inout_x At input has \f[ \hat{x}_{k-1|k-1} \f] , at output must have \f$ \hat{x}_{k|k-1} \f$ .
247  * \param out_skip Set this to true if for some reason you want to skip the prediction step (to do not modify either the vector or the covariance). Default:false
248  * \note Even if you return "out_skip=true", the value of "inout_x" MUST be updated as usual (this is to allow numeric approximation of Jacobians).
249  */
250  virtual void OnTransitionModel(
251  const KFArray_ACT &in_u,
252  KFArray_VEH &inout_x,
253  bool &out_skipPrediction
254  ) const = 0;
255 
256  /** Implements the transition Jacobian \f$ \frac{\partial f}{\partial x} \f$
257  * \param out_F Must return the Jacobian.
258  * The returned matrix must be \f$V \times V\f$ with V being either the size of the whole state vector (for non-SLAM problems) or VEH_SIZE (for SLAM problems).
259  */
260  virtual void OnTransitionJacobian( KFMatrix_VxV &out_F ) const
261  {
262  MRPT_UNUSED_PARAM(out_F);
263  m_user_didnt_implement_jacobian=true;
264  }
265 
266  /** Only called if using a numeric approximation of the transition Jacobian, this method must return the increments in each dimension of the vehicle state vector while estimating the Jacobian.
267  */
268  virtual void OnTransitionJacobianNumericGetIncrements(KFArray_VEH &out_increments) const
269  {
270  for (size_t i=0;i<VEH_SIZE;i++) out_increments[i] = 1e-6;
271  }
272 
273  /** Implements the transition noise covariance \f$ Q_k \f$
274  * \param out_Q Must return the covariance matrix.
275  * The returned matrix must be of the same size than the jacobian from OnTransitionJacobian
276  */
277  virtual void OnTransitionNoise( KFMatrix_VxV &out_Q ) const = 0;
278 
279  /** This will be called before OnGetObservationsAndDataAssociation to allow the application to reduce the number of covariance landmark predictions to be made.
280  * For example, features which are known to be "out of sight" shouldn't be added to the output list to speed up the calculations.
281  * \param in_all_prediction_means The mean of each landmark predictions; the computation or not of the corresponding covariances is what we're trying to determined with this method.
282  * \param out_LM_indices_to_predict The list of landmark indices in the map [0,getNumberOfLandmarksInTheMap()-1] that should be predicted.
283  * \note This is not a pure virtual method, so it should be implemented only if desired. The default implementation returns a vector with all the landmarks in the map.
284  * \sa OnGetObservations, OnDataAssociation
285  */
287  const vector_KFArray_OBS &in_all_prediction_means,
288  mrpt::vector_size_t &out_LM_indices_to_predict ) const
289  {
290  MRPT_UNUSED_PARAM(in_all_prediction_means);
291  // Default: all of them:
292  const size_t N = this->getNumberOfLandmarksInTheMap();
293  out_LM_indices_to_predict.resize(N);
294  for (size_t i=0;i<N;i++) out_LM_indices_to_predict[i]=i;
295  }
296 
297  /** Return the observation NOISE covariance matrix, that is, the model of the Gaussian additive noise of the sensor.
298  * \param out_R The noise covariance matrix. It might be non diagonal, but it'll usually be.
299  * \note Upon call, it can be assumed that the previous contents of out_R are all zeros.
300  */
301  virtual void OnGetObservationNoise(KFMatrix_OxO &out_R) const = 0;
302 
303  /** This is called between the KF prediction step and the update step, and the application must return the observations and, when applicable, the data association between these observations and the current map.
304  *
305  * \param out_z N vectors, each for one "observation" of length OBS_SIZE, N being the number of "observations": how many observed landmarks for a map, or just one if not applicable.
306  * \param out_data_association An empty vector or, where applicable, a vector where the i'th element corresponds to the position of the observation in the i'th row of out_z within the system state vector (in the range [0,getNumberOfLandmarksInTheMap()-1]), or -1 if it is a new map element and we want to insert it at the end of this KF iteration.
307  * \param in_all_predictions A vector with the prediction of ALL the landmarks in the map. Note that, in contrast, in_S only comprises a subset of all the landmarks.
308  * \param in_S The full covariance matrix of the observation predictions (i.e. the "innovation covariance matrix"). This is a M·O x M·O matrix with M=length of "in_lm_indices_in_S".
309  * \param in_lm_indices_in_S The indices of the map landmarks (range [0,getNumberOfLandmarksInTheMap()-1]) that can be found in the matrix in_S.
310  *
311  * This method will be called just once for each complete KF iteration.
312  * \note It is assumed that the observations are independent, i.e. there are NO cross-covariances between them.
313  */
314  virtual void OnGetObservationsAndDataAssociation(
315  vector_KFArray_OBS &out_z,
316  mrpt::vector_int &out_data_association,
317  const vector_KFArray_OBS &in_all_predictions,
318  const KFMatrix &in_S,
319  const vector_size_t &in_lm_indices_in_S,
320  const KFMatrix_OxO &in_R
321  ) = 0;
322 
323  /** Implements the observation prediction \f$ h_i(x) \f$.
324  * \param idx_landmark_to_predict The indices of the landmarks in the map whose predictions are expected as output. For non SLAM-like problems, this input value is undefined and the application should just generate one observation for the given problem.
325  * \param out_predictions The predicted observations.
326  */
327  virtual void OnObservationModel(
328  const mrpt::vector_size_t &idx_landmarks_to_predict,
329  vector_KFArray_OBS &out_predictions
330  ) const = 0;
331 
332  /** Implements the observation Jacobians \f$ \frac{\partial h_i}{\partial x} \f$ and (when applicable) \f$ \frac{\partial h_i}{\partial y_i} \f$.
333  * \param idx_landmark_to_predict The index of the landmark in the map whose prediction is expected as output. For non SLAM-like problems, this will be zero and the expected output is for the whole state vector.
334  * \param Hx The output Jacobian \f$ \frac{\partial h_i}{\partial x} \f$.
335  * \param Hy The output Jacobian \f$ \frac{\partial h_i}{\partial y_i} \f$.
336  */
338  const size_t &idx_landmark_to_predict,
339  KFMatrix_OxV &Hx,
340  KFMatrix_OxF &Hy
341  ) const
342  {
343  MRPT_UNUSED_PARAM(idx_landmark_to_predict); MRPT_UNUSED_PARAM(Hx); MRPT_UNUSED_PARAM(Hy);
344  m_user_didnt_implement_jacobian=true;
345  }
346 
347  /** Only called if using a numeric approximation of the observation Jacobians, this method must return the increments in each dimension of the vehicle state vector while estimating the Jacobian.
348  */
350  KFArray_VEH &out_veh_increments,
351  KFArray_FEAT &out_feat_increments ) const
352  {
353  for (size_t i=0;i<VEH_SIZE;i++) out_veh_increments[i] = 1e-6;
354  for (size_t i=0;i<FEAT_SIZE;i++) out_feat_increments[i] = 1e-6;
355  }
356 
357  /** Computes A=A-B, which may need to be re-implemented depending on the topology of the individual scalar components (eg, angles).
358  */
359  virtual void OnSubstractObservationVectors(KFArray_OBS &A, const KFArray_OBS &B) const
360  {
361  A -= B;
362  }
363 
364 
365  public:
366  /** If applicable to the given problem, this method implements the inverse observation model needed to extend the "map" with a new "element".
367  * \param in_z The observation vector whose inverse sensor model is to be computed. This is actually one of the vector<> returned by OnGetObservationsAndDataAssociation().
368  * \param out_yn The F-length vector with the inverse observation model \f$ y_n=y(x,z_n) \f$.
369  * \param out_dyn_dxv The \f$F \times V\f$ Jacobian of the inv. sensor model wrt the robot pose \f$ \frac{\partial y_n}{\partial x_v} \f$.
370  * \param out_dyn_dhn The \f$F \times O\f$ Jacobian of the inv. sensor model wrt the observation vector \f$ \frac{\partial y_n}{\partial h_n} \f$.
371  *
372  * - O: OBS_SIZE
373  * - V: VEH_SIZE
374  * - F: FEAT_SIZE
375  *
376  * \note OnNewLandmarkAddedToMap will be also called after calling this method if a landmark is actually being added to the map.
377  * \deprecated This version of the method is deprecated. The alternative method is preferred to allow a greater flexibility.
378  */
380  const KFArray_OBS & in_z,
381  KFArray_FEAT & out_yn,
382  KFMatrix_FxV & out_dyn_dxv,
383  KFMatrix_FxO & out_dyn_dhn ) const
384  {
385  MRPT_UNUSED_PARAM(in_z); MRPT_UNUSED_PARAM(out_yn);
386  MRPT_UNUSED_PARAM(out_dyn_dxv); MRPT_UNUSED_PARAM(out_dyn_dhn);
387  MRPT_START
388  THROW_EXCEPTION("Inverse sensor model required but not implemented in derived class.")
389  MRPT_END
390  }
391 
392  /** If applicable to the given problem, this method implements the inverse observation model needed to extend the "map" with a new "element".
393  * The uncertainty in the new map feature comes from two parts: one from the vehicle uncertainty (through the out_dyn_dxv Jacobian),
394  * and another from the uncertainty in the observation itself. By default, out_use_dyn_dhn_jacobian=true on call, and if it's left at "true",
395  * the base KalmanFilter class will compute the uncertainty of the landmark relative position from out_dyn_dhn.
396  * Only in some problems (e.g. MonoSLAM), it'll be needed for the application to directly return the covariance matrix \a out_dyn_dhn_R_dyn_dhnT, which is the equivalent to:
397  *
398  * \f$ \frac{\partial y_n}{\partial h_n} R \frac{\partial y_n}{\partial h_n}^\top \f$.
399  *
400  * but may be computed from additional terms, or whatever needed by the user.
401  *
402  * \param in_z The observation vector whose inverse sensor model is to be computed. This is actually one of the vector<> returned by OnGetObservationsAndDataAssociation().
403  * \param out_yn The F-length vector with the inverse observation model \f$ y_n=y(x,z_n) \f$.
404  * \param out_dyn_dxv The \f$F \times V\f$ Jacobian of the inv. sensor model wrt the robot pose \f$ \frac{\partial y_n}{\partial x_v} \f$.
405  * \param out_dyn_dhn The \f$F \times O\f$ Jacobian of the inv. sensor model wrt the observation vector \f$ \frac{\partial y_n}{\partial h_n} \f$.
406  * \param out_dyn_dhn_R_dyn_dhnT See the discussion above.
407  *
408  * - O: OBS_SIZE
409  * - V: VEH_SIZE
410  * - F: FEAT_SIZE
411  *
412  * \note OnNewLandmarkAddedToMap will be also called after calling this method if a landmark is actually being added to the map.
413  */
415  const KFArray_OBS & in_z,
416  KFArray_FEAT & out_yn,
417  KFMatrix_FxV & out_dyn_dxv,
418  KFMatrix_FxO & out_dyn_dhn,
419  KFMatrix_FxF & out_dyn_dhn_R_dyn_dhnT,
420  bool & out_use_dyn_dhn_jacobian
421  ) const
422  {
423  MRPT_UNUSED_PARAM(out_dyn_dhn_R_dyn_dhnT);
424  MRPT_START
425  OnInverseObservationModel(in_z,out_yn,out_dyn_dxv,out_dyn_dhn);
426  out_use_dyn_dhn_jacobian=true;
427  MRPT_END
428  }
429 
430  /** If applicable to the given problem, do here any special handling of adding a new landmark to the map.
431  * \param in_obsIndex The index of the observation whose inverse sensor is to be computed. It corresponds to the row in in_z where the observation can be found.
432  * \param in_idxNewFeat The index that this new feature will have in the state vector (0:just after the vehicle state, 1: after that,...). Save this number so data association can be done according to these indices.
433  * \sa OnInverseObservationModel
434  */
436  const size_t in_obsIdx,
437  const size_t in_idxNewFeat )
438  {
439  MRPT_UNUSED_PARAM(in_obsIdx); MRPT_UNUSED_PARAM(in_idxNewFeat);
440  // Do nothing in this base class.
441  }
442 
443  /** This method is called after the prediction and after the update, to give the user an opportunity to normalize the state vector (eg, keep angles within -pi,pi range) if the application requires it.
444  */
445  virtual void OnNormalizeStateVector()
446  {
447  // Do nothing in this base class.
448  }
449 
450  /** This method is called after finishing one KF iteration and before returning from runOneKalmanIteration().
451  */
452  virtual void OnPostIteration()
453  {
454  // Do nothing in this base class.
455  }
456 
457  /** @}
458  */
459 
460  public:
461  CKalmanFilterCapable() : m_user_didnt_implement_jacobian(true) {} //!< Default constructor
462  virtual ~CKalmanFilterCapable() {} //!< Destructor
464  mrpt::utils::CTimeLogger &getProfiler() { return m_timLogger; }
466  TKF_options KF_options; //!< Generic options for the Kalman Filter algorithm itself.
467 
468 
469  private:
470  // "Local" variables to runOneKalmanIteration, declared here to avoid
471  // allocating them over and over again with each call.
472  // (The variables that go into the stack remains in the function body)
473  vector_KFArray_OBS all_predictions;
474  vector_size_t predictLMidxs;
475  typename mrpt::aligned_containers<KFMatrix_OxV>::vector_t Hxs; //!< The vector of all partial Jacobians dh[i]_dx for each prediction
476  typename mrpt::aligned_containers<KFMatrix_OxF>::vector_t Hys; //!< The vector of all partial Jacobians dh[i]_dy[i] for each prediction
477  KFMatrix S;
478  KFMatrix Pkk_subset;
479  vector_KFArray_OBS Z; // Each entry is one observation:
480  KFMatrix K; // Kalman gain
481  KFMatrix S_1; // Inverse of S
482  KFMatrix dh_dx_full_obs;
483  KFMatrix aux_K_dh_dx;
484 
485  protected:
486 
487  /** The main entry point, executes one complete step: prediction + update.
488  * It is protected since derived classes must provide a problem-specific entry point for users.
489  * The exact order in which this method calls the virtual method is explained in http://www.mrpt.org/Kalman_Filters
490  */
491  void runOneKalmanIteration();
492 
493  private:
494  mutable bool m_user_didnt_implement_jacobian;
495 
496  /** Auxiliary functions for Jacobian numeric estimation */
497  static void KF_aux_estimate_trans_jacobian( const KFArray_VEH &x, const std::pair<KFCLASS*,KFArray_ACT> &dat, KFArray_VEH &out_x);
498  static void KF_aux_estimate_obs_Hx_jacobian(const KFArray_VEH &x, const std::pair<KFCLASS*,size_t> &dat, KFArray_OBS &out_x);
499  static void KF_aux_estimate_obs_Hy_jacobian(const KFArray_FEAT &x,const std::pair<KFCLASS*,size_t> &dat,KFArray_OBS &out_x);
500 
501  template <size_t VEH_SIZEb, size_t OBS_SIZEb, size_t FEAT_SIZEb, size_t ACT_SIZEb, typename KFTYPEb>
502  friend
506  const vector_int &data_association,
508  }; // end class
509 
510  } // end namespace
511 
512  // Specializations MUST occur at the same namespace:
513  namespace utils
514  {
515  template <>
516  struct TEnumTypeFiller<bayes::TKFMethod>
517  {
519  static void fill(bimap<enum_t,std::string> &m_map)
520  {
521  m_map.insert(bayes::kfEKFNaive, "kfEKFNaive");
522  m_map.insert(bayes::kfEKFAlaDavison, "kfEKFAlaDavison");
523  m_map.insert(bayes::kfIKFFull, "kfIKFFull");
524  m_map.insert(bayes::kfIKF, "kfIKF");
525  }
526  };
527  } // End of namespace
528 } // end namespace
529 
530 // Template implementation:
532 
533 #endif
Virtual base for Kalman Filter (EKF,IEKF,UKF) implementations.
CKalmanFilterCapable< VEH_SIZE, OBS_SIZE, FEAT_SIZE, ACT_SIZE, KFTYPE > KFCLASS
My class, in a shorter name!
KFMatrix m_pkk
The system full covariance matrix.
bool use_analytic_observation_jacobian
(default=true) If true, OnObservationJacobians will be called; otherwise, the Jacobian will be estima...
virtual void OnNormalizeStateVector()
This method is called after the prediction and after the update, to give the user an opportunity to n...
Classes for serialization, sockets, ini-file manipulation, streams, list of properties-values, timewatch, extensions to STL.
Definition: zip.h:16
static void fill(bimap< enum_t, std::string > &m_map)
ENUMTYPE read_enum(const std::string &section, const std::string &name, const ENUMTYPE &defaultValue, bool failIfNotFound=false) const
Reads an "enum" value, where the value in the config file can be either a numerical value or the symb...
void BASE_IMPEXP memcpy(void *dest, size_t destSize, const void *src, size_t copyCount) MRPT_NO_THROWS
An OS and compiler independent version of "memcpy".
CMatrixFixedNumeric< KFTYPE, VEH_SIZE, VEH_SIZE > KFMatrix_VxV
bool enable_profiler
If enabled (default=false), detailed timing information will be dumped to the console thru a CTimerLo...
#define THROW_EXCEPTION(msg)
virtual void OnInverseObservationModel(const KFArray_OBS &in_z, KFArray_FEAT &out_yn, KFMatrix_FxV &out_dyn_dxv, KFMatrix_FxO &out_dyn_dhn, KFMatrix_FxF &out_dyn_dhn_R_dyn_dhnT, bool &out_use_dyn_dhn_jacobian) const
If applicable to the given problem, this method implements the inverse observation model needed to ex...
CMatrixFixedNumeric< KFTYPE, VEH_SIZE, FEAT_SIZE > KFMatrix_VxF
CArrayNumeric is an array for numeric types supporting several mathematical operations (actually...
Definition: CArrayNumeric.h:25
double debug_verify_analytic_jacobians_threshold
(default-1e-2) Sets the threshold for the difference between the analytic and the numerical jacobians...
STL namespace.
Only specializations of this class are defined for each enum type of interest.
Definition: TEnumType.h:23
mrpt::aligned_containers< KFArray_OBS >::vector_t vector_KFArray_OBS
virtual void OnObservationJacobiansNumericGetIncrements(KFArray_VEH &out_veh_increments, KFArray_FEAT &out_feat_increments) const
Only called if using a numeric approximation of the observation Jacobians, this method must return th...
virtual void OnNewLandmarkAddedToMap(const size_t in_obsIdx, const size_t in_idxNewFeat)
If applicable to the given problem, do here any special handling of adding a new landmark to the map...
This class allows loading and storing values and vectors of different types from a configuration text...
virtual void OnPreComputingPredictions(const vector_KFArray_OBS &in_all_prediction_means, mrpt::vector_size_t &out_LM_indices_to_predict) const
This will be called before OnGetObservationsAndDataAssociation to allow the application to reduce the...
This base class is used to provide a unified interface to files,memory buffers,..Please see the deriv...
Definition: CStream.h:38
A numeric matrix of compile-time fixed size.
This base provides a set of functions for maths stuff.
Definition: CArray.h:18
CArrayNumeric< KFTYPE, ACT_SIZE > KFArray_ACT
#define MRPT_END
std::vector< size_t > vector_size_t
#define MRPT_UNUSED_PARAM(a)
Can be used to avoid "not used parameters" warnings from the compiler.
A helper class that can convert an enum value into its textual representation, and viceversa...
bool verbose
If set to true timing and other information will be dumped during the execution (default=false) ...
CMatrixFixedNumeric< KFTYPE, FEAT_SIZE, OBS_SIZE > KFMatrix_FxO
size_t getNumberOfLandmarksInMap(const CKalmanFilterCapable< VEH_SIZE, OBS_SIZE, FEAT_SIZE, ACT_SIZE, KFTYPE > &obj)
A bidirectional version of std::map, declared as bimap and which actually contains two std...
Definition: bimap.h:27
CMatrixFixedNumeric< KFTYPE, OBS_SIZE, FEAT_SIZE > KFMatrix_OxF
CMatrixFixedNumeric< KFTYPE, FEAT_SIZE, FEAT_SIZE > KFMatrix_FxF
void addNewLandmarks(CKalmanFilterCapable< VEH_SIZE, OBS_SIZE, FEAT_SIZE, ACT_SIZE, KFTYPE > &obj, const typename CKalmanFilterCapable< VEH_SIZE, OBS_SIZE, FEAT_SIZE, ACT_SIZE, KFTYPE >::vector_KFArray_OBS &Z, const vector_int &data_association, const typename CKalmanFilterCapable< VEH_SIZE, OBS_SIZE, FEAT_SIZE, ACT_SIZE, KFTYPE >::KFMatrix_OxO &R)
virtual void OnTransitionJacobianNumericGetIncrements(KFArray_VEH &out_increments) const
Only called if using a numeric approximation of the transition Jacobian, this method must return the ...
CMatrixFixedNumeric< KFTYPE, ACT_SIZE, ACT_SIZE > KFMatrix_AxA
KFVector m_xkk
The system state vector.
Generic options for the Kalman Filter algorithm in itself.
#define MRPT_START
virtual void OnSubstractObservationVectors(KFArray_OBS &A, const KFArray_OBS &B) const
Computes A=A-B, which may need to be re-implemented depending on the topology of the individual scala...
#define MRPT_LOAD_CONFIG_VAR(variableName, variableType, configFileObject, sectionNameStr)
An useful macro for loading variables stored in a INI-like file under a key with the same name that t...
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
bool isMapEmpty(const CKalmanFilterCapable< VEH_SIZE, OBS_SIZE, 0, ACT_SIZE, KFTYPE > &obj)
void loadFromConfigFile(const mrpt::utils::CConfigFileBase &iniFile, const std::string &section)
This method load the options from a ".ini"-like file or memory-stored string list.
std::vector< int32_t > vector_int
bool debug_verify_analytic_jacobians
(default=false) If true, will compute all the Jacobians numerically and compare them to the analytica...
virtual void OnObservationJacobians(const size_t &idx_landmark_to_predict, KFMatrix_OxV &Hx, KFMatrix_OxF &Hy) const
Implements the observation Jacobians and (when applicable) .
bool isMapEmpty(const CKalmanFilterCapable< VEH_SIZE, OBS_SIZE, FEAT_SIZE, ACT_SIZE, KFTYPE > &obj)
TKFMethod
The Kalman Filter algorithm to employ in bayes::CKalmanFilterCapable For further details on each algo...
CArrayNumeric< KFTYPE, VEH_SIZE > KFArray_VEH
virtual void OnInverseObservationModel(const KFArray_OBS &in_z, KFArray_FEAT &out_yn, KFMatrix_FxV &out_dyn_dxv, KFMatrix_FxO &out_dyn_dhn) const
If applicable to the given problem, this method implements the inverse observation model needed to ex...
KFTYPE kftype
The numeric type used in the Kalman Filter (default=double)
CMatrixFixedNumeric< KFTYPE, FEAT_SIZE, VEH_SIZE > KFMatrix_FxV
Eigen::Matrix< KFTYPE, Eigen::Dynamic, 1 > KFVector
#define ASSERT_(f)
void getLandmarkCov(size_t idx, KFMatrix_FxF &feat_cov) const
Returns the covariance of the idx'th landmark (not applicable to non-SLAM problems).
A versatile "profiler" that logs the time spent within each pair of calls to enter(X)-leave(X), among other stats.
Definition: CTimeLogger.h:35
CMatrixTemplateNumeric< KFTYPE > KFMatrix
virtual void OnTransitionJacobian(KFMatrix_VxV &out_F) const
Implements the transition Jacobian .
TKFMethod method
The method to employ (default: kfEKFNaive)
size_t getNumberOfLandmarksInMap(const CKalmanFilterCapable< VEH_SIZE, OBS_SIZE, 0, ACT_SIZE, KFTYPE > &obj)
void dumpToTextStream(CStream &out) const
This method must display clearly all the contents of the structure in textual form, sending it to a CStream.
void getLandmarkMean(size_t idx, KFArray_FEAT &feat) const
Returns the mean of the estimated value of the idx'th landmark (not applicable to non-SLAM problems)...
void insert(const KEY &k, const VALUE &v)
Insert a new pair KEY<->VALUE in the bi-map.
Definition: bimap.h:68
mrpt::utils::CTimeLogger m_timLogger
CArrayNumeric< KFTYPE, FEAT_SIZE > KFArray_FEAT
CMatrixFixedNumeric< KFTYPE, VEH_SIZE, OBS_SIZE > KFMatrix_VxO
This base class provides a common printf-like method to send debug information to std::cout...
std::vector< TYPE1, Eigen::aligned_allocator< TYPE1 > > vector_t
bool use_analytic_transition_jacobian
(default=true) If true, OnTransitionJacobian will be called; otherwise, the Jacobian will be estimate...
This is a virtual base class for sets of options than can be loaded from and/or saved to configuratio...
void addNewLandmarks(CKalmanFilterCapable< VEH_SIZE, OBS_SIZE, 0, ACT_SIZE, KFTYPE > &obj, const typename CKalmanFilterCapable< VEH_SIZE, OBS_SIZE, 0, ACT_SIZE, KFTYPE >::vector_KFArray_OBS &Z, const vector_int &data_association, const typename CKalmanFilterCapable< VEH_SIZE, OBS_SIZE, 0, ACT_SIZE, KFTYPE >::KFMatrix_OxO &R)
int IKF_iterations
Number of refinement iterations, only for the IKF method.
virtual int printf(const char *fmt,...) MRPT_printf_format_check(2
Writes a string to the stream in a textual form.
virtual void OnPostIteration()
This method is called after finishing one KF iteration and before returning from runOneKalmanIteratio...
CMatrixFixedNumeric< KFTYPE, OBS_SIZE, VEH_SIZE > KFMatrix_OxV
CArrayNumeric< KFTYPE, OBS_SIZE > KFArray_OBS
CMatrixFixedNumeric< KFTYPE, OBS_SIZE, OBS_SIZE > KFMatrix_OxO



Page generated by Doxygen 1.8.8 for MRPT 1.2.2 SVN:Unversioned directory at Tue Oct 14 02:14:08 UTC 2014