I was looking at the swerve drive kinematics documentation on WPILib (Swerve Drive Kinematics — FIRST Robotics Competition documentation), and it was unclear whether the SwerveModuleState class used [0, 360] or [-180, +180] for the module angle.
It takes a Rotation2d, which can take any angle with Rotation2d.fromDegrees();
0 degrees is facing forward.
I’m aware that it’s a Rotation2d object. Let me rephrase.
If I’m at 0 degrees, and I turn the wheel left and right by 1 degree, should that correspond to -1 and +1 degree?
Or should it be +359 and +1 degree?
Rotation2d.fromDegrees(-1) == Rotation2d.fromDegrees(359). They are the same thing.
It shouldn’t matter since whatever you’re giving the SwerveModuleState
to should be able to handle angles properly, and getSin
and getCos
will return the same.
Just out of personal curiosity, I ran a test to see what SwerveDriveKinematics
returns and it looks like it bounds them within (-180,180).
Semantically,
Rotation2d.fromDegrees(-1).equals(Rotation2d.fromDegrees(359))
But your point holds.
yes I did actually check this, the equals method just checks that the sin and cos are within a tolerance of each other.
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.