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