From ec60ec9eba475fcfbdfc5d7bd157095affb7d66f Mon Sep 17 00:00:00 2001 From: Martin Miller Date: Sat, 25 Mar 2017 16:16:02 -0500 Subject: Update State::motionModel and addFeatures Add the feature motion model update to the state method. It is implemented in two ways: one is the for loop that operates on each feature instance directly, which is how it has been implemented in the past. The second method is to compose a large L matrix for all features and compute the per feature dx in one go. It is expected that the second method is faster, but it is not yet tested for speed. --- src/state.cpp | 84 +++++++++++++++++++++++++++++++++++++++++++++++++---------- src/state.h | 10 ++++--- 2 files changed, 77 insertions(+), 17 deletions(-) (limited to 'src') diff --git a/src/state.cpp b/src/state.cpp index 959cf22..a5a09fd 100644 --- a/src/state.cpp +++ b/src/state.cpp @@ -47,7 +47,7 @@ State::update ( const Matrix &z ) Matrix H; H=body->H(); Matrix S; - S=body->S(P); + S=body->S(Pxx()); Matrix K; K = P*H.transpose()*S.inverse(); P = (Matrix::Identity()-K*H)*P; @@ -78,9 +78,6 @@ State::feature_update ( const std::vector &z, const Quaterniond & void State::addFeatures ( std::vector &F, const Quaterniond &q) { - // Expand P matrix all at once - expandP(F.size()); - // // Add new features for (auto i=F.begin(); i!=F.end(); ++i) { // Estimate initial depth @@ -88,7 +85,14 @@ State::addFeatures ( std::vector &F, const Quaterniond &q) // Create feature Feature *f = new Feature(i->id, i->source, i->reflection, body->ned(), q, -0.44); + if (!f->sane()) { + delete f; + continue; + } features.push_back(f); + + // Expand P + expandP(); // Initialize P values int j=features.size(); @@ -110,8 +114,6 @@ State::addFeatures ( std::vector &F, const Quaterniond &q) State::initializePi ( int i, const Matrix &Pi ) { int pt=9+3*(i-1); - std::cout << pt << std::endl; - std::cout << P.cols() << std::endl; P.block(pt,0,3,P.cols()) = MatrixXd::Zero(3,P.cols()); P.block(0,pt,P.rows(),3) = MatrixXd::Zero(P.rows(),3); P.block<3,3>(pt,pt) = Pi; @@ -196,11 +198,63 @@ 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; + vel = body->vel(); + +#ifdef FASTMOTIONMODEL + Matrix fullL; + fullL = L(); + + Matrix V; + V << vel[1], vel[2], vel[0], ang[1], ang[2], ang[0]; + + Matrix f; + f = fullL*V*dt; + + // Update features' states + { + int rows = 3*features.size(); + auto i = features.begin(); + for (int row=0; row(row); + (*i)->dx(dx); + } + } + +#else /* ----- not FASTMOTIONMODEL ----- */ + for (auto i=features.begin(); i!=features.end(); ++i) { + (*i)->motionModel(ang,vel,dt); + } +#endif /* ----- not FASTMOTIONMODEL ----- */ return ; } /* ----- end of method State::motionModel ----- */ +/* + *-------------------------------------------------------------------------------------- + * Class: State + * Method: State :: L + * Description: Return the composition of all Li's of the features + *-------------------------------------------------------------------------------------- + */ +Matrix +State::L ( ) +{ + Matrix l; + int rows = 3*features.size(); + l = Matrix::Zero(rows,6); + { + auto i=features.begin(); + for (int row=0; row(row,0) = (*i)->L(); + } + } + return l; +} /* ----- end of method State::L ----- */ + void State::position_covariance ( const Matrix &p ) { @@ -249,17 +303,19 @@ State::exists ( int id ) *-------------------------------------------------------------------------------------- * Class: State * Method: State :: expandP - * Description: Grows P so that Nnew new features can be added. This could mean - * explicitly resizing the P matrix or P being a block of a preallocated matrix. + * Description: Expand the P matrix to fit one more feature. *-------------------------------------------------------------------------------------- */ void -State::expandP ( int Nnew ) +State::expandP ( ) { - int curRows, newRows; - curRows = P.rows(); - newRows = curRows + 3*Nnew; - P.conservativeResize(newRows,newRows); + P.conservativeResize(3+P.rows(),3+P.cols()); return ; } /* ----- end of method State::expandP ----- */ +Matrix +State::Pxx ( ) +{ + return P.topLeftCorner<9,9>() ; +} /* ----- end of method State::Pxx ----- */ + diff --git a/src/state.h b/src/state.h index 1d8dd63..67b235f 100644 --- a/src/state.h +++ b/src/state.h @@ -9,7 +9,8 @@ #include "feature.h" #include "types.h" -#define MAXFEATURES 30 +#define MAXFEATURES 50 +#define FASTMOTIONMODEL // Uncomment this to perform motion model update on all features at once using Eigen::Matrix; using Eigen::MatrixXd; using Eigen::Dynamic; @@ -34,6 +35,8 @@ class State bool exists(int id); MatrixXd F(const Quaterniond &q, const Vector3d &w, double dt); MatrixXd Q(double dt); + Matrix Pxx(); + Matrix L(); /* ==================== MUTATORS ======================================= */ void accelerometer_bias(const Vector3d &b); @@ -58,12 +61,13 @@ class State private: /* ==================== METHODS ======================================= */ - void expandP(int Nnew); + void expandP(); void addFeatures(std::vector &F, const Quaterniond &q); /* ==================== DATA MEMBERS ======================================= */ Body *body; - Matrix P; + //Matrix P; + Matrix P; char utm_c; int utm_i; std::list features; -- cgit v1.1