The Problem
Our team has been trying to get swerve working this year and we’ve run into a slight issue. That being that, when simulating the swerve module states with an Xbox controller, rotational inputs make the modules turn like so: (All speeds in all screenshots are positive and all angles are unoptimized.)
Translating works exactly as expected. For example, moving forward and to the left yields this:
However, while not touching the translation input and only moving the rotational input fully to the left, I get this:
Each angle is opposite of itself if I push the rotational input to the right.
Translating and rotating looks like this: (Forward and rotating left)
The Code
We’ve defined the kinematics object like so:
public static final SwerveDriveKinematics kDriveKinematics = new SwerveDriveKinematics(
new Translation2d(kWheelBase / 2, kTrackWidth / 2), // Front left
new Translation2d(kWheelBase / 2, -kTrackWidth / 2), // Front right
new Translation2d(-kWheelBase / 2, kTrackWidth / 2), // Rear left
new Translation2d(-kWheelBase / 2, -kTrackWidth / 2)); // Rear right
And later in our drive()
method, we get the module states:
ChassisSpeeds chassisSpeeds = new ChassisSpeeds(xSpeed, ySpeed, rotSpeed);
SwerveModuleState[] states = DriveConstants.kDriveKinematics.toSwerveModuleStates(chassisSpeeds);
m_frontLeftModule.setModuleState(states[0]);
m_frontRightModule.setModuleState(states[1]);
m_rearLeftModule.setModuleState(states[2]);
m_rearRightModule.setModuleState(states[3]);
None of this has been run on an actual robot yet, only simulations. I’ve seen that a cause could be that the order of the modules was not the same across the code, but I believe this is all in the same order, that being: front left, front right, rear left, rear right.
Please inform me if there is any more information I can provide.