-
Notifications
You must be signed in to change notification settings - Fork 30
/
test_OMPLPlanner.cpp
360 lines (305 loc) · 13.1 KB
/
test_OMPLPlanner.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
#include "OMPLTestHelpers.hpp"
#include "../../constraint/MockConstraints.hpp"
#include <aikido/planner/ompl/Planner.hpp>
#include <aikido/constraint/uniform/RealVectorBoxConstraint.hpp>
#include <aikido/constraint/SampleableSubSpace.h>
#include <aikido/constraint/TestableSubSpace.hpp>
#include <aikido/constraint/dart.hpp>
#include <ompl/geometric/planners/rrt/RRTConnect.h>
using StateSpace = aikido::statespace::dart::MetaSkeletonStateSpace;
using Rn = aikido::statespace::Rn;
using aikido::planner::ompl::getSpaceInformation;
TEST_F(PlannerTest, PlanToConfiguration)
{
Eigen::Vector3d startPose(-5, -5, 0);
Eigen::Vector3d goalPose(5, 5, 0);
auto startState = stateSpace->createState();
auto subState1 =
stateSpace->getSubStateHandle<Rn>(startState, 0);
subState1.setValue(startPose);
auto goalState = stateSpace->createState();
auto subState2 =
stateSpace->getSubStateHandle<Rn>(goalState, 0);
subState2.setValue(goalPose);
// Plan
auto traj = aikido::planner::ompl::planOMPL<ompl::geometric::RRTConnect>(
startState, goalState, stateSpace, interpolator, std::move(dmetric),
std::move(sampler), std::move(collConstraint),
std::move(boundsConstraint), std::move(boundsProjection), 5.0);
// Check the first waypoint
auto s0 = stateSpace->createState();
traj->evaluate(0, s0);
auto r0 = s0.getSubStateHandle<Rn>(0);
EXPECT_TRUE(r0.getValue().isApprox(startPose));
// Check the last waypoint
traj->evaluate(traj->getDuration(), s0);
r0 = s0.getSubStateHandle<Rn>(0);
EXPECT_TRUE(r0.getValue().isApprox(goalPose));
}
TEST_F(PlannerTest, PlanToGoalRegion)
{
auto startState = stateSpace->createState();
Eigen::Vector3d startPose(-5, -5, 0);
auto subState1 =
stateSpace->getSubStateHandle<Rn>(startState, 0);
subState1.setValue(startPose);
auto boxConstraint =
std::make_shared<aikido::statespace::RealVectorBoxConstraint>(
stateSpace->getSubSpace<Rn>(0), make_rng(),
Eigen::Vector3d(4, 4, 0), Eigen::Vector3d(5, 5, 0));
std::vector<std::shared_ptr<aikido::constraint::SampleableConstraint>>
sConstraints;
sConstraints.push_back(boxConstraint);
aikido::constraint::SampleableConstraintPtr goalSampleable =
std::make_shared<aikido::constraint::SampleableSubSpace>(stateSpace,
sConstraints);
std::vector<std::shared_ptr<aikido::constraint::TestableConstraint>>
tConstraints;
tConstraints.push_back(boxConstraint);
aikido::constraint::TestableConstraintPtr goalTestable =
std::make_shared<aikido::constraint::TestableSubSpace>(stateSpace,
tConstraints);
// Plan
auto traj = aikido::planner::ompl::planOMPL<ompl::geometric::RRTConnect>(
startState, goalTestable, goalSampleable, stateSpace, interpolator,
std::move(dmetric), std::move(sampler), std::move(collConstraint),
std::move(boundsConstraint), std::move(boundsProjection), 5.0);
// Check the first waypoint
auto s0 = stateSpace->createState();
traj->evaluate(0, s0);
auto r0 = s0.getSubStateHandle<Rn>(0);
EXPECT_TRUE(r0.getValue().isApprox(startPose));
// Check the last waypoint
traj->evaluate(traj->getDuration(), s0);
EXPECT_TRUE(goalTestable->isSatisfied(s0));
}
TEST_F(PlannerTest, PlanThrowsOnNullGoalTestable)
{
auto startState = stateSpace->createState();
Eigen::Vector3d startPose(-5, -5, 0);
auto subState1 =
stateSpace->getSubStateHandle<Rn>(startState, 0);
subState1.setValue(startPose);
// Easiest sampleable to get
auto goalSampleable =
aikido::constraint::createSampleableBounds(stateSpace, make_rng());
// Plan
EXPECT_THROW(aikido::planner::ompl::planOMPL<ompl::geometric::RRTConnect>(
startState, nullptr, std::move(goalSampleable), stateSpace,
interpolator, std::move(dmetric), std::move(sampler),
std::move(collConstraint), std::move(boundsConstraint),
std::move(boundsProjection), 5.0),
std::invalid_argument);
}
TEST_F(PlannerTest, PlanThrowsOnGoalTestableMismatch)
{
auto startState = stateSpace->createState();
Eigen::Vector3d startPose(-5, -5, 0);
auto subState1 =
stateSpace->getSubStateHandle<Rn>(startState, 0);
subState1.setValue(startPose);
// Easiest sampleable to get
auto goalSampleable =
aikido::constraint::createSampleableBounds(stateSpace, make_rng());
// Easiest testable to get
auto ss = std::make_shared<StateSpace>(robot);
auto goalTestable = std::make_shared<PassingConstraint>(ss);
// Plan
EXPECT_THROW(
aikido::planner::ompl::planOMPL<ompl::geometric::RRTConnect>(
startState, goalTestable, std::move(goalSampleable), stateSpace,
interpolator, std::move(dmetric), std::move(sampler),
std::move(collConstraint), std::move(boundsConstraint),
std::move(boundsProjection), 5.0),
std::invalid_argument);
}
TEST_F(PlannerTest, PlanThrowsOnNullGoalSampler)
{
auto startState = stateSpace->createState();
Eigen::Vector3d startPose(-5, -5, 0);
auto subState1 =
stateSpace->getSubStateHandle<Rn>(startState, 0);
subState1.setValue(startPose);
// Dummy testable
auto goalTestable = std::make_shared<PassingConstraint>(stateSpace);
// Plan
EXPECT_THROW(
aikido::planner::ompl::planOMPL<ompl::geometric::RRTConnect>(
startState, goalTestable, nullptr, stateSpace, interpolator,
std::move(dmetric), std::move(sampler), std::move(collConstraint),
std::move(boundsConstraint), std::move(boundsProjection), 5.0),
std::invalid_argument);
}
TEST_F(PlannerTest, PlanThrowsOnGoalSamplerMismatch)
{
auto startState = stateSpace->createState();
Eigen::Vector3d startPose(-5, -5, 0);
auto subState1 =
stateSpace->getSubStateHandle<Rn>(startState, 0);
subState1.setValue(startPose);
// Easiest sampleable to get
auto ss = std::make_shared<StateSpace>(robot);
auto goalSampleable =
aikido::constraint::createSampleableBounds(ss, make_rng());
// Dummy testable
auto goalTestable = std::make_shared<PassingConstraint>(stateSpace);
// Plan
EXPECT_THROW(
aikido::planner::ompl::planOMPL<ompl::geometric::RRTConnect>(
startState, goalTestable, std::move(goalSampleable), stateSpace,
interpolator, std::move(dmetric), std::move(sampler),
std::move(collConstraint), std::move(boundsConstraint),
std::move(boundsProjection), 5.0),
std::invalid_argument);
}
TEST_F(PlannerTest, GetSpaceInformationThrowsOnNullStateSpace)
{
EXPECT_THROW(getSpaceInformation(
nullptr, std::move(interpolator), std::move(dmetric),
std::move(sampler), std::move(collConstraint),
std::move(boundsConstraint), std::move(boundsProjection)),
std::invalid_argument);
}
TEST_F(PlannerTest, GetSpaceInformationThrowsOnNullInterpolator)
{
EXPECT_THROW(getSpaceInformation(
std::move(stateSpace), nullptr, std::move(dmetric),
std::move(sampler), std::move(collConstraint),
std::move(boundsConstraint), std::move(boundsProjection)),
std::invalid_argument);
}
TEST_F(PlannerTest, GetSpaceInformationThrowsOnInterpolatorMismatch)
{
auto ss = std::make_shared<aikido::statespace::SO2>();
auto binterpolator =
std::make_shared<aikido::statespace::GeodesicInterpolator>(ss);
EXPECT_THROW(
getSpaceInformation(
std::move(stateSpace), std::move(binterpolator), std::move(dmetric),
std::move(sampler), std::move(collConstraint),
std::move(boundsConstraint), std::move(boundsProjection)),
std::invalid_argument);
}
TEST_F(PlannerTest, GetSpaceInformationThrowsOnNullDistanceMetric)
{
EXPECT_THROW(getSpaceInformation(
std::move(stateSpace), std::move(interpolator), nullptr,
std::move(sampler), std::move(collConstraint),
std::move(boundsConstraint), std::move(boundsProjection)),
std::invalid_argument);
}
TEST_F(PlannerTest, GetSpaceInformationThrowsOnDistanceMetricMismatch)
{
auto ss = std::make_shared<StateSpace>(robot);
auto dm = aikido::distance::createDistanceMetric(ss);
EXPECT_THROW(getSpaceInformation(
std::move(stateSpace), std::move(interpolator),
std::move(dm), std::move(sampler), std::move(collConstraint),
std::move(boundsConstraint), std::move(boundsProjection)),
std::invalid_argument);
}
TEST_F(PlannerTest, GetSpaceInformationThrowsOnNullSampler)
{
EXPECT_THROW(getSpaceInformation(
std::move(stateSpace), std::move(interpolator),
std::move(dmetric), nullptr, std::move(collConstraint),
std::move(boundsConstraint), std::move(boundsProjection)),
std::invalid_argument);
}
TEST_F(PlannerTest, GetSpaceInformationThrowsOnSamplerMismatch)
{
auto ss = std::make_shared<StateSpace>(robot);
auto ds = aikido::constraint::createSampleableBounds(ss, make_rng());
EXPECT_THROW(getSpaceInformation(
std::move(stateSpace), std::move(interpolator),
std::move(dmetric), std::move(ds), std::move(collConstraint),
std::move(boundsConstraint), std::move(boundsProjection)),
std::invalid_argument);
}
TEST_F(PlannerTest, GetSpaceInformationThrowsOnNullValidityConstraint)
{
EXPECT_THROW(getSpaceInformation(
std::move(stateSpace), std::move(interpolator),
std::move(dmetric), std::move(sampler), nullptr,
std::move(boundsConstraint), std::move(boundsProjection)),
std::invalid_argument);
}
TEST_F(PlannerTest, GetSpaceInformationThrowsOnValidityConstraintMismatch)
{
auto ss = std::make_shared<StateSpace>(robot);
auto dv = std::make_shared<MockTranslationalRobotConstraint>(
ss, Eigen::Vector3d(-0.1, -0.1, -0.1), Eigen::Vector3d(0.1, 0.1, 0.1));
EXPECT_THROW(getSpaceInformation(
std::move(stateSpace), std::move(interpolator),
std::move(dmetric), std::move(sampler), std::move(dv),
std::move(boundsConstraint), std::move(boundsProjection)),
std::invalid_argument);
}
TEST_F(PlannerTest, GetSpaceInformationThrowsOnNullBoundsConstraint)
{
EXPECT_THROW(
getSpaceInformation(std::move(stateSpace), std::move(interpolator),
std::move(dmetric), std::move(sampler),
std::move(collConstraint), nullptr,
std::move(boundsProjection)),
std::invalid_argument);
}
TEST_F(PlannerTest, GetSpaceInformationThrowsOnBoundsConstraintMismatch)
{
auto ss = std::make_shared<StateSpace>(robot);
auto ds = aikido::constraint::createTestableBounds(ss);
EXPECT_THROW(
getSpaceInformation(std::move(stateSpace), std::move(interpolator),
std::move(dmetric), std::move(sampler),
std::move(collConstraint), std::move(ds),
std::move(boundsProjection)),
std::invalid_argument);
}
TEST_F(PlannerTest, GetSpaceInformationThrowsOnNullBoundsProjector)
{
EXPECT_THROW(
getSpaceInformation(std::move(stateSpace), std::move(interpolator),
std::move(dmetric), std::move(sampler),
std::move(collConstraint),
std::move(boundsConstraint), nullptr),
std::invalid_argument);
}
TEST_F(PlannerTest, GetSpaceInformationThrowsOnBoundsProjectorMismatch)
{
auto ss = std::make_shared<StateSpace>(robot);
auto ds = aikido::constraint::createProjectableBounds(ss);
EXPECT_THROW(
getSpaceInformation(std::move(stateSpace), std::move(interpolator),
std::move(dmetric), std::move(sampler),
std::move(collConstraint),
std::move(boundsConstraint), std::move(ds)),
std::invalid_argument);
}
TEST_F(PlannerTest, GetSpaceInformationNotNull)
{
auto si = getSpaceInformation(
std::move(stateSpace), std::move(interpolator), std::move(dmetric),
std::move(sampler), std::move(collConstraint),
std::move(boundsConstraint), std::move(boundsProjection));
EXPECT_FALSE(si == nullptr);
}
TEST_F(PlannerTest, GetSpaceInformationCreatesGeometricStateSpace)
{
auto si = getSpaceInformation(
std::move(stateSpace), std::move(interpolator), std::move(dmetric),
std::move(sampler), std::move(collConstraint),
std::move(boundsConstraint), std::move(boundsProjection));
auto ss = boost::dynamic_pointer_cast<aikido::planner::ompl::GeometricStateSpace>(
si->getStateSpace());
EXPECT_FALSE(ss == nullptr);
}
TEST_F(PlannerTest, GetSpaceInformationCreatesValidityChecker)
{
auto si = getSpaceInformation(
std::move(stateSpace), std::move(interpolator), std::move(dmetric),
std::move(sampler), std::move(collConstraint),
std::move(boundsConstraint), std::move(boundsProjection));
auto vc = boost::dynamic_pointer_cast<aikido::planner::ompl::StateValidityChecker>(
si->getStateValidityChecker());
EXPECT_FALSE(vc == nullptr);
}