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 
64 BaroUpdate::BaroUpdate() : qnh_(0) {}
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!
84  return true;
85 }
86 
87 } // namespace hector_pose_estimation
hector_pose_estimation::State::position
virtual const boost::shared_ptr< PositionStateType > & position() const
Definition: state.h:114
hector_pose_estimation::HeightBaroCommon::auto_elevation_
bool auto_elevation_
Definition: height.h:67
hector_pose_estimation::Measurement_< BaroModel >::getModel
virtual Model * getModel() const
Definition: measurement.h:135
hector_pose_estimation::BaroModel::qnh_
double qnh_
Definition: baro.h:58
hector_pose_estimation::HeightBaroCommon::resetElevation
double resetElevation(const State &state, boost::function< double()> altitude_func)
Definition: height.cpp:82
hector_pose_estimation::Z
@ Z
Definition: types.h:40
hector_pose_estimation::HeightModel::getElevation
double getElevation() const
Definition: height.h:48
hector_pose_estimation::State
Definition: state.h:42
hector_pose_estimation::BaroModel::~BaroModel
virtual ~BaroModel()
Definition: baro.cpp:45
hector_pose_estimation::Baro::onReset
virtual void onReset()
Definition: baro.cpp:75
hector_pose_estimation::HeightBaroCommon::onReset
virtual void onReset()
Definition: height.cpp:78
hector_pose_estimation::BaroModel::BaroModel
BaroModel()
Definition: baro.cpp:38
hector_pose_estimation::State::getPosition
virtual ConstPositionType getPosition() const
Definition: state.cpp:118
update
void update(const std::string &key, const XmlRpc::XmlRpcValue &v)
hector_pose_estimation
Definition: collection.h:39
hector_pose_estimation::Baro::setQnh
void setQnh(double qnh)
Definition: baro.h:97
hector_pose_estimation::HeightBaroCommon
Definition: height.h:57
hector_pose_estimation::Measurement_
Definition: measurement.h:40
hector_pose_estimation::Baro::Baro
Baro(const std::string &name="baro")
Definition: baro.cpp:68
hector_pose_estimation::BaroUpdate
Definition: baro.h:61
baro.h
hector_pose_estimation::BaroModel::getExpectedValue
virtual void getExpectedValue(MeasurementVector &y_pred, const State &state)
Definition: baro.cpp:47
hector_pose_estimation::HeightModel::stddev_
double stddev_
Definition: height.h:51
hector_pose_estimation::Baro::setElevation
void setElevation(double elevation)
Definition: baro.h:94
hector_pose_estimation::Baro::prepareUpdate
virtual bool prepareUpdate(State &state, const Update &update)
Definition: baro.cpp:80
hector_pose_estimation::BaroModel
Definition: baro.h:43
hector_pose_estimation::BaroModel::getAltitude
double getAltitude(const BaroUpdate &update)
Definition: baro.cpp:59
set_filter.h
hector_pose_estimation::BaroModel::getStateJacobian
virtual void getStateJacobian(MeasurementMatrix &C, const State &state, bool init)
Definition: baro.cpp:52
hector_pose_estimation::BaroUpdate::BaroUpdate
BaroUpdate()
Definition: baro.cpp:64


hector_pose_estimation_core
Author(s): Johannes Meyer
autogenerated on Wed Mar 2 2022 00:24:40