baro.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 
31 
32 #include <boost/bind.hpp>
33 
34 namespace hector_pose_estimation {
35 
36 template class Measurement_<BaroModel>;
37 
39 {
40  stddev_ = 1.0;
41  qnh_ = 1013.25;
42  parameters().add("qnh", qnh_);
43 }
44 
46 
47 void BaroModel::getExpectedValue(MeasurementVector& y_pred, const State& state)
48 {
49  y_pred(0) = qnh_ * pow(1.0 - (0.0065 * (state.getPosition().z() + getElevation())) / 288.15, 5.255);
50 }
51 
52 void BaroModel::getStateJacobian(MeasurementMatrix& C, const State& state, bool)
53 {
54  if (state.position()) {
55  state.position()->cols(C)(0,Z) = qnh_ * 5.255 * pow(1.0 - (0.0065 * (state.getPosition().z() + getElevation())) / 288.15, 4.255) * (-0.0065 / 288.15);
56  }
57 }
58 
59 double BaroModel::getAltitude(const BaroUpdate& update)
60 {
61  return 288.15 / 0.0065 * (1.0 - pow(update.getVector()(0) / qnh_, 1.0/5.255));
62 }
63 
65 BaroUpdate::BaroUpdate(double pressure) : qnh_(0) { *this = pressure; }
66 BaroUpdate::BaroUpdate(double pressure, double qnh) : qnh_(qnh) { *this = pressure; }
67 
68 Baro::Baro(const std::string &name)
69  : Measurement_<BaroModel>(name)
70  , HeightBaroCommon(this)
71 {
72  parameters().add("auto_elevation", auto_elevation_);
73 }
74 
76 {
78 }
79 
80 bool Baro::prepareUpdate(State &state, const Update &update) {
81  if (update.qnh() != 0) setQnh(update.qnh());
82  // Note: boost::bind is not real-time safe!
83  setElevation(resetElevation(state, boost::bind(&BaroModel::getAltitude, getModel(), update)));
84  return true;
85 }
86 
87 } // namespace hector_pose_estimation
virtual void getExpectedValue(MeasurementVector &y_pred, const State &state)
Definition: baro.cpp:47
virtual bool update(const MeasurementUpdate &update)
virtual bool prepareUpdate(State &state, const Update &update)
Definition: baro.cpp:80
double resetElevation(const State &state, boost::function< double()> altitude_func)
Definition: height.cpp:82
void setElevation(double elevation)
Definition: baro.h:94
virtual ParameterList & parameters()
Definition: measurement.h:63
double getAltitude(const BaroUpdate &update)
Definition: baro.cpp:59
virtual const boost::shared_ptr< PositionStateType > & position() const
Definition: state.h:114
virtual void getStateJacobian(MeasurementMatrix &C, const State &state, bool init)
Definition: baro.cpp:52
ParameterList & add(const std::string &key, T &value, const T &default_value)
Definition: parameters.h:148
ParameterList & parameters()
Definition: model.h:47
Baro(const std::string &name="baro")
Definition: baro.cpp:68
virtual Vector const & getVector() const
void setQnh(double qnh)
Definition: baro.h:97
double getElevation() const
Definition: height.h:48
virtual ConstPositionType getPosition() const
Definition: state.cpp:118
virtual void onReset()
Definition: baro.cpp:75


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