Skip to content

Commit 6a00d5f

Browse files
authored
Add variable hist len (#7)
1 parent 323a31a commit 6a00d5f

File tree

1 file changed

+4
-6
lines changed

1 file changed

+4
-6
lines changed

src/pyomyo/Classifier.py

+4-6
Original file line numberDiff line numberDiff line change
@@ -85,14 +85,12 @@ def classify(self, d):
8585
class MyoClassifier(Myo):
8686
'''Adds higher-level pose classification and handling onto Myo.'''
8787

88-
HIST_LEN = 25
89-
90-
def __init__(self, cls, tty=None, mode=emg_mode.PREPROCESSED):
88+
def __init__(self, cls, tty=None, mode=emg_mode.PREPROCESSED, hist_len=25):
9189
Myo.__init__(self, tty, mode=mode)
9290
# Add a classifier
9391
self.cls = cls
94-
95-
self.history = deque([0] * MyoClassifier.HIST_LEN, MyoClassifier.HIST_LEN)
92+
self.hist_len = hist_len
93+
self.history = deque([0] * self.hist_len, self.hist_len)
9694
self.history_cnt = Counter(self.history)
9795
self.add_emg_handler(self.emg_handler)
9896
self.last_pose = None
@@ -106,7 +104,7 @@ def emg_handler(self, emg, moving):
106104
self.history.append(y)
107105

108106
r, n = self.history_cnt.most_common(1)[0]
109-
if self.last_pose is None or (n > self.history_cnt[self.last_pose] + 5 and n > MyoClassifier.HIST_LEN / 2):
107+
if self.last_pose is None or (n > self.history_cnt[self.last_pose] + 5 and n > self.hist_len / 2):
110108
self.on_raw_pose(r)
111109
self.last_pose = r
112110

0 commit comments

Comments
 (0)