PX4 Firmware
PX4 Autopilot Software http://px4.io
land.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 //
10 static const uint32_t REQ_LAND_INIT_COUNT = 1;
11 static const uint32_t LAND_TIMEOUT = 1000000; // 1.0 s
12 
14 {
15  // measure
17 
18  if (landMeasure(y) != OK) {
19  _landCount = 0;
20  }
21 
22  // if finished
24  mavlink_and_console_log_info(&mavlink_log_pub, "[lpe] land init");
27  }
28 }
29 
31 {
33  y.setZero();
34  _landCount += 1;
35  return OK;
36 }
37 
39 {
40  // measure land
42 
43  if (landMeasure(y) != OK) { return; }
44 
45  // measurement matrix
47  C.setZero();
48  // y = -(z - tz)
49  C(Y_land_vx, X_vx) = 1;
50  C(Y_land_vy, X_vy) = 1;
51  C(Y_land_agl, X_z) = -1;// measured altitude, negative down dir.
52  C(Y_land_agl, X_tz) = 1;// measured altitude, negative down dir.
53 
54  // use parameter covariance
56  R.setZero();
57  R(Y_land_vx, Y_land_vx) = _param_lpe_land_vxy.get() * _param_lpe_land_vxy.get();
58  R(Y_land_vy, Y_land_vy) = _param_lpe_land_vxy.get() * _param_lpe_land_vxy.get();
59  R(Y_land_agl, Y_land_agl) = _param_lpe_land_z.get() * _param_lpe_land_z.get();
60 
61  // residual
62  Matrix<float, n_y_land, n_y_land> S_I = inv<float, n_y_land>((C * m_P * C.transpose()) + R);
63  Vector<float, n_y_land> r = y - C * _x;
66 
67  // fault detection
68  float beta = (r.transpose() * (S_I * r))(0, 0);
69 
70  // artifically increase beta threshhold to prevent fault during landing
71  float beta_thresh = 1e2f;
72 
73  if (beta / BETA_TABLE[n_y_land] > beta_thresh) {
74  if (!(_sensorFault & SENSOR_LAND)) {
76  mavlink_and_console_log_info(&mavlink_log_pub, "[lpe] land fault, beta %5.2f", double(beta));
77  }
78 
79  // abort correction
80  return;
81 
82  } else if (_sensorFault & SENSOR_LAND) {
83  _sensorFault &= ~SENSOR_LAND;
85  }
86 
87  // kalman filter correction always for land detector
89  Vector<float, n_x> dx = K * r;
90  _x += dx;
91  m_P -= K * C * m_P;
92 }
93 
95 {
97  if (!(_sensorTimeout & SENSOR_LAND)) {
99  _landCount = 0;
100  mavlink_and_console_log_info(&mavlink_log_pub, "[lpe] land timeout ");
101  }
102  }
103 }
static const float BETA_TABLE[7]
static const uint32_t REQ_LAND_INIT_COUNT
Definition: land.cpp:10
int landMeasure(Vector< float, n_y_land > &y)
Definition: land.cpp:30
orb_advert_t mavlink_log_pub
Matrix< Type, N, M > transpose() const
Definition: Matrix.hpp:353
__BEGIN_DECLS typedef void * orb_advert_t
ORB topic advertiser handle.
Definition: uORB.h:134
static const uint32_t LAND_TIMEOUT
Definition: land.cpp:11
#define OK
Definition: uavcan_main.cpp:71
uORB::PublicationData< ekf2_innovations_s > _pub_innov