world_canvas_utils.py
Go to the documentation of this file.
00001 #!/usr/bin/env python
00002 #
00003 # License: BSD
00004 #   https://raw.github.com/robotics-in-concert/rocon_qt_gui/license/LICENSE
00005 #
00006 ##############################################################################
00007 
00008 import tf
00009 import rospy
00010 from world_canvas_msgs.msg import Annotation
00011 import unique_id
00012 from rospy_message_converter import message_converter
00013 from tf.transformations import quaternion_from_euler
00014 from math import radians
00015 import ar_track_alvar_msgs.msg as ar_msgs
00016 import yocs_msgs.msg as yocs_msgs
00017 
00018 def create_map_annotation(world, map_name, map_msg):
00019     ann = Annotation()
00020     ann.timestamp = rospy.Time.now()
00021     ann.world = world
00022     ann.name = map_name
00023     ann.type = 'nav_msgs/OccupancyGrid'
00024     ann.keywords.append(map_name)
00025     ann.shape = 1 # CUBE
00026     ann.color.r = 0.2
00027     ann.color.g = 0.2
00028     ann.color.b = 0.2
00029     ann.color.a = 0.01
00030     ann.size.x = map_msg.info.width * map_msg.info.resolution
00031     ann.size.y = map_msg.info.height * map_msg.info.resolution
00032     ann.size.z = 0.000001
00033     ann.pose.header.frame_id = '/map'
00034     ann.pose.header.stamp = rospy.Time.now()
00035     ann.pose.pose.pose = map_msg.info.origin
00036     return ann
00037 
00038 def create_alvar_marker_from_info(annotation_info, world, frame_id):
00039     ann = Annotation()
00040     ann.timestamp = rospy.Time.now()
00041     ann.id = unique_id.toMsg(unique_id.fromRandom())
00042     ann.world = world
00043     ann.name = "marker " + str(annotation_info['name'])
00044     ann.type = 'ar_track_alvar_msgs/AlvarMarker'
00045     ann.keywords.append(str(world))
00046     ann.shape = 0 # Cylinder 
00047     ann.color.r = 1.0
00048     ann.color.g = 1.0
00049     ann.color.b = 1.0
00050     ann.color.a = 1.0
00051     ann.size.x = 0.18 
00052     ann.size.y = 0.18
00053     ann.size.z = 0.01
00054     ann.pose.header.frame_id = frame_id
00055     ann.pose.header.stamp = rospy.Time.now()
00056     ann.pose.pose.pose.position.x = annotation_info['x']
00057     ann.pose.pose.pose.position.y = annotation_info['y']
00058     ann.pose.pose.pose.position.z = annotation_info['height']
00059     (ann.pose.pose.pose.orientation.x, ann.pose.pose.pose.orientation.y, ann.pose.pose.pose.orientation.z, ann.pose.pose.pose.orientation.w) = tf.transformations.quaternion_from_euler(radians(annotation_info['roll']), radians(annotation_info['pitch']), radians(annotation_info['yaw']))
00060 
00061     obj = ar_msgs.AlvarMarker()
00062     obj.id = int(annotation_info['name'])
00063     obj.confidence = 80
00064     obj.pose.header = ann.pose.header
00065     obj.pose.pose = ann.pose.pose.pose
00066 
00067     return ann, obj
00068 
00069 def create_waypoint_from_info(annotation_info, world, frame_id):
00070     ann = Annotation()
00071     ann.timestamp = rospy.Time.now()
00072     ann.id = unique_id.toMsg(unique_id.fromRandom())
00073     ann.world = world
00074     ann.name = annotation_info['name']
00075     ann.type = 'yocs_msgs/Waypoint'
00076     ann.keywords.append(str(world))
00077     ann.shape = 3 # Arrow
00078     ann.color.r = 0.2
00079     ann.color.g = 0.2
00080     ann.color.b = 0.8
00081     ann.color.a = 0.5
00082     ann.size.x = float(annotation_info['radius']) * 2
00083     ann.size.y = float(annotation_info['radius']) * 2
00084     ann.size.z = float(annotation_info['height'])
00085     ann.pose.header.frame_id = frame_id
00086     ann.pose.header.stamp = rospy.Time.now()
00087     ann.pose.pose.pose.position.x = annotation_info['x']
00088     ann.pose.pose.pose.position.y = annotation_info['y']
00089     ann.pose.pose.pose.position.z = 0.0#annotation_info['height']
00090     (ann.pose.pose.pose.orientation.x, ann.pose.pose.pose.orientation.y, ann.pose.pose.pose.orientation.z, ann.pose.pose.pose.orientation.w) = tf.transformations.quaternion_from_euler(radians(annotation_info['roll']), radians(annotation_info['pitch']), radians(annotation_info['yaw']))
00091 
00092     obj = yocs_msgs.Waypoint()
00093     obj.name = annotation_info['name'] 
00094     obj.header.frame_id = frame_id
00095     obj.header.stamp = rospy.Time.now()
00096     obj.pose.position.x = annotation_info['x']
00097     obj.pose.position.y = annotation_info['y']
00098     obj.pose.position.z = 0.0
00099     (obj.pose.orientation.x, obj.pose.orientation.y, obj.pose.orientation.z, obj.pose.orientation.w) = tf.transformations.quaternion_from_euler(radians(annotation_info['roll']), radians(annotation_info['pitch']), radians(annotation_info['yaw']))
00100 
00101     # waypoints are assumed to lay on the floor, so z coordinate is zero;
00102     # but WCF assumes that the annotation pose is the center of the object
00103     ann.pose.pose.pose.position.z += ann.size.z/2.0
00104 
00105     return ann, obj


rocon_qt_library
Author(s): Donguk Lee
autogenerated on Fri Feb 12 2016 02:50:13