YARP
Yet Another Robot Platform
 
Loading...
Searching...
No Matches
IRangefinder2DTest.h
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2006-2021 Istituto Italiano di Tecnologia (IIT)
3 * SPDX-License-Identifier: BSD-3-Clause
4 */
5
6#ifndef IRANGEFINDER2DTEST_H
7#define IRANGEFINDER2DTEST_H
8
10#include <catch2/catch_amalgamated.hpp>
12#include <yarp/os/LogStream.h>
13
14using namespace yarp::dev;
15using namespace yarp::sig;
16using namespace yarp::os;
17
18namespace yarp::dev::tests
19{
21 {
22 double test_scanrate = 0.02;
23 double test_horizontal_res = 1.0;
24 double test_min=0.1;
25 double test_max=8.0;
26 size_t test_lsize=360;
27 double test_cartesian_x=0.5;
29 double test_theta=0;
30 double test_rho=0.5;
31 double min_angle=0;
32 double max_angle=360;
33 };
34
36 {
37 REQUIRE(irf != nullptr);
38
39 bool b;
40
41 // wait for the device to be ready
43 for (size_t counter = 0; counter<10; counter++)
44 {
45 b = irf->getDeviceStatus(status);
46 CHECK(b);
48 yDebug() << "Device not ready yet, retrying..";
50 }
52
53 std::string info;
54 b = irf->getDeviceInfo(info);
55 CHECK(b);
56 CHECK(!info.empty());
57
58 double scanrate;
59 b = irf->getScanRate(scanrate);
60 CHECK(b);
61 CHECK(scanrate==v.test_scanrate);
62
63 double min_angle, max_angle;
64 b = irf->getScanLimits(min_angle, max_angle);
65 CHECK(b);
66 CHECK(min_angle == v.min_angle);
67 CHECK(max_angle == v.max_angle);
68
69 double hstep;
70 b = irf->getHorizontalResolution(hstep);
71 CHECK(b);
72 CHECK(hstep == v.test_horizontal_res);
73
74 double min,max;
75 b = irf->getDistanceRange(min,max);
76 CHECK(b);
77 CHECK(min == v.test_min);
78 CHECK(max == v.test_max);
79
80 std::vector<yarp::sig::LaserMeasurementData> las;
81 double timestamp;
82 b = irf->getLaserMeasurement(las, &timestamp);
83 CHECK(b);
84 CHECK(timestamp != 0);
85 CHECK(las.size() == v.test_lsize);
86
87 //check the measurement values.
88 //REQUIRE is needed to prevent segfault if nothing is received.
89 {
90 REQUIRE(las.size() > 0);
91 double r,t;
92 las[0].get_polar(r, t);
95 }
96 {
97 REQUIRE(las.size() > 0);
98 double x,y;
99 las[0].get_cartesian(x, y);
100 CHECK(yarp::dev::tests::check_approximate(x, v.test_cartesian_x));
101 CHECK(yarp::dev::tests::check_approximate(y, v.test_cartesian_y));
102 }
103
104 }
105}
106
107#endif
#define yDebug(...)
Definition Log.h:275
A generic interface for planar laser range finders.
A mini-server for performing network communication in the background.
bool check_approximate(double value, double expected, double tolerance)
Definition TestUtils.cpp:33
void exec_iRangefinder2D_test_1(IRangefinder2D *irf, const ValuestoCheck &v=ValuestoCheck())
For streams capable of holding different kinds of content, check what they actually have.
void delay(double seconds)
Wait for a certain number of seconds.
Definition Time.cpp:111
An interface to the operating system, including Port based communication.
Definition OSTestMsg.cpp:13