Route per-board logic through Board.get_type() - #116
Draft
SaintSampo wants to merge 2 commits into
Draft
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Replaces the scattered board-name string checks (
"NanoXRP" in implementation._machine,"Beta" in ...) with a single detection point onBoard, so per-board logic reads as data/identity comparisons instead of duplicated_machinematches — and adding a future board is a one-line change inget_type()rather than edits across the library.Changes
board.py— the one detection pointBoard.XRP/Board.BETA/Board.NANOconstants and a cachedBoard.get_type(). This is now the only place a machine name is matched.are_motors_powered/get_battery_voltagechecks use it.Call sites converted to
Board.get_type() == Board.<X>differential_drive.py— wheel diameter/track andnominal_voltage(ternaries); the_movetuning block keeps itsifon the clean identity.encoded_motor.py— motor class (SinglePWMMotor/DualPWMMotor) as a ternary; the default speed controller keeps itsif/elsewith one PID param per line.motor.py—flip_dirternary.imu.py— the cached_is_nanoxrpinit flag; the hard-IRQ update handler still reads that cached bool, soget_type()is never called from an interrupt.encoder.py— theresolutiongear-ratioif/else.Also includes a small related fix (separate commit):
dashboard.pyreads battery voltage viaBoard.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.