Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Swerve Setpoint Generator] Limit max speed when voltage sags #931

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

TheComputer314
Copy link
Contributor

@TheComputer314 TheComputer314 commented Dec 16, 2024

This prevents an edge case where the torque limit breaks when the desired velocity is not possible for the motor given the current max supply voltage.

image

This prevents an edge case where the torque limit breaks when the desired velocity is not possible for the motor given the current max supply voltage.
@github-actions github-actions bot added the PathPlannerLib Changes to PathPlannerLib label Dec 16, 2024
@TheComputer314 TheComputer314 changed the title Limit max speed when voltage sags [Swerve Setpoint Generator] Limit max speed when voltage sags Dec 16, 2024
@mjansen4857
Copy link
Owner

These changes would allow the setpoint generator to generate setpoints that are not attainable for the robot. Desaturating the modules based on the voltage would limit the speed to a maximum that it can't necessarily decelerate to because the desaturation does not take the motor torque/wheel friction into account. The ability for the motor torque to be negative is also important because that is what will cause the robot to slow down when the drive motor is moving faster than the battery voltage would allow.

Additionally, #930 sort of supersedes this PR by allowing the user to specify a static voltage to avoid the behavior of using a dynamic voltage.

@mjansen4857
Copy link
Owner

I'm also not really sure what the graphs you posted are showing, so if I am missing some other issue that still persists, let me know.

@TheComputer314
Copy link
Contributor Author

TheComputer314 commented Dec 20, 2024

Sorry for not adding an explanation to the graphs.

The first graph shows the setpoint velocity making a discontinuous jump when voltage sags below 12 volts, as the drive acceleration constraint stops taking effect due to max_vel_step reaching exactly 0, letting the other constraints take over, which ignores the voltage limited max speed.

The second graph got deleted from the initial post, as it was implementation error in a separate unrelated modification I made.

The ability for the motor torque to be negative is also important because that is what will cause the robot to slow down when the drive motor is moving faster than the battery voltage would allow.

From my testing in simulation with these changes, the setpoint can still decelerate when the voltage sags, even in a unreasonable scenario of dropping 4 volts in 1 tick.

image

In the above image, I have a trigger bound such that when the button is pressed, the supply voltage fed into the generator is subtracted by 4. It's initially held, then released, then held again. Blue is setpoint, yellow is actual. If accounting for battery internal capacitance and a less extreme voltage sag, the deceleration is more gradual.

@mjansen4857
Copy link
Owner

Oh interesting. I’ll reopen this for now and do some testing with it.

@mjansen4857 mjansen4857 reopened this Dec 20, 2024
@mjansen4857
Copy link
Owner

Ok so this will need to be updated a bit for some changes made to the generator, and needs the same changes made to the new python version. I can help with translation if needed.

@mjansen4857 mjansen4857 added this to the Kickoff Release milestone Dec 27, 2024
@TheComputer314
Copy link
Contributor Author

What autoformatter does PPLib Python use?

@mjansen4857
Copy link
Owner

I haven’t set one up yet. I just typically use the Code -> Format Code option in PyCharm. If you don’t use that then don’t worry about it.

@mjansen4857
Copy link
Owner

So it looks like the python version is missing the current draw limits. This will also need to be ported to the C++ version as well which was just merged

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
PathPlannerLib Changes to PathPlannerLib
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants