| 25 | namespace libRSF |
| 26 | { |
| 27 | std::vector<Data> SampleMeasurementsDown(const std::vector<Data> &Input, const double SampleTime) |
| 28 | { |
| 29 | std::vector<Data> Output; |
| 30 | |
| 31 | if(Input.empty()) |
| 32 | { |
| 33 | PRINT_ERROR("There is no Measurement!"); |
| 34 | return Output; |
| 35 | } |
| 36 | |
| 37 | double Time = Input.front().getTimestamp(); |
| 38 | double TimeNext = Time + SampleTime; |
| 39 | double TimeMax = Input.back().getTimestamp(); |
| 40 | |
| 41 | std::vector<Data> AveragingWindow; |
| 42 | for(const Data &Sensor : Input) |
| 43 | { |
| 44 | /** group measurements in periods of sample time length*/ |
| 45 | AveragingWindow.push_back(Sensor); |
| 46 | |
| 47 | /** average when period is over*/ |
| 48 | if(Sensor.getTimestamp() >= TimeNext || Sensor.getTimestamp() == TimeMax) |
| 49 | { |
| 50 | /** average measurements */ |
| 51 | Output.push_back(AverageMeasurement(AveragingWindow)); |
| 52 | |
| 53 | /** set timestamp to last used measurements */ |
| 54 | Output.back().setTimestamp(AveragingWindow.back().getTimestamp()); |
| 55 | |
| 56 | /** set end of new window and clear old one */ |
| 57 | AveragingWindow.clear(); |
| 58 | TimeNext += SampleTime; |
| 59 | } |
| 60 | } |
| 61 | |
| 62 | return Output; |
| 63 | } |
| 64 | |
| 65 | Data AverageMeasurement(const std::vector<Data> &Input) |
| 66 | { |
nothing calls this directly
no test coverage detected