diff options
author | Martin Miller | 2017-03-25 18:33:46 -0500 |
---|---|---|
committer | Martin Miller | 2017-03-25 18:33:46 -0500 |
commit | b7b8835f7075c2dcfeed8a272662a7a44168b092 (patch) | |
tree | 93e3d27e7361c6159db4e4579648b27c2a64d7a2 /src/state.cpp | |
parent | 7c0b1419c76aaaf3f2f4de73bdf1be331e741926 (diff) | |
download | refslam-b7b8835f7075c2dcfeed8a272662a7a44168b092.zip refslam-b7b8835f7075c2dcfeed8a272662a7a44168b092.tar.gz |
Methods added to State to get H
Added a method to return an H matrix for the provided measurements. This
should be a versatile method that can work for the full H update or the
indpendent update depending on what measurements are passed.
Some helper methods were also added for determining a features
location in the state vector and for return a feature pointer by id.
Diffstat (limited to 'src/state.cpp')
-rw-r--r-- | src/state.cpp | 104 |
1 files changed, 100 insertions, 4 deletions
diff --git a/src/state.cpp b/src/state.cpp index dae6a4d..281fac3 100644 --- a/src/state.cpp +++ b/src/state.cpp @@ -41,11 +41,79 @@ State::enu ( const UTM &utm ) return ; } /* ----- end of method State::enu ----- */ +/* + *-------------------------------------------------------------------------------------- + * Class: State + * Method: State :: H + * Description: Returns the matrix H for the measurements z + *-------------------------------------------------------------------------------------- + */ +MatrixXd +State::H ( const Vector3d &pos, const Quaterniond &q, const std::vector<measurement_t> &z ) +{ + MatrixXd h; + // Determine the size of H + int rows = 0; + for (auto i=z.begin(); i!=z.end(); ++i) { + switch ( i->z_type ) { + case REFLECTION: + rows += 6; + break; + + case MONO: + rows += 4; + break; + + case HEIGHT: + rows += 1; + break; + + default: + break; + } /* ----- end switch ----- */ + } + int cols = 9 + 3*features.size(); + h = MatrixXd::Zero(rows,cols); + for (int i=0,row=0; i<z.size(); ++i) { + switch ( z[i].z_type ) { + int col; + case REFLECTION: + col = rowById(z[i].id); + Feature *fi; + fi = featureById(z[i].id); + if (col==-1) { + fprintf(stderr, "Feature %d not found, quitting.\n", z[i].id); + exit(1); + } + + h.block<6,9>(row,0) = fi->Hx(pos,q); + h.block<6,3>(row,col) = fi->Hy(pos,q); + row += 6; + break; + + case MONO: + fprintf(stderr, "mono points not supported.\n"); + exit(1); + break; + + case HEIGHT: + h.block<1,9>(row,0) = body->H(); + row += 1; + break; + + default: + break; + } /* ----- end switch ----- */ + } + return h; +} /* ----- end of method State::H ----- */ + void -State::update ( const Matrix<double,1,1> &z ) +State::update ( const Vector3d &pos, const Quaterniond &q, const std::vector<measurement_t> &z ) { - Matrix<double,1,9> H; - H=body->H(); + MatrixXd h; + h = H(pos,q,z); + /* Matrix<double,1,1> S; S=body->S(Pxx()); Matrix<double,9,1> K; @@ -57,6 +125,7 @@ State::update ( const Matrix<double,1,1> &z ) h = body->h(); dx = K*(z-h); body->update(dx); + */ } void @@ -196,7 +265,7 @@ void State::motionModel ( const Vector3d &acc, const Vector3d &ang, const Quaterniond &q, const double dt) { - //Pkk1(ang,q,dt); + Pkk1(ang,q,dt); body->motionModel(acc,ang,q,dt); Vector3d vel; @@ -334,6 +403,33 @@ State::exists ( int id ) /* *-------------------------------------------------------------------------------------- * Class: State + * Method: State :: rowById + * Description: Returns the first row of the feature with the given ID. Returns + * -1 if not found. + *-------------------------------------------------------------------------------------- + */ +int +State::rowById ( int id ) +{ + int j=9; + for (auto i=features.begin(); i!=features.end(); ++i, j+=3) { + if ((*i)->id()==id) return j; + } + return -1; +} /* ----- end of method State::rowById ----- */ + +Feature * +State::featureById ( int id ) +{ + for (auto i=features.begin(); i!=features.end(); ++i) { + if ((*i)->id()==id) return *i; + } + return NULL; +} /* ----- end of method State::featureById ----- */ + +/* + *-------------------------------------------------------------------------------------- + * Class: State * Method: State :: expandP * Description: Expand the P matrix to fit one more feature. *-------------------------------------------------------------------------------------- |