00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
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
00080
00081
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
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