diff --git a/gtsam_unstable/geometry/Event.h b/gtsam_unstable/geometry/Event.h index 039c963d6..143f849bc 100644 --- a/gtsam_unstable/geometry/Event.h +++ b/gtsam_unstable/geometry/Event.h @@ -34,6 +34,7 @@ public: /// Speed of sound static const double Speed; + static const Matrix14 JacobianZ; /// Default Constructor Event() : @@ -53,6 +54,12 @@ public: double time() const { return time_;} Point3 location() const { return location_;} + // TODO we really have to think of a better way to do linear arguments + double height(OptionalJacobian<1,4> H = boost::none) const { + if (H) *H = JacobianZ; + return location_.z(); + } + /** print with optional string */ void print(const std::string& s = "") const { std::cout << s << "time = " << time_; @@ -101,6 +108,7 @@ public: }; const double Event::Speed = 330; +const Matrix14 Event::JacobianZ = (Matrix14() << 0,0,0,1).finished(); // Define GTSAM traits namespace traits { diff --git a/gtsam_unstable/slam/tests/testTOAFactor.cpp b/gtsam_unstable/slam/tests/testTOAFactor.cpp index 6944befbf..ef95917e1 100644 --- a/gtsam_unstable/slam/tests/testTOAFactor.cpp +++ b/gtsam_unstable/slam/tests/testTOAFactor.cpp @@ -40,8 +40,12 @@ static const double timeOfEvent = 25; static const Event exampleEvent(timeOfEvent, 1, 0, 0); static const Point3 microphoneAt0; -// A TOA factor factory :-) -MakeBinaryFactor makeFactor(&Event::toa, model); +// A TOA factor factory +static MakeBinaryFactor MakeFactor(&Event::toa, model); + +// A height prior factory +static SharedNoiseModel heightModel(noiseModel::Isotropic::Sigma(1, 100*cm)); +static MakeUnaryFactor MakePrior(&Event::height, heightModel); //***************************************************************************** TEST( TOAFactor, NewWay ) { @@ -49,7 +53,7 @@ TEST( TOAFactor, NewWay ) { Expression eventExpression(key); Expression microphoneConstant(microphoneAt0); // constant expression double z = 7; - ExpressionFactor factor = makeFactor(z, eventExpression, microphoneConstant); + ExpressionFactor factor = MakeFactor(z, eventExpression, microphoneConstant); } //***************************************************************************** @@ -63,9 +67,9 @@ TEST( TOAFactor, WholeEnchilada ) { microphones.push_back(Point3(0, 0, height)); microphones.push_back(Point3(403 * cm, 0, height)); microphones.push_back(Point3(403 * cm, 403 * cm, height)); - microphones.push_back(Point3(0, 403 * cm, height)); + microphones.push_back(Point3(0, 403 * cm, 2*height)); EXPECT_LONGS_EQUAL(4, microphones.size()); - microphones.push_back(Point3(200 * cm, 200 * cm, height)); +// microphones.push_back(Point3(200 * cm, 200 * cm, height)); // Create a ground truth point const double timeOfEvent = 0; @@ -88,7 +92,7 @@ TEST( TOAFactor, WholeEnchilada ) { Expression eventExpression(key); for (size_t i = 0; i < K; i++) { Expression microphoneConstant(microphones[i]); // constant expression - graph.add(makeFactor(measurements[i], eventExpression, microphoneConstant)); + graph.add(MakeFactor(measurements[i], eventExpression, microphoneConstant)); } /// Print the graph @@ -123,7 +127,7 @@ TEST( TOAFactor, WholeEnchilada ) { /// Test real data TEST( TOAFactor, RealExperiment1 ) { - static const bool verbose = false; + static const bool verbose = true; // Create microphones const double height = 0.5; @@ -170,10 +174,14 @@ TEST( TOAFactor, RealExperiment1 ) { for (size_t i = 0; i < 4; i++) { Expression mic_(microphones[i]); // constant expression for (size_t j = 0; j < 15; j++) - graph.add(makeFactor(data[j][i], eventExpressions[j], mic_)); + graph.add(MakeFactor(data[j][i], eventExpressions[j], mic_)); } - /// Print the graph + // Add height priors + for (size_t j = 0; j < 15; j++) + graph.add(MakePrior((212 - 45) * cm, eventExpressions[j])); + + /// Print the graph if (verbose) GTSAM_PRINT(graph);