Skip to content

Commit cd66203

Browse files
[ImuFactor] Add an on manifold Imu Factor
Unit testing is left to a follow up commit. The core use-facing api is found in - symforce/slam/imu_preintegration/preintegrated_imu_measurements.h - symforce/slam/imu_preintegration/imu_factor.h Unlike most other factors (/residual functions) in symforce, the ImuFactor is a functor so as to store the pre-integrated values with the function rather than in the `Values`. (There are a lot of parameters that are constant and unique to each factor). A python version of the `ImuFactor` class will come in a subsequent commit. Topic: on_manifold_imu_factor
1 parent 474f1bd commit cd66203

15 files changed

Lines changed: 4003 additions & 0 deletions

CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,8 @@ if(SYMFORCE_BUILD_CC_SYM)
286286
add_subdirectory(symforce/pybind)
287287
endif()
288288

289+
add_subdirectory(symforce/slam)
290+
289291

290292
# ==============================================================================
291293
# Examples, Benchmarks, and Tests

gen/cpp/sym/factors/imu_manifold_preintegration_update.h

Lines changed: 842 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

gen/cpp/sym/factors/internal_imu_factor.h

Lines changed: 2372 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

gen/python/sym/factors/__init__.py

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

symforce/pybind/CMakeLists.txt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@
33
# This source code is under the Apache 2.0 license found in the LICENSE file.
44
# ----------------------------------------------------------------------------
55

6+
# ==============================================================================
7+
# Third Party Dependencies
8+
# ==============================================================================
9+
610
include(FetchContent)
711

812
find_package(pybind11 QUIET)
@@ -21,6 +25,13 @@ else()
2125
message(STATUS "pybind11 found")
2226
endif()
2327

