Replies: 2 comments
-
|
Does something like this work for you? from pyControl.utility import *
from devices import *
from pyControl.hardware import Analog_trigger
# Variables.
v.reward_duration = 100 * ms # Time reward solenoid is open for.
v.target_positions = [100, 200, 300, 400, 500]
target_reached_trigger = Analog_trigger(
threshold=v.target_positions[0],
rising_event="reached_target",
falling_event="reached_target",
)
# Instantiate hardware - would normally be in a seperate hardware definition file.
board = Breakout_1_2() # Breakout board.
running_wheel = Rotary_encoder(
name="running_wheel",
sampling_rate=100,
output="position",
triggers=[target_reached_trigger],
) # Running wheel must be plugged into port 1 of breakout board.
solenoid = Digital_output(board.port_2.POW_A) # Reward delivery solenoid.
# States and events.
states = [
"running_for_reward",
"reward",
]
events = [
"reached_target",
]
initial_state = "running_for_reward"
# State behaviour functions.
def running_for_reward(event):
if event == "reached_target":
goto_state("reward")
def reward(event):
if event == "entry":
timed_goto_state("running_for_reward", v.reward_duration)
solenoid.on()
elif event == "exit":
solenoid.off()
new_target_position = choice(v.target_positions)
print(f"New target position: {new_target_position}")
target_reached_trigger.set_threshold(new_target_position) |
Beta Was this translation helpful? Give feedback.
0 replies
-
|
Hi Andy,
Thank you, this looks exactly like what I need, I appreciate your help. Unfortunately, Analog_trigger is not available in the version we use, but I will give it a try after the next update.
Thanks,
Barna
From: Andy Lustig ***@***.***>
Date: Thursday, March 26, 2026 at 3:42 PM
To: pyControl/code ***@***.***>
Cc: bdudok ***@***.***>, Author ***@***.***>
Subject: Re: [pyControl/code] Position based trigger from rotary encoder (Discussion #172)
Does something like this work for you?
from pyControl.utility import *
from devices import *
from pyControl.hardware import Analog_trigger
# Variables.
v.reward_duration = 100 * ms # Time reward solenoid is open for.
v.target_positions = [100, 200, 300, 400, 500]
target_reached_trigger = Analog_trigger(
threshold=v.target_positions[0],
rising_event="reached_target",
falling_event="reached_target",
)
# Instantiate hardware - would normally be in a seperate hardware definition file.
board = Breakout_1_2() # Breakout board.
running_wheel = Rotary_encoder(
name="running_wheel",
sampling_rate=100,
output="position",
triggers=[target_reached_trigger],
) # Running wheel must be plugged into port 1 of breakout board.
solenoid = Digital_output(board.port_2.POW_A) # Reward delivery solenoid.
# States and events.
states = [
"running_for_reward",
"reward",
]
events = [
"reached_target",
]
initial_state = "running_for_reward"
# State behaviour functions.
def running_for_reward(event):
if event == "reached_target":
goto_state("reward")
def reward(event):
if event == "entry":
timed_goto_state("running_for_reward", v.reward_duration)
solenoid.on()
elif event == "exit":
solenoid.off()
new_target_position = choice(v.target_positions)
print(f"New target position: {new_target_position}")
target_reached_trigger.set_threshold(new_target_position)
—
Reply to this email directly, view it on GitHub<#172?email_source=notifications&email_token=AGZ7XEUEMPGLB6SEPOTVE2L4SWI3PA5CNFSNUABIM5UWIORPF5TWS5BNNB2WEL2ENFZWG5LTONUW63SDN5WW2ZLOOQXTCNRTGMZDONZTUZZGKYLTN5XKMYLVORUG64VFMV3GK3TUVRTG633UMVZF6Y3MNFRWW#discussioncomment-16332773>, or unsubscribe<https://github.com/notifications/unsubscribe-auth/AGZ7XEXP6YCT7YAE4PKL4FD4SWI3PAVCNFSM6AAAAACXA67OQ6VHI2DSMVQWIX3LMV43URDJONRXK43TNFXW4Q3PNVWWK3TUHMYTMMZTGI3TOMY>.
You are receiving this because you authored the thread.
|
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Currently the task script needs to poll the position variable using a timer, whenever we want to do something that depends on distance traveled or reaching a specific treadmill location. Instead, it would be so much better to get an interrupt at a pre-set position value.
I looked at the running wheel example task.
The task sets up a trigger based on velocity:
Would it be possible to set something similar up based on position, ie. it generates an interrupt when that position is reached? I would need to be able to edit the threshold during runtime. This is how I do this currently, which is not ideal:
I don't think Analog trigger would work for this, because that requires an analog input on a pin, as far as I undeerstand, and position is computed on the board, not by the periphery.
Beta Was this translation helpful? Give feedback.
All reactions