PX4 Firmware
PX4 Autopilot Software http://px4.io
data_validator_group.h
Go to the documentation of this file.
1 /****************************************************************************
2  *
3  * Copyright (c) 2015 PX4 Development Team. 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 PX4 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 data_validator_group.h
36  *
37  * A data validation group to identify anomalies in data streams
38  *
39  * @author Lorenz Meier <lorenz@px4.io>
40  */
41 
42 #pragma once
43 
44 #include "data_validator.h"
45 
47 {
48 public:
49  /**
50  * @param siblings initial number of DataValidator's. Must be > 0.
51  */
52  DataValidatorGroup(unsigned siblings);
54 
55  /**
56  * Create a new Validator (with index equal to the number of currently existing validators)
57  * @return the newly created DataValidator or nullptr on error
58  */
60 
61  /**
62  * Put an item into the validator group.
63  *
64  * @param index Sensor index
65  * @param timestamp The timestamp of the measurement
66  * @param val The 3D vector
67  * @param error_count The current error count of the sensor
68  * @param priority The priority of the sensor
69  */
70  void put(unsigned index, uint64_t timestamp, const float val[3], uint64_t error_count, int priority);
71 
72  /**
73  * Get the best data triplet of the group
74  *
75  * @return pointer to the array of best values
76  */
77  float *get_best(uint64_t timestamp, int *index);
78 
79  /**
80  * Get the RMS / vibration factor
81  *
82  * @return float value representing the RMS, which a valid indicator for vibration
83  */
84  float get_vibration_factor(uint64_t timestamp);
85 
86  /**
87  * Get the vibration offset in the sensor unit
88  *
89  * @return float value representing the vibration offset
90  */
91  float get_vibration_offset(uint64_t timestamp, int axis);
92 
93  /**
94  * Get the number of failover events
95  *
96  * @return the number of failovers
97  */
98  unsigned failover_count() const { return _toggle_count; }
99 
100  /**
101  * Get the index of the failed sensor in the group
102  *
103  * @return index of the failed sensor
104  */
105  int failover_index();
106 
107  /**
108  * Get the error state of the failed sensor in the group
109  *
110  * @return bitmask with erro states of the failed sensor
111  */
112  uint32_t failover_state();
113 
114  /**
115  * Print the validator value
116  *
117  */
118  void print();
119 
120  /**
121  * Set the timeout value for the whole group
122  *
123  * @param timeout_interval_us The timeout interval in microseconds
124  */
125  void set_timeout(uint32_t timeout_interval_us);
126 
127  /**
128  * Set the equal count threshold for the whole group
129  *
130  * @param threshold The number of equal values before considering the sensor stale
131  */
132  void set_equal_value_threshold(uint32_t threshold);
133 
134 
135 private:
136  DataValidator *_first{nullptr}; /**< first node in the group */
137  DataValidator *_last{nullptr}; /**< last node in the group */
138 
139  uint32_t _timeout_interval_us{0}; /**< currently set timeout */
140 
141  int _curr_best{-1}; /**< currently best index */
142  int _prev_best{-1}; /**< the previous best index */
143 
144  uint64_t _first_failover_time{0}; /**< timestamp where the first failover occured or zero if none occured */
145 
146  unsigned _toggle_count{0}; /**< number of back and forth switches between two sensors */
147 
148  static constexpr float MIN_REGULAR_CONFIDENCE = 0.9f;
149 
150  /* we don't want this class to be copied */
153 };
void put(unsigned index, uint64_t timestamp, const float val[3], uint64_t error_count, int priority)
Put an item into the validator group.
void set_timeout(uint32_t timeout_interval_us)
Set the timeout value for the whole group.
DataValidator * _first
first node in the group
int failover_index()
Get the index of the failed sensor in the group.
DataValidator * _last
last node in the group
void print()
Print the validator value.
uint32_t failover_state()
Get the error state of the failed sensor in the group.
DataValidatorGroup operator=(const DataValidatorGroup &)
float * get_best(uint64_t timestamp, int *index)
Get the best data triplet of the group.
static constexpr float MIN_REGULAR_CONFIDENCE
float get_vibration_offset(uint64_t timestamp, int axis)
Get the vibration offset in the sensor unit.
float get_vibration_factor(uint64_t timestamp)
Get the RMS / vibration factor.
void set_equal_value_threshold(uint32_t threshold)
Set the equal count threshold for the whole group.
DataValidator * add_new_validator()
Create a new Validator (with index equal to the number of currently existing validators) ...
unsigned failover_count() const
Get the number of failover events.
uint32_t _timeout_interval_us
currently set timeout
A data validation class to identify anomalies in data streams.
int _prev_best
the previous best index
int _curr_best
currently best index
unsigned _toggle_count
number of back and forth switches between two sensors
DataValidatorGroup(unsigned siblings)
uint64_t _first_failover_time
timestamp where the first failover occured or zero if none occured