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

Check if a camera is publishing images at desired framerate. More...

#include <CameraTest.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 camera is publishing images at desired framerate.

Accepts the following parameters:

Parameter name Type Units Default Value Required Description Notes
name string - "CameraTest" No The name of the test. -
portname string - - Yes The yarp port name of the camera to test. -
measure_time int s 1 No The duration of the test.
expected_frequency int Hz 30 No The expected framerate of the camera.
tolerance int Number of frames 5 No The tolerance on the total number of frames read during the period (expected_frequency*measure_time) to consider the test sucessful.

Definition at line 44 of file CameraTest.h.

Constructor & Destructor Documentation

◆ CameraTest()

CameraTest::CameraTest ( )

Definition at line 44 of file CameraTest.cpp.

44 : yarp::robottestingframework::TestCase("CameraTest") {
45}

◆ ~CameraTest()

CameraTest::~CameraTest ( )
virtual

Definition at line 47 of file CameraTest.cpp.

47{ }

Member Function Documentation

◆ run()

void CameraTest::run ( )
virtual

Definition at line 82 of file CameraTest.cpp.

82 {
83 ROBOTTESTINGFRAMEWORK_TEST_REPORT("Reading images...");
84 double timeStart=yarp::os::Time::now();
85 double timeNow=timeStart;
86
87 int frames=0;
88 while(timeNow<timeStart+measure_time) {
89 Image *image=port.read(false);
90 if(image!=0)
91 frames++;
92 yarp::os::Time::delay(0.01);
93 timeNow=yarp::os::Time::now();
94 }
95
96 int expectedFrames = measure_time*expected_frequency;
97 ROBOTTESTINGFRAMEWORK_TEST_REPORT(Asserter::format("Received %d frames, expecting %d",
98 frames,
99 expectedFrames));
100 ROBOTTESTINGFRAMEWORK_TEST_FAIL_IF_FALSE(abs(frames-expectedFrames)<tolerance,
101 "checking number of received frames");
102}

◆ setup()

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

Definition at line 49 of file CameraTest.cpp.

49 {
50
51 if(property.check("name"))
52 setName(property.find("name").asString());
53
54 // updating parameters
55 ROBOTTESTINGFRAMEWORK_ASSERT_ERROR_IF_FALSE(property.check("portname"),
56 "The portname must be given as the test paramter!");
57 cameraPortName = property.find("portname").asString();
58 measure_time = property.check("measure_time") ? property.find("measure_time").asInt32() : TIMES;
59 expected_frequency = property.check("expected_frequency") ? property.find("expected_frequency").asInt32() : FREQUENCY;
60 tolerance = property.check("tolerance") ? property.find("tolerance").asInt32() : TOLERANCE;
61
62 // opening port
63 ROBOTTESTINGFRAMEWORK_ASSERT_ERROR_IF_FALSE(port.open("/CameraTest/image:i"),
64 "opening port, is YARP network available?");
65
66 ROBOTTESTINGFRAMEWORK_TEST_REPORT(Asserter::format("Listening to camera for %d seconds",
67 measure_time));
68
69 // connecting
70 ROBOTTESTINGFRAMEWORK_TEST_REPORT(Asserter::format("connecting from %s to %s",
71 port.getName().c_str(), cameraPortName.c_str()));
72 ROBOTTESTINGFRAMEWORK_ASSERT_ERROR_IF_FALSE(Network::connect(cameraPortName, port.getName()),
73 "could not connect to remote port, camera unavailable");
74 return true;
75}

◆ tearDown()

void CameraTest::tearDown ( )
virtual

Definition at line 77 of file CameraTest.cpp.

77 {
78 Network::disconnect(cameraPortName, port.getName());
79 port.close();
80}

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