So we are trying to read out CANcoders for swerve drive. We are using
public Rotation2d getCanCoder() { return Rotation2d.fromDegrees(angleEncoder.getAbsolutePosition()); }
We are getting an error because rotation2d.fromdegrees is expecting a double, but angleEncoder.getAbsolutePosition() is a StatusSignal Double from CTRE.
Is there any way to convert from one to the other?
Thank you.
StatusSignal is a generic class that offers methods to expose the enclosed type. If you need a double, then it would seem that getValue()
would meet your needs.
1 Like
Not related to your question, but your code has a unit error. CANCoders return position in rotations, not degrees. You want this:
Rotation2d.fromRotations(angleEncoder.getAbsolutePosition().getValue())
2 Likes
Was this a new change this year? I used this exact same code last year but now I’m needing to tweak things because of library changes.
Yes the CTRE API has massively changed since last year. It is very important for you to check 3rd party library documentation for breaking changes as a software developer.
2 Likes
You probably used CTRE’s Phoenix 5 vendor library last year, but you’re using Phoenix 6 this year.
Phoenix 6 was available last year, but you had to pay extra for Phoenix Pro to use it. This year it’s free-to-use with upgraded features if you buy Phoenix Pro.
Here’s the API migration guide with info about moving from 5 to 6.
1 Like