converts.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 # Imports
00008 ##############################################################################
00009 import rospy
00010 import copy
00011 from math import cos, sin
00012 import sensor_msgs.msg as sensor_msgs
00013 import geometry_msgs.msg as geometry_msgs
00014 from visualization_msgs.msg import MarkerArray, Marker
00015 
00016 ##############################################################################
00017 # converter Function
00018 ##############################################################################
00019 def laser_scan_to_point_cloud(laser_scan_msg, density=100):
00020     """
00021         Change type 
00022 
00023         :param sensor_msgs.LaserScan laser_scan_msg: laser scans data (r, theta) type
00024         :param int intensity: laser scans data (r, theta) type
00025 
00026     """
00027     point_cloud = sensor_msgs.PointCloud()
00028     point_cloud.header.frame_id = laser_scan_msg.header.frame_id
00029 
00030     for idx in range(0, len(laser_scan_msg.ranges), 100/density):
00031         point = geometry_msgs.Point32()
00032         a = laser_scan_msg.angle_min + laser_scan_msg.angle_increment * idx
00033         point.x = laser_scan_msg.ranges[idx] * cos(a)
00034         point.y = laser_scan_msg.ranges[idx] * sin(a)
00035         point_cloud.points.append(point)
00036     return point_cloud
00037 
00038 def annotations_to_viz_markers(annotations):
00039     '''
00040         world_canvas_msgs.Annotations to visualization_msgs.MarkerArray
00041     '''
00042     markers_list = MarkerArray()
00043     marker_id = 1
00044     for a in annotations:
00045         marker, label = anntation_to_viz_marker(a, marker_id)
00046         markers_list.markers.append(marker)
00047         markers_list.markers.append(label)
00048         marker_id = marker_id + 1
00049 
00050     return markers_list
00051 
00052 def anntation_to_viz_marker(a, marker_id):
00053     # Marker
00054     marker = Marker()
00055     marker.id = marker_id
00056     marker.header = a.pose.header
00057     marker.type = a.shape
00058     marker.ns = a.type
00059     marker.action = Marker.ADD
00060     marker.lifetime = rospy.Duration.from_sec(0)
00061     marker.pose = copy.deepcopy(a.pose.pose.pose)
00062     marker.scale = a.size
00063     marker.color = a.color
00064 
00065     # view facing text
00066     label = copy.deepcopy(marker)
00067     label.id = label.id + 1000000 # marker id must be unique
00068     label.type = Marker.TEXT_VIEW_FACING
00069     label.text = a.name  #+ ' [' + a.type + ']'
00070     label.pose.position.z = label.pose.position.z + label.scale.z/2.0 + 0.1 # just above the visual
00071     label.scale.x = label.scale.y = label.scale.z = 0.3
00072     label.color.r = label.color.g = label.color.b = label.color.a = 1.0
00073 
00074     return marker, label


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