PX4 Firmware
PX4 Autopilot Software http://px4.io
range_finder_checks.cpp
Go to the documentation of this file.
1 /****************************************************************************
2  *
3  * Copyright (c) 2019 Estimation and Control Library (ECL). 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
7  * are met:
8  *
9  * 1. Redistributions of source code must retain the above copyright
10  * notice, this list of conditions and the following disclaimer.
11  * 2. Redistributions in binary form must reproduce the above copyright
12  * notice, this list of conditions and the following disclaimer in
13  * the documentation and/or other materials provided with the
14  * distribution.
15  * 3. Neither the name ECL nor the names of its contributors may be
16  * used to endorse or promote products derived from this software
17  * without specific prior written permission.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
22  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
23  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
24  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
25  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
26  * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
27  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
29  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30  * POSSIBILITY OF SUCH DAMAGE.
31  *
32  ****************************************************************************/
33 
34 /**
35  * @file range_finder_checks.cpp
36  * Perform checks on range finder data in order to evaluate validity.
37  *
38  *
39  */
40 
41 #include "ekf.h"
42 
43 // check that the range finder data is continuous
45 {
46  // update range data continuous flag (1Hz ie 2000 ms)
47  /* Timing in micro seconds */
48 
49  /* Apply a 2.0 sec low pass filter to the time delta from the last range finder updates */
50  float alpha = 0.5f * _dt_update;
53 
55 }
56 
58 {
60 
61  // check if out of date
63  _rng_hgt_valid = false;
64  return;
65  }
66 
67  // Don't allow faulty flag to clear unless range data is continuous
69  return;
70  }
71 
72  // Don't run the checks after this unless we have retrieved new data from the buffer
73  if (!_range_data_ready) {
74  return;
75  }
76 
77  if (_range_sample_delayed.quality == 0) {
79  _rng_hgt_valid = false;
81  _rng_hgt_valid = true;
82  }
83 
84  // Check if excessively tilted
86  _rng_hgt_valid = false;
87  return;
88  }
89 
90  // Check if out of range
94  _rng_hgt_valid = false;
95  return;
96  } else {
97  // Range finders can fail to provide valid readings when resting on the ground
98  // or being handled by the user, which prevents use of as a primary height sensor.
99  // To work around this issue, we replace out of range data with the expected on ground value.
101  return;
102  }
103  }
104 
106 
108 }
109 
111 {
112  // Check for "stuck" range finder measurements when range was not valid for certain period
113  // This handles a failure mode observed with some lidar sensors
114  if (((_range_sample_delayed.time_us - _time_last_rng_ready) > (uint64_t)10e6) &&
116 
117  // require a variance of rangefinder values to check for "stuck" measurements
120  _rng_stuck_min_val = 0.0f;
121  _rng_stuck_max_val = 0.0f;
123 
124  } else {
127  }
128 
131  }
132 
134  }
135 
136  } else {
138  }
139 }
struct estimator::filter_control_status_u::@60 flags
float _dt_update
delta time since last ekf update. This time can be used for filters which run at the same rate as the...
Definition: ekf.h:286
float range_cos_max_tilt
cosine of the maximum tilt angle from the vertical that permits use of range finder and flow data ...
Definition: common.h:299
int32_t range_signal_hysteresis_ms
minimum duration during which the reported range finder signal quality needs to be non-zero in order ...
Definition: common.h:301
void updateRangeDataContinuity()
uint64_t _time_bad_rng_signal_quality
timestamp at which range finder signal quality was 0 (used for hysteresis)
Definition: ekf.h:474
float _rng_stuck_max_val
maximum value for new rng measurement when being stuck
Definition: ekf.h:487
float _rng_valid_min_val
minimum distance that the rangefinder can measure (m)
rangeSample _range_sample_delayed
float range_stuck_threshold
minimum variation in range finder reading required to declare a range finder 'unstuck' when readings ...
Definition: common.h:300
uint64_t _time_last_rng_ready
time the last range finder measurement was ready (uSec)
Definition: ekf.h:337
float rng
range (distance to ground) measurement (m)
Definition: common.h:136
float _rng_stuck_min_val
minimum value for new rng measurement when being stuck
Definition: ekf.h:486
int8_t quality
Signal quality in percent (0...100%), where 0 = invalid signal, 100 = perfect signal, and -1 = unknown signal quality.
Definition: common.h:138
#define RNG_MAX_INTERVAL
Maximum allowable time interval between range finder measurements (uSec)
Definition: common.h:210
uint64_t time_us
timestamp of the measurement (uSec)
Definition: common.h:111
Vector< float, 6 > f(float t, const Matrix< float, 6, 1 > &, const Matrix< float, 3, 1 > &)
Definition: integration.cpp:8
float rng_gnd_clearance
minimum valid value for range when on ground (m)
Definition: common.h:291
filter_control_status_u _control_status
float _rng_valid_max_val
maximum distance that the rangefinder can measure (m)
bool _rng_hgt_valid
true if range finder sample retrieved from buffer is valid
Definition: ekf.h:472
float _R_rng_to_earth_2_2
2,2 element of the rotation matrix from sensor frame to earth frame
Definition: ekf.h:465
uint32_t in_air
7 - true when the vehicle is airborne
Definition: common.h:448
float _dt_last_range_update_filt_us
filtered value of the delta time elapsed since the last range measurement came into the filter (uSec)...
Definition: ekf.h:466
bool isRangeDataContinuous()
Definition: ekf.h:749
uint32_t rng_stuck
21 - true when rng data wasn&#39;t ready for more than 10s and new rng values haven&#39;t changed enough ...
Definition: common.h:462
void updateRangeDataStuck()
void updateRangeDataValidity()
Class for core functions for ekf attitude and position estimator.
uint64_t time_us
timestamp of the measurement (uSec)
Definition: common.h:137
bool _range_data_ready
true when new range finder data has fallen behind the fusion time horizon and is available to be fuse...
Definition: ekf.h:320