Apollo 11.0
自动驾驶开放平台
lidar_detection_component.cc
浏览该文件的文档.
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
18
19#include "cyber/common/log.h"
21
22namespace apollo {
23namespace perception {
24namespace lidar {
25
28 if (!GetProtoConfig(&comp_config)) {
29 AERROR << "Get LidarDetectionComponentConfig file failed";
30 return false;
31 }
32 AINFO << "Lidar Detection Component Configs: " << comp_config.DebugString();
33
34 sensor_name_ = comp_config.sensor_name();
35 // writer
36 output_channel_name_ = comp_config.output_channel_name();
37 writer_ =
38 node_->CreateWriter<onboard::LidarFrameMessage>(output_channel_name_);
39
40 use_object_builder_ = comp_config.use_object_builder();
41
42 // detector init
43 auto plugin_param = comp_config.plugin_param();
44 std::string detector_name = plugin_param.name();
45 BaseLidarDetector* detector =
46 BaseLidarDetectorRegisterer::GetInstanceByName(detector_name);
47 CHECK_NOTNULL(detector);
48 detector_.reset(detector);
49
50 LidarDetectorInitOptions detection_init_options;
51 detection_init_options.sensor_name = sensor_name_;
52 detection_init_options.config_path = plugin_param.config_path();
53 detection_init_options.config_file = plugin_param.config_file();
54 ACHECK(detector_->Init(detection_init_options))
55 << "lidar detector init error";
56
57 // TODO(zero): Fix paddle doesn't output log to file
58 FLAGS_logtostderr = 0;
59
60 // object builder init
61 if (use_object_builder_) {
62 ObjectBuilderInitOptions builder_init_options;
63 ACHECK(builder_.Init(builder_init_options));
64 }
65
66 AINFO << "Successfully init lidar detection component.";
67 return true;
68}
69
71 const std::shared_ptr<LidarFrameMessage>& message) {
73 // internal proc
74 bool status = InternalProc(message);
75 if (status) {
76 writer_->Write(message);
77 AINFO << "Send Lidar detection output message.";
78 }
79 return status;
80}
81
82bool LidarDetectionComponent::InternalProc(
83 const std::shared_ptr<LidarFrameMessage>& in_message) {
84 // detector
85 PERF_BLOCK("lidar_detector")
86 LidarDetectorOptions detection_options;
87 if (!detector_->Detect(detection_options, in_message->lidar_frame_.get())) {
88 AERROR << "Lidar detector detect error!";
89 return false;
90 }
92
93 // object builder
94 PERF_BLOCK("object_builder")
95 if (use_object_builder_) {
96 ObjectBuilderOptions builder_options;
97 if (!builder_.Build(builder_options, in_message->lidar_frame_.get())) {
98 AERROR << "Lidar detector, object builder error.";
99 return false;
100 }
101 }
103
104 return true;
105}
106
107} // namespace lidar
108} // namespace perception
109} // namespace apollo
bool GetProtoConfig(T *config) const
std::shared_ptr< Node > node_
bool Init() override
Init the Lidar Detection Component object
bool Proc(const std::shared_ptr< LidarFrameMessage > &message) override
Detect foreground obejcts using lidar detction models
bool Init(const ObjectBuilderInitOptions &options=ObjectBuilderInitOptions())
Init the Object Builder object with initialization options
bool Build(const ObjectBuilderOptions &options, LidarFrame *frame)
Calculate and fill object size, center, directions.
#define ACHECK(cond)
Definition log.h:80
#define AERROR
Definition log.h:44
#define AINFO
Definition log.h:42
class register implement
Definition arena_queue.h:37
#define PERF_FUNCTION(...)
Definition profiler.h:54
#define PERF_BLOCK_END
Definition profiler.h:53
#define PERF_BLOCK(...)
Definition profiler.h:52