ground_vehicle_model.cpp
Go to the documentation of this file.
1 //=================================================================================================
2 // Copyright (c) 2013, Johannes Meyer and contributors, Technische Universitat Darmstadt
3 // All rights reserved.
4 
5 // Redistribution and use in source and binary forms, with or without
6 // modification, are permitted provided that the following conditions are met:
7 // * Redistributions of source code must retain the above copyright
8 // notice, this list of conditions and the following disclaimer.
9 // * Redistributions in binary form must reproduce the above copyright
10 // notice, this list of conditions and the following disclaimer in the
11 // documentation and/or other materials provided with the distribution.
12 // * Neither the name of the Flight Systems and Automatic Control group,
13 // TU Darmstadt, nor the names of its contributors may be used to
14 // endorse or promote products derived from this software without
15 // specific prior written permission.
16 
17 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
18 // ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19 // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20 // DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY
21 // DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
22 // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
23 // LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
24 // ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
26 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 //=================================================================================================
28 
32 
33 #include <limits>
34 
35 namespace hector_pose_estimation {
36 
37 template class System_<GroundVehicleModel>;
38 
40 {
41  gain_ = 1.0;
42  base_height_ = 0.0;
43  min_height_ = -std::numeric_limits<double>::quiet_NaN();
44  max_height_ = std::numeric_limits<double>::quiet_NaN();
45 
46  parameters().add("gain", gain_);
47  parameters().add("base_height", base_height_);
48  parameters().add("min_height", min_height_);
49  parameters().add("max_height", max_height_);
50 
51  // derivative of the 3rd column of the rotation matrix
52  dR3 << 0.0, 1.0, 0.0,
53  -1.0, 0.0, 0.0,
54  0.0, 0.0, 0.0;
55 }
56 
58 {
59 }
60 
62 {
64  if (state.position()) state.position()->vector().z() = base_height_;
65 }
66 
67 void GroundVehicleModel::getDerivative(StateVector& x_dot, const State& state)
68 {
69  // forward to GenericQuaternionSystemModel
71 
72  const State::RotationMatrix &R = state.R();
74 
75  // Update the body z velocity towards 0
76  if (state.velocity()) {
77  // v_z_body = R.col(2).dot(v)
78  state.velocity()->segment(x_dot) += -gain_ * R.col(2) * (R.col(2).dot(v));
79  }
80 }
81 
82 void GroundVehicleModel::getStateJacobian(SystemMatrix& A, const State& state, bool init)
83 {
85 
86  const State::RotationMatrix &R = state.R();
88 
89  if (state.velocity()) {
90  state.velocity()->block(A) += -gain_ * R.col(2) * R.col(2).transpose();
91 
92  if (state.orientation()) {
93  state.velocity()->block(A, *state.orientation()) += -gain_ * (dR3 * (R.col(2).dot(v)) + R.col(2) * (v.transpose() * dR3));
94  }
95  }
96 }
97 
99 {
101  if (flags & STATE_VELOCITY_XY) {
102  flags |= STATE_VELOCITY_Z;
103  flags |= STATE_POSITION_Z;
104  }
105  return flags;
106 }
107 
109 {
110  bool result = GenericQuaternionSystemModel::limitState(state);
111  if (state.position()) {
112  if (state.position()->vector().z() < min_height_) {
113  state.position()->vector().z() = min_height_;
114  result = false;
115  }
116  if (state.position()->vector().z() > max_height_) {
117  state.position()->vector().z() = max_height_;
118  result = false;
119  }
120  }
121  return result;
122 }
123 
124 } // namespace hector_pose_estimation
virtual void getDerivative(StateVector &x_dot, const State &state)
virtual const boost::shared_ptr< OrientationStateType > & orientation() const
Definition: state.h:112
virtual SystemStatus getStatusFlags(const State &state)
Matrix_< 3, 3 >::type RotationMatrix
Definition: state.h:71
virtual bool limitState(State &state)
Definition: system_model.h:55
const State::RotationMatrix & R() const
Definition: state.cpp:131
virtual ConstVelocityType getVelocity() const
Definition: state.cpp:119
virtual const boost::shared_ptr< PositionStateType > & position() const
Definition: state.h:114
virtual void getDerivative(StateVector &x_dot, const State &state)
ParameterList & add(const std::string &key, T &value, const T &default_value)
Definition: parameters.h:148
ParameterList & parameters()
Definition: model.h:47
virtual bool init(PoseEstimation &estimator, System &system, State &state)
EIGEN_MAKE_ALIGNED_OPERATOR_NEW GroundVehicleModel()
unsigned int SystemStatus
Definition: types.h:70
virtual const boost::shared_ptr< VelocityStateType > & velocity() const
Definition: state.h:115
virtual void getStateJacobian(SystemMatrix &A, const State &state, bool init=true)
virtual void getStateJacobian(SystemMatrix &A, const State &state, bool init=true)
VectorBlock< const Vector, 3 > ConstVelocityType
Definition: state.h:64


hector_pose_estimation_core
Author(s): Johannes Meyer
autogenerated on Thu Feb 18 2021 03:29:30