Organizing configs in constants
As your robot grows, managing configuration across multiple subsystems can become unwieldy. YAMS supports a clean pattern where you define all your configs in a centralized Constants file, then bind them to subsystems at construction time using .withSubsystem().
The problem
Without organization, each subsystem file contains its own configuration inline:
// 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, new CANBus(CANPort.CAN_S0)), DCMotor.getKrakenX60(1), smcConfig);
ArmConfig armConfig = new ArmConfig()
.withLength(Inches.of(18))
// ... more config
this.arm = new Arm(armConfig, smc);
}
}This approach has drawbacks:
Configs are scattered across many files
Hard to compare settings between mechanisms
Tuning requires opening multiple files
CAN IDs, motor types, and gear ratios are buried in subsystem code
The solution: Centralized constants with withSubsystem()
YAMS configs can be created without a subsystem reference, then bound later using .withSubsystem(). This enables a clean separation:
Then in your subsystems, use .withSubsystem() to bind the config:
Benefits of this pattern
Single Source of Truth
All CAN IDs, gear ratios, PID gains in one file
Easy Comparison
See all mechanism configs side-by-side
Faster Tuning
Change gains without navigating subsystem files
Cleaner Subsystems
Subsystem classes focus on behavior, not configuration
Reusable Configs
Share base configs between similar mechanisms
Complete example: Constants file
Complete example: Subsystem using constants
After live tuning: copy the values into Constants
Live tuning changes gains while the robot runs, but the values are lost when the code restarts. With this pattern the gains live in Constants, so that is where you copy them:
If the config also has withSimClosedLoopController(...) or withSimFeedforward(...), values found in simulation belong in those lines, because the simulation uses them.
Organizing multiple config files
For larger robots, you may want to split configs into separate files:
When not to use this pattern
This pattern adds a layer of indirection. For simple robots with 1-2 mechanisms, inline configuration may be clearer. Consider using centralized configs when:
You have 3+ mechanisms
Multiple team members tune different subsystems
You want to quickly compare settings across mechanisms
You're building a constants dashboard or config loader
Last updated
Was this helpful?
