-
Notifications
You must be signed in to change notification settings - Fork 163
[ImuFactor] Add an on manifold Imu Factor #279
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
Closed
bradley-solliday-skydio
wants to merge
1
commit into
main
from
bradley.solliday/revup/main/on_manifold_imu_factor
Closed
Changes from all commits
Commits
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 hidden or 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
815 changes: 815 additions & 0 deletions
815
gen/cpp/sym/factors/internal/imu_manifold_preintegration_update.h
Large diffs are not rendered by default.
Oops, something went wrong.
937 changes: 937 additions & 0 deletions
937
gen/cpp/sym/factors/internal/imu_manifold_preintegration_update_auto_derivative.h
Large diffs are not rendered by default.
Oops, something went wrong.
2,377 changes: 2,377 additions & 0 deletions
2,377
gen/cpp/sym/factors/internal/internal_imu_factor.h
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or 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 hidden or 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 hidden or 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 |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| # ---------------------------------------------------------------------------- | ||
| # SymForce - Copyright 2022, Skydio, Inc. | ||
| # This source code is under the Apache 2.0 license found in the LICENSE file. | ||
| # ---------------------------------------------------------------------------- | ||
|
|
||
| # ============================================================================== | ||
| # SymForce Targets | ||
| # ============================================================================== | ||
|
|
||
| file(GLOB_RECURSE SYMFORCE_SLAM_SOURCES CONFIGURE_DEPENDS *.cc **/*.cc) | ||
| file(GLOB_RECURSE SYMFORCE_SLAM_HEADERS CONFIGURE_DEPENDS *.h **/*.h *.tcc **/*.tcc) | ||
|
|
||
| add_library( | ||
| symforce_slam | ||
| ${SYMFORCE_LIBRARY_TYPE} | ||
| ${SYMFORCE_SLAM_SOURCES} | ||
| ${SYMFORCE_SLAM_HEADERS} | ||
| ) | ||
| target_compile_options(symforce_slam PRIVATE ${SYMFORCE_COMPILE_OPTIONS}) | ||
| target_link_libraries(symforce_slam | ||
| symforce_gen | ||
| symforce_opt | ||
| ${SYMFORCE_EIGEN_TARGET} | ||
| ) |
Empty file.
Empty file.
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1,73 @@ | ||
| # ---------------------------------------------------------------------------- | ||
| # SymForce - Copyright 2022, Skydio, Inc. | ||
| # This source code is under the Apache 2.0 license found in the LICENSE file. | ||
| # ---------------------------------------------------------------------------- | ||
|
|
||
| import functools | ||
|
|
||
| from symforce import codegen | ||
| from symforce import typing as T | ||
| from symforce.slam.imu_preintegration.manifold_symbolic import imu_manifold_preintegration_update | ||
| from symforce.slam.imu_preintegration.manifold_symbolic import internal_imu_residual | ||
|
|
||
|
|
||
| def generate_manifold_imu_preintegration( | ||
| config: codegen.CodegenConfig, output_dir: T.Openable | ||
| ) -> None: | ||
| """ | ||
| Generate the on-manifold IMU preintegration update and residual functions. | ||
| """ | ||
|
|
||
| update_output_names = [ | ||
| "new_DR", | ||
| "new_Dv", | ||
| "new_Dp", | ||
| "new_covariance", | ||
| "new_DR_D_gyro_bias", | ||
| "new_Dv_D_accel_bias", | ||
| "new_Dv_D_gyro_bias", | ||
| "new_Dp_D_accel_bias", | ||
| "new_Dp_D_gyro_bias", | ||
| ] | ||
|
|
||
| codegen_update = codegen.Codegen.function( | ||
| functools.partial(imu_manifold_preintegration_update, use_handwritten_derivatives=True), | ||
| config=config, | ||
| output_names=update_output_names, | ||
| ) | ||
| codegen_update.generate_function(output_dir=output_dir, skip_directory_nesting=True) | ||
|
|
||
| codegen_update_auto_derivative = codegen.Codegen.function( | ||
| functools.partial(imu_manifold_preintegration_update, use_handwritten_derivatives=False), | ||
| name="imu_manifold_preintegration_update_auto_derivative", | ||
| docstring=""" | ||
| Alternative to ImuManifoldPreintegrationUpdate that uses auto-derivatives. Exists only to | ||
| help verify correctness of ImuManifoldPreintegrationUpdate. Should have the same output. | ||
| Since this function is more expensive, there is no reason to use it instead. | ||
| """ | ||
|
Comment on lines
+43
to
+47
Member
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. No need to change anything here, but |
||
| + ( | ||
| imu_manifold_preintegration_update.__doc__ | ||
| if imu_manifold_preintegration_update.__doc__ is not None | ||
| else "" | ||
| ), | ||
| config=config, | ||
| output_names=update_output_names, | ||
| ) | ||
| codegen_update_auto_derivative.generate_function( | ||
| output_dir=output_dir, skip_directory_nesting=True | ||
| ) | ||
|
|
||
| codegen_residual = codegen.Codegen.function( | ||
| internal_imu_residual, | ||
| config=config, | ||
| ).with_linearization( | ||
| which_args=[ | ||
| "pose_i", | ||
| "vel_i", | ||
| "pose_j", | ||
| "vel_j", | ||
| "accel_bias_i", | ||
| "gyro_bias_i", | ||
| ] | ||
| ) | ||
| codegen_residual.generate_function(output_dir=output_dir, skip_directory_nesting=True) | ||
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1,53 @@ | ||
| /* ---------------------------------------------------------------------------- | ||
| * SymForce - Copyright 2022, Skydio, Inc. | ||
| * This source code is under the Apache 2.0 license found in the LICENSE file. | ||
| * ---------------------------------------------------------------------------- */ | ||
|
|
||
| #include "./imu_factor.h" | ||
|
|
||
| #include <Eigen/Cholesky> | ||
|
|
||
| #include <sym/factors/internal/internal_imu_factor.h> | ||
|
|
||
| #include "preintegrated_imu_measurements.h" | ||
|
|
||
| namespace sym { | ||
|
|
||
| template <typename Scalar> | ||
| ImuFactor<Scalar>::ImuFactor(const ImuPreintegrator<Scalar>& preintegrator) | ||
| : preintegrated_measurements_{preintegrator.PreintegratedMeasurements()}, | ||
| // NOTE(brad, chao): llt then inverse is 2x faster than inverse then llt | ||
| sqrt_info_{preintegrator.Covariance().llt().matrixL().solve( | ||
| Eigen::Matrix<Scalar, 9, 9>::Identity())} {} | ||
|
|
||
| template <typename Scalar> | ||
| sym::Factor<Scalar> ImuFactor<Scalar>::Factor(const std::vector<Key>& keys_to_func) const { | ||
| const auto begin = keys_to_func.begin(); | ||
| // NOTE(brad): *this is copied. Keys to optimize happen to be first 6 keys to func | ||
| return sym::Factor<Scalar>::Hessian(*this, keys_to_func, std::vector<Key>(begin, begin + 6)); | ||
| } | ||
|
|
||
| template <typename Scalar> | ||
| void ImuFactor<Scalar>::operator()( | ||
| const sym::Pose3<Scalar>& pose_i, const Eigen::Matrix<Scalar, 3, 1>& vel_i, | ||
| const sym::Pose3<Scalar>& pose_j, const Eigen::Matrix<Scalar, 3, 1>& vel_j, | ||
| const Eigen::Matrix<Scalar, 3, 1>& accel_bias_i, const Eigen::Matrix<Scalar, 3, 1>& gyro_bias_i, | ||
| const Eigen::Matrix<Scalar, 3, 1>& gravity, const Scalar epsilon, | ||
| Eigen::Matrix<Scalar, 9, 1>* const res, Eigen::Matrix<Scalar, 9, 24>* const jacobian, | ||
| Eigen::Matrix<Scalar, 24, 24>* const hessian, Eigen::Matrix<Scalar, 24, 1>* const rhs) const { | ||
| InternalImuFactor( | ||
| pose_i, vel_i, pose_j, vel_j, accel_bias_i, gyro_bias_i, preintegrated_measurements_.DR, | ||
| preintegrated_measurements_.Dv, preintegrated_measurements_.Dp, sqrt_info_, | ||
| preintegrated_measurements_.DR_D_gyro_bias, preintegrated_measurements_.Dv_D_accel_bias, | ||
| preintegrated_measurements_.Dv_D_gyro_bias, preintegrated_measurements_.Dp_D_accel_bias, | ||
| preintegrated_measurements_.Dp_D_gyro_bias, preintegrated_measurements_.accel_bias, | ||
| preintegrated_measurements_.gyro_bias, gravity, preintegrated_measurements_.integrated_dt, | ||
| epsilon, | ||
| // outputs | ||
| res, jacobian, hessian, rhs); | ||
| } | ||
|
|
||
| } // namespace sym | ||
|
|
||
| template class sym::ImuFactor<double>; | ||
| template class sym::ImuFactor<float>; |
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.