Set angle for each specific Swerve Module

How can I create a method in Drive.java or SwerveModule.java which sets an individual swerve module to an angle?

1 Like

I mainly want to do this so I can have each of the swerve wheels in a ‘X’ shape so the bot does not get pushed over. I made something like this yesterday but I’m not entirely sure if it’ll work: X mode for brake · FRC5190/2023OffseasonSwerve@eac7dc0 · GitHub

1 Like

our team set up a command for x pattern, our code looks like this,

package frc.robot.commands.drive;

import edu.wpi.first.math.geometry.Rotation2d;
import edu.wpi.first.math.kinematics.SwerveModuleState;
import edu.wpi.first.wpilibj2.command.CommandBase;
import frc.robot.subsystems.drive.SwerveSubsystem;

public class XPattern extends CommandBase {
public XPattern() {
addRequirements(SwerveSubsystem.getInstance());
}

@Override
public void execute() {
    SwerveSubsystem.getInstance()
            .setModuleStatesNoOptimize(
                    new SwerveModuleState(0, Rotation2d.fromDegrees(45)),
                    new SwerveModuleState(0, Rotation2d.fromDegrees(-45)),
                    new SwerveModuleState(0, Rotation2d.fromDegrees(-45)),
                    new SwerveModuleState(0, Rotation2d.fromDegrees(45)));
}

@Override
public boolean isFinished() {
    return false;
}

}

Y’all might have initialized your swerve modules differently than us but this might help

1 Like

Nvm

There was a thread about this about a month ago with some good advice.

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.