diff --git a/build.gradle b/build.gradle index 909d64a..3be07aa 100644 --- a/build.gradle +++ b/build.gradle @@ -1,6 +1,6 @@ plugins { id "java" - id "edu.wpi.first.GradleRIO" version "2025.2.1" + id "edu.wpi.first.GradleRIO" version "2025.3.2" id 'com.diffplug.spotless' version '6.20.0' } diff --git a/src/main/java/frc/robot/subsystems/ArmSubsystem.java b/src/main/java/frc/robot/subsystems/ArmSubsystem.java deleted file mode 100644 index 68cae9b..0000000 --- a/src/main/java/frc/robot/subsystems/ArmSubsystem.java +++ /dev/null @@ -1 +0,0 @@ -// Homework for Week 2 \ No newline at end of file diff --git a/src/main/java/frc/robot/subsystems/ArmSubsystem2.java b/src/main/java/frc/robot/subsystems/ArmSubsystem2.java new file mode 100644 index 0000000..1cfbb0f --- /dev/null +++ b/src/main/java/frc/robot/subsystems/ArmSubsystem2.java @@ -0,0 +1,53 @@ +// Homework for Week 2 +package frc.robot.subsystems; + +import com.ctre.phoenix6.configs.Slot0Configs; +import com.ctre.phoenix6.controls.PositionVoltage; +import com.ctre.phoenix6.hardware.TalonFX; +import edu.wpi.first.wpilibj2.command.SubsystemBase; + +public class ArmSubsystem2 extends SubsystemBase { + + private static final double kRotationsPerRadian = 10.0; // 5 rotations (0.5 radians) * 2 + + private final TalonFX motor; + private double targetPos; + private final PositionVoltage positionRequest; + + public ArmSubsystem2() { + motor = new TalonFX(1); + + Slot0Configs slot0 = new Slot0Configs(); + slot0.kP = 2.0; + slot0.kI = 0.0; + slot0.kD = 0.1; + motor.getConfigurator().apply(slot0); + + positionRequest = new PositionVoltage(0).withSlot(0); + } + + public void setPos(double rad) { + targetPos = rad; + motor.setControl(positionRequest.withPosition(rad * kRotationsPerRadian)); + } + + public double getPos() { + return motor.getRotorPosition().getValueAsDouble() / kRotationsPerRadian; + } + + public void zeroEncoder() { + motor.setPosition(0.0); + } + + public boolean isAtTargetPos(double tolRad) { + return Math.abs(getPos() - targetPos) <= tolRad; + } + + public void stop() { + setPos(getPos()); + } + + public double getTargetPos() { + return targetPos; + } +} diff --git a/src/main/java/frc/robot/subsystems/Week3_Notes.txt b/src/main/java/frc/robot/subsystems/Week3_Notes.txt new file mode 100644 index 0000000..c0c091b --- /dev/null +++ b/src/main/java/frc/robot/subsystems/Week3_Notes.txt @@ -0,0 +1,31 @@ +Command Scheduler: +Runs commands ever 20 ms +Contains a scheduler that registers the buttons pressed/commands needing to be ran, and runs them accordingly +Once a command is run, the scheduler ends the command +Runs periodic() method in each Subsystem + +Subsystems: +Abstraction for a collection of robot hardware that operates as one +Most methods private so methods can be replicated safely in other Subsystems +CommandScheduler never schedules a command that comes from the same subsystem--either interrupts current command or is ignored +Default commands-automatically scheduled when no other command is running +Take care of basic functionality + +Creating Subsystems: +extends SubsystemBase, holds common methods that are useful for each subsystem +one variable for each piece for hardware +motors and sensors defined at top--private and final +initialize hardware in constructor +if you need to access values, use getters & setters + +Periodic method: +Called every 20 ms +usually logs/getters for values +updates basic values/basic tasks +dont control motors + +Requirements and default commands: +Only one method per subsystem at any given time +periodic always runs, so if method that moves motors is ran and the robot is in a bad circumstance, it is bad +since motor commmands cant be called in periodic, they are called in "Default Command" +default command--gaurantees behavior if input \ No newline at end of file