PX4 Firmware
PX4 Autopilot Software http://px4.io
landing_target.cpp
Go to the documentation of this file.
1 #include "../BlockLocalPositionEstimator.hpp"
3 #include <matrix/math.hpp>
4 
6 
7 static const uint64_t TARGET_TIMEOUT = 2000000; // [us]
8 
10 {
11  if (_param_ltest_mode.get() == Target_Moving) {
12  // target is in moving mode, do not initialize
13  return;
14  }
15 
17 
18  if (landingTargetMeasure(y) == OK) {
19  mavlink_and_console_log_info(&mavlink_log_pub, "Landing target init");
22  }
23 }
24 
26 {
27  if (_param_ltest_mode.get() == Target_Stationary) {
32 
33  } else {
34  return -1;
35  }
36 
37  return OK;
38 
39  }
40 
41  return -1;
42 }
43 
45 {
46  if (_param_ltest_mode.get() == Target_Moving) {
47  // nothing to do in this mode
48  return;
49  }
50 
51  // measure
53 
54  if (landingTargetMeasure(y) != OK) { return; }
55 
56  // calculate covariance
57  float cov_vx = _sub_landing_target_pose.get().cov_vx_rel;
58  float cov_vy = _sub_landing_target_pose.get().cov_vy_rel;
59 
60  // use sensor value only if reasoanble
61  if (cov_vx < _param_lpe_lt_cov.get() || cov_vy < _param_lpe_lt_cov.get()) {
62  cov_vx = _param_lpe_lt_cov.get();
63  cov_vy = _param_lpe_lt_cov.get();
64  }
65 
66  // target measurement matrix and noise matrix
68  C.setZero();
69  // residual = (y + vehicle velocity)
70  // sign change because target velocitiy is -vehicle velocity
71  C(Y_target_x, X_vx) = -1;
72  C(Y_target_y, X_vy) = -1;
73 
74  // covariance matrix
76  R.setZero();
77  R(0, 0) = cov_vx;
78  R(1, 1) = cov_vy;
79 
80  // residual
81  Vector<float, n_y_target> r = y - C * _x;
82 
83  // residual covariance, (inverse)
85  inv<float, n_y_target>(C * m_P * C.transpose() + R);
86 
87  // fault detection
88  float beta = (r.transpose() * (S_I * r))(0, 0);
89 
90  if (beta > BETA_TABLE[n_y_target]) {
92  mavlink_and_console_log_info(&mavlink_log_pub, "Landing target fault, beta %5.2f", double(beta));
94  }
95 
96  // abort correction
97  return;
98 
99  } else if (_sensorFault & SENSOR_LAND_TARGET) {
100  _sensorFault &= ~SENSOR_LAND_TARGET;
101  mavlink_and_console_log_info(&mavlink_log_pub, "Landing target OK");
102  }
103 
104  // kalman filter correction
106  m_P * C.transpose() * S_I;
107  Vector<float, n_x> dx = K * r;
108  _x += dx;
109  m_P -= K * C * m_P;
110 
111 }
112 
114 {
118  mavlink_and_console_log_info(&mavlink_log_pub, "Landing target timeout");
119  }
120  }
121 }
static const float BETA_TABLE[7]
orb_advert_t mavlink_log_pub
Matrix< Type, N, M > transpose() const
Definition: Matrix.hpp:353
int landingTargetMeasure(Vector< float, n_y_target > &y)
static const uint64_t TARGET_TIMEOUT
__BEGIN_DECLS typedef void * orb_advert_t
ORB topic advertiser handle.
Definition: uORB.h:134
const T & get() const
uORB::SubscriptionData< landing_target_pose_s > _sub_landing_target_pose
#define OK
Definition: uavcan_main.cpp:71
void setZero()
Definition: Matrix.hpp:416