last_pressed = time() if __name__ == '__main__': wiimote = Wiimote(button_callback=button_pressed) wiimote.pair() gait_analyzer = GaitAnalyzer(step_frequency_observer=step_frequency_changed, skip_observer=skipped) count = 0 SMOOTHING_WINDOW = 2 # array of SMOOTHING_WINDOW*2 + 1 values. values = [] while True: if IS_SMOOTHING: values.append(wiimote.read_accelerometer()) # print values if len(values) == SMOOTHING_WINDOW * 2 + 1: # smooth the values and extract x, y, z x = sum([x for x,y,z in values]) / len(values) y = sum([y for x,y,z in values]) / len(values) z = sum([z for x,y,z in values]) / len(values) # add the smoothed value gait_analyzer.add_point(x,y,z) # remove the first value del values[0] else: x,y,z = wiimote.read_accelerometer() gait_analyzer.add_point(x,y,z) count += 1
last_pressed = time() if __name__ == '__main__': wiimote = Wiimote(button_callback=button_pressed) wiimote.pair() gait_analyzer = GaitAnalyzer( step_frequency_observer=step_frequency_changed, skip_observer=skipped) count = 0 SMOOTHING_WINDOW = 2 # array of SMOOTHING_WINDOW*2 + 1 values. values = [] while True: if IS_SMOOTHING: values.append(wiimote.read_accelerometer()) # print values if len(values) == SMOOTHING_WINDOW * 2 + 1: # smooth the values and extract x, y, z x = sum([x for x, y, z in values]) / len(values) y = sum([y for x, y, z in values]) / len(values) z = sum([z for x, y, z in values]) / len(values) # add the smoothed value gait_analyzer.add_point(x, y, z) # remove the first value del values[0] else: x, y, z = wiimote.read_accelerometer() gait_analyzer.add_point(x, y, z) count += 1