Apollo 11.0
自动驾驶开放平台
v2x_fusion_component.cc
浏览该文件的文档.
1/******************************************************************************
2 * Copyright 2020 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
18
19namespace apollo {
20namespace v2x {
21namespace ft {
22
24
25std::string V2XFusionComponent::Name() const { return FLAGS_v2x_module_name; }
26
28 v2x_obstacles_reader_ =
29 node_->CreateReader<V2XObstacles>(FLAGS_v2x_obstacle_topic, nullptr);
30 localization_reader_ = node_->CreateReader<LocalizationEstimate>(
31 FLAGS_localization_topic, nullptr);
32 perception_fusion_obstacles_writer_ =
33 node_->CreateWriter<PerceptionObstacles>(FLAGS_perception_obstacle_topic);
34 return true;
35}
36
38 const std::shared_ptr<PerceptionObstacles>& perception_obstacles) {
39 if (FLAGS_use_v2x) {
40 return V2XMessageFusionProcess(perception_obstacles);
41 }
42 perception_fusion_obstacles_writer_->Write(*perception_obstacles);
43 return true;
44}
45
46bool V2XFusionComponent::V2XMessageFusionProcess(
47 const std::shared_ptr<PerceptionObstacles>& perception_obstacles) {
48 // Read localization info. and call OnLocalization to update
49 // the PoseContainer.
50 localization_reader_->Observe();
51 auto localization_msg = localization_reader_->GetLatestObserved();
52 if (localization_msg == nullptr) {
53 AERROR << "V2X: cannot receive any localization message.";
54 return false;
55 }
56 base::Object hv_obj;
57 CarstatusPb2Object(*localization_msg, &hv_obj, "VEHICLE");
58 v2x_obstacles_reader_->Observe();
59 auto v2x_obstacles_msg = v2x_obstacles_reader_->GetLatestObserved();
60 if (v2x_obstacles_msg == nullptr) {
61 AERROR << "V2X: cannot receive any v2x obstacles message.";
62 perception_fusion_obstacles_writer_->Write(*perception_obstacles);
63 } else {
64 header_.CopyFrom(perception_obstacles->header());
65 std::vector<Object> fused_objects;
66 std::vector<Object> v2x_fused_objects;
67 std::vector<std::vector<Object>> fusion_result;
68 std::vector<Object> v2x_objects;
69 V2xPbs2Objects(*v2x_obstacles_msg, &v2x_objects, "V2X");
70 std::vector<Object> perception_objects;
71 Pbs2Objects(*perception_obstacles, &perception_objects, "VEHICLE");
72 perception_objects.push_back(hv_obj);
73 fusion_.CombineNewResource(perception_objects, &fused_objects,
74 &fusion_result);
75 fusion_.CombineNewResource(v2x_objects, &fused_objects, &fusion_result);
76 fusion_.GetV2xFusionObjects(fusion_result, &v2x_fused_objects);
77 auto output_msg = std::make_shared<PerceptionObstacles>();
78 SerializeMsg(v2x_fused_objects, output_msg);
79 perception_fusion_obstacles_writer_->Write(*output_msg);
80 }
81 return true;
82}
83
84void V2XFusionComponent::SerializeMsg(
85 const std::vector<base::Object>& objects,
86 std::shared_ptr<PerceptionObstacles> output_msg) {
87 static int seq_num = 0;
88 Objects2Pbs(objects, output_msg);
89 apollo::common::Header* header = output_msg->mutable_header();
90 header->set_timestamp_sec(apollo::cyber::Time::Now().ToSecond());
91 header->set_module_name("v2x_fusion");
92 header->set_sequence_num(seq_num++);
93 header->set_lidar_timestamp(header_.lidar_timestamp());
94 header->set_camera_timestamp(header_.camera_timestamp());
95 header->set_radar_timestamp(header_.radar_timestamp());
96 output_msg->set_error_code(apollo::common::ErrorCode::PERCEPTION_ERROR_NONE);
97}
98
99} // namespace ft
100} // namespace v2x
101} // namespace apollo
std::shared_ptr< Node > node_
static Time Now()
get the current time.
Definition time.cc:57
bool CombineNewResource(const std::vector< base::Object > &new_objects, std::vector< base::Object > *fused_objects, std::vector< std::vector< base::Object > > *fusion_result)
Definition fusion.cc:68
bool GetV2xFusionObjects(const std::vector< std::vector< base::Object > > &fusion_result, std::vector< base::Object > *fused_objects)
Definition fusion.cc:109
bool Proc(const std::shared_ptr< PerceptionObstacles > &perception_obstacles) override
#define AERROR
Definition log.h:44
double V2xPbs2Objects(const V2XObstacles &obstacles, std::vector< base::Object > *objects, const std::string &frame_id)
void CarstatusPb2Object(const LocalizationEstimate &carstatus, base::Object *object, const std::string &frame_id)
void Objects2Pbs(const std::vector< base::Object > &objects, std::shared_ptr< PerceptionObstacles > obstacles)
double Pbs2Objects(const PerceptionObstacles &obstacles, std::vector< base::Object > *objects, const std::string &frame_id)
class register implement
Definition arena_queue.h:37
optional uint64 camera_timestamp
Definition header.proto:22
optional uint64 lidar_timestamp
Definition header.proto:19
optional uint64 radar_timestamp
Definition header.proto:25