From 816411abf8e9ff633a29449cc0ac445c11f73a1c Mon Sep 17 00:00:00 2001 From: Martin Miller Date: Sat, 18 Mar 2017 20:32:08 -0500 Subject: Major rewrite moves state variables into state. Rather than maintain X and P in the main function they are moved into the body and state classes, respectively. This will become much more important when features are added and the accounting becomes more complicated. --- src/state.cpp | 83 +++++++++++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 75 insertions(+), 8 deletions(-) (limited to 'src/state.cpp') diff --git a/src/state.cpp b/src/state.cpp index 294b522..304e5ed 100644 --- a/src/state.cpp +++ b/src/state.cpp @@ -17,18 +17,46 @@ */ #include "state.h" +State::State ( ) +{ + body = new Body; + P = Matrix::Zero(9,9); + P.block(6,6,3,3) = 1e-6*Matrix3d::Identity(); + return ; +} /* ----- end of method State::State ----- */ + +void +State::vel ( const Matrix &v ) +{ + body->vel(v); + return ; +} /* ----- end of method State::vel ----- */ + +void +State::enu ( const UTM &utm ) +{ + utm_c = utm.zone_c; + utm_i = utm.zone_i; + body->enu(utm); + return ; +} /* ----- end of method State::enu ----- */ + void -State::update (Matrix &X, Matrix &P, - const Matrix H, const Matrix &h, - const Matrix &z, const Matrix &R) +State::update ( const Matrix &z ) { + Matrix H; + H=body->H(); Matrix S; + S=body->S(P); Matrix K; - S = H*P*H.transpose() + R; K = P*H.transpose()*S.inverse(); P = (Matrix::Identity()-K*H)*P; P = 0.5*(P+P.transpose()); - X += K*(z-h); + Matrix dx; + Matrix h; + h = body->h(); + dx = K*(z-h); + body->update(dx); } /* @@ -38,13 +66,52 @@ State::update (Matrix &X, Matrix &P, * Description: Updates P_k|k-1 *-------------------------------------------------------------------------------------- */ - void -State::Pkk1 ( Matrix &P, const Matrix &F, - const Matrix &Q ) +void +State::Pkk1 ( const Vector3d &ang, const Quaternion &q, const double dt) { + Matrix F,Q; + Q = body->Q(dt); + F = body->F(ang,q); P = F*P*F.transpose()+Q; // Enforce symmetry P = 0.5*(P+P.transpose()); return ; } /* ----- end of method State::Pkk1 ----- */ +void +State::motionModel ( const Vector3d &acc, const Vector3d &ang, + const Quaternion &q, const double dt) +{ + Pkk1(ang,q,dt); + body->motionModel(acc,ang,q,dt); + return ; +} /* ----- end of method State::motionModel ----- */ + +void +State::position_covariance ( const Matrix &p ) +{ + P.block(0,0,3,3) = p; + return ; +} /* ----- end of method State::position_covariance ----- */ + +void +State::velocity_covariance ( const Matrix &p ) +{ + P.block(3,3,3,3) = p; + return ; +} /* ----- end of method State::velocity_covariance ----- */ + +void +State::unicsv ( ) +{ + body->unicsv(); + return ; +} /* ----- end of method State::unicsv ----- */ + +void +State::accelerometer_bias ( const Vector3d &b) +{ + body->accelerometer_bias(b); + return ; +} /* ----- end of method State::accelerometer_bias ----- */ + -- cgit v1.1