Hi Thomas, Thanks for your reply and sorry for the naive questions. Here is my code below and attached.
I used 5 timers and 3 timers at the same time. Do you think it is ok to use three timer at the same time?
And for the data log, should I mannully log the data, or the data will be automaticcally loged? Like here, left poke (active poke), right poke (inactive poke) and reward.
Thanks a lot for your time and help.
--------------------------------------------------------------------------------------------------------------------------------------------------------
from pyControl.utility import *
from devices import *
# Variables.
v.fixed_ratio = 3
v.nosepoking_duration = 500*ms
v.reward_duration = 1.5*second
v.cue_duration = 20*second
v.remove_duration = 60*second
v.inter_trial_interval = 0*second
v.poke_count = 0
v.n_rewards = 0
v.max_rewards = 40
v.session_duration = 1*hour
board = Breakout_1_2() # Instantiate the breakout board object.
# Instantiate the poke objects.
left_poke = Poke(port=board.port_1, rising_event='left_poke' , falling_event='left_poke_out' )
right_poke = Poke(port=board.port_2, rising_event='right_poke' , falling_event='right_poke_out')
Rew = Digital_output(board.port_3.POW_A)
Vaccum = Digital_output(board.port_3.POW_B)
# States and events.
states = ['waiting_for_poke',
'count_success_poke',
'exit_poke',
'reward',
'inter_trial_interval']
events = ['left_poke',
'left_poke_out',
'success_poke_timer',
'reward_timer',
'cue_timer',
'remove_timer',
'session_timer']
initial_state = 'waiting_for_poke'
# Run start and stop behaviour.
def run_start():
# Set session timer
set_timer('session_timer', v.session_duration)
def run_end():
# Turn off all hardware outputs.
hw.off()
# State behaviour functions.
def waiting_for_poke(event):
if event == 'left_poke':
goto_state('count_success_poke')
def count_success_poke(event):
if event == 'entry':
set_timer('success_poke_timer', v.nosepoking_duration)
elif event == 'left_poke_out':
disarm_timer('success_poke_timer')
goto_state('waiting_for_poke')
elif event == 'success_poke_timer':
v.poke_count += 1
if v.poke_acount == v.fixed_ratio:
v.poke_count = 0
goto_state('reward')
else:
goto_state('exit_poke')
def exit_poke(event):
if event == 'left_poke_out':
goto_state('waiting_for_poke')
def reward(event):
if event == 'entry':
set_timer('reward_timer', v.reward_duration)
set_timer('cue_timer', v.cue_duration)
set_timer('remove_timer', v.remove_duration)
Rew.on()
left_poke.LED.on()
Vaccum.on()
elif event == 'reward_timer':
Rew.off()
elif event == 'cue_timer':
left_poke.LED.off()
elif event == 'remove_timer':
Vaccum.off()
v.n_rewards += 1
if v.n_rewards == v.max_rewards:
stop_framework()
else:
goto_state('inter_trial_interval')
def inter_trial_interval(event):
if event == 'entry':
timed_goto_state('waiting_for_poke', v.inter_trial_interval)
def all_states(event):
# When 'session_timer' event occurs stop framework to end session.
if event == 'session_timer':
stop_framework()