icub-test
SensorsDuplicateReadings.h
1 /*
2  * iCub Robot Unit Tests (Robot Testing Framework)
3  *
4  * Copyright (C) 2015-2019 Istituto Italiano di Tecnologia (IIT)
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19  */
20 
21 #ifndef _SENSORSDUPLICATEREADINGS_H_
22 #define _SENSORSDUPLICATEREADINGS_H_
23 
24 #include <yarp/robottestingframework/TestCase.h>
25 #include <yarp/os/BufferedPort.h>
26 #include <yarp/sig/Vector.h>
27 #include <vector>
28 
29 class DuplicateReadingsPortInfo {
30 public:
31  std::string name;
32  int toleratedDuplicates;
33 };
34 
35 
36 class DuplicateDetector : public yarp::os::BufferedPort<yarp::sig::Vector> {
37 public:
38 
39  void reset() {
40  count = 0;
41  tolerance = 1e-12;
42  }
43 
44  unsigned long getCount() { return count; }
45  unsigned long getMaxNrOfDuplicates() { return maxNrOfDuplicates; }
46  double getMaxJitter() { return maxJitter; }
47  unsigned long getTotalNrOfDuplicates() { return totalNrOfDuplicates; }
48 
49  virtual void onRead(yarp::sig::Vector& vec);
50 
51 private:
52  unsigned long count;
53  double tolerance;
54  unsigned long currentNrOfDuplicates;
55  unsigned long totalNrOfDuplicates;
56  unsigned long maxNrOfDuplicates;
57  double lastNewValueTime;
58  double currentJitter;
59  double maxJitter;
60  yarp::sig::Vector lastReading;
61 };
62 
63 
88 class SensorsDuplicateReadings : public yarp::robottestingframework::TestCase {
89 public:
91  virtual ~SensorsDuplicateReadings();
92 
93  virtual bool setup(yarp::os::Property& property);
94 
95  virtual void tearDown();
96 
97  virtual void run();
98 
99 private:
100  DuplicateDetector port;
101  std::vector<DuplicateReadingsPortInfo> ports;
102  double testTime;
103 };
104 
105 #endif //_PORTSFREQUENCY_H
Check if a yarp port is correctly publishing unique values at each update .