Skip to content

Commit

Permalink
feat(autoware_trajecotry): add conversion function from point traject…
Browse files Browse the repository at this point in the history
…ory to pose trajectory

Signed-off-by: Y.Hisaki <yhisaki31@gmail.com>
  • Loading branch information
yhisaki committed Feb 19, 2025
1 parent cb5cd89 commit 7523d34
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ namespace autoware::trajectory
template <>
class Trajectory<geometry_msgs::msg::Point>
{
template <class PointType>
friend class Trajectory;

using PointType = geometry_msgs::msg::Point;

protected:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ class Trajectory<geometry_msgs::msg::Pose> : public Trajectory<geometry_msgs::ms
Trajectory & operator=(const Trajectory & rhs);
Trajectory & operator=(Trajectory && rhs) = default;

// enable making trajectory from point trajectory
explicit Trajectory(const Trajectory<geometry_msgs::msg::Point> & point_trajectory);

bool build(const std::vector<PointType> & points);

/**
Expand Down
27 changes: 27 additions & 0 deletions common/autoware_trajectory/src/pose.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include "autoware/trajectory/pose.hpp"

#include "autoware/trajectory/detail/helpers.hpp"
#include "autoware/trajectory/forward.hpp"
#include "autoware/trajectory/interpolator/spherical_linear.hpp"

#include <tf2/LinearMath/Quaternion.h>
Expand Down Expand Up @@ -45,6 +46,32 @@ Trajectory<PointType> & Trajectory<PointType>::operator=(const Trajectory & rhs)
return *this;
}

Trajectory<PointType>::Trajectory(const Trajectory<geometry_msgs::msg::Point> & point_trajectory)
: Trajectory()

Check warning on line 50 in common/autoware_trajectory/src/pose.cpp

View check run for this annotation

Codecov / codecov/patch

common/autoware_trajectory/src/pose.cpp#L49-L50

Added lines #L49 - L50 were not covered by tests
{
x_interpolator_ = point_trajectory.x_interpolator_->clone();
y_interpolator_ = point_trajectory.y_interpolator_->clone();
z_interpolator_ = point_trajectory.z_interpolator_->clone();
bases_ = point_trajectory.get_internal_bases();
start_ = point_trajectory.start_;

Check warning on line 56 in common/autoware_trajectory/src/pose.cpp

View check run for this annotation

Codecov / codecov/patch

common/autoware_trajectory/src/pose.cpp#L56

Added line #L56 was not covered by tests
end_ = point_trajectory.end_;

// build mock orientations
std::vector<geometry_msgs::msg::Quaternion> orientations(bases_.size());
for (size_t i = 0; i < bases_.size(); ++i) {
orientations[i].w = 1.0;

Check warning on line 62 in common/autoware_trajectory/src/pose.cpp

View check run for this annotation

Codecov / codecov/patch

common/autoware_trajectory/src/pose.cpp#L62

Added line #L62 was not covered by tests
}
bool success = orientation_interpolator_->build(bases_, orientations);

if (!success) {
throw std::runtime_error(
"Failed to build orientation interpolator."); // This Exception should not be thrown.

Check warning on line 68 in common/autoware_trajectory/src/pose.cpp

View check run for this annotation

Codecov / codecov/patch

common/autoware_trajectory/src/pose.cpp#L68

Added line #L68 was not covered by tests
}

// align orientation with trajectory direction
align_orientation_with_trajectory_direction();
}

Check warning on line 73 in common/autoware_trajectory/src/pose.cpp

View check run for this annotation

Codecov / codecov/patch

common/autoware_trajectory/src/pose.cpp#L73

Added line #L73 was not covered by tests

bool Trajectory<PointType>::build(const std::vector<PointType> & points)
{
std::vector<geometry_msgs::msg::Point> path_points;
Expand Down

0 comments on commit 7523d34

Please sign in to comment.