4 import roslib; roslib.load_manifest(
'jsk_interactive_test')
7 import httplib, urllib2, urllib, json
8 from socket
import gethostname
9 from getpass
import getuser
12 from std_msgs.msg
import ColorRGBA
13 from geometry_msgs.msg
import Vector3, Pose, Point, Quaternion, PoseStamped
14 from visualization_msgs.msg
import MarkerArray, Marker
17 from tf
import transformations
30 url =
'http://jsk-db.herokuapp.com/interactive_marker_test' 31 params = {
'ui_type': ui_type,
32 'user':
'%s@%s' % (getuser(), gethostname()),
34 data = urllib.urlencode(params)
35 req = urllib2.Request(url, data)
37 response = urllib2.urlopen(req)
39 rospy.logfatal(
'failed to record result')
42 url =
'http://jsk-db.herokuapp.com/interactive_marker_test/json' 43 req = urllib2.Request(url)
45 response = urllib2.urlopen(req)
46 data = json.loads(response.read())
47 rospy.loginfo(
"======================================================")
48 rospy.loginfo(
" http://jsk-db.herokuapp.com/interactive_marker_test")
49 rospy.loginfo(
" user / ui_type / time")
51 rospy.loginfo(
"%12s / %8s / %s sec", d[
'user'], d[
'ui_type'], d[
'time'])
52 rospy.loginfo(
"======================================================")
54 rospy.logfatal(
'failed to record result')
61 i = min(range(size*size*size),key=
lambda i:numpy.linalg.norm(numpy.array([self.
poses[i].position.x,self.
poses[i].position.y,self.
poses[i].position.z])-
62 numpy.array([feedback.pose.position.x,feedback.pose.position.y,feedback.pose.position.z])))
64 pos = numpy.linalg.norm(numpy.array([p.position.x,p.position.y,p.position.z])-
65 numpy.array([feedback.pose.position.x,feedback.pose.position.y,feedback.pose.position.z]))
70 rot = math.acos(numpy.dot(transformations.quaternion_matrix([p.orientation.x,p.orientation.y,p.orientation.z,p.orientation.w])[0:3,2],
71 transformations.quaternion_matrix([feedback.pose.orientation.x,feedback.pose.orientation.y,feedback.pose.orientation.z,feedback.pose.orientation.w])[0:3,2]))
73 rospy.loginfo(
'error %6.3f / %6.3f'%(pos, numpy.rad2deg(rot)))
75 self.
colors[i] = ColorRGBA(1.0,0.2,0.2,0.8)
79 self.server.setPose(
'control', msg.pose, msg.header)
80 self.server.applyChanges()
84 pub_goal = rospy.Publisher(
'interactive_goal_marker', MarkerArray)
85 rospy.init_node(
'publish_interactive_goal_marker')
86 self.
ui_type = rospy.get_param(
'~ui_type')
92 hand_mesh =
'file://'+roslib.packages.get_pkg_dir(
'jsk_interactive_test')+
'/scripts/RobotHand.dae' 93 hand_mesh_scale = Vector3(0.2, 0.2, 0.2)
94 goal_mesh =
'file://'+roslib.packages.get_pkg_dir(
'jsk_interactive_test')+
'/scripts/Bottle.dae' 95 goal_mesh_scale = Vector3(1.0, 1.0, 1.0)
100 rospy.Subscriber(
'/goal_marker/move_marker', PoseStamped, self.
poseCB)
102 for i
in range(size*size*size):
103 x = space * ((i%(size) - size/2) + numpy.random.normal(0,0.1))
104 y = space * (((i/(size))%size - size/2) + numpy.random.normal(0,0.1))
105 z = space * ((i/(size*size) - size/2) + numpy.random.normal(0,0.1))
106 q = transformations.quaternion_from_euler(*numpy.random.normal(0,0.7,3))
107 self.poses.append(Pose(Point(x,y,z), Quaternion(*q)))
108 self.colors.append(ColorRGBA(0.8,0.8,0.8,0.8))
109 self.status.append(
False)
114 int_marker = InteractiveMarker()
115 int_marker.header.frame_id =
"/map" 116 int_marker.name =
"control" 117 int_marker.scale = 0.3
119 mesh_marker = Marker()
120 mesh_marker.type = Marker.MESH_RESOURCE
121 mesh_marker.scale = hand_mesh_scale
122 mesh_marker.color = ColorRGBA(0.2,0.2,1.0,0.8)
123 mesh_marker.mesh_resource = hand_mesh
125 target_marker = Marker()
126 target_marker.type = Marker.CYLINDER
127 target_marker.scale = Vector3(0.07,0.07,0.1)
128 target_marker.color = ColorRGBA(0.4,0.4,1.0,0.6)
130 mesh_control = InteractiveMarkerControl()
131 mesh_control.always_visible =
True 132 mesh_control.markers.append(mesh_marker)
133 mesh_control.markers.append(target_marker)
135 int_marker.controls.append(mesh_control)
137 if rospy.has_param(rospy.search_param(
'make_interactive_marker_arrow'))
and rospy.get_param(rospy.search_param(
'make_interactive_marker_arrow')):
138 control = InteractiveMarkerControl()
139 control.orientation.w = 1
140 control.orientation.x = 1
141 control.orientation.y = 0
142 control.orientation.z = 0
143 control.interaction_mode = InteractiveMarkerControl.ROTATE_AXIS
144 int_marker.controls.append(copy.deepcopy(control))
145 control.orientation.w = 1
146 control.orientation.x = 0
147 control.orientation.y = 1
148 control.orientation.z = 0
149 control.interaction_mode = InteractiveMarkerControl.ROTATE_AXIS
150 int_marker.controls.append(copy.deepcopy(control))
151 control.orientation.w = 1
152 control.orientation.x = 0
153 control.orientation.y = 0
154 control.orientation.z = 1
155 control.interaction_mode = InteractiveMarkerControl.ROTATE_AXIS
156 int_marker.controls.append(copy.deepcopy(control))
157 control.orientation.w = 1
158 control.orientation.x = 1
159 control.orientation.y = 0
160 control.orientation.z = 0
161 control.interaction_mode = InteractiveMarkerControl.MOVE_AXIS
162 int_marker.controls.append(copy.deepcopy(control))
163 control.orientation.w = 1
164 control.orientation.x = 0
165 control.orientation.y = 1
166 control.orientation.z = 0
167 control.interaction_mode = InteractiveMarkerControl.MOVE_AXIS
168 int_marker.controls.append(copy.deepcopy(control))
169 control.orientation.w = 1
170 control.orientation.x = 0
171 control.orientation.y = 0
172 control.orientation.z = 1
173 control.interaction_mode = InteractiveMarkerControl.MOVE_AXIS
174 int_marker.controls.append(copy.deepcopy(control))
177 server.applyChanges()
181 while not rospy.is_shutdown():
182 array = MarkerArray()
183 for i
in range(size*size*size):
185 msg.header.stamp = rospy.get_rostime()
186 msg.header.frame_id =
'/map' 187 msg.mesh_use_embedded_materials =
False 188 msg.mesh_resource = goal_mesh
189 msg.type = Marker.MESH_RESOURCE
190 msg.scale = goal_mesh_scale
191 msg.color = self.
colors[i]
192 msg.pose = self.
poses[i]
193 msg.lifetime = rospy.Time(10)
195 array.markers.append(msg)
198 msg.header.stamp = rospy.get_rostime()
199 msg.header.frame_id =
'/map' 200 msg.type = Marker.TEXT_VIEW_FACING
206 msg.text =
'Done, time = %5.2f'%(self.
done_time)
207 msg.lifetime = rospy.Time(10)
208 msg.id = size*size*size
209 array.markers.append(msg)
210 pub_goal.publish(array)
213 rospy.loginfo(
"%2d/%d %5.2f"%(len(filter(
lambda x: x !=
False, self.
status)),len(self.
status),float((rospy.get_rostime()-self.
start_time).to_sec())))
216 rospy.loginfo(
"Done.. %5.2f"%self.
done_time)
221 rospy.loginfo(
"%5.2f"%s.to_sec())
223 if __name__ ==
'__main__':
226 except rospy.ROSInterruptException:
def processFeedback(self, feedback)
def recordResult(self, ui_type, time)