bpod rotary encoder tutorial

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
bpod rotary encoder tutorial
#1
Hi guys 
I am a bit lost with the rotary encoder module. I am currently trying to set up thresholds for left and right movement and trigger specific states for this threshold, but so far no luck.

Can I define both +ticks and -ticks for left and right?

Does anybody have a more detailed guide or a script that I can use as a guide and if yes can you point me in the right direction?

Best regards Max
Reply
#2
Hi Max,


The RotaryEncoderModule class (documented here) has a field for thresholds. Units are exposed in degrees, which are mapped to tics behind the scenes. Setting thresholds of - and + 20 degrees with respect to the starting position is then:

Code:
R.thresholds = [-20 20];


These threshold crossings generate RotaryEncoder1_1 and RotaryEncoder1_2 events respectively.
Once thresholds have been crossed, they need to be reset before they can be crossed again.
You can set them from MATLAB with the enableThresholds() method of the RotaryEncoderModule class, or directly from the state machine by putting {'RotaryEncoder1', 'E'} in the desired state's output actions (also see the serial interface documentation, here).

Please let me know if you run into any issues.

Thanks,
-Josh
Reply
#3
Hi Thanks for the reply, I should have mentioned that I am trying to get it to work with python, which seems to be a bit more complicated.

So far I could manage to initialize the rotary encoder and set the thresholds, but I am not sure, if they are set correctly and I have no idea of knowing how to check it.
If I try to access the two set thresholds as a state change condition
Code:
state_change_conditions={

           "RotaryEncoder1_1": "next_state",
, I don't get any changes. 

This is my code:

Code:
from pybpodapi.bpod import Bpod

from pybpodapi.state_machine import StateMachine

#from rotary_encoder import MyRotaryEncoder
from pybpod_rotaryencoder_module.module_api import RotaryEncoderModule

#import inspect






bpod = Bpod()
rotary_encoder=RotaryEncoderModule('COM6')

rotary_encoder.set_zero_position()

rotary_encoder.set_thresholds([-5, 5])

rotary_encoder.enable_thresholds([True, True, False, False, False, False, False, False])

rotary_encoder.enable_evt_transmission()

rotary_encoder.enable_stream()







#print(rotary_encoder)

#print(rotary_encoder.current_position())

#print("\n \n \n")
rotary_encoder.close()

for trial in range(trials):
  sma = StateMachine(bpod)



# sart state blink green two times

   sma.add_state(

       state_name="start1",

       state_timer=1,

       state_change_conditions={"Tup": "start2"},

       output_actions=[("BNC1", 1)],

   )
...
# detect rotary encoder movement left -> blink red light

   sma.add_state(

       state_name="detect",

       state_timer=10,

       state_change_conditions={

           "RotaryEncoder1_1": "blink_green_3x",

           "RotaryEncoder1_2": "blink_red_2x",

           #"Tup": "blink_red_2x"

           },

       output_actions=[("BNC1", 1)],

   )
...
   bpod.send_state_machine(sma)
bpod.close()

Any idea where in the code my error is caused Smile
Reply
#4
Hi Max,

I don't see anything wrong with the code, but perhaps the PyBpod experts will see something I didn't.
I requested to have you added to the pyBpod slack channel, which is the current forum for PyBpod issues.
Once we have a public link, I'll add it here - but for now, the invitation should arrive by Email.

-Josh
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)