Skip to content

Commit b1b5e6f

Browse files
authored
Add separate de-skewing (#32)
* Add separate deskewing * Fix deskewing * Add copy and update dependency * Move into odometry * Use cache@v4 * Test this * Cosmetics * Remove again * Clean up * Move back here * Just use the default
1 parent 212233d commit b1b5e6f

File tree

10 files changed

+133
-14
lines changed

10 files changed

+133
-14
lines changed

.github/workflows/cpp.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ jobs:
4242
steps:
4343
- uses: actions/checkout@v3
4444
- name: Cache dependencies
45-
uses: actions/cache@v2
45+
uses: actions/cache@v4
4646
with:
4747
path: ~/.apt/cache
4848
key: ${{ runner.os }}-apt-${{ hashFiles('**/ubuntu_dependencies.yml') }}

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ authors = [
88
]
99
license_files = "LICENSE"
1010
dependencies = [
11-
"kiss-icp<=1.1.0",
11+
"kiss-icp>=1.2.0",
1212
"diskcache>=5.3.0",
1313
"pytorch_lightning>=1.6.4",
1414
]

src/mapmos/mapping.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ def remove_voxels_far_from_location(self, location: np.ndarray):
5959
self._internal_map._remove_far_away_points(location)
6060

6161
def update_belief(self, points: np.ndarray, logits: np.ndarray):
62-
self._internal_map._update_belief(mapmos_pybind._Vector3dVector(points), logits)
62+
self._internal_map._update_belief(mapmos_pybind._Vector3dVector(points), logits.ravel())
6363

6464
def get_belief(self, points: np.ndarray):
6565
belief = self._internal_map._get_belief(mapmos_pybind._Vector3dVector(points))

src/mapmos/odometry.py

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,13 @@
2020
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
2121
# SOFTWARE.
2222

23-
from typing import Type
24-
2523
import numpy as np
2624
from kiss_icp.config import KISSConfig
2725
from kiss_icp.kiss_icp import KissICP, get_registration
2826

2927
from mapmos.config import DataConfig, OdometryConfig
3028
from mapmos.mapping import VoxelHashMap
29+
from mapmos.pybind import mapmos_pybind
3130
from mapmos.registration import get_registration
3231

3332

@@ -61,10 +60,7 @@ def __init__(
6160

6261
def register_points(self, points, timestamps, scan_index):
6362
# Apply motion compensation
64-
points = self.compensator.deskew_scan(points, timestamps, self.last_delta)
65-
66-
# Preprocess the input cloud
67-
points_prep = self.preprocess(points)
63+
points_prep = self.preprocessor.preprocess(points, timestamps, self.last_delta)
6864

6965
# Voxelize
7066
source, points_downsample = self.voxelize(points_prep)
@@ -83,6 +79,8 @@ def register_points(self, points, timestamps, scan_index):
8379
kernel=sigma / 3,
8480
)
8581

82+
point_deskewed = self.deskew(points, timestamps, self.last_delta)
83+
8684
# Compute the difference between the prediction and the actual estimate
8785
model_deviation = np.linalg.inv(initial_guess) @ new_pose
8886

@@ -92,17 +90,29 @@ def register_points(self, points, timestamps, scan_index):
9290
self.last_delta = np.linalg.inv(self.last_pose) @ new_pose
9391
self.last_pose = new_pose
9492

95-
points_reg = self.transform(points, self.last_pose)
96-
return np.asarray(points_reg)
93+
return self.transform(point_deskewed, self.last_pose)
9794

9895
def get_map_points(self):
9996
map_points, map_timestamps = self.local_map.point_cloud_with_timestamps()
10097
return map_points.reshape(-1, 3), map_timestamps.reshape(-1, 1)
10198

99+
def current_location(self):
100+
return self.last_pose[:3, 3]
101+
102102
def transform(self, points, pose):
103103
points_hom = np.hstack((points, np.ones((len(points), 1))))
104104
points = (pose @ points_hom.T).T[:, :3]
105105
return points
106106

107-
def current_location(self):
108-
return self.last_pose[:3, 3]
107+
def deskew(self, points, timestamps, relative_motion):
108+
return (
109+
np.asarray(
110+
mapmos_pybind._deskew(
111+
frame=mapmos_pybind._Vector3dVector(points),
112+
timestamps=timestamps,
113+
relative_motion=relative_motion,
114+
)
115+
)
116+
if self.config.data.deskew
117+
else points
118+
)

src/mapmos/paper_pipeline.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ def _run_pipeline(self):
7272
for scan_index in pbar:
7373
local_scan, timestamps, gt_labels = self._next(scan_index)
7474
map_points, map_indices = self.odometry.get_map_points()
75+
7576
scan_points = self.odometry.register_points(local_scan, timestamps, scan_index)
7677
self.poses[scan_index - self._first] = self.odometry.last_pose
7778

src/mapmos/pipeline.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ def _run_pipeline(self):
126126
for scan_index in pbar:
127127
local_scan, timestamps, gt_labels = self._next(scan_index)
128128
map_points, map_indices = self.odometry.get_map_points()
129+
129130
scan_points = self.odometry.register_points(local_scan, timestamps, scan_index)
130131
self.poses[scan_index - self._first] = self.odometry.last_pose
131132

src/mapmos/pybind/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ find_package(Python COMPONENTS Interpreter Development.Module REQUIRED)
4141
find_package(pybind11 CONFIG REQUIRED)
4242

4343
# Python bindings
44-
pybind11_add_module(mapmos_pybind MODULE mapmos_pybind.cpp VoxelHashMap.cpp Registration.cpp)
44+
pybind11_add_module(mapmos_pybind MODULE mapmos_pybind.cpp VoxelHashMap.cpp Registration.cpp Deskew.cpp)
4545
target_compile_features(mapmos_pybind PRIVATE cxx_std_17)
4646
target_link_libraries(mapmos_pybind PUBLIC Eigen3::Eigen tsl::robin_map TBB::tbb Sophus::Sophus)
4747
install(TARGETS mapmos_pybind LIBRARY DESTINATION .)

src/mapmos/pybind/Deskew.cpp

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
// MIT License
2+
//
3+
// Copyright (c) 2022 Ignacio Vizzo, Tiziano Guadagnino, Benedikt Mersch, Cyrill
4+
// Stachniss.
5+
//
6+
// Permission is hereby granted, free of charge, to any person obtaining a copy
7+
// of this software and associated documentation files (the "Software"), to deal
8+
// in the Software without restriction, including without limitation the rights
9+
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
// copies of the Software, and to permit persons to whom the Software is
11+
// furnished to do so, subject to the following conditions:
12+
//
13+
// The above copyright notice and this permission notice shall be included in all
14+
// copies or substantial portions of the Software.
15+
//
16+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+
// SOFTWARE.
23+
#include "Deskew.hpp"
24+
25+
#include <tbb/blocked_range.h>
26+
#include <tbb/parallel_for.h>
27+
28+
#include <Eigen/Core>
29+
#include <Eigen/Geometry>
30+
#include <algorithm>
31+
#include <functional>
32+
#include <vector>
33+
34+
namespace mapmos {
35+
36+
std::vector<Eigen::Vector3d> Deskew(const std::vector<Eigen::Vector3d> &frame,
37+
const std::vector<double> &timestamps,
38+
const Sophus::SE3d &relative_motion) {
39+
const std::vector<Eigen::Vector3d> &deskewed_frame = [&]() {
40+
const auto &omega = relative_motion.log();
41+
const Sophus::SE3d &inverse_motion = relative_motion.inverse();
42+
std::vector<Eigen::Vector3d> deskewed_frame(frame.size());
43+
tbb::parallel_for(
44+
// Index Range
45+
tbb::blocked_range<size_t>{0, deskewed_frame.size()},
46+
// Parallel Compute
47+
[&](const tbb::blocked_range<size_t> &r) {
48+
for (size_t idx = r.begin(); idx < r.end(); ++idx) {
49+
const auto &point = frame.at(idx);
50+
const auto &stamp = timestamps.at(idx);
51+
const auto pose = inverse_motion * Sophus::SE3d::exp(stamp * omega);
52+
deskewed_frame.at(idx) = pose * point;
53+
};
54+
});
55+
return deskewed_frame;
56+
}();
57+
return deskewed_frame;
58+
}
59+
60+
} // namespace mapmos

src/mapmos/pybind/Deskew.hpp

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
// MIT License
2+
//
3+
// Copyright (c) 2022 Ignacio Vizzo, Tiziano Guadagnino, Benedikt Mersch, Cyrill
4+
// Stachniss.
5+
//
6+
// Permission is hereby granted, free of charge, to any person obtaining a copy
7+
// of this software and associated documentation files (the "Software"), to deal
8+
// in the Software without restriction, including without limitation the rights
9+
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
// copies of the Software, and to permit persons to whom the Software is
11+
// furnished to do so, subject to the following conditions:
12+
//
13+
// The above copyright notice and this permission notice shall be included in all
14+
// copies or substantial portions of the Software.
15+
//
16+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+
// SOFTWARE.
23+
#pragma once
24+
#include <tbb/global_control.h>
25+
#include <tbb/task_arena.h>
26+
27+
#include <Eigen/Core>
28+
#include <sophus/se3.hpp>
29+
#include <vector>
30+
31+
namespace mapmos {
32+
33+
std::vector<Eigen::Vector3d> Deskew(const std::vector<Eigen::Vector3d> &frame,
34+
const std::vector<double> &timestamps,
35+
const Sophus::SE3d &relative_motion);
36+
37+
} // namespace mapmos

src/mapmos/pybind/mapmos_pybind.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
#include <memory>
3131
#include <vector>
3232

33+
#include "Deskew.hpp"
3334
#include "Registration.hpp"
3435
#include "VoxelHashMap.hpp"
3536
#include "stl_vector_eigen.h"
@@ -45,6 +46,15 @@ PYBIND11_MODULE(mapmos_pybind, m) {
4546
m, "_Vector3dVector", "std::vector<Eigen::Vector3d>",
4647
py::py_array_to_vectors_double<Eigen::Vector3d>);
4748

49+
m.def(
50+
"_deskew",
51+
[](const std::vector<Eigen::Vector3d> &points, const std::vector<double> &timestamps,
52+
const Eigen::Matrix4d &relative_motion) {
53+
Sophus::SE3d motion(relative_motion);
54+
return Deskew(points, timestamps, motion);
55+
},
56+
"frame"_a, "timestamps"_a, "relative_motion"_a);
57+
4858
// Map representation
4959
py::class_<VoxelHashMap> internal_map(m, "_VoxelHashMap", "Don't use this");
5060
internal_map

0 commit comments

Comments
 (0)