25 #ifndef INCLUDED_TestIMU_Common_h_GUID_F125CC83_F6D6_4EA5_9281_0DBEC87D309D
26 #define INCLUDED_TestIMU_Common_h_GUID_F125CC83_F6D6_4EA5_9281_0DBEC87D309D
42 using std::unique_ptr;
44 using namespace vbtracker;
45 using namespace Eigen;
51 state.setErrorCovariance(
55 originalStateError = state.errorCovariance();
59 processModel.setNoiseAutocorrelation(
65 EIGEN_MAKE_ALIGNED_OPERATOR_NEW
67 Eigen::Quaterniond roomToCameraRotation = Eigen::Quaterniond::Identity();
74 Eigen::Quaterniond
xform(Eigen::Quaterniond
const &quat) {
75 return getTransformedOrientation(quat, roomToCameraRotation,
85 Eigen::Vector3d imuVariance;
88 inline void outputQuat(std::ostream &os, Quaterniond
const &q) {
89 os <<
"[" << q.w() <<
" (" << q.vec().transpose() <<
")]";
91 inline std::ostream &operator<<(std::ostream &os, Quaterniond
const &q) {
99 static const char *
get() {
return "kalman::QFirst"; }
102 static const char *
get() {
return "kalman::QLast"; }
105 static const char *
get() {
return "kalman::SplitQ"; }
109 static const double SMALL_VALUE = 0.1;
111 template <
typename MeasurementType,
typename InProgressType>
112 inline void commonSmallPositiveYChecks(
TestData *data,
113 MeasurementType &kalmanMeas,
114 InProgressType &inProgress) {
116 Vector3d residual = kalmanMeas.getResidual(data->
state);
118 CAPTURE(residual.transpose());
119 AND_THEN(
"residual directly computed by measurement should be 0, "
121 CHECK(residual.isApprox(Vector3d(0, SMALL_VALUE, 0)));
124 CAPTURE(inProgress.deltaz.transpose());
125 AND_THEN(
"computed deltaz should equal residual") {
126 CHECK(residual.isApprox(inProgress.deltaz));
129 AND_THEN(
"delta z (residual/propagated mean residual) should be "
130 "approximately 0, SMALL_VALUE, 0") {
131 REQUIRE(inProgress.deltaz[0] == Approx(0.));
132 REQUIRE(inProgress.deltaz[1] == Approx(SMALL_VALUE));
133 REQUIRE(inProgress.deltaz[2] == Approx(0.));
136 CAPTURE(inProgress.stateCorrection.transpose());
137 AND_THEN(
"state correction should have a rotation component with small "
139 REQUIRE(inProgress.stateCorrectionFinite);
140 REQUIRE(inProgress.stateCorrection[3] == Approx(0.));
141 REQUIRE(inProgress.stateCorrection[4] > 0);
142 REQUIRE(inProgress.stateCorrection[4] < SMALL_VALUE);
143 REQUIRE(inProgress.stateCorrection[5] == Approx(0.));
146 AND_THEN(
"state correction should have an angular velocity component "
147 "with zero or small positive y") {
148 REQUIRE(inProgress.stateCorrection[9] == Approx(0.));
149 REQUIRE(inProgress.stateCorrection[10] >= 0.);
150 REQUIRE(inProgress.stateCorrection[11] == Approx(0.));
152 AND_THEN(
"state correction should not contain any translational/linear "
153 "velocity components") {
154 REQUIRE(inProgress.stateCorrection.template head<3>().isZero());
156 inProgress.stateCorrection.template segment<3>(6).isZero());
158 AND_WHEN(
"the correction is applied") {
159 auto errorCovarianceCorrectionWasFinite = inProgress.finishCorrection();
160 THEN(
"the new error covariance should be finite") {
161 REQUIRE(errorCovarianceCorrectionWasFinite);
162 AND_THEN(
"State error should have decreased") {
164 data->originalStateError.array())
171 template <
typename MeasurementType>
172 inline void smallPositiveYChecks(
TestData *data, MeasurementType &kalmanMeas) {
173 using JacobianType =
typename MeasurementType::JacobianType;
175 JacobianType jacobian = kalmanMeas.getJacobian(data->
state);
176 AND_THEN(
"the jacobian should be finite") {
177 INFO(
"jacobian\n" << jacobian);
178 REQUIRE(jacobian.allFinite());
179 AND_THEN(
"the jacobian should not be zero") {
180 REQUIRE_FALSE(jacobian.isZero());
183 data->
state, data->processModel, kalmanMeas);
184 commonSmallPositiveYChecks(data, kalmanMeas, inProgress);
188 #endif // INCLUDED_TestIMU_Common_h_GUID_F125CC83_F6D6_4EA5_9281_0DBEC87D309D
AngleRadiansd Angle
Default angle type.
Eigen::Matrix< Scalar, n, 1 > Vector
A vector of length n.
double linearVelocityDecayCoefficient
double processNoiseAutocorrelation[6]
Vector< Dimension< T >::value > DimVector
A vector of length = dimension of T.
StateSquareMatrix const & errorCovariance() const
P.
SquareMatrix< Dimension< T >::value > DimSquareMatrix
A square matrix, n x n, where n is the dimension of T.
IMUInputParams imu
IMU input-related parameters.
CorrectionInProgress< StateType, MeasurementType > beginCorrection(StateType &state, ProcessModelType &processModel, MeasurementType &meas)
General configuration parameters.
Can specialize to get better names.
Eigen::Quaterniond xform(Eigen::Quaterniond const &quat)
double angularVelocityDecayCoefficient