bpod_modules_ibl.RotaryEncoderModule
- class bpod_modules_ibl.RotaryEncoderModule
Bases:
object- __init__(port, encoder_resolution=1024, reset_to_defaults=True)
Create a RotaryEncoderModule instance and open the connection.
- Parameters:
port (
str) – Serial port name (e.g.,'/dev/ttyACM0'or'COM5').encoder_resolution (
int, optional) – The incremental encoder’s resolution in pulses per revolution. Defaults to 1024.reset_to_defaults (
bool, optional) – Whether to reset the Rotary Encoder Module to default settings. Defaults to True.
- Raises:
SerialException – If the port cannot be opened during the probe step.
ValueError – If the device on the given port does not appear to be a Rotary Encoder Module.
- enable_thresholds(value)
Enable or disable thresholds based on the provided value.
- Parameters:
value (
bool,strorSequenceofint) –If bool: enables all 8 thresholds if True, or disables them if False.
If str: must be a binary string of exactly 8 characters (e.g., ‘11010100’). Each character represents whether the corresponding threshold (bit 0 to 7) should be enabled (1) or disabled (0).
If Sequence[int]: a sequence of integers (ranging from 0 to 7) specifying which thresholds to enable. All other thresholds will be disabled.
- Raises:
ValueError – If value is not a bool, a valid binary string, or a valid sequence of integers.
- get_degrees() float
Get the current encoder position in degrees.
- Returns:
The current encoder position in degrees.
- Return type:
- get_logged_data() ndarray[tuple[int, ...], dtype[void]]
Retrieve logged data from the SD card.
- Returns:
Structured NumPy array with one element per logged sample. Each element has the following fields:
timenumpy.timedelta64with unitusdegreesnumpy.float64
- Return type:
- get_tics() int
Get the current encoder position in tics.
- Returns:
The current encoder position in tics.
- Return type:
- static probe(port, raise_value_error=True)
Probe for a Rotary Encoder Module on the specified port.
- Parameters:
- Returns:
The hardware version of the Rotary Encoder Module. Will return None if the device does not appear to be a Rotary Encoder Module and raise_value_error is False.
- Return type:
- Raises:
SerialException – If the port cannot be opened.
ValueError – If the device does not appear to be a Rotary Encoder Module and raise_value_error is True.
- reset()
Reset Rotary Encoder Module to default settings.
- set_degrees(degrees)
Set the current encoder position in degrees.
- Parameters:
degrees (
float) – The new encoder position in degrees.- Raises:
RuntimeError – When setting of the encoder position fails.
ValueError – When the new encoder position is outside the allowed range.
- set_resolution(value) None
Set the encoder resolution in tics per revolution.
- Parameters:
value (
int) – The new encoder resolution in tics per revolution. Must be a positive integer.- Raises:
ValueError – If the encoder resolution is not a positive integer.
- Return type:
- set_sd_logging(enable_logging) None
Enable or disable SD card logging.
- Parameters:
enable_logging (
bool) – Whether to enable SD card logging. True enables logging, False disables it.- Raises:
RuntimeError – If the hardware does not support SD card logging.
- Return type:
- set_stream_prefix(prefix=b'M') None
Set the stream prefix.
- Parameters:
prefix (
strorbytes, optional) – A single character or byte to be used as the stream prefix.- Raises:
ValueError – If the prefix is not a single character or byte.
RuntimeError – If the hardware version is not 1 or if setting the prefix fails.
- Return type:
- set_thresholds(degrees) None
Set the thresholds in degrees.
- Parameters:
degrees (
Sequenceoffloat) – Thresholds in degrees. The sequence must not contain more than 8 values.- Raises:
ValueError – If any threshold exceeds the current wrap point or the number of thresholds exceeds 8.
RuntimeError – If setting of the thresholds fails.
- Return type:
- set_tics(tics)
Set the current encoder position in tics.
- Parameters:
tics (
int) – The new encoder position in tics. Value must be an integer between -32768 and 32767.- Raises:
RuntimeError – When setting of the encoder position fails.
ValueError – When the new encoder position is outside the allowed range.