-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Jade Turner <[email protected]>
- Loading branch information
1 parent
4af4a0c
commit 6db16c8
Showing
12 changed files
with
278 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
// Copyright (c) 2024 CurtinFRC | ||
// Open Source Software, you can modify it according to the terms | ||
// of the MIT License at the root of this project | ||
|
||
package frc.robot; | ||
|
||
import edu.wpi.first.wpilibj.DigitalInput; | ||
import edu.wpi.first.wpilibj2.command.Command; | ||
import edu.wpi.first.wpilibj2.command.Commands; | ||
import edu.wpi.first.wpilibj2.command.WaitCommand; | ||
import edu.wpi.first.wpilibj2.command.button.Trigger; | ||
import frc.robot.subsystems.index.Index; | ||
import frc.robot.subsystems.intake.Intake; | ||
import frc.robot.subsystems.shooter.Shooter; | ||
|
||
public class Superstructure { | ||
private static final int FRONT_BEAMBREAK_PORT = 5; | ||
private static final int BACK_BEAMBREAK_PORT = 6; | ||
|
||
// TODO should be logged akit style | ||
private final DigitalInput frontBeambreak = new DigitalInput(FRONT_BEAMBREAK_PORT); | ||
private final DigitalInput backBeamBreak = new DigitalInput(BACK_BEAMBREAK_PORT); | ||
|
||
private final Shooter m_shooter; | ||
private final Intake m_intake; | ||
private final Index m_index; | ||
|
||
public final Trigger m_hasNote = new Trigger(backBeamBreak::get); | ||
public final Trigger m_intaking = new Trigger(frontBeambreak::get).negate(); | ||
|
||
public Superstructure(Shooter shooter, Intake intake, Index index) { | ||
m_shooter = shooter; | ||
m_intake = intake; | ||
m_index = index; | ||
|
||
m_intaking.onTrue( | ||
Commands.parallel( | ||
m_intake.setVoltage(5).until(m_hasNote).andThen(m_intake.stop()), | ||
m_index | ||
.setVoltage(-3.5) | ||
.until(m_hasNote) | ||
.andThen(new WaitCommand(0.5)) | ||
.andThen(m_index.setVoltage(2)) | ||
.until(m_hasNote) | ||
.andThen(m_index.stop()))); | ||
} | ||
|
||
public Command intake() { | ||
return m_intake.setVoltage(10).until(m_intaking); | ||
} | ||
|
||
public Command shoot() { | ||
return m_shooter | ||
.spinup(250) | ||
.withTimeout(1.5) | ||
.andThen(Commands.parallel(m_shooter.maintain(), m_index.setVoltage(8))); | ||
} | ||
|
||
public Command stop() { | ||
return Commands.parallel(m_shooter.stop(), m_intake.stop(), m_index.stop()); | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package frc.robot.subsystems.index; | ||
|
||
import edu.wpi.first.wpilibj2.command.Command; | ||
import edu.wpi.first.wpilibj2.command.SubsystemBase; | ||
import org.littletonrobotics.junction.Logger; | ||
|
||
public class Index extends SubsystemBase { | ||
private final IndexIO io; | ||
private final IndexIOInputsAutoLogged inputs; | ||
|
||
public Index(IndexIO io) { | ||
this.io = io; | ||
inputs = new IndexIOInputsAutoLogged(); | ||
} | ||
|
||
@Override | ||
public void periodic() { | ||
io.updateInputs(inputs); | ||
Logger.processInputs("Index", inputs); | ||
} | ||
|
||
public Command stop() { | ||
return runOnce(() -> io.stop()); | ||
} | ||
|
||
public Command setVoltage(double volts) { | ||
return run(() -> io.setVoltage(volts)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package frc.robot.subsystems.index; | ||
|
||
import org.littletonrobotics.junction.AutoLog; | ||
|
||
public interface IndexIO { | ||
@AutoLog | ||
public static class IndexIOInputs { | ||
public double position; | ||
public double velocity; | ||
public double appliedVolts; | ||
public double currentAmps; | ||
} | ||
|
||
/** Updates the set of loggable inputs. */ | ||
public default void updateInputs(IndexIOInputs inputs) {} | ||
|
||
/** Run open loop at the specified voltage. */ | ||
public default void setVoltage(double volts) {} | ||
|
||
/** Stop in open loop. */ | ||
public default void stop() {} | ||
} |
29 changes: 29 additions & 0 deletions
29
src/main/java/frc/robot/subsystems/index/IndexIOSparkMax.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package frc.robot.subsystems.index; | ||
|
||
import com.revrobotics.spark.SparkLowLevel.MotorType; | ||
import com.revrobotics.spark.SparkMax; | ||
import edu.wpi.first.wpilibj.RobotController; | ||
|
||
public class IndexIOSparkMax implements IndexIO { | ||
private static final int PORT = 21; | ||
|
||
SparkMax spark = new SparkMax(PORT, MotorType.kBrushless); | ||
|
||
@Override | ||
public void updateInputs(IndexIOInputs inputs) { | ||
inputs.appliedVolts = spark.getAppliedOutput() * RobotController.getBatteryVoltage(); | ||
inputs.currentAmps = spark.getOutputCurrent(); | ||
inputs.position = spark.getEncoder().getPosition(); | ||
inputs.velocity = spark.getEncoder().getVelocity(); | ||
} | ||
|
||
@Override | ||
public void setVoltage(double volts) { | ||
spark.setVoltage(volts); | ||
} | ||
|
||
@Override | ||
public void stop() { | ||
spark.stopMotor(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package frc.robot.subsystems.intake; | ||
|
||
import edu.wpi.first.wpilibj2.command.Command; | ||
import edu.wpi.first.wpilibj2.command.SubsystemBase; | ||
import org.littletonrobotics.junction.Logger; | ||
|
||
public class Intake extends SubsystemBase { | ||
private final IntakeIO io; | ||
private final IntakeIOInputsAutoLogged inputs; | ||
|
||
public Intake(IntakeIO io) { | ||
this.io = io; | ||
inputs = new IntakeIOInputsAutoLogged(); | ||
} | ||
|
||
@Override | ||
public void periodic() { | ||
io.updateInputs(inputs); | ||
Logger.processInputs("Intake", inputs); | ||
} | ||
|
||
public Command stop() { | ||
return runOnce(() -> io.stop()); | ||
} | ||
|
||
public Command setVoltage(double volts) { | ||
return run(() -> io.setVoltage(volts)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package frc.robot.subsystems.intake; | ||
|
||
import org.littletonrobotics.junction.AutoLog; | ||
|
||
public interface IntakeIO { | ||
@AutoLog | ||
public static class IntakeIOInputs { | ||
public double position; | ||
public double velocity; | ||
public double appliedVolts; | ||
public double currentAmps; | ||
} | ||
|
||
/** Updates the set of loggable inputs. */ | ||
public default void updateInputs(IntakeIOInputs inputs) {} | ||
|
||
/** Run open loop at the specified voltage. */ | ||
public default void setVoltage(double volts) {} | ||
|
||
/** Stop in open loop. */ | ||
public default void stop() {} | ||
} |
29 changes: 29 additions & 0 deletions
29
src/main/java/frc/robot/subsystems/intake/IntakeIOSparkMax.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package frc.robot.subsystems.intake; | ||
|
||
import com.revrobotics.spark.SparkLowLevel.MotorType; | ||
import com.revrobotics.spark.SparkMax; | ||
import edu.wpi.first.wpilibj.RobotController; | ||
|
||
public class IntakeIOSparkMax implements IntakeIO { | ||
private static final int PORT = 32; | ||
|
||
SparkMax spark = new SparkMax(PORT, MotorType.kBrushless); | ||
|
||
@Override | ||
public void updateInputs(IntakeIOInputs inputs) { | ||
inputs.appliedVolts = spark.getAppliedOutput() * RobotController.getBatteryVoltage(); | ||
inputs.currentAmps = spark.getOutputCurrent(); | ||
inputs.position = spark.getEncoder().getPosition(); | ||
inputs.velocity = spark.getEncoder().getVelocity(); | ||
} | ||
|
||
@Override | ||
public void setVoltage(double volts) { | ||
spark.setVoltage(volts); | ||
} | ||
|
||
@Override | ||
public void stop() { | ||
spark.stopMotor(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters