Carma-platform v4.2.0
CARMA Platform is built on robot operating system (ROS) and utilizes open source software (OSS) that enables Cooperative Driving Automation (CDA) features to allow Automated Driving Systems to interact and cooperate with infrastructure and other vehicles through communication.
msg_conversion.hpp
Go to the documentation of this file.
1// Copyright 2023 Leidos
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15#ifndef CARMA_COOPERATIVE_PERCEPTION__MSG_CONVERSION_HPP_
16#define CARMA_COOPERATIVE_PERCEPTION__MSG_CONVERSION_HPP_
17
18#include <units.h>
19
20#include <carma_cooperative_perception_interfaces/msg/detection_list.hpp>
21#include <carma_cooperative_perception_interfaces/msg/track.hpp>
22#include <carma_cooperative_perception_interfaces/msg/track_list.hpp>
23#include <carma_perception_msgs/msg/external_object.hpp>
24#include <carma_perception_msgs/msg/external_object_list.hpp>
25#include <carma_v2x_msgs/msg/sensor_data_sharing_message.hpp>
26
30
31#include <geometry_msgs/msg/pose_stamped.hpp>
32
33#include <lanelet2_core/geometry/Lanelet.h>
34#include <lanelet2_extension/projection/local_frame_projector.h>
35
36#include <tf2/LinearMath/Quaternion.h>
37
38#include <memory>
39#include <string>
40#include <string_view>
41
43{
45{
46public:
49 double pose_covariance_x{0.125};
50 double pose_covariance_y{0.125};
51 double pose_covariance_z{0.125};
52 double pose_covariance_yaw{0.005};
53 double twist_covariance_x{0.005};
54 double twist_covariance_z{0.005};
55 double twist_covariance_yaw{0.005};
56 bool adjust_pose{false};
57 double x_offset{0.0};
58 double y_offset{0.0};
59 double yaw_offset{0.0};
60
61 // Stream operator for logging
62 friend std::ostream & operator<<(std::ostream & os, const SdsmToDetectionListConfig & config)
63 {
64 os << "SdsmToDetectionListConfig{"
65 << "\n overwrite_covariance: " << config.overwrite_covariance
66 << "\n pose_covariance_x: " << config.pose_covariance_x
67 << "\n pose_covariance_y: " << config.pose_covariance_y
68 << "\n pose_covariance_z: " << config.pose_covariance_z
69 << "\n pose_covariance_yaw: " << config.pose_covariance_yaw
70 << "\n twist_covariance_x: " << config.twist_covariance_x
71 << "\n twist_covariance_z: " << config.twist_covariance_z
72 << "\n twist_covariance_yaw: " << config.twist_covariance_yaw
73 << "\n adjust_pose: " << config.adjust_pose
74 << "\n x_offset: " << config.x_offset
75 << "\n y_offset: " << config.y_offset
76 << "\n yaw_offset: " << config.yaw_offset
77 << "\n}";
78 return os;
79 }
80};
81
82// NOTE: If incoming SDSM message doesn't have timezone enabled,
83// it automatically uses the local timezone. If the node is running in a container,
84// it would mean the container's default timezone (most likely UTC), unless otherwise set.
85// Make sure the container's timezone is same as the implicit timezone of the SDSM's timestamp
86auto to_time_msg(
87 const DDateTime & d_date_time, bool is_simulation) -> builtin_interfaces::msg::Time;
88
89auto calc_detection_time_stamp(DDateTime d_date_time, const MeasurementTimeOffset & offset)
90 -> DDateTime;
91
92auto to_ddate_time_msg(const builtin_interfaces::msg::Time & builtin_time)
93 -> j2735_v2x_msgs::msg::DDateTime;
94
96 const builtin_interfaces::msg::Time & external_object_list_time,
97 const builtin_interfaces::msg::Time & external_object_time)
98 -> carma_v2x_msgs::msg::MeasurementTimeOffset;
99
100auto to_position_msg(const UtmCoordinate & position_utm) -> geometry_msgs::msg::Point;
101
102auto heading_to_enu_yaw(const units::angle::degree_t & heading) -> units::angle::degree_t;
103
105 const geometry_msgs::msg::PoseStamped & current_pose,
106 const carma_v2x_msgs::msg::PositionOffsetXYZ & detected_object_data)
107 -> carma_v2x_msgs::msg::PositionOffsetXYZ;
108
110 const geometry_msgs::msg::PoseStamped & source_pose,
111 const std::shared_ptr<lanelet::projection::LocalFrameProjector> & map_projection)
112 -> carma_v2x_msgs::msg::Position3D;
113
115 const carma_v2x_msgs::msg::SensorDataSharingMessage & sdsm, std::string_view georeference,
116 bool is_simulation, const std::optional<SdsmToDetectionListConfig>& conversion_adjustment)
117 -> carma_cooperative_perception_interfaces::msg::DetectionList;
118
120{
122 carma_cooperative_perception_interfaces::msg::Detection::MOTION_MODEL_CTRV};
124 carma_cooperative_perception_interfaces::msg::Detection::MOTION_MODEL_CTRV};
125 std::uint8_t motorcycle_model{
126 carma_cooperative_perception_interfaces::msg::Detection::MOTION_MODEL_CTRV};
127 std::uint8_t pedestrian_model{
128 carma_cooperative_perception_interfaces::msg::Detection::MOTION_MODEL_CTRV};
129 std::uint8_t unknown_model{
130 carma_cooperative_perception_interfaces::msg::Detection::MOTION_MODEL_CTRV};
131};
132
134 const carma_perception_msgs::msg::ExternalObject & object,
135 const MotionModelMapping & motion_model_mapping)
137
139 const carma_perception_msgs::msg::ExternalObjectList & object_list,
140 const MotionModelMapping & motion_model_mapping)
141 -> carma_cooperative_perception_interfaces::msg::DetectionList;
142
144 -> carma_perception_msgs::msg::ExternalObject;
145
147 const carma_cooperative_perception_interfaces::msg::TrackList & track_list)
148 -> carma_perception_msgs::msg::ExternalObjectList;
149
150auto to_sdsm_msg(
151 const carma_perception_msgs::msg::ExternalObjectList & external_object_list,
152 const geometry_msgs::msg::PoseStamped & current_pose,
153 const std::shared_ptr<lanelet::projection::LocalFrameProjector> & map_projection)
154 -> carma_v2x_msgs::msg::SensorDataSharingMessage;
155
157 const carma_perception_msgs::msg::ExternalObject & external_object,
158 const std::shared_ptr<lanelet::projection::LocalFrameProjector> & map_projection)
159 -> carma_v2x_msgs::msg::DetectedObjectData;
160
162 double yaw, const lanelet::BasicPoint3d & obj_pose,
163 const std::shared_ptr<lanelet::projection::LocalFrameProjector> & map_projection)
164 -> units::angle::degree_t;
165
166} // namespace carma_cooperative_perception
167
168#endif // CARMA_COOPERATIVE_PERCEPTION__MSG_CONVERSION_HPP_
friend std::ostream & operator<<(std::ostream &os, const SdsmToDetectionListConfig &config)
auto enu_orientation_to_true_heading(double yaw, const lanelet::BasicPoint3d &obj_pose, const std::shared_ptr< lanelet::projection::LocalFrameProjector > &map_projection) -> units::angle::degree_t
auto to_external_object_list_msg(const carma_cooperative_perception_interfaces::msg::TrackList &track_list) -> carma_perception_msgs::msg::ExternalObjectList
auto calc_sdsm_time_offset(const builtin_interfaces::msg::Time &external_object_list_time, const builtin_interfaces::msg::Time &external_object_time) -> carma_v2x_msgs::msg::MeasurementTimeOffset
auto to_ddate_time_msg(const builtin_interfaces::msg::Time &builtin_time) -> j2735_v2x_msgs::msg::DDateTime
auto calc_detection_time_stamp(DDateTime d_date_time, const MeasurementTimeOffset &offset) -> DDateTime
std::variant< multiple_object_tracking::CtrvDetection, multiple_object_tracking::CtraDetection > Detection
auto to_detection_msg(const carma_perception_msgs::msg::ExternalObject &object, const MotionModelMapping &motion_model_mapping) -> carma_cooperative_perception_interfaces::msg::Detection
auto to_time_msg(const DDateTime &d_date_time, bool is_simulation) -> builtin_interfaces::msg::Time
auto to_detected_object_data_msg(const carma_perception_msgs::msg::ExternalObject &external_object, const std::shared_ptr< lanelet::projection::LocalFrameProjector > &map_projection) -> carma_v2x_msgs::msg::DetectedObjectData
auto to_external_object_msg(const carma_cooperative_perception_interfaces::msg::Track &track) -> carma_perception_msgs::msg::ExternalObject
auto heading_to_enu_yaw(const units::angle::degree_t &heading) -> units::angle::degree_t
auto calc_relative_position(const geometry_msgs::msg::PoseStamped &current_pose, const carma_v2x_msgs::msg::PositionOffsetXYZ &detected_object_data) -> carma_v2x_msgs::msg::PositionOffsetXYZ
auto to_sdsm_msg(const carma_perception_msgs::msg::ExternalObjectList &external_object_list, const geometry_msgs::msg::PoseStamped &current_pose, const std::shared_ptr< lanelet::projection::LocalFrameProjector > &map_projection) -> carma_v2x_msgs::msg::SensorDataSharingMessage
auto to_position_msg(const UtmCoordinate &position_utm) -> geometry_msgs::msg::Point
std::variant< multiple_object_tracking::CtrvTrack, multiple_object_tracking::CtraTrack > Track
auto transform_pose_from_map_to_wgs84(const geometry_msgs::msg::PoseStamped &source_pose, const std::shared_ptr< lanelet::projection::LocalFrameProjector > &map_projection) -> carma_v2x_msgs::msg::Position3D
auto to_detection_list_msg(const carma_v2x_msgs::msg::SensorDataSharingMessage &sdsm, std::string_view georeference, bool is_simulation, const std::optional< SdsmToDetectionListConfig > &conversion_adjustment) -> carma_cooperative_perception_interfaces::msg::DetectionList
Converts a carma_v2x_msgs::msg::SensorDataSharingMessage (SDSM) to carma_cooperative_perception_inter...