PIDF Tuning - TAMSFormers5212/TAMSformers-Database GitHub Wiki

Guess and Checking

All control methods are at their core physics based, but due to the general limitations in the knowledge of high schools (even if they are TAMS students), it is usually more realistic to just guess and check numbers until you reach a point where they work well enough. This solution also has the benefit of being guaranteed to apply in real life unlike calculations which will need to be retuned due to the imperfections in real life.

PID

[insert wpilib page]

Proportional (P)

P, the propotional term, can be thought of as the power behind the PID. It returns an output as a function of a proportion of the error.

Integral (I)

I, the integral term, is based on the calculus term. It essentially acts as a memory of how long it has taken to reach the setpoint. It slowly builds up to add more power to the motor if the motor is not reaching the setpoint.

Adding an I term is often unstable and isn't nessecary for most FRC mechanisms.

Derivative (D)

D, the derivative term, is likened to a dampening effect. It is usually added to prevent overshooting the setpoint. Though it would be possible to not overshoot by reducing P, it is beneficial for a faster mechanism to have more P and use D dampening.

Tuning a PID

Our process is simple. First, add a very small P. The expected behavior is to move a little bit and never get to the setpoint. Then, double the P value and keep doubling it until the mechanism starts to get to the setpoint quickly. From there you can tune it until it's pretty good with just P with only a small amount of oscillation. There you can add a D value. We like to start at 1/10th of the P value as a starting guess. Adjust this value until the motion arrives at the setpoint quickly and smoothly.

FeedForward

[insert wpilib page]

Unlike PID, which is a feedBACK controller, feed forward (FF) works in front of the mechanism in a way. While a feedback controller would need to look at the current state of the mechanism to calculate an output which lags behind, feed forward will calculate an output based on where the mechanism should be in front of the current state so that hopefully it will be more accurate when the command gets to the motor.

Tuning a Feedforward

Feedforwards offer a more stable control system compared to PID which can react violently based on the feedback system. Feedforwards can be calculated based on information known about the system and the motor. There are going to be a couple of constants you'll need to find. All feedforwards need a kS, kV, and kA term. Some feedforwards have other terms like an arm feedforward which has a kG term.

[SimpleMotorFeedforward] [ArmFeedforward] [ElevatorFeedforward]

kS is the static term. This does not change during operation. It is generally used for friction. You can find this as the minimum amount of motor voltage that will start the mechanism moving. You can find this by testing small voltage amounts until the mechanism starts moving, then using a value just under that. Alternatively, kinetic friction can be found by finding the voltage that will keep it spinning at a constant, low speed. The flywheel will require a hand start at first because static friction is greater than kinetic friction. kS is most useful when the friction force is a significant value compared to normal operating power. This is true for velocity based mechanisms such as drivetrains and flywheels.

kG is the gravity term. This is used when gravity has a big influence on the system like in arms or elevators. It's found by the value that holds the mechanism in place at maximum gravity force. For an arm this is parallel to the ground, and that value is multiplied by the sin or cos of the arm angle. For elevators this is the same except when the elevator is all the way down.

kV is the velocity term. It's typically what actually gets the mechanism to move. Idk how to find really find it we just guessed and checked for the 2024 shooter. Testing sysid in the offseason.

kA is the acceleration term. For most things kA will not be nessecary to achieve a good amount of control. We didn't use this at all on the shooter, but it may become important when you are controlling acceleration such as with a motion profile.

Physics Calculations

We have also used physica calculations to arrive a some values. Some of these are going to take a lot of physics, but some a simple and can give you good results.

kG is usually the easiest because its just gravity. You'll be able to figure it out after you first semester of physics.

For most mechanisms, reCalc.com offers a prediction for kS/kG, kV, and kA value based on the system information. You can find things like mass and center of mass in CAD though it won't be perfect. As a result, you absolutely need to test the calculated values one at a time.

⚠️ **GitHub.com Fallback** ⚠️