KalmanFilter.cpp
Go to the documentation of this file.
1 
18 #include <iostream>
19 
21 
23  KalmanFilter::KalmanFilter(ISM::Object pObject) :
24 
25  mReset(true)
26  {
27  mF = Eigen::MatrixXd::Identity(7, 7);
28  mH = Eigen::MatrixXd::Identity(7, 7);
29 
30  mQ = 0.1 * Eigen::MatrixXd::Identity(7, 7);
31  mR = 1 * Eigen::MatrixXd::Identity(7, 7);
32 
33  mP = Eigen::MatrixXd::Identity(mF.rows(), mF.cols());
34 
35  update(pObject);
36  }
37 
38  // dtor
40  }
41 
43  mReset = true;
44  }
45 
46  void KalmanFilter::update(ISM::Object pObject) {
47 
48 
49  // Bring last update time uptodate.
50  lastUpdate = std::chrono::high_resolution_clock::now();
51 
52  // Rename the mesaurement to x.
53  Eigen::VectorXd x = Eigen::VectorXd::Zero(7);
54 
55 
56  if(!pObject.pose){
57  std::cerr << "Got a Object without poses." << std::endl;
58  std::exit(1);
59  }
60 
61  boost::shared_ptr<ISM::Pose> current_pose = pObject.pose;
62  x(0) = current_pose->point->getEigen().x();
63  x(1) = current_pose->point->getEigen().y();
64  x(2) = current_pose->point->getEigen().z();
65  x(3) = current_pose->quat->getEigen().w();
66  x(4) = current_pose->quat->getEigen().x();
67  x(5) = current_pose->quat->getEigen().y();
68  x(6) = current_pose->quat->getEigen().z();
69 
70  // If reset flag is true, reset the system to the current measurement.
71  if (mReset) {
72  mReset = false;
73  mX = x;
74  mZ = mH * x;
75  }
76 
77  // Prediction step.
78  Eigen::VectorXd xPred = mF * x;
79  Eigen::MatrixXd PPred = mF * mP * mF.transpose() + mQ;
80 
81  // Update step
82  Eigen::MatrixXd Ku = PPred * mH.transpose();
83  Eigen::MatrixXd Kl = (mH * PPred * mH.transpose() + mR);
84  Eigen::MatrixXd K = Ku * Kl.inverse();
85  Eigen::VectorXd xNew = xPred + K * (mZ - mH * xPred);
86  mP = PPred - K * mH * PPred;
87 
88  // Set the x and the z
89  mX = xNew;
90  mZ = mH * mX;
91 
92  // Save instance of Asr::AsrObject.
93  mInstance = pObject;
94 
95  }
96 
97  bool KalmanFilter::isTimedOut(unsigned int threshold)
98  {
99  return std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::high_resolution_clock::now() - lastUpdate).count() > threshold;
100  }
101 
103  {
104 
105  // Write the pose maintained by the kalman-filter back into the object.
106  geometry_msgs::Pose current_pose;
107  current_pose.position.x = mZ(0);
108  current_pose.position.y = mZ(1);
109  current_pose.position.z = mZ(2);
110  current_pose.orientation.w = mZ(3);
111  current_pose.orientation.x = mZ(4);
112  current_pose.orientation.y = mZ(5);
113  current_pose.orientation.z = mZ(6);
114 
115  //mInstance.sampledPoses.pop_back();
116  geometry_msgs::PoseWithCovariance current_pose_with_c;
117  current_pose_with_c.pose = current_pose;
118  // mInstance.sampledPoses.push_back(current_pose_with_c);
119  // Return the instance updated by the kalman filter.
120  return mInstance;
121  }
122 }
std::chrono::high_resolution_clock::time_point lastUpdate
Definition: KalmanFilter.h:47
TFSIMD_FORCE_INLINE const tfScalar & x() const
bool isTimedOut(unsigned int threshold)


asr_psm
Author(s): Braun Kai, Gehrung Joachim, Heizmann Heinrich, Meißner Pascal
autogenerated on Fri Nov 15 2019 03:57:54