Skip to content

Add ModuleIOSimTalonFX and refactor TalonFX module IO layer#18

Open
nlaverdure wants to merge 11 commits into
main-2027-alpha2from
feat/module-io-sim-talon-fx
Open

Add ModuleIOSimTalonFX and refactor TalonFX module IO layer#18
nlaverdure wants to merge 11 commits into
main-2027-alpha2from
feat/module-io-sim-talon-fx

Conversation

@nlaverdure

Copy link
Copy Markdown
Member

Summary

  • Add ModuleIOSimTalonFX: Phoenix 6 hardware-in-the-loop simulation using TalonFXSimState / CANcoderSimState driven by DCMotorSim physics. Uses the same hardware configuration and control requests as ModuleIOTalonFX, so sim behavior closely tracks hardware.
  • Extract ModuleIOTalonFXBase: Abstract base class shared by ModuleIOTalonFX (hardware) and ModuleIOSimTalonFX (sim), holding all device fields, control requests, status signals, and set* methods. Each subclass only contains what is unique to it (high-frequency odometry queues for hardware; sim state + physics update for sim).
  • Centralize DriveConstants: Moved all TalonFXConfiguration and CANcoderConfiguration setup into CONSTANT_CREATOR's withDriveMotorInitialConfigs / withSteerMotorInitialConfigs inline builders. Removed intermediate factory methods (buildDriveConfig, buildTurnConfig, configureCANcoder) and single-use private constants. Remaining named constants are those with meaningful rationale or used in multiple places (STEER_GAINS, DRIVE_GAINS, SLIP_CURRENT, STEER_STATOR_CURRENT_LIMIT).
  • Update ModuleIOSimWPI: Uses centralized DriveConstants.createDriveSim() / createTurnSim() and Robot.defaultPeriodSecs in place of local LinearSystemId calls and the 0.02 literal.

Test plan

  • Hardware: deploy and verify all four modules initialize, drive velocity closed-loop and turn position closed-loop respond correctly
  • Sim (ModuleIOSimTalonFX): launch in simulation, confirm modules steer and drive under joystick input, odometry updates at 50 Hz
  • Sim (ModuleIOSimWPI): confirm no regression in existing WPI sim path

🤖 Generated with Claude Code

nlaverdure and others added 11 commits June 16, 2026 20:15
* added Ratio enum

* formatting

* add gear ratios

* use varags, reduce field visibility

* remove DRIVE_MOTOR_REDUCTION field

* remove unnecessary vendordeps

* refine DriveGearRatio couple ratio to support multiple chassis-frame stages

Add chassisStages parameter to explicitly separate chassis-frame gear
reduction stages (whose product is the couple ratio) from azimuth-frame
stages. Add Javadoc to constructor, getDriveMotorReduction, and getCoupleRatio.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

---------

Co-authored-by: BenGamer3 <benbenw2020@gmail.com>
Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
* Updating the trigger encoders for glass

* Fixing the trigger encoders and made a build of the robot code
- Add ModuleIOSimTalonFX: Phoenix 6 hardware-in-the-loop sim using
  TalonFXSimState + CANcoderSimState driven by DCMotorSim physics
- Expose DRIVE_INITIAL_CONFIGS and TURN_INITIAL_CONFIGS as public in
  DriveConstants so both TalonFX IO implementations share the same source
- Add createDriveSim() / createTurnSim() factory methods to DriveConstants,
  eliminating duplicated DCMotorSim construction in ModuleIOSimWPI and
  ModuleIOSimTalonFX
- Replace hardcoded 0.02s with Robot.defaultPeriodSecs in both sim classes

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Add buildDriveConfig(), buildTurnConfig(), and configureCANcoder() to
DriveConstants, eliminating ~40 lines of duplicated config mutation from
both ModuleIOTalonFX and ModuleIOSimTalonFX constructors.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…IO classes

Move shared hardware fields, all 6 control requests, all 9 status signals,
device construction, config application, signal initialization, all 5 set*
methods, and signal-reading helper into abstract base class. ModuleIOTalonFX
and ModuleIOSimTalonFX now only contain what is unique to each: odometry
queues/debouncers and physics sim state respectively.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Move all non-per-module field mutations (NeutralMode, gains, gear
ratios, MotionMagic, FeedbackSensorSource, ContinuousWrap, inversion)
from factory methods into DRIVE_INITIAL_CONFIGS and TURN_INITIAL_CONFIGS.
Move the remaining per-module mutations (DriveMotorInverted,
FeedbackRemoteSensorID, EncoderInverted) directly into the
ModuleIOTalonFXBase constructor. Removes buildDriveConfig(),
buildTurnConfig(), and configureCANcoder() from DriveConstants entirely.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Remove private static final intermediates that were only referenced
once: closed-loop output types, motor/feedback types, stator current
limit, friction voltages, and both initial TalonFXConfiguration
objects. All config now lives directly in CONSTANT_CREATOR, keeping
only named constants that have a meaningful rationale or are used in
more than one place (STEER_GAINS, DRIVE_GAINS, SLIP_CURRENT,
STEER_STATOR_CURRENT_LIMIT).

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Replace two remaining DRIVE_MOTOR_REDUCTION usages (createDriveSim
and withSensorToMechanismRatio) with SELECTED_RATIO.getDriveMotorReduction()
following the DriveGearRatio enum introduced in main.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Add configureModule() to bake DriveMotorInverted into
DriveMotorInitialConfigs.MotorOutput.Inverted and EncoderId into
SteerMotorInitialConfigs.Feedback.FeedbackRemoteSensorID immediately
after createModuleConstants(). ModuleIOTalonFXBase can now apply
constants.DriveMotorInitialConfigs and constants.SteerMotorInitialConfigs
directly without mutation, keeping all configuration logic in DriveConstants.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
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