So, REV really does not like you to work with RAW units, like CTR components do.
That means you basically say in NEO setup - my encoder goes from blah1 to blah2 in one full revolution. What the blah1 and blah2 are - that’s up to you. Could be degrees, could be meters, could be just arbitrary numbers. Just need to be a pair of doubles.
In the past I always calibrated that to some SI units to make it easier to use with the other components. For instance, if I use encoder on the arm shaft, I would calibrate it, so NEO will get me degrees of rotation. For linear motion I calibrated it to be meters, accounting for gearbox as well.
If your encoder provides relative or absolute values, NEO can be “explained” as much as well, with the ability to handle the rollover correctly.
To provide you a code example - here a branch of our test code that does NEO Swerve with the Duty Cycle encoders for Angle (those are built by Helix Labs), and built-in encoders for drive.
Note that with built-in encoders on NEO you cannot change sensor phase (because they are also used to handle brushless motion). So check the configureDriveMotor method.
The line starting with
driveEncoder.setPositionConversionFactor
sets the encoder output, and getDriveEncoderPositionSI method recalculates it into meters. Why do I need two? It was easier to calibrate the PID routines this way for auto trajectory driving.
We developed this code for our sister team, so we left it to them to recalculate PID constants if they want everything to be nice and neat.
And remember the main rule of PID - if you apply positive power,
- The PID error must decrease (meaning the part or robot should be moving “forward” - whatever that means)
- The sensor values (encoder values) must increase
which means with inverted motors and/or inability to change sensor phase you will rely on software methods to invert the numbers if needed.