Has anyone had any success with the PID functionality that comes with the SRX? At this point we’ve wired up a quad encoder to the analog breakout (three different ones - we’re testing them to see which one we like more), and have seen many different functions that relate to PID with the encoders in the SRX documentation, and have tried several, but we’re not sure where the PID loop is getting error from or how to write that to the SRX from the encoder. We’ve used PIDWrite, and that didn’t help us, it just acted like Set().
At this point we’ve wired up a quad encoder to the analog breakout
How did you do that?
Are you trying to use the internal PID(F) closed-loop in the Talon SRX? In which case use ::Set() to set the set point after selecting the mode (Position or Velocity).
PIDWrite is part of the wpilib implementation that runs in the RIO, not in the Talon. For that to work you need to source the encoder position/velocity into it by providing a PIDInput to a PIDController.
If you are using the internal PIDF closed-loop in the talon firmware…
Check the signal values mentioned in section 11.2 of the Talon SRX software reference manual. “Closed-loop Error” is the main signal you care about. That’s the target set pt minus the current pos/vel. The Self test is very helpful for seeing what’s happening. Check that the selected sensor is what you want and that the sensor position and sensor velocity signals seem right before trying to closed-loop to a position/speed.
The actual math is in section 18 (the actual code in the talon for pidf), that might help.
I would test quadrature encoder first. There is an upcoming Talon firmware update with some fixes for analog encoder specifically.
We checked ClosedLoopError and it only gives us 0. We’re using ::Set() to set the set point now, but that didn’t change anything. We’ve selected the sensor we want and it seems to be giving us the right signals.
Did you set the mode to position servo in your source? Does it match the selected mode in the self test? Closed Loop Error will not change unless Talon is in a closed-loop mode (position or velocity).
Position and Speed are the control modes I’m talking about. You must be in one of these modes for there to be a ClosedLoopError. How else will the Talon know whether to calculate ClosedLoopError in position or in velocity?
If you are selecting PercentVbus, then the Set() calls will simply control the output voltage of the Talon (no closed loop). And CloseLoopErr will not change since Talon won’t calculate it.
*Pardon me if the following questions seem obvious but it’s best not to assume.
It sounds like you’re saying you ran the quadrature outputs of the encoder through an analog breakout… that’s not what you meant is it?
Are you wiring the encoder outputs to the SRX or to the roboRIO?
What is the model number of the encoder you are using.
we’re not sure where the PID loop is getting error from
The PID in the Talon uses the speed (or position) command it receives via CAN bus from your software as the setpoint for the PID, and uses the signal from the encoder (which must be attached directly to the SRX and not to the roboRIO) as the process variable for the PID. The error is computed by the PID in the SRX by (I assume) subtracting the process variable from the setpoint.
or how to write that to the SRX from the encoder.
As explained above, you don’t write the error to the SRX. Your software (in the roboRIO) writes the desired speed (or position) via CAN bus to the SRX.
Position and Speed are the control modes I’m talking about. You must be in one of these modes for there to be a ClosedLoopError. How else will the Talon know whether to calculate ClosedLoopError in position or in velocity?
If you are selecting PercentVbus, then the Set() calls will simply control the output voltage of the Talon (no closed loop). And CloseLoopErr will not change since Talon won’t calculate it.
Hello, we are using a Talon SRX controller in position mode set up to use a quadratic encoder with a motor that has a quadrature encoder connected to it. The encoder gives us correct values when we monitor it, but when we try to use it and a PID to stop the motor at a certain point, the motor continues to turn regardless of the fact that the encoder’s values are past the setpoint; it doesn’t even attempt to slow down.
The same goes for the soft limit function, when we set a soft limit and have to motor turn toward the limit, the motor continues to turn, even past the limit we set. The strange part is, when we try to rotate to motor back - back into the range of values between the soft limits - we can’t. The functionality to turn the motor backwards exists, but it refuses to rotate backwards when the values of the encoder are outside the limit we set.
Sounds like a direction problem. Can you at least confirm the Sensor Position as reported in the Self-Test moves in a positive direction when the motor is driven with positive throttle. See section 7.4 in the Talon SRX Software reference manual for details.
Next leave the motor controller in throttle mode, enable the soft limits and drive the motor to the forward and reverse soft limits. See if that works by itself. Use the Self-Test to confirm the soft limits thresholds.
Remember that the forward soft limit only takes effect when Talon SRX is throttling forward (green). And Reverse soft limit is in effect only when throttling reverse(Red).
Also obviously the forward soft limit must be greater than the reverse soft limit since positive drive => positive sensor position change.
K. just to be clear be sure to check the actual “Sensor Position” signal, not just the “Quadrature Encoder Position”. They are different and soft-limit/closed-loop logic only uses the “Sensor Position” signal.
Ah, we had the encoder’s output inverted and not the sensor position’s.
Inverting the sensor position fixed our problem, both the PID and soft limits work now.