4 Copyright (C) 2016, Allgeyer Tobias, Aumann Florian, Borella Jocelyn, Braun Kai, Heizmann Heinrich, Heller Florian, Mehlhaus Jonas, Meissner Pascal, Schleicher Ralf, Stoeckle Patrick, Walter Milena 6 This program is free software; you can redistribute it and/or modify 7 it under the terms of the GNU General Public License as published by 8 the Free Software Foundation; either version 2 of the License, or 9 (at your option) any later version. 11 This program is distributed in the hope that it will be useful, 12 but WITHOUT ANY WARRANTY; without even the implied warranty of 13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 GNU General Public License for more details. 16 You should have received a copy of the GNU General Public License along 17 with this program; if not, write to the Free Software Foundation, Inc., 18 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 24 from visualization_msgs.msg
import MarkerArray
25 from visualization_msgs.msg
import Marker
26 from geometry_msgs.msg
import Point
27 from rosparam
import upload_params
35 if len(matrix_1[0]) != len(matrix_2):
36 print "Invalid Matrix" 38 for i
in range(len(matrix_1)):
40 for j
in range(len(matrix_2[0])):
42 for k
in range(len(matrix_1[0])):
43 element = element + matrix_1[i][k] * matrix_2[k][j]
45 result_matrix.append(line)
51 result_vect.append(mat[0]*vector[0]+mat[1]*vector[1]+mat[2]*vector[2])
56 rotation_matrix_x = []
57 rotation_matrix_x.append([1,0,0])
58 rotation_matrix_x.append([0,math.cos(angle_x),-math.sin(angle_x)])
59 rotation_matrix_x.append([0,math.sin(angle_x),math.cos(angle_x)])
61 rotation_matrix_y = []
62 rotation_matrix_y.append([math.cos(angle_y),0,math.sin(angle_y)])
63 rotation_matrix_y.append([0,1,0])
64 rotation_matrix_y.append([-math.sin(angle_y),0,math.cos(angle_y)])
66 rotation_matrix_z = []
67 rotation_matrix_z.append([math.cos(angle_z),-math.sin(angle_z),0])
68 rotation_matrix_z.append([math.sin(angle_z),math.cos(angle_z),0])
69 rotation_matrix_z.append([0,0,1])
74 r = math.sqrt(x**2 + y**2 + z**2)
75 elev = math.acos(z / r)
80 x = r * math.sin(elev) * math.cos(az)
81 y = r * math.sin(elev) * math.sin(az)
82 z = r * math.cos(elev)
87 elev = sph[1] + d_elev
92 norm = math.sqrt(vec[0]**2 + vec[1]**2 + vec[2]**2)
94 return vec[0] / norm, vec[1] / norm, vec[2] / norm
99 x = float(
"{0:.5f}".format(vec[0]))
100 y = float(
"{0:.5f}".format(vec[1]))
101 z = float(
"{0:.5f}".format(vec[2]))
104 if __name__ ==
"__main__":
105 rospy.init_node(
'normal_generator_tool', anonymous=
True)
106 rospack = rospkg.RosPack()
109 f = open(rospack.get_path(
'asr_object_database') +
'/src/normal_generator_tool/normalsToolParams.yaml',
'r') 112 upload_params('/', yamlfile)
114 marker_frame = rospy.get_param(
'marker_frame')
115 pub_topic = rospy.get_param(
'pub_topic')
116 output_rel_path = rospy.get_param(
'output_rel_path')
117 base_vectors = rospy.get_param(
'base_vectors')
118 pan_min = rospy.get_param(
'pan')[0]
119 pan_max = rospy.get_param(
'pan')[1]
120 tilt_min = rospy.get_param(
'tilt')[0]
121 tilt_max = rospy.get_param(
'tilt')[1]
122 d_x = rospy.get_param(
'd_pan')
123 d_y = rospy.get_param(
'd_tilt')
124 publish_rate = rospy.get_param(
'publish_rate')
126 publisher = rospy.Publisher(pub_topic, MarkerArray, queue_size=10)
130 an_x = 90.0*math.pi/180
136 for base_vec
in base_vectors:
140 for pan_curr
in range(pan_min, pan_max + 1, d_x):
141 for tilt_curr
in range(tilt_min, tilt_max + 1, d_y):
142 d_az = pan_curr*math.pi/180
143 d_elev = tilt_curr*math.pi/180
152 for normal
in normals:
153 for idx,nor
in enumerate(normal):
155 output_string += str(nor) +
"," 157 output_string += str(nor)
160 print 'Created normals:' 162 print '--------------------' 164 fh = open(rospack.get_path(
'asr_object_database') + output_rel_path,
'w')
165 fh.writelines(output_string)
169 markerArray = MarkerArray()
171 size_vec = len(base_vectors)
174 color_step = 1.0 / size_vec
176 for normal
in normals:
177 hue = (marker_id / (len(normals) / size_vec)) * color_step + 0.0
178 rgb = colorsys.hsv_to_rgb(hue, 1.0, 1.0)
181 marker.id = marker_id
182 marker.header.frame_id = marker_frame
183 marker.ns =
'normals' 184 marker.scale.x = 0.01
187 marker.color.r = rgb[0]
188 marker.color.g = rgb[1]
189 marker.color.b = rgb[2]
192 point_start = Point()
194 point_end.x = normal[0]
195 point_end.y = normal[1]
196 point_end.z = normal[2]
197 marker.points.append(point_start)
198 marker.points.append(point_end)
200 marker.type = marker.ARROW
201 markerArray.markers.append(marker)
203 marker_id = marker_id +1
206 print 'Publishing normals (Rate: ' + str(publish_rate) +
' Hz)' 207 rate = rospy.Rate(publish_rate)
208 while not rospy.is_shutdown():
209 publisher.publish(markerArray)