rviz.py
Go to the documentation of this file.
00001 
00002 # Software License Agreement (BSD License)
00003 #
00004 #  Copyright (c) 2010, UC Regents
00005 #  All rights reserved.
00006 #
00007 #  Redistribution and use in source and binary forms, with or without
00008 #  modification, are permitted provided that the following conditions
00009 #  are met:
00010 #
00011 #   * Redistributions of source code must retain the above copyright
00012 #     notice, this list of conditions and the following disclaimer.
00013 #   * Redistributions in binary form must reproduce the above
00014 #     copyright notice, this list of conditions and the following
00015 #     disclaimer in the documentation and/or other materials provided
00016 #     with the distribution.
00017 #   * Neither the name of the University of California nor the names of its
00018 #     contributors may be used to endorse or promote products derived
00019 #     from this software without specific prior written permission.
00020 #
00021 #  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00022 #  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00023 #  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
00024 #  FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
00025 #  COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
00026 #  INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
00027 #  BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00028 #  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00029 #  CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00030 #  LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
00031 #  ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00032 #  POSSIBILITY OF SUCH DAMAGE.
00033 
00034 import rospy
00035 from numpy import array
00036 from visualization_msgs.msg import Marker
00037 from geometry_msgs.msg import Point
00038 
00039 def ellipsoid_marker(position, size=[0.1, 0.1, 0.1], rgba=[1.0, 1.0, 1.0, 1.0], 
00040                      ns="", id=0, frame_id="", lifetime=None, stamp=None):
00041     marker = Marker()
00042     if stamp is None:
00043         marker.header.stamp = rospy.Time.now()
00044     else:
00045         marker.header.stamp = stamp
00046     marker.header.frame_id = frame_id
00047     marker.ns = ns
00048     marker.id = id
00049     marker.type = Marker.SPHERE
00050     marker.action = Marker.ADD
00051     marker.pose.position.x = position[0]
00052     marker.pose.position.y = position[1]
00053     marker.pose.position.z = position[2]
00054     marker.scale.x = size[0]
00055     marker.scale.y = size[1]
00056     marker.scale.z = size[2]
00057     marker.color.r = rgba[0]
00058     marker.color.g = rgba[1]
00059     marker.color.b = rgba[2]
00060     marker.color.a = rgba[3]
00061     if lifetime is None:
00062         marker.lifetime = rospy.Duration()
00063     else:
00064         marker.lifetime = rospy.Duration(lifetime)
00065     return marker
00066 
00067 def arrow_marker(position, direction, shaft_radius=0.02, head_radius=0.04, rgba=[1.0, 1.0, 1.0, 1.0], 
00068                      ns="", id=0, frame_id="", lifetime=None, stamp=None):
00069     marker = Marker()
00070     if stamp is None:
00071         marker.header.stamp = rospy.Time.now()
00072     else:
00073         marker.header.stamp = stamp
00074     marker.header.frame_id = frame_id
00075     marker.ns = ns
00076     marker.id = id
00077     marker.type = Marker.ARROW
00078     marker.action = Marker.ADD
00079     #marker.pose.position.x = position[0]
00080     #marker.pose.position.y = position[1]
00081     #marker.pose.position.z = position[2]
00082     marker.points = [Point(*tuple(position)), Point(*tuple(position+direction*1.0))]
00083     marker.scale.x = shaft_radius
00084     marker.scale.y = head_radius
00085     marker.scale.z = 1.0
00086     marker.color.r = rgba[0]
00087     marker.color.g = rgba[1]
00088     marker.color.b = rgba[2]
00089     marker.color.a = rgba[3]
00090     if lifetime is None:
00091         marker.lifetime = rospy.Duration()
00092     else:
00093         marker.lifetime = rospy.Duration(lifetime)
00094     return marker
00095 
00096 def mesh_marker(position, orientation=None, mesh_resource="", rgba=[1.0, 1.0, 1.0, 1.0],
00097                 ns="", id=0, frame_id="", lifetime=None, stamp=None):
00098     marker = Marker()
00099     if stamp is None:
00100         marker.header.stamp = rospy.Time.now()
00101     else:
00102         marker.header.stamp = stamp
00103     marker.header.frame_id = frame_id
00104     marker.ns = ns
00105     marker.id = id
00106     marker.type = Marker.MESH_RESOURCE
00107     marker.mesh_resource = mesh_resource
00108     marker.action = Marker.ADD
00109     marker.pose.position.x = position[0]
00110     marker.pose.position.y = position[1]
00111     marker.pose.position.z = position[2]
00112     if orientation is not None:
00113         marker.pose.orientation.x = orientation[0] 
00114         marker.pose.orientation.y = orientation[1] 
00115         marker.pose.orientation.z = orientation[2] 
00116         marker.pose.orientation.w = orientation[3] 
00117     #marker.points = [Point(*tuple(position)), Point(*tuple(position+direction*1.0))]
00118     marker.scale.x = 1.0
00119     marker.scale.y = 1.0
00120     marker.scale.z = 1.0
00121     marker.color.r = rgba[0]
00122     marker.color.g = rgba[1]
00123     marker.color.b = rgba[2]
00124     marker.color.a = rgba[3]
00125     if lifetime is None:
00126         marker.lifetime = rospy.Duration()
00127     else:
00128         marker.lifetime = rospy.Duration(lifetime)
00129     return marker
00130 
00131 def spherelist_marker(points, size=[0.1, 0.1, 0.1], rgba=[1.0, 1.0, 1.0, 1.0], 
00132                      ns="", id=0, frame_id="", lifetime=None, stamp=None):
00133     marker = Marker()
00134     if stamp is None:
00135         marker.header.stamp = rospy.Time.now()
00136     else:
00137         marker.header.stamp = stamp
00138     marker.header.frame_id = frame_id
00139     marker.ns = ns
00140     marker.id = id
00141     marker.type = Marker.SPHERE_LIST
00142     marker.action = Marker.ADD
00143     for i in range(len(points)):
00144         marker.points.append(points[i])
00145     marker.scale.x = size[0]
00146     marker.scale.y = size[1]
00147     marker.scale.z = size[2]
00148     marker.color.r = rgba[0]
00149     marker.color.g = rgba[1]
00150     marker.color.b = rgba[2]
00151     marker.color.a = rgba[3]
00152     if lifetime is None:
00153         marker.lifetime = rospy.Duration()
00154     else:
00155         marker.lifetime = rospy.Duration(lifetime)
00156     return marker
00157 


flyer_common
Author(s): Patrick Bouffard
autogenerated on Sun Jan 5 2014 11:37:49