/* * ===================================================================================== * * Filename: body.cpp * * Description: Method definitions for body class. * * Version: 1.0 * Created: 03/17/2017 08:07:35 PM * Revision: none * Compiler: gcc * * Author: Martin Miller (MHM), miller7@illinois.edu * Organization: Aerospace Robotics and Controls Lab (ARC) * * ===================================================================================== */ #include "body.h" /* *-------------------------------------------------------------------------------------- * Class: Body * Method: Body :: update * Description: Increments the state by dx after a Kalman update. *-------------------------------------------------------------------------------------- */ void Body::update ( const Matrix &dx ) { X += dx; return ; } /* ----- end of method Body::update ----- */ void Body::vel ( const Matrix &v ) { X.segment(3,3) = v; return ; } /* ----- end of method Body::vel ----- */ /* *-------------------------------------------------------------------------------------- * Class: Body * Method: Body :: S * Description: Returns the matrix S=HPH.T+R. HPH.T is trivial, so Body::H() is * not called explicitly. *-------------------------------------------------------------------------------------- */ Matrix Body::S ( const Matrix &P ) { Matrix S; S << P(2,2); return S+R(); } /* ----- end of method Body::S ----- */ /* *-------------------------------------------------------------------------------------- * Class: Body * Method: Body :: enu * Description: Stores the position input as ENU. Internally stored as NED. *-------------------------------------------------------------------------------------- */ void Body::enu ( const UTM &utm ) { utm_c = utm.zone_c; utm_i = utm.zone_i; X[0] = utm.northing; X[1] = utm.easting; X[2] = -utm.up; return ; } /* ----- end of method Body::enu ----- */ /* *-------------------------------------------------------------------------------------- * Class: Body * Method: Body :: R * Description: Returns R matrix of measurement noise for height measurement. *-------------------------------------------------------------------------------------- */ Matrix Body::R() { Matrix R; R << 1e-8; return R; } /* *-------------------------------------------------------------------------------------- * Class: Body * Method: Body :: Q * Description: Returns Q matrix of process noise for the body. *-------------------------------------------------------------------------------------- */ Matrix Body::Q (double dt) { Matrix Q; Q = Matrix::Zero(); Q.block<3,3>(0,0) = 0.25*dt*dt*dt*dt*Matrix::Identity(); Q.block<3,3>(3,0) = 0.5*dt*dt*dt*Matrix::Identity(); Q.block<3,3>(0,3) = 0.5*dt*dt*dt*Matrix::Identity(); Q.block<3,3>(3,3) = dt*dt*Matrix::Identity(); Q *= 800e-6; Q.block<3,3>(6,6) = dt*dt*5e-3*Matrix::Identity(); return Q; } /* ----- end of method Body::q ----- */ /* *-------------------------------------------------------------------------------------- * Class: Body * Method: Body :: H * Description: Returns the Jacobian of the measurement model, H. *-------------------------------------------------------------------------------------- */ Matrix Body::H ( ) { Matrix H; H = Matrix::Zero(); H[0,2] = 1; return H ; } /* ----- end of method Body::H ----- */ /* *-------------------------------------------------------------------------------------- * Class: Body * Method: Body :: h * Description: Returns the predicted measurement vector, h. *-------------------------------------------------------------------------------------- */ Matrix Body::h ( ) { Matrix h; h[0] = X[2]; return h; } /* ----- end of method Body::h_hat ----- */ /* *-------------------------------------------------------------------------------------- * Class: Body * Method: Body :: F * Description: Returns the Jacobian of the motion model of the body. *-------------------------------------------------------------------------------------- */ Matrix Body::F ( const Vector3d &ang, const Quaterniond &q, double dt ) { Matrix F = Matrix::Zero(); Matrix Rbw(q.toRotationMatrix()); Matrix W; W = skewSymmetric(ang); F.block<3,3>(0,3) = Rbw; F.block<3,3>(3,3) = -W; F.block<3,3>(3,6) = -Matrix::Identity(); F *= dt; F += Matrix::Identity(); return F; } /* ----- end of method Body::F ----- */ /* *-------------------------------------------------------------------------------------- * Class: Body * Method: Body :: motionModel * Description: Propagates the motion model of the body into vector X. *-------------------------------------------------------------------------------------- */ void Body::motionModel ( const Vector3d &acc, const Vector3d &ang, const Quaterniond &q, const double dt) { Vector3d bias(X.segment(6,3)); Vector3d gravity_world(0.,0.,9.80655); Matrix A; Matrix b; A = Matrix::Zero(); b = Matrix::Zero(); Matrix Rbw(q.toRotationMatrix()); A.block<3,3>(0,0) = Rbw; Matrix W; W = skewSymmetric(ang); A.block<3,3>(3,0) = -W; b.segment(3,3) = acc-bias+Rbw.transpose()*gravity_world; X.segment(0,6) += (A*X.segment(3,3)+b)*dt; return ; } /* ----- end of method Body::motionModel ----- */ /* *-------------------------------------------------------------------------------------- * Class: Body * Method: Body :: skewSymmetric * Description: Create the skew symmetric matrix y from the vector x. *-------------------------------------------------------------------------------------- */ Matrix Body::skewSymmetric ( const Vector3d &x ) { Matrix y; y << 0.,-x[2], x[1], x[2],0.,-x[0],-x[1],x[0],0.; return y; } /* ----- end of method Body::skewSymmetric ----- */ void Body::unicsv ( ) { printf("%d,%c,%f,%f,%f,%f,%f,%f,%f,%f,%f\n", utm_i, utm_c, X[0], X[1], -X[2], X[3], X[4], X[5], X[6], X[7], X[8]); return ; } /* ----- end of method Body::unicsv ----- */ void Body::accelerometer_bias ( const Vector3d &b ) { X.segment(6,3) = b; return ; } /* ----- end of method State::accelerometer_bias ----- */