Apollo 11.0
自动驾驶开放平台
eight_route.cc
浏览该文件的文档.
1/******************************************************************************
2 * Copyright 2019 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 <cmath>
19#include <vector>
20
21namespace apollo {
22namespace hdmap {
23
24EightRoute::EightRoute(std::shared_ptr<JsonConf> sp_conf) : Alignment(sp_conf) {
25 Reset();
26}
27
28void EightRoute::Reset() {
29 progress_ = 0.0;
31}
32
33bool EightRoute::IsEightRoutePose(const std::vector<FramePose>& poses,
34 int pose_index) {
35 if (poses.empty() || pose_index <= 0 ||
36 pose_index >= static_cast<int>(poses.size())) {
37 AINFO << "params error, poses size: " << poses.size()
38 << ", pose_index: " << pose_index;
39 return true;
40 }
41
42 double yaw = GetYaw(poses[pose_index - 1].tx, poses[pose_index - 1].ty,
43 poses[pose_index].tx, poses[pose_index].ty);
44 double yaw_diff = fabs(last_yaw_ - yaw);
45 last_yaw_ = yaw;
46 yaw_diff = yaw_diff < 180 ? yaw_diff : 360 - yaw_diff;
47
48 double xdiff = poses[pose_index].tx - poses[pose_index - 1].tx;
49 double ydiff = poses[pose_index].ty - poses[pose_index - 1].ty;
50 double zdiff = poses[pose_index].tz - poses[pose_index - 1].tz;
51 double dist = std::sqrt(xdiff * xdiff + ydiff * ydiff + zdiff * zdiff);
52 double during =
53 poses[pose_index].time_stamp - poses[pose_index - 1].time_stamp;
54 if (during < 0) {
55 AINFO << "skip back pose is bad pose";
56 return false;
57 }
58 double vel = dist / during;
59 AINFO << poses[pose_index].time_stamp << ", yaw_diff:" << yaw_diff
60 << ", dist: " << dist << ", during: " << during << ", vel: " << vel;
61 if (yaw_diff > sp_conf_->eight_angle && vel > sp_conf_->eight_vel) {
62 return true;
63 }
64 return false;
65}
66
67double EightRoute::GetGoodPoseDuring() {
68 if (sp_good_pose_info_ == nullptr || sp_good_pose_info_->start_time < 0 ||
69 sp_good_pose_info_->end_time < 0) {
70 return 0.0;
71 }
72 return sp_good_pose_info_->end_time - sp_good_pose_info_->start_time;
73}
74
75double EightRoute::GetEightRouteProgress(const std::vector<FramePose>& poses) {
76 int size = static_cast<int>(poses.size());
77 int start_index = TimeToIndex(poses, start_time_);
78 // select first good pose
79 while (start_index < size) {
80 if (IsGoodPose(poses, start_index) &&
81 IsEightRoutePose(poses, start_index)) {
82 AINFO << "find first good pose.index:" << start_index;
83 break;
84 }
85 ++start_index;
86 }
87 if (start_index >= size) {
88 AINFO << "not find first good pose, start_time: " << start_time_
89 << ", start_index: " << start_index << ", pose size: " << size;
90 return 0.0;
91 }
92 if (start_index + 1 >= size) {
93 AINFO << "not have enough poses, wait for a moment";
94 return 0.0;
95 }
96 last_yaw_ = GetYaw(poses[start_index].tx, poses[start_index].ty,
97 poses[start_index + 1].tx, poses[start_index + 1].ty);
98
99 int not_eight_count = 0;
100 for (int i = start_index + 2; i < size; ++i) {
101 if (!IsGoodPose(poses, i)) {
102 AINFO << "not good pose";
103 return 0.0;
104 }
105 if (!IsEightRoutePose(poses, i)) {
106 ++not_eight_count;
107 AINFO << "not eight route pose";
108 if (not_eight_count > sp_conf_->eight_bad_pose_tolerance) {
109 AINFO << "not-eight pose count reached upper limitation";
111 return 0.0;
112 }
113 } else {
114 not_eight_count = 0;
115 }
116 AINFO << "good pose";
117 UpdateGoodPoseInfo(poses[i]);
118 // ClearBadPoseInfo();
119 }
120 double eight_route_during = GetGoodPoseDuring();
121 if (eight_route_during < 1e-8) {
122 AINFO << "num of eight route good pose too small, during: "
123 << eight_route_during;
125 return 0.0;
126 }
128 double progress = eight_route_during / sp_conf_->eight_duration;
129 if (progress >= 1.0) {
130 progress = 1.0;
131 }
133 return progress;
134}
135
136ErrorCode EightRoute::Process(const std::vector<FramePose>& poses) {
137 AINFO << "[EightRoute::process] begin";
138 size_t size = poses.size();
139 if (size <= 1) {
141 return return_state_;
142 }
143
144 progress_ = GetEightRouteProgress(poses);
146 AINFO << "get_eight_route_progress failed.";
147 return return_state_;
148 }
149 if (progress_ < last_progress_) {
151 return return_state_;
152 }
153
154 AINFO << "[EightRoute::process] end, progress:" << progress_;
156 return return_state_;
157}
158
159double EightRoute::GetProgress() const { return progress_; }
160
161} // namespace hdmap
162} // namespace apollo
std::shared_ptr< JsonConf > sp_conf_
Definition alignment.h:141
virtual void ClearGoodPoseInfo()
Definition alignment.h:62
int TimeToIndex(const std::vector< FramePose > &poses, double time)
Definition alignment.h:119
virtual bool IsGoodPose(const std::vector< FramePose > &poses, int pose_index)
Definition alignment.h:64
std::shared_ptr< BadOrGoodPoseInfo > sp_good_pose_info_
Definition alignment.h:143
virtual void UpdateGoodPoseInfo(const FramePose &pose)
Definition alignment.h:58
EightRoute(std::shared_ptr< JsonConf > sp_conf)
ErrorCode Process(const std::vector< FramePose > &poses)
#define AINFO
Definition log.h:42
double GetYaw(double from_x, double from_y, double to_x, double to_y)
Definition common.h:111
class register implement
Definition arena_queue.h:37