Current limiting on swerve

Hello,

My team recently got Krakens for our drive motors on our swerve. Currently, we have this for the config:

driveConfig.CurrentLimits.SupplyCurrentLimit = 50;
driveConfig.CurrentLimits.SupplyCurrentThreshold = 55;
driveConfig.CurrentLimits.SupplyTimeThreshold = 0.1;
driveConfig.CurrentLimits.StatorCurrentLimit = 50;

What do these values do? Also, any ideas on what we should set them to? These are just guesses.

2 Likes

So, there is a lot of misconception on the purposes of current limits, what they should be used for, and a basic understanding of battery budget. Let’s start with a simple definition of supply current limits and stator current limits.

Supply current limits basically forces the motor controller to not consume more than X amount of amps from the battery. This is useful for preventing brownouts when you consume more than your battery budget will allow, more on that later.

Stator current limits, in the CTRE Swerve API also called Slip Current Limit, is the maximum amount of current that is actually used by the stator or shaft of the motor. This is different from the supply in the fact that stator current is also directly proportional to the amount of torque being applied the motor. Another property of stator current limits is they can affectively limit the acceleration of the robot.

Lots of numbers are thrown around on what’s safe, and whatnot and that’s true to an extent. There is more too it than that, especially if you want to maximize battery life and maximize your on match performance.

Let’s dive a bit deeper on the characteristics of the electrical system of the robot.

You have a hard 120a breaker from the battery to the PDP or PDH. Then you typically have a 40a auto-resettable breaker in the PDP or PDH. You would assume this caps your draw at 40a, but these are primarily safety features with LOTS of wiggle room. Specifically, the REV 40a datasheet can actually sustain 80a for a minimum of 5s. The 120a main robot breaker can also sustain near double it’s rated capacity. This isn’t quite the end, as this draw on the battery can ruin it’s lifespan.

You can do some pretty basic napkin math to estimate how much you will need to supply current limit, and you’ll want to actually do real match-like testing to verify you get the results you want (no or very few brownouts for ~2-3 minutes of intense play).

If I have a 8 motor drivetrain, and the battery can sustain 270a for ~5s (let’s round down to 250a to be on the safe side). That leaves 270/4 for the drive motors or ~67a supply limit. But you can exceed the 270a for very very brief 1s cycles, and your motor shouldn’t be consuming >20a just cycling. This is why you see some teams actually set there current limits to 80, or even 120a and this may even be an area where stator current limits will help a bit more. The greatest battery draw on an FRC drivetrain is the initial acceleration.

In the above graph, you can actually see the supply current spike to 120a for .5s when the robot goes from 0 to 100% dutycycle then the drawn current settles down to ~10a. These are things to be aware of if you want to maximize the juice you get in this battery limited environment. It’s also why efficiency of a motor matters. The less juice to get the same power, means more aggressive limits, which means faster acceleration, which adds up.

Edit: To further answer the post, the thresholds is the time it takes for the limit to actually take affect. The defaults are typically fine.

29 Likes

This was a very clean and well-thought-out answer, thank you!

Where did you get the data that the battery should take no more than 270A for no more than 5s? Is that a good rule of thumb to follow? I am trying to figure out how to advise my students on applying current limits across the robot.

The MK battery datasheet.

1 Like

That’s a really good explanation! I still have a few questions though.

Does the supply current limit not affect acceleration then? Also, then, is having a supply current limit which is greater than the stator current limit meaningless?

Supply current does limit acceleration, but it is a non-linear relationship. On the other hand, a stator current limit is a hard cap on acceleration, which is more limiting than the effect of a supply current limit.

I put together this Desmos graph to approximate the effects of supply and stator current limit on motor output power.

Theoretically, yes, because the magnitude of stator current should always be greater than or equal to that of supply current.

2 Likes

On your Desmos graph, it appears that the key is wrong. It says “Green = Stator Current, Blue = Supply Current, Red = Power”. It appears that Green and Blue are swapped. As you said, “the magnitude of stator current should always be greater than or equal to that of supply current.”

Other than that, great tool for helping understand motor/stator current and power!

3 Likes

Yep, it looks like for the “Both Current Limits” folder I accidentally swapped the colors, here’s the corrected graphs.

How do you set supply current limits when dealing with the generated swerve drive code? I found where the stator current limits are set but I don’t see anywhere where the supply current limits are being set in the swervemodulefactory or anywhere related. Do you set them on the swerve motors themselves or is it necessary to set them? I am asking because my team’s drive is browning out mid match and I am trying to stop that.

1 Like

You can configure supply current limits using the driveInitialConfigs field in TunerConstants (introduced in 24.3.0). Additionally, in the 2025 API, the TalonFX has default current limits enabled.

However, if your robot is browning out mid-match with a reasonable slip current configured (such as 120 A), then I would first check your battery and wiring, as is mentioned here.