When to tune the Feedforward in a PID System?

Hello guys, I’ve been retuning a shooter used in our trainings, and I get quite unsure whether to tune the kV first or kP first. I started on kP and used kV as a compensation as how we did the thing before but I am not quite confident now (Though iafter all it worked). It seems to make more sense to me if I should start with kV after kS?
Any suggestion is welcome!

2 Likes

In an ideal system, you’d be able to hit the velocity setpoint (when spinning freely) with just kV and kS. kP is used to close the gap a little bit, but since its contribution drops to zero as the actual velocity approaches the setpoint, most of the work should be done by kV. So start with tuning that.

2 Likes

kV. Setting kV equal to the motor’s backEMF constant will get you to the correct value in almost every case, while a small amount might need to be added to account for viscous friction for some mechanisms with a lot of it.

2 Likes

For me, I always adjust the feedforward first. If the feedforward is functioning well, Kp can simply provide assistance, which helps prevent mechanical damage and enhances the control’s reliability and repeatability. For further information, i recommend watching this video.

2 Likes

Incidentally, wpilib states this advice for everyone.

5 Likes

You should always tune the FeedForward first. If you don’t, the PID is acting on the control part of the problem, not the error portion. PID likes to only work on error.

For a velocity/flywheel PID, the feedforward calculates the rough voltage the motor needs to be at to sustain that velocity. The kP and kI parts can tweak the voltage to hit the exact RPM you want.

For an elevator design (move something in a linear direction), the feed forward is used to counteract gravity constantly. If you don’t, your PID constants get weird, as the mechanism will run slower up and much faster down. The feedforward should be set to the voltage needed to hold the mechanism in place, and always added to the motor command (assuming positive voltage = goes up, positive up command + positive FF= bigger request up, negative down request + positive FF = smaller down request)

For an arm design with a pivot point, gravity acts on your mechanism uniquely. Depending what angle your arm is at, gravity affects it differently (when flat, you need the most help to fight gravity, at top, you don’t need much help). You still end up needing to find the voltage to hold the mechanism, but it needs to be when parallel to the ground. Then you take the calculated feed forward times the cosine of the mechanism’s angle in relation to the ground. (I won’t prove it in all cases, the simple ones are parallel to the ground, so cos(0)=1 for max boost, and perpendicular to the ground, so cos(90*)=0 and no boost needed as gravity is neutralized).

I forget what all the constants WpiLib uses to describe this, that’s why I put the effective “what are the constants really doing” language. I think kV is the voltage needed to go one unit (say a drive wheel, it takes 12v to drive 5m/s, so kV is 2.4), kG is the voltage needed to overcome gravity (aka the arm and elevator voltage example), and kS is the voltage needed to break static friction (usually zero for us).

4 Likes

Note: this isn’t always true. Some systems are too unstable to operate without some amount of feedback. If you need feedback to stabilize the system well enough to tune the feedforward in the first place, you will have no choice but to start with feedback.

Generally manual tuning of systems like this is iterative; you adjust the feedback again once the feedforward has been tuned, and so on until you’re satisfied.

2 Likes

I’ve seen some stuff related to backEMF of motors around here, but I haven’t been able to find much info on it. Where can I find the constant? Or, if able, how do I calculate it?

Rated voltage divided by the free speed of the motor will get get you it close enough, watch out for units however. Also, do not use back-emf feedforwards when using current control.

1 Like

Further complicating matters: most manufacturer motor specifications will give kV in units of rotation/(volt*minute). WPILib has standardized on (volt*second)/rotation. The conversion is easy to do but you must do it or the gain will not work.

1 Like

The motor constant Kv, is not the same as the feedforwards gain kV, where they usually have different capitalization despite using the same letters. You also have to be careful in which coordinate system the code wants, before or after the gearbox.

On a different note, I don’t like the name kV for the velocity feedforwards for this reasons, and in my own work, split the term into kB and kVis for both readability reasons and to allow different handling of back-emf and viscous damping feedforwards.