-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathCameraMove_ave10yaw.py
198 lines (152 loc) · 4.84 KB
/
CameraMove_ave10yaw.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
import viz
import vizact
import vizshape
import math
import datetime
import Queue
viz.go()#viz.PROMPT)
''' *************************** Set Up Scene **************************** '''
#ground = viz.add('tut_ground.wrl')
#sky = viz.clearcolor(viz.SKYBLUE)
#gallery = viz.addChild('gallery.osgb')
grid = vizshape.addGrid()
''' *********************** End of Scene set up ************************* '''
''' *************************** KINECT CODE ***************************** '''
#myHead = vrpn.addTracker( 'Tracker0@localhost', HEAD)
HEAD = 0
NECK = 1
TORSO = 2
WAIST = 3
LEFTCOLLAR = 4
LEFTSHOULDER = 5
LEFTELBOW = 6
LEFTWRIST = 7
LEFTHAND = 8
LEFTFINGERTIP = 9
RIGHTCOLLAR = 10
RIGHTSHOULDER = 11
RIGHTELBOW = 12
RIGHTWRIST = 13
RIGHTHAND = 14
RIGHTFINGERTIP = 15
LEFTHIP = 16
LEFTKNEE = 17
LEFTANKLE = 18
LEFTFOOT = 19
RIGHTHIP = 20
RIGHTKNEE = 21
RIGHTANKLE = 22
RIGHTFOOT = 23
# Store trackers, links, and vizshape objects
trackers = []
links = []
shapes = []
# Start vrpn
vrpn = viz.addExtension('vrpn7.dle')
trackerLocation = 'Tracker0@localhost'
# Now add all trackers and link a shape to it
for i in range(0,24):
t = vrpn.addTracker(trackerLocation, i)
s = vizshape.addSphere(radius = 0.1)
l = viz.link(t,s)
trackers.append(t)
links.append(l)
shapes.append(s)
if i == HEAD:
s.color(viz.GREEN)
elif i == TORSO:
s.color(viz.RED)
# Add an arrow pointing from the torso in the direction the body is facing
arrow = vizshape.addCylinder(1,0.05,topRadius=0)
arrow.parent(s)
arrow.setEuler([0,-90,0])
arrow.setPosition([0,0,-0.5])
arrow.color(viz.RED)
elif i in [LEFTSHOULDER,RIGHTSHOULDER,LEFTHIP,RIGHTHIP]:
s.color(viz.BLUE)
# Trackers for specified bodyparts
RF = vrpn.addTracker(trackerLocation, RIGHTFOOT)
LF = vrpn.addTracker(trackerLocation, LEFTFOOT)
RK = vrpn.addTracker(trackerLocation, RIGHTKNEE)
LK = vrpn.addTracker(trackerLocation, LEFTKNEE)
RH = vrpn.addTracker(trackerLocation, RIGHTHIP)
LH = vrpn.addTracker(trackerLocation, LEFTHIP)
RS = vrpn.addTracker(trackerLocation, RIGHTSHOULDER)
LS = vrpn.addTracker(trackerLocation, LEFTSHOULDER)
Torso = vrpn.addTracker(trackerLocation, TORSO)
''' ************************ End of KINECT CODE ************************* '''
''' ************************* Initializations *************************** '''
#tracker = viz.add('intersense.dls')
#viz.translate(viz.HEAD_POS,0,-1.8,0)
#viz.eyeheight(1.8);
viz.MainView.setPosition(0,1.8,-3)
prevStep = "DOWN"
initialStep = 0
checkYaw = 0
yaw = 0
yaws = []
aveYaw = 0
YAW_SIZE = 10
now = datetime.datetime.now()
counter = 0
#filename = 'Output files/output {}-{} {},{},{}.csv'.format(now.month,now.day,now.hour,now.minute,now.second)
''' ********************* End of Initializations ************************ '''
def setDown():
global prevStep
prevStep = "DOWN"
viz.MainView.velocity(0,0,0)
def crossProduct(a,b):
c = [a[1]*b[2] - a[2]*b[1],
a[2]*b[0] - a[0]*b[2],
a[0]*b[1] - a[1]*b[0]]
return c
def unitVector(x,y,z):
vecMag = math.sqrt(x*x+y*y+z*z)
return x/vecMag, y/vecMag, z/vecMag
def step():
global prevStep
prevStep = "UP"
x,y,z = unitVector(math.cos(math.radians(aveYaw+90)), 0, math.sin(math.radians(aveYaw+90)))
viz.MainView.velocity(x, y, z)
vizact.ontimer2(.9,0,setDown)
def checkStep():
global checkYaw, yaw, counter, yaws, aveYaw, YAW_SIZE
LFvert = (LF.getPosition())[1]
RFvert = (RF.getPosition())[1]
# ************************* Output to file **************************** #
counter += 1
#if counter % 30 == 0:
# with open(filename, 'a') as f:
# x,y,z = viz.MainView.getPosition()
# s = str(counter)+','+str(LFvert)+','+str(RFvert)+','+str(initialStep)+','+str(checkYaw)+','+str(yaw)+','+str(x)+','+str(y)+','+str(z)+'\n'
# f.write(s)
# f.closed
# ************************** End of output **************************** #
checkYaw = yaw
yaw = Torso.getEuler()[0]
if len(yaws) > YAW_SIZE:
yaws.pop(0)
yaws.append(yaw)
aveYaw = sum(yaws) / len(yaws)
print aveYaw
if prevStep == "DOWN" and (LFvert > initialStep or RFvert > initialStep):
step()
# Code for movement using torso yaw
x,y,z = unitVector(math.cos(math.radians(aveYaw+90)), 0, math.sin(math.radians(aveYaw+90)))
x = x + viz.MainView.getPosition()[0]
z = z + viz.MainView.getPosition()[2]
viz.MainView.lookat([x,1.8,z])
# Code for movement using HMD
#data = tracker.getData()
#viz.MainView.setEuler(data[3], data[4], data[5])
#viz.MainView.rotate(data[3]+90,data[4],data[5],'',viz.BODY_ORI)
def getInitial():
global initialStep
initialKnee = ((LK.getPosition())[1] + (RK.getPosition())[1])/2
initialFeet = ((LF.getPosition())[1] + (RF.getPosition())[1])/2
initialStep = (initialKnee + initialFeet) * .7
# with open(filename, 'w') as f:
# f.write('runs of checkStep,LF Height,RF Height,Step Threshold,checkYaw,yaw,Mainview Xpos,Mainview Ypos,Mainview Zpos\n')
# f.closed
vizact.ontimer2(0.33, 2, getInitial)
vizact.ontimer(1/60, checkStep)