-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathExercise.py
62 lines (51 loc) · 2 KB
/
Exercise.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
import numpy as np
from Utils.HelperMethods import displayText
class Exercise:
def __init__(self, statesList, tts, name = None):
self.tts = tts;
self.stateFlow = statesList
self.currentState = None
self.nextState = statesList[0]
self.name = name
self.reps = -1
self.isExerciseReset = False
def setHuman(self,human):
pass
def calculateNextState(self):
return self.stateFlow[(self.currentState.order + 1) % len(self.stateFlow)]
def transitionToNextState(self):
self.currentState = self.nextState
self.nextState = self.calculateNextState()
def checkAndUpdateState(self):
if self.nextState.isStateReached():
self.transitionToNextState()
print ("State order: ",str(self.currentState.order))
if self.currentState.order == 0:
if self.isExerciseReset:
self.isExerciseReset = False
else:
self.reps += 1
print("speaking rep message")
self.tts.BotSpeak(100, self.reps)
print ("rep done. reps: ",str(self.reps))
def reset(self):
print ("Reseting rep")
self.tts.BotSpeak(8, "Wrong rep. Do again")
self.nextState = self.stateFlow[0]
self.isExerciseReset = True
self.resetViolations()
def continueExercise(self, data):
if self.currentState is None:
self.checkAndUpdateState()
elif data is not np.nan:
self.currentState.updatePosition(data)
if self.currentState.areConstraintsMet():
self.checkAndUpdateState()
else:
self.currentState.constraintViolations += 1
def displayText(self, frame):
if self.currentState is not None:
displayText("Reps: "+ str(self.reps),50,40,frame)
displayText(self.currentState.name,50,60,frame)
def resetViolations():
pass