def __init__(self, id, finger, trial_table): ShowBase.__init__(self) IndividuationStateMachine.__init__(self) props = WindowProperties() props.setTitle('Individuation Demo') self.win.requestProperties(props) self.render.setAntialias(AntialiasAttrib.MMultisample) self.render.setShaderAuto() # allows shadows self.setFrameRateMeter(True) self.dev = MpI(Hand, clock=mono_clock.get_time) self.finger = int(finger) * 3 # offset self.f2 = int(finger) # self.disableMouse() self.countdown_timer = CountdownTimer() self.table = pd.read_table(trial_table) # trial table self.setup_lights() self.setup_camera() self.load_models() self.load_audio() # add tasks (run every frame) taskMgr.add(self.get_user_input, 'move') taskMgr.add(self.update_target_color, 'target_color') taskMgr.add(self.update_state, 'update_state') taskMgr.add(self.update_feedback_bar, 'update_feedback_bar') self.accept('space', self.space_on) # toggle a boolean somewhere # helpers self.space = False self.trial_counter = 0 self.dist = 100 self.queue = list() self.med_data = None self.noise = 0.0
def setup_input(self): keys = list(self.static_settings['key_options']) self.keys = keys[:int(self.static_settings['n_choices'])] self.device = MpI(Keyboard, keys=keys, clock=self.global_clock.getTime) self.keyboard_state = [False] * len(keys)
def setup_camera(self): self.cam.setPos(-2, -4, 2) self.cam.lookAt(0, 0, 0) def colour_change(self, task): dist = sqrt((self.cube.get_x() - self.target.get_x())**2 + (self.cube.get_y() - self.target.get_y())**2 + (self.cube.get_z() - self.target.get_z())**2) d2 = 1 - dist self.cube.setColorScale(d2, d2, d2, d2) return task.cont def move_task(self, task): dt = globalClock.get_dt() if dt > 0.018: print(dt) ts, dat = self.dev.read() if ts is not None: if self.zeroing is None: self.zeroing = np.median(dat, axis=0) dat = np.array(dat) - self.zeroing self.cube.setPos(-dat[-1, 9] * 2, dat[-1, 10] * 2, -dat[-1, 11] * 4) return task.cont if __name__ == '__main__': demo = BlamDemo(MpI(Hand)) with demo.dev: demo.run()
from force_handle import ForceHandle from toon.input import MultiprocessInput as MpI from toon.input.clock import mono_clock import numpy as np import matplotlib.pyplot as plt np.set_printoptions(precision=4, suppress=True, linewidth=150) if __name__ == '__main__': lst = list() device = MpI(ForceHandle, clock=mono_clock.get_time, sampling_frequency=250) #device = ForceHandle(clock=mono_clock.get_time) t0 = mono_clock.get_time() t1 = t0 + 45 t2 = 0 time2 = 0 with device as dev: while mono_clock.get_time() < t1: time, data = dev.read() if time is not None: print(data) dff = np.diff(time) #print(dff) lst.append(dff) while mono_clock.get_time() < t2: pass t2 = mono_clock.get_time() + (1 / 60) lst = np.concatenate(lst) #plt.plot(lst)
if logging: print(data[-1, :]) with open(log_file_name, 'ab') as f: np.savetxt(f, data, fmt='%10.5f', delimiter=',') for counter, c in enumerate(curves): c.setData(y=current_data_view[:, counter]) if __name__ == '__main__': parser = argparse.ArgumentParser() parser.add_argument('demo', help='Demo mode or not', type=bool, default=True) args = parser.parse_args() if args.demo: device = MpI(FakeInput, sampling_frequency=250, data_shape=[[6]], data_type=[ctypes.c_double]) else: device = MpI(ForceHandle, sampling_frequency=250) with device as dev: win.show() timer = pg.QtCore.QTimer() timer.timeout.connect(update) timer.start(16) if (sys.flags.interactive != 1) or not hasattr(QtCore, 'PYQT_VERSION'): QtGui.QApplication.instance().exec_()
from force_handle import ForceHandle from toon.input import MultiprocessInput as MpI from toon.input.clock import mono_clock import numpy as np np.set_printoptions(precision=4, suppress=True) if __name__ == '__main__': device = MpI(ForceHandle, clock=mono_clock.get_time) t0 = mono_clock.get_time() t1 = t0 + 10 t2 = 0 with device as dev: while mono_clock.get_time() < t1: time, data = dev.read() if time is not None: print(data) #print(np.diff(time)) while mono_clock.get_time() < t2: pass t2 = mono_clock.get_time() + (1 / 60)
c.setData(y=current_force_data_view[:, 3 * current_index + counter] - reference_vals[3 * current_index + counter]) for counter, c in enumerate(calib_curves): c.setData(y=current_calib_data_view[:, 3 * current_index + counter]) if __name__ == '__main__': parser = argparse.ArgumentParser() parser.add_argument('--demo', help='Demo mode or not', dest='demo', action='store_true') parser.set_defaults(demo=False) args = parser.parse_args() if args.demo: device = MpI( FakeInput, sampling_frequency=1000, data_shape=[[15], [20], [15]], data_type=[ctypes.c_double, ctypes.c_double, ctypes.c_double]) else: device = MpI(Hand) with device as dev: win.show() timer = pg.QtCore.QTimer() timer.timeout.connect(update) timer.start(17) if (sys.flags.interactive != 1) or not hasattr(QtCore, 'PYQT_VERSION'): QtGui.QApplication.instance().exec_()