moveit2
The MoveIt Motion Planning Framework for ROS 2.
Loading...
Searching...
No Matches
constraints_library.cpp
Go to the documentation of this file.
1/*********************************************************************
2 * Software License Agreement (BSD License)
3 *
4 * Copyright (c) 2012, Willow Garage, Inc.
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 *
11 * * Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * * Redistributions in binary form must reproduce the above
14 * copyright notice, this list of conditions and the following
15 * disclaimer in the documentation and/or other materials provided
16 * with the distribution.
17 * * Neither the name of Willow Garage nor the names of its
18 * contributors may be used to endorse or promote products derived
19 * from this software without specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
27 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
31 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32 * POSSIBILITY OF SUCH DAMAGE.
33 *********************************************************************/
34
35/* Author: Ioan Sucan */
36
37#include <boost/date_time/posix_time/posix_time.hpp>
38#include <filesystem>
39#include <fstream>
43
44#include <ompl/tools/config/SelfConfig.h>
45#include <utility>
46
47namespace ompl_interface
48{
49namespace
50{
51rclcpp::Logger getLogger()
52{
53 return moveit::getLogger("moveit.planners.ompl.constraints_library");
54}
55
56template <typename T>
57void msgToHex(const T& msg, std::string& hex)
58{
59 static const char SYMBOL[] = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' };
60 auto type_support = rosidl_typesupport_cpp::get_message_type_support_handle<T>();
61 rmw_serialized_message_t serialized_msg = { nullptr, 0, 0, rcutils_get_default_allocator() };
62 rmw_ret_t result = rmw_serialize(&msg, type_support, &serialized_msg);
63 if (result != RMW_RET_OK)
64 {
65 // TODO(henningkayser): handle error
66 RCLCPP_ERROR(getLogger(), "Failed to serialize message!");
67 return;
68 }
69 const size_t serial_size_arg = serialized_msg.buffer_length;
70
71 hex.resize(serial_size_arg * 2);
72 for (std::size_t i = 0; i < serial_size_arg; ++i)
73 {
74 hex[i * 2] = SYMBOL[serialized_msg.buffer[i] / 16];
75 hex[i * 2 + 1] = SYMBOL[serialized_msg.buffer[i] % 16];
76 }
77}
78
79template <typename T>
80void hexToMsg(const std::string& hex, T& msg)
81{
82 const size_t serial_size_arg = hex.length() / 2;
83 rmw_serialized_message_t serialized_msg = rcutils_get_zero_initialized_uint8_array();
84 rcutils_ret_t rcutils_result = rcutils_uint8_array_resize(&serialized_msg, serial_size_arg);
85 if (rcutils_result != RCUTILS_RET_OK)
86 {
87 // TODO(henningkayser): handle error
88 RCLCPP_ERROR(getLogger(), "Failed to allocate message buffer!");
89 return;
90 }
91
92 for (std::size_t i = 0; i < serial_size_arg; ++i)
93 {
94 serialized_msg.buffer[i] = (hex[i * 2] <= '9' ? (hex[i * 2] - '0') : (hex[i * 2] - 'A' + 10)) * 16 +
95 (hex[i * 2 + 1] <= '9' ? (hex[i * 2 + 1] - '0') : (hex[i * 2 + 1] - 'A' + 10));
96 }
97 auto type_support = rosidl_typesupport_cpp::get_message_type_support_handle<T>();
98 rmw_ret_t result = rmw_deserialize(&serialized_msg, type_support, &msg);
99 if (result != RMW_RET_OK)
100 {
101 // TODO(henningkayser): handle error
102 RCLCPP_ERROR(getLogger(), "Failed to deserialize message!");
103 return;
104 }
105}
106} // namespace
107
108class ConstraintApproximationStateSampler : public ob::StateSampler
109{
110public:
111 ConstraintApproximationStateSampler(const ob::StateSpace* space,
112 const ConstraintApproximationStateStorage* state_storage, std::size_t milestones)
113 : ob::StateSampler(space), state_storage_(state_storage)
114 {
115 max_index_ = milestones - 1;
116 inv_dim_ = space->getDimension() > 0 ? 1.0 / static_cast<double>(space->getDimension()) : 1.0;
117 }
118
119 void sampleUniform(ob::State* state) override
120 {
121 space_->copyState(state, state_storage_->getState(rng_.uniformInt(0, max_index_)));
122 }
123
124 void sampleUniformNear(ob::State* state, const ob::State* near, const double distance) override
125 {
126 int index = -1;
127 int tag = near->as<ModelBasedStateSpace::StateType>()->tag;
128
129 if (tag >= 0)
130 {
131 const ConstrainedStateMetadata& md = state_storage_->getMetadata(tag);
132 if (!md.first.empty())
133 {
134 std::size_t matt = md.first.size() / 3;
135 std::size_t att = 0;
136 do
137 {
138 index = md.first[rng_.uniformInt(0, md.first.size() - 1)];
139 } while (dirty_.find(index) != dirty_.end() && ++att < matt);
140 if (att >= matt)
141 {
142 index = -1;
143 }
144 else
145 {
146 dirty_.insert(index);
147 }
148 }
149 }
150 if (index < 0)
151 index = rng_.uniformInt(0, max_index_);
152
153 double dist = space_->distance(near, state_storage_->getState(index));
154
155 if (dist > distance)
156 {
157 double d = pow(rng_.uniform01(), inv_dim_) * distance;
158 space_->interpolate(near, state_storage_->getState(index), d / dist, state);
159 }
160 else
161 {
162 space_->copyState(state, state_storage_->getState(index));
163 }
164 }
165
166 void sampleGaussian(ob::State* state, const ob::State* mean, const double stdDev) override
167 {
168 sampleUniformNear(state, mean, rng_.gaussian(0.0, stdDev));
169 }
170
171protected:
174 std::set<std::size_t> dirty_;
175 unsigned int max_index_;
176 double inv_dim_;
177};
178
179bool interpolateUsingStoredStates(const ConstraintApproximationStateStorage* state_storage, const ob::State* from,
180 const ob::State* to, const double t, ob::State* state)
181{
182 int tag_from = from->as<ModelBasedStateSpace::StateType>()->tag;
183 int tag_to = to->as<ModelBasedStateSpace::StateType>()->tag;
184
185 if (tag_from < 0 || tag_to < 0)
186 return false;
187
188 if (tag_from == tag_to)
189 {
190 state_storage->getStateSpace()->copyState(state, to);
191 }
192 else
193 {
194 const ConstrainedStateMetadata& md = state_storage->getMetadata(tag_from);
195
196 auto it = md.second.find(tag_to);
197 if (it == md.second.end())
198 return false;
199 const std::pair<std::size_t, std::size_t>& istates = it->second;
200 std::size_t index = static_cast<std::size_t>((istates.second - istates.first + 2) * t + 0.5);
201
202 if (index == 0)
203 {
204 state_storage->getStateSpace()->copyState(state, from);
205 }
206 else
207 {
208 --index;
209 if (index >= istates.second - istates.first)
210 {
211 state_storage->getStateSpace()->copyState(state, to);
212 }
213 else
214 {
215 state_storage->getStateSpace()->copyState(state, state_storage->getState(istates.first + index));
216 }
217 }
218 }
219 return true;
220}
221
223{
225 {
226 return
227 [this](const ompl::base::State* from, const ompl::base::State* to, const double t, ompl::base::State* state) {
228 return interpolateUsingStoredStates(state_storage_, from, to, t, state);
229 };
230 }
231 return InterpolationFunction();
232}
233
234ompl::base::StateSamplerPtr
235allocConstraintApproximationStateSampler(const ob::StateSpace* space, const std::vector<int>& expected_signature,
236 const ConstraintApproximationStateStorage* state_storage,
237 std::size_t milestones)
238{
239 std::vector<int> sig;
240 space->computeSignature(sig);
241 if (sig != expected_signature)
242 {
243 return ompl::base::StateSamplerPtr();
244 }
245 else
246 {
247 return std::make_shared<ConstraintApproximationStateSampler>(space, state_storage, milestones);
248 }
249}
250
251ConstraintApproximation::ConstraintApproximation(std::string group, std::string state_space_parameterization,
252 bool explicit_motions, moveit_msgs::msg::Constraints msg,
253 std::string filename, ompl::base::StateStoragePtr storage,
254 std::size_t milestones)
255 : group_(std::move(group))
256 , state_space_parameterization_(std::move(state_space_parameterization))
257 , explicit_motions_(explicit_motions)
258 , constraint_msg_(std::move(msg))
259 , ompldb_filename_(std::move(filename))
260 , state_storage_ptr_(std::move(storage))
261 , milestones_(milestones)
262{
264 state_storage_->getStateSpace()->computeSignature(space_signature_);
265 if (milestones_ == 0)
266 milestones_ = state_storage_->size();
267}
268
269ompl::base::StateSamplerAllocator
270ConstraintApproximation::getStateSamplerAllocator(const moveit_msgs::msg::Constraints& /*unused*/) const
271{
272 if (state_storage_->size() == 0)
273 return ompl::base::StateSamplerAllocator();
274 return [this](const ompl::base::StateSpace* ss) {
276 };
277}
278
280{
281 constraint_approximations_.clear();
282 std::ifstream fin((path + "/manifest").c_str());
283 if (!fin.good())
284 {
285 RCLCPP_WARN(getLogger(),
286 "Manifest not found in folder '%s'. Not loading "
287 "constraint approximations.",
288 path.c_str());
289 return;
290 }
291
292 RCLCPP_INFO(getLogger(), "Loading constrained space approximations from '%s'...", path.c_str());
293
294 while (fin.good() && !fin.eof())
295 {
296 std::string group, state_space_parameterization, serialization, filename;
297 bool explicit_motions;
298 unsigned int milestones;
299 fin >> group;
300 if (fin.eof())
301 break;
302 fin >> state_space_parameterization;
303 if (fin.eof())
304 break;
305 fin >> explicit_motions;
306 if (fin.eof())
307 break;
308 fin >> milestones;
309 if (fin.eof())
310 break;
311 fin >> serialization;
312 if (fin.eof())
313 break;
314 fin >> filename;
315
316 if (context_->getGroupName() != group &&
317 context_->getOMPLStateSpace()->getParameterizationType() != state_space_parameterization)
318 {
319 RCLCPP_INFO(getLogger(), "Ignoring constraint approximation of type '%s' for group '%s' from '%s'...",
320 state_space_parameterization.c_str(), group.c_str(), filename.c_str());
321 continue;
322 }
323
324 RCLCPP_INFO(getLogger(), "Loading constraint approximation of type '%s' for group '%s' from '%s'...",
325 state_space_parameterization.c_str(), group.c_str(), filename.c_str());
326 moveit_msgs::msg::Constraints msg;
327 hexToMsg(serialization, msg);
328 auto* cass = new ConstraintApproximationStateStorage(context_->getOMPLSimpleSetup()->getStateSpace());
329 cass->load((std::string{ path }.append("/").append(filename)).c_str());
330 auto cap = std::make_shared<ConstraintApproximation>(group, state_space_parameterization, explicit_motions, msg,
331 filename, ompl::base::StateStoragePtr(cass), milestones);
332 if (constraint_approximations_.find(cap->getName()) != constraint_approximations_.end())
333 RCLCPP_WARN(getLogger(), "Overwriting constraint approximation named '%s'", cap->getName().c_str());
334 constraint_approximations_[cap->getName()] = cap;
335 std::size_t sum = 0;
336 for (std::size_t i = 0; i < cass->size(); ++i)
337 sum += cass->getMetadata(i).first.size();
338 RCLCPP_INFO(getLogger(),
339 "Loaded %lu states (%lu milestones) and %lu connections (%0.1lf per state) "
340 "for constraint named '%s'%s",
341 cass->size(), cap->getMilestoneCount(), sum,
342 static_cast<double>(sum) / static_cast<double>(cap->getMilestoneCount()), msg.name.c_str(),
343 explicit_motions ? ". Explicit motions included." : "");
344 }
345 RCLCPP_INFO(getLogger(), "Done loading constrained space approximations.");
346}
347
349{
350 RCLCPP_INFO(getLogger(), "Saving %u constrained space approximations to '%s'",
351 static_cast<unsigned int>(constraint_approximations_.size()), path.c_str());
352 try
353 {
354 std::filesystem::create_directory(path);
355 }
356 catch (...)
357 {
358 }
359
360 std::ofstream fout((path + "/manifest").c_str());
361 if (fout.good())
362 {
363 for (std::map<std::string, ConstraintApproximationPtr>::const_iterator it = constraint_approximations_.begin();
364 it != constraint_approximations_.end(); ++it)
365 {
366 fout << it->second->getGroup() << '\n';
367 fout << it->second->getStateSpaceParameterization() << '\n';
368 fout << it->second->hasExplicitMotions() << '\n';
369 fout << it->second->getMilestoneCount() << '\n';
370 std::string serialization;
371 msgToHex(it->second->getConstraintsMsg(), serialization);
372 fout << serialization << '\n';
373 fout << it->second->getFilename() << '\n';
374 if (it->second->getStateStorage())
375 it->second->getStateStorage()->store((path + "/" + it->second->getFilename()).c_str());
376 }
377 }
378 else
379 {
380 RCLCPP_ERROR(getLogger(), "Unable to save constraint approximation to '%s'", path.c_str());
381 }
382 fout.close();
383}
384
386{
387 constraint_approximations_.clear();
388}
389
391{
392 for (const std::pair<const std::string, ConstraintApproximationPtr>& constraint_approximation :
393 constraint_approximations_)
394 {
395 out << constraint_approximation.second->getGroup() << '\n';
396 out << constraint_approximation.second->getStateSpaceParameterization() << '\n';
397 out << constraint_approximation.second->hasExplicitMotions() << '\n';
398 out << constraint_approximation.second->getMilestoneCount() << '\n';
399 out << constraint_approximation.second->getFilename() << '\n';
400 // TODO(henningkayser): format print constraint message
401 // out << constraint_approximation.second->getConstraintsMsg() << '\n';
402 }
403}
404
405const ConstraintApproximationPtr&
406ConstraintsLibrary::getConstraintApproximation(const moveit_msgs::msg::Constraints& msg) const
407{
408 auto it = constraint_approximations_.find(msg.name);
409 if (it != constraint_approximations_.end())
410 return it->second;
411
412 static ConstraintApproximationPtr empty;
413 return empty;
414}
415
417ConstraintsLibrary::addConstraintApproximation(const moveit_msgs::msg::Constraints& constr, const std::string& group,
418 const planning_scene::PlanningSceneConstPtr& scene,
420{
421 return addConstraintApproximation(constr, constr, group, scene, options);
422}
423
425 const moveit_msgs::msg::Constraints& constr_sampling, const moveit_msgs::msg::Constraints& constr_hard,
426 const std::string& group, const planning_scene::PlanningSceneConstPtr& scene,
428{
430 if (context_->getGroupName() != group &&
431 context_->getOMPLStateSpace()->getParameterizationType() != options.state_space_parameterization)
432 {
433 RCLCPP_INFO(getLogger(), "Ignoring constraint approximation of type '%s' for group '%s'...",
434 options.state_space_parameterization.c_str(), group.c_str());
435 return res;
436 }
437
438 context_->clear();
439 context_->setPlanningScene(scene);
440 context_->setCompleteInitialState(scene->getCurrentState());
441
442 rclcpp::Clock clock;
443 auto start = clock.now();
444 ompl::base::StateStoragePtr state_storage =
445 constructConstraintApproximation(context_, constr_sampling, constr_hard, options, res);
446 RCLCPP_INFO(getLogger(), "Spent %lf seconds constructing the database", (clock.now() - start).seconds());
447 if (state_storage)
448 {
449 auto constraint_approx = std::make_shared<ConstraintApproximation>(
450 group, options.state_space_parameterization, options.explicit_motions, constr_hard,
451 group + "_" + boost::posix_time::to_iso_extended_string(boost::posix_time::microsec_clock::universal_time()) +
452 ".ompldb",
453 state_storage, res.milestones);
454 if (constraint_approximations_.find(constraint_approx->getName()) != constraint_approximations_.end())
455 RCLCPP_WARN(getLogger(), "Overwriting constraint approximation named '%s'", constraint_approx->getName().c_str());
456 constraint_approximations_[constraint_approx->getName()] = constraint_approx;
457 res.approx = constraint_approx;
458 }
459 else
460 {
461 RCLCPP_ERROR(getLogger(), "Unable to construct constraint approximation for group '%s'", group.c_str());
462 }
463 return res;
464}
465
466ompl::base::StateStoragePtr ConstraintsLibrary::constructConstraintApproximation(
467 ModelBasedPlanningContext* pcontext, const moveit_msgs::msg::Constraints& constr_sampling,
468 const moveit_msgs::msg::Constraints& constr_hard, const ConstraintApproximationConstructionOptions& options,
470{
471 // state storage structure
473 ob::StateStoragePtr state_storage(cass);
474
475 // construct a sampler for the sampling constraints
477 moveit::core::Transforms no_transforms(pcontext->getRobotModel()->getModelFrame());
478 kset.add(constr_hard, no_transforms);
479
480 const moveit::core::RobotState& default_state = pcontext->getCompleteInitialRobotState();
481
482 unsigned int attempts = 0;
483
484 double bounds_val = std::numeric_limits<double>::max() / 2.0 - 1.0;
485 pcontext->getOMPLStateSpace()->setPlanningVolume(-bounds_val, bounds_val, -bounds_val, bounds_val, -bounds_val,
486 bounds_val);
487 pcontext->getOMPLStateSpace()->setup();
488
489 // construct the constrained states
490
491 moveit::core::RobotState robot_state(default_state);
492 const constraint_samplers::ConstraintSamplerManagerPtr& csmng = pcontext->getConstraintSamplerManager();
493 ConstrainedSampler* constrained_sampler = nullptr;
494 if (csmng)
495 {
496 constraint_samplers::ConstraintSamplerPtr constraint_sampler =
497 csmng->selectSampler(pcontext->getPlanningScene(), pcontext->getJointModelGroup()->getName(), constr_sampling);
498 if (constraint_sampler)
499 constrained_sampler = new ConstrainedSampler(pcontext, constraint_sampler);
500 }
501
502 ob::StateSamplerPtr ss(constrained_sampler ? ob::StateSamplerPtr(constrained_sampler) :
503 pcontext->getOMPLStateSpace()->allocDefaultStateSampler());
504
505 ompl::base::ScopedState<> temp(pcontext->getOMPLStateSpace());
506 int done = -1;
507 bool slow_warn = false;
508 ompl::time::point start = ompl::time::now();
509 while (state_storage->size() < options.samples)
510 {
511 ++attempts;
512 int done_now = 100 * state_storage->size() / options.samples;
513 if (done != done_now)
514 {
515 done = done_now;
516 RCLCPP_INFO(getLogger(), "%d%% complete (kept %0.1lf%% sampled states)", done,
517 100.0 * static_cast<double>(state_storage->size()) / static_cast<double>(attempts));
518 }
519
520 if (!slow_warn && attempts > 10 && attempts > state_storage->size() * 100)
521 {
522 slow_warn = true;
523 RCLCPP_WARN(getLogger(), "Computation of valid state database is very slow...");
524 }
525
526 if (attempts > options.samples && state_storage->size() == 0)
527 {
528 RCLCPP_ERROR(getLogger(), "Unable to generate any samples");
529 break;
530 }
531
532 ss->sampleUniform(temp.get());
533 pcontext->getOMPLStateSpace()->copyToRobotState(robot_state, temp.get());
534 if (kset.decide(robot_state).satisfied)
535 {
536 if (state_storage->size() < options.samples)
537 {
538 temp->as<ModelBasedStateSpace::StateType>()->tag = state_storage->size();
539 state_storage->addState(temp.get());
540 }
541 }
542 }
543
544 result.state_sampling_time = ompl::time::seconds(ompl::time::now() - start);
545 RCLCPP_INFO(getLogger(), "Generated %u states in %lf seconds", static_cast<unsigned int>(state_storage->size()),
546 result.state_sampling_time);
547 if (constrained_sampler)
548 {
549 result.sampling_success_rate = constrained_sampler->getConstrainedSamplingRate();
550 RCLCPP_INFO(getLogger(), "Constrained sampling rate: %lf", result.sampling_success_rate);
551 }
552
553 result.milestones = state_storage->size();
554 if (options.edges_per_sample > 0)
555 {
556 RCLCPP_INFO(getLogger(), "Computing graph connections (max %u edges per sample) ...", options.edges_per_sample);
557
558 // construct connections
559 const ob::StateSpacePtr& space = pcontext->getOMPLSimpleSetup()->getStateSpace();
560 unsigned int milestones = state_storage->size();
561 std::vector<ob::State*> int_states(options.max_explicit_points, nullptr);
562 pcontext->getOMPLSimpleSetup()->getSpaceInformation()->allocStates(int_states);
563
564 ompl::time::point start = ompl::time::now();
565 int good = 0;
566 int done = -1;
567
568 for (std::size_t j = 0; j < milestones; ++j)
569 {
570 int done_now = 100 * j / milestones;
571 if (done != done_now)
572 {
573 done = done_now;
574 RCLCPP_INFO(getLogger(), "%d%% complete", done);
575 }
576 if (cass->getMetadata(j).first.size() >= options.edges_per_sample)
577 continue;
578
579 const ob::State* sj = state_storage->getState(j);
580
581 for (std::size_t i = j + 1; i < milestones; ++i)
582 {
583 if (cass->getMetadata(i).first.size() >= options.edges_per_sample)
584 continue;
585 double d = space->distance(state_storage->getState(i), sj);
586 if (d >= options.max_edge_length)
587 continue;
588 unsigned int isteps =
589 std::min<unsigned int>(options.max_explicit_points, d / options.explicit_points_resolution);
590 double step = 1.0 / static_cast<double>(isteps);
591 bool ok = true;
592 space->interpolate(state_storage->getState(i), sj, step, int_states[0]);
593 for (unsigned int k = 1; k < isteps; ++k)
594 {
595 double this_step = step / (1.0 - (k - 1) * step);
596 space->interpolate(int_states[k - 1], sj, this_step, int_states[k]);
597 pcontext->getOMPLStateSpace()->copyToRobotState(robot_state, int_states[k]);
598 if (!kset.decide(robot_state).satisfied)
599 {
600 ok = false;
601 break;
602 }
603 }
604
605 if (ok)
606 {
607 cass->getMetadata(i).first.push_back(j);
608 cass->getMetadata(j).first.push_back(i);
609
610 if (options.explicit_motions)
611 {
612 cass->getMetadata(i).second[j].first = state_storage->size();
613 for (unsigned int k = 0; k < isteps; ++k)
614 {
615 int_states[k]->as<ModelBasedStateSpace::StateType>()->tag = -1;
616 state_storage->addState(int_states[k]);
617 }
618 cass->getMetadata(i).second[j].second = state_storage->size();
619 cass->getMetadata(j).second[i] = cass->getMetadata(i).second[j];
620 }
621
622 good++;
623 if (cass->getMetadata(j).first.size() >= options.edges_per_sample)
624 break;
625 }
626 }
627 }
628
629 result.state_connection_time = ompl::time::seconds(ompl::time::now() - start);
630 RCLCPP_INFO(getLogger(), "Computed possible connexions in %lf seconds. Added %d connexions",
631 result.state_connection_time, good);
632 pcontext->getOMPLSimpleSetup()->getSpaceInformation()->freeStates(int_states);
633
634 return state_storage;
635 }
636
637 // TODO(davetcoleman): this function did not originally return a value,
638 // causing compiler warnings in ROS Melodic
639 // Update with more intelligent logic as needed
640 RCLCPP_ERROR(getLogger(), "No StateStoragePtr found - implement better solution here.");
641 return state_storage;
642}
643
644} // namespace ompl_interface
A class that contains many different constraints, and can check RobotState *versus the full set....
const std::string & getName() const
Get the name of the joint group.
Representation of a robot's state. This includes position, velocity, acceleration and effort.
Provides an implementation of a snapshot of a transform tree that can be easily queried for transform...
void sampleGaussian(ob::State *state, const ob::State *mean, const double stdDev) override
void sampleUniformNear(ob::State *state, const ob::State *near, const double distance) override
ConstraintApproximationStateSampler(const ob::StateSpace *space, const ConstraintApproximationStateStorage *state_storage, std::size_t milestones)
const ConstraintApproximationStateStorage * state_storage_
The states to sample from.
void printConstraintApproximations(std::ostream &out=std::cout) const
ConstraintApproximationConstructionResults addConstraintApproximation(const moveit_msgs::msg::Constraints &constr_sampling, const moveit_msgs::msg::Constraints &constr_hard, const std::string &group, const planning_scene::PlanningSceneConstPtr &scene, const ConstraintApproximationConstructionOptions &options)
void saveConstraintApproximations(const std::string &path)
void loadConstraintApproximations(const std::string &path)
const ConstraintApproximationPtr & getConstraintApproximation(const moveit_msgs::msg::Constraints &msg) const
const moveit::core::RobotState & getCompleteInitialRobotState() const
const moveit::core::RobotModelConstPtr & getRobotModel() const
const ModelBasedStateSpacePtr & getOMPLStateSpace() const
const moveit::core::JointModelGroup * getJointModelGroup() const
const constraint_samplers::ConstraintSamplerManagerPtr & getConstraintSamplerManager()
const planning_scene::PlanningSceneConstPtr & getPlanningScene() const
Get the planning scene associated to this planning context.
rclcpp::Logger getLogger(const std::string &name)
Creates a namespaced logger.
Definition logger.cpp:106
The MoveIt interface to OMPL.
bool interpolateUsingStoredStates(const ConstraintApproximationStateStorage *state_storage, const ob::State *from, const ob::State *to, const double t, ob::State *state)
std::pair< std::vector< std::size_t >, std::map< std::size_t, std::pair< std::size_t, std::size_t > > > ConstrainedStateMetadata
ompl::base::StateSamplerPtr allocConstraintApproximationStateSampler(const ob::StateSpace *space, const std::vector< int > &expected_signature, const ConstraintApproximationStateStorage *state_storage, std::size_t milestones)
std::function< bool(const ompl::base::State *from, const ompl::base::State *to, const double t, ompl::base::State *state)> InterpolationFunction
ompl::base::StateStorageWithMetadata< std::vector< std::size_t > > ConstraintApproximationStateStorage
ConstraintApproximationStateStorage * state_storage_
ConstraintApproximation(const planning_models::RobotModelConstPtr &kinematic_model, const std::string &group, const std::string &factory, const std::string &serialization, const std::string &filename, const ompl::base::StateStoragePtr &storage)
InterpolationFunction getInterpolationFunction() const
ompl::base::StateSamplerAllocator getStateSamplerAllocator(const moveit_msgs::msg::Constraints &msg) const