Hi,
Thanks for all your help building this awesome tool!
I'm currently having issues using pybpod to trigger state changes using a counter threshold.
MRE below:
def get_state_machine_trial(self, i):
sma = StateMachine(self.bpod)
sma.set_global_timer(1, 10)
sma.set_global_counter(counter_number=1, target_event="Port1In", threshold=5)
sma.add_state(
state_name="trial_start",
state_timer=0,
state_change_conditions={"Tup": "wait_for_lick"},
output_actions=[
("GlobalTimerTrig", 1),
],
)
sma.add_state(
state_name="wait_for_lick",
state_change_conditions={
"GlobalCounter1_End": "reset_counter",
"GlobalTimer1_End": "exit",
},
)
sma.add_state(
state_name="reset_counter",
state_timer=0.1,
state_change_conditions={
"Tup": "wait_for_lick",
},
output_actions=[(Bpod.OutputChannels.GlobalCounterReset, 1)],
)
return sma
If i understand correctly, 5 'Port1In' events should trigger the state change from 'wait_for_lick' to 'reset_counter'. However this doesn't occur according to the output logs even though the event is detected.
Output log:
{"trial_start_time": 1.40301, "trial_end_time": 11.403013, "pc_timestamp": "2024-09-23T12:09:09.363124", "states_info": [{"name": "trial_start", "start_time": 0, "end_time": 0.0001}, {"name": "wait_for_lick", "start_time": 0.0001, "end_time": 10.0}, {"name": "reset_counter", "start_time": NaN, "end_time": NaN}], "events_info": [{"name": "GlobalTimer1_Start", "start_time": 0.0001}, {"name": "Tup", "start_time": 0.0001}, {"name": "Port1In", "start_time": 5.4670000000000005}, {"name": "Port1Out", "start_time": 5.61}, {"name": "Port1In", "start_time": 5.875900000000001}, {"name": "Port1Out", "start_time": 5.9451}, {"name": "Port1In", "start_time": 6.0216}, {"name": "Port1Out", "start_time": 6.1458}, {"name": "Port1In", "start_time": 6.2799000000000005}, {"name": "Port1Out", "start_time": 6.417400000000001}, {"name": "Port1In", "start_time": 6.5296}, {"name": "GlobalCounter1_End", "start_time": 6.5297}, {"name": "Tup", "start_time": 6.629700000000001}, {"name": "Port1Out", "start_time": 6.6591000000000005}, {"name": "Port1In", "start_time": 6.8124}, {"name": "Port1Out", "start_time": 6.9556000000000004}, {"name": "Port1In", "start_time": 7.0681}, {"name": "Port1Out", "start_time": 7.168200000000001}, {"name": "Port1In", "start_time": 7.3243}, {"name": "Port1Out", "start_time": 7.506200000000001}, {"name": "Port1In", "start_time": 7.5831}, {"name": "Port1Out", "start_time": 7.722700000000001}, {"name": "Port1In", "start_time": 7.8276}, {"name": "GlobalCounter1_End", "start_time": 7.8277}, {"name": "Tup", "start_time": 7.927700000000001}, {"name": "Port1Out", "start_time": 7.9766}, {"name": "Port1In", "start_time": 8.0708}, {"name": "Port1Out", "start_time": 8.2034}, {"name": "Port1In", "start_time": 8.337900000000001}, {"name": "Port1Out", "start_time": 8.4749}, {"name": "Port1In", "start_time": 8.5695}, {"name": "Port1Out", "start_time": 8.721}, {"name": "Port1In", "start_time": 8.8446}, {"name": "Port1Out", "start_time": 8.981200000000001}, {"name": "Port1In", "start_time": 9.1148}, {"name": "GlobalCounter1_End", "start_time": 9.1149}, {"name": "Tup", "start_time": 9.2149}, {"name": "Port1Out", "start_time": 9.2761}, {"name": "Port1In", "start_time": 9.3214}, {"name": "Port1Out", "start_time": 9.5032}, {"name": "Port1In", "start_time": 9.6125}, {"name": "Port1Out", "start_time": 9.7294}, {"name": "Port1In", "start_time": 9.8177}, {"name": "Port1Out", "start_time": 9.9794}, {"name": "GlobalTimer1_End", "start_time": 10.0}], "rotary_encoder_position": [], "texture": "", "texture_rewarded": false}
Interestingly, when I hook up a state following the counter trigger (such as 'reset_counter' in this case) to something external like opening a solenoid, I can hear the solenoid opening, but the logs look the same as the above (with the solenoid opening state start time as NaN). This implies a weird behavior where the state is reached but its start time is not logged and remains as NaN.
Any help you're able to provide would be much appreciated!