mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-05-14 05:57:38 +08:00
data_validator cleanup: use dimensions variable, use static for some constants (#167)
This commit is contained in:
@@ -70,17 +70,13 @@ DataValidator::~DataValidator()
|
||||
void
|
||||
DataValidator::put(uint64_t timestamp, float val, uint64_t error_count_in, int priority_in)
|
||||
{
|
||||
float data[3];
|
||||
|
||||
data[0] = val;
|
||||
data[1] = 0.0f;
|
||||
data[2] = 0.0f;
|
||||
float data[dimensions] = { val }; //sets the first value and all others to 0
|
||||
|
||||
put(timestamp, data, error_count_in, priority_in);
|
||||
}
|
||||
|
||||
void
|
||||
DataValidator::put(uint64_t timestamp, float val[3], uint64_t error_count_in, int priority_in)
|
||||
DataValidator::put(uint64_t timestamp, float val[dimensions], uint64_t error_count_in, int priority_in)
|
||||
{
|
||||
_event_count++;
|
||||
|
||||
@@ -93,7 +89,7 @@ DataValidator::put(uint64_t timestamp, float val[3], uint64_t error_count_in, in
|
||||
_error_count = error_count_in;
|
||||
_priority = priority_in;
|
||||
|
||||
for (unsigned i = 0; i < _dimensions; i++) {
|
||||
for (unsigned i = 0; i < dimensions; i++) {
|
||||
if (_time_last == 0) {
|
||||
_mean[i] = 0;
|
||||
_lp[i] = val[i];
|
||||
@@ -176,7 +172,7 @@ DataValidator::print()
|
||||
return;
|
||||
}
|
||||
|
||||
for (unsigned i = 0; i < _dimensions; i++) {
|
||||
for (unsigned i = 0; i < dimensions; i++) {
|
||||
ECL_INFO("\tval: %8.4f, lp: %8.4f mean dev: %8.4f RMS: %8.4f conf: %8.4f",
|
||||
(double) _value[i], (double)_lp[i], (double)_mean[i],
|
||||
(double)_rms[i], (double)confidence(hrt_absolute_time()));
|
||||
|
||||
+12
-11
@@ -46,6 +46,8 @@
|
||||
|
||||
class __EXPORT DataValidator {
|
||||
public:
|
||||
static const unsigned dimensions = 3;
|
||||
|
||||
DataValidator(DataValidator *prev_sibling = nullptr);
|
||||
virtual ~DataValidator();
|
||||
|
||||
@@ -61,7 +63,7 @@ public:
|
||||
*
|
||||
* @param val Item to put
|
||||
*/
|
||||
void put(uint64_t timestamp, float val[3], uint64_t error_count, int priority);
|
||||
void put(uint64_t timestamp, float val[dimensions], uint64_t error_count, int priority);
|
||||
|
||||
/**
|
||||
* Get the next sibling in the group
|
||||
@@ -147,7 +149,6 @@ public:
|
||||
static constexpr uint32_t ERROR_FLAG_HIGH_ERRDENSITY = (0x00000001U << 4);
|
||||
|
||||
private:
|
||||
static const unsigned _dimensions = 3;
|
||||
uint32_t _error_mask; /**< sensor error state */
|
||||
uint64_t _time_last; /**< last timestamp */
|
||||
uint64_t _timeout_interval; /**< interval in which the datastream times out in us */
|
||||
@@ -155,17 +156,17 @@ private:
|
||||
uint64_t _error_count; /**< error count */
|
||||
int _error_density; /**< ratio between successful reads and errors */
|
||||
int _priority; /**< sensor nominal priority */
|
||||
float _mean[_dimensions]; /**< mean of value */
|
||||
float _lp[3]; /**< low pass value */
|
||||
float _M2[3]; /**< RMS component value */
|
||||
float _rms[3]; /**< root mean square error */
|
||||
float _value[3]; /**< last value */
|
||||
float _vibe[3]; /**< vibration level, in sensor unit */
|
||||
float _mean[dimensions]; /**< mean of value */
|
||||
float _lp[dimensions]; /**< low pass value */
|
||||
float _M2[dimensions]; /**< RMS component value */
|
||||
float _rms[dimensions]; /**< root mean square error */
|
||||
float _value[dimensions]; /**< last value */
|
||||
float _vibe[dimensions]; /**< vibration level, in sensor unit */
|
||||
float _value_equal_count; /**< equal values in a row */
|
||||
DataValidator *_sibling; /**< sibling in the group */
|
||||
const unsigned NORETURN_ERRCOUNT = 10000; /**< if the error count reaches this value, return sensor as invalid */
|
||||
const float ERROR_DENSITY_WINDOW = 100.0f; /**< window in measurement counts for errors */
|
||||
const unsigned VALUE_EQUAL_COUNT_MAX = 100; /**< if the sensor value is the same (accumulated also between axes) this many times, flag it */
|
||||
static const constexpr unsigned NORETURN_ERRCOUNT = 10000; /**< if the error count reaches this value, return sensor as invalid */
|
||||
static const constexpr float ERROR_DENSITY_WINDOW = 100.0f; /**< window in measurement counts for errors */
|
||||
static const constexpr unsigned VALUE_EQUAL_COUNT_MAX = 100; /**< if the sensor value is the same (accumulated also between axes) this many times, flag it */
|
||||
|
||||
/* we don't want this class to be copied */
|
||||
DataValidator(const DataValidator&);
|
||||
|
||||
Reference in New Issue
Block a user