PX4 Firmware
PX4 Autopilot Software http://px4.io
baro.cpp
Go to the documentation of this file.
1 #include "../BlockLocalPositionEstimator.hpp"
3 #include <matrix/math.hpp>
4 
6 
7 // required number of samples for sensor
8 // to initialize
9 static const uint32_t REQ_BARO_INIT_COUNT = 100;
10 static const uint32_t BARO_TIMEOUT = 100000; // 0.1 s
11 
13 {
14  // measure
16 
17  if (baroMeasure(y) != OK) {
18  _baroStats.reset();
19  return;
20  }
21 
22  // if finished
26  "[lpe] baro init %d m std %d cm",
27  (int)_baroStats.getMean()(0),
28  (int)(100 * _baroStats.getStdDev()(0)));
31 
32  if (!_altOriginInitialized) {
33  _altOriginInitialized = true;
34  _altOriginGlobal = false;
36  }
37  }
38 }
39 
41 {
42  //measure
43  y.setZero();
45  _baroStats.update(y);
47  return OK;
48 }
49 
51 {
52  // measure
54 
55  if (baroMeasure(y) != OK) { return; }
56 
57  // subtract baro origin alt
58  y -= _baroAltOrigin;
59 
60  // baro measurement matrix
62  C.setZero();
63  C(Y_baro_z, X_z) = -1; // measured altitude, negative down dir.
64 
66  R.setZero();
67  R(0, 0) = _param_lpe_bar_z.get() * _param_lpe_bar_z.get();
68 
69  // residual
71  inv<float, n_y_baro>((C * m_P * C.transpose()) + R);
72  Vector<float, n_y_baro> r = y - (C * _x);
73 
74  // fault detection
75  float beta = (r.transpose() * (S_I * r))(0, 0);
76 
77  if (beta > BETA_TABLE[n_y_baro]) {
78  if (!(_sensorFault & SENSOR_BARO)) {
79  mavlink_log_critical(&mavlink_log_pub, "[lpe] baro fault, r %5.2f m, beta %5.2f",
80  double(r(0)), double(beta));
82  }
83 
84  } else if (_sensorFault & SENSOR_BARO) {
85  _sensorFault &= ~SENSOR_BARO;
87  }
88 
89  // kalman filter correction always
91  Vector<float, n_x> dx = K * r;
92  _x += dx;
93  m_P -= K * C * m_P;
94 }
95 
97 {
99  if (!(_sensorTimeout & SENSOR_BARO)) {
101  _baroStats.reset();
102  mavlink_and_console_log_info(&mavlink_log_pub, "[lpe] baro timeout ");
103  }
104  }
105 }
static const float BETA_TABLE[7]
matrix::Vector< Type, M > getMean()
Definition: BlockStats.hpp:85
BlockStats< float, n_y_baro > _baroStats
orb_advert_t mavlink_log_pub
int baroMeasure(Vector< float, n_y_baro > &y)
Definition: baro.cpp:40
Matrix< Type, N, M > transpose() const
Definition: Matrix.hpp:353
static const uint32_t BARO_TIMEOUT
Definition: baro.cpp:10
uORB::SubscriptionData< vehicle_air_data_s > _sub_airdata
__BEGIN_DECLS typedef void * orb_advert_t
ORB topic advertiser handle.
Definition: uORB.h:134
const T & get() const
static const uint32_t REQ_BARO_INIT_COUNT
Definition: baro.cpp:9
matrix::Vector< Type, M > getStdDev()
Definition: BlockStats.hpp:90
#define OK
Definition: uavcan_main.cpp:71
void update(const matrix::Vector< Type, M > &u)
Definition: BlockStats.hpp:71