This is another part of your long threads related to PID tuning (and maybe radio disconnection). I just saw this one and it has been largely answered in your other threads. I’ll try to fill-in a little more explanation and may be somewhat redundant. With no publicly available complete code I have to do some guessing and I can’t point to exact lines of code to reference.
WPILib PID controller and the now separate but related WPILib Feed Forward calculator have little to do with the CTRE Talon PIDF controller at the detailed implementation level. (They solve the same problem with almost the same equations but are accessed very differently.)
You can communicate your velocity intentions to a Talon in one of two ways:
set the voltage (%VBus fraction of the battery) to what it takes to go your (approximate) velocity
set the velocity in PIDF velocity mode after initially setting the kP, kI, kD, kF
You communicate your intentions to WPILib by:
- set the velocity
and then WPILib has to communicate to the Talon by:
- set the voltage (%VBus fraction of the battery) based on your estimating what that voltage should be for the desired PID error correction PLUS (+) the WPILib feed forward (still, again YOU have to somehow relate voltage to velocity for your particular device - I’m not getting into that exact code)
The Talon PIDF only receives your desired velocity setpoint each iterative cycle (normally 0.02 seconds in Robot). The Talon computes internally the required voltage by its relationship of that setpoint through your preset kP, kI, kD, kF. (With those you relate velocity to voltage and determine the gain of your controller.)
That’s enough details except I’ll do feed forward a bit more since that goes directly to your question and apparent error in your code shown in other threads.
The WPILib feed forward calculation is a little more sophisticated than the Talon calculation. WPILib gives you 3 parameters to tune (static, dynamic, acceleration) and Talon only one (dynamic). As a practical matter we find the Talon method is adequate.
The result of the WPILib feed forward is a voltage to add to the WPILib PID controller output voltage and that total voltage goes to the Talon.
The Talon feed forward is intrinsic to its PIDF controller and is done automagically for you by multiplying your initially defined kF by your velocity setpoint that you set on each and every Robot iteration.
It is incorrect to send a WPILib feed forward to a Talon PIDF controller. The units are different and indeed the concepts are different. Specifically:
Say you want 800 RPM (actually use the correct Talon native velocity units but I’ll ignore that for simplicity).
If you used the WPILib feed forward correctly tuned, you might get back from it 0.15 (%VBus).
If you set the Talon in velocity mode you tell it 800. If you added the WPILib feed forward you’d be telling the Talon to go 800 + 0.15 = 800.15. That is not the velocity you wanted and may be the source of your error!!
Where is the Talon feed forward? The Talon already had multiplied your previously defined kF by the setpoint for you and added it to the error correction terms for you. Note that the single kF does usually work well enough over your velocity range. The exact calculation is in the CTRE documentation and has been repeated for you in your other threads.
Basically kF is %VBus/Velocity (I’m ignoring the 1023 native throttle units conversion which you must do). That ratio is amazingly constant over a wide range of velocity and deviations don’t much matter in the PID controller.
Calculate kF over your velocity range and pick the slightly smaller value so you don’t overshoot any of your setpoints. It’s trivial and NOT exacting - pick a %VBus and see what the velocity is near your shooter’s two desired RPMs. No need to use SYSID for Talon parameters.