Apollo 11.0
自动驾驶开放平台
lidar_tracking_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
20#include "cyber/time/clock.h"
21
22namespace apollo {
23namespace perception {
24namespace lidar {
25
27
30 if (!GetProtoConfig(&comp_config)) {
31 AERROR << "Get LidarTrackingComponentConfig file failed";
32 return false;
33 }
34 AINFO << "Lidar Tracking Component Configs: " << comp_config.DebugString();
35
36 // writer
37 std::string output_channel_name = comp_config.output_channel_name();
38 writer_ = node_->CreateWriter<SensorFrameMessage>(output_channel_name);
39
40 // multi target tracking init
41 auto multi_target_tracker_param = comp_config.multi_target_tracker_param();
42 std::string multi_target_tracker_name = multi_target_tracker_param.name();
43 multi_target_tracker_ = BaseMultiTargetTrackerRegisterer::GetInstanceByName(
44 multi_target_tracker_name);
45 CHECK_NOTNULL(multi_target_tracker_);
46
47 MultiTargetTrackerInitOptions tracker_init_options;
48 tracker_init_options.config_path = multi_target_tracker_param.config_path();
49 tracker_init_options.config_file = multi_target_tracker_param.config_file();
50 ACHECK(multi_target_tracker_->Init(tracker_init_options));
51
52 // // fused classifier init
53 // auto fusion_classifier_param = comp_config.fusion_classifier_param();
54 // std::string fusion_classifier_name = fusion_classifier_param.name();
55 // fusion_classifier_ =
56 // BaseClassifierRegisterer::GetInstanceByName(fusion_classifier_name);
57 // CHECK_NOTNULL(fusion_classifier_);
58
59 // ClassifierInitOptions fusion_classifier_init_options;
60 // fusion_classifier_init_options.config_path =
61 // fusion_classifier_param.config_path();
62 // fusion_classifier_init_options.config_file =
63 // fusion_classifier_param.config_file();
64 // ACHECK(fusion_classifier_->Init(fusion_classifier_init_options));
65 return true;
66}
67
69 const std::shared_ptr<LidarFrameMessage>& message) {
71 AINFO << std::setprecision(16)
72 << "Enter LidarTracking component, message timestamp: "
73 << message->timestamp_
74 << " current timestamp: " << Clock::NowInSeconds();
75
76 auto out_message = std::make_shared<SensorFrameMessage>();
77
78 if (InternalProc(message, out_message)) {
79 writer_->Write(out_message);
80 return true;
81 }
82
83 AERROR << "Send lidar tracking output message failed!";
84 return false;
85}
86
87bool LidarTrackingComponent::InternalProc(
88 const std::shared_ptr<const LidarFrameMessage>& in_message,
89 const std::shared_ptr<SensorFrameMessage>& out_message) {
90 out_message->timestamp_ = in_message->timestamp_;
91 out_message->lidar_timestamp_ = in_message->lidar_timestamp_;
92 out_message->seq_num_ = in_message->seq_num_;
93 out_message->process_stage_ = onboard::ProcessStage::LIDAR_RECOGNITION;
94 out_message->sensor_id_ = in_message->lidar_frame_->sensor_info.name;
95
96 if (in_message->error_code_ != apollo::common::ErrorCode::OK) {
97 out_message->error_code_ = in_message->error_code_;
98 AERROR << "Lidar tracking receive message with error code, skip it.";
99 return true;
100 }
101
102 auto& lidar_frame = in_message->lidar_frame_;
103 // multi target tracker
104 PERF_BLOCK("multi_target_tracker")
105 MultiTargetTrackerOptions tracker_options;
106 if (!multi_target_tracker_->Track(tracker_options, lidar_frame.get())) {
107 AINFO << "Lidar tracking, multi_target_tracker_ Track error.";
108 return false;
109 }
111
112 // // fused classifer
113 // PERF_BLOCK("fusion_classifier")
114 // ClassifierOptions fusion_classifier_options;
115 // if (!fusion_classifier_->Classify(fusion_classifier_options,
116 // lidar_frame.get())) {
117 // AERROR << "Lidar tracking, fusion_classifier_ Classify error.";
118 // return false;
119 // }
120 // PERF_BLOCK_END
121
122 // get out_message
123 out_message->hdmap_ = lidar_frame->hdmap_struct;
124 auto& frame = out_message->frame_;
125 frame = base::FramePool::Instance().Get();
126 frame->sensor_info = lidar_frame->sensor_info;
127 frame->timestamp = in_message->timestamp_;
128 frame->objects = lidar_frame->tracked_objects;
129 frame->sensor2world_pose = lidar_frame->lidar2world_pose;
130 frame->lidar_frame_supplement.on_use = true;
131 frame->lidar_frame_supplement.cloud_ptr = lidar_frame->cloud;
132
133 const double end_timestamp = Clock::NowInSeconds();
134 const double end_latency = (end_timestamp - in_message->timestamp_) * 1e3;
135 AINFO << std::setprecision(16)
136 << "FRAME_STATISTICS:LidarTracking:End:msg_time["
137 << in_message->timestamp_ << "]:cur_time[" << end_timestamp
138 << "]:cur_latency[" << end_latency << "]";
139
140 return true;
141}
142
143} // namespace lidar
144} // namespace perception
145} // namespace apollo
a singleton clock that can be used to get the current timestamp.
Definition clock.h:39
static double NowInSeconds()
gets the current time in second.
Definition clock.cc:56
bool GetProtoConfig(T *config) const
std::shared_ptr< Node > node_
virtual bool Init(const MultiTargetTrackerInitOptions &options=MultiTargetTrackerInitOptions())=0
Init multi target tarcker
bool Proc(const std::shared_ptr< LidarFrameMessage > &message) override
Data callback upon receiving a LidarFrameMessage.
#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