-
Notifications
You must be signed in to change notification settings - Fork 0
/
BFback_stridetime_rev2.py
175 lines (130 loc) · 5.39 KB
/
BFback_stridetime_rev2.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
import viz
import vizshape
viz.go(
#viz.FULLSCREEN
)
#viz.MainView.setPosition(0, 0, -1)
#viz.MainView.setEuler(0,0,0)
#set target tolerance for step time
global targetL
targetL = 1
global targetR
targetR = 1
global targettol
targettol = 0.05
global boxL
boxL = viz.addChild('target.obj',color=(0.063,0.102,0.898),scale=[0.2,targettol,0.0125])
boxL.setPosition([-0.3,targetL-targettol,0])
#boxL.alpha(0.6)
global boxR
boxR = viz.addChild('target.obj',color=(0.063,0.102,0.898),scale=[0.2,targettol,0.0125])
boxR.setPosition([0.3,targetR-targettol,0])
#boxR.alpha(0.6)
viz.MainView.setPosition(0,0.85,-2.5)
viz.MainView.setEuler(0,0,0)
# //////////////////////////////////////////////////
# START OF CODE DEMONSTRATING USE OF MMSERVER MODULE
# //////////////////////////////////////////////////
# Import the MotionMonitor Server module.
import mmserver
# This is the IP port to use for connecting to clients. This value must match the one specified in MotionMonitor. It should not be 50007, since that port is needed by Vizard to connect to the VRPN.
IP_PORT = int('50008')
# Enable physics if you want the server's objects to move smoothly (but this means that other objects will respond to gravity by default).
#viz.phys.enable()
# Add a purple ball to our world, whose position will later be updated by the data we receive.
global cursorR
cursorR = viz.add('box2.obj', color=viz.GRAY, scale=[0.1,0.05,0.0125], cache=viz.CACHE_NONE)
cursorR.setPosition([0.3,0,0])
global cursorL
cursorL = viz.add('box2.obj', color=viz.GRAY, scale=[0.1,0.05,0.0125], cache=viz.CACHE_NONE)
cursorL.setPosition([-0.3,0,0])
global HistBallR
HistBallR = viz.add('box.wrl', color=viz.YELLOW, scale=[0.2,0.05,0.0125], cache=viz.CACHE_NONE)
HistBallR.setPosition([0.3,targetR,0])
HistBallR.alpha(0.8)
global histR
histR = 1
global histL
histL = 1
global HistBallL
HistBallL = viz.add('box.wrl', color=viz.YELLOW, scale=[0.2,0.05,0.0125], cache=viz.CACHE_NONE)
HistBallL.setPosition([-0.3,targetL,0])
HistBallL.alpha(0.8)
# Register callback for our "connected" event.
def onConnected():
print 'MotionMonitor server connected.'
viz.callback(mmserver.CONNECTED_EVENT, onConnected)
# Register callback for our "disconnected" event.
def onDisconnected():
print 'MotionMonitor server disconnected.'
# mmserver.waitForConnection(IP_PORT) # NOTE: if we want the server to be available for another connection after being disconnected, enable this line
viz.callback(mmserver.DISCONNECTED_EVENT, onDisconnected)
# Register callback for our "calibration file generated" event.
#def onCalibrationFileGenerated(calibrationFileName):
# print 'Calibration file generated.'
# import pickle
# with open(calibrationFileName, 'rb') as file:
# data = pickle.load(file) # load the data from the calibration file
# animator.setCalibrationData(data) # send the calibration data to the animator module... this should make the avatar's segments snap into their correct positions
#viz.callback(mmserver.CALIBRATION_FILE_GENERATED_EVENT, onCalibrationFileGenerated)
# Register callback for our "scalar value received" event.
def onScalarValueReceived(scalarName, scalarValue, invalid):
return # currently, do nothing
viz.callback(mmserver.SCALAR_VALUE_RECEIVED_EVENT, onScalarValueReceived)
# Register callback for our "vector value received" event.
def onVectorValueReceived(vectorName, vectorValue, invalid):
global cursorR
global cursorL
global HistBallR
global histR
global HistBallL
global histL
global boxL
global boxR
global targettol
global target
global steptimeL
global steptimeR
#global data
#print(data)
#print(vectorName)
if (vectorName == 'BallPositionR') and not invalid: # look for the BallPosition variable in the data stream#
mmserver.sendVectorValue('ReturnedBallPositionR', vectorValue) # echo back the value of BallPosition to #MotionMonitor
#print(vectorValue[2])
#if (vectorValue[2] == histR):
# viz.visible(0)
#else:
# viz.visible(1)
cursorR.setScale(0.1,vectorValue[2],0.01250)#move ball according to step time in Z direction
if (vectorValue[2] <= 0.1):
HistBallR.setPosition([0, histR, 0])#update yellow history ball when HS happens
steptimeR = histR
else:
histR = vectorValue[2]
if (abs(steptimeR-targetR) <= targettol-0.041):#highlight the target when the target is hit
boxR.color( viz.WHITE )
else:
boxR.color( viz.BLUE )
if (vectorName == 'BallPositionL') and not invalid:
mmserver.sendVectorValue('ReturnedBallPositionL', vectorValue)
cursorL.setPosition(- vectorValue[1], vectorValue[2], vectorValue[0])
if (vectorValue[2] <= 0.1):
HistBallL.setPosition([-0.3, histL, 0])
steptimeL = histL
else:
histL = vectorValue[2]
if (abs(steptimeL-targetL) <= targettol-0.041):
boxL.color( viz.WHITE )
else:
boxL.color( viz.BLUE )
viz.callback(mmserver.VECTOR_VALUE_RECEIVED_EVENT, onVectorValueReceived)
# Register callback for our "quat value received" event.
def onQuatValueReceived(quatName, quatValue, invalid):
return # currently, do nothing
viz.callback(mmserver.QUAT_VALUE_RECEIVED_EVENT, onQuatValueReceived)
# Now that everything is set up, tell the server to wait for a connection from MotionMonitor. This call is non-blocking and will return immediately.
mmserver.waitForConnection(IP_PORT)
# ////////////////////////////////////////////////
# END OF CODE DEMONSTRATING USE OF MMSERVER MODULE
# ////////////////////////////////////////////////