Apollo 11.0
自动驾驶开放平台
adaptive_kalman_filter.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 *****************************************************************************/
17
18#include "cyber/common/log.h"
19
20namespace apollo {
21namespace perception {
22namespace radar {
23
24double AdaptiveKalmanFilter::s_q_matrix_ratio_ = 0.074;
25
27
29
31 belief_anchor_point_ = object.center;
32 belief_velocity_ = object.velocity.cast<double>();
33 a_matrix_.setIdentity();
34 // initialize states to the states of the detected obstacle
35 posteriori_state_(0) = belief_anchor_point_(0);
36 posteriori_state_(1) = belief_anchor_point_(1);
37 posteriori_state_(2) = belief_velocity_(0);
38 posteriori_state_(3) = belief_velocity_(1);
39 priori_state_ = posteriori_state_;
40 q_matrix_.setIdentity();
41 q_matrix_ *= s_q_matrix_ratio_;
42 r_matrix_.setIdentity();
43 r_matrix_.topLeftCorner(2, 2) =
44 object.center_uncertainty.topLeftCorner(2, 2).cast<double>();
45 r_matrix_.block<2, 2>(2, 2) =
46 object.velocity_uncertainty.topLeftCorner(2, 2).cast<double>();
47 p_matrix_.setIdentity();
48 p_matrix_.topLeftCorner(2, 2) =
49 object.center_uncertainty.topLeftCorner(2, 2).cast<double>();
50 p_matrix_.block<2, 2>(2, 2) =
51 object.velocity_uncertainty.topLeftCorner(2, 2).cast<double>();
52 c_matrix_.setIdentity();
53}
54
55Eigen::VectorXd AdaptiveKalmanFilter::Predict(const double time_diff) {
56 Eigen::VectorXd state;
57 state.resize(4);
58 state[0] = belief_anchor_point_[0] + belief_velocity_[0] * time_diff;
59 state[1] = belief_anchor_point_[1] + belief_velocity_[1] * time_diff;
60 state[2] = belief_velocity_[0];
61 state[3] = belief_velocity_[1];
62 return state;
63}
64
66 const base::Object& new_object, double time_diff) {
67 // predict and then correct
68 a_matrix_.setIdentity();
69 a_matrix_(0, 2) = time_diff;
70 a_matrix_(1, 3) = time_diff;
71 priori_state_ = a_matrix_ * posteriori_state_;
72 p_matrix_ = ((a_matrix_ * p_matrix_) * a_matrix_.transpose()) + q_matrix_;
73 belief_anchor_point_ = new_object.center;
74 belief_velocity_ = new_object.velocity.cast<double>();
75 Eigen::Vector4d measurement;
76 measurement(0) = belief_anchor_point_(0);
77 measurement(1) = belief_anchor_point_(1);
78 measurement(2) = belief_velocity_(0);
79 measurement(3) = belief_velocity_(1);
80 r_matrix_.setIdentity();
81 r_matrix_.topLeftCorner(2, 2) =
82 new_object.center_uncertainty.topLeftCorner(2, 2).cast<double>();
83 r_matrix_.block<2, 2>(2, 2) =
84 new_object.velocity_uncertainty.topLeftCorner(2, 2).cast<double>();
85 k_matrix_ =
86 p_matrix_ * c_matrix_.transpose() *
87 (c_matrix_ * p_matrix_ * c_matrix_.transpose() + r_matrix_).inverse();
88 Eigen::Vector4d predict_measurement(priori_state_(0), priori_state_(1),
89 priori_state_(2), priori_state_(3));
90 posteriori_state_ =
91 priori_state_ + k_matrix_ * (measurement - predict_measurement);
92 p_matrix_ =
93 (Eigen::Matrix4d::Identity() - k_matrix_ * c_matrix_) * p_matrix_ *
94 (Eigen::Matrix4d::Identity() - k_matrix_ * c_matrix_).transpose() +
95 k_matrix_ * r_matrix_ * k_matrix_.transpose();
96 belief_anchor_point_(0) = posteriori_state_(0);
97 belief_anchor_point_(1) = posteriori_state_(1);
98 belief_velocity_(0) = posteriori_state_(2);
99 belief_velocity_(1) = posteriori_state_(3);
100 Eigen::VectorXd state;
101 state.resize(4);
102 state[0] = belief_anchor_point_[0];
103 state[1] = belief_anchor_point_[1];
104 state[2] = belief_velocity_[0];
105 state[3] = belief_velocity_[1];
106 return state;
107}
108
109void AdaptiveKalmanFilter::GetState(Eigen::Vector3d* anchor_point,
110 Eigen::Vector3d* velocity) {
111 if (anchor_point == nullptr) {
112 AERROR << "anchor_point is not available";
113 return;
114 }
115 if (velocity == nullptr) {
116 AERROR << "velocity is not available";
117 return;
118 }
119 *anchor_point = belief_anchor_point_;
120 *velocity = belief_velocity_;
121}
122
123} // namespace radar
124} // namespace perception
125} // namespace apollo
void GetState(Eigen::Vector3d *anchor_point, Eigen::Vector3d *velocity)
Get the State object
Eigen::VectorXd Predict(const double time_diff) override
Predict the state of the object after time_diff
Eigen::VectorXd UpdateWithObject(const base::Object &new_object, double time_diff) override
Update the state of the target based on the observations
void Init(const base::Object &object) override
Init base filter config
#define AERROR
Definition log.h:44
class register implement
Definition arena_queue.h:37
Eigen::Matrix3f velocity_uncertainty
Definition object.h:90
Eigen::Matrix3f center_uncertainty
Definition object.h:58