cropbox_search_states.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 __builtin__
24 import tf
25 import math
26 import dynamic_reconfigure.client
27 
28 from asr_msgs.msg import AsrAttributedPointCloud, AsrAttributedPoint
29 from geometry_msgs.msg import Pose, Point, Quaternion
30 from nav_msgs.msg import OccupancyGrid
31 
32 from common.evaluation_decorators import *
33 from asr_world_model.srv import GetIntermediateObjectWeight, GetRecognizerName
34 
35 class CropBoxGeneration(smach.State):
36  """
37  Please enter some comments here!
38  """
39 
40  def __init__(self):
41  smach.State.__init__(
42  self,
43  outcomes=['succeeded', 'aborted'],
44  output_keys=['object_pointcloud'])
45  self.isInitDone = 0
46  # You can activate the params for dynamic reconfigure of the NBV here
47  self.newMOmegaUtility = None #320
48  self.newMOmegaBase = None #50
49 
50 
51  def initNode(self):
52  rospy.loginfo('Init CROP_BOX_GENERATION')
53  self.isInitDone = 1
54  self.isWaitForMap = 0
55  self.isReconfigDone = 0
56  rospy.Subscriber("map", OccupancyGrid, self.mapCallback)
57  self.reconfigureNBV()
58  self.initSteps()
59 
60  self.objectType = rospy.get_param('/scene_exploration_sm/PlaceholderObjectTypeInCropboxSearch')
61  self.identifier = rospy.get_param('/scene_exploration_sm/PlaceholderIdentifierInCropboxSearch')
62  rospy.loginfo(str(self.objectType) + " with identifier " + str(self.identifier) + " will be used for CropBoxGeneration.")
63 
64  r = rospy.Rate(20) # 20hz
65  rospy.loginfo('Wait for callback from map and reconfiguration of NBV')
66  while (self.isWaitForMap == 0 or self.isReconfigDone == 0):
67  r.sleep()
68 
69  def mapCallback(self, data):
70  self.width = (data.info.width * data.info.resolution) / 2 + 0.48
71  self.length = (data.info.height * data.info.resolution) / 2 + 0.35
72  self.height = rospy.get_param("/scene_exploration_sm/RoomHeight")
73  rospy.loginfo('Points in point_cloud are generated between width: ' + str(-self.width) + ' x ' + str(self.width)
74  + ', length: ' + str(-self.length) + ' x ' + str(self.length) + ' and height: ' + str(0) + ' x ' + str(self.height))
75  self.isWaitForMap = 1
76 
77  def initSteps(self):
78  fcp = rospy.get_param("/nbv/fcp")
79  ncp = rospy.get_param("/nbv/ncp")
80 
81  distToMiddleOfFrustum = (fcp + ncp) / 2.0
82  fovx = rospy.get_param("/nbv/fovx")
83  self.groudStep = min(distToMiddleOfFrustum * math.tan(math.radians(fovx) / 2.0), (fcp - ncp))
84 
85  fovy = rospy.get_param("/nbv/fovy")
86  self.heightStep = distToMiddleOfFrustum * math.tan(math.radians(fovy) / 2.0)
87  rospy.loginfo("Interval of points in point_cloud on groud: " + str(self.groudStep) + " and in height: " + str(self.heightStep))
88 
89 
90  def reconfigureNBVCallback(self, config):
91  if ((self.newMOmegaUtility is None or config.groups.groups.Rating.mOmegaUtility == self.newMOmegaUtility) and
92  (self.newMOmegaBase is None or config.groups.groups.Rating.mOmegaBase == self.newMOmegaBase) and
93  config.groups.groups.Other.enableCropBoxFiltering == True and
94  config.groups.groups.Other.enableIntermediateObjectWeighting == False):
95  rospy.loginfo("Dynamic reconfiguration of NBV done.")
96  self.isReconfigDone = 1
97 
98  def reconfigureNBV(self):
99  mapToSet = {"enableCropBoxFiltering": True, "enableIntermediateObjectWeighting": False}
100  rospy.loginfo("Dynamic reconfigure of NBV: enableCropBoxFiltering=True and enableIntermediateObjectWeighting=False")
101 
102  if self.newMOmegaUtility is not None:
103  rospy.loginfo("Dynamic reconfigure of NBV: mOmegaUtility=" + str(self.newMOmegaUtility))
104  mapToSet.update({"mOmegaUtility": self.newMOmegaUtility})
105  if self.newMOmegaBase is not None:
106  rospy.loginfo("Dynamic reconfigure of NBV: mOmegaBase=" + str(self.newMOmegaBase))
107  mapToSet.update({"mOmegaBase": self.newMOmegaBase})
108 
109  client = dynamic_reconfigure.client.Client("nbv", timeout=30, config_callback=self.reconfigureNBVCallback)
110  client.update_configuration(mapToSet)
111 
112 
113  @log
114  @key_press
115  @timed
116  def execute(self, userdata):
117  rospy.loginfo('Executing CROP_BOX_GENERATION')
118  if (self.isInitDone == 0):
119  if self.initNode() == 'aborted':
120  return 'aborted'
121 
122  point_cloud = AsrAttributedPointCloud()
123 
124  for x in self.frange(-self.width, self.width, self.groudStep):
125  for y in self.frange(-self.length, self.length, self.groudStep):
126  for z in self.frange(0.0, self.height, self.heightStep):
127  point = AsrAttributedPoint()
128  point.pose.position = Point(*[x, y, z])
129  point.pose.orientation = Quaternion(*tf.transformations.quaternion_from_euler(-1.57,0,0))
130  point.type = self.objectType
131  point.identifier = self.identifier
132  point_cloud.elements.append(point)
133  userdata.object_pointcloud = point_cloud
134  return 'succeeded'
135 
136 
137  def frange(self, start, stop, step):
138  i = start
139  while i <= stop:
140  yield i
141  i += step
142 


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