# Swerve Drive Deleceration

Our robot for this year is done, other than some last-minute tuning. One problem we have been running into is decelerating the robot. When we stop, the robot stops instantly and almost tips over. We are planning to add weight to lower the center of gravity, but is there anything we can do to mitigate this on the programming side? We use SlewRateLimiter for acceleration, but when we stop, it goes straight to the motors and stops them. When we try to set the desired speed to 0 instead, the wheels start moving in random directions without input.

Our code is at GitHub - R-venRobotics1288/2023-Code-Template. Any advice would be appreciated!

2 Likes

to my understanding, a slew rate limiter should also limit your decelerationâ€¦

3 Likes

This if statement will get evaluated as false when you release your joysticks, calling the drivetrain stop function, which ignores the slew rate limiters you have in place.

1 Like

Forgot to elaborate clearly. We know thatâ€™s why the issue is happening. The problem is that we canâ€™t find an alternative. We have tried running the drive method with 0 for xspeed, yspeed, and rotation, but that causes the wheels to act sporadically before we even give an input on the joystick. How would we go about implementing it properly?

1 Like

The if statement asks, â€śare the joysticks currently pushed away from their center/home positions?â€ť If so, drive with the rate-limited joystick percentages.

This works at the beginning; the joysticks move, then the rate-limited values ramp up. But it doesnâ€™t work at the end; the joysticks return to home, then the rate-limited values slowly return to home. Before the rate-limited values get there, the if statement says â€śjoysticks are centeredâ€ť and the program says â€śstop!â€ť

To get the desired result, you want to ask, â€śare the rate-limited joystick percentages beyond their center/home positions?â€ť That way, when the joysticks return to center, the robot continues to drive until the rate-limited values catch up.

The stick positions are being modified by deadbands before they get fed to the rate limiters. Because of this, the info youâ€™d want to build your if statement on isnâ€™t available; itâ€™s sliced out of the rate-limited outputs and itâ€™s timed incorrectly on the non-rate-limited inputs. Maybe consider calculating the deadband on the output of the rate limiters?

Thatâ€™s a good idea. Iâ€™ll try it out later today.

Part of your problem might be that the drives are set to brake mode so the motor will stop allowing movement the second it stops, you can change this to coast and itâ€™ll pause for the stop but then keep rolling forward for a little.

Update for future teams: applying the deadzone
to the SlewRateLimiter worked perfectly after a bit of tuning. The one downside is that the robot doesnâ€™t decelerate enough when you instantly turn around, but this is largely due to our robot being decently top-heavy (we had it tip during a match ). Thanks for the help!

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