So I’m confused about the decoding factors. So if I wire up an encoder to the roboRIO and decide to program with Java, then I need to use the Encoder class from wpilibj. However, I don’t understand decoding factors. So if you instantiate an encoder, if you don’t specify the decoding factor (like 1X, 2X, or 4X), then the encoder, by default, uses 4X decoding. If this post is too long, then please bare with me, because I’m so confused
So if I use a PG71 motor and I use the encoder that comes with the PG71, the encoder makes 497 counts per revolution of the shaft at the end of the gearbox. Let’s say that I don’t specify the decoding factor when I instantiate it and, as a result, the encoder uses the default decoding factor (which is 4X). And I choose the unit for distance as a revolution of the shaft at the end of the PG71 gearbox. My understanding of the decoding factor is that each of the “counts” in the 497 counts/rev is really an encoder cycle, so if decoding factor is 4X, then all 4 edges of each encoder cycle is counted, and so the actual number of counts/rev is 497 x 4 = 1988 counts/rev. So, when I use setDistancePerPulse(), do I do setDistancePerPulse(1/497)? or do I do setDistancePerPulse(1/1988)? Does changing the decoding factor affect the double that you put in the setDistancePerPulse() method?
Also, what’s the difference between the get() and getRaw() methods? Does getRaw() only get you the number of encoder cycles, and get() will get the actual counts by multiplying the number of encoder cycles by the decoding factor?
Now, as for programming an encoder when it’s wired to a Talon SRX. The Talon SRX always does 4X decoding, right? And let’s say that I use the set(ControlMode mode, double value) method. Let’s say that I, again, use the PG71 motor, and I wire the encoder from the PG71 to the Talon SRX, and that the control mode I wanna use is Position, so the output value is in encoder “ticks”. If I want to make the shaft at the end of the PG71 motor turn 1 full revolution, and the Talon SRX always does 4X decoding, do I do set(ControlMode.Position, 497) or set(ControlMode.Position, 1988)?
Also, can I use a Talon SRX with an encoder wired to it without specifying a PID loop and the PID gains? By that, I mean that can I do something like set(ControlMode.Position, 497) and when I run it, the PG71 will turn until 497 encoder ticks has been made and that in the event that it overshoots, it will rotate backwards until the encoder ticks go to 497 when I don’t specify any PID loop and PID gains whatsoever?