Swerve Next Steps

Now that you have a working swerve drive, you may want to explore some of the following topics.

Setting Current Limits

Current limits are an important part of battery management. The following represents a short example of setting the stator/slip current limit and the supply current limit of the drive motors in a Tuner generated swerve project. To determine the correct current limits, and understand what they do and how they affect robot control, please refer to Improving Performance with Current Limits.

52    // The stator current at which the wheels start to slip;
53    // This needs to be tuned to your individual robot
54    private static final Current kSlipCurrent = Amps.of(120);
55
56    // Initial configs for the drive and steer motors and the azimuth encoder; these cannot be null.
57    // Some configs will be overwritten; check the `with*InitialConfigs()` API documentation.
58    private static final TalonFXConfiguration driveInitialConfigs = new TalonFXConfiguration()
59        .withCurrentLimits(
60            new CurrentLimitsConfigs()
61                // Default supply current limit is 70 A, but it can be lowered to avoid brownouts.
62                // Supply current limits can be larger than the breaker current rating.
63                .withSupplyCurrentLimit(Amps.of(70))
64                .withSupplyCurrentLimitEnable(true)
65        );
47    // The stator current at which the wheels start to slip;
48    // This needs to be tuned to your individual robot
49    static constexpr units::ampere_t kSlipCurrent = 120_A;
50
51    // Initial configs for the drive and steer motors and the azimuth encoder; these cannot be null.
52    // Some configs will be overwritten; check the `With*InitialConfigs()` API documentation.
53    static constexpr configs::TalonFXConfiguration driveInitialConfigs = configs::TalonFXConfiguration{}
54        .WithCurrentLimits(
55            configs::CurrentLimitsConfigs{}
56                // Default supply current limit is 70 A, but it can be lowered to avoid brownouts.
57                // Supply current limits can be larger than the breaker current rating.
58                .WithSupplyCurrentLimit(70_A)
59                .WithSupplyCurrentLimitEnable(true)
60        );
58    # The stator current at which the wheels start to slip;
59    # This needs to be tuned to your individual robot
60    _slip_current: units.ampere = 120.0
61
62    # Initial configs for the drive and steer motors and the azimuth encoder; these cannot be null.
63    # Some configs will be overwritten; check the `with_*_initial_configs()` API documentation.
64    _drive_initial_configs = configs.TalonFXConfiguration().with_current_limits(
65        configs.CurrentLimitsConfigs()
66        # Default supply current limit is 70 A, but it can be lowered to avoid brownouts.
67        # Supply current limits can be larger than the breaker current rating.
68        .with_supply_current_limit(70.0)
69        .with_supply_current_limit_enable(True)
70    )