toChassisSpeeds() outputs weird data

When using toChassisSpeeds and providing swerve module states (which are correct and in the correct order) the XY chassis speed output is good, but the omegaRadiansPerSecound is weird. very very small (.008) and jumps a lot even while spinning at a constant speed.

Did someone encunted this? what could be the problem?

It would help a lot to see your code, but my first thought would be to look for a unit conversion problem, perhaps in the module locations.

2 Likes

We need more information. like @bovlb said code will help. Also what kind of driving are you doing and what do you expect the omegaRadiansPerSecound to be? If you are driving straight I would expect it to be low (almost 0) .

image

I think my units are correct, XY speeds are good, and when viewing the provided swerve states in advantage scope they look good (Also checked order which is good)

I agree. If you have correct XY speeds but incorrect omega speeds, it should be the module translations in your kinematics. Can you share the complete code?

Sure,

Dont think its the locations,

public static final Translation2d frontLeftLocation = new Translation2d(
-WIDTH / 2,
LENGTH / 2);

    public static final Translation2d frontRightLocation = new Translation2d(
            WIDTH / 2,
            LENGTH / 2);

    public static final Translation2d rearLeftLocation = new Translation2d(
            -WIDTH / 2,
            -LENGTH / 2);

    public static final Translation2d rearRightLocation = new Translation2d(
            WIDTH / 2,
            -LENGTH / 2);

Seems to be right if i remember correctly

I think this is it. In WPILib’s coordinate system, the x-axis of your chassis points toward the front, and the y-axis points toward the left.

The correct module translations is:

 public static final Translation2d frontLeftLocation = new Translation2d(
            LENGTH / 2,
            WIDTH / 2);

 public static final Translation2d frontRightLocation = new Translation2d(
            LENGTH / 2,
            -WIDTH / 2);

    public static final Translation2d rearLeftLocation = new Translation2d(
            -LENGTH / 2,
            WIDTH / 2);

    public static final Translation2d rearRightLocation = new Translation2d(
            -LENGTH / 2,
            -WIDTH / 2);
1 Like

The method toSwerveStates() works well, so I am not really sure that this is the issue, But I will definitely try. Thanks!