Apollo  6.0
Open source self driving car software
alignment.h
Go to the documentation of this file.
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  *****************************************************************************/
16 #pragma once
17 
18 #include <memory>
19 #include <vector>
20 
21 #include "modules/map/tools/map_datachecker/proto/collection_error_code.pb.h"
23 
24 namespace apollo {
25 namespace hdmap {
26 
27 typedef struct BadOrGoodPoseInfo {
29  double start_time;
30  double end_time;
33 
34 class Alignment {
35  public:
36  explicit Alignment(std::shared_ptr<JsonConf> sp_conf)
37  : return_state_(ErrorCode::SUCCESS),
38  sp_conf_(sp_conf),
39  sp_good_pose_info_(std::make_shared<BadOrGoodPoseInfo>()),
40  sp_bad_pose_info_(std::make_shared<BadOrGoodPoseInfo>()) {}
41 
42  virtual ~Alignment() {}
43  virtual ErrorCode Process(const std::vector<FramePose>& poses) = 0;
44  virtual void Reset() = 0;
45 
46  virtual double GetProgress() const { return progress_; }
47 
48  virtual void SetStartTime(double start_time) { start_time_ = start_time; }
49 
50  virtual void SetEndTime(double end_time) { end_time_ = end_time; }
51 
52  virtual void UpdateBadPoseInfo(const FramePose& pose) {
53  UpdatePoseInfo(pose, sp_bad_pose_info_);
54  }
55 
56  virtual void ClearBadPoseInfo() { ClearPoseInfo(sp_bad_pose_info_); }
57 
58  virtual void UpdateGoodPoseInfo(const FramePose& pose) {
59  UpdatePoseInfo(pose, sp_good_pose_info_);
60  }
61 
62  virtual void ClearGoodPoseInfo() { ClearPoseInfo(sp_good_pose_info_); }
63 
64  virtual bool IsGoodPose(const std::vector<FramePose>& poses, int pose_index) {
65  if (pose_index <= 0 || pose_index >= static_cast<int>(poses.size())) {
66  AINFO << "params error. poses size:" << poses.size()
67  << ",pose_index:" << pose_index;
68  return false;
69  }
70 
71  unsigned int position_type = poses[pose_index].position_type;
72  float diff_age = poses[pose_index].diff_age;
73  double local_std = poses[pose_index].local_std;
74 
75  if (sp_conf_->position_type_range.find(position_type) !=
76  sp_conf_->position_type_range.end() &&
77  diff_age >= sp_conf_->diff_age_range.first &&
78  diff_age <= sp_conf_->diff_age_range.second &&
79  local_std <= sp_conf_->local_std_upper_limit) {
80  return true;
81  }
82  return false;
83  }
84 
85  ErrorCode GetReturnState() const { return return_state_; }
86 
87  protected:
88  void UpdatePoseInfo(const FramePose& pose,
89  std::shared_ptr<BadOrGoodPoseInfo> sp_pose_info) {
90  if (sp_pose_info == nullptr) {
91  AERROR << "sp_pose_info is nullptr";
92  return;
93  }
94  BadOrGoodPoseInfo& pose_info = *sp_pose_info;
95  if (pose_info.pose_count == 0) {
96  pose_info.start_time = pose.time_stamp;
97  ++pose_info.pose_count;
98  AINFO << "update start time: " << pose_info.start_time
99  << ",pose count: " << pose_info.pose_count;
100  } else {
101  pose_info.end_time = pose.time_stamp;
102  ++pose_info.pose_count;
103  AINFO << "update start time: " << pose_info.start_time
104  << ",pose count: " << pose_info.pose_count;
105  }
106  }
107 
108  void ClearPoseInfo(std::shared_ptr<BadOrGoodPoseInfo> sp_pose_info) {
109  if (sp_pose_info == nullptr) {
110  AERROR << "sp_pose_info is nullptr";
111  return;
112  }
113  BadOrGoodPoseInfo& pose_info = *sp_pose_info;
114  pose_info.start_time = -1.0;
115  pose_info.end_time = -1.0;
116  pose_info.pose_count = 0;
117  }
118 
119  int TimeToIndex(const std::vector<FramePose>& poses, double time) {
120  size_t size = poses.size();
121  if (size == 0 || time <= 0) {
122  return -1;
123  }
124 
125  for (size_t i = 0; i < size; ++i) {
126  if (poses[i].time_stamp >= time) {
127  return static_cast<int>(i);
128  }
129  }
130  return static_cast<int>(size);
131  }
132 
133  protected:
134  double progress_;
136  double start_time_;
137  double end_time_;
139  double end_index_;
140  ErrorCode return_state_;
141  std::shared_ptr<JsonConf> sp_conf_ = nullptr;
142  // BadOrGoodPoseInfo _bad_pose_info, _good_pose_info;
143  std::shared_ptr<BadOrGoodPoseInfo> sp_good_pose_info_ = nullptr;
144  std::shared_ptr<BadOrGoodPoseInfo> sp_bad_pose_info_ = nullptr;
145 };
146 
147 } // namespace hdmap
148 } // namespace apollo
double end_time
Definition: alignment.h:30
virtual void UpdateBadPoseInfo(const FramePose &pose)
Definition: alignment.h:52
Definition: alignment.h:27
int pose_count
Definition: alignment.h:31
PlanningContext is the runtime context in planning. It is persistent across multiple frames...
Definition: atomic_hash_map.h:25
double time_stamp
Definition: common.h:43
double end_time_
Definition: alignment.h:137
double end_index_
Definition: alignment.h:139
virtual void UpdateGoodPoseInfo(const FramePose &pose)
Definition: alignment.h:58
virtual bool IsGoodPose(const std::vector< FramePose > &poses, int pose_index)
Definition: alignment.h:64
int TimeToIndex(const std::vector< FramePose > &poses, double time)
Definition: alignment.h:119
Definition: future.h:29
int start_index_
Definition: alignment.h:138
BadOrGoodPoseInfo()
Definition: alignment.h:28
virtual double GetProgress() const
Definition: alignment.h:46
virtual void ClearGoodPoseInfo()
Definition: alignment.h:62
void ClearPoseInfo(std::shared_ptr< BadOrGoodPoseInfo > sp_pose_info)
Definition: alignment.h:108
virtual void SetStartTime(double start_time)
Definition: alignment.h:48
ErrorCode return_state_
Definition: alignment.h:140
Definition: common.h:42
double last_progress_
Definition: alignment.h:135
Definition: client_alignment.h:35
double progress_
Definition: alignment.h:134
virtual ~Alignment()
Definition: alignment.h:42
void UpdatePoseInfo(const FramePose &pose, std::shared_ptr< BadOrGoodPoseInfo > sp_pose_info)
Definition: alignment.h:88
virtual void ClearBadPoseInfo()
Definition: alignment.h:56
virtual void SetEndTime(double end_time)
Definition: alignment.h:50
#define AERROR
Definition: log.h:44
Alignment(std::shared_ptr< JsonConf > sp_conf)
Definition: alignment.h:36
ErrorCode GetReturnState() const
Definition: alignment.h:85
double start_time
Definition: alignment.h:29
double start_time_
Definition: alignment.h:136
#define AINFO
Definition: log.h:42