testEvent.cpp
Go to the documentation of this file.
1 /* ----------------------------------------------------------------------------
2 
3  * GTSAM Copyright 2010, Georgia Tech Research Corporation,
4  * Atlanta, Georgia 30332-0415
5  * All Rights Reserved
6  * Authors: Frank Dellaert, et al. (see THANKS for the full author list)
7 
8  * See LICENSE for the license information
9 
10  * -------------------------------------------------------------------------- */
11 
23 
25 
26 using namespace std::placeholders;
27 using namespace std;
28 using namespace gtsam;
29 
30 // Create a noise model for the TOA error
31 static const double ms = 1e-3;
32 static const double cm = 1e-2;
34 static SharedNoiseModel model(noiseModel::Isotropic::Sigma(1, 0.5 * ms));
35 
36 static const double timeOfEvent = 25;
37 static const Event exampleEvent(timeOfEvent, 1, 0, 0);
38 static const Point3 microphoneAt0(0, 0, 0);
39 
40 static const double kSpeedOfSound = 340;
41 static const TimeOfArrival kToa(kSpeedOfSound);
42 
43 //*****************************************************************************
44 TEST(Event, Constructor) {
45  const double t = 0;
46  Event actual(t, 201.5 * cm, 201.5 * cm, (212 - 45) * cm);
47 }
48 
49 //*****************************************************************************
50 TEST(Event, Toa1) {
51  Event event(0, 1, 0, 0);
52  double expected = 1. / kSpeedOfSound;
53  EXPECT_DOUBLES_EQUAL(expected, kToa(event, microphoneAt0), 1e-9);
54 }
55 
56 //*****************************************************************************
57 TEST(Event, Toa2) {
58  double expectedTOA = timeOfEvent + 1. / kSpeedOfSound;
60 }
61 
62 //*************************************************************************
63 TEST(Event, Derivatives) {
64  Matrix14 actualH1;
65  Matrix13 actualH2;
66  kToa(exampleEvent, microphoneAt0, actualH1, actualH2);
67  Matrix expectedH1 = numericalDerivative11<double, Event>(
68  std::bind(kToa, std::placeholders::_1, microphoneAt0, nullptr, nullptr),
69  exampleEvent);
70  EXPECT(assert_equal(expectedH1, actualH1, 1e-8));
71  Matrix expectedH2 = numericalDerivative11<double, Point3>(
72  std::bind(kToa, exampleEvent, std::placeholders::_1, nullptr, nullptr),
74  EXPECT(assert_equal(expectedH2, actualH2, 1e-8));
75 }
76 
77 //*****************************************************************************
79  Key key = 12;
80  Expression<Event> event_(key);
81  Expression<Point3> knownMicrophone_(microphoneAt0); // constant expression
82  Expression<double> expression(kToa, event_, knownMicrophone_);
83 
84  Values values;
85  values.insert(key, exampleEvent);
86  double expectedTOA = timeOfEvent + 1. / kSpeedOfSound;
87  EXPECT_DOUBLES_EQUAL(expectedTOA, expression.value(values), 1e-9);
88 }
89 
90 //*****************************************************************************
91 TEST(Event, Retract) {
92  Event event, expected(1, 2, 3, 4);
93  Vector4 v;
94  v << 1, 2, 3, 4;
95  EXPECT(assert_equal(expected, event.retract(v)));
96 }
97 
98 //*****************************************************************************
99 int main() {
100  TestResult tr;
101  return TestRegistry::runAllTests(tr);
102 }
103 //*****************************************************************************
const gtsam::Symbol key('X', 0)
TEST(Event, Constructor)
Definition: testEvent.cpp:44
static const double ms
Definition: testEvent.cpp:31
static int runAllTests(TestResult &result)
Eigen::Matrix< double, 1, 1 > Vector1
Definition: testEvent.cpp:33
Matrix expected
Definition: testMatrix.cpp:971
bool assert_equal(const Matrix &expected, const Matrix &actual, double tol)
Definition: Matrix.cpp:40
Eigen::MatrixXd Matrix
Definition: base/Matrix.h:39
leaf::MyValues values
Definition: BFloat16.h:88
Some functions to compute numerical derivatives.
Event retract(const Vector4 &v) const
Updates a with tangent space delta.
Definition: Event.h:72
#define EXPECT_DOUBLES_EQUAL(expected, actual, threshold)
Definition: Test.h:161
Expressions for Block Automatic Differentiation.
static const Event exampleEvent(timeOfEvent, 1, 0, 0)
static const Point3 microphoneAt0(0, 0, 0)
#define EXPECT(condition)
Definition: Test.h:150
Array< int, Dynamic, 1 > v
Array< double, 1, 3 > e(1./3., 0.5, 2.)
traits
Definition: chartTesting.h:28
Time of arrival to given sensor.
Definition: Event.h:87
static SharedNoiseModel model(noiseModel::Isotropic::Sigma(1, 0.5 *ms))
Space-time event.
T value(const Values &values, std::vector< Matrix > *H=nullptr) const
Return value and optional derivatives, reverse AD version Notes: this is not terribly efficient...
static const TimeOfArrival kToa(kSpeedOfSound)
void insert(Key j, const Value &val)
Definition: Values.cpp:155
Vector3 Point3
Definition: Point3.h:38
The matrix class, also used for vectors and row-vectors.
static const double kSpeedOfSound
Definition: testEvent.cpp:40
static const double timeOfEvent
Definition: testEvent.cpp:36
static const double cm
Definition: testEvent.cpp:32
int main()
Definition: testEvent.cpp:99
std::uint64_t Key
Integer nonlinear key type.
Definition: types.h:102
Point2 t(10, 10)
noiseModel::Base::shared_ptr SharedNoiseModel
Definition: NoiseModel.h:741


gtsam
Author(s):
autogenerated on Tue Jul 4 2023 02:38:06