How to drive SDS Swerve autonomously (With library)

I’m currently at a stage with the robot where I’m able to do autonomous, although a big issue is that so far I am unable to drive the swerve drive autonomously due to the way the values are passed. From what I can see it’s passed through in the following function:
m_driving.setDefaultCommand(new DefaultDriveCommand(
m_driving,
() → modifyAxis(driveStick.getRawAxis(1)) * m_driving.MAX_VELOCITY_METERS_PER_SECOND,
() → modifyAxis(driveStick.getRawAxis(0)) * m_driving.MAX_VELOCITY_METERS_PER_SECOND,
() → modifyAxis(driveStick.getRawAxis(4)) * m_driving.MAX_ANGULAR_VELOCITY_RADIANS_PER_SECOND
));

What I’ve done is assumed the way to drive the robot is to just pass any double -1 to 1 to those values and it would work, but I think I’m assuming wrong.

// If less then 2 seconds
        if (movementTimer.get() < 2.0) {
            this.m_translationXSupplier = 0;
            this.m_translationYSupplier = 0;
            this.m_rotationSupplier = 0.5;
        }
        else {
            this.m_translationXSupplier = 0;
            this.m_translationYSupplier = 0;
            this.m_rotationSupplier = 0;
        }

This does not work, any ideas?

Also code is at: https://github.com/R0NAM1/FRC_2022_Rapid_React

I think you want your auto command to look more like:

public class DefaultDriveCommand extends TimedCommand {
    private final drivingSystem m_drivetrainSubsystem;

    public Drivebackwards(drivingSystem drivetrainSubsystem) {
        super(2, drivetrainSubsystem); // Run for 2 seconds
        this.m_drivetrainSubsystem = drivetrainSubsystem;
    }

    @Override
    public void execute() {
        m_drivetrainSubsystem.drive(
            ChassisSpeeds.fromFieldRelativeSpeeds(0, 0, 0.5
                m_drivetrainSubsystem.getGyroscopeRotation()
            )
        );
    }

    @Override
    public void end(boolean interrupted) {
        m_drivetrainSubsystem.drive(new ChassisSpeeds(0.0, 0.0, 0.0));
    }
}

Some questions:

  1. What is ‘super’?
  2. How did you figure out that ChassisSpeeds.fromFieldRelativeSpeeds drives the swerve drive? The biggest thing I’ve encountered is outdated/lack of infomation so I’m trying to figure out more about how others are figuring this stuff out.

super() is the super-class constructor. You’ll see that I changed your class from CommandBase to TimedCommand. This means that the command will run for a specific time, so the timer (and the requirements) are managed for you.

m_drivetrainSubsystem.drive sets the speeds on the robot, but ChassisSpeeds. fromFieldRelativeSpeeds converts your values into the right format.

m_drivetrainSubsystem.drive sets the speeds on the robot, but ChassisSpeeds. fromFieldRelativeSpeeds converts your values into the right format.

I see, but the weird thing about the SDS Swerve Drive Library is that it does not follow the WPI convention of doing it (from what I can see of course, if your using the SDS library and this does work then great! I’ll implement it).

I should perhaps explain that I have never used the SDS Swerve Drive Library. I’m just trying to make your autonomous command match what your default command does, within the WPILIB framework.

Ah alright, I’ll mess with it when I can, but the structure of the autonomous command you gave me does help a lot, thank you!

1 Like

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