Browse Source

data_validator cleanup: use dimensions variable, use static for some constants (#167)

master
Beat Küng 9 years ago committed by Lorenz Meier
parent
commit
5e0a229ee8
  1. 12
      validation/data_validator.cpp
  2. 23
      validation/data_validator.h

12
validation/data_validator.cpp

@ -70,17 +70,13 @@ DataValidator::~DataValidator()
void void
DataValidator::put(uint64_t timestamp, float val, uint64_t error_count_in, int priority_in) DataValidator::put(uint64_t timestamp, float val, uint64_t error_count_in, int priority_in)
{ {
float data[3]; float data[dimensions] = { val }; //sets the first value and all others to 0
data[0] = val;
data[1] = 0.0f;
data[2] = 0.0f;
put(timestamp, data, error_count_in, priority_in); put(timestamp, data, error_count_in, priority_in);
} }
void 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++; _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; _error_count = error_count_in;
_priority = priority_in; _priority = priority_in;
for (unsigned i = 0; i < _dimensions; i++) { for (unsigned i = 0; i < dimensions; i++) {
if (_time_last == 0) { if (_time_last == 0) {
_mean[i] = 0; _mean[i] = 0;
_lp[i] = val[i]; _lp[i] = val[i];
@ -176,7 +172,7 @@ DataValidator::print()
return; 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", 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) _value[i], (double)_lp[i], (double)_mean[i],
(double)_rms[i], (double)confidence(hrt_absolute_time())); (double)_rms[i], (double)confidence(hrt_absolute_time()));

23
validation/data_validator.h

@ -46,6 +46,8 @@
class __EXPORT DataValidator { class __EXPORT DataValidator {
public: public:
static const unsigned dimensions = 3;
DataValidator(DataValidator *prev_sibling = nullptr); DataValidator(DataValidator *prev_sibling = nullptr);
virtual ~DataValidator(); virtual ~DataValidator();
@ -61,7 +63,7 @@ public:
* *
* @param val Item to put * @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 * Get the next sibling in the group
@ -147,7 +149,6 @@ public:
static constexpr uint32_t ERROR_FLAG_HIGH_ERRDENSITY = (0x00000001U << 4); static constexpr uint32_t ERROR_FLAG_HIGH_ERRDENSITY = (0x00000001U << 4);
private: private:
static const unsigned _dimensions = 3;
uint32_t _error_mask; /**< sensor error state */ uint32_t _error_mask; /**< sensor error state */
uint64_t _time_last; /**< last timestamp */ uint64_t _time_last; /**< last timestamp */
uint64_t _timeout_interval; /**< interval in which the datastream times out in us */ uint64_t _timeout_interval; /**< interval in which the datastream times out in us */
@ -155,17 +156,17 @@ private:
uint64_t _error_count; /**< error count */ uint64_t _error_count; /**< error count */
int _error_density; /**< ratio between successful reads and errors */ int _error_density; /**< ratio between successful reads and errors */
int _priority; /**< sensor nominal priority */ int _priority; /**< sensor nominal priority */
float _mean[_dimensions]; /**< mean of value */ float _mean[dimensions]; /**< mean of value */
float _lp[3]; /**< low pass value */ float _lp[dimensions]; /**< low pass value */
float _M2[3]; /**< RMS component value */ float _M2[dimensions]; /**< RMS component value */
float _rms[3]; /**< root mean square error */ float _rms[dimensions]; /**< root mean square error */
float _value[3]; /**< last value */ float _value[dimensions]; /**< last value */
float _vibe[3]; /**< vibration level, in sensor unit */ float _vibe[dimensions]; /**< vibration level, in sensor unit */
float _value_equal_count; /**< equal values in a row */ float _value_equal_count; /**< equal values in a row */
DataValidator *_sibling; /**< sibling in the group */ DataValidator *_sibling; /**< sibling in the group */
const unsigned NORETURN_ERRCOUNT = 10000; /**< if the error count reaches this value, return sensor as invalid */ static const constexpr 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 */ static const constexpr 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 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 */ /* we don't want this class to be copied */
DataValidator(const DataValidator&); DataValidator(const DataValidator&);

Loading…
Cancel
Save