Rotation2D get rotations method

I’ve searched and can’t seem to find a method within robotpy Rotation2d to get the number of rotations. This exists in java as something like getRotations().

All languages have methods for getting degrees (degrees(), getDegrees()) but not rotations.

Is there a reason for this?

Is the solution to just use the degrees() method and divide by 360?

Thanks!

1 Like

Does it? Unless I’m blind I don’t see such a method: WPILibC++: frc::Rotation2d Class Reference

Woops. You’re absolutely correct that C++ does not have this method either. Which now answers why python doesn’t also. Sorry! I’ll edit my original post to reflect this.

Is just taking degrees() and dividing by 360 a way to get rotations under Rotation2D though? I appreciate your help.

We implement the java unit conversions in wpimath: wpimath.units Package — RobotPy API documentation

Looks like the java version converts rotations to radians and creates the Rotation2d from that. allwpilib/wpimath/src/main/java/edu/wpi/first/math/geometry/Rotation2d.java at 6cc7e52de74abce2b01de4f94cb58a3047a81f5c · wpilibsuite/allwpilib · GitHub

… not really sure why C++ doesn’t have it. I suppose we could add it if there was a reason to.

C++ can now implicitly construct a Rotation2d from any unit type with #6316: allwpilib/wpimath/src/main/native/include/frc/geometry/Rotation2d.h at main · wpilibsuite/allwpilib · GitHub. Rotation2d::Radians() and Rotation2d::Degrees() can both autoconvert to any angle unit the user wants.

Our team is working on creating a python version of this base talonfx swerve setup. It’s java and uses the getRotations() method.