OSVR-Core  0.6-1962-g59773924
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
PoseConstantVelocity.h
Go to the documentation of this file.
1 
11 // Copyright 2015 Sensics, Inc.
12 //
13 // Licensed under the Apache License, Version 2.0 (the "License");
14 // you may not use this file except in compliance with the License.
15 // You may obtain a copy of the License at
16 //
17 // http://www.apache.org/licenses/LICENSE-2.0
18 //
19 // Unless required by applicable law or agreed to in writing, software
20 // distributed under the License is distributed on an "AS IS" BASIS,
21 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
22 // See the License for the specific language governing permissions and
23 // limitations under the License.
24 
25 #ifndef INCLUDED_PoseConstantVelocity_h_GUID_BC2C6525_D7E6_4BB2_0220_9D6065795E12
26 #define INCLUDED_PoseConstantVelocity_h_GUID_BC2C6525_D7E6_4BB2_0220_9D6065795E12
27 
28 // Internal Includes
29 #include "PoseState.h"
30 
31 // Library/third-party includes
32 // - none
33 
34 // Standard includes
35 #include <cassert>
36 
37 namespace osvr {
38 namespace kalman {
41  public:
42  EIGEN_MAKE_ALIGNED_OPERATOR_NEW
43  using State = pose_externalized_rotation::State;
44  using StateVector = pose_externalized_rotation::StateVector;
45  using StateSquareMatrix = pose_externalized_rotation::StateSquareMatrix;
46  using NoiseAutocorrelation = types::Vector<6>;
47  PoseConstantVelocityProcessModel(double positionNoise = 0.01,
48  double orientationNoise = 0.1) {
49  setNoiseAutocorrelation(positionNoise, orientationNoise);
50  }
51  void setNoiseAutocorrelation(double positionNoise = 0.01,
52  double orientationNoise = 0.1) {
53  m_mu.head<3>() = types::Vector<3>::Constant(positionNoise);
54  m_mu.tail<3>() = types::Vector<3>::Constant(orientationNoise);
55  }
56  void setNoiseAutocorrelation(NoiseAutocorrelation const &noise) {
57  m_mu = noise;
58  }
59 
61  StateSquareMatrix getStateTransitionMatrix(State const &,
62  double dt) const {
63  return pose_externalized_rotation::stateTransitionMatrix(dt);
64  }
65 
66  void predictState(State &s, double dt) {
67  auto xHatMinus = computeEstimate(s, dt);
68  auto Pminus = predictErrorCovariance(s, *this, dt);
69  s.setStateVector(xHatMinus);
70  s.setErrorCovariance(Pminus);
71  }
72 
79  StateSquareMatrix getSampledProcessNoiseCovariance(double dt) const {
80  auto const dim = types::Dimension<State>::value;
81  StateSquareMatrix cov = StateSquareMatrix::Zero();
82  auto dt3 = (dt * dt * dt) / 3;
83  auto dt2 = (dt * dt) / 2;
84  for (std::size_t xIndex = 0; xIndex < dim / 2; ++xIndex) {
85  auto xDotIndex = xIndex + dim / 2;
86  // xIndex is 'i' and xDotIndex is 'j' in eq. 4.8
87  const auto mu = getMu(xIndex);
88  cov(xIndex, xIndex) = mu * dt3;
89  auto symmetric = mu * dt2;
90  cov(xIndex, xDotIndex) = symmetric;
91  cov(xDotIndex, xIndex) = symmetric;
92  cov(xDotIndex, xDotIndex) = mu * dt;
93  }
94  return cov;
95  }
96 
99  StateVector computeEstimate(State &state, double dt) const {
100  OSVR_KALMAN_DEBUG_OUTPUT("Time change", dt);
101  StateVector ret = pose_externalized_rotation::applyVelocity(
102  state.stateVector(), dt);
103 
104  return ret;
105  }
106 
107  private:
110  NoiseAutocorrelation m_mu;
111  double getMu(std::size_t index) const {
112  assert(index < types::Dimension<State>::value / 2 &&
113  "Should only be passing "
114  "'i' - the main state, not "
115  "the derivative");
116  // This may not be totally correct but it's one of the parameters
117  // you can kind of fudge in kalman filters anyway.
118  // Should techincally be the diagonal of the correlation kernel of
119  // the noise sources. (p77, p197 in Welch 1996)
120  return m_mu(index);
121  }
122  };
123 
124 } // namespace kalman
125 } // namespace osvr
126 #endif // INCLUDED_PoseConstantVelocity_h_GUID_BC2C6525_D7E6_4BB2_0220_9D6065795E12
Eigen::Matrix< Scalar, n, 1 > Vector
A vector of length n.
StateSquareMatrix getSampledProcessNoiseCovariance(double dt) const
types::DimSquareMatrix< StateType > predictErrorCovariance(StateType const &state, ProcessModelType &processModel, double dt)
typename detail::Dimension_impl< T >::type Dimension
A constant-velocity model for a 6DOF pose (with velocities)
The main namespace for all C++ elements of the framework, internal and external.
Definition: ClientKit.h:31
StateVector computeEstimate(State &state, double dt) const
Header.
StateSquareMatrix getStateTransitionMatrix(State const &, double dt) const
Also known as the "process model jacobian" in TAG, this is A.