velocity PID using PIDController

Hi,

Im trying to use the WPILib PIDController to keep our shooter on the desired speed.

I read the info on this page:
http://wpilib.screenstepslive.com/s/4485/m/13809/l/599721-operating-the-robot-with-feedback-from-sensors-pid-control

By looking at the code snippet I understand that we need to calculate the desired motor volt value and use the setsetpoint() to set it.
The algorithm will run a loop that will get us and keep us on the desired setpoint, Is that correct?

Actually what we really need is to set the motor speed, measured by the encoder, as a setpoint. how can we achieve that with the PIDController?

Thanks for any help!!

If you are using Talons, you can achieve PID speed control without PIDController (read the talon software manual).

Otherwise, you need to set up an Encoder object and use that as the PIDInput for PIDController

Thanks!
I found my mistake in understanding the PIDController mechanism.
the setsetpoint() get the target encoder value and not the motor target value.

In a related thread, I noticed there was a mention of the difference n tuning of PID loops that are based in velocity rather than position, anyone care to elaborate on that?

I would suggest finding your max RPM value, then setting your desired power level in the motor to be

desiredRPM / maxRMX + pidControllerError

This utilizes a feedforward and making our PID easier to tune.

Basically:
Once the PID has reached a position setpoint, the ideal output (or state) is 0 (at rest).

Once the PID has reached a rate setpoint, the ideal output is to maintain the necessary speed (this, in PID terms, is called feedforward).

I’ve generally found that good tuning of a velocity PID starts with feed-forward - as mentioned, set it to (max motor command)/(max output speed), and play with it to see how close you can get to your setpoint without any feedback. After that, bring in the rest of the PID to help reject disturbances and get you even closer to the setpoint.

Technically, you can still to feed-forward on a position-controlled loop as well. Instead of feeding the setpoint forward with a gain, feed the derivative of the setpoint forward. WPILib can do this, I think. However, I have not yet had much luck tuning it, P and I usually work well enough.

If you have an arm that requires motor voltage to hold it at the desired position (due to gravity or other forces), you can use that as the feed-forward.

If you have several different desired positions, you can have a different feed-forward value for each position.

The usual caveats about stalling motors goes without saying. Just saying :slight_smile:

Nifty, I hadn’t thought of that but it’s another great point! Vex has done quite a bit of work determining what motors can be stalled and at what voltages, so that might be useful as well…

A PID loop is a feedback loop, so you need a feedback device for it to work properly. There is no need to use a PID loop for voltage, because you can literally just set the motor to that voltage. You set the PID loop to a value that can be verified by that feedback device, i.e. position in ticks.

Well, yes and no.

You can open-loop set the motor controller’s output PWM duty cycle, and that will give you an effective voltage at the motor closely equal to some fraction of the battery voltage, minus voltage drops in the wiring.

But to get a true voltage at the motor, you need a feedback controller. Fortunately, this capability is built-in to some FRC motor controllers.