Skip to content

Commit 76fe34d

Browse files
committed
- Improved tests for IRangefinder2D
- Fixed issue in LaserScan2D.thrift
1 parent 7db2b74 commit 76fe34d

File tree

2 files changed

+29
-14
lines changed

2 files changed

+29
-14
lines changed

src/libYARP_dev/src/idl/LaserScan2D.thrift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@ struct LaserScan2D
2929
/** the scan data, measured in [m]. The angular increment of each ray is obtained by (angle_max-angle_min)/num_of_elements. Invalid data are represented as std::inf. */
3030
5: YarpVector scans;
3131

32-
6: i32 status;
32+
/** the status of the device. See yarp::dev::IRangefinder2D::Device_status. The default value is DEVICE_TIMEOUT. */
33+
6: i32 status=3;
3334
}
3435
(
3536
yarp.api.include = "yarp/dev/api.h"

src/libYARP_dev/src/yarp/dev/tests/IRangefinder2DTest.h

Lines changed: 27 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,16 @@ namespace yarp::dev::tests
2121

2222
bool b;
2323

24+
yarp::dev::IRangefinder2D::Device_status status;
25+
for (size_t counter = 0; counter<10; counter++)
26+
{
27+
b = irf->getDeviceStatus(status);
28+
CHECK(b);
29+
if (status == yarp::dev::IRangefinder2D::Device_status::DEVICE_OK_IN_USE) break;
30+
yarp::os::Time::delay(0.5);
31+
}
32+
CHECK(status == yarp::dev::IRangefinder2D::Device_status::DEVICE_OK_IN_USE);
33+
2434
std::string info;
2535
b = irf->getDeviceInfo(info);
2636
CHECK(b);
@@ -31,11 +41,6 @@ namespace yarp::dev::tests
3141
CHECK(b);
3242
CHECK(scanrate==0.02);
3343

34-
yarp::dev::IRangefinder2D::Device_status status;
35-
b = irf->getDeviceStatus(status);
36-
CHECK(b);
37-
CHECK(status== yarp::dev::IRangefinder2D::Device_status::DEVICE_OK_IN_USE);
38-
3944
double hstep;
4045
b = irf->getHorizontalResolution(hstep);
4146
CHECK(b);
@@ -53,14 +58,23 @@ namespace yarp::dev::tests
5358
CHECK(b);
5459
CHECK(timestamp != 0);
5560
CHECK(las.size() == 360);
56-
{double r,t;
57-
las[0].get_polar(r, t);
58-
CHECK(r == 0.5);
59-
CHECK(t == 0);}
60-
{double x,y;
61-
las[0].get_cartesian(x, y);
62-
CHECK(x == 0.5);
63-
CHECK(y == 0);}
61+
62+
//check the measurement values.
63+
//REQUIRE is needed to prevent segfault if nothing is received.
64+
{
65+
REQUIRE(las.size() > 0);
66+
double r,t;
67+
las[0].get_polar(r, t);
68+
CHECK(r == 0.5);
69+
CHECK(t == 0);
70+
}
71+
{
72+
REQUIRE(las.size() > 0);
73+
double x,y;
74+
las[0].get_cartesian(x, y);
75+
CHECK(x == 0.5);
76+
CHECK(y == 0);
77+
}
6478

6579
}
6680
}

0 commit comments

Comments
 (0)