Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
@@ -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'
}

Expand Down
1 change: 0 additions & 1 deletion src/main/java/frc/robot/subsystems/ArmSubsystem.java

This file was deleted.

53 changes: 53 additions & 0 deletions src/main/java/frc/robot/subsystems/ArmSubsystem2.java
Original file line number Diff line number Diff line change
@@ -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;
}
}
31 changes: 31 additions & 0 deletions src/main/java/frc/robot/subsystems/Week3_Notes.txt
Original file line number Diff line number Diff line change
@@ -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