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 
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 /* ************************************************************************* */
TestRegistry::runAllTests
static int runAllTests(TestResult &result)
Definition: TestRegistry.cpp:27
EXPECT_CORRECT_FACTOR_JACOBIANS
#define EXPECT_CORRECT_FACTOR_JACOBIANS(factor, values, numerical_derivative_step, tolerance)
Check the Jacobians produced by a factor against finite differences.
Definition: factorTesting.h:114
Vector.h
typedef and functions to augment Eigen's VectorXd
e
Array< double, 1, 3 > e(1./3., 0.5, 2.)
gtsam::NoiseModelFactor::error
double error(const Values &c) const override
Definition: NonlinearFactor.cpp:136
TestHarness.h
biased_x_rotation::bias
const Vector3 bias(1, 2, 3)
gtsam::PriorFactor
Definition: nonlinear/PriorFactor.h:30
different_sigmas::values
HybridValues values
Definition: testHybridBayesNet.cpp:245
gtsam::Vector3
Eigen::Vector3d Vector3
Definition: Vector.h:43
gtsam::Vector
Eigen::VectorXd Vector
Definition: Vector.h:38
PriorFactor.h
factorTesting.h
Evaluate derivatives of a nonlinear factor numerically.
gtsam::HybridValues::insert
void insert(Key j, const Vector &value)
Definition: HybridValues.cpp:85
gtsam::SharedNoiseModel
noiseModel::Base::shared_ptr SharedNoiseModel
Definition: NoiseModel.h:762
model
noiseModel::Diagonal::shared_ptr model
Definition: doc/Code/Pose2SLAMExample.cpp:7
EXPECT_DOUBLES_EQUAL
#define EXPECT_DOUBLES_EQUAL(expected, actual, threshold)
Definition: Test.h:161
TestResult
Definition: TestResult.h:26
ImuBias.h
TEST
TEST(PriorFactor, ConstructorScalar)
Definition: testPriorFactor.cpp:22
gtsam::imuBias::ConstantBias
Definition: ImuBias.h:32
gtsam
traits
Definition: SFMdata.h:40
gtsam::PriorFactor::evaluateError
Vector evaluateError(const T &x, OptionalMatrixType H) const override
Definition: nonlinear/PriorFactor.h:98
main
int main()
Definition: testPriorFactor.cpp:69
gtsam::Values
Definition: Values.h:65
std
Definition: BFloat16.h:88
v
Array< int, Dynamic, 1 > v
Definition: Array_initializer_list_vector_cxx11.cpp:1
callEvaluateError
Vector callEvaluateError(const PriorFactor< ConstantBias > &factor, const ConstantBias &bias)
Definition: testPriorFactor.cpp:41


gtsam
Author(s):
autogenerated on Sat Nov 16 2024 04:08:14