-
Notifications
You must be signed in to change notification settings - Fork 51
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(autoware_trajectory): add trajectory point (#233)
* add TrajectoryPoint class to templates Signed-off-by: Daniel Sanchez <danielsanchezaran@gmail.com> * add tests Signed-off-by: Daniel Sanchez <danielsanchezaran@gmail.com> * add method to_point for TrajectoryPoint type Signed-off-by: Daniel <danielsanchezaran@gmail.com> * change name of test to avoid name collision Signed-off-by: Daniel <danielsanchezaran@gmail.com> * add missing items Signed-off-by: Y.Hisaki <yhisaki31@gmail.com> * rename example name for clarity Signed-off-by: Y.Hisaki <yhisaki31@gmail.com> --------- Signed-off-by: Daniel Sanchez <danielsanchezaran@gmail.com> Signed-off-by: Daniel <danielsanchezaran@gmail.com> Signed-off-by: Y.Hisaki <yhisaki31@gmail.com> Co-authored-by: Y.Hisaki <yhisaki31@gmail.com>
- Loading branch information
1 parent
d56554a
commit 2e5c9e0
Showing
8 changed files
with
567 additions
and
0 deletions.
There are no files selected for viewing
File renamed without changes.
File renamed without changes.
File renamed without changes.
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
221 changes: 221 additions & 0 deletions
221
common/autoware_trajectory/include/autoware/trajectory/trajectory_point.hpp
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,221 @@ | ||
// Copyright 2024 TIER IV, Inc. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
#ifndef AUTOWARE__TRAJECTORY__TRAJECTORY_POINT_HPP_ | ||
#define AUTOWARE__TRAJECTORY__TRAJECTORY_POINT_HPP_ | ||
|
||
#include "autoware/trajectory/detail/interpolated_array.hpp" | ||
#include "autoware/trajectory/pose.hpp" | ||
|
||
#include <autoware_planning_msgs/msg/trajectory.hpp> | ||
|
||
#include <memory> | ||
#include <utility> | ||
#include <vector> | ||
|
||
namespace autoware::trajectory | ||
{ | ||
template <> | ||
class Trajectory<autoware_planning_msgs::msg::TrajectoryPoint> | ||
: public Trajectory<geometry_msgs::msg::Pose> | ||
{ | ||
using BaseClass = Trajectory<geometry_msgs::msg::Pose>; | ||
using PointType = autoware_planning_msgs::msg::TrajectoryPoint; | ||
|
||
std::shared_ptr<detail::InterpolatedArray<double>> | ||
longitudinal_velocity_mps_; //!< Longitudinal velocity in m/s | ||
std::shared_ptr<detail::InterpolatedArray<double>> | ||
lateral_velocity_mps_; //!< Lateral velocity in m/s | ||
std::shared_ptr<detail::InterpolatedArray<double>> | ||
heading_rate_rps_; //!< Heading rate in rad/s}; | ||
std::shared_ptr<detail::InterpolatedArray<double>> | ||
acceleration_mps2_; //!< Longitudinal acceleration in m/s^2} Warning, this is not used | ||
std::shared_ptr<detail::InterpolatedArray<double>> | ||
front_wheel_angle_rad_; //!< Front wheel angle in rad} Warning, this is not used | ||
std::shared_ptr<detail::InterpolatedArray<double>> | ||
rear_wheel_angle_rad_; //!< Rear wheel angle in rad} Warning, this is not used | ||
|
||
public: | ||
Trajectory(); | ||
~Trajectory() override = default; | ||
Trajectory(const Trajectory & rhs); | ||
Trajectory(Trajectory && rhs) = default; | ||
Trajectory & operator=(const Trajectory & rhs); | ||
Trajectory & operator=(Trajectory && rhs) = default; | ||
|
||
[[nodiscard]] std::vector<double> get_internal_bases() const override; | ||
|
||
detail::InterpolatedArray<double> & longitudinal_velocity_mps() | ||
{ | ||
return *longitudinal_velocity_mps_; | ||
} | ||
|
||
detail::InterpolatedArray<double> & lateral_velocity_mps() { return *lateral_velocity_mps_; } | ||
|
||
detail::InterpolatedArray<double> & heading_rate_rps() { return *heading_rate_rps_; } | ||
|
||
detail::InterpolatedArray<double> & acceleration_mps2() { return *acceleration_mps2_; } | ||
|
||
detail::InterpolatedArray<double> & front_wheel_angle_rad() { return *front_wheel_angle_rad_; } | ||
|
||
detail::InterpolatedArray<double> & rear_wheel_angle_rad() { return *rear_wheel_angle_rad_; } | ||
|
||
[[nodiscard]] const detail::InterpolatedArray<double> & longitudinal_velocity_mps() const | ||
{ | ||
return *longitudinal_velocity_mps_; | ||
} | ||
|
||
[[nodiscard]] const detail::InterpolatedArray<double> & lateral_velocity_mps() const | ||
{ | ||
return *lateral_velocity_mps_; | ||
} | ||
|
||
[[nodiscard]] const detail::InterpolatedArray<double> & heading_rate_rps() const | ||
{ | ||
return *heading_rate_rps_; | ||
} | ||
|
||
[[nodiscard]] const detail::InterpolatedArray<double> & acceleration_mps2() const | ||
{ | ||
return *acceleration_mps2_; | ||
} | ||
|
||
[[nodiscard]] const detail::InterpolatedArray<double> & front_wheel_angle_rad() const | ||
{ | ||
return *front_wheel_angle_rad_; | ||
} | ||
|
||
[[nodiscard]] const detail::InterpolatedArray<double> & rear_wheel_angle_rad() const | ||
{ | ||
return *rear_wheel_angle_rad_; | ||
} | ||
|
||
/** | ||
* @brief Build the trajectory from the points | ||
* @param points Vector of points | ||
* @return True if the build is successful | ||
*/ | ||
bool build(const std::vector<PointType> & points); | ||
|
||
/** | ||
* @brief Compute the point on the trajectory at a given s value | ||
* @param s Arc length | ||
* @return Point on the trajectory | ||
*/ | ||
[[nodiscard]] PointType compute(double s) const; | ||
|
||
/** | ||
* @brief Restore the trajectory points | ||
* @param min_points Minimum number of points | ||
* @return Vector of points | ||
*/ | ||
[[nodiscard]] std::vector<PointType> restore(const size_t & min_points = 4) const; | ||
|
||
class Builder | ||
{ | ||
private: | ||
std::unique_ptr<Trajectory> trajectory_; | ||
|
||
public: | ||
Builder() : trajectory_(std::make_unique<Trajectory>()) {} | ||
|
||
template <class InterpolatorType, class... Args> | ||
Builder & set_xy_interpolator(Args &&... args) | ||
{ | ||
trajectory_->x_interpolator_ = | ||
std::make_shared<InterpolatorType>(std::forward<Args>(args)...); | ||
trajectory_->y_interpolator_ = | ||
std::make_shared<InterpolatorType>(std::forward<Args>(args)...); | ||
return *this; | ||
} | ||
|
||
template <class InterpolatorType, class... Args> | ||
Builder & set_z_interpolator(Args &&... args) | ||
{ | ||
trajectory_->z_interpolator_ = | ||
std::make_shared<InterpolatorType>(std::forward<Args>(args)...); | ||
return *this; | ||
} | ||
|
||
template <class InterpolatorType, class... Args> | ||
Builder & set_orientation_interpolator(Args &&... args) | ||
{ | ||
trajectory_->orientation_interpolator_ = | ||
std::make_shared<InterpolatorType>(std::forward<Args>(args)...); | ||
return *this; | ||
} | ||
|
||
template <class InterpolatorType, class... Args> | ||
Builder & set_longitudinal_velocity_interpolator(Args &&... args) | ||
{ | ||
trajectory_->longitudinal_velocity_mps_ = std::make_shared<detail::InterpolatedArray<double>>( | ||
std::make_shared<InterpolatorType>(std::forward<Args>(args)...)); | ||
return *this; | ||
} | ||
|
||
template <class InterpolatorType, class... Args> | ||
Builder & set_lateral_velocity_interpolator(Args &&... args) | ||
{ | ||
trajectory_->lateral_velocity_mps_ = std::make_shared<detail::InterpolatedArray<double>>( | ||
std::make_shared<InterpolatorType>(std::forward<Args>(args)...)); | ||
return *this; | ||
} | ||
|
||
template <class InterpolatorType, class... Args> | ||
Builder & set_heading_rate_interpolator(Args &&... args) | ||
{ | ||
trajectory_->heading_rate_rps_ = std::make_shared<detail::InterpolatedArray<double>>( | ||
std::make_shared<InterpolatorType>(std::forward<Args>(args)...)); | ||
return *this; | ||
} | ||
|
||
template <class InterpolatorType, class... Args> | ||
Builder & set_acceleration_interpolator(Args &&... args) | ||
{ | ||
trajectory_->acceleration_mps2_ = std::make_shared<detail::InterpolatedArray<double>>( | ||
std::make_shared<InterpolatorType>(std::forward<Args>(args)...)); | ||
return *this; | ||
} | ||
|
||
template <class InterpolatorType, class... Args> | ||
Builder & set_front_wheel_angle_interpolator(Args &&... args) | ||
{ | ||
trajectory_->front_wheel_angle_rad_ = std::make_shared<detail::InterpolatedArray<double>>( | ||
std::make_shared<InterpolatorType>(std::forward<Args>(args)...)); | ||
return *this; | ||
} | ||
|
||
template <class InterpolatorType, class... Args> | ||
Builder & set_rear_wheel_angle_interpolator(Args &&... args) | ||
{ | ||
trajectory_->rear_wheel_angle_rad_ = std::make_shared<detail::InterpolatedArray<double>>( | ||
std::make_shared<InterpolatorType>(std::forward<Args>(args)...)); | ||
return *this; | ||
} | ||
|
||
std::optional<Trajectory> build(const std::vector<PointType> & points) | ||
{ | ||
if (trajectory_->build(points)) { | ||
auto result = std::make_optional<Trajectory>(std::move(*trajectory_)); | ||
trajectory_.reset(); | ||
return result; | ||
} | ||
return std::nullopt; | ||
} | ||
}; | ||
}; | ||
|
||
} // namespace autoware::trajectory | ||
|
||
#endif // AUTOWARE__TRAJECTORY__TRAJECTORY_POINT_HPP_ |
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
Oops, something went wrong.