Send pyControl Output to Arduino #173
Replies: 1 comment 2 replies
-
|
Are you having trouble with the feeder not getting activated at all like you expect? Or are you saying you would like it to be activated in more situations than it currently is? Your task logic right now seems to me like the feeder activated after 1 lever press and will remain activated until the pasta is grabbed, but only if the pasta grab occurs before a lick, otherwise it will remain activated. When else would you like to activate the feeder in the task? It seems odd that the feeder can remain active even when not in the reward state. Would turning off the feeder when exiting the reward state make more sense? # right lever 1 time, no time limit -> reward
# max rewards = 30
from pyControl.utility import *
import hardware_definition as hw
# -------------------------------------------------------------------------
# States and events.
# -------------------------------------------------------------------------
states = ["init_trial", "reward"]
events = ["lever_press", "lick", "session_timer", "reward_sol_timer", "pasta_grab"]
initial_state = "init_trial"
# -------------------------------------------------------------------------
# Variables.
# -------------------------------------------------------------------------
v.session_duration = 60 * minute
v.reward_duration = 70 * ms # Reward delivery duration (ms) [left, right]
v.n_maximum_rewards = 30 # Number of rewards possible
v.n_rewards = 0 # Number of rewards obtained.
v.n_pasta = 0
v.n_right_press_required = 1 # Number of right press required for reward
v.n_right_press = 0 # Number of right presses in sequence so far
# -------------------------------------------------------------------------
# Define behaviour.
# -------------------------------------------------------------------------
# Run start and stop behaviour.
def run_start():
set_timer("session_timer", v.session_duration)
def run_end():
# Turn off all hardware outputs.
print("Stopping Experiment.")
hw.off()
initial_state = "init_trial"
# State behaviour functions.
def init_trial(event):
if event == "lever_press":
v.n_right_press += 1
print("lever pressed! Presses in sequence: {}".format(v.n_right_press))
if v.n_right_press >= v.n_right_press_required:
hw.PlexonPulse1.on() # should trigger disk rotation
v.n_right_press = 0
goto_state("reward")
def reward(event):
if event == "lick":
v.n_rewards += 1
print("Total rewards: {}".format(v.n_rewards))
print("Rewards left: {}".format((v.n_maximum_rewards - v.n_rewards)))
set_timer("reward_sol_timer", v.reward_duration)
hw.center_poke.SOL.on()
elif event == "pasta_grab":
v.n_pasta += 1
print("Total rewards: {}".format(v.n_pasta))
goto_state("init_trial")
elif event == "reward_sol_timer":
hw.center_poke.SOL.off()
if v.n_rewards >= v.n_maximum_rewards:
print("End of Session")
stop_framework()
else:
goto_state("init_trial")
elif event == "exit":
hw.PlexonPulse1.off() # stop disk rotation
# State independent behaviour.
def all_states(event):
# When 'session_timer' event occurs stop framework to end session.
if event == "session_timer":
print("End of Session")
stop_framework()Sorry, I'm not quite understanding the task, could you please provide more explanation? |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
I currently have a behavior box set up with a lever press on one side and a feeder on the other, where the lever press is connected with pyControl and the feeder is connected to an arduino which is connected to DAC_1 of the pyControl board. We would like to send an output signal from pyControl to the arduino whenever the lever press is pressed, so that the arduino can activate the feeder. I came across a similar question on the old Google Groups where they said to modify the all_states function in the task file, is that still how we resolve this situation? I've attached my current hardware definitions file and one of our task files. Thank you!
pasta_box_test1.py
pasta_hardware_finalized.py
Beta Was this translation helpful? Give feedback.
All reactions