testPriorFactor.cpp
Go to the documentation of this file.
1 
9 #include <gtsam/base/Vector.h>
13 
14 using namespace std;
15 using namespace std::placeholders;
16 using namespace gtsam;
17 using namespace imuBias;
18 
19 /* ************************************************************************* */
20 
21 // Constructor scalar
22 TEST(PriorFactor, ConstructorScalar) {
24  PriorFactor<double> factor(1, 1.0, model);
25 }
26 
27 // Constructor vector3
28 TEST(PriorFactor, ConstructorVector3) {
29  SharedNoiseModel model = noiseModel::Isotropic::Sigma(3, 1.0);
30  PriorFactor<Vector3> factor(1, Vector3(1, 2, 3), model);
31 }
32 
33 // Constructor dynamic sized vector
34 TEST(PriorFactor, ConstructorDynamicSizeVector) {
35  Vector v(5);
36  v << 1, 2, 3, 4, 5;
37  SharedNoiseModel model = noiseModel::Isotropic::Sigma(5, 1.0);
38  PriorFactor<Vector> factor(1, v, model);
39 }
40 
42  const ConstantBias& bias) {
43  return factor.evaluateError(bias);
44 }
45 
46 // Test for imuBias::ConstantBias
48  Vector3 biasAcc(1, 2, 3);
49  Vector3 biasGyro(0.1, 0.2, 0.3);
50  ConstantBias bias(biasAcc, biasGyro);
51 
52  PriorFactor<ConstantBias> factor(1, bias,
53  noiseModel::Isotropic::Sigma(6, 0.1));
54  Values values;
55  values.insert(1, bias);
56 
57  EXPECT_DOUBLES_EQUAL(0.0, factor.error(values), 1e-8);
58  EXPECT_CORRECT_FACTOR_JACOBIANS(factor, values, 1e-7, 1e-5);
59 
60  ConstantBias incorrectBias(
61  (Vector6() << 1.1, 2.1, 3.1, 0.2, 0.3, 0.4).finished());
62  values.clear();
63  values.insert(1, incorrectBias);
64  EXPECT_DOUBLES_EQUAL(3.0, factor.error(values), 1e-8);
65  EXPECT_CORRECT_FACTOR_JACOBIANS(factor, values, 1e-7, 1e-5);
66 }
67 
68 /* ************************************************************************* */
69 int main() {
70  TestResult tr;
71  return TestRegistry::runAllTests(tr);
72 }
73 /* ************************************************************************* */
Vector evaluateError(const T &x, OptionalMatrixType H) const override
void clear()
Definition: Values.h:298
static int runAllTests(TestResult &result)
Eigen::Vector3d Vector3
Definition: Vector.h:43
noiseModel::Diagonal::shared_ptr model
leaf::MyValues values
Definition: BFloat16.h:88
Evaluate derivatives of a nonlinear factor numerically.
#define EXPECT_DOUBLES_EQUAL(expected, actual, threshold)
Definition: Test.h:161
int main()
Eigen::VectorXd Vector
Definition: Vector.h:38
Array< int, Dynamic, 1 > v
Array< double, 1, 3 > e(1./3., 0.5, 2.)
traits
Definition: chartTesting.h:28
typedef and functions to augment Eigen&#39;s VectorXd
double error(const Values &c) const override
#define EXPECT_CORRECT_FACTOR_JACOBIANS(factor, values, numerical_derivative_step, tolerance)
Check the Jacobians produced by a factor against finite differences.
Vector callEvaluateError(const PriorFactor< ConstantBias > &factor, const ConstantBias &bias)
TEST(PriorFactor, ConstructorScalar)
void insert(Key j, const Value &val)
Definition: Values.cpp:155
noiseModel::Base::shared_ptr SharedNoiseModel
Definition: NoiseModel.h:741


gtsam
Author(s):
autogenerated on Tue Jul 4 2023 02:39:05