Apollo  6.0
Open source self driving car software
base_filter.h
Go to the documentation of this file.
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 #pragma once
17 
18 #include <string>
19 
20 #include "Eigen/Dense"
21 
22 namespace apollo {
23 namespace perception {
24 namespace fusion {
25 
26 // @brief base filter inference
27 class BaseFilter {
28  public:
29  EIGEN_MAKE_ALIGNED_OPERATOR_NEW
30 
31  public:
32  // @brief constructor
33  explicit BaseFilter(const std::string name)
34  : init_(false), name_(name), states_num_(0) {}
35 
36  // @brief destructor
37  virtual ~BaseFilter() {}
38 
39  // @brief filter initialized
40  // @params[IN] gloabl_states: a vector contains system states(
41  // position, velocity etc.)
42  // @params[IN] global_uncertainty: a covariance matrix which
43  // indicate the uncertainty of each system state
44  virtual bool Init(const Eigen::VectorXd &global_states,
45  const Eigen::MatrixXd &global_uncertainty) = 0;
46 
47  // @brief predict the current state and uncertainty of system
48  // @params[IN] transform_matrix: transform the state from the
49  // pre moment to current moment
50  // @params[IN] env_uncertainty_matrix: the uncertainty brought by
51  // the environment when predict.
52  virtual bool Predict(const Eigen::MatrixXd &transform_matrix,
53  const Eigen::MatrixXd &env_uncertainty_matrix) = 0;
54 
55  // @brief use the current observation to correct the predict
56  // @params[IN] cur_observation: the observation in current time
57  // @params[IN] cur_observation_uncertainty: the uncertainty of
58  // the observation
59  virtual bool Correct(const Eigen::VectorXd &cur_observation,
60  const Eigen::MatrixXd &cur_observation_uncertainty) = 0;
61 
62  // @brief set the control matrix
63  virtual bool SetControlMatrix(const Eigen::MatrixXd &c_matrix) = 0;
64 
65  // @brief get the system states
66  virtual Eigen::VectorXd GetStates() const = 0;
67 
68  // @brief get the name of the filter
69  std::string Name() { return name_; }
70 
71  protected:
72  // @brief whether the filter has been init
73  bool init_;
74 
75  // @brief the name of the filter
76  std::string name_;
77 
78  // @brief the number of the system states
80 
81  Eigen::MatrixXd transform_matrix_;
82  Eigen::VectorXd global_states_;
83  Eigen::MatrixXd global_uncertainty_;
84  Eigen::MatrixXd env_uncertainty_;
85  Eigen::MatrixXd cur_observation_;
87  Eigen::MatrixXd c_matrix_;
88 };
89 
90 } // namespace fusion
91 } // namespace perception
92 } // namespace apollo
int states_num_
Definition: base_filter.h:79
Eigen::MatrixXd env_uncertainty_
Definition: base_filter.h:84
virtual ~BaseFilter()
Definition: base_filter.h:37
PlanningContext is the runtime context in planning. It is persistent across multiple frames...
Definition: atomic_hash_map.h:25
Eigen::MatrixXd cur_observation_
Definition: base_filter.h:85
Eigen::MatrixXd cur_observation_uncertainty_
Definition: base_filter.h:86
Eigen::VectorXd global_states_
Definition: base_filter.h:82
virtual bool Predict(const Eigen::MatrixXd &transform_matrix, const Eigen::MatrixXd &env_uncertainty_matrix)=0
Definition: base_filter.h:27
std::string Name()
Definition: base_filter.h:69
virtual bool SetControlMatrix(const Eigen::MatrixXd &c_matrix)=0
std::string name_
Definition: base_filter.h:76
Eigen::MatrixXd c_matrix_
Definition: base_filter.h:87
virtual Eigen::VectorXd GetStates() const =0
Eigen::MatrixXd global_uncertainty_
Definition: base_filter.h:83
Eigen::MatrixXd transform_matrix_
Definition: base_filter.h:81
virtual bool Correct(const Eigen::VectorXd &cur_observation, const Eigen::MatrixXd &cur_observation_uncertainty)=0
virtual bool Init(const Eigen::VectorXd &global_states, const Eigen::MatrixXd &global_uncertainty)=0
BaseFilter(const std::string name)
Definition: base_filter.h:33
bool init_
Definition: base_filter.h:73