lanelet2_route_planning v2.0.0
Loading...
Searching...
No Matches
conversions.cpp
Go to the documentation of this file.
1// Copyright Institute for Automotive Engineering (ika), RWTH Aachen University
2// SPDX-License-Identifier: Apache-2.0
3
4#include <perception_msgs_utils/object_access.hpp>
5#include <route_planning_msgs_utils/route_access.hpp>
6
8
10
11Eigen::Vector2d to2d(const Eigen::Vector3d& point) { return point.head<2>(); }
12
13Eigen::Vector3d to3d(const Eigen::Vector2d& point) { return Eigen::Vector3d(point.x(), point.y(), 0.0); }
14
15Eigen::Vector3d to3d(const Eigen::Vector2d& point, double z) { return Eigen::Vector3d(point.x(), point.y(), z); }
16
17std::vector<Eigen::Vector2d> to2d(const std::vector<Eigen::Vector3d>& points) {
18 std::vector<Eigen::Vector2d> points_2d;
19 for (const auto& point : points) {
20 points_2d.push_back(to2d(point));
21 }
22 return points_2d;
23}
24
25std::vector<Eigen::Vector3d> to3d(const std::vector<Eigen::Vector2d>& points) {
26 std::vector<Eigen::Vector3d> points_3d;
27 for (const auto& point : points) {
28 points_3d.push_back(to3d(point));
29 }
30 return points_3d;
31}
32
33geometry_msgs::msg::Point toRos(const Eigen::Vector2d& point) { return toRos(to3d(point)); }
34
35geometry_msgs::msg::Point toRos(const Eigen::Vector3d& point) {
36 geometry_msgs::msg::Point ros_point;
37 ros_point.x = point.x();
38 ros_point.y = point.y();
39 ros_point.z = point.z();
40 return ros_point;
41}
42
43geometry_msgs::msg::Point toRos(const lanelet::BasicPoint2d& point) { return toRos(Eigen::Vector2d(point.x(), point.y())); }
44
45lanelet::BasicPoint2d toLanelet(const Eigen::Vector2d& point) { return lanelet::BasicPoint2d(point.x(), point.y()); }
46
47lanelet::BasicPoint3d toLanelet(const Eigen::Vector3d& point) { return point; }
48
49Eigen::Vector2d toEigen2d(const geometry_msgs::msg::Point& point) { return Eigen::Vector2d(point.x, point.y); }
50
51Eigen::Vector3d toEigen(const geometry_msgs::msg::Point& point) { return Eigen::Vector3d(point.x, point.y, point.z); }
52
53geometry_msgs::msg::Point egoPosition(const perception_msgs::msg::EgoData& ego_data) {
54 geometry_msgs::msg::Point position;
55 position.x = perception_msgs::object_access::getX(ego_data);
56 position.y = perception_msgs::object_access::getY(ego_data);
57 position.z = perception_msgs::object_access::getZ(ego_data);
58 return position;
59}
60
61std::vector<Eigen::Vector2d> toEigen(const lanelet::BasicLineString2d& line_string) {
62 return std::vector<Eigen::Vector2d>(line_string.begin(), line_string.end());
63}
64
65std::vector<Eigen::Vector3d> toEigen(const lanelet::BasicLineString3d& line_string) {
66 return std::vector<Eigen::Vector3d>(line_string.begin(), line_string.end());
67}
68
69lanelet::BasicLineString2d toLanelet(const std::vector<Eigen::Vector2d>& line_string) {
70 lanelet::BasicLineString2d lanelet_line_string;
71 for (const auto& point : line_string) {
72 lanelet_line_string.push_back(toLanelet(point));
73 }
74 return lanelet_line_string;
75}
76
77lanelet::BasicLineString3d toLanelet(const std::vector<Eigen::Vector3d>& line_string) {
78 lanelet::BasicLineString3d lanelet_line_string;
79 for (const auto& point : line_string) {
80 lanelet_line_string.push_back(toLanelet(point));
81 }
82 return lanelet_line_string;
83}
84
85geometry_msgs::msg::Quaternion toRosQuaternion(const Eigen::Vector2d& vector) {
86 Eigen::Vector2d unit_vector = vector.normalized();
87 double angle = std::atan2(unit_vector.y(), unit_vector.x());
88 Eigen::Quaterniond quaternion(Eigen::AngleAxisd(angle, Eigen::Vector3d::UnitZ()));
89 geometry_msgs::msg::Quaternion ros_quaternion;
90 ros_quaternion.x = quaternion.x();
91 ros_quaternion.y = quaternion.y();
92 ros_quaternion.z = quaternion.z();
93 ros_quaternion.w = quaternion.w();
94 return ros_quaternion;
95}
96
97std::vector<Eigen::Vector3d> suggestedReferenceLineToEigen(
98 const std::vector<route_planning_msgs::msg::RouteElement>& route_elements) {
99 std::vector<Eigen::Vector3d> reference_line;
100 for (const auto& route_element : route_elements) {
101 const auto& lane_element = route_planning_msgs::route_access::getSuggestedLaneElement(route_element);
102 reference_line.push_back(toEigen(lane_element.reference_pose.position));
103 }
104 return reference_line;
105}
106
107} // namespace lanelet2_route_planning
geometry_msgs::msg::Point egoPosition(const perception_msgs::msg::EgoData &ego_data)
Extracts an EgoData position as a ROS point.
Eigen::Vector3d to3d(const Eigen::Vector2d &point)
Converts a 2D Eigen point to a 3D Eigen point.
lanelet::BasicPoint2d toLanelet(const Eigen::Vector2d &point)
Converts a 2D Eigen point to a Lanelet point.
geometry_msgs::msg::Quaternion toRosQuaternion(const Eigen::Vector2d &vector)
Converts a 2D Eigen vector pointing in a specific direction to a ROS quaternion.
Eigen::Vector2d to2d(const Eigen::Vector3d &point)
Converts a 3D Eigen point to a 2D Eigen point.
geometry_msgs::msg::Point toRos(const Eigen::Vector2d &point)
Converts a 2D Eigen point to a ROS point.
std::vector< Eigen::Vector3d > suggestedReferenceLineToEigen(const std::vector< route_planning_msgs::msg::RouteElement > &route_elements)
Extracts the reference line along the suggested lane from a list of RouteElements.
Eigen::Vector2d toEigen2d(const geometry_msgs::msg::Point &point)
Converts a ROS point to a 2D Eigen point.
Eigen::Vector3d toEigen(const geometry_msgs::msg::Point &point)
Converts a ROS point to a 3D Eigen point.