From d26d8282f0124694ee7ced0a22f8f60e5a87651d Mon Sep 17 00:00:00 2001 From: Jupp Tscheak <jupp.tscheak@daimler.com> Date: Mon, 9 Aug 2021 14:55:14 +0200 Subject: [PATCH] Class "SplineSection" can only be used with unit types. Revised the control strategies that are spline based accordingly. Signed-off-by: Jupp Tscheak <jupp.tscheak@daimler.com> --- MantleAPI/include/MantleAPI/Common/spline.h | 8 +++++--- MantleAPI/include/MantleAPI/Traffic/control_strategy.h | 8 ++++---- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/MantleAPI/include/MantleAPI/Common/spline.h b/MantleAPI/include/MantleAPI/Common/spline.h index 352afa20..7e6f5d70 100644 --- a/MantleAPI/include/MantleAPI/Common/spline.h +++ b/MantleAPI/include/MantleAPI/Common/spline.h @@ -35,6 +35,7 @@ struct SplineSegment Vec3<T> d; }; +template <typename T, class = typename std::enable_if_t<units::traits::is_unit_t<T>::value>> struct SplineSection { Time start_time{0}; @@ -45,17 +46,18 @@ struct SplineSection /// \f[ /// P(x) = \sum_{i=0}^{3} a_{i} x^{i} = a_3 x^3 + a_2 x^2 + a_1 x + a_0 /// \f] - std::array<double, 4> polynomial{0, 0, 0, 0}; + std::array<T, 4> polynomial{0, 0, 0, 0}; }; /// @brief Equality comparison for SplineSection. -inline bool operator==(const SplineSection& lhs, const SplineSection& rhs) noexcept +template <typename T, class = typename std::enable_if_t<units::traits::is_unit_t<T>::value>> +inline bool operator==(const SplineSection<T>& lhs, const SplineSection<T>& rhs) noexcept { return lhs.start_time == rhs.start_time && lhs.end_time == rhs.end_time && std::equal(lhs.polynomial.begin(), lhs.polynomial.end(), rhs.polynomial.begin(), - [](const double a, const double b) { return IsEqual(a, b); }); + [](const T& a, const T& b) { return IsEqual(a, b); }); } } // namespace mantle_api diff --git a/MantleAPI/include/MantleAPI/Traffic/control_strategy.h b/MantleAPI/include/MantleAPI/Traffic/control_strategy.h index fd41f113..a231dcbf 100644 --- a/MantleAPI/include/MantleAPI/Traffic/control_strategy.h +++ b/MantleAPI/include/MantleAPI/Traffic/control_strategy.h @@ -91,7 +91,7 @@ struct FollowHeadingSplineControlStrategy : public ControlStrategy type = ControlStrategyType::kFollowHeadingSpline; } - std::vector<mantle_api::SplineSection> heading_splines; + std::vector<mantle_api::SplineSection<units::angle::radian_t>> heading_splines; double default_value{0}; }; @@ -103,7 +103,7 @@ struct FollowVelocitySplineControlStrategy : public ControlStrategy type = ControlStrategyType::kFollowVelocitySpline; } - std::vector<mantle_api::SplineSection> velocity_splines; + std::vector<mantle_api::SplineSection<units::velocity::meters_per_second_t>> velocity_splines; double default_value{0}; }; @@ -127,7 +127,7 @@ struct FollowLateralOffsetSplineControlStrategy : public ControlStrategy type = ControlStrategyType::kFollowLateralOffsetSpline; } - std::vector<mantle_api::SplineSection> lateral_offset_splines; + std::vector<mantle_api::SplineSection<units::length::meter_t>> lateral_offset_splines; }; // TODO: Create new control strategy for following 3D trajectories with shapes NURBS, polyline, clothoid @@ -177,7 +177,7 @@ struct AcquireLaneOffsetControlStrategy : public ControlStrategy int road_id{}; int lane_id{}; - double offset{}; + units::length::meter_t offset{}; TransitionDynamics transition_dynamics; }; -- GitLab