22#include <carma_perception_msgs/msg/external_object.hpp>
29 const carma_v2x_msgs::msg::BSM & in_msg, carma_perception_msgs::msg::ExternalObject & out_msg,
30 const std::string & map_frame_id,
double pred_period,
double pred_step_size,
31 const lanelet::projection::LocalFrameProjector & map_projector,
32 tf2::Quaternion ned_in_map_rotation)
34 out_msg.presence_vector |= carma_perception_msgs::msg::ExternalObject::BSM_ID_PRESENCE_VECTOR;
37 out_msg.dynamic_obj =
true;
38 out_msg.presence_vector |= carma_perception_msgs::msg::ExternalObject::DYNAMIC_OBJ_PRESENCE;
43 for (
int i = in_msg.core_data.id.size() - 1;
i >= 0;
48 out_msg.id |= in_msg.core_data.id[
i] << (8 *
i);
50 out_msg.presence_vector |= carma_perception_msgs::msg::ExternalObject::ID_PRESENCE_VECTOR;
53 out_msg.bsm_id = in_msg.core_data.id;
54 out_msg.presence_vector |= carma_perception_msgs::msg::ExternalObject::BSM_ID_PRESENCE_VECTOR;
58 out_msg.header.stamp = in_msg.header.stamp;
59 out_msg.header.frame_id = map_frame_id;
64 in_msg.core_data.size.presence_vector &
65 carma_v2x_msgs::msg::VehicleSize::VEHICLE_LENGTH_AVAILABLE) {
67 out_msg.size.x = in_msg.core_data.size.vehicle_length / 2;
73 in_msg.core_data.size.presence_vector &
74 carma_v2x_msgs::msg::VehicleSize::VEHICLE_WIDTH_AVAILABLE) {
76 out_msg.size.y = in_msg.core_data.size.vehicle_width / 2;
83 out_msg.object_type = carma_perception_msgs::msg::ExternalObject::SMALL_VEHICLE;
87 if (in_msg.core_data.presence_vector & carma_v2x_msgs::msg::BSMCoreData::SPEED_AVAILABLE) {
88 out_msg.presence_vector |= carma_perception_msgs::msg::ExternalObject::VELOCITY_PRESENCE_VECTOR;
89 float_t speed_mps = in_msg.core_data.speed;
91 out_msg.velocity.twist.linear.x = std::min(speed_mps, in_msg.core_data.SPEED_MAX);
105 double largest_position_std =
106 std::max(in_msg.core_data.accuracy.semi_major, in_msg.core_data.accuracy.semi_minor);
108 double lat_variance = in_msg.core_data.accuracy.semi_minor * in_msg.core_data.accuracy.semi_minor;
110 double lon_variance = in_msg.core_data.accuracy.semi_major * in_msg.core_data.accuracy.semi_major;
112 double heading_variance =
113 in_msg.core_data.accuracy.orientation * in_msg.core_data.accuracy.orientation;
115 double position_confidence = 0.1;
120 constexpr double MAX_POSITION_STD = 1.85;
123 (in_msg.core_data.accuracy.presence_vector |
124 carma_v2x_msgs::msg::PositionalAccuracy::ACCURACY_AVAILABLE) &&
125 (in_msg.core_data.accuracy.presence_vector |
126 carma_v2x_msgs::msg::PositionalAccuracy::ACCURACY_ORIENTATION_AVAILABLE)) {
138 out_msg.confidence = 1.0 - std::min(1.0, fabs(largest_position_std / MAX_POSITION_STD));
139 out_msg.presence_vector |=
140 carma_perception_msgs::msg::ExternalObject::CONFIDENCE_PRESENCE_VECTOR;
142 in_msg.core_data.accuracy.presence_vector |
143 carma_v2x_msgs::msg::PositionalAccuracy::ACCURACY_AVAILABLE) {
146 heading_variance = 1.0;
150 out_msg.confidence = 1.0 - std::min(1.0, fabs(largest_position_std / MAX_POSITION_STD));
151 out_msg.presence_vector |=
152 carma_perception_msgs::msg::ExternalObject::CONFIDENCE_PRESENCE_VECTOR;
154 in_msg.core_data.accuracy.presence_vector |
155 carma_v2x_msgs::msg::PositionalAccuracy::ACCURACY_ORIENTATION_AVAILABLE) {
167 (in_msg.core_data.presence_vector & carma_v2x_msgs::msg::BSMCoreData::LATITUDE_AVAILABLE) &&
168 (in_msg.core_data.presence_vector & carma_v2x_msgs::msg::BSMCoreData::LONGITUDE_AVAILABLE) &&
169 (in_msg.core_data.presence_vector & carma_v2x_msgs::msg::BSMCoreData::ELEVATION_AVAILABLE) &&
170 (in_msg.core_data.presence_vector & carma_v2x_msgs::msg::BSMCoreData::HEADING_AVAILABLE)) {
171 double longitude = std::min(in_msg.core_data.longitude, in_msg.core_data.LONGITUDE_MAX);
172 longitude = std::max(longitude, in_msg.core_data.LONGITUDE_MIN);
174 double latitude = std::min(in_msg.core_data.latitude, in_msg.core_data.LATITUDE_MAX);
177 double elev = std::min(in_msg.core_data.elev, in_msg.core_data.ELEVATION_MAX);
180 double heading = std::min(in_msg.core_data.heading, in_msg.core_data.HEADING_MAX);
184 map_projector, ned_in_map_rotation, {latitude, longitude, elev}, heading, lat_variance,
185 lon_variance, heading_variance);
186 out_msg.presence_vector |= carma_perception_msgs::msg::ExternalObject::POSE_PRESENCE_VECTOR;
190 out_msg.presence_vector |= carma_perception_msgs::msg::ExternalObject::POSE_PRESENCE_VECTOR;
197 std::vector<geometry_msgs::msg::Pose> predicted_poses;
200 out_msg.pose.pose, out_msg.velocity.twist.linear.x, pred_period, pred_step_size);
203 predicted_poses, out_msg.velocity.twist.linear.x, rclcpp::Time(out_msg.header.stamp),
204 rclcpp::Duration(pred_step_size * 1e9), map_frame_id, out_msg.confidence, out_msg.confidence);
205 out_msg.presence_vector |= carma_perception_msgs::msg::ExternalObject::PREDICTION_PRESENCE_VECTOR;
geometry_msgs::msg::PoseWithCovariance pose_from_gnss(const lanelet::projection::LocalFrameProjector &projector, const tf2::Quaternion &ned_in_map_rotation, const lanelet::GPSPoint &gps_point, const double &heading, const double lat_variance, const double lon_variance, const double heading_variance)
std::vector< carma_perception_msgs::msg::PredictedState > predicted_poses_to_predicted_state(const std::vector< geometry_msgs::msg::Pose > &poses, double constant_velocity, const rclcpp::Time &start_time, const rclcpp::Duration &step_size, const std::string &frame, double initial_pose_confidence, double initial_vel_confidence)
std::vector< geometry_msgs::msg::Pose > sample_2d_linear_motion(const geometry_msgs::msg::Pose &pose, double velocity, double period, double step_size)
void convert(const carma_v2x_msgs::msg::PSM &in_msg, carma_perception_msgs::msg::ExternalObject &out_msg, const std::string &map_frame_id, double pred_period, double pred_step_size, const lanelet::projection::LocalFrameProjector &map_projector, const tf2::Quaternion &ned_in_map_rotation, rclcpp::node_interfaces::NodeClockInterface::SharedPtr node_clock)