Apollo 11.0
自动驾驶开放平台
barrier_status_tracker.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 *****************************************************************************/
16#include <cstdlib>
17
18#include "cyber/common/file.h"
19#include "cyber/common/log.h"
20
22#include "modules/perception/barrier_recognition/tracker/proto/barrier_tracker_config.pb.h"
25
26
27namespace apollo {
28namespace perception {
29namespace lidar {
30
32 std::string config_file = GetConfigFile(options.config_path, options.config_file);
33
35 ACHECK(cyber::common::GetProtoFromFile(config_file, &config));
36
37 s_tracking_time_win_ = config.tracking_time_window();
38 status_change_threshold_ = config.status_change_threshold();
39 open_threshold_ = config.open_threshold();
40 close_threshold_ = config.close_threshold();
41 return true;
42}
43
44bool BarrierStatusTracker::Track(double timestamp, const float open_percent, int& status_id) {
45 if (first_timestamp_ < 1e-3) {
46 first_timestamp_ = timestamp;
47 }
48 double relative_timestamp = timestamp - first_timestamp_;
49 while (!prev_status_.empty() &&
50 relative_timestamp - prev_status_.front().first > s_tracking_time_win_) {
51 prev_status_.pop_front();
52 }
53 prev_status_.push_back(std::make_pair(relative_timestamp, open_percent));
54 float theta = 0.;
55 // check cached status
56 if (prev_status_.size() == 1) {
57 AINFO << "No cached open_percent status, return unkown.";
58 status_id = 0;
59 } else if (open_percent < close_threshold_) {
60 status_id = 1;
61 } else {
62 std::vector<float> status_samples(static_cast<int>(prev_status_.size() * 2), 0);
63 for (size_t i = 0; i < prev_status_.size(); i++) {
64 auto& status = prev_status_.at(i);
65 status_samples[i*2] = status.first;
66 status_samples[i*2+1] = status.second;
67 }
68
69 float fit_line[3] = {0};
70 algorithm::ILineFit2dTotalLeastSquare(status_samples.data(),
71 fit_line,
72 prev_status_.size());
73 theta = std::atan(-fit_line[0] / (fit_line[1] + 1e-6)); // -PI/2 ~ PI/2
74
75 if (std::abs(theta) < status_change_threshold_) {
76 if (open_percent > open_threshold_) {
77 status_id = 3;
78 } else if (open_percent < close_threshold_) {
79 status_id = 1;
80 } else {
81 status_id = 0;
82 }
83 } else if (theta > 0.) {
84 status_id = 4;
85 } else {
86 status_id = 2;
87 }
88 }
89
90 return true;
91}
92
93} // namespace lidar
94} // namespace perception
95} // namespace apollo
bool Track(double timestamp, const float open_percent, int &status_id)
Tracking status.
bool Init(const StatusTrackerInitOptions &options=StatusTrackerInitOptions())
Init BarrierStatusTracker config
#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
void ILineFit2dTotalLeastSquare(T *x, T *l, int n)
Definition i_line.h:36
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