00001
00002 import roslib; roslib.load_manifest('projector_interface')
00003 from std_msgs.msg import ColorRGBA
00004 from pr2_python.pointclouds import pointcloud2_to_xyz_array, xyz_array_to_pointcloud2
00005 import datetime
00006 import scipy.io
00007 import numpy as np
00008 from itertools import chain
00009
00010
00011 from point_tests import sameObject, closestPoint
00012
00013 load('rosh_robot', globals())
00014
00015 xmin = -0.79651666
00016 xmax = 0.06501853
00017 ymin = 0.03261997
00018 ymax = 0.50817382
00019
00020
00021 ys = np.linspace(ymin,ymax,3)
00022 xs = np.arange(xmin+0.05, xmax, ys[1] - ys[0])
00023 xx, yy = np.meshgrid(xs, ys)
00024 points = np.array([(x,y,0) for x,y in zip(xx.ravel(), yy.ravel())])
00025 points_msg = xyz_array_to_pointcloud2(points, now(), '/table')
00026 topics.object_cloud(points_msg)
00027 services.set_selection_method(1)
00028
00029 order = [
00030 [0, 2, 1, 3],
00031 [7, 5, 6, 4],
00032 [8, 10, 9, 11],
00033 [0, 4, 8 ],
00034 [1, 5, 9 ],
00035 [2, 6, 10],
00036 [3, 7, 11]
00037 ]
00038
00039 targets = []
00040 stds = []
00041 times = []
00042 cursor_history = []
00043 history_size = 0
00044
00045 start_time = now()
00046 for idx in chain(*[reversed(o) for o in order]):
00047 point = points[idx]
00048 targets.append(point)
00049 print 'hilighting ', point
00050 services.clear_hilights()
00051
00052 pt = PointStamped()
00053 pt.header.frame_id = '/table'
00054 pt.header.stamp = now()
00055 pt.point.x, pt.point.y, pt.point.z = point
00056
00057 t1 = now()
00058 services.hilight_object(pt, ColorRGBA(255,0,0,0))
00059 click_pts_msg = services.get_cursor_stats()
00060 click_pt = [
00061 click_pts_msg.click_pos.point.x,
00062 click_pts_msg.click_pos.point.y,
00063 click_pts_msg.click_pos.point.z
00064 ]
00065 r = Rate(10)
00066 while not sameObject(closestPoint(points, click_pt), point):
00067 click_pts_msg = services.get_cursor_stats()
00068 click_pt = [
00069 click_pts_msg.click_pos.point.x,
00070 click_pts_msg.click_pos.point.y,
00071 click_pts_msg.click_pos.point.z
00072 ]
00073 r.sleep()
00074 click_pts = pointcloud2_to_xyz_array(click_pts_msg.points)
00075 t2 = now()
00076 times.append((t2-t1).to_sec())
00077 history_size = click_pts.shape[0]
00078 cursor_history.extend(click_pts)
00079 stds.append(click_pts.std(0))
00080 print 'std = ', stds[-1]
00081 sleep(3)
00082
00083 services.clear_hilights()
00084 path = '/home/robotics/lazewatskyd/ros-pkgs/wu-ros-pkg/3d_interaction/projector_interface/study/data/2_closest_point_%s.mat'
00085 timestr = datetime.datetime.today().strftime('%d-%m-%y-%H.%M.%f')
00086 scipy.io.savemat(path % timestr, dict(targets=targets,
00087 stds=stds,
00088 times=times,
00089 cursor_history=cursor_history,
00090 history_size=history_size,
00091 total_time=(now()-start_time).to_sec()))
00092 print 'Saved %s' % (path % timestr)