From 527ea5e5114220a663c8a14192a49ade6278d762 Mon Sep 17 00:00:00 2001 From: Alex Cunningham Date: Wed, 12 Jun 2013 20:01:59 +0000 Subject: [PATCH] Moved serialization tests over to a single test scenario - factors don't appear to work at the moment --- .../testGraphValuesSerialization.m | 56 +++++++++++++++++++ matlab/gtsam_tests/testPlanarSLAMExample.m | 10 ---- matlab/gtsam_tests/testPose2SLAMExample.m | 10 ---- matlab/gtsam_tests/test_gtsam.m | 3 + 4 files changed, 59 insertions(+), 20 deletions(-) create mode 100644 matlab/gtsam_tests/testGraphValuesSerialization.m diff --git a/matlab/gtsam_tests/testGraphValuesSerialization.m b/matlab/gtsam_tests/testGraphValuesSerialization.m new file mode 100644 index 000000000..1d4066c82 --- /dev/null +++ b/matlab/gtsam_tests/testGraphValuesSerialization.m @@ -0,0 +1,56 @@ +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% GTSAM Copyright 2010, Georgia Tech Research Corporation, +% Atlanta, Georgia 30332-0415 +% All Rights Reserved +% Authors: Frank Dellaert, et al. (see THANKS for the full author list) +% +% See LICENSE for the license information +% +% @brief Simple robotics example using the pre-built planar SLAM domain +% @author Alex Cunningham +% @author Frank Dellaert +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +import gtsam.* + +%% Create keys for variables +i1 = symbol('x',1); i2 = symbol('x',2); i3 = symbol('x',3); +j1 = symbol('l',1); j2 = symbol('l',2); + +%% Create graph and factors +graph = NonlinearFactorGraph; + +% Prior factor - FAIL: unregistered class +priorMean = Pose2(0.0, 0.0, 0.0); % prior at origin +priorNoise = noiseModel.Diagonal.Sigmas([0.3; 0.3; 0.1]); +graph.add(PriorFactorPose2(i1, priorMean, priorNoise)); % add directly to graph + +% Between Factors - FAIL: unregistered class +odometry = Pose2(2.0, 0.0, 0.0); +odometryNoise = noiseModel.Diagonal.Sigmas([0.2; 0.2; 0.1]); +graph.add(BetweenFactorPose2(i1, i2, odometry, odometryNoise)); +graph.add(BetweenFactorPose2(i2, i3, odometry, odometryNoise)); + +% BearingRange Factors - FAIL: unregistered class +degrees = pi/180; +brNoise = noiseModel.Diagonal.Sigmas([0.1; 0.2]); +graph.add(BearingRangeFactor2D(i1, j1, Rot2(45*degrees), sqrt(4+4), brNoise)); +graph.add(BearingRangeFactor2D(i2, j1, Rot2(90*degrees), 2, brNoise)); +graph.add(BearingRangeFactor2D(i3, j2, Rot2(90*degrees), 2, brNoise)); + +%% Create Values +values = Values; +values.insert(i1, Pose2(0.5, 0.0, 0.2)); +values.insert(i2, Pose2(2.3, 0.1,-0.2)); +values.insert(i3, Pose2(4.1, 0.1, 0.1)); +values.insert(j1, Point2(1.8, 2.1)); +values.insert(j2, Point2(4.1, 1.8)); + +%% Check that serialization works properly +serialized_values = serializeValues(values); % returns a string +deserializedValues = deserializeValues(serialized_values); % returns a new values +CHECK('values.equals(deserializedValues)',values.equals(deserializedValues,1e-9)); + +serialized_graph = serializeGraph(graph); % returns a string +deserializedGraph = deserializeGraph(serialized_graph); % returns a new graph +CHECK('graph.equals(deserializedGraph)',graph.equals(deserializedGraph,1e-9)); \ No newline at end of file diff --git a/matlab/gtsam_tests/testPlanarSLAMExample.m b/matlab/gtsam_tests/testPlanarSLAMExample.m index 584b86345..7694a1a0b 100644 --- a/matlab/gtsam_tests/testPlanarSLAMExample.m +++ b/matlab/gtsam_tests/testPlanarSLAMExample.m @@ -67,13 +67,3 @@ CHECK('pose_1.equals(Pose2,1e-4)',pose_1.equals(Pose2,1e-4)); point_1 = result.at(symbol('l',1)); marginals.marginalCovariance(symbol('l',1)); CHECK('point_1.equals(Point2(2,2),1e-4)',point_1.equals(Point2(2,2),1e-4)); - -%% Check that serialization works properly -serialized_values = serializeValues(initialEstimate); -deserializedValues = deserializeValues(serialized_values); -CHECK('initialEstimate.equals(deserializedValues)',initialEstimate.equals(deserializedValues,1e-9)); - -% FAILS: unregistered class? -% serialized_graph = serializeGraph(graph); -% deserializedGraph = deserializeGraph(serialized_graph); -% CHECK('graph.equals(deserializedGraph)',graph.equals(deserializedGraph,1e-9)); \ No newline at end of file diff --git a/matlab/gtsam_tests/testPose2SLAMExample.m b/matlab/gtsam_tests/testPose2SLAMExample.m index 2ac354955..8c70c27e7 100644 --- a/matlab/gtsam_tests/testPose2SLAMExample.m +++ b/matlab/gtsam_tests/testPose2SLAMExample.m @@ -60,13 +60,3 @@ P = marginals.marginalCovariance(1); pose_1 = result.at(1); CHECK('pose_1.equals(Pose2,1e-4)',pose_1.equals(Pose2,1e-4)); - -%% Check that serialization works properly -serialized_values = serializeValues(initialEstimate); -deserializedValues = deserializeValues(serialized_values); -CHECK('initialEstimate.equals(deserializedValues)',initialEstimate.equals(deserializedValues,1e-9)); - -% FAILS: unregistered class? -% serialized_graph = serializeGraph(graph); -% deserializedGraph = deserializeGraph(serialized_graph); -% CHECK('graph.equals(deserializedGraph)',graph.equals(deserializedGraph,1e-9)); diff --git a/matlab/gtsam_tests/test_gtsam.m b/matlab/gtsam_tests/test_gtsam.m index 113e594fd..1f8125b81 100644 --- a/matlab/gtsam_tests/test_gtsam.m +++ b/matlab/gtsam_tests/test_gtsam.m @@ -30,5 +30,8 @@ testStereoVOExample display 'Starting: testVisualISAMExample' testVisualISAMExample +display 'Starting: testGraphValuesSerialization' +testVisualISAMExample + % end of tests display 'Tests complete!'