-
Notifications
You must be signed in to change notification settings - Fork 675
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
feat(interpolation): add functions for flexible usage (non-static spline interpolation) #352
Changes from 2 commits
28504f8
c86840c
75d9b3b
f73fe11
e7a88bc
0f42e6d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,6 +15,9 @@ | |
#ifndef INTERPOLATION__SPLINE_INTERPOLATION_HPP_ | ||
#define INTERPOLATION__SPLINE_INTERPOLATION_HPP_ | ||
|
||
#include "interpolation/interpolation_utils.hpp" | ||
#include "tier4_autoware_utils/geometry/geometry.hpp" | ||
|
||
#include <algorithm> | ||
#include <cmath> | ||
#include <iostream> | ||
|
@@ -26,6 +29,8 @@ namespace interpolation | |
// NOTE: X(s) = a_i (s - s_i)^3 + b_i (s - s_i)^2 + c_i (s - s_i) + d_i : (i = 0, 1, ... N-1) | ||
struct MultiSplineCoef | ||
{ | ||
MultiSplineCoef() = default; | ||
|
||
explicit MultiSplineCoef(const size_t num_spline) | ||
{ | ||
a.resize(num_spline); | ||
|
@@ -40,9 +45,81 @@ struct MultiSplineCoef | |
std::vector<double> d; | ||
}; | ||
|
||
// static spline interpolation functions | ||
std::vector<double> slerp( | ||
const std::vector<double> & base_keys, const std::vector<double> & base_values, | ||
const std::vector<double> & query_keys); | ||
|
||
// std::vector<double> slerpDiff( | ||
// const std::vector<double> & base_keys, const std::vector<double> & base_values, | ||
// const std::vector<double> & query_keys); | ||
|
||
// TODO(murooka) use template | ||
// template <typename T> | ||
// std::vector<double> slerpYawFromPoints(const std::vector<T> & points); | ||
std::vector<double> slerpYawFromPoints(const std::vector<geometry_msgs::msg::Point> & points); | ||
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. (@rej55 Let's discuss in a thread) Thank you. It's a good point. For static spline interpolation (this function For non-static spline interpolation, I implemented SplineInterpolation1d and SplineInterpolationPoint2d classes. 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. I feel it is a little weird having It is better to create |
||
} // namespace interpolation | ||
|
||
// non-static 1-dimensional spline interpolation | ||
// | ||
// Usage: | ||
// ``` | ||
// SplineInterpolation1d spline; | ||
// spline.calcSplineCoefficients(base_keys, base_values); // memorize pre-interpolation result | ||
// internally const auto interpolation_result1 = spline.getSplineInterpolatedValues(base_keys, | ||
// query_keys1); const auto interpolation_result2 = spline.getSplineInterpolatedValues(base_keys, | ||
// query_keys2); | ||
// ``` | ||
class SplineInterpolation1d | ||
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. 1-dimensional spline interpolation |
||
{ | ||
public: | ||
SplineInterpolation1d() = default; | ||
|
||
void calcSplineCoefficients( | ||
const std::vector<double> & base_keys, const std::vector<double> & base_values); | ||
|
||
std::vector<double> getSplineInterpolatedValues( | ||
const std::vector<double> & base_keys, const std::vector<double> & query_keys) const; | ||
|
||
private: | ||
interpolation::MultiSplineCoef multi_spline_coef_; | ||
}; | ||
|
||
// non-static points spline interpolation | ||
// NOTE: We can calculate yaw from the x and y by interpolation derivatives. | ||
// | ||
// Usage: | ||
// ``` | ||
// SplineInterpolationPoint spline; | ||
// spline.calcSplineCoefficients(base_keys, base_values); // memorize pre-interpolation result | ||
// internally const auto interpolation_result1 = spline.getSplineInterpolatedPoint(base_keys, | ||
// query_keys1); const auto interpolation_result2 = spline.getSplineInterpolatedPoint(base_keys, | ||
// query_keys2); const auto yaw_interpolation_result = spline.getSplineInterpolatedValues(base_keys, | ||
// query_keys1); | ||
// ``` | ||
class SplineInterpolationPoint | ||
{ | ||
public: | ||
SplineInterpolationPoint() = default; | ||
|
||
// TODO(murooka) use template | ||
// template <typename T> | ||
// void calcSplineCoefficients(const std::vector<T> & points); | ||
void calcSplineCoefficients(const std::vector<geometry_msgs::msg::Point> & points); | ||
|
||
// TODO(murooka) implement these functions | ||
// std::vector<geometry_msgs::msg::Point> getSplineInterpolatedPoints(const double width); | ||
// std::vector<geometry_msgs::msg::Pose> getSplineInterpolatedPoses(const double width); | ||
|
||
geometry_msgs::msg::Point getSplineInterpolatedPoint(const size_t idx, const double s) const; | ||
double getSplineInterpolatedYaw(const size_t idx, const double s) const; | ||
|
||
double getAccumulatedDistance(const size_t idx) const; | ||
|
||
private: | ||
interpolation::MultiSplineCoef multi_spline_coef_x_; | ||
interpolation::MultiSplineCoef multi_spline_coef_y_; | ||
std::vector<double> base_s_vec_; | ||
}; | ||
|
||
#endif // INTERPOLATION__SPLINE_INTERPOLATION_HPP_ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
refactor: validateInput -> validateKeys and validateKeysAndValues