Hi, we’re trying to update all of our libraries and code to phoenix 6, however, with the most of the changes involving the way classes and status signals work, we’re having trouble with the difference between getPosition() and getRotorPosition() and their velocity variants. Also, if I want to set the encoder position to 0, for example, do I Use setRotorPosition()?
I believe getPosition() uses whatever you configured as your feedback source–be it the motor itself, a remote CANCoder, or other remote encoder–while getRotorPosition() always returns the position of the motor, independent of external encoder readings.
To add to what @swurl said, getRotorPosition() is to get the motor rotor’s position and is only affected by RotorOffset. getPosition() is to get the position of the mechanism, so it can use an external sensor, and it also uses the RotorToSensorRatio and SensorToMechanismRatio.
You’re probably using an old version of the library if you see setRotorPosition(). There was an issue where this method was misnamed because it set the mechanism position This was fixed over the summer. The correct method is setPosition(). It sets the mechanism position (as described above), but since you’re setting it to zero it doesn’t really matter if it’s rotor or mechanism position. You should consider upgrading to the latest alpha/beta.
“Best” is subjective, but that’s what I would do.
If you’re using CANCoders and buying Phoenix Pro, you’d probably want to use RotorToSensorRatio with FusedCANCoder or SyncCANcoder for azimuth control, but you wouldn’t have to.