Organizing Configs in Constants
The Problem
// ArmSubsystem.java - config mixed with subsystem logic
public class ArmSubsystem extends SubsystemBase {
private final Arm arm;
public ArmSubsystem() {
SmartMotorControllerConfig smcConfig = new SmartMotorControllerConfig(this)
.withGearing(new MechanismGearing(GearBox.fromReductionStages(5, 4, 3)))
.withClosedLoopController(5, 0, 0.1)
.withFeedforward(new ArmFeedforward(0.1, 0.3, 0.5, 0.01))
.withTrapezoidalProfile(RotationsPerSecond.of(1.0), RotationsPerSecondPerSecond.of(2.0));
SmartMotorController smc = new TalonFXWrapper(new TalonFX(1), DCMotor.getKrakenX60(1), smcConfig);
ArmConfig armConfig = new ArmConfig(smc)
.withLength(Inches.of(18))
.withMass(Pounds.of(5))
// ... more config
this.arm = new Arm(armConfig);
}
}The Solution: Centralized Constants with withSubsystem()
withSubsystem()Benefits of This Pattern
Benefit
Description
Complete Example: Constants File
Complete Example: Subsystem Using Constants
Organizing Multiple Config Files
When NOT to Use This Pattern
Last updated