MTC
generate_random_pose.h
1 /*********************************************************************
2  * Software License Agreement (BSD License)
3  *
4  * Copyright (c) 2020, PickNik 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 PickNik Inc 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 /* Authors: Henning Kayser
36  Desc: Generator Stage for randomized poses based on GeneratePose
37 */
38 
39 #pragma once
40 
41 #include <moveit/task_constructor/stages/generate_pose.h>
42 
43 #include <random>
44 
45 namespace moveit {
46 namespace task_constructor {
47 namespace stages {
48 
50 {
51 public:
52  GenerateRandomPose(const std::string& name = "generate random pose");
53 
54  bool canCompute() const override;
55  void compute() override;
56 
59  using PoseDimensionSampler = std::function<double(double)>;
60  enum PoseDimension : uint8_t
61  {
62  X,
63  Y,
64  Z,
65  ROLL,
66  PITCH,
67  YAW
68  };
69 
81  template <template <class Realtype = double> class RandomNumberDistribution>
82  void sampleDimension(const PoseDimension pose_dimension, double width) {
83  sampleDimension(pose_dimension, getPoseDimensionSampler<RandomNumberDistribution>(width));
84  }
85 
87  void sampleDimension(const PoseDimension pose_dimension, const PoseDimensionSampler& pose_dimension_sampler) {
88  pose_dimension_samplers_.emplace_back(std::make_pair(pose_dimension, pose_dimension_sampler));
89  }
90 
92  void setMaxSolutions(size_t max_solutions) { setProperty("max_solutions", max_solutions); }
93 
94 private:
96  template <template <class Realtype = double> class RandomNumberDistribution>
97  PoseDimensionSampler getPoseDimensionSampler(double /* width */) {
98  static_assert(sizeof(RandomNumberDistribution<double>) == -1, "This distribution type is not supported!");
99  throw 0; // suppress -Wreturn-type
100  }
101 
102  std::vector<std::pair<PoseDimension, PoseDimensionSampler>> pose_dimension_samplers_;
103 };
104 template <>
106 GenerateRandomPose::getPoseDimensionSampler<std::normal_distribution>(double stddev);
107 template <>
109 GenerateRandomPose::getPoseDimensionSampler<std::uniform_real_distribution>(double range);
110 } // namespace stages
111 } // namespace task_constructor
112 } // namespace moveit
void setProperty(const std::string &name, const boost::any &value)
Set a previously declared property to a new value.
Definition: stage.cpp:448
Definition: generate_random_pose.h:50
void setMaxSolutions(size_t max_solutions)
Definition: generate_random_pose.h:92
std::function< double(double)> PoseDimensionSampler
Definition: generate_random_pose.h:59
void sampleDimension(const PoseDimension pose_dimension, const PoseDimensionSampler &pose_dimension_sampler)
Definition: generate_random_pose.h:87
void sampleDimension(const PoseDimension pose_dimension, double width)
Definition: generate_random_pose.h:82