Apollo 10.0
自动驾驶开放平台
traffic_light_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 *****************************************************************************/
17
18#include "modules/perception/traffic_light_detection/proto/traffic_light_detection_component.pb.h"
19
21#include "cyber/time/clock.h"
24
25namespace apollo {
26namespace perception {
27namespace trafficlight {
28
30 // init component config
31 if (InitConfig() != cyber::SUCC) {
32 AERROR << "TrafficLightDetectComponent InitConfig failed.";
33 return false;
34 }
35 // init algorithm plugin
36 if (InitAlgorithmPlugin() != cyber::SUCC) {
37 AERROR << "TrafficLightDetectComponent InitAlgorithmPlugin failed.";
38 return false;
39 }
40
41 return true;
42}
43
45 const std::shared_ptr<TrafficDetectMessage>& message) {
47 auto time_imags = std::to_string(message->timestamp_);
48 AINFO << "Enter detection component, message timestamp: " << time_imags;
49
50 bool status = InternalProc(message);
51 if (status) {
52 writer_->Write(message);
53 AINFO << "Send trafficlight detect output message.";
54 }
55 return status;
56}
57
58int TrafficLightDetectComponent::InitConfig() {
60 if (!GetProtoConfig(&traffic_light_param)) {
61 AINFO << "load trafficlights detection component proto param failed";
62 return cyber::FAIL;
63 }
64
65 auto plugin_param = traffic_light_param.plugin_param();
66 tl_detector_name_ = plugin_param.name();
67 config_path_ = plugin_param.config_path();
68 config_file_ = plugin_param.config_file();
69
70 gpu_id_ = traffic_light_param.gpu_id();
71 AINFO << "tl_detector_name: " << tl_detector_name_
72 << " config_path: " << config_path_ << " config_file: " << config_file_
73 << " gpu_id: " << gpu_id_;
74
75 writer_ = node_->CreateWriter<TrafficDetectMessage>(
76 traffic_light_param.detection_output_channel_name());
77
78 return cyber::SUCC;
79}
80
81bool TrafficLightDetectComponent::InitAlgorithmPlugin() {
82 trafficlight::BaseTrafficLightDetector* detector =
83 trafficlight::BaseTrafficLightDetectorRegisterer::GetInstanceByName(
84 tl_detector_name_);
85 CHECK_NOTNULL(detector);
86 detector_.reset(detector);
87 ACHECK(detector_ != nullptr);
88 detector_init_options_.gpu_id = gpu_id_;
89 detector_init_options_.config_path = config_path_;
90 detector_init_options_.config_file = config_file_;
91
92 if (!detector_->Init(detector_init_options_)) {
93 AERROR << "Trafficlight detector init failed";
94 return false;
95 }
96
97 return cyber::SUCC;
98}
99
100bool TrafficLightDetectComponent::InternalProc(
101 const std::shared_ptr<TrafficDetectMessage const>& message) {
102 PERF_BLOCK("traffic_light_detector")
103 bool status = detector_->Detect(message->traffic_light_frame_.get());
105
106 return true;
107}
108
109} // namespace trafficlight
110} // namespace perception
111} // namespace apollo
bool GetProtoConfig(T *config) const
std::shared_ptr< Node > node_
bool Proc(const std::shared_ptr< TrafficDetectMessage > &message) override
Trigger the detection process based on the traffic detect message.
bool Init() override
Initialize configuration files, algorithm plug-ins.
#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