28+
# ==============================================================================
29+
# SymForce Targets
30+
# ==============================================================================
31+
32+
# ------------------------------------------------------------------------------
33+
# cc_sym
34+
2435
pybind11_add_module(
2536
cc_sym
2637
SHARED

symforce/slam/CMakeLists.txt

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# ----------------------------------------------------------------------------
2+
# SymForce - Copyright 2022, Skydio, Inc.
3+
# This source code is under the Apache 2.0 license found in the LICENSE file.
4+
# ----------------------------------------------------------------------------
5+
6+
# ==============================================================================
7+
# SymForce Targets
8+
# ==============================================================================
9+
10+
file(GLOB_RECURSE SYMFORCE_SLAM_SOURCES CONFIGURE_DEPENDS *.cc **/*.cc)
11+
file(GLOB_RECURSE SYMFORCE_SLAM_HEADERS CONFIGURE_DEPENDS *.h **/*.h *.tcc **/*.tcc)
12+
13+
add_library(
14+
symforce_slam
15+
${SYMFORCE_LIBRARY_TYPE}
16+
${SYMFORCE_SLAM_SOURCES}
17+
${SYMFORCE_SLAM_HEADERS}
18+
)
19+
target_compile_options(symforce_slam PRIVATE ${SYMFORCE_COMPILE_OPTIONS})
20+
target_link_libraries(symforce_slam
21+
symforce_gen
22+
${SYMFORCE_EIGEN_TARGET}
23+
)

symforce/slam/__init__.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# ----------------------------------------------------------------------------
2+
# SymForce - Copyright 2022, Skydio, Inc.
3+
# This source code is under the Apache 2.0 license found in the LICENSE file.
4+
# ----------------------------------------------------------------------------
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# ----------------------------------------------------------------------------
2+
# SymForce - Copyright 2022, Skydio, Inc.
3+
# This source code is under the Apache 2.0 license found in the LICENSE file.
4+
# ----------------------------------------------------------------------------
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
# ----------------------------------------------------------------------------
2+
# SymForce - Copyright 2022, Skydio, Inc.
3+
# This source code is under the Apache 2.0 license found in the LICENSE file.
4+
# ----------------------------------------------------------------------------
5+
6+
from symforce import codegen
7+
from symforce import typing as T
8+
from symforce.slam.imu_preintegration.manifold_symbolic import imu_manifold_preintegration_update
9+
from symforce.slam.imu_preintegration.manifold_symbolic import internal_imu_residual
10+
11+
12+
def generate_manifold_imu_preintegration(
13+
config: codegen.CodegenConfig, output_dir: T.Openable
14+
) -> None:
15+
"""
16+
Generate the on-manifold IMU preintegration update and residual functions.
17+
"""
18+
codegen_update = codegen.Codegen.function(
19+
imu_manifold_preintegration_update,
20+
config=config,
21+
output_names=[
22+
"new_DR",
23+
"new_Dv",
24+
"new_Dp",
25+
"new_covariance",
26+
"new_DR_D_gyro_bias",
27+
"new_Dp_D_gyro_bias",
28+
"new_Dp_D_accel_bias",
29+
"new_Dv_D_gyro_bias",
30+
"new_Dv_D_accel_bias",
31+
],
32+
)
33+
codegen_update.generate_function(output_dir=output_dir, skip_directory_nesting=True)
34+
35+
codegen_residual = codegen.Codegen.function(
36+
internal_imu_residual,
37+
config=config,
38+
).with_linearization(
39+
which_args=[
40+
"pose_i",
41+
"vel_i",
42+
"pose_j",
43+
"vel_j",
44+
"accel_bias_i",
45+
"gyro_bias_i",
46+
]
47+
)
48+
codegen_residual.generate_function(output_dir=output_dir, skip_directory_nesting=True)
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/* ----------------------------------------------------------------------------
2+
* SymForce - Copyright 2022, Skydio, Inc.
3+
* This source code is under the Apache 2.0 license found in the LICENSE file.
4+
* ---------------------------------------------------------------------------- */
5+
6+
#include "./imu_factor.h"
7+
8+
#include <Eigen/Cholesky>
9+
10+
#include <sym/factors/internal_imu_factor.h>
11+
12+
#include "preintegrated_imu_measurements.h"
13+
14+
namespace sym {
15+
16+
template <typename Scalar>
17+
ImuFactor<Scalar>::ImuFactor(const PreintegratedImuMeasurements<Scalar>& preintegrated_measurements,
18+
const Eigen::Matrix<Scalar, 9, 9>& covariance)
19+
: preintegrated_measurements_{preintegrated_measurements},
20+
sqrt_info_{covariance.llt().matrixL().solve(Eigen::Matrix<Scalar, 9, 9>::Identity())} {}
21+
22+
template <typename Scalar>
23+
void ImuFactor<Scalar>::operator()(
24+
const sym::Pose3<Scalar>& pose_i, const Eigen::Matrix<Scalar, 3, 1>& vel_i,
25+
const sym::Pose3<Scalar>& pose_j, const Eigen::Matrix<Scalar, 3, 1>& vel_j,
26+
const Eigen::Matrix<Scalar, 3, 1>& accel_bias_i, const Eigen::Matrix<Scalar, 3, 1>& gyro_bias_i,
27+
const Eigen::Matrix<Scalar, 3, 1>& gravity, const Scalar epsilon,
28+
Eigen::Matrix<Scalar, 9, 1>* const res, Eigen::Matrix<Scalar, 9, 24>* const jacobian,
29+
Eigen::Matrix<Scalar, 24, 24>* const hessian, Eigen::Matrix<Scalar, 24, 1>* const rhs) const {
30+
InternalImuFactor(
31+
pose_i, vel_i, pose_j, vel_j, accel_bias_i, gyro_bias_i, preintegrated_measurements_.DR,
32+
preintegrated_measurements_.Dv, preintegrated_measurements_.Dp, sqrt_info_,
33+
preintegrated_measurements_.DR_D_gyro_bias, preintegrated_measurements_.Dp_D_accel_bias,
34+
preintegrated_measurements_.Dp_D_gyro_bias, preintegrated_measurements_.Dv_D_accel_bias,
35+
preintegrated_measurements_.Dv_D_gyro_bias, preintegrated_measurements_.accel_bias,
36+
preintegrated_measurements_.gyro_bias, gravity, preintegrated_measurements_.integrated_dt,
37+
epsilon,
38+
// outputs
39+
res, jacobian, hessian, rhs);
40+
}
41+
42+
} // namespace sym
43+
44+
template class sym::ImuFactor<double>;
45+
template class sym::ImuFactor<float>;

0 commit comments

Comments
 (0)