Apollo 10.0
自动驾驶开放平台
common.h
浏览该文件的文档.
1/******************************************************************************
2 * Copyright 2023 The Apollo Authors. All Rights Reserved.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 *****************************************************************************/
16
17#pragma once
18
19#include <limits>
20
21#include "modules/common_msgs/perception_msgs/perception_obstacle.pb.h"
22
24
25namespace apollo {
26namespace perception {
27
28bool ConvertObjectToPb(const base::ObjectPtr &object_ptr,
29 PerceptionObstacle *pb_msg) {
30 if (object_ptr == nullptr || pb_msg == nullptr) {
31 return false;
32 }
33
34 pb_msg->set_id(object_ptr->track_id);
35 pb_msg->set_theta(object_ptr->theta);
36
37 apollo::common::Point3D *obj_center = pb_msg->mutable_position();
38 obj_center->set_x(object_ptr->center(0));
39 obj_center->set_y(object_ptr->center(1));
40 obj_center->set_z(object_ptr->center(2));
41
42 apollo::common::Point3D *obj_velocity = pb_msg->mutable_velocity();
43 obj_velocity->set_x(object_ptr->velocity(0));
44 obj_velocity->set_y(object_ptr->velocity(1));
45 obj_velocity->set_z(object_ptr->velocity(2));
46
47 apollo::common::Point3D *obj_acceleration = pb_msg->mutable_acceleration();
48 obj_acceleration->set_x(object_ptr->acceleration(0));
49 obj_acceleration->set_y(object_ptr->acceleration(1));
50 obj_acceleration->set_z(object_ptr->acceleration(2));
51
52 pb_msg->set_length(object_ptr->size(0));
53 pb_msg->set_width(object_ptr->size(1));
54 pb_msg->set_height(object_ptr->size(2));
55
56 for (size_t i = 0; i < object_ptr->polygon.size(); ++i) {
57 auto &pt = object_ptr->polygon.at(i);
58 apollo::common::Point3D *p = pb_msg->add_polygon_point();
59 p->set_x(pt.x);
60 p->set_y(pt.y);
61 p->set_z(pt.z);
62 }
63
64 for (auto &point : object_ptr->lidar_supplement.cloud.points()) {
65 pb_msg->add_point_cloud(point.x);
66 pb_msg->add_point_cloud(point.y);
67 pb_msg->add_point_cloud(point.z);
68 }
69
70 apollo::common::Point3D *obj_anchor_point = pb_msg->mutable_anchor_point();
71 obj_anchor_point->set_x(object_ptr->anchor_point(0));
72 obj_anchor_point->set_y(object_ptr->anchor_point(1));
73 obj_anchor_point->set_z(object_ptr->anchor_point(2));
74
75 BBox2D *obj_bbox2d = pb_msg->mutable_bbox2d();
76 const base::BBox2DF &box = object_ptr->camera_supplement.box;
77 obj_bbox2d->set_xmin(box.xmin);
78 obj_bbox2d->set_ymin(box.ymin);
79 obj_bbox2d->set_xmax(box.xmax);
80 obj_bbox2d->set_ymax(box.ymax);
81
82 for (size_t i = 0; i < 3; i++) {
83 for (size_t j = 0; j < 3; j++) {
84 pb_msg->add_position_covariance(object_ptr->center_uncertainty(i, j));
85 pb_msg->add_velocity_covariance(object_ptr->velocity_uncertainty(i, j));
86 pb_msg->add_acceleration_covariance(
87 object_ptr->acceleration_uncertainty(i, j));
88 }
89 }
90
91 pb_msg->set_tracking_time(object_ptr->tracking_time);
92 pb_msg->set_type(static_cast<PerceptionObstacle::Type>(object_ptr->type));
93 pb_msg->set_sub_type(
94 static_cast<PerceptionObstacle::SubType>(object_ptr->sub_type));
95 pb_msg->set_timestamp(object_ptr->latest_tracked_time); // in seconds.
96 pb_msg->set_semantic_type(static_cast<PerceptionObstacle::SemanticType>(
97 object_ptr->lidar_supplement.semantic_type));
98
99 constexpr float kFloatMax = std::numeric_limits<float>::max();
100 if (object_ptr->lidar_supplement.height_above_ground != kFloatMax) {
101 pb_msg->set_height_above_ground(
102 object_ptr->lidar_supplement.height_above_ground);
103 } else {
104 pb_msg->set_height_above_ground(std::numeric_limits<double>::quiet_NaN());
105 }
106
107 if (object_ptr->type == base::ObjectType::VEHICLE) {
108 LightStatus *light_status = pb_msg->mutable_light_status();
109 const base::CarLight &car_light = object_ptr->car_light;
110 light_status->set_brake_visible(car_light.brake_visible);
111 light_status->set_brake_switch_on(car_light.brake_switch_on);
112
113 light_status->set_left_turn_visible(car_light.left_turn_visible);
114 light_status->set_left_turn_switch_on(car_light.left_turn_switch_on);
115
116 light_status->set_right_turn_visible(car_light.right_turn_visible);
117 light_status->set_right_turn_switch_on(car_light.right_turn_switch_on);
118 }
119
120 if (object_ptr->fusion_supplement.on_use) {
121 for (const auto &measurement : object_ptr->fusion_supplement.measurements) {
122 SensorMeasurement *pb_measurement = pb_msg->add_measurements();
123 pb_measurement->set_sensor_id(measurement.sensor_id);
124 pb_measurement->set_id(measurement.track_id);
125
126 apollo::common::Point3D *pb_position = pb_measurement->mutable_position();
127 pb_position->set_x(measurement.center(0));
128 pb_position->set_y(measurement.center(1));
129 pb_position->set_z(measurement.center(2));
130
131 pb_measurement->set_theta(measurement.theta);
132 pb_measurement->set_length(measurement.size(0));
133 pb_measurement->set_width(measurement.size(1));
134 pb_measurement->set_height(measurement.size(2));
135
136 apollo::common::Point3D *pb_velocity = pb_measurement->mutable_velocity();
137 pb_velocity->set_x(measurement.velocity(0));
138 pb_velocity->set_y(measurement.velocity(1));
139 pb_velocity->set_z(measurement.velocity(2));
140
141 pb_measurement->set_type(
142 static_cast<PerceptionObstacle::Type>(measurement.type));
143 // pb_measurement->set_sub_type();
144 pb_measurement->set_timestamp(measurement.timestamp);
145
146 BBox2D *pb_box = pb_measurement->mutable_box();
147 pb_box->set_xmin(measurement.box.xmin);
148 pb_box->set_ymin(measurement.box.ymin);
149 pb_box->set_xmax(measurement.box.xmax);
150 pb_box->set_ymax(measurement.box.ymax);
151 }
152 }
153
154 return true;
155}
156
157} // namespace perception
158} // namespace apollo
std::shared_ptr< Object > ObjectPtr
Definition object.h:127
bool ConvertObjectToPb(const base::ObjectPtr &object_ptr, PerceptionObstacle *pb_msg)
Definition common.h:28
class register implement
Definition arena_queue.h:37