Apollo 10.0
自动驾驶开放平台
conti_ars_preprocessor.cc
浏览该文件的文档.
1/******************************************************************************
2 * Copyright 2018 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/radar_detection/proto/preprocessor.pb.h"
19
20#include "cyber/common/file.h"
21#include "cyber/common/log.h"
25
26namespace apollo {
27namespace perception {
28namespace radar {
29
30int ContiArsPreprocessor::current_idx_ = 0;
31std::unordered_map<int, int> ContiArsPreprocessor::local2global_;
32
34 std::string config_file =
35 GetConfigFile(options.config_path, options.config_file);
36
37 PreprocessorConfig config;
38 ACHECK(cyber::common::GetProtoFromFile(config_file, &config));
39
40 delay_time_ = config.delay_time();
41 return true;
42}
43
45 const drivers::ContiRadar& raw_obstacles,
46 const PreprocessorOptions& options,
47 drivers::ContiRadar* corrected_obstacles) {
49 SkipObjects(raw_obstacles, corrected_obstacles);
50 ExpandIds(corrected_obstacles);
51 CorrectTime(corrected_obstacles);
52 return true;
53}
54
55void ContiArsPreprocessor::SkipObjects(
56 const drivers::ContiRadar& raw_obstacles,
57 drivers::ContiRadar* corrected_obstacles) {
58 corrected_obstacles->mutable_header()->CopyFrom(raw_obstacles.header());
59 double timestamp = raw_obstacles.header().timestamp_sec() - 1e-6;
60 for (const auto& contiobs : raw_obstacles.contiobs()) {
61 double object_timestamp = contiobs.header().timestamp_sec();
62 if (object_timestamp > timestamp &&
63 object_timestamp < timestamp + CONTI_ARS_INTERVAL) {
64 drivers::ContiRadarObs* obs = corrected_obstacles->add_contiobs();
65 *obs = contiobs;
66 }
67 }
68 if (raw_obstacles.contiobs_size() > corrected_obstacles->contiobs_size()) {
69 AINFO << "skip objects: " << raw_obstacles.contiobs_size() << "-> "
70 << corrected_obstacles->contiobs_size();
71 }
72}
73
74void ContiArsPreprocessor::ExpandIds(drivers::ContiRadar* corrected_obstacles) {
75 for (int iobj = 0; iobj < corrected_obstacles->contiobs_size(); ++iobj) {
76 const auto& contiobs = corrected_obstacles->contiobs(iobj);
77 int id = contiobs.obstacle_id();
78 int corrected_id = 0;
79 auto ob = local2global_.find(id);
80 if (ob != local2global_.end()) {
81 if (CONTI_NEW == contiobs.meas_state()) {
82 corrected_id = GetNextId();
83 ob->second = corrected_id;
84 } else {
85 corrected_id = ob->second;
86 }
87 } else {
88 corrected_id = GetNextId();
89 local2global_.insert({id, corrected_id});
90 }
91 corrected_obstacles->mutable_contiobs(iobj)->set_obstacle_id(corrected_id);
92 }
93}
94
95void ContiArsPreprocessor::CorrectTime(
96 drivers::ContiRadar* corrected_obstacles) {
97 double correct_timestamp =
98 corrected_obstacles->header().timestamp_sec() - delay_time_;
99 corrected_obstacles->mutable_header()->set_timestamp_sec(correct_timestamp);
100}
101
102int ContiArsPreprocessor::GetNextId() {
103 ++current_idx_;
104 if (MAX_RADAR_IDX == current_idx_) {
105 current_idx_ = 1;
106 }
107 return current_idx_;
108}
109
111
112} // namespace radar
113} // namespace perception
114} // namespace apollo
bool Init(const PreprocessorInitOptions &options) override
Init ContiArsPreprocessor config
bool Preprocess(const drivers::ContiRadar &raw_obstacles, const PreprocessorOptions &options, drivers::ContiRadar *corrected_obstacles) override
Correct radar raw obstacles.
#define ACHECK(cond)
Definition log.h:80
#define AINFO
Definition log.h:42
bool GetProtoFromFile(const std::string &file_name, google::protobuf::Message *message)
Parses the content of the file specified by the file_name as a representation of protobufs,...
Definition file.cc:132
const double CONTI_ARS_INTERVAL
Definition types.h:24
const int MAX_RADAR_IDX
Definition types.h:23
std::string GetConfigFile(const std::string &config_path, const std::string &config_file)
Definition util.cc:80
class register implement
Definition arena_queue.h:37
#define PERF_FUNCTION(...)
Definition profiler.h:54
#define PERCEPTION_REGISTER_PREPROCESSOR(name)
optional double timestamp_sec
Definition header.proto:9
optional apollo::common::Header header
repeated ContiRadarObs contiobs