Hi CD,
We’re having an issue with a VP integrated encoder plugged into a Talon SRX. It is set to absolute position mode, and briefly outputs a correct degree readout but after being turned around a little bit manually, the degree output starts spiking rapidly and reaches thousands of degrees. We never had this issue in the past, and have already swapped both the encoder and the cable that is connected to the SRX (could still be cable, but unlikely…) and we haven’t had any luck.
The only things I can think of doing are swapping the SRX or downgrading to Talon SRX firmware 3.3 (upgraded to 3.8 just before the competition). Has anyone seen a similar issue or another idea for fixing it? Again, we never had issues in the past, and I can’t think of anything which has changed…
We have at most 2 hours tomorrow morning to fix this.
Could you post the relevant code associated with the encoder? It’s unlikely, but possible that it’s the SRX, and posting the code would help us debug.
You say the data you are getting is in degrees. How are you getting this? The CTRE mag encoder in absolute mode is 4096 units per rotation. Unless you are converting this or utilizing the feedback coefficient function, this would explain why it reaches thousands of units.
I am using a version of 449’s wrapper, but here’s the conversion function:
protected Double encoderToFeet(double nativeUnits) {
if (encoderCPR == null) {
return null;
}
return nativeUnits / (encoderCPR * 4) * postEncoderGearing * unitsPerRotation;
}
Where encoderCPR is set to 1024, postEncoderGearing is 1, and unitsPerRotation is 360.
This is what’s being fed to this function:
canTalon.getSelectedSensorPosition(0);
And here’s the full Talon SRX class (warning… very lengthy):
https://gist.github.com/18melan/9e422ef49c944f79bb2dbacf36b8ba69
The logic that is setting the angle (from the subsystem) worked perfectly in the past, and nothing has changed, so I really don’t think it has to do with the code posted above (except maybe CPR? Keep reading…)
For conversion, see the function I posted above. However, I was under the impression CPR was 1024? Does it change to 4096 when switched to absolute mode? Why might it have worked consistently during the season with 1024 set for my CPR?
Take a look at page 53 on the Talon SRX Software manual. That has information on how to look at encoder values in the webdash and may provide some helpful debugging info. Good luck tomorrow, and see you at Forsyth!
We have had a similar issue with a SRX Mag Encoder that never rotates more than 250deg (without any wraparound) yet often we will randomly get very large negative or position readings after moving it. It is not an ideal solution, but adding or subtracting 4096 till you reach your ‘desired’ value has worked for us. If you manually do this, you should find you will reach your correct position.
The CPR value you have is fine if used with 449’s wrapper, its being multiplied by 4 to make 4096.
Have you tried a reset on the TalonSRX? Hold down b/c cal button on the TalonSRX while applying power, it should flash green rapidly. Deletes all old configuration parameters… and often fixes any weird behavior you are experiencing.
We are using firmware version 3.8, but only with relative mode.
If you use the relative mode for the mag encoder, does it have the same issue with massive spikes in degrees? Is it possible to add a limit switch and use the SRX zero on limit switch parameter to provide the same functionally equivalent behavior as the absolute encoder?