Setting PID constants in code for TalonSRX Velocity Control

I’m working with the CTRE Demo code for tuning closed-loop velocity control on the TalonSRX. When I set the PIDF constants in code (using _talon.setP, _talon.setI, etc), the values seem to not get set on the talon itself.

Here’s what I’m seeing: When I run the code with any PID constants set, the system doesn’t move whatsoever. No matter if I set any combination of P, I, D, or F, there is no response. If I go onto the roborio’s web viewer (on http://roborio-<team>-frc.local) I can see the PID constants I set. If I manually re-enter and save the PID constants on the roborio web viewer, the system responds exactly as I would expect.

This only seems to be a problem when I set the control mode to TalonControlMode.Speed. I don’t see the problem if I’m using TalonControlMode.Position. I’ve made sure all the firmware on the TalonSRXs, RoboRIO, and PDP are all up to date, as well as my wpilib and ctre lib installs.

I just noticed…

 _talon.configPeakOutputVoltage(+12.0f, 0.0f);

… which caps the output to forward only. If you want to spin reverse you should do…

_talon.configPeakOutputVoltage(+12.0f, -12.0f);

… which allows full motor output in both directions.

I think the peak outputs get reset to the defaults when you save in web-config.

*Is this for a flywheel (shooter)?

This is a pretty fly wheel…

#bringingdiscoback

This was the problem. Thanks!

Depending on your application, you may actually want:

_talon.configPeakOutputVoltage(0.0f, -12.0f);

in the case that you only want it to spin in the ‘reverse direction’ and never apply ‘forward’ voltage. If you realize you’re driving your car faster than you want on the highway usually you just let off the gas, not throw the engine into reverse.

Capping the output to one direction is perfectly legitimate. However depending on the Fgain, you may not get a direction change caused by being under the target velocity. This happens when the F term provides most of the motor output, and the PID simply tweaks the output to approach the target speed.

This is ideal for applications where you want both directions, such as drive wheels. Here’s an example of a team using speed servo all the time on four mecanum wheels…
https://www.chiefdelphi.com/forums/showthread.php?t=141120&highlight=mecanum+talon+speed

Notice our velocity walkthrough in the Talon SRX Software Reference Manual does not require you to enforce only driving in one direction.

This is our first time use of the SRX. We are programming in LabView and using the velocity example program…
We have followed the example for Java velocity closed-loop with interpretations for what LV wants.
I am confused about F-gain. We go through the process. Our motor is running at about 6000 RPM maximum. We get a velocity of 39136 from self-test. Using the formulas we compute F-gain as .026139. If we put that value in the F-gain field in the example, the motor runs to full speed when we set the requested output to -25600 (-3750RPM). Both SRXs are showing Green LEDs.

We have tried bringing down F-gain then setting PID values that get us close to what we want. But with our tuning, the SRX doesn’t really regulate. When we start other motors, the speed drops 250 RPM, when we put in a fresh battery, the speed goes up 400 RPM.

I think that we are doing something fundamental wrong. Does F-gain need to change based on the speed we are running.

We are using two motors with one in slave mode. Occasionally the SRXs get out of sync after we download and will buck (one showing RED the other showing GREEN) each other.

I’m assuming you’re using a CTRE Magnetic Encoder?
We solved this by deleting the 6.8 multiplier and trying a raw rpm value. Once we did that, the F-gain started to make sense and we were able to tune sensible PID numbers.

See if this helps:
http://imgur.com/a/Ljv4H

Edit: I forgot to add, have you checked to make sure your encoder and your motor controllers have the same polarity?

Austin, you are a life saver.
Doh, we were showing Green with the encoder counting positive so I thought it was OK. At sometime, the reverse-control-output got set. I don’t understand how it did anything but go to full speed in the wrong direction rather than somewhat working.
Thanks again, Hope we see you at World,
Randy

Glad to hear it. I would be interested to hear if it took anything else to mod the example code to get your desired function or if I just went a bit crazy with the delete key…