Apollo 11.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
44bool TrafficLightDetectComponent::Proc(const std::shared_ptr<TrafficDetectMessage>& message) {
46 auto time_imags = std::to_string(message->timestamp_);
47 AINFO << "Enter detection component, message timestamp: " << time_imags;
48
49 bool status = InternalProc(message);
50 if (status) {
51 writer_->Write(message);
52 AINFO << "Send trafficlight detect output message.";
53 }
54 return status;
55}
56
57int TrafficLightDetectComponent::InitConfig() {
59 if (!GetProtoConfig(&traffic_light_param)) {
60 AINFO << "load trafficlights detection component proto param failed";
61 return cyber::FAIL;
62 }
63
64 auto plugin_param = traffic_light_param.plugin_param();
65 tl_detector_name_ = plugin_param.name();
66 config_path_ = plugin_param.config_path();
67 config_file_ = plugin_param.config_file();
68
69 gpu_id_ = traffic_light_param.gpu_id();
70 AINFO << "tl_detector_name: " << tl_detector_name_ << " config_path: " << config_path_
71 << " config_file: " << config_file_ << " gpu_id: " << gpu_id_;
72
73 writer_ = node_->CreateWriter<TrafficDetectMessage>(traffic_light_param.detection_output_channel_name());
74
75 return cyber::SUCC;
76}
77
78bool TrafficLightDetectComponent::InitAlgorithmPlugin() {
79 trafficlight::BaseTrafficLightDetector* detector
80 = trafficlight::BaseTrafficLightDetectorRegisterer::GetInstanceByName(tl_detector_name_);
81 CHECK_NOTNULL(detector);
82 detector_.reset(detector);
83 ACHECK(detector_ != nullptr);
84 detector_init_options_.gpu_id = gpu_id_;
85 detector_init_options_.config_path = config_path_;
86 detector_init_options_.config_file = config_file_;
87
88 if (!detector_->Init(detector_init_options_)) {
89 AERROR << "Trafficlight detector init failed";
90 return false;
91 }
92
93 return cyber::SUCC;
94}
95
96bool TrafficLightDetectComponent::InternalProc(const std::shared_ptr<TrafficDetectMessage const>& message) {
97 PERF_BLOCK("traffic_light_detector")
98 bool status = detector_->Detect(message->traffic_light_frame_.get());
100
101 return true;
102}
103
104} // namespace trafficlight
105} // namespace perception
106} // 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