Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 3 additions & 6 deletions .github/release-please-config.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,12 @@
"path": "vcpkg.json",
"jsonpath": "$.version"
},
"python/bindings.cpp",
"ros/pixi.toml",
"ros/CMakeLists.txt",
{
"path": "ros/package.xml",
"type": "xml",
"xpath": "//package/version"
}
"ros/package.xml"
]
}
},
"$schema": "https://raw.githubusercontent.com/googleapis/release-please/main/schemas/config.json"
}
}
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ log
.vscode
.envrc
.clangd

.kiro
.helix

*.bbl
Expand Down
4 changes: 2 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ include(FetchContent)
FetchContent_Declare(
tsl
GIT_REPOSITORY https://github.com/Tessil/robin-map.git
GIT_TAG v1.4.0
FIND_PACKAGE_ARGS CONFIG
GIT_TAG v1.4.1
FIND_PACKAGE_ARGS CONFIG
)
FetchContent_MakeAvailable(tsl)

Expand Down
29 changes: 18 additions & 11 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,28 +1,27 @@
[project]
name = "form"
version = "0.1.1"
description = "Add your description here"
description = "FORM LiDAR Odometry"
readme = "README.md"
authors = [{ name = "Easton Potokar", email = "contagon6@gmail.com" }]
requires-python = ">=3.11"
dependencies = [
"evalio>=0.4",
"gradio-rerun>=0.24.0",
"ipython>=9.5.0",
"polars>=1.30.0",
dependencies = ["evalio>=0.5", "polars>=1.30.0"]

[dependency-groups]
dev = ["cmake>=4.3", "snakeviz>=2.2.2", "ipython>=9.5.0"]
vis = [
"pyvista>=0.46.3",
"rerun-sdk>=0.23",
"seaborn>=0.13.2",
"gradio-rerun>=0.24.0",
"rerun-sdk>=0.31",
]

[dependency-groups]
dev = ["snakeviz>=2.2.2"]

[build-system]
requires = ["scikit-build-core>=0.10", "nanobind", "evalio>=0.4"]
requires = ["scikit-build-core>=0.12", "nanobind>=2.12", "evalio>=0.5"]
build-backend = "scikit_build_core.build"

[tool.scikit-build]
cmake.version = ">=4.3"
minimum-version = "build-system.requires"
build-dir = "build/{wheel_tag}"

Expand All @@ -34,3 +33,11 @@ VCPKG_INSTALLED_DIR = "./.vcpkg_installed"
[tool.basedpyright]
typeCheckingMode = "standard"
include = ["python"]

[tool.uv]
cache-keys = [
{ file = "pyproject.toml" },
{ file = "form/**/*.{h,c,hpp,cpp}" },
{ file = "python/**/*.{cpp,py,txt}" },
{ file = "CMakeLists.txt" },
]
12 changes: 5 additions & 7 deletions python/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,24 +11,22 @@ find_package(
FetchContent_Declare(
nanobind
GIT_REPOSITORY https://github.com/wjakob/nanobind
GIT_TAG v2.7.0
# FIND_PACKAGE_ARGS CONFIG
GIT_TAG v2.12.0
FIND_PACKAGE_ARGS CONFIG
)
FetchContent_MakeAvailable(nanobind)

FetchContent_Declare(
evalio
GIT_REPOSITORY https://github.com/contagon/evalio.git
GIT_TAG "failed-runs"
# FIND_PACKAGE_ARGS
GIT_TAG "v0.5.0"
FIND_PACKAGE_ARGS
)
FetchContent_MakeAvailable(evalio)
# find_package(evalio REQUIRED)


set_property(TARGET FORM PROPERTY POSITION_INDEPENDENT_CODE ON)

nanobind_add_module(_core MODULE bindings.cpp)
nanobind_add_module(_core STABLE_ABI MODULE bindings.cpp)
target_link_libraries(_core PRIVATE evalio FORM)
install(TARGETS _core DESTINATION form)

Expand Down
164 changes: 63 additions & 101 deletions python/bindings.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#include "evalio/convert/base.h"
#include "evalio/convert/gtsam.h"
#include "evalio/pipeline.h"
#include "evalio/types.h"

Expand All @@ -14,51 +16,56 @@
#include <nanobind/stl/tuple.h>
#include <nanobind/stl/variant.h>
#include <nanobind/stl/vector.h>
#include <utility>

namespace nb = nanobind;
namespace ev = evalio;

// ------------------------- Helpers ------------------------- //
gtsam::Pose3 pose_to_gtsam(const evalio::SE3 &pose) {
return gtsam::Pose3(gtsam::Rot3(pose.rot.toEigen()), gtsam::Point3(pose.trans));
}
namespace evalio {

evalio::SE3 pose_to_evalio(const gtsam::Pose3 &pose) {
return evalio::SE3(evalio::SO3::fromEigen(pose.rotation().toQuaternion()),
pose.translation());
template <> inline Point convert(const form::PointFeat &in) {
return {
.x = in.x,
.y = in.y,
.z = in.z,
.intensity = 0.0,
.t = Duration::from_sec(0),
.row = 0,
.col = static_cast<uint16_t>(in.scan),
};
}

template <typename Point> evalio::Point point_to_evalio(const Point &point) {
template <> inline Point convert(const form::PlanarFeat &in) {
return {
.x = point.x,
.y = point.y,
.z = point.z,
.x = in.x,
.y = in.y,
.z = in.z,
.intensity = 0.0,
.t = evalio::Duration::from_sec(0),
.t = Duration::from_sec(0),
.row = 0,
.col = static_cast<uint16_t>(point.scan),
.col = static_cast<uint16_t>(in.scan),
};
}

form::PointXYZf point_to_form(const evalio::Point &point) {
return form::PointXYZf(point.x, point.y, point.z);
template <> inline form::PointXYZf convert(const Point &in) {
return {
static_cast<float>(in.x),
static_cast<float>(in.y),
static_cast<float>(in.z),
};
}

} // namespace evalio

// ------------------------- Pipeline ------------------------- //
class FORM : public evalio::Pipeline {
class FORMDev : public ev::Pipeline {
public:
FORM() : evalio::Pipeline(), params_(), estimator_() {}

form::Estimator estimator_;
form::Estimator::Params params_;
FORMDev() : estimator_(), params_() {}

// helper params
gtsam::Pose3 lidar_T_imu_ = gtsam::Pose3::Identity();
evalio::Duration delta_time_;
evalio::SE3 current_pose = evalio::SE3::identity();
// Info
static std::string version() { return "0.1.1-dev"; } // x-release-please-version

// ------------------------- Info ------------------------- //
static std::string name() { return "form"; }
static std::string name() { return "form-dev"; }

static std::string url() { return "https://github.com/rpl-cmu/form"; }

Expand Down Expand Up @@ -88,95 +95,50 @@ class FORM : public evalio::Pipeline {
);
// clang-format on

// ------------------------- Getters ------------------------- //
// Returns the most recent pose estimate
const evalio::SE3 pose() override { return current_pose; }

// Returns the current submap of the environment
const std::map<std::string, std::vector<evalio::Point>> map() override {
const auto world_map =
form::tuple::transform(estimator_.m_keypoint_map, [&](auto &map) {
return map.to_voxel_map(estimator_.m_constraints.get_values(),
estimator_.m_params.map.min_dist_map);
});

std::tuple<std::string, std::string> map_names = {"planar", "point"};
std::map<std::string, std::vector<evalio::Point>> points;

form::tuple::for_seq(std::make_index_sequence<2>{}, [&](auto I) {
const auto name = std::get<I>(map_names);
points.insert({name, {}});
auto &vec = points[name];

for (const auto &[_, voxel] : std::get<I>(world_map)) {
for (const auto &point : voxel) {
vec.push_back(point_to_evalio(point));
}
}
});

return points;
// Getters
const std::map<std::string, std::vector<ev::Point>> map() override {
const auto planar = std::get<0>(estimator_.m_keypoint_map)
.to_vector(estimator_.m_constraints.get_values());
const auto point = std::get<1>(estimator_.m_keypoint_map)
.to_vector(estimator_.m_constraints.get_values());

return ev::make_map("planar", planar, "point", point);
}

// ------------------------- Setters ------------------------- //
// Set the IMU parameters
void set_imu_params(evalio::ImuParams params) override {}
// Setters
void set_imu_params(ev::ImuParams params) override {}

// Set the LiDAR parameters
void set_lidar_params(evalio::LidarParams params) override {
void set_lidar_params(ev::LidarParams params) override {
params_.extraction.min_norm_squared = params.min_range * params.min_range;
params_.extraction.max_norm_squared = params.max_range * params.max_range;
params_.extraction.num_columns = params.num_columns;
params_.extraction.num_rows = params.num_rows;
delta_time_ = params.delta_time();
}

// Set the transformation from IMU to LiDAR
void set_imu_T_lidar(evalio::SE3 T) override {
lidar_T_imu_ = pose_to_gtsam(T).inverse();
void set_imu_T_lidar(ev::SE3 T) override {
lidar_T_imu_ = ev::convert<gtsam::Pose3>(T).inverse();
}

// ------------------------- Doers ------------------------- //
// Initialize the pipeline
// Doers
void initialize() override { estimator_ = form::Estimator(params_); }

// Add an IMU measurement
void add_imu(evalio::ImuMeasurement mm) override {}

// Add a LiDAR measurement
std::map<std::string, std::vector<evalio::Point>>
add_lidar(evalio::LidarMeasurement mm) override {
// convert to evalio
std::vector<form::PointXYZf> scan;
auto start = mm.stamp;
auto end = mm.stamp + delta_time_;
void add_imu(ev::ImuMeasurement mm) override {}

for (const auto &point : mm.points) {
scan.push_back(point_to_form(point));
}
void add_lidar(ev::LidarMeasurement mm) override {
const auto scan = ev::convert_iter<std::vector<form::PointXYZf>>(mm.points);

// run the estimator
auto [planar_kp, point_kp] = estimator_.register_scan(scan);
current_pose =
pose_to_evalio(estimator_.current_lidar_estimate() * lidar_T_imu_);

// extract the keypoints
std::map<std::string, std::vector<evalio::Point>> points = {{"planar", {}},
{"point", {}}};
auto &all_planar = points["planar"];
auto &all_point = points["point"];
for (const auto &point : planar_kp) {
const auto ev_point = point_to_evalio(point);
all_planar.push_back(ev_point);
}

for (const auto &point : point_kp) {
const auto ev_point = point_to_evalio(point);
all_point.push_back(ev_point);
}

return points;
this->save(mm.stamp, estimator_.current_lidar_estimate() * lidar_T_imu_);
this->save(mm.stamp, "planar", planar_kp, "point", point_kp);
}

private:
form::Estimator estimator_;
form::Estimator::Params params_;

gtsam::Pose3 lidar_T_imu_ = gtsam::Pose3::Identity();
ev::SE3 current_pose_ = ev::SE3::identity();
};

NB_MODULE(_core, m) {
Expand All @@ -186,11 +148,11 @@ NB_MODULE(_core, m) {

// Only have to override the static methods here
// All the others will be automatically inherited from the base class
nb::class_<FORM, evalio::Pipeline>(m, "FORM")
nb::class_<FORMDev, evalio::Pipeline>(m, "FORMDev")
.def(nb::init<>())
.def_static("name", &FORM::name)
.def_static("url", &FORM::url)
.def_static("default_params", &FORM::default_params);
.def_static("name", &FORMDev::name)
.def_static("url", &FORMDev::url)
.def_static("default_params", &FORMDev::default_params);

// Expose extraction methods too
nb::class_<form::FeatureExtractor::Params>(m, "KeypointExtractionParams")
Expand Down
2 changes: 1 addition & 1 deletion ros/package.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0"?>
<package format="3">
<name>form</name>
<version>0.1.0</version>
<version>0.1.1</version><!-- x-release-please-version -->
<description>FORM: Fixed-lag Odometry with Reparative Mapping - ROS 2 Wrapper</description>
<maintainer email="potokar@cmu.edu">Easton Potokar</maintainer>
<license>MIT</license>
Expand Down
Loading
Loading