motor, encoder, and sensor support for NanoXRP hardware#93
Merged
SaintSampo merged 8 commits intoOpen-STEM:jacob-nanoxrpfrom Mar 23, 2026
Merged
motor, encoder, and sensor support for NanoXRP hardware#93SaintSampo merged 8 commits intoOpen-STEM:jacob-nanoxrpfrom
SaintSampo merged 8 commits intoOpen-STEM:jacob-nanoxrpfrom
Conversation
Updated defaults.py, encoded_motor.py, and resetbot.py to only initialize and use the fourth motor if Pin.board.MOTOR_4_IN_1 is available. This improves compatibility with hardware configurations that do not include a fourth motor.
syncing with main
Import sys.implementation and make defaults platform-aware: instantiate motor_four conditionally, remove duplicate instantiation, and choose a NanoXRP-specific drivetrain with explicit wheel dimensions. Replace sys.implementation usage in EncodedMotor with a direct import. Extend Encoder to accept a flip_dir flag, normalize pin ordering at init, and invert returned counts when flip_dir is true to allow reversing encoder direction.
Adjust defaults and encoder behavior for NanoXRP hardware. In defaults.py the drivetrain is constructed directly for NanoXRP with left_motor, right_motor, imu and corrected wheel_diam (3.46) and wheel_track (7.8) instead of the invalid annotated call. In encoder.py the module now imports sys.implementation and selects a NanoXRP-specific gear_ratio (68) while keeping counts_per_motor_shaft_revolution at 12; other platforms retain the original gear ratio. These changes adapt drivetrain and encoder resolution to the NanoXRP platform.
add a runtime guard for the middle reflectance sensor to avoid crashes on older XRP boards where LINE_M (middle pin) isn't defined. Docstrings updated to reflect the widened pin type.
Ensure the encoder's base and next pins are determined by numeric GPIO ID instead of comparing Pin string representations. Introduce local pA/pB pins and a helper _get_pin_id that extracts the numeric GPIO from machine.Pin (with a regex fallback to id()). Update docstring types for encAPin/encBPin to allow int/str. This makes the in_base selection for the RP2 StateMachine more reliable across MicroPython ports.
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.
No description provided.