Skip to content

Update maxswerve example to REV's 2026 MAXSwerve template - #100

Merged
virtuald merged 2 commits into
robotpy:mainfrom
Altainia:maxswerve-2027
Oct 15, 2026
Merged

virtuald merged 2 commits into
robotpy:mainfrom
Altainia:maxswerve-2027

Conversation

@Altainia

@Altainia Altainia commented Oct 15, 2026 •

Copy link
Copy Markdown
Contributor

Refs #99.

Updates examples/maxswerve to REV's current MAXSwerve Java template (REVrobotics/MAXSwerve-Java-Template @ b614589, "Update for 2026"), written for the 2027 API on main. The old example didn't import under 2027 (wpimath.controller is gone).

It also takes maxswerve off the ignore list in examples/run_examples.py, so CI now runs its tests like the other examples. Because the example uses commands2, tests/requirements.txt now includes robotpy-commands-v2>=2027.0.0a7,<2028. The 2027 version has to be named, or pip installs the stable 2026 release; the requirement will need updating along with the wpilib version.

What follows the template

  • configs.py (new) mirrors Configs.java:
  • The module, drive subsystem, robot container (auto trajectory, X-formation binding) and constants follow the template.
  • swerveutils.py and the slew-rate limiting are gone, as they are in the template.

Where it differs, because of 2027 API changes

  1. No encoder conversion factors (removed from REVLib 2027). The SPARKs run in native units: RPM and rotations for the drive encoder, rotations for the absolute encoder. The module converts to meters and radians itself. The template's gains are kept in its own units and scaled when configured:

    • drive P is 0.04 × (m/s per RPM);
    • drive kV is 12/5676 V/RPM;
    • turning P is 2π.

    Position wrapping is enabled over one rotation.

  2. No SwerveControllerCommand or HolonomicDriveController in WPILib 2027. swervecontrollercommand.py is a small equivalent with the same behaviour:

    • it follows a trajectory from DrivetrainSplineTrajectoryGenerator;
    • x/y PID corrections are added to the sampled field-relative velocities;
    • a profiled theta controller holds the final heading.
  3. Gyro: the ADIS16470 class is gone, so the example uses wpilib.OnboardIMU (FLAT mounting).

  4. Buttons: 2027 renumbered the Xbox buttons. The template's set-X binding (raw button 6) is now RIGHT_BUMPER.

  5. TimedRobot changes: initialization is in __init__, and test mode is now utility mode. Usage reporting is hal.report_usage("RobotDrive", "MAXSwerve").

Testing

All runs used RobotPy 2027.0.0a7 and robotpy-rev 2027.0.0a7.post1 on Linux.

  • robotpy test --builtin in examples/maxswerve gives 11 passed and 1 skipped (test_opmode, which every example skips). The new tests cover:
  • examples/run_examples.py passes for all 12 examples, and examples/check_header.py and black --check are clean.
  • In simulation, I drove each SPARK through SparkMaxSim.iterate with a simple motor model (not included in this PR):
    • One module at 2 m/s: it settles at 2.03 m/s. With the old feedforward it reached 0.47 m/s.
    • The autonomous S-curve: it ends about 3 cm from (3, 0) with a near-ideal plant. With a 50 kg robot it ends 0.24 m past the endpoint, which is momentum against the template's example gains. REV's Java template overshoots by about the same amount in stingr-sim, a MuJoCo-based simulator.

Merging this won't fix the 2026.0.4 release that #99 was reported against. The fix for that release is in the issue.

Altainia and others added 2 commits October 15, 2026 11:44
Port REVrobotics/MAXSwerve-Java-Template (b614589, "Update for 2026") to
the RobotPy 2027 API, replacing the old 2025-era port that no longer
imported.

- Drive feedforward is nominal voltage / free speed, as REVLib reads kV
  in volts per unit of velocity (the old 1 / free speed was ~12x too weak)
- Add configs.py like the template's Configs, including the Through Bore
  Encoder V2 absolute encoder preset and rev.FeedbackSensor
- Drop the slew rate limiting and swerveutils, which the template removed
- REVLib 2027 has no encoder conversion factors, so the module converts
  between native units and meters/radians and the gains are scaled
- WPILib 2027 has no SwerveControllerCommand or HolonomicDriveController,
  so add a minimal SwerveControllerCommand for the autonomous routine
- Use Systemcore's OnboardIMU instead of the ADIS16470
- Test the feedforward, unit conversions, X formation binding and
  autonomous, and run the example in run_examples.py

Refs #99

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The maxswerve example uses commands2, which the test environment didn't have.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@virtuald
virtuald merged commit 9985e4e into robotpy:main Oct 15, 2026
27 checks passed
@virtuald

Copy link
Copy Markdown
Member

Thanks!

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.

2 participants