diff --git a/examples/tests/testPlanarSLAMExample_lago.cpp b/examples/tests/testPlanarSLAMExample_lago.cpp index cdac66497..4430c8531 100644 --- a/examples/tests/testPlanarSLAMExample_lago.cpp +++ b/examples/tests/testPlanarSLAMExample_lago.cpp @@ -23,6 +23,8 @@ // the robot positions and Point2 variables (x, y) to represent the landmark coordinates. #include +#include + // Each variable in the system (poses and landmarks) must be identified with a unique key. // We can either use simple integer keys (1, 2, 3, ...) or symbols (X1, X2, L1). // Here we will use Symbols @@ -205,7 +207,7 @@ map computeThetasToRoot(vector& keysInBinary, map } /* *************************************************************************** */ -TEST( Lago, sumOverLoops ) { +TEST( Lago, orientationsOverSpanningTree ) { NonlinearFactorGraph g = simple::graph(); PredecessorMap tree = findMinimumSpanningTree >(g); @@ -222,7 +224,45 @@ TEST( Lago, sumOverLoops ) { expected[x2]= -PI; // edge x0->x2 (traversed backwards wrt edge (x2,x0)) expected[x3]= -PI/2; // edge x0->x3 (consistent with edge (x0,x3)) + vector keysInBinary; + map deltaThetaMap; + vector spanningTree; // ids of between factors forming the spanning tree T + vector chords; // ids of between factors corresponding to chords wrt T + getSymbolicSubgraph(keysInBinary, spanningTree, chords, deltaThetaMap, tree, g); + map actual; + actual = computeThetasToRoot(keysInBinary, deltaThetaMap, tree); + DOUBLES_EQUAL(expected[x0], actual[x0], 1e-6); + DOUBLES_EQUAL(expected[x1], actual[x1], 1e-6); + DOUBLES_EQUAL(expected[x2], actual[x2], 1e-6); + DOUBLES_EQUAL(expected[x3], actual[x3], 1e-6); +} + +/* + * Linear factor graph with regularized orientation measurements + */ +GaussianFactorGraph buildOrientationGraph(const vector& spanningTree, const vector& chords, + const NonlinearFactorGraph& g, map orientationsToRoot){ + GaussianFactorGraph lagoGraph; + + BOOST_FOREACH(const size_t& factorId, spanningTree){ // put original measurements in the spanning tree + Key key1 = g[factorId]->keys()[0]; + Key key2 = g[factorId]->keys()[1]; + boost::shared_ptr< BetweenFactor > pose2Between = boost::dynamic_pointer_cast< BetweenFactor >(g[factorId]); + if (!pose2Between) throw std::invalid_argument("buildOrientationGraph: invalid between factor!");; + double deltaTheta = pose2Between->measured().theta(); + //SharedNoiseModel model = g[factorId]->get_noiseModel() + //lagoGraph.add(JacobianFactor(key1, -1, key2, 1, deltaTheta, model)); + } + + return lagoGraph; +} + +/* *************************************************************************** */ +TEST( Lago, sumOverLoops ) { + NonlinearFactorGraph g = simple::graph(); + PredecessorMap tree = findMinimumSpanningTree >(g); vector keysInBinary; map deltaThetaMap; @@ -230,11 +270,15 @@ TEST( Lago, sumOverLoops ) { vector chords; // ids of between factors corresponding to chords wrt T getSymbolicSubgraph(keysInBinary, spanningTree, chords, deltaThetaMap, tree, g); - actual = computeThetasToRoot(keysInBinary, deltaThetaMap, tree); - DOUBLES_EQUAL(expected[x0], actual[x0], 1e-6); - DOUBLES_EQUAL(expected[x1], actual[x1], 1e-6); - DOUBLES_EQUAL(expected[x2], actual[x2], 1e-6); - DOUBLES_EQUAL(expected[x3], actual[x3], 1e-6); + map orientationsToRoot = computeThetasToRoot(keysInBinary, deltaThetaMap, tree); + + GaussianFactorGraph lagoGraph = buildOrientationGraph(spanningTree, chords, g, orientationsToRoot); + +// Vector2 expected; +// expected[0]= 0.0; +// expected[1]= 0.0; +// DOUBLES_EQUAL(expected[x0], actual[x0], 1e-6); +// DOUBLES_EQUAL(expected[x1], actual[x1], 1e-6); } /* *************************************************************************** */