2024-01-17 19:56:57 -05:00
|
|
|
// Copyright (c) FIRST and other WPILib contributors.
|
|
|
|
// Open Source Software; you can modify and/or share it under the terms of
|
|
|
|
// the WPILib BSD license file in the root directory of this project.
|
|
|
|
|
2024-01-18 18:44:55 -05:00
|
|
|
package frc.robot.subsystem;
|
2024-01-17 19:56:57 -05:00
|
|
|
|
2024-01-22 19:33:18 -05:00
|
|
|
import java.io.File;
|
|
|
|
import java.io.IOException;
|
|
|
|
import edu.wpi.first.math.geometry.Translation2d;
|
|
|
|
import edu.wpi.first.math.kinematics.SwerveModulePosition;
|
|
|
|
import edu.wpi.first.wpilibj.Filesystem;
|
2024-01-17 19:56:57 -05:00
|
|
|
import edu.wpi.first.wpilibj2.command.SubsystemBase;
|
2024-01-22 19:33:18 -05:00
|
|
|
import swervelib.SwerveDrive;
|
|
|
|
import swervelib.parser.SwerveParser;
|
2024-01-17 19:56:57 -05:00
|
|
|
|
|
|
|
public class Drive extends SubsystemBase {
|
|
|
|
/** Creates a new Drive. */
|
2024-01-22 19:39:19 -05:00
|
|
|
|
2024-01-22 19:33:18 -05:00
|
|
|
SwerveDrive swerveDrive;
|
2024-01-22 19:39:19 -05:00
|
|
|
|
2024-01-22 19:33:18 -05:00
|
|
|
File swerveJsonDirectory = new File(Filesystem.getDeployDirectory(),"swerve");
|
2024-01-22 19:39:19 -05:00
|
|
|
|
2024-01-22 19:33:18 -05:00
|
|
|
public void drive(double x, double y, double zRotation){
|
|
|
|
swerveDrive.drive(new Translation2d(x*2, y*2), zRotation, true, false);
|
|
|
|
}
|
|
|
|
|
|
|
|
public Drive() {
|
|
|
|
|
|
|
|
try {
|
|
|
|
this.swerveDrive = new SwerveParser(swerveJsonDirectory).createSwerveDrive(2);
|
|
|
|
} catch (IOException e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public SwerveModulePosition[] distance(){
|
|
|
|
return swerveDrive.getModulePositions();
|
|
|
|
}
|
|
|
|
public void reset(){
|
|
|
|
|
|
|
|
}
|
2024-01-17 19:56:57 -05:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public void periodic() {
|
|
|
|
// This method will be called once per scheduler run
|
|
|
|
}
|
|
|
|
}
|