YARP
Yet Another Robot Platform
Loading...
Searching...
No Matches
INavigation2DTest.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 INAVIGATION2DTEST_H
7
#define INAVIGATION2DTEST_H
8
9
#include <
yarp/dev/IMap2D.h
>
10
#include <
yarp/dev/INavigation2D.h
>
11
#include <catch2/catch_amalgamated.hpp>
12
13
using namespace
yarp::dev
;
14
using namespace
yarp::dev::Nav2D
;
15
using namespace
yarp::sig
;
16
using namespace
yarp::os
;
17
18
namespace
yarp::dev::tests
19
{
20
inline
void
test_similar_angles
(
INavigation2D
*
inav
,
double
angle1
,
double
angle2
)
21
{
22
bool
b0
,
b1
;
23
b0
=
inav
->setInitialPose(
Map2DLocation
(
"map_1"
, 10.2, 20.1,
angle1
));
CHECK
(
b0
);
24
yarp::os::Time::delay
(0.1);
25
INFO
(
"Testing angle"
+ std::to_string(
angle1
) +
" is similar to:"
+ std::to_string(
angle2
));
26
b1
=
inav
->checkNearToLocation(
Map2DLocation
(
"map_1"
, 10.2, 20.1,
angle2
), 0.1, 10.0);
CHECK
(
b1
);
27
//yInfo() << "Testing angle" << angle1 << " is similar to:" << angle2 + 5.0;
28
b1
=
inav
->checkNearToLocation(
Map2DLocation
(
"map_1"
, 10.2, 20.1,
angle2
+ 5.0), 0.1, 10.0);
CHECK
(
b1
);
29
//yInfo() << "Testing angle" << angle1 << " is different from:" << angle2 + 20.0;
30
b1
=
inav
->checkNearToLocation(
Map2DLocation
(
"map_1"
, 10.2, 20.1,
angle2
+ 20.0), 0.1, 10.0);
CHECK
(!
b1
);
31
//yInfo() << "Testing angle" << angle1 << " is similar to:" << angle2 - 5.0;
32
b1
=
inav
->checkNearToLocation(
Map2DLocation
(
"map_1"
, 10.2, 20.1,
angle2
- 5.0), 0.1, 10.0);
CHECK
(
b1
);
33
//yInfo() << "Testing angle" << angle1 << " is different from:" << angle2 - 20.0;
34
b1
=
inav
->checkNearToLocation(
Map2DLocation
(
"map_1"
, 10.2, 20.1,
angle2
- 20.0), 0.1, 10.0);
CHECK
(!
b1
);
35
}
36
37
inline
void
exec_iNav2D_test_1
(
INavigation2D
*
inav
,
IMap2D
*
imap
)
38
{
40
Map2DLocation
loc_test
=
Map2DLocation
(
"map_1"
, 10.0, 20.0, 15);
41
Map2DLocation
my_current_loc
=
Map2DLocation
(
"map_1"
, 10.2, 20.1, 15.5);
42
Map2DLocation
loc_to_be_tested
;
43
Map2DArea
area_test
(
"map_1"
, std::vector<Map2DLocation> {
Map2DLocation
(
"map_1"
, -10, -10, 0),
44
Map2DLocation
(
"map_1"
, -10, +10, 0),
45
Map2DLocation
(
"map_1"
, +10, +10, 0),
46
Map2DLocation
(
"map_1"
, +10, -10, 0)},
"this is a test area"
);
47
bool
b0
,
b1
;
48
b0
=
imap
->storeArea(
"area_test"
,
area_test
);
CHECK
(
b0
);
49
b0
=
imap
->storeLocation(
"loc_test"
,
loc_test
);
CHECK
(
b0
);
50
51
{
52
b0
=
inav
->setInitialPose(
my_current_loc
);
CHECK
(
b0
);
53
yarp::os::Time::delay
(0.1);
54
b0
=
inav
->getCurrentPosition(
loc_to_be_tested
);
CHECK
(
b0
);
CHECK
(
loc_to_be_tested
==
my_current_loc
);
55
b1
=
inav
->checkInsideArea(
"area_test"
);
CHECK
(
b1
==
false
);
56
b1
=
inav
->checkInsideArea(
area_test
);
CHECK
(
b1
==
false
);
57
b0
=
inav
->setInitialPose(
Map2DLocation
(
"map_1"
, 0, 0, 0));
CHECK
(
b0
);
58
yarp::os::Time::delay
(0.1);
59
b0
=
inav
->getCurrentPosition(
loc_to_be_tested
);
CHECK
(
loc_to_be_tested
==
Map2DLocation
(
"map_1"
, 0, 0, 0));
60
b1
=
inav
->checkInsideArea(
"area_test"
);
CHECK
(
b1
);
61
b1
=
inav
->checkInsideArea(
area_test
);
CHECK
(
b1
);
62
}
63
64
{
65
double
lin_tol
= 1.0;
//m
66
double
ang_tol
= 1.0;
//deg
67
b0
=
inav
->setInitialPose(
my_current_loc
);
CHECK
(
b0
);
68
yarp::os::Time::delay
(0.1);
69
b1
=
inav
->checkNearToLocation(
"loc_test"
,
lin_tol
,
ang_tol
);
CHECK
(
b1
);
70
b1
=
inav
->checkNearToLocation(
loc_test
,
lin_tol
,
ang_tol
);
CHECK
(
b1
);
71
}
72
{
73
double
lin_tol
= 0.0001;
//m
74
double
ang_tol
= 0.0001;
//deg
75
b0
=
inav
->setInitialPose(
my_current_loc
);
CHECK
(
b0
);
76
yarp::os::Time::delay
(0.1);
77
b1
=
inav
->checkNearToLocation(
"loc_test"
,
lin_tol
,
ang_tol
);
CHECK
(
b1
==
false
);
78
b1
=
inav
->checkNearToLocation(
loc_test
,
lin_tol
,
ang_tol
);
CHECK
(
b1
==
false
);
79
}
80
{
81
double
lin_tol
= 1.0;
//m
82
Map2DLocation
my_current_loc2
=
my_current_loc
;
my_current_loc2
.theta = 90;
83
b0
=
inav
->setInitialPose(
my_current_loc2
);
CHECK
(
b0
);
84
yarp::os::Time::delay
(0.1);
85
b1
=
inav
->checkNearToLocation(
"loc_test"
,
lin_tol
);
CHECK
(
b1
);
86
b1
=
inav
->checkNearToLocation(
loc_test
,
lin_tol
);
CHECK
(
b1
);
87
}
88
{
89
double
lin_tol
= 0.1;
//m
90
double
ang_tol
= 0.1;
//deg
91
b0
=
inav
->setInitialPose(
my_current_loc
);
CHECK
(
b0
);
yarp::os::Time::delay
(0.1);
92
b1
=
inav
->checkNearToLocation(
Map2DLocation
(
"map_1"
, 10.2, 20.1, 15.5),
lin_tol
,
ang_tol
);
CHECK
(
b1
);
93
b1
=
inav
->checkNearToLocation(
Map2DLocation
(
"map_1"
, 10.2, 20.1, 15.5 + 180),
lin_tol
,
ang_tol
);
CHECK
(
b1
==
false
);
94
b1
=
inav
->checkNearToLocation(
Map2DLocation
(
"map_1"
, 10.2, 20.1, 15.5 + 360),
lin_tol
,
ang_tol
);
CHECK
(
b1
);
95
b1
=
inav
->checkNearToLocation(
Map2DLocation
(
"map_1"
, 10.2, 20.1, 15.5 + 720),
lin_tol
,
ang_tol
);
CHECK
(
b1
);
96
b1
=
inav
->checkNearToLocation(
Map2DLocation
(
"map_1"
, 10.2, 20.1, 15.5 - 180),
lin_tol
,
ang_tol
);
CHECK
(
b1
==
false
);
97
b1
=
inav
->checkNearToLocation(
Map2DLocation
(
"map_1"
, 10.2, 20.1, 15.5 - 360),
lin_tol
,
ang_tol
);
CHECK
(
b1
);
98
b1
=
inav
->checkNearToLocation(
Map2DLocation
(
"map_1"
, 10.2, 20.1, 15.5 - 720),
lin_tol
,
ang_tol
);
CHECK
(
b1
);
99
100
//in the following tests, the tolerance is set to 10.0 deg
101
test_similar_angles
(
inav
, +2.0, +2.0);
102
test_similar_angles
(
inav
, -2.0, +2.0);
103
test_similar_angles
(
inav
, +2.0, -2.0);
104
test_similar_angles
(
inav
, -2.0, -2.0);
105
106
test_similar_angles
(
inav
, +182.0, +182.0);
107
test_similar_angles
(
inav
, -182.0, +182.0);
108
test_similar_angles
(
inav
, +182.0, -182.0);
109
test_similar_angles
(
inav
, -182.0, -182.0);
110
111
test_similar_angles
(
inav
, 2.0, 358.0);
112
test_similar_angles
(
inav
, -2.0, 358.0);
113
test_similar_angles
(
inav
, 2.0, -358.0);
114
test_similar_angles
(
inav
, -2.0, -358.0);
115
116
test_similar_angles
(
inav
, +2.0, 718.0);
117
test_similar_angles
(
inav
, -2.0, 718.0);
118
test_similar_angles
(
inav
, +2.0, -718.0);
119
test_similar_angles
(
inav
, -2.0, -718.0);
120
}
121
{
122
b0
=
inav
->setInitialPose(
my_current_loc
);
CHECK
(
b0
);
yarp::os::Time::delay
(0.1);
123
yarp::dev::OdometryData
my_current_odom
;
124
b1
=
inav
->getEstimatedOdometry(
my_current_odom
);
CHECK
(
b1
);
125
INFO
(
"Current position is:"
+
my_current_loc
.toString());
126
INFO
(
"Estimated Odometry is:"
+
my_current_odom
.toString());
127
bool
bodom
=
fabs
(
my_current_loc
.x -
my_current_odom
.odom_x) < 0.0000001 &&
128
fabs
(
my_current_loc
.y -
my_current_odom
.odom_y) < 0.0000001 &&
129
fabs
(
my_current_loc
.theta -
my_current_odom
.odom_theta) < 0.0000001;
130
CHECK
(
bodom
);
131
}
132
}
133
134
inline
void
exec_iNav2D_test_2
(
INavigation2D
*
inav
,
IMap2D
*
imap
)
135
{
137
bool
b0
,
b1
,
b2
;
138
Map2DLocation
tloc
(
"test"
, 1, 2, 3);
139
Map2DLocation
gloc1
;
140
Map2DLocation
gloc_empty
;
141
std::string
tname
(
"testLoc"
);
142
std::string
gname1
;
143
NavigationStatusEnum
gstat1
;
144
145
b0
=
inav
->storeLocation(
tname
,
tloc
);
CHECK
(
b0
);
146
147
//going to a location by absolute value
148
b1
=
inav
->stopNavigation();
CHECK
(
b1
);
149
b1
=
inav
->getNavigationStatus(
gstat1
);
CHECK
(
b1
);
CHECK
(
gstat1
== NavigationStatusEnum::navigation_status_idle);
150
151
b1
=
inav
->getAbsoluteLocationOfCurrentTarget(
gloc1
);
CHECK
(
b1
);
CHECK
(
gloc1
==
gloc_empty
);
152
b1
=
inav
->getNameOfCurrentTarget(
gname1
);
CHECK
(
b1
);
CHECK
(
gname1
==
""
);
153
b1
=
inav
->gotoTargetByAbsoluteLocation(
tloc
);
CHECK
(
b1
);
154
b1
=
inav
->getAbsoluteLocationOfCurrentTarget(
gloc1
);
CHECK
(
b1
);
CHECK
(
gloc1
==
tloc
);
155
b1
=
inav
->getNameOfCurrentTarget(
gname1
);
CHECK
(
b1
);
CHECK
(
gname1
==
""
);
156
157
//going to an existing location by name
158
b1
=
inav
->stopNavigation();
CHECK
(
b1
);
159
b1
=
inav
->getNavigationStatus(
gstat1
);
CHECK
(
b1
);
CHECK
(
gstat1
== NavigationStatusEnum::navigation_status_idle);
160
161
b1
=
inav
->getAbsoluteLocationOfCurrentTarget(
gloc1
);
CHECK
(
b1
);
CHECK
(
gloc1
==
gloc_empty
);
162
b1
=
inav
->getNameOfCurrentTarget(
gname1
);
CHECK
(
b1
);
CHECK
(
gname1
==
""
);
163
164
b1
=
inav
->gotoTargetByLocationName(
tname
);
CHECK
(
b1
);
165
b1
=
inav
->getAbsoluteLocationOfCurrentTarget(
gloc1
);
CHECK
(
b1
);
CHECK
(
gloc1
==
tloc
);
166
b1
=
inav
->getNameOfCurrentTarget(
gname1
);
CHECK
(
b1
);
CHECK
(
gname1
==
tname
);
167
168
//stop must clear navigation target name
169
b1
=
inav
->stopNavigation();
CHECK
(
b1
);
170
b1
=
inav
->getNavigationStatus(
gstat1
);
CHECK
(
b1
);
CHECK
(
gstat1
== NavigationStatusEnum::navigation_status_idle);
171
b1
=
inav
->getNameOfCurrentTarget(
gname1
);
CHECK
(
b1
);
CHECK
(
gname1
==
""
);
172
173
//trying to goto to a non-existing location by name, target name must be not set
174
b1
=
inav
->gotoTargetByLocationName(
"non-existing-loc"
);
CHECK
(
b1
==
false
);
175
b1
=
inav
->getAbsoluteLocationOfCurrentTarget(
gloc1
);
CHECK
(
b1
);
CHECK
(
gloc1
==
gloc_empty
);
176
b1
=
inav
->getNameOfCurrentTarget(
gname1
);
CHECK
(
b1
);
CHECK
(
gname1
==
""
);
177
178
//mix of last two tests. A non existing location must clear a previously set target name
179
b1
=
inav
->gotoTargetByLocationName(
tname
);
CHECK
(
b1
);
180
b1
=
inav
->getAbsoluteLocationOfCurrentTarget(
gloc1
);
CHECK
(
b1
);
CHECK
(
gloc1
==
tloc
);
181
b1
=
inav
->gotoTargetByLocationName(
"non-existing-loc"
);
CHECK
(
b1
==
false
);
182
b1
=
inav
->getAbsoluteLocationOfCurrentTarget(
gloc1
);
CHECK
(
b1
);
CHECK
(
gloc1
==
gloc_empty
);
183
}
184
185
inline
void
exec_iNav2D_test_3
(
INavigation2DTargetActions
*
inav_trgt
,
INavigation2DControlActions
*
inav_ctl
)
186
{
188
bool
b;
189
Map2DLocation
loc(
"test"
, 1, 2, 3);
190
yarp::dev::Nav2D::NavigationStatusEnum
status;
191
192
b =
inav_ctl
->getNavigationStatus(status);
CHECK
(b);
193
CHECK
(status==
yarp::dev::Nav2D::NavigationStatusEnum::navigation_status_idle
);
194
195
b =
inav_trgt
->gotoTargetByAbsoluteLocation(loc);
CHECK
(b);
196
b =
inav_ctl
->getNavigationStatus(status);
CHECK
(b);
197
CHECK
(status ==
yarp::dev::Nav2D::NavigationStatusEnum::navigation_status_moving
);
198
199
size_t
count=0;
200
do
201
{
202
b =
inav_ctl
->getNavigationStatus(status);
CHECK
(b);
203
if
(status ==
yarp::dev::Nav2D::NavigationStatusEnum::navigation_status_goal_reached
)
204
{
205
break
;
206
}
207
yarp::os::Time::delay
(0.1);
208
count++;
209
if
(count>200) {
CHECK
(0);
break
; }
210
}
211
while
(1);
212
213
count = 0;
214
do
215
{
216
b =
inav_ctl
->getNavigationStatus(status);
CHECK
(b);
217
if
(status ==
yarp::dev::Nav2D::NavigationStatusEnum::navigation_status_idle
)
218
{
219
break
;
220
}
221
yarp::os::Time::delay
(0.1);
222
count++;
223
if
(count > 200) {
CHECK
(0);
break
; }
224
}
while
(1);
225
226
//test complete
227
}
228
}
229
230
#endif
IMap2D.h
INavigation2D.h
yarp::dev::Nav2D::IMap2D
IMap2D Interface.
Definition
IMap2D.h:29
yarp::dev::Nav2D::INavigation2DControlActions
Definition
INavigation2D.h:150
yarp::dev::Nav2D::INavigation2DTargetActions
Definition
INavigation2D.h:94
yarp::dev::Nav2D::INavigation2D
An interface to control the navigation of a mobile robot in a 2D environment.
Definition
INavigation2D.h:286
yarp::dev::Nav2D::Map2DArea
Definition
Map2DArea.h:23
yarp::dev::OdometryData
Definition
OdometryData.h:23
yarp::os::BufferedPort
A mini-server for performing network communication in the background.
Definition
BufferedPort.h:60
yarp::dev::Nav2D
Definition
ILocalization2D.h:16
yarp::dev::Nav2D::NavigationStatusEnum
NavigationStatusEnum
Definition
INavigation2D.h:29
yarp::dev::Nav2D::navigation_status_goal_reached
@ navigation_status_goal_reached
Definition
INavigation2D.h:34
yarp::dev::Nav2D::navigation_status_idle
@ navigation_status_idle
Definition
INavigation2D.h:30
yarp::dev::Nav2D::navigation_status_moving
@ navigation_status_moving
Definition
INavigation2D.h:32
yarp::dev::tests
Definition
IAxisInfoTest.h:16
yarp::dev::tests::exec_iNav2D_test_1
void exec_iNav2D_test_1(INavigation2D *inav, IMap2D *imap)
Definition
INavigation2DTest.h:37
yarp::dev::tests::exec_iNav2D_test_3
void exec_iNav2D_test_3(INavigation2DTargetActions *inav_trgt, INavigation2DControlActions *inav_ctl)
Definition
INavigation2DTest.h:185
yarp::dev::tests::exec_iNav2D_test_2
void exec_iNav2D_test_2(INavigation2D *inav, IMap2D *imap)
Definition
INavigation2DTest.h:134
yarp::dev::tests::test_similar_angles
void test_similar_angles(INavigation2D *inav, double angle1, double angle2)
Definition
INavigation2DTest.h:20
yarp::dev
For streams capable of holding different kinds of content, check what they actually have.
Definition
jointData.cpp:13
yarp::os::Time::delay
void delay(double seconds)
Wait for a certain number of seconds.
Definition
Time.cpp:111
yarp::os
An interface to the operating system, including Port based communication.
Definition
AbstractCarrier.h:13
yarp::sig
Definition
audioBufferSizeData.cpp:13
yarp::dev::Nav2D::Map2DLocation
Definition
Map2DLocation.h:22
YARP
3.9.0+239-20241014.1+git1a16d4b8b
src
libYARP_dev
src
yarp
dev
tests
INavigation2DTest.h
Generated on Tue Oct 15 2024 02:31:52 for YARP by
1.9.8