pose_sampling.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 
3 '''
4 Copyright (c) 2016, Allgeyer Tobias, Aumann Florian, Borella Jocelyn, Hutmacher Robin, Karrenbauer Oliver, Marek Felix, Meissner Pascal, Trautmann Jeremias, Wittenbeck Valerij
5 
6 All rights reserved.
7 
8 Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
9 
10 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
11 
12 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
13 
14 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
15 
16 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
17 '''
18 
19 import roslib
20 import rospy
21 import smach
22 import smach_ros
23 import random
24 import numpy as np
25 import tf
26 import math
27 
28 from geometry_msgs.msg import Pose, Point, Quaternion, Twist
29 from asr_msgs.msg import AsrAttributedPointCloud, AsrAttributedPoint
30 
31 class PoseSampling(smach.State):
32  """
33  Generate sample pointcloud using normal distribution for defined accumulation
34  points.
35 
36  This calls is adapted from Ralfs NBV Test class.
37  """
38 
39  def get_random_vector(self, mean, standard_deviaton):
40  """ adapted from MathHelper in NBV """
41  result = []
42  for i in xrange(len(mean)):
43  result.append(np.random.normal(mean[i], standard_deviaton[i]))
44  return result
45 
47  """ adapted from MathHelper in NBV """
48  random_angles = self.get_random_vector([0,0,0], [2*np.pi, 2*np.pi, 1])
49  return tf.transformations.quaternion_from_euler(random_angles[0],
50  random_angles[1],
51  0)
52 
53 
54  def __init__(self):
55  smach.State.__init__(
56  self,
57  outcomes=['succeeded', 'aborted'],
58  output_keys=['object_pointcloud'])
59 
60  def execute(self, userdata):
61 
62  pcl = AsrAttributedPointCloud()
63  sample_size = 200
64  # Define accumulation points
65  hp = []
66  hp.append([16.0, 16.0, 0.98])
67  hp.append([25.0, 11.0, 1.32])
68  # hp.append([18.6, 7.3, 1.80])
69  hp.append([1.916, 22.485, 1.0])
70 
71  object_type_names = ['Smacks'] #more?
72  for idx in xrange(len(hp)):
73  for cnt in xrange(sample_size):
74  random_vector = self.get_random_vector(hp[idx], [.5, .5, 0.2])
75  random_quaternion = self.get_random_quaternion()
76 
77  element = AsrAttributedPoint()
78  pose = Pose()
79  pose.orientation = Quaternion(*random_quaternion)
80  pose.position = Point(*random_vector)
81  element.type = 'Smacks'
82  element.pose = pose
83  pcl.elements.append(element)
84 
85  userdata.object_pointcloud = pcl
86  return 'succeeded'
87 
def get_random_vector(self, mean, standard_deviaton)


asr_state_machine
Author(s): Allgeyer Tobias, Aumann Florian, Borella Jocelyn, Hutmacher Robin, Karrenbauer Oliver, Marek Felix, Meißner Pascal, Trautmann Jeremias, Wittenbeck Valerij
autogenerated on Mon Feb 28 2022 21:53:50