Apollo 10.0
自动驾驶开放平台
static_align.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 <vector>
19
20namespace apollo {
21namespace hdmap {
22
23StaticAlign::StaticAlign(std::shared_ptr<JsonConf> sp_conf)
24 : Alignment(sp_conf) {
25 sp_conf_ = sp_conf;
26 static_align_detect_method_ = StaticAlignDetectMethod::DYNAMIC_CENTROID;
27 Reset();
28}
29
30void StaticAlign::Reset() {
31 progress_ = 0.0;
32 last_progress_ = 0.0;
33 start_time_ = -1.0;
34 end_time_ = -1.0;
35 start_index_ = -1;
36 end_index_ = -1;
37 sp_bad_pose_info_ = std::make_shared<BadOrGoodPoseInfo>();
38 sp_good_pose_info_ = std::make_shared<BadOrGoodPoseInfo>();
39 dynamic_centroid_ = Centroid3D();
40}
41
42bool StaticAlign::IsStaticPose(const FramePose& pose) {
43 if (dynamic_centroid_.count == 0) {
44 return true;
45 }
46 double move_dist_x = pose.tx - dynamic_centroid_.center.x;
47 double move_dist_y = pose.ty - dynamic_centroid_.center.y;
48 double move_dist_z = pose.tz - dynamic_centroid_.center.z;
49 double move_dist =
50 std::sqrt(move_dist_x * move_dist_x + move_dist_y * move_dist_y +
51 move_dist_z * move_dist_z);
52 AINFO << "dist thresh: " << sp_conf_->static_align_dist_thresh
53 << ", dist: " << move_dist;
54 if (move_dist <= sp_conf_->static_align_dist_thresh) {
55 return true;
56 }
57 return false;
58}
59
60void StaticAlign::UpdateDynamicCentroid(const FramePose& pose) {
61 int count = dynamic_centroid_.count;
62 if (count == 0) {
63 dynamic_centroid_.start_time = pose.time_stamp;
64 } else {
65 dynamic_centroid_.end_time = pose.time_stamp;
66 }
67 AINFO << "cetroid start: " << dynamic_centroid_.start_time
68 << ", end: " << dynamic_centroid_.end_time;
69
70 double x = dynamic_centroid_.center.x * count + pose.tx;
71 double y = dynamic_centroid_.center.y * count + pose.ty;
72 double z = dynamic_centroid_.center.z * count + pose.tz;
73 ++count;
74
75 dynamic_centroid_.count = count;
76 dynamic_centroid_.center.x = x / count;
77 dynamic_centroid_.center.y = y / count;
78 dynamic_centroid_.center.z = z / count;
79}
80
81double StaticAlign::GetCentroidTimeDuring() {
82 if (dynamic_centroid_.start_time > 0 && dynamic_centroid_.end_time > 0) {
83 return dynamic_centroid_.end_time - dynamic_centroid_.start_time;
84 }
85 return 0.0;
86}
87
88void StaticAlign::UpdateGoodPoseInfo(const FramePose& pose) {
89 UpdateDynamicCentroid(pose);
90}
91
92double StaticAlign::StaticAlignDynamicCentroid(
93 const std::vector<FramePose>& poses) {
94 int start_index = TimeToIndex(poses, start_time_);
95 AINFO << "start_index:" << start_index << ",pose size:" << poses.size();
96 dynamic_centroid_ = Centroid3D();
97 for (int i = start_index + 1; i < static_cast<int>(poses.size()); ++i) {
98 if (!IsGoodPose(poses, i)) {
99 AINFO << "not good pose";
101 return 0.0;
102 }
103 if (!IsStaticPose(poses[i])) {
104 AINFO << "not static pose";
106 return 0.0;
107 }
108 UpdateGoodPoseInfo(poses[i]);
110 }
111
112 double progress = GetCentroidTimeDuring() / sp_conf_->static_align_duration;
113 if (progress > 1.0) {
114 progress = 1.0;
115 }
116 return progress;
117}
118
119double StaticAlign::StaticAlignRansac(const std::vector<FramePose>& poses) {
120 // TODO(yuanyijun): implementation of selecting an center by RANSAC
121 return 0.0;
122}
123
124double StaticAlign::GetStaticAlignProgress(
125 const std::vector<FramePose>& poses) {
126 double progress = 0.0;
127 switch (static_align_detect_method_) {
129 progress = StaticAlignDynamicCentroid(poses);
130 break;
132 progress = StaticAlignRansac(poses);
133 break;
134 default:
135 break;
136 }
138 return progress;
139}
140
141ErrorCode StaticAlign::Process(const std::vector<FramePose>& poses) {
142 AINFO << "[StaticAlign::process] begin";
143 size_t size = poses.size();
144 if (size <= 1) {
145 AINFO << "system has no pose, exit process";
147 return return_state_;
148 }
149
150 progress_ = GetStaticAlignProgress(poses);
152 AINFO << "get_static_align_progress error, progress 0.0";
153 return return_state_;
154 }
155
156 AINFO << "[StaticAlign::process] end, progress:" << progress_;
158 return return_state_;
159}
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
std::shared_ptr< BadOrGoodPoseInfo > sp_bad_pose_info_
Definition alignment.h:144
StaticAlign(std::shared_ptr< JsonConf > sp_conf)
ErrorCode Process(const std::vector< FramePose > &poses)
#define AINFO
Definition log.h:42
struct apollo::hdmap::Centroid3D Centroid3D
class register implement
Definition arena_queue.h:37