Skip to content

Route per-board logic through Board.get_type() - #116

Draft
SaintSampo wants to merge 2 commits into
mainfrom
boardRefactor
Draft

Route per-board logic through Board.get_type()#116
SaintSampo wants to merge 2 commits into
mainfrom
boardRefactor

Conversation

@SaintSampo

@SaintSampo SaintSampo commented Aug 6, 2026

Copy link
Copy Markdown
Member

Summary

Replaces the scattered board-name string checks ("NanoXRP" in implementation._machine, "Beta" in ...) with a single detection point on Board, so per-board logic reads as data/identity comparisons instead of duplicated _machine matches — and adding a future board is a one-line change in get_type() rather than edits across the library.

Changes

board.py — the one detection point

  • Adds Board.XRP / Board.BETA / Board.NANO constants and a cached Board.get_type(). This is now the only place a machine name is matched.
  • Its own are_motors_powered / get_battery_voltage checks use it.

Call sites converted to Board.get_type() == Board.<X>

  • differential_drive.py — wheel diameter/track and nominal_voltage (ternaries); the _move tuning block keeps its if on the clean identity.
  • encoded_motor.py — motor class (SinglePWMMotor/DualPWMMotor) as a ternary; the default speed controller keeps its if/else with one PID param per line.
  • motor.pyflip_dir ternary.
  • imu.py — the cached _is_nanoxrp init flag; the hard-IRQ update handler still reads that cached bool, so get_type() is never called from an interrupt.
  • encoder.py — the resolution gear-ratio if/else.

Also includes a small related fix (separate commit): dashboard.py reads battery voltage via Board.get_battery_voltage() instead of a raw ADC, so it uses the per-board formula and, on the Nano, restores the shared VIN/RM2 pin after reading.

Import Board and obtain the default board in Dashboard. Replace direct ADC creation on 'BOARD_VIN_MEASURE' and manual scaling with board.get_battery_voltage() to report battery voltage. Centralizes voltage measurement through the Board abstraction.
Add Board.get_type() with Board.XRP/BETA/NANO constants as the single
board-detection point, and replace the scattered
'NanoXRP'/'Beta' in implementation._machine string checks across board,
differential_drive, encoded_motor, motor, imu, and encoder with
comparisons against those constants.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant