diff --git a/modules/prediction/container/obstacles/obstacle.cc b/modules/prediction/container/obstacles/obstacle.cc index 6a93fe7616969650fd538278ac05a72ed135585e..79e87fee8e5ad0263ed42b4e33742363a54763a5 100644 --- a/modules/prediction/container/obstacles/obstacle.cc +++ b/modules/prediction/container/obstacles/obstacle.cc @@ -46,6 +46,7 @@ Obstacle::Obstacle() : type_(PerceptionObstacle::UNKNOWN_MOVABLE), feature_history_(0), kf_motion_tracker_(), + kf_motion_tracker_enabled_(false), kf_lane_trackers_(0) { } @@ -55,6 +56,7 @@ Obstacle::~Obstacle() { type_ = PerceptionObstacle::UNKNOWN_UNMOVABLE; feature_history_.clear(); kf_lane_trackers_.clear(); + kf_motion_tracker_enabled_ = false; // TODO(author) current_lanes_.clear(); } @@ -131,7 +133,9 @@ void Obstacle::Insert(const PerceptionObstacle& perception_obstacle, SetVelocity(perception_obstacle, &feature); SetAcceleration(&feature); SetTheta(perception_obstacle, &feature); - InitKFMotionTracker(&feature); + if (!kf_motion_tracker_enabled_) { + InitKFMotionTracker(&feature); + } UpdateKFMotionTracker(&feature); } @@ -368,6 +372,8 @@ void Obstacle::InitKFMotionTracker(Feature* feature) { x(5, 0) = feature->acceleration().y(); kf_motion_tracker_.SetStateEstimate(x, P); + + kf_motion_tracker_enabled_ = true; } void Obstacle::UpdateKFMotionTracker(Feature* feature) { @@ -422,5 +428,42 @@ void Obstacle::UpdateMotionBelief(Feature* feature) { << "]."; } +void Obstacle::InitKFLaneTracker(const std::string& lane_id, + const double beta) { + KalmanFilter kf; + + // transition matrix: update delta_t at each processing step + Eigen::Matrix F; + F.setIdentity(); + F(1, 1) = beta; + kf.SetTransitionMatrix(F); + + // observation matrix + Eigen::Matrix H; + H(0, 0) = 1.0; + H(1, 1) = 1.0; + kf.SetObservationMatrix(H); + + // Set covariance of transition noise matrix Q + Eigen::Matrix Q; + Q.setIdentity(); + Q *= FLAGS_q_var; + kf.SetTransitionNoise(Q); + + // Set observation noise matrix R + Eigen::Matrix R; + R.setIdentity(); + R *= FLAGS_r_var; + kf.SetObservationNoise(R); + + // Set current state covariance matrix P + Eigen::Matrix P; + P.setIdentity(); + P *= FLAGS_p_var; + kf.SetStateCovariance(P); + + kf_lane_trackers_.emplace(lane_id, std::move(kf)); +} + } // namespace prediction } // namespace apollo diff --git a/modules/prediction/container/obstacles/obstacle.h b/modules/prediction/container/obstacles/obstacle.h index b8aae23f73b920ff6721898bbc1558eb910d1971..3346f00d7af4300a6f105c5a9a423f90ca6eacae 100644 --- a/modules/prediction/container/obstacles/obstacle.h +++ b/modules/prediction/container/obstacles/obstacle.h @@ -103,11 +103,14 @@ class Obstacle { void UpdateMotionBelief(Feature* feature); + void InitKFLaneTracker(const std::string& lane_id, const double beta); + private: int id_; apollo::perception::PerceptionObstacle::Type type_; std::deque feature_history_; apollo::common::math::KalmanFilter kf_motion_tracker_; + bool kf_motion_tracker_enabled_; std::unordered_map> kf_lane_trackers_; // TODO(author) std::vector _current_lanes;