height.cpp
Go to the documentation of this file.
1 //=================================================================================================
2 // Copyright (c) 2011, Johannes Meyer, TU 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 
33 
34 #include <ros/console.h>
35 
36 namespace hector_pose_estimation {
37 
38 template class Measurement_<HeightModel>;
39 
41 {
42  stddev_ = 10.0;
43  elevation_ = 0.0;
44  parameters().add("stddev", stddev_);
45 }
46 
48 
49 void HeightModel::getMeasurementNoise(NoiseVariance& R, const State&, bool init)
50 {
51  if (init) {
52  R(0,0) = pow(stddev_, 2);
53  }
54 }
55 
56 void HeightModel::getExpectedValue(MeasurementVector& y_pred, const State& state)
57 {
58  y_pred(0) = state.getPosition().z() + getElevation();
59 }
60 
61 void HeightModel::getStateJacobian(MeasurementMatrix& C, const State& state, bool init)
62 {
63  if (!init) return; // C is time-constant
64 
65  if (state.position()) {
66  state.position()->cols(C)(0,Z) = 1.0;
67  }
68 }
69 
71  : auto_elevation_(true)
72  , elevation_initialized_(false)
73 {
74 }
75 
77 
79  elevation_initialized_ = false;
80 }
81 
82 double HeightBaroCommon::resetElevation(const State &state, boost::function<double()> altitude_func) {
84  if (auto_elevation_) GlobalReference::Instance()->setCurrentAltitude(state, altitude_func());
86  }
87 
88  return GlobalReference::Instance()->position().altitude;
89 }
90 
91 Height::Height(const std::string &name)
92  : Measurement_<HeightModel>(name)
93  , HeightBaroCommon(this)
94 {
95  parameters().add("auto_elevation", auto_elevation_);
96 }
97 
100 }
101 
102 template <typename T> struct functor_wrapper
103 {
104  functor_wrapper(const T& value) : value(value) {}
105  T& operator()() { return value; }
106  const T& operator()() const { return value; }
107 private:
108  T value;
109 };
110 
111 bool Height::prepareUpdate(State &state, const Update &update) {
113  return true;
114 }
115 
116 } // namespace hector_pose_estimation
virtual bool update(const MeasurementUpdate &update)
double resetElevation(const State &state, boost::function< double()> altitude_func)
Definition: height.cpp:82
static const GlobalReferencePtr & Instance()
HeightBaroCommon(Measurement *measurement)
Definition: height.cpp:70
virtual ParameterList & parameters()
Definition: measurement.h:63
virtual const boost::shared_ptr< PositionStateType > & position() const
Definition: state.h:114
Height(const std::string &name="height")
Definition: height.cpp:91
virtual void getStateJacobian(MeasurementMatrix &C, const State &state, bool init)
Definition: height.cpp:61
virtual void getExpectedValue(MeasurementVector &y_pred, const State &state)
Definition: height.cpp:56
ParameterList & add(const std::string &key, T &value, const T &default_value)
Definition: parameters.h:148
ParameterList & parameters()
Definition: model.h:47
virtual Vector const & getVector() const
virtual void getMeasurementNoise(NoiseVariance &R, const State &, bool init)
Definition: height.cpp:49
double getElevation() const
Definition: height.h:48
void setElevation(double elevation)
Definition: height.h:77
virtual bool prepareUpdate(State &state, const Update &update)
Definition: height.cpp:111
virtual bool init(PoseEstimation &estimator, Measurement &measurement, State &state)
virtual ConstPositionType getPosition() const
Definition: state.cpp:118


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