Skip to content

Commit

Permalink
Shooter code (Elsa wrote)
Browse files Browse the repository at this point in the history
  • Loading branch information
ColinH0 committed Sep 12, 2024
1 parent 97cfb9e commit 17ce243
Show file tree
Hide file tree
Showing 4 changed files with 91 additions and 0 deletions.
26 changes: 26 additions & 0 deletions src/main/java/frc/robot/subsystems/shooter/Shooter.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package frc.robot.subsystems.shooter;

import edu.wpi.first.wpilibj2.command.SubsystemBase;

public class Shooter extends SubsystemBase {
private ShooterIO io;
private ShooterIOInputsAutoLogged inputs = new ShooterIOInputsAutoLogged();

private static Shooter instance;

public static Shooter getInstance() {
return instance;
}

public static Shooter initialize(ShooterIO io) {
if (instance == null) {
instance = new Shooter(io);
}
return instance;
}

private Shooter(ShooterIO shooterIO) {
io = shooterIO;
io.updateInputs(inputs);
}
}
20 changes: 20 additions & 0 deletions src/main/java/frc/robot/subsystems/shooter/ShooterIO.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package frc.robot.subsystems.shooter;

import org.littletonrobotics.junction.AutoLog;

import frc.robot.subsystems.shooter.ShooterIO.ShooterIOInputs;

public interface ShooterIO {
@AutoLog
public static class ShooterIOInputs{
public double leftMotorVelocity = 0.0;
public double rightMotorVelocity = 0.0;
}

public default void spinForwards() {}

public default void spinBackwards() {}

public default void updateInputs(ShooterIOInputs inputs) {}

}
42 changes: 42 additions & 0 deletions src/main/java/frc/robot/subsystems/shooter/ShooterIOReal.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package frc.robot.subsystems.shooter;

import com.revrobotics.CANSparkFlex;
import com.revrobotics.CANSparkLowLevel.MotorType;
import com.revrobotics.RelativeEncoder;

public class ShooterIOReal implements ShooterIO {
private CANSparkFlex leftShooterMotor = new CANSparkFlex(0, MotorType.kBrushless); // Can IDs not accurate
private CANSparkFlex rightShooterMotor = new CANSparkFlex(1, MotorType.kBrushless); // Can IDs not accurate
private RelativeEncoder leftShooterEncoder = leftShooterMotor.getEncoder();
private RelativeEncoder rightShooterEncoder = rightShooterMotor.getEncoder();


public ShooterIOReal() {
rightShooterMotor.follow(leftShooterMotor, true);

rightShooterMotor.burnFlash();
leftShooterMotor.burnFlash();
}

public void spinForwards() {
leftShooterMotor.set(1.0);
}

public void spinBackwards() {
leftShooterMotor.set(-1.0);
}

public double getLeftvelocity() {
return leftShooterEncoder.getVelocity();
}

public double getRightvelocity() {
return rightShooterEncoder.getVelocity();
}

@Override
public void updateInputs(ShooterIOInputs inputs) {
inputs.leftMotorVelocity = getLeftvelocity();
inputs.rightMotorVelocity = getRightvelocity();
}
}
3 changes: 3 additions & 0 deletions src/main/java/frc/robot/subsystems/shooter/ShooterIOSim.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package frc.robot.subsystems.shooter;

public class ShooterIOSim {}

0 comments on commit 17ce243

Please sign in to comment.