treadmill#

Teensy treadmill encoder over USB-serial.

Firmware Data Format:
  • With SHOW_MICROS defined: "micros,distance(mm),speed(mm/s)"

  • Without SHOW_MICROS: "distance(mm),speed(mm/s)"

Supported Commands:
Command | Description |

|---------|———————————————-| | ‘?’ | Print version and header info | | ‘c’ | Initiate speed output calibration |

Built on mesofield.devices.base.BaseSerialDevice. Each parsed line is recorded as a dict {"distance": float, "speed": float, "device_us": int|None} so that the default BaseDataProducer.save_data() writes a 4-column CSV (timestamp,distance,speed,device_us).

The producer (EncoderSerialInterface) writes the CSV; the matching ingest-side parser (TreadmillSource) lives at the bottom of this module so producer and parser sit in the same file. EncoderSerialInterface.Parser resolves to TreadmillSource for manifest-driven dispatch.

class mesofield.devices.treadmill.EncoderSerialInterface[source]#

Bases: BaseSerialDevice

Teensy encoder/treadmill device.

Constructor accepts either a cfg dict (BaseSerialDevice-style) or legacy positional/keyword args (port, baudrate) for backward compatibility with mesofield.hardware.

__init__(cfg=None, port=None, baudrate=None, **kwargs)[source]#
Parameters:
Return type:

None

parse_line(line)[source]#

Decode one raw serial line into (payload, ts) or None.

Parameters:

line (bytes)

Return type:

Tuple[Dict[str, Any], float | None] | None

send_command(command)[source]#

Send a single-character firmware command (no newline).

Parameters:

command (str)

Return type:

bytes

Parser#

alias of TreadmillSource

class mesofield.devices.treadmill.TreadmillSource[source]#

Bases: TimeseriesSource

Load treadmill samples aligned to the experiment window.

build_timeseries(path, *, context=None)[source]#

Return (timeline, value, meta).

Parameters:
  • path (Path)

  • context (SourceContext | None)

Return type:

tuple[np.ndarray, pd.DataFrame, dict]