|
| 1 | +#ifndef OPENKF_RANGE_BEARING_MEAS_MODEL_H |
| 2 | +#define OPENKF_RANGE_BEARING_MEAS_MODEL_H |
| 3 | + |
| 4 | +#include "meas_model.h" |
| 5 | +#include "types.h" |
| 6 | + |
| 7 | +namespace kf |
| 8 | +{ |
| 9 | +namespace measmodel |
| 10 | +{ |
| 11 | +/// @brief Measurement space dimension for constant acceleration measurement |
| 12 | +/// model |
| 13 | +/// \vec{z}=[pos_x, pos_y]^T |
| 14 | +static constexpr int32_t DIM_Z_BEARING{2}; |
| 15 | + |
| 16 | +template <int32_t DIM_X> |
| 17 | +class BearingMeasModel |
| 18 | + : public MeasModel<BearingMeasModel, DIM_X, DIM_Z_BEARING> |
| 19 | +{ |
| 20 | + public: |
| 21 | + BearingMeasModel(Vector<2> const& sensPos2D, float32_t const rangeSigma, |
| 22 | + float32_t const bearingSigma) |
| 23 | + : m_sensPos2D{sensPos2D}, m_rangeNoiseSigma{rangeSigma}, |
| 24 | + m_bearingNoiseSigma{bearingSigma} |
| 25 | + { |
| 26 | + } |
| 27 | + ~BearingMeasModel() {} |
| 28 | + |
| 29 | + static constexpr int32_t IDX_X_PX{0}; //< Index for position x in state |
| 30 | + static constexpr int32_t IDX_X_PY{1}; //< Index for position y in state |
| 31 | + |
| 32 | + static constexpr int32_t IDX_Z_RANGE{0}; //< Index for range in measurement |
| 33 | + static constexpr int32_t IDX_Z_BEARING{ |
| 34 | + 1}; //< Index for bearing in measurement |
| 35 | + |
| 36 | + /// @brief Measurement model function that maps the state space vector to |
| 37 | + /// the measurement space. |
| 38 | + /// @param vecX State space vector \vec{x} |
| 39 | + /// @return Measurement space vector \vec{z} |
| 40 | + Vector<DIM_Z_BEARING> h(Vector<DIM_X> const& vecX) const |
| 41 | + { |
| 42 | + Vector<DIM_Z_BEARING> vecZ; |
| 43 | + float32_t const px{vecX(IDX_X_PX) - m_sensPos2D(IDX_X_PX)}; |
| 44 | + float32_t const py{vecX(IDX_X_PY) - m_sensPos2D(IDX_X_PY)}; |
| 45 | + vecZ(IDX_Z_RANGE) = std::sqrt(px * px + py * py); |
| 46 | + vecZ(IDX_Z_BEARING) = std::atan2(py, px); |
| 47 | + return vecZ; |
| 48 | + } |
| 49 | + |
| 50 | + /// @brief Method that calculates the jacobians of the measurement model. |
| 51 | + /// @param vecX State Space vector \vec{x} |
| 52 | + /// @return The jacobians of the measurement model. |
| 53 | + Matrix<DIM_Z_BEARING, DIM_X> getJacobianHk(Vector<DIM_X> const& vecX) const |
| 54 | + { |
| 55 | + Matrix<DIM_Z_BEARING, DIM_X> matH; |
| 56 | + matH.setZero(); |
| 57 | + |
| 58 | + float32_t const px{vecX(IDX_X_PX) - m_sensPos2D(IDX_X_PX)}; |
| 59 | + float32_t const py{vecX(IDX_X_PY) - m_sensPos2D(IDX_X_PY)}; |
| 60 | + float32_t const denom{px * px + py * py}; |
| 61 | + |
| 62 | + matH(IDX_Z_RANGE, IDX_X_PX) = px / std::sqrt(denom); |
| 63 | + matH(IDX_Z_RANGE, IDX_X_PY) = py / std::sqrt(denom); |
| 64 | + matH(IDX_Z_BEARING, IDX_X_PX) = -py / denom; |
| 65 | + matH(IDX_Z_BEARING, IDX_X_PY) = px / denom; |
| 66 | + return matH; |
| 67 | + } |
| 68 | + |
| 69 | + /// @brief Get the measurement noise covariance R |
| 70 | + /// @return The measurement noise covariance R |
| 71 | + Matrix<DIM_Z_BEARING, DIM_Z_BEARING> getMeasurementNoiseCov() const |
| 72 | + { |
| 73 | + float32_t const rangeNoiseSigma2{m_rangeNoiseSigma * m_rangeNoiseSigma}; |
| 74 | + float32_t const bearingNoiseSigma2{m_bearingNoiseSigma * |
| 75 | + m_bearingNoiseSigma}; |
| 76 | + |
| 77 | + Matrix<DIM_Z_BEARING, DIM_Z_BEARING> matR; |
| 78 | + matR.setZero(); |
| 79 | + matR(IDX_Z_RANGE, IDX_Z_RANGE) = rangeNoiseSigma2; |
| 80 | + matR(IDX_Z_BEARING, IDX_Z_BEARING) = bearingNoiseSigma2; |
| 81 | + return matR; |
| 82 | + } |
| 83 | + |
| 84 | + /// @brief Set range noise standard deviation |
| 85 | + /// @param rangeSigma Range measurement noise standard deviation |
| 86 | + void setRangeNoiseSigma(float32_t const rangeSigma) |
| 87 | + { |
| 88 | + m_rangeNoiseSigma = rangeSigma; |
| 89 | + } |
| 90 | + |
| 91 | + /// @brief Set bearing noise standard deviation |
| 92 | + /// @param bearingSigma Bearing measurement noise standard deviation |
| 93 | + void setBearingNoiseSigma(float32_t const bearingSigma) |
| 94 | + { |
| 95 | + m_bearingNoiseSigma = bearingSigma; |
| 96 | + } |
| 97 | + |
| 98 | + private: |
| 99 | + Vector<2> m_sensPos2D; //< Sensor position in 2D |
| 100 | + float32_t m_rangeNoiseSigma; //< Range measurement noise standard deviation |
| 101 | + float32_t |
| 102 | + m_bearingNoiseSigma; //< Bearing measurement noise standard deviation |
| 103 | +}; |
| 104 | +} // namespace measmodel |
| 105 | + |
| 106 | +} // namespace kf |
| 107 | +#endif // OPENKF_RANGE_BEARING_MEAS_MODEL_H |
0 commit comments