Skip to content

Commit b6f194e

Browse files
committed
WIP
Signed-off-by: Mamoru Sobue <mamoru.sobue@tier4.jp>
1 parent 0def92b commit b6f194e

File tree

3 files changed

+59
-5
lines changed

3 files changed

+59
-5
lines changed

common/autoware_trajectory/include/autoware/trajectory/utils/autoware_msgs.hpp

+9-4
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#include <autoware_planning_msgs/msg/path.hpp>
2525
#include <autoware_planning_msgs/msg/trajectory.hpp>
2626

27+
#include <optional>
2728
#include <string>
2829
#include <vector>
2930

@@ -64,15 +65,18 @@ std::optional<Trajectory<autoware_planning_msgs::msg::PathPoint>> from_autoware_
6465
std::optional<Trajectory<autoware_planning_msgs::msg::TrajectoryPoint>> from_autoware_msgs(
6566
const autoware_planning_msgs::msg::Trajectory & path, const bool use_akima = false);
6667

68+
namespace detail
69+
{
70+
6771
/**
6872
* @brief if the input point size is less than 3, add 3rd point, otherwise return as is
6973
* @param[in] inputs vector of point whose size is at least 2
7074
* @return the vector of points whose size is at least 3, or error reason
7175
* @note {x, y, z}/orientation are interpolated by Linear/SphericalLinear. other properties as
7276
* interpolated by StairStep
7377
*/
74-
tl::expected<std::vector<autoware_internal_planning_msgs::msg::PathPointWithLaneId>, std::string>
75-
populate3(const std::vector<autoware_internal_planning_msgs::msg::PathPointWithLaneId> & inputs);
78+
template <typename PointType>
79+
tl::expected<std::vector<PointType>, std::string> populate3(const std::vector<PointType> & inputs);
7680

7781
/**
7882
* @brief if the input point size is less than 4, add 4th point, otherwise return as is
@@ -82,8 +86,8 @@ populate3(const std::vector<autoware_internal_planning_msgs::msg::PathPointWithL
8286
* @note {x, y, z}/orientation are interpolated by Linear/SphericalLinear. other properties as
8387
* interpolated by StairStep
8488
*/
85-
tl::expected<std::vector<autoware_internal_planning_msgs::msg::PathPointWithLaneId>, std::string>
86-
populate4(const std::vector<autoware_internal_planning_msgs::msg::PathPointWithLaneId> & inputs);
89+
template <typename PointType>
90+
tl::expected<std::vector<PointType>, std::string> populate4(const std::vector<PointType> & inputs);
8791

8892
/**
8993
* @brief if the input point size is less than 5, add 5th point, otherwise return as is
@@ -96,6 +100,7 @@ std::vector<autoware_internal_planning_msgs::msg::PathPointWithLaneId> populate5
96100
const std::vector<autoware_internal_planning_msgs::msg::PathPointWithLaneId> & inputs,
97101
const size_t minimum_number_of_points);
98102
*/
103+
} // namespace detail
99104

100105
} // namespace autoware::trajectory
101106
#endif // AUTOWARE__TRAJECTORY__UTILS__AUTOWARE_MSGS_HPP_

common/autoware_trajectory/src/utils/autoware_msgs.cpp

+50
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,56 @@
2525
namespace autoware::trajectory
2626
{
2727

28+
template <typename T>
29+
const geometry_msgs::msg::Pose & get_geometry_msgs_pose([[maybe_unused]] const T & point)
30+
{
31+
static_assert("No specialization given");
32+
}
33+
34+
template <>
35+
const geometry_msgs::msg::Pose & get_geometry_msgs_pose(
36+
const autoware_internal_planning_msgs::msg::PathPointWithLaneId & point)
37+
{
38+
return point.point.pose;
39+
}
40+
41+
template <>
42+
const geometry_msgs::msg::Pose & get_geometry_msgs_pose(
43+
const autoware_planning_msgs::msg::PathPoint & point)
44+
{
45+
return point.pose;
46+
}
47+
48+
template <>
49+
const geometry_msgs::msg::Pose & get_geometry_msgs_pose(
50+
const autoware_planning_msgs::msg::TrajectoryPoint & point)
51+
{
52+
return point.pose;
53+
}
54+
55+
template <typename PointType>
56+
tl::expected<std::vector<PointType>, std::string> populate3(const std::vector<PointType> & inputs)
57+
{
58+
if (inputs.size() >= 3) {
59+
return inputs;
60+
}
61+
if (inputs.size() < 2) {
62+
return tl::unexpected("cannot populate3() from #" + std::to_string(inputs.size()) + " points!");
63+
}
64+
65+
const auto & p1 = get_geometry_msgs_pose<PointType>(inputs.at(0));
66+
const auto & pos1 = p1.position;
67+
const auto & p2 = get_geometry_msgs_pose<PointType>(inputs.at(1));
68+
const auto & pos2 = p2.position;
69+
const auto l = autoware_utils_geometry::calc_distance3d(pos1, pos2);
70+
71+
const auto quat_result =
72+
interpolator::SphericalLinear::Builder{}
73+
.set_bases(std::vector<double>{0.0, l})
74+
.set_values(std::vector<geometry_msgs::msg::Quaternion>({p1.orientation, p2.orientation}))
75+
.build();
76+
}
77+
2878
tl::expected<std::vector<autoware_internal_planning_msgs::msg::PathPointWithLaneId>, std::string>
2979
populate3(const std::vector<autoware_internal_planning_msgs::msg::PathPointWithLaneId> & inputs)
3080
{

common/autoware_trajectory/test/test_autoware_msgs.cpp

-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717

1818
#include <gtest/gtest.h>
1919

20-
#include <optional>
2120
#include <vector>
2221

2322
using autoware_internal_planning_msgs::msg::PathPointWithLaneId;

0 commit comments

Comments
 (0)