-
Notifications
You must be signed in to change notification settings - Fork 769
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Wrap ISAM2 full update method #1569
Merged
Merged
Changes from 4 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
d3bcfdd
ISAM2: wrap full update method and error method
varunagrawal 6992f0d
added test for full ISAM2 update method
varunagrawal 42e8f49
added tests for newly wrapped isam2 methods
varunagrawal 93ed850
get tests working
varunagrawal a14fb8d
formatting and fix
varunagrawal File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,24 +6,29 @@ | |
See LICENSE for the license information | ||
|
||
visual_isam unit tests. | ||
Author: Frank Dellaert & Duy Nguyen Ta (Python) | ||
Author: Frank Dellaert & Duy Nguyen Ta & Varun Agrawal (Python) | ||
""" | ||
# pylint: disable=maybe-no-member,invalid-name | ||
|
||
import unittest | ||
|
||
import gtsam.utils.visual_data_generator as generator | ||
import gtsam.utils.visual_isam as visual_isam | ||
from gtsam import symbol | ||
from gtsam.utils.test_case import GtsamTestCase | ||
|
||
import gtsam | ||
from gtsam import symbol | ||
|
||
|
||
class TestVisualISAMExample(GtsamTestCase): | ||
"""Test class for ISAM2 with visual landmarks.""" | ||
def test_VisualISAMExample(self): | ||
"""Test to see if ISAM works as expected for a simple visual SLAM example.""" | ||
|
||
def setUp(self): | ||
# Data Options | ||
options = generator.Options() | ||
options.triangle = False | ||
options.nrCameras = 20 | ||
self.options = options | ||
|
||
# iSAM Options | ||
isamOptions = visual_isam.Options() | ||
|
@@ -32,26 +37,87 @@ def test_VisualISAMExample(self): | |
isamOptions.batchInitialization = True | ||
isamOptions.reorderInterval = 10 | ||
isamOptions.alwaysRelinearize = False | ||
self.isamOptions = isamOptions | ||
|
||
# Generate data | ||
data, truth = generator.generate_data(options) | ||
self.data, self.truth = generator.generate_data(options) | ||
|
||
def test_VisualISAMExample(self): | ||
"""Test to see if ISAM works as expected for a simple visual SLAM example.""" | ||
# Initialize iSAM with the first pose and points | ||
isam, result, nextPose = visual_isam.initialize( | ||
data, truth, isamOptions) | ||
self.data, self.truth, self.isamOptions) | ||
|
||
# Main loop for iSAM: stepping through all poses | ||
for currentPose in range(nextPose, self.options.nrCameras): | ||
isam, result = visual_isam.step(self.data, isam, result, | ||
self.truth, currentPose) | ||
|
||
for i, true_camera in enumerate(self.truth.cameras): | ||
pose_i = result.atPose3(symbol('x', i)) | ||
self.gtsamAssertEquals(pose_i, true_camera.pose(), 1e-5) | ||
|
||
for j, expected_point in enumerate(self.truth.points): | ||
point_j = result.atPoint3(symbol('l', j)) | ||
self.gtsamAssertEquals(point_j, expected_point, 1e-5) | ||
|
||
def test_isam2_error(self): | ||
"""Test for isam2 error() method.""" | ||
#TODO(Varun) fix | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. TODO There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done |
||
# Initialize iSAM with the first pose and points | ||
isam, result, nextPose = visual_isam.initialize( | ||
self.data, self.truth, self.isamOptions) | ||
|
||
# Main loop for iSAM: stepping through all poses | ||
for currentPose in range(nextPose, self.options.nrCameras): | ||
isam, result = visual_isam.step(self.data, isam, result, | ||
self.truth, currentPose) | ||
|
||
values = gtsam.VectorValues() | ||
|
||
estimate = isam.calculateBestEstimate() | ||
|
||
for key in estimate.keys(): | ||
try: | ||
v = gtsam.Pose3.Logmap(estimate.atPose3(key)) | ||
except RuntimeError: | ||
v = estimate.atPoint3(key) | ||
|
||
print(key) | ||
print(type(v)) | ||
print(v) | ||
values.insert(key, v) | ||
print(isam.error(values)) | ||
|
||
self.assertEqual(isam.error(values), 34212421.14731998) | ||
|
||
def test_isam2_update(self): | ||
""" | ||
Test for full version of ISAM2::update method | ||
""" | ||
# Initialize iSAM with the first pose and points | ||
isam, result, nextPose = visual_isam.initialize( | ||
self.data, self.truth, self.isamOptions) | ||
|
||
remove_factor_indices = [] | ||
constrained_keys = gtsam.KeyGroupMap() | ||
no_relin_keys = gtsam.KeyList() | ||
extra_reelim_keys = gtsam.KeyList() | ||
isamArgs = (remove_factor_indices, constrained_keys, no_relin_keys, | ||
extra_reelim_keys, False) | ||
|
||
# Main loop for iSAM: stepping through all poses | ||
for currentPose in range(nextPose, options.nrCameras): | ||
isam, result = visual_isam.step(data, isam, result, truth, | ||
currentPose) | ||
for currentPose in range(nextPose, self.options.nrCameras): | ||
isam, result = visual_isam.step(self.data, isam, result, | ||
self.truth, currentPose, isamArgs) | ||
|
||
for i, _ in enumerate(truth.cameras): | ||
for i in range(len(self.truth.cameras)): | ||
pose_i = result.atPose3(symbol('x', i)) | ||
self.gtsamAssertEquals(pose_i, truth.cameras[i].pose(), 1e-5) | ||
self.gtsamAssertEquals(pose_i, self.truth.cameras[i].pose(), 1e-5) | ||
|
||
for j, _ in enumerate(truth.points): | ||
for j in range(len(self.truth.points)): | ||
point_j = result.atPoint3(symbol('l', j)) | ||
self.gtsamAssertEquals(point_j, truth.points[j], 1e-5) | ||
self.gtsamAssertEquals(point_j, self.truth.points[j], 1e-5) | ||
|
||
|
||
if __name__ == "__main__": | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we have space here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done