diff --git a/build.gradle b/build.gradle index 8fa63ce..f3695ba 100644 --- a/build.gradle +++ b/build.gradle @@ -1,6 +1,7 @@ plugins { id "java" - id "edu.wpi.first.GradleRIO" version "2024.2.1" + id "edu.wpi.first.GradleRIO" version "2024.1.1" + } java { @@ -49,7 +50,31 @@ def includeDesktopSupport = false // Defining my dependencies. In this case, WPILib (+ friends), and vendor libraries. // Also defines JUnit 5. + +repositories { + maven { + url = uri("https://maven.pkg.github.com/Mechanical-Advantage/AdvantageKit") + credentials { + username = "Mechanical-Advantage-Bot" + password = "\u0067\u0068\u0070\u005f\u006e\u0056\u0051\u006a\u0055\u004f\u004c\u0061\u0079\u0066\u006e\u0078\u006e\u0037\u0051\u0049\u0054\u0042\u0032\u004c\u004a\u006d\u0055\u0070\u0073\u0031\u006d\u0037\u004c\u005a\u0030\u0076\u0062\u0070\u0063\u0051" + } + } + mavenLocal() +} + +configurations.all { + exclude group: "edu.wpi.first.wpilibj" +} + +task(checkAkitInstall, dependsOn: "classes", type: JavaExec) { + mainClass = "org.littletonrobotics.junction.CheckInstall" + classpath = sourceSets.main.runtimeClasspath +} +compileJava.finalizedBy checkAkitInstall + dependencies { + def akitJson = new groovy.json.JsonSlurper().parseText(new File(projectDir.getAbsolutePath() + "/vendordeps/AdvantageKit.json").text) + annotationProcessor "org.littletonrobotics.akit.junction:junction-autolog:$akitJson.version" implementation wpi.java.deps.wpilib() implementation wpi.java.vendor.java() @@ -67,13 +92,8 @@ dependencies { nativeRelease wpi.java.vendor.jniRelease(wpi.platforms.desktop) simulationRelease wpi.sim.enableRelease() - testImplementation 'org.junit.jupiter:junit-jupiter:5.10.1' - // testRuntimeOnly 'org.junit.platform:junit-platform-launcher' -} + -test { - useJUnitPlatform() - systemProperty 'junit.jupiter.extensions.autodetection.enabled', 'true' } // Simulation configuration (e.g. environment variables). @@ -99,3 +119,13 @@ wpi.java.configureTestTasks(test) tasks.withType(JavaCompile) { options.compilerArgs.add '-XDstringConcat=inline' } + +javadoc { + configure(options) { + options.addBooleanOption("-allow-script-in-comments",true) + options.addStringOption("link", "https://github.wpilib.org/allwpilib/docs/release/java/") + options.header = "" + } +} diff --git a/src/main/java/frc/lib/util/swerve/SwerveModuleIO.java b/src/main/java/frc/lib/util/swerve/SwerveModuleIO.java new file mode 100644 index 0000000..2c18612 --- /dev/null +++ b/src/main/java/frc/lib/util/swerve/SwerveModuleIO.java @@ -0,0 +1,50 @@ +package frc.lib.util.swerve; + +import org.littletonrobotics.junction.AutoLog; +import com.ctre.phoenix6.controls.ControlRequest; + + +public interface SwerveModuleIO { + + @AutoLog + public static class SwerveModuleInputs { + public double angleEncoderValue; + public double driveMotorSelectedPosition; + public double driveMotorSelectedSensorVelocity; + public double angleMotorSelectedPosition; + public double driveMotorTemperature; + public double angleMotorTemperature; + + } + + public default void updateInputs(SwerveModuleInputs inputs) { + int i = 0; + } + + public default void setDriveMotor(ControlRequest request) {}; + + public default void setAngleMotor(ControlRequest request) {}; + + public default void setAngleSelectedSensorPosition(double angle) {}; + + public default void setAngleMotorPosition(ControlRequest request) {}; + + + public default double getEncoderPosition() { + return 0.0; + } + + public default double getVelocityOfMotor() { + return 0.0; + } + + public default double getAngleMotor() { + return 0.0; + } + + public default double getPositionDriveMotor() { + return 0.0; + } + + +} diff --git a/src/main/java/frc/lib/util/swerve/SwerveModuleReal.java b/src/main/java/frc/lib/util/swerve/SwerveModuleReal.java new file mode 100644 index 0000000..bd860a8 --- /dev/null +++ b/src/main/java/frc/lib/util/swerve/SwerveModuleReal.java @@ -0,0 +1,15 @@ +package frc.lib.util.swerve; + +import com.ctre.phoenix6.controls.ControlRequest; + +public class SwerveModuleReal implements SwerveModuleIO { + + + + @Override + public void setAngleMotor(ControlRequest request) { + // TODO Auto-generated method stub + SwerveModuleIO.super.setAngleMotor(request); + } + +} diff --git a/src/main/java/frc/robot/Constants.java b/src/main/java/frc/robot/Constants.java index f9ac7fb..6db87ec 100644 --- a/src/main/java/frc/robot/Constants.java +++ b/src/main/java/frc/robot/Constants.java @@ -1,5 +1,6 @@ package frc.robot; +import com.ctre.phoenix6.mechanisms.swerve.SwerveModuleConstants; import com.ctre.phoenix6.signals.InvertedValue; import com.ctre.phoenix6.signals.NeutralModeValue; import com.ctre.phoenix6.signals.SensorDirectionValue; @@ -108,10 +109,12 @@ public static final class Swerve { * Front Left Module - Module 0 */ public static final class Mod0 { - public static final int driveMotorID = 10; + public static final int driveMotorID = 50; public static final int angleMotorID = 8; - public static final int canCoderID = 10; + public static final int canCoderID = 3; public static final Rotation2d angleOffset = Rotation2d.fromDegrees(115.400390625); + public static final SwerveModuleConstants constants = + new SwerveModuleConstants(driveMotorID, angleMotorID, canCoderID, angleOffset); } /** diff --git a/src/main/java/frc/robot/RobotContainer.java b/src/main/java/frc/robot/RobotContainer.java index 50617d4..3cd7d06 100644 --- a/src/main/java/frc/robot/RobotContainer.java +++ b/src/main/java/frc/robot/RobotContainer.java @@ -18,6 +18,8 @@ import edu.wpi.first.wpilibj2.command.button.CommandXboxController; import frc.robot.commands.TeleopSwerve; import frc.robot.subsystems.Swerve; +import frc.robot.subsystems.SwerveIO; +import frc.robot.subsystems.SwerveReal; /** * This class is where the bulk of the robot should be declared. Since Command-based is a @@ -31,11 +33,24 @@ public class RobotContainer { private final SendableChooser autoChooser = new SendableChooser<>(); + SwerveIO swerveIO;; + + /* Subsystems */ private final Swerve s_Swerve = new Swerve(); + + /** The container for the robot. Contains subsystems, OI devices, and commands. */ - public RobotContainer() { + public RobotContainer(boolean isReal) { + + if (isReal) { + // Instantiate IO Implements + s_Swerve = new Swerve(new SwerveReal()); + } else { + s_Swerve = new Swerve(new SwerveIO() {}); + } + s_Swerve.setDefaultCommand(new TeleopSwerve(s_Swerve, driver, Constants.Swerve.isFieldRelative, Constants.Swerve.isOpenLoop)); // autoChooser.addOption(resnickAuto, new ResnickAuto(s_Swerve)); @@ -44,6 +59,7 @@ public RobotContainer() { configureButtonBindings(); } + public void periodic() { } diff --git a/src/main/java/frc/robot/subsystems/Swerve.java b/src/main/java/frc/robot/subsystems/Swerve.java index bb13942..6be3cd7 100644 --- a/src/main/java/frc/robot/subsystems/Swerve.java +++ b/src/main/java/frc/robot/subsystems/Swerve.java @@ -3,6 +3,7 @@ import java.util.Optional; import com.kauailabs.navx.frc.AHRS; import com.pathplanner.lib.auto.AutoBuilder; +import edu.wpi.first.math.estimator.SwerveDrivePoseEstimator; import edu.wpi.first.math.geometry.Pose2d; import edu.wpi.first.math.geometry.Rotation2d; import edu.wpi.first.math.geometry.Translation2d; @@ -27,6 +28,22 @@ public class Swerve extends SubsystemBase { public AHRS gyro = new AHRS(Constants.Swerve.navXID); private double fieldOffset = gyro.getYaw(); + private SwerveIO io; + private SwerveInputsAutoLogged inputs = new SwerveInputsAutoLogged(); + + public Swerve(SwerveIO io) { + this.io = io; + SmartDashboard.putData("Field Pos", field); + + for (int i = 0; i < 4; i++) { + swerveMods[i] = io.createSwerveModule(i, Constants.Swerve.swerveConstants[i]); + } + io.updateInputs(inputs); + + swerveOdometry = new SwerveDrivePoseEstimator(Constants.Swerve.swerveKinematics, getYaw(), + getPositions(), new Pose2d()); + } + /** * Swerve Subsystem */ diff --git a/src/main/java/frc/robot/subsystems/SwerveIO.java b/src/main/java/frc/robot/subsystems/SwerveIO.java new file mode 100644 index 0000000..115245b --- /dev/null +++ b/src/main/java/frc/robot/subsystems/SwerveIO.java @@ -0,0 +1,27 @@ +package frc.robot.subsystems; + +import org.littletonrobotics.junction.AutoLog; +import frc.lib.util.swerve.SwerveModule; +import frc.lib.util.swerve.SwerveModuleIO; + + + +public class SwerveIO { + + @AutoLog + public static class SwerveInputs { + public float yaw; + public float roll; + } + + public default void updateInputs(SwerveInputs inputs) {} + + public default + + SwerveModule SwerveModule + + frc.robot.subsystems.SwerveModule createSwerveModule(int moduleNumber, + frc.lib.util.swerve.SwerveModuleConstants constants) { + return new SwerveModule(moduleNumber, constants, new SwerveModuleIO() {}); + } +} diff --git a/src/main/java/frc/robot/subsystems/SwerveModule.java b/src/main/java/frc/robot/subsystems/SwerveModule.java new file mode 100644 index 0000000..d3d40ae --- /dev/null +++ b/src/main/java/frc/robot/subsystems/SwerveModule.java @@ -0,0 +1,5 @@ +package frc.robot.subsystems; + +public class SwerveModule { + +} diff --git a/src/main/java/frc/robot/subsystems/SwerveReal.java b/src/main/java/frc/robot/subsystems/SwerveReal.java new file mode 100644 index 0000000..816892a --- /dev/null +++ b/src/main/java/frc/robot/subsystems/SwerveReal.java @@ -0,0 +1,28 @@ +package frc.robot.subsystems; + +import com.ctre.phoenix6.mechanisms.swerve.SwerveModuleConstants; +import com.kauailabs.navx.frc.AHRS; +import frc.lib.util.swerve.SwerveModuleReal; +import frc.robot.Constants; +import frc.robot.subsystems.SwerveIO.SwerveInputs; + +public class SwerveReal implements SwerveOI { + + private AHRS gyro = new AHRS(Constants.Swerve.navXID); + + // Real Swereve Initializer + + public SwerveReal() {} + + @Override + + public void updateInputs(SwerveInputs inputs) { + inputs.yaw = gyro.getYaw(); + } + + @Override + public SwerveModule creatSwerveModule(int moduleNumber, SwerveModuleConstants constants) { + return new SwerveModule(moduleNumber, constants, new SwerveModuleReal(constants)); + } + +} diff --git a/vendordeps/AdvantageKit.json b/vendordeps/AdvantageKit.json new file mode 100644 index 0000000..bdbd93d --- /dev/null +++ b/vendordeps/AdvantageKit.json @@ -0,0 +1,42 @@ +{ + "fileName": "AdvantageKit.json", + "name": "AdvantageKit", + "version": "3.0.2", + "uuid": "d820cc26-74e3-11ec-90d6-0242ac120003", + "frcYear": "2024", + "mavenUrls": [], + "jsonUrl": "https://github.com/Mechanical-Advantage/AdvantageKit/releases/latest/download/AdvantageKit.json", + "javaDependencies": [ + { + "groupId": "org.littletonrobotics.akit.junction", + "artifactId": "wpilib-shim", + "version": "3.0.2" + }, + { + "groupId": "org.littletonrobotics.akit.junction", + "artifactId": "junction-core", + "version": "3.0.2" + }, + { + "groupId": "org.littletonrobotics.akit.conduit", + "artifactId": "conduit-api", + "version": "3.0.2" + } + ], + "jniDependencies": [ + { + "groupId": "org.littletonrobotics.akit.conduit", + "artifactId": "conduit-wpilibio", + "version": "3.0.2", + "skipInvalidPlatforms": false, + "isJar": false, + "validPlatforms": [ + "linuxathena", + "windowsx86-64", + "linuxx86-64", + "osxuniversal" + ] + } + ], + "cppDependencies": [] +} \ No newline at end of file