Skip to content

Library support for Cytron NanoXRP board#94

Open
SaintSampo wants to merge 15 commits intomainfrom
jacob-nanoxrp
Open

Library support for Cytron NanoXRP board#94
SaintSampo wants to merge 15 commits intomainfrom
jacob-nanoxrp

Conversation

@SaintSampo
Copy link
Copy Markdown
Collaborator

Library support for Cytron NanoXRP board including:

  • Supporting buzzer hardware
  • removed 4th motor
  • Drivetrain dimension differences and alternative PID
  • Accounting for different IMU orientation
  • Added 3rd reflectance sensor

Todo:

  • investigate adding blocks for the NanoXRP
  • create example file for Nanoxrp Buzzer, middle reflectance sensor.

SaintSampo and others added 15 commits March 14, 2025 14:39
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.
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.
motor, encoder, and sensor support for NanoXRP hardware
Detect NanoXRP via sys.implementation and apply platform-specific tweaks: import implementation in motor/imu/differential_drive, skip creating heading PID on NanoXRP, and use different PID gains for main/secondary controllers for distance/rotation on NanoXRP versus other platforms. Also flip IMU yaw sign on NanoXRP and invert motor flip_dir handling to correct orientation differences. These changes adapt control and sensor behavior to NanoXRP's hardware quirks and dynamics.
Introduce XRPLib/buzzer.py: a Buzzer class for XRP robots that plays notes and songs (blocking and non-blocking). Features note parsing (naturals, sharps, flats), tempo/duration conversion, frequency computation, PWM control on default pin 13, a Timer-based non-blocking playback path, and several built-in songs. Also update XRPLib/defaults.py to import Buzzer and expose a default buzzer instance (buzzer) when running on NanoXRP via Buzzer.get_default_buzzer().
Move gyro delta calculations into the NanoXRP branch and correctly swap pitch/roll while inverting yaw. Previously the deltas were computed before the platform check and only yaw was negated, which produced incorrect pitch/roll mapping on NanoXRP devices. The original computation is preserved for other implementations.
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