bitsim
Model, simulate, estimate and control robots in C++
Loading...
Searching...
No Matches
kf_model_base.h
Go to the documentation of this file.
1#ifndef BITSIM_ESTIMATION_KF_MODEL_BASE_H
2#define BITSIM_ESTIMATION_KF_MODEL_BASE_H
3
4#include <map>
5#include <stdexcept> //for std::invalid_argument
6#include <string>
7
8namespace bitsim
9{
10namespace estimation
11{
12
13template <typename MatrixType> class KFModelBase
14{
15 public:
16 using matrix_type = MatrixType;
17
18 virtual void add_matrix(const std::string &name, matrix_type &mat);
19 virtual matrix_type &get_matrix(const std::string &mat);
20 virtual const matrix_type &get_matrix(const std::string &mat) const;
21
22 protected:
23 std::map<std::string, matrix_type> matrices_;
24};
25
26template <typename MatrixType>
27void KFModelBase<MatrixType>::add_matrix(const std::string &name, matrix_type &mat)
28{
29 matrices_.insert_or_assign(name, mat);
30}
31
32template <typename MatrixType>
35{
36
37 auto itr = matrices_.find(name);
38 if (itr != matrices_.end())
39 {
40 return itr->second;
41 }
42
43 throw std::invalid_argument("Matrix not found");
44}
45
46template <typename MatrixType>
48KFModelBase<MatrixType>::get_matrix(const std::string &name) const
49{
50
51 auto itr = matrices_.find(name);
52 if (itr != matrices_.end())
53 {
54 return itr->second;
55 }
56
57 throw std::invalid_argument("Matrix not found");
58}
59
60template <typename MatrixType, typename StateType>
61class KFMotionModelBase : public KFModelBase<MatrixType>
62{
63 public:
64 using matrix_type = MatrixType;
65 using state_type = StateType;
66
67 virtual state_type &get_state() { return state_; }
68 virtual const state_type &get_state() const { return state_; }
69 virtual void set_state(const state_type &state) { state_ = state; }
70
71 protected:
72 // the state
74};
75
76} // namespace estimation
77} // namespace bitsim
78
79#endif // BITSIM_ESTIMATION_KF_MODEL_BASE_H
Definition kf_model_base.h:14
MatrixType matrix_type
Definition kf_model_base.h:16
virtual matrix_type & get_matrix(const std::string &mat)
Definition kf_model_base.h:34
std::map< std::string, matrix_type > matrices_
Definition kf_model_base.h:23
virtual void add_matrix(const std::string &name, matrix_type &mat)
Definition kf_model_base.h:27
Definition kf_model_base.h:62
virtual const state_type & get_state() const
Definition kf_model_base.h:68
virtual void set_state(const state_type &state)
Definition kf_model_base.h:69
StateType state_type
Definition kf_model_base.h:65
MatrixType matrix_type
Definition kf_model_base.h:64
virtual state_type & get_state()
Definition kf_model_base.h:67
state_type state_
Definition kf_model_base.h:73
DynMat< real_t > matrix_type
Definition kf_model_base.h:16
virtual matrix_type & get_matrix(const std::string &mat)
Definition kf_model_base.h:34
virtual const matrix_type & get_matrix(const std::string &mat) const
Definition kf_model_base.h:48
virtual void add_matrix(const std::string &name, matrix_type &mat)
Definition kf_model_base.h:27
Definition diff_drive_ekf.cpp:12
Definition dc_motor_backend_base.h:9