Calculating PID Gains Without Physical Robot

Hi there,

I’m doing most of the code for my team’s robot this year (for Infinite Recharge at Home) and I was thinking of adding PID control to automate our shooter and ensure it launches power cells at a stable velocity rather than the manual approach we took last year. Unfortunately, the pandemic has prevented in-person meetings as well as access to our robot at school, so while I have the code ready, I have no idea what the PID gains should be. I was just wondering if anyone else has a similar problem and how they managed to get a rough estimate for their values. Is there any way I can get somewhat accurate values for the gains by plugging in various details about the shooter into a formula, or a way to get a rough estimate to those values based on the weight, rotational inertia of the shooting mechanism, etc.? If it helps, the PID is for an AndyMark 775 RedLine motor (no gearbox, so 1:1 ratio) controlled by a TalonSRX motor controller using the Velocity Closed-Loop Control Mode. Let me know your thoughts!

The WPILib robot characterization tool allows you to estimate PID gains from a simple DC motor model for most mechanisms. As you don’t have a robot, you won’t be able to run the feedforward characterization - but if you can estimate what the feedforward characterization would likely output for your robot (this may take a bit of physics and/or guesswork), I think (but am not positive) you could put the resulting characterization values into the feedback characterizer by hand, and have it output the corresponding feedback gains.

If that turns out to not be supported, you can file a github issue suggesting it, or maybe even modify the code and submit a pull request to add it. Or, you can do the relevant state-space math by hand, or with your own script. Talk to @calcmogul for further information on that.

Here’s a link on generating a flywheel model based on motor types and such: State-Space Controller Walkthrough — FIRST Robotics Competition documentation

You can pass that model to a LinearQuadraticRegulator object to compute an optimal feedback gain: State-Space Controller Walkthrough — FIRST Robotics Competition documentation

3512 has had the best luck with a model derived from frc-characterization feedforward gains since it’s most accurate, but motors and mass estimates may get you close.

this is a whitepaper our team made in the before times for tuning pid with less trial and error testing

Thanks for all your help! I ended up going with the state-space math and making a flywheel model from the moment of intertia for now as that was the only information I had to work with.

1 Like

Be extremely careful around unit conversions before attempting to use the gains in practice. The FRC motor control landscape has a bunch of competing APIs that all have different standards, and this is particularly painful for dimensioned quantities. Historically, most of the use of PID in FRC has been divorced from accurate system models, so you’ll probably find a lot of the documentation to be frustrating when approached from this angle (this is starting to change, though!). The information is usually sufficient to work out the correct conversion, but it’s not necessarily laid out to make doing so easy.

1 Like

Okay, I’ll be sure to keep that in mind. Although I won’t be able to be on my team as a member next year, I have commented it to ensure whoever is taking a look at it in the future will know what to change/do (that is, if they do end up reusing parts of the code). Thanks again!