world_model_stand_alone_scenario.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 
3 '''
4 Copyright (c) 2016, Aumann Florian, Borella Jocelyn, Hutmacher Robin, Karrenbauer Oliver, Meissner Pascal, Schleicher Ralf, Stoeckle Patrick, Trautmann Jeremias
5 All rights reserved.
6 
7 Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
8 
9 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
10 
11 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.
12 
13 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.
14 
15 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.
16 '''
17 
18 import roslib
19 import rospy
20 import numpy
21 import tf
22 import tf2_ros
23 import time
24 import random
25 
26 from geometry_msgs.msg import (Pose, PoseWithCovariance, PoseWithCovarianceStamped, Point, Quaternion, Twist, Vector3)
27 from asr_msgs.msg import AsrObject
28 from actionlib import *
29 from actionlib.msg import *
30 from asr_next_best_view.msg import RobotStateMessage
31 from asr_next_best_view.srv import CalculateCameraPose, TriggerFrustumVisualization, GetPose
32 from sensor_msgs.msg import JointState
33 from asr_world_model.srv import PushFoundObject, PushFoundObjectList, GetFoundObjectList, EmptyViewportList
34 
35 def push_object_in_wm(detected_objects):
36  try:
37  rospy.wait_for_service('/env/asr_world_model/push_found_object_list',timeout=3)
38  push_found_objects = rospy.ServiceProxy('/env/asr_world_model/push_found_object_list', PushFoundObjectList)
39  push_found_objects(detected_objects)
40  except (rospy.exceptions.ROSException, rospy.ServiceException) as e:
41  rospy.logwarn("Could not find world_model service")
42  sys.exit(1)
43 
45  try:
46  rospy.wait_for_service('/env/asr_world_model/get_found_object_list',timeout=3)
47  get_found_objects = rospy.ServiceProxy('/env/asr_world_model/get_found_object_list', GetFoundObjectList)
48  print get_found_objects()
49  except (rospy.exceptions.ROSException, rospy.ServiceException) as e:
50  rospy.logwarn("Could not find world_model service")
51  sys.exit(1)
52 
54  try:
55  rospy.wait_for_service('/env/asr_world_model/empty_viewport_list',timeout=3)
56  get_found_objects = rospy.ServiceProxy('/env/asr_world_model/empty_viewport_list', EmptyViewportList)
57  get_found_objects()
58  except (rospy.exceptions.ROSException, rospy.ServiceException) as e:
59  rospy.logwarn("Could not find world_model service")
60  sys.exit(1)
61 
62 
64  obj = AsrObject()
65  obj.type = 'CoffeeBox'
66  obj.header.frame_id = '/camera_left_frame'
67  obj.identifier = '0'
68  obj.providedBy = 'textured'
69  obj.colorName = 'textured'
70  obj.meshResourcePath = 'package://asr_object_database/rsc/databases/textured_objects/CoffeeBox/CoffeeBox.dae'
71  pose_cov = PoseWithCovariance()
72  pose_cov.pose.position.x = random.gauss(0,0.01)
73  pose_cov.pose.position.y = random.gauss(0,0.01) + random.randint(0, 1)
74  pose_cov.pose.position.z = 1.12
75  if random.randint(0, 5) == 0:
76  pose_cov.pose.position.x = pose_cov.pose.position.x + 1
77  q = tf.transformations.quaternion_from_euler(90, 0, 0, 'rzyx')
78  pose_cov.pose.orientation = Quaternion(*q)
79  obj.sampledPoses.append(pose_cov)
80  return obj
81 
82 def get_smacks():
83  obj = AsrObject()
84  obj.type = 'Smacks'
85  obj.header.frame_id = '/camera_left_frame'
86  obj.identifier = '0'
87  obj.providedBy = 'textured'
88  obj.colorName = 'textured'
89  obj.meshResourcePath = 'package://asr_object_database/rsc/databases/textured_objects/Smacks/Smacks.dae'
90  pose_cov = PoseWithCovariance()
91  pose_cov.pose.position.x = random.gauss(0,0.5)
92  pose_cov.pose.position.y = random.gauss(0,0.5)
93  pose_cov.pose.position.z = 1.12
94  q = tf.transformations.quaternion_from_euler(90, 0, 0, 'rzyx')
95  pose_cov.pose.orientation = Quaternion(*q)
96  obj.sampledPoses.append(pose_cov)
97  return obj
98 
99 if __name__ == '__main__':
100  global detected_objects
101  # Initialize the node and name it.
102  rospy.init_node('test_world_model')
103  object_list = []
104  for i in range(500):
105  found_object = AsrObject()
106  found_object = get_coffee_box()
107  object_list.append(found_object)
108  push_object_in_wm(object_list)
110  for i in range(500):
111  found_object = AsrObject()
112  found_object = get_coffee_box()
113  object_list.append(found_object)
114  push_object_in_wm(object_list)


asr_world_model
Author(s): Aumann Florian, Borella Jocelyn, Hutmacher Robin, Karrenbauer Oliver, Meißner Pascal, Schleicher Ralf, Stöckle Patrick, Trautmann Jeremias
autogenerated on Thu Jan 9 2020 07:20:01