-
Notifications
You must be signed in to change notification settings - Fork 333
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Tiziano/fix rotation and voxel (#70)
* Treat optimized rotation as so3 rather than RPY * Manual merge from internal Gitlab dev branch --------- Co-authored-by: Matt Alvarado <[email protected]> Co-authored-by: tizianoGuadagnino <[email protected]>
- Loading branch information
1 parent
01c1c98
commit ba9fb90
Showing
21 changed files
with
284 additions
and
233 deletions.
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
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 |
---|---|---|
|
@@ -30,61 +30,44 @@ | |
#include <tuple> | ||
#include <vector> | ||
|
||
#include "Transforms.hpp" | ||
|
||
namespace { | ||
Eigen::Isometry3d MakeTransform(const Eigen::Vector3d &xyz, const Eigen::Vector3d &rpy) { | ||
Eigen::AngleAxisd omega(rpy.norm(), rpy.normalized()); | ||
Eigen::Isometry3d transform(omega); | ||
transform.translation() = xyz; | ||
return transform; | ||
using VelocityTuple = std::tuple<Eigen::Vector3d, Eigen::Vector3d>; | ||
VelocityTuple VelocityEstimation(const Eigen::Isometry3d &start_pose, | ||
const Eigen::Isometry3d &finish_pose, | ||
double scan_duration) { | ||
const auto delta_pose = kiss_icp::ConcatenateIsometries(start_pose.inverse(), finish_pose); | ||
const auto linear_velocity = delta_pose.translation() / scan_duration; | ||
const auto rotation = Eigen::AngleAxisd(delta_pose.rotation()); | ||
const auto angular_velocity = rotation.axis() * rotation.angle() / scan_duration; | ||
return std::make_tuple(linear_velocity, angular_velocity); | ||
} | ||
} // namespace | ||
|
||
namespace kiss_icp { | ||
using VelocityTuple = MotionCompensator::VelocityTuple; | ||
using Vector3dVector = std::vector<Eigen::Vector3d>; | ||
|
||
VelocityTuple MotionCompensator::VelocityEstimation(const Eigen::Matrix4d &start_pose, | ||
const Eigen::Matrix4d &finish_pose) { | ||
const Eigen::Matrix4d delta_pose = start_pose.inverse() * finish_pose; | ||
const Eigen::Vector3d linear_velocity = delta_pose.block<3, 1>(0, 3) / scan_duration_; | ||
const auto rotation = Eigen::AngleAxisd(delta_pose.block<3, 3>(0, 0)); | ||
const Eigen::Vector3d angular_velocity = rotation.axis() * rotation.angle() / scan_duration_; | ||
return std::make_tuple(linear_velocity, angular_velocity); | ||
} | ||
|
||
Vector3dVector MotionCompensator::DeSkewScan(const std::vector<Eigen::Vector3d> &frame, | ||
const std::vector<double> ×tamps, | ||
const Eigen::Vector3d &linear_velocity, | ||
const Eigen::Vector3d &angular_velocity) { | ||
std::vector<Eigen::Vector3d> corrected_frame(frame.size()); | ||
tbb::parallel_for(size_t(0), frame.size(), [&](size_t i) { | ||
const auto &dt = timestamps[i]; | ||
const auto motion = MakeTransform(dt * linear_velocity, dt * angular_velocity); | ||
corrected_frame[i] = motion * frame[i]; | ||
}); | ||
return corrected_frame; | ||
} | ||
|
||
using Vector3dVector = std::vector<Eigen::Vector3d>; | ||
Vector3dVector MotionCompensator::DeSkewScan(const std::vector<Eigen::Vector3d> &frame, | ||
const std::vector<double> ×tamps, | ||
const std::vector<Eigen::Matrix4d> &poses) { | ||
// If not enough poses for the estimation, do not de-skew | ||
const size_t N = poses.size(); | ||
if (N <= 2) return frame; | ||
|
||
const Eigen::Isometry3d &start_pose, | ||
const Eigen::Isometry3d &finish_pose) { | ||
// Estimate linear and angular velocities | ||
const auto &start_pose = poses[N - 2]; | ||
const auto &finish_pose = poses[N - 1]; | ||
const auto [lvel, avel] = VelocityEstimation(start_pose, finish_pose); | ||
const auto [lvel, avel] = VelocityEstimation(start_pose, finish_pose, scan_duration_); | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
nachovizzo
Author
Collaborator
|
||
|
||
// TODO(Nacho) Add explanation of this | ||
std::vector<double> timestamps_ = timestamps; | ||
std::for_each(timestamps_.begin(), timestamps_.end(), [&](double ×tamp) { | ||
timestamp = scan_duration_ * (timestamp - mid_pose_timestamp_); | ||
}); | ||
|
||
// Compensate using the estimated velocities | ||
return MotionCompensator::DeSkewScan(frame, timestamps_, lvel, avel); | ||
std::vector<Eigen::Vector3d> corrected_frame(frame.size()); | ||
tbb::parallel_for(size_t(0), frame.size(), [&](size_t i) { | ||
const auto &dt = timestamps_[i]; | ||
const auto motion = MakeTransform(dt * lvel, dt * avel); | ||
corrected_frame[i] = motion * frame[i]; | ||
}); | ||
return corrected_frame; | ||
} | ||
|
||
} // namespace kiss_icp |
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
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
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
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 |
---|---|---|
@@ -0,0 +1,64 @@ | ||
// MIT License | ||
// | ||
// Copyright (c) 2022 Ignacio Vizzo, Tiziano Guadagnino, Benedikt Mersch, Cyrill | ||
// Stachniss. | ||
// | ||
// Permission is hereby granted, free of charge, to any person obtaining a copy | ||
// of this software and associated documentation files (the "Software"), to deal | ||
// in the Software without restriction, including without limitation the rights | ||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
// copies of the Software, and to permit persons to whom the Software is | ||
// furnished to do so, subject to the following conditions: | ||
// | ||
// The above copyright notice and this permission notice shall be included in all | ||
// copies or substantial portions of the Software. | ||
// | ||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
// SOFTWARE. | ||
#pragma once | ||
|
||
#include <Eigen/Core> | ||
#include <Eigen/Geometry> | ||
#include <algorithm> | ||
#include <vector> | ||
|
||
namespace Eigen { | ||
using Vector6d = Eigen::Matrix<double, 6, 1>; | ||
} // namespace Eigen | ||
|
||
namespace kiss_icp { | ||
|
||
inline Eigen::Isometry3d MakeTransform(const Eigen::Vector3d &xyz, const Eigen::Vector3d &theta) { | ||
const double angle = theta.norm(); | ||
const Eigen::Vector3d axis = theta.normalized(); | ||
Eigen::AngleAxisd omega(angle, axis); | ||
Eigen::Isometry3d transform = Eigen::Isometry3d::Identity(); | ||
transform.linear() = omega.toRotationMatrix(); | ||
transform.translation() = xyz; | ||
return transform; | ||
} | ||
|
||
inline Eigen::Isometry3d Vector6dToIsometry3d(const Eigen::Vector6d &x) { | ||
const Eigen::Vector3d &xyz = x.tail<3>(); | ||
const Eigen::Vector3d &theta = x.head<3>(); | ||
return MakeTransform(xyz, theta); | ||
} | ||
|
||
inline void TransformPoints(const Eigen::Isometry3d &T, std::vector<Eigen::Vector3d> &points) { | ||
std::transform(points.cbegin(), points.cend(), points.begin(), | ||
[&](const auto &point) { return T * point; }); | ||
} | ||
|
||
inline Eigen::Isometry3d ConcatenateIsometries(const Eigen::Isometry3d &lhs, | ||
const Eigen::Isometry3d &rhs) { | ||
Eigen::Isometry3d returned = Eigen::Isometry3d::Identity(); | ||
returned.linear() = lhs.rotation() * rhs.rotation(); | ||
returned.translation() = lhs.rotation() * rhs.translation() + lhs.translation(); | ||
return returned; | ||
} | ||
} // namespace kiss_icp |
Oops, something went wrong.
Since
lvel
andavel
are going by reference capture to lambda I guess we need to do a similar trick as done inVoxelHashMap.cpp:136
:because it seems doesn't compiles on CLang because of the bug "in C++ standard"? (oh :) https://stackoverflow.com/questions/46114214/lambda-implicit-capture-fails-with-variable-declared-from-structured-binding