moveit2
The MoveIt Motion Planning Framework for ROS 2.
Loading...
Searching...
No Matches
test_constant_features_with_move_group.cpp
Go to the documentation of this file.
1// Copyright 2024 Intrinsic Innovation LLC.
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
19#include <memory>
20
21#include <gtest/gtest.h>
22#include <warehouse_ros/message_collection.h>
23
24#include <geometry_msgs/msg/point.hpp>
27
28#include "../fixtures/move_group_fixture.hpp"
29
30namespace
31{
32
33using ::geometry_msgs::msg::Point;
34
35using ::warehouse_ros::MessageCollection;
36using ::warehouse_ros::Metadata;
37using ::warehouse_ros::Query;
38
39using ::moveit_ros::trajectory_cache::QueryOnlyEqFeature;
40using ::moveit_ros::trajectory_cache::QueryOnlyGTEFeature;
41using ::moveit_ros::trajectory_cache::QueryOnlyLTEFeature;
42using ::moveit_ros::trajectory_cache::QueryOnlyRangeInclusiveWithToleranceFeature;
43
44using ::moveit_ros::trajectory_cache::MetadataOnlyFeature;
45
46TEST_F(MoveGroupFixture, MetadataOnlyFeature)
47{
48 MessageCollection<Point> coll = db_->openCollection<Point>("test_db", "test_collection");
49
50 Query::Ptr query = coll.createQuery();
51 Metadata::Ptr metadata = coll.createMetadata();
52 ASSERT_EQ(metadata->lookupFieldNames().size(), 0);
53
54 Point msg;
55
57
58 MetadataOnlyFeature<std::string, Point> string_metadata_feature("string_metadata", "test_string");
59 MetadataOnlyFeature<double, Point> double_metadata_feature("double_metadata", 1.0);
60 MetadataOnlyFeature<int, Point> int_metadata_feature("int_metadata", 2);
61 MetadataOnlyFeature<bool, Point> bool_metadata_feature("bool_metadata", true);
62
63 // Names.
64 EXPECT_EQ(string_metadata_feature.getName(), "MetadataOnlyFeature.string_metadata");
65 EXPECT_EQ(double_metadata_feature.getName(), "MetadataOnlyFeature.double_metadata");
66 EXPECT_EQ(int_metadata_feature.getName(), "MetadataOnlyFeature.int_metadata");
67 EXPECT_EQ(bool_metadata_feature.getName(), "MetadataOnlyFeature.bool_metadata");
68
69 // Expect no-ops.
70 EXPECT_EQ(string_metadata_feature.appendFeaturesAsFuzzyFetchQuery(*query, msg, *move_group_, 0.0),
71 moveit::core::MoveItErrorCode::SUCCESS);
72 EXPECT_EQ(string_metadata_feature.appendFeaturesAsExactFetchQuery(*query, msg, *move_group_, 0.0),
73 moveit::core::MoveItErrorCode::SUCCESS);
74
75 // Fetch ok.
76 string_metadata_feature.appendFeaturesAsInsertMetadata(*metadata, msg, *move_group_);
77 EXPECT_EQ(metadata->lookupFieldNames().size(), 1);
78 EXPECT_TRUE(metadata->lookupField("string_metadata"));
79 EXPECT_EQ(metadata->lookupString("string_metadata"), "test_string");
80
81 double_metadata_feature.appendFeaturesAsInsertMetadata(*metadata, msg, *move_group_);
82 EXPECT_EQ(metadata->lookupFieldNames().size(), 2);
83 EXPECT_TRUE(metadata->lookupField("double_metadata"));
84 EXPECT_EQ(metadata->lookupDouble("double_metadata"), 1.0);
85
86 int_metadata_feature.appendFeaturesAsInsertMetadata(*metadata, msg, *move_group_);
87 EXPECT_EQ(metadata->lookupFieldNames().size(), 3);
88 EXPECT_TRUE(metadata->lookupField("int_metadata"));
89 EXPECT_EQ(metadata->lookupInt("int_metadata"), 2);
90
91 bool_metadata_feature.appendFeaturesAsInsertMetadata(*metadata, msg, *move_group_);
92 EXPECT_EQ(metadata->lookupFieldNames().size(), 4);
93 EXPECT_TRUE(metadata->lookupField("bool_metadata"));
94 EXPECT_TRUE(metadata->lookupBool("bool_metadata"));
95}
96
97TEST_F(MoveGroupFixture, QueryOnlyEqFeature)
98{
99 MessageCollection<Point> coll = db_->openCollection<Point>("test_db", "test_collection");
100
101 Metadata::Ptr metadata = coll.createMetadata();
102 metadata->append("test_metadata", "test_metadata");
103
104 Point msg;
105 coll.insert(msg, metadata);
106
107 QueryOnlyEqFeature<std::string, Point> eq_feature("test_metadata", "test_metadata");
108 QueryOnlyEqFeature<std::string, Point> unrelated_eq_feature("unrelated", "test_metadata");
109 QueryOnlyEqFeature<std::string, Point> mismatched_eq_feature("test_metadata", "mismatched");
110
111 // Names.
112 EXPECT_EQ(eq_feature.getName(), "QueryOnlyEqFeature.test_metadata");
113 EXPECT_EQ(unrelated_eq_feature.getName(), "QueryOnlyEqFeature.unrelated");
114
115 // Expect no-ops.
116 {
117 Metadata::Ptr noop_metadata = coll.createMetadata();
118 eq_feature.appendFeaturesAsInsertMetadata(*noop_metadata, msg, *move_group_);
119 EXPECT_TRUE(noop_metadata->lookupFieldNames().empty());
120 }
121
122 // Match.
123 {
124 Query::Ptr fuzzy_query = coll.createQuery();
125 eq_feature.appendFeaturesAsFuzzyFetchQuery(*fuzzy_query, msg, *move_group_, 0.0);
126 EXPECT_EQ(coll.queryList(fuzzy_query).size(), 1);
127
128 Query::Ptr exact_query = coll.createQuery();
129 eq_feature.appendFeaturesAsExactFetchQuery(*exact_query, msg, *move_group_, 0.0);
130 EXPECT_EQ(coll.queryList(exact_query).size(), 1);
131 }
132
133 // Unrelated. No match.
134 {
135 Query::Ptr fuzzy_query = coll.createQuery();
136 unrelated_eq_feature.appendFeaturesAsFuzzyFetchQuery(*fuzzy_query, msg, *move_group_, 0.0);
137 EXPECT_TRUE(coll.queryList(fuzzy_query).empty());
138
139 Query::Ptr exact_query = coll.createQuery();
140 unrelated_eq_feature.appendFeaturesAsExactFetchQuery(*exact_query, msg, *move_group_, 0.0);
141 EXPECT_TRUE(coll.queryList(exact_query).empty());
142 }
143
144 // Mismatched. No match.
145 {
146 Query::Ptr fuzzy_query = coll.createQuery();
147 mismatched_eq_feature.appendFeaturesAsFuzzyFetchQuery(*fuzzy_query, msg, *move_group_, 0.0);
148 EXPECT_TRUE(coll.queryList(fuzzy_query).empty());
149
150 Query::Ptr exact_query = coll.createQuery();
151 mismatched_eq_feature.appendFeaturesAsExactFetchQuery(*exact_query, msg, *move_group_, 0.0);
152 EXPECT_TRUE(coll.queryList(exact_query).empty());
153 }
154}
155
156TEST_F(MoveGroupFixture, QueryOnlyGTEFeature)
157{
158 MessageCollection<Point> coll = db_->openCollection<Point>("test_db", "test_collection");
159
160 Metadata::Ptr metadata = coll.createMetadata();
161 metadata->append("test_metadata", 5.0);
162
163 Point msg;
164 coll.insert(msg, metadata);
165
166 metadata = coll.createMetadata();
167 metadata->append("unrelated", 5.0);
168 coll.insert(msg, metadata);
169
170 QueryOnlyGTEFeature<double, Point> gte_feature("test_metadata", 4.0);
171 QueryOnlyGTEFeature<double, Point> gte_eq_feature("test_metadata", 5.0);
172 QueryOnlyGTEFeature<double, Point> unrelated_gte_feature("unrelated", 6.0);
173 QueryOnlyGTEFeature<double, Point> mismatched_gte_feature("test_metadata", 6.0);
174
175 // Names.
176 EXPECT_EQ(gte_feature.getName(), "QueryOnlyGTEFeature.test_metadata");
177 EXPECT_EQ(unrelated_gte_feature.getName(), "QueryOnlyGTEFeature.unrelated");
178
179 // Expect no-ops.
180 {
181 Metadata::Ptr metadata = coll.createMetadata();
182 gte_feature.appendFeaturesAsInsertMetadata(*metadata, msg, *move_group_);
183 EXPECT_TRUE(metadata->lookupFieldNames().empty());
184 }
185
186 // Match.
187 {
188 Query::Ptr fuzzy_query = coll.createQuery();
189 gte_feature.appendFeaturesAsFuzzyFetchQuery(*fuzzy_query, msg, *move_group_, 0.0);
190 EXPECT_EQ(coll.queryList(fuzzy_query).size(), 1);
191
192 Query::Ptr exact_query = coll.createQuery();
193 gte_feature.appendFeaturesAsExactFetchQuery(*exact_query, msg, *move_group_, 0.0);
194 EXPECT_EQ(coll.queryList(exact_query).size(), 1);
195 }
196
197 {
198 Query::Ptr fuzzy_query = coll.createQuery();
199 gte_eq_feature.appendFeaturesAsFuzzyFetchQuery(*fuzzy_query, msg, *move_group_, 0.0);
200 EXPECT_EQ(coll.queryList(fuzzy_query).size(), 1);
201
202 Query::Ptr exact_query = coll.createQuery();
203 gte_eq_feature.appendFeaturesAsExactFetchQuery(*exact_query, msg, *move_group_, 0.0);
204 EXPECT_EQ(coll.queryList(exact_query).size(), 1);
205 }
206
207 // Unrelated. No match.
208 {
209 Query::Ptr unrelated_fuzzy_query = coll.createQuery();
210 unrelated_gte_feature.appendFeaturesAsFuzzyFetchQuery(*unrelated_fuzzy_query, msg, *move_group_, 0.0);
211 EXPECT_TRUE(coll.queryList(unrelated_fuzzy_query).empty());
212
213 Query::Ptr exact_query = coll.createQuery();
214 unrelated_gte_feature.appendFeaturesAsExactFetchQuery(*exact_query, msg, *move_group_, 0.0);
215 EXPECT_TRUE(coll.queryList(exact_query).empty());
216 }
217
218 // Mismatched. No match.
219 {
220 Query::Ptr fuzzy_query = coll.createQuery();
221 mismatched_gte_feature.appendFeaturesAsFuzzyFetchQuery(*fuzzy_query, msg, *move_group_, 0.0);
222 EXPECT_TRUE(coll.queryList(fuzzy_query).empty());
223
224 Query::Ptr exact_query = coll.createQuery();
225 mismatched_gte_feature.appendFeaturesAsExactFetchQuery(*exact_query, msg, *move_group_, 0.0);
226 EXPECT_TRUE(coll.queryList(exact_query).empty());
227 }
228}
229
230TEST_F(MoveGroupFixture, QueryOnlyLTEFeature)
231{
232 MessageCollection<Point> coll = db_->openCollection<Point>("test_db", "test_collection");
233
234 Metadata::Ptr metadata = coll.createMetadata();
235 metadata->append("test_metadata", 5.0);
236
237 Point msg;
238 coll.insert(msg, metadata);
239
240 QueryOnlyLTEFeature<double, Point> lte_feature("test_metadata", 6.0);
241 QueryOnlyLTEFeature<double, Point> lte_eq_feature("test_metadata", 5.0);
242 QueryOnlyLTEFeature<double, Point> unrelated_lte_feature("unrelated", 6.0);
243 QueryOnlyLTEFeature<double, Point> mismatched_lte_feature("test_metadata", 4.0);
244
245 // Names.
246 EXPECT_EQ(lte_feature.getName(), "QueryOnlyLTEFeature.test_metadata");
247 EXPECT_EQ(unrelated_lte_feature.getName(), "QueryOnlyLTEFeature.unrelated");
248
249 // Expect no-ops.
250 {
251 Metadata::Ptr metadata = coll.createMetadata();
252 lte_feature.appendFeaturesAsInsertMetadata(*metadata, msg, *move_group_);
253 EXPECT_TRUE(metadata->lookupFieldNames().empty());
254 }
255
256 // Match.
257 {
258 Query::Ptr fuzzy_query = coll.createQuery();
259 lte_feature.appendFeaturesAsFuzzyFetchQuery(*fuzzy_query, msg, *move_group_, 0.0);
260 EXPECT_EQ(coll.queryList(fuzzy_query).size(), 1);
261
262 Query::Ptr exact_query = coll.createQuery();
263 lte_feature.appendFeaturesAsExactFetchQuery(*exact_query, msg, *move_group_, 0.0);
264 EXPECT_EQ(coll.queryList(exact_query).size(), 1);
265 }
266
267 {
268 Query::Ptr fuzzy_query = coll.createQuery();
269 lte_eq_feature.appendFeaturesAsFuzzyFetchQuery(*fuzzy_query, msg, *move_group_, 0.0);
270 EXPECT_EQ(coll.queryList(fuzzy_query).size(), 1);
271
272 Query::Ptr exact_query = coll.createQuery();
273 lte_eq_feature.appendFeaturesAsExactFetchQuery(*exact_query, msg, *move_group_, 0.0);
274 EXPECT_EQ(coll.queryList(exact_query).size(), 1);
275 }
276
277 // Unrelated. No match.
278 {
279 Query::Ptr fuzzy_query = coll.createQuery();
280 unrelated_lte_feature.appendFeaturesAsFuzzyFetchQuery(*fuzzy_query, msg, *move_group_, 0.0);
281 EXPECT_TRUE(coll.queryList(fuzzy_query).empty());
282
283 Query::Ptr exact_query = coll.createQuery();
284 unrelated_lte_feature.appendFeaturesAsExactFetchQuery(*exact_query, msg, *move_group_, 0.0);
285 EXPECT_TRUE(coll.queryList(exact_query).empty());
286 }
287
288 // Mismatched. No match.
289 {
290 Query::Ptr fuzzy_query = coll.createQuery();
291 mismatched_lte_feature.appendFeaturesAsFuzzyFetchQuery(*fuzzy_query, msg, *move_group_, 0.0);
292 EXPECT_TRUE(coll.queryList(fuzzy_query).empty());
293
294 Query::Ptr exact_query = coll.createQuery();
295 mismatched_lte_feature.appendFeaturesAsExactFetchQuery(*exact_query, msg, *move_group_, 0.0);
296 EXPECT_TRUE(coll.queryList(exact_query).empty());
297 }
298}
299
300TEST_F(MoveGroupFixture, QueryOnlyRangeInclusiveWithToleranceFeature)
301{
302 MessageCollection<Point> coll = db_->openCollection<Point>("test_db", "test_collection");
303
304 Metadata::Ptr metadata = coll.createMetadata();
305 metadata->append("test_metadata", 5.0);
306
307 Point msg;
308 coll.insert(msg, metadata);
309
310 QueryOnlyRangeInclusiveWithToleranceFeature<double, Point> exact_range_feature("test_metadata", 5.0, 5.0);
311 QueryOnlyRangeInclusiveWithToleranceFeature<double, Point> lower_range_feature("test_metadata", 4.0, 5.0);
312 QueryOnlyRangeInclusiveWithToleranceFeature<double, Point> upper_range_feature("test_metadata", 5.0, 6.0);
313 QueryOnlyRangeInclusiveWithToleranceFeature<double, Point> over_range_feature("test_metadata", 4.5, 5.5);
314
315 QueryOnlyRangeInclusiveWithToleranceFeature<double, Point> unrelated_range_feature("unrelated", 5.5, 6.0);
316 QueryOnlyRangeInclusiveWithToleranceFeature<double, Point> mismatched_range_feature("test_metadata", 5.5, 6.0);
317
318 // Names.
319 EXPECT_EQ(exact_range_feature.getName(), "QueryOnlyRangeInclusiveWithToleranceFeature.test_metadata");
320 EXPECT_EQ(unrelated_range_feature.getName(), "QueryOnlyRangeInclusiveWithToleranceFeature.unrelated");
321
322 // Expect no-ops.
323 {
324 Metadata::Ptr metadata = coll.createMetadata();
325 exact_range_feature.appendFeaturesAsInsertMetadata(*metadata, msg, *move_group_);
326 EXPECT_TRUE(metadata->lookupFieldNames().empty());
327 }
328
329 // Match.
330 {
331 Query::Ptr fuzzy_query = coll.createQuery();
332 exact_range_feature.appendFeaturesAsFuzzyFetchQuery(*fuzzy_query, msg, *move_group_, 0.0);
333 EXPECT_EQ(coll.queryList(fuzzy_query).size(), 1);
334
335 Query::Ptr exact_query = coll.createQuery();
336 exact_range_feature.appendFeaturesAsExactFetchQuery(*exact_query, msg, *move_group_, 0.0);
337 EXPECT_EQ(coll.queryList(exact_query).size(), 1);
338 }
339
340 {
341 Query::Ptr fuzzy_query = coll.createQuery();
342 lower_range_feature.appendFeaturesAsFuzzyFetchQuery(*fuzzy_query, msg, *move_group_, 0.0);
343 EXPECT_EQ(coll.queryList(fuzzy_query).size(), 1);
344
345 Query::Ptr exact_query = coll.createQuery();
346 lower_range_feature.appendFeaturesAsExactFetchQuery(*exact_query, msg, *move_group_, 0.0);
347 EXPECT_EQ(coll.queryList(exact_query).size(), 1);
348 }
349
350 {
351 Query::Ptr fuzzy_query = coll.createQuery();
352 upper_range_feature.appendFeaturesAsFuzzyFetchQuery(*fuzzy_query, msg, *move_group_, 0.0);
353 EXPECT_EQ(coll.queryList(fuzzy_query).size(), 1);
354
355 Query::Ptr exact_query = coll.createQuery();
356 upper_range_feature.appendFeaturesAsExactFetchQuery(*exact_query, msg, *move_group_, 0.0);
357 EXPECT_EQ(coll.queryList(exact_query).size(), 1);
358 }
359
360 {
361 Query::Ptr fuzzy_query = coll.createQuery();
362 over_range_feature.appendFeaturesAsFuzzyFetchQuery(*fuzzy_query, msg, *move_group_, 0.0);
363 EXPECT_EQ(coll.queryList(fuzzy_query).size(), 1);
364
365 Query::Ptr exact_query = coll.createQuery();
366 over_range_feature.appendFeaturesAsExactFetchQuery(*exact_query, msg, *move_group_, 0.0);
367 EXPECT_EQ(coll.queryList(exact_query).size(), 1);
368 }
369
370 // Unrelated. No match.
371 {
372 Query::Ptr fuzzy_query = coll.createQuery();
373 unrelated_range_feature.appendFeaturesAsFuzzyFetchQuery(*fuzzy_query, msg, *move_group_, 0.0);
374 EXPECT_TRUE(coll.queryList(fuzzy_query).empty());
375
376 Query::Ptr exact_query = coll.createQuery();
377 unrelated_range_feature.appendFeaturesAsExactFetchQuery(*exact_query, msg, *move_group_, 0.0);
378 EXPECT_TRUE(coll.queryList(exact_query).empty());
379 }
380
381 // Mismatched. No match.
382 {
383 Query::Ptr fuzzy_query = coll.createQuery();
384 mismatched_range_feature.appendFeaturesAsFuzzyFetchQuery(*fuzzy_query, msg, *move_group_, 0.0);
385 EXPECT_TRUE(coll.queryList(fuzzy_query).empty());
386
387 Query::Ptr exact_query = coll.createQuery();
388 mismatched_range_feature.appendFeaturesAsExactFetchQuery(*exact_query, msg, *move_group_, 0.0);
389 EXPECT_TRUE(coll.queryList(exact_query).empty());
390 }
391}
392
393} // namespace
394
395int main(int argc, char** argv)
396{
397 rclcpp::init(argc, argv);
398 ::testing::InitGoogleTest(&argc, argv);
399 int result = RUN_ALL_TESTS();
400 rclcpp::shutdown();
401 return result;
402}
Test fixture to spin up a node to start a move group with.
User-specified constant features to key the trajectory cache on.
TEST_F(BulletCollisionDetectionTester, DISABLED_ContinuousCollisionSelf)
Continuous self collision checks are not supported yet by the bullet integration.
int main(int argc, char **argv)