-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathoutput_waveplayer.py
106 lines (73 loc) · 2.44 KB
/
output_waveplayer.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
from pybpodapi.bpod import Bpod
from pybpodapi.state_machine import StateMachine
import time
import numpy as np
from pybpodgui_plugin_waveplayer.module_api import WavePlayerModule
from pybpodapi.com.arcom import ArCOM, ArduinoTypes
# load wave
waveplayer = WavePlayerModule("COM4")
# configure wave
sampleRate = 1000 # of samples per second 1kHz
wave = np.ones(100000) * 5
waveplayer.set_sampling_period(sampleRate)
waveplayer.set_output_range(0)
waveplayer.set_loop_mode([False, False, False, False, False, False, False, False])
#waveplayer.set_loop_mode([False, False, False, False])
waveplayer.debug()
print(waveplayer.load_waveform(1, wave))
waveplayer.disconnect()
# create bpod object all necessary settings are imported from GUI
bpod = Bpod('COM5')
bpod.modules[0].name
bpod.modules[1].name
wave_player = [x for x in bpod.modules if x.name == "WavePlayer1"][0]
bpod.load_serial_message(wave_player, 1, [ord('P'), 3, 0]) #15=1111
#wave_player.load_message([ord('P'), 15, 1],1)
"""
for _ in range(10):
print(f"loop:{_}")
waveplayer.play(1,1)
waveplayer.play(2,1)
waveplayer.play(3,1)
waveplayer.play(4,1)
time.sleep(5)
waveplayer.stop()
waveplayer.disconnect()"""
#from pybpodapi.com.arcom import ArCOM, ArduinoTypes
#arcom = ArCOM().open("COM6", 115200)
#arcom.write_array(ArduinoTypes.get_uint8_array([ord("P"), 1, 0]))
#arcom.close()
# trial loop
trials = 10
#LoadSerialMessages('WavePlayer1', ['P', 15, 1])
# main loop for 10 trials
for trial in range(trials):
# create state machine object
sma = StateMachine(bpod)
# initial state, all states follow the same notation
sma.add_state(
state_name="start_state",
state_timer=2,
state_change_conditions={"Tup": "next_state"},
output_actions=[('Serial4', 1)],
)
# blink state
sma.add_state(
state_name="next_state",
state_timer=2,
state_change_conditions={"Tup": "end_state"},
output_actions=[("BNC1", 1), ("BNC2", 1)],
)
# start testing for recifing signals
sma.add_state(
state_name="end_state",
state_timer=2,
state_change_conditions={"Tup": "exit"},
output_actions=[('Serial4', 1)],
)
bpod.send_state_machine(sma)
if not bpod.run_state_machine(sma): # Locks until state machine 'exit' is reached
break
# print some infos about the trial
print("Current trial info: {0}".format(bpod.session.current_trial))
bpod.close()