icub-test
Loading...
Searching...
No Matches
Public Member Functions
SensorsDuplicateReadings Class Reference

Check if a yarp port is correctly publishing unique values at each update . More...

#include <SensorsDuplicateReadings.h>

Inherits yarp::robottestingframework::TestCase.

Public Member Functions

virtual bool setup (yarp::os::Property &property)
 
virtual void tearDown ()
 
virtual void run ()
 

Detailed Description

Check if a yarp port is correctly publishing unique values at each update .

For some sensors, such as strain gauge based force sensors, errors on the measurement ensure that two different readings of the sensors are always different. If on a port that is publishing a sensor reading you get two times exactly the same value, this could mean that the same sensor reading was sent multiple times. This could happen for several reasons:

Accepts the following parameters:

Parameter name Type Units Default Value Required Description Notes
name string - "SensorsDuplicateReadings" No The name of the test. -
time double s - Yes Duration of the test for each port. -
PORTS (group ) Bottle - - Yes List of couples of port/toleratedDuplicates with this format: (portname1, toleratedDuplicates1) (portname1, toleratedDuplicates1)

Definition at line 88 of file SensorsDuplicateReadings.h.

Constructor & Destructor Documentation

◆ SensorsDuplicateReadings()

SensorsDuplicateReadings::SensorsDuplicateReadings ( )

Definition at line 36 of file SensorsDuplicateReadings.cpp.

36 : yarp::robottestingframework::TestCase("SensorsDuplicateReadings") {
37}

◆ ~SensorsDuplicateReadings()

SensorsDuplicateReadings::~SensorsDuplicateReadings ( )
virtual

Definition at line 39 of file SensorsDuplicateReadings.cpp.

39{ }

Member Function Documentation

◆ run()

void SensorsDuplicateReadings::run ( )
virtual

Definition at line 74 of file SensorsDuplicateReadings.cpp.

74 {
75 for(unsigned int i=0; i<ports.size(); i++) {
76 port.reset();
77 ROBOTTESTINGFRAMEWORK_TEST_REPORT(Asserter::format("Checking port %s ...", ports[i].name.c_str()));
78 bool connected = Network::connect(ports[i].name.c_str(), port.getName());
79 ROBOTTESTINGFRAMEWORK_TEST_FAIL_IF(connected,
80 Asserter::format("could not connect to remote port %s.", ports[i].name.c_str()));
81 if(connected) {
82 port.useCallback();
83 Time::delay(testTime);
84 port.disableCallback();
85
86 ROBOTTESTINGFRAMEWORK_TEST_REPORT(Asserter::format("Computed a total of %lu duplicates out of %lu samples.",
87 port.getTotalNrOfDuplicates(),port.getCount()));
88 ROBOTTESTINGFRAMEWORK_TEST_REPORT(Asserter::format("Maximum number of consecutive duplicates: %lu Maximum jitter: %lf ",
89 port.getMaxNrOfDuplicates(), port.getMaxJitter()));
90
91 ROBOTTESTINGFRAMEWORK_TEST_FAIL_IF(port.getTotalNrOfDuplicates() > ports[i].toleratedDuplicates,
92 Asserter::format("Number of duplicates (%lu) is higher than the tolerated (%d)",
93 port.getTotalNrOfDuplicates(),
94 ports[i].toleratedDuplicates));
95
96 Network::disconnect(ports[i].name.c_str(), port.getName());
97 }
98 }
99}

◆ setup()

bool SensorsDuplicateReadings::setup ( yarp::os::Property &  property)
virtual

Definition at line 41 of file SensorsDuplicateReadings.cpp.

41 {
42
43 //updating the test name
44 if(property.check("name"))
45 setName(property.find("name").asString());
46
47 // updating parameters
48 testTime = (property.check("time")) ? property.find("time").asFloat64() : 2;
49
50 ROBOTTESTINGFRAMEWORK_ASSERT_ERROR_IF(property.check("PORTS"),
51 "A list of the ports must be given");
52
53 yarp::os::Bottle portsSet = property.findGroup("PORTS").tail();
54 for(unsigned int i=0; i<portsSet.size(); i++) {
55 yarp::os::Bottle* btport = portsSet.get(i).asList();
56 ROBOTTESTINGFRAMEWORK_ASSERT_ERROR_IF(btport && btport->size()>=3, "The ports must be given as lists of <portname> <toleratedDuplicates>");
57 DuplicateReadingsPortInfo info;
58 info.name = btport->get(0).asString();
59 info.toleratedDuplicates = btport->get(1).asInt32();
60 ports.push_back(info);
61 }
62
63 // opening port
64 ROBOTTESTINGFRAMEWORK_ASSERT_ERROR_IF(port.open("..."),
65 "opening port, is YARP network available?");
66 return true;
67}

◆ tearDown()

void SensorsDuplicateReadings::tearDown ( )
virtual

Definition at line 69 of file SensorsDuplicateReadings.cpp.

69 {
70 // finalization goes her ...
71 port.close();
72}

The documentation for this class was generated from the following files: