Apollo  v5.5.0
Open source self driving car software
kalman_motion_fusion.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 <deque>
19 #include <string>
20 #include <vector>
21 
24 
25 namespace apollo {
26 namespace perception {
27 namespace fusion {
28 
30  public:
31  explicit KalmanMotionFusion(TrackPtr track) : BaseMotionFusion(track) {}
32  ~KalmanMotionFusion() = default;
33 
34  KalmanMotionFusion(const KalmanMotionFusion&) = delete;
36 
37  // @brief init kalman filter and some magic number
38  bool Init() override;
39 
40  // @brief update the tracker with current measurement
41  // @params[IN] measurement: sensor results
42  // @params[IN] target_timestamp: tracker timestamp
43  void UpdateWithMeasurement(const SensorObjectConstPtr& measurement,
44  double target_timestamp) override;
45 
46  // @brief update the tracker only use time diff
47  // @params[IN] sensor_id
48  // @params[IN] measurement_timestamp
49  // @params[IN] target_timestamp
50  void UpdateWithoutMeasurement(const std::string& sensor_id,
51  double measurement_timestamp,
52  double target_timestamp) override;
53 
54  std::string Name() const override { return "KalmamnMotionFusion"; }
55 
56  void GetStates(Eigen::Vector3d* anchor_point, Eigen::Vector3d* velocity);
57 
58  private:
59  bool InitFilter(const SensorObjectConstPtr& sensor_object);
60 
61  void MotionFusionWithoutMeasurement(const double time_diff);
62  void MotionFusionWithMeasurement(const SensorObjectConstPtr& measurement,
63  double time_diff);
64 
65  // Update state
66  void UpdateMotionState();
67 
68  // @brief We use the history sensor information
69  // to compute the acceleration.
70  // @params[IN] sensor_type: which sensor type we
71  // need in history queue
72  // @params[IN] velocity: the current velocity
73  // @params[IN] timestamp: the current timestamp
74  // @return result acceleration
75  Eigen::VectorXd ComputeAccelerationMeasurement(
76  const base::SensorType& sensor_type, const Eigen::Vector3d& velocity,
77  const double& timestamp);
78 
79  void UpdateSensorHistory(const base::SensorType& sensor_type,
80  const Eigen::Vector3d& velocity,
81  const double& timestamp);
82  // @brief reward r matrix according coming sensor type and converge status
83  // @params[IN] sensor_type: sensor type of coming measurement
84  // @params[IN] converged: converge status of coming measurement
85  void RewardRMatrix(const base::SensorType& sensor_type, const bool& converged,
86  Eigen::MatrixXd* r_matrix);
87  // @brief compute pseudo measurement
88  // @params[IN] measurement: original measurement
89  // @params[IN] sensor_type: sensor type of coming measurement
90  // @params[OUT] has_good_radar: whether good radar has been found or not
91  // @return pseudo measurement of coming measurement
92  Eigen::Vector4d ComputePseudoMeasurement(const Eigen::Vector4d& measurement,
93  const base::SensorType& sensor_type);
94 
95  // @brief compute pseudo lidar measurement
96  // @params[IN] measurement: original lidar measurement
97  // @return pseudo measurement of coming lidar measurement
98  Eigen::Vector4d ComputePseudoLidarMeasurement(
99  const Eigen::Vector4d& measurement);
100  // @brief compute pseudo camera measurement
101  // @params[IN] measurement: original camera measurement
102  // @return pseudo measurement of coming camera measurement
103  Eigen::Vector4d ComputePseudoCameraMeasurement(
104  const Eigen::Vector4d& measurement);
105  // @brief compute pseudo radar measurement
106  // @params[IN] measurement: original radar measurement
107  // @return pseudo measurement of coming radar measurement
108  Eigen::Vector4d ComputePseudoRadarMeasurement(
109  const Eigen::Vector4d& measurement);
110 
111  int GetSensorHistoryLength(const base::SensorType& sensor_type);
112  int GetSensorHistoryIndex(const base::SensorType& sensor_type,
113  const int& trace_length);
114 
115  private:
116  bool filter_init_ = false;
117  std::deque<Eigen::Vector3d> history_velocity_;
118  std::deque<double> history_timestamp_;
119  std::deque<base::SensorType> history_sensor_type_;
120  KalmanFilter kalman_filter_;
121  Eigen::Vector3d fused_anchor_point_;
122  Eigen::Vector3d fused_velocity_;
123  Eigen::Vector3d fused_acceleration_;
124  Eigen::Matrix3f center_uncertainty_ = Eigen::Matrix3f::Zero();
125  Eigen::Matrix3f velo_uncertainty_ = Eigen::Matrix3f::Zero();
126  Eigen::Matrix3f acc_uncertainty_ = Eigen::Matrix3f::Zero();
127 
128  static int s_eval_window_;
129  static size_t s_history_size_maximum_;
130  double velocity_length_change_thresh_ = 5.0f; // diff < 5 m/s
131 };
132 
133 } // namespace fusion
134 } // namespace perception
135 } // namespace apollo
void GetStates(Eigen::Vector3d *anchor_point, Eigen::Vector3d *velocity)
Definition: blob.h:72
Definition: kalman_motion_fusion.h:29
KalmanMotionFusion & operator=(const KalmanMotionFusion &)=delete
Definition: base_motion_fusion.h:29
void UpdateWithMeasurement(const SensorObjectConstPtr &measurement, double target_timestamp) override
Definition: kalman_filter.h:26
std::string Name() const override
Definition: kalman_motion_fusion.h:54
std::shared_ptr< Track > TrackPtr
Definition: track.h:160
SensorType
Sensor types are set in the order of lidar, radar, camera, ultrasonic Please make sure SensorType has...
Definition: sensor_meta.h:29
std::shared_ptr< const SensorObject > SensorObjectConstPtr
Definition: sensor_object.h:69
void UpdateWithoutMeasurement(const std::string &sensor_id, double measurement_timestamp, double target_timestamp) override
KalmanMotionFusion(TrackPtr track)
Definition: kalman_motion_fusion.h:31