~mrol-dev/mrol/trunk

« back to all changes in this revision

Viewing changes to mrol_ros/test/make_cup.py

  • Committer: Vikas Dhiman
  • Date: 2012-03-12 18:24:32 UTC
  • mfrom: (16.1.11 trunk)
  • Revision ID: wecacuee@gmail.com-20120312182432-all2q2rb80mzbzhj
Merging Julians changes.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
from __future__ import division
2
 
import roslib
3
 
roslib.load_manifest('mrol-mapping-ros-pkg')
4
 
import numpy as np
5
 
import pylab as p
6
 
#import matplotlib.axes3d as p3
7
 
import mpl_toolkits.mplot3d.axes3d as p3
8
 
import mrol_mapping.mapper as mapper
9
 
import mrol_mapping.poseutil as poseutil
10
 
 
11
 
import icp_mrol.icp_mrol as icp
12
 
 
13
 
 
14
 
 
15
 
def load_and_align(bestpose, fname, First=False, ICP=False):
16
 
    xyzs = np.loadtxt(fname)
17
 
    #(xyzs, _) = poseutil.transformPoints(xyzs, (0,0,0,np.deg2rad(60),0,0))
18
 
    xyzs = xyzs[(xyzs[:,0]<-0.1)]
19
 
    xyzs = xyzs[(xyzs[:,0]>-0.5)]
20
 
    xyzs = xyzs[(xyzs[:,1]<0.5)]
21
 
    xyzs = xyzs[(xyzs[:,1]>0.25)]
22
 
    xyzs = xyzs[(xyzs[:,2]>1.)]
23
 
    xyzs = xyzs[(xyzs[:,2]<1.3)]
24
 
    if First:
25
 
        return xyzs, bestpose
26
 
    else:
27
 
        if not ICP:
28
 
            bestpose = cupMapper.align_points(xyzs, bestpose)[0]
29
 
        else:
30
 
            bestpose = icp.align(bestpose, xyzs, cupMapper.get_voxels(), reject_threshold=res*10., terminate_threshold=res/100., iterations = 100, quiet=True)[0]
31
 
    (transform, _) = poseutil.transformPoints(xyzs, bestpose)
32
 
    return transform, bestpose
33
 
 
34
 
fig=p.figure()
35
 
ax = p3.Axes3D(fig)
36
 
 
37
 
res = 0.0003
38
 
cupMapper = mapper.VoxelMap(res,levels=6)
39
 
cupMapper.set_feature_range(0.25)
40
 
initpose = (0,0,0,0,0,0)
41
 
 
42
 
cup1, pose = load_and_align(initpose, 'segmented_points225.dat', First=True)
43
 
cupMapper.add_points(cup1,initpose)
44
 
 
45
 
ax.plot3D(cup1[:,0],cup1[:,1],cup1[:,2],'.')
46
 
ax.set_xlabel('X')
47
 
ax.set_ylabel('Y')
48
 
ax.set_zlabel('Z')
49
 
fig.add_axes(ax)
50
 
#p.show() # ctrl-c here?
51
 
 
52
 
print pose
53
 
 
54
 
cup2, pose = load_and_align(initpose, 'segmented_points234.dat') 
55
 
ax.plot3D(cup2[:,0],cup2[:,1],cup2[:,2],'.')
56
 
print pose
57
 
cupMapper.add_points(cup2,initpose)
58
 
 
59
 
cup3, pose = load_and_align(initpose, 'segmented_points265.dat')
60
 
ax.plot3D(cup3[:,0],cup3[:,1],cup3[:,2],'.')
61
 
print pose
62
 
cupMapper.add_points(cup3,initpose)
63
 
 
64
 
cup4, pose = load_and_align(initpose, 'segmented_points273.dat')
65
 
ax.plot3D(cup4[:,0],cup4[:,1],cup4[:,2],'.')
66
 
print pose
67
 
cupMapper.add_points(cup4,initpose)
68
 
 
69
 
cup5, pose = load_and_align(initpose, 'segmented_points296.dat')
70
 
ax.plot3D(cup5[:,0],cup5[:,1],cup5[:,2],'.')
71
 
print pose
72
 
cupMapper.add_points(cup5,initpose)
73
 
 
74
 
cup6, pose = load_and_align(initpose, 'segmented_points308.dat')
75
 
ax.plot3D(cup6[:,0],cup6[:,1],cup6[:,2],'.')
76
 
print pose
77
 
cupMapper.add_points(cup6,initpose)
78
 
 
79
 
cupModel = cupMapper.get_voxels()
80
 
cupModel = cupModel - np.mean(cupModel,axis=0)
81
 
 
82
 
np.savetxt('cupModel.dat',cupModel)
83
 
 
84
 
fig=p.figure()
85
 
ax = p3.Axes3D(fig)
86
 
ax.plot3D(cupModel[:,0],cupModel[:,1],cupModel[:,2],'.')
87
 
ax.set_xlabel('X')
88
 
ax.set_ylabel('Y')
89
 
ax.set_zlabel('Z')
90
 
fig.add_axes(ax)
91
 
 
92
 
p.show()