Phoenix 6 naming confusion

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()?

Thanks.

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.

1 Like

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.

3 Likes

Thanks for the reply. I can’t update the vendor dependency for some reason. For me the naming is still the same.

For a Falcon swerve module, I guess the best thing is to use the getPosition method and use the sensorToMechanismRatio, right?

Sorry, I had the 2024 version. When testing with WPILIB 2024 beta, it worked.

Thanks!

1 Like

“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.

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.