Acceleration control for swerve drivetrains

Hi everyone!
My team is looking to implement acceleration control on our swerve drivetrain. When accelerating or decelerating too fast our robot tilts on its side…
Ideally, we only want to limit linear acceleration on the field, and not the acceleration that is used to turn the robot in place.
Has anyone here got experience with implementing such a thing and has tips to share? Perhaps the “naive solution” of just setting a ramp rate to the drive motors is enough? I’d love to hear!
Thanks a lot!


It sounds like you want a SlewRateLimiter we use one in our Teleop driving command.

We declare
private SlewRateLimiter xLimiter = new SlewRateLimiter(3);
This creates a limiter that allows for 3 units change per second. In this case 1 unit will be 100% or 1. Meaning it can reach 100% in 1/3 of a second.

it is used in code like
xTranslation = -xLimiter.calculate(modifyAxis(m_gamepad.getLeftY()));


One additional caution is be aware of the unit and range of what you are limiting. In my example I was limiting percent output based on the axis of a controller. so the range was 0…1 So a rate limit of 3 was 100% in 1/3 of a second. If you limit after conversion to metersPerSecond you will want a higher limit. For the sake of easy math let’s assume that 3m/s is the max velocity of your drivetrain so to get to 100% in 1/3 of a second you would want your limit to be 9 and not 3.


If l combine these two together ,will the swerve be smoother.(Use the slewratelimiter when getting input from the joystick and calculate it again with the speed input.)

I would only do it once. limiting the rate of change of the percent and the velocity are functionally the same. Do one or the other.

Thanks , l think do it in the joystick is much preferrable.

You want to apply your rate limit after any joystick scaling, because the scaling might be nonlinear which will change the effective acceleration limit based on the current speed.


Listen to @Oblarg , always listen to Oblarg.
My example had the modifyAxis before the limiter but I did not call that out. Thanks for making that point it is important.

1 Like

So, if l have optimized the joystick before, just like below,

l should use the slewratelimiter later

And use it to drive my robot , is that right?


Yes, that looks right to me.

1 Like

Thanks ,besides , if l want to judge whether l have told my robot to rotate and use the code below,

Should l change the tAxes.getX() to translation.getX()?

1 Like


Thanks a lot for all the help! I think that I understand :slight_smile:

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.