Skip to content

Commit

Permalink
Moved scoring states for intake to separate classes
Browse files Browse the repository at this point in the history
  • Loading branch information
IanTapply22 committed Dec 19, 2023
1 parent d44bb89 commit f05e5fc
Show file tree
Hide file tree
Showing 12 changed files with 181 additions and 84 deletions.
94 changes: 10 additions & 84 deletions src/main/java/frc/robot/subsystems/intake/IntakeSubsystem.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import edu.wpi.first.wpilibj2.command.Commands;
import edu.wpi.first.wpilibj2.command.SubsystemBase;
import frc.robot.subsystems.intake.enums.IntakeGamepieces;
import frc.robot.subsystems.intake.enums.IntakeScoreType;
import frc.robot.subsystems.intake.states.ScoringState;

/**
* This an example implementation of our intake subsystem from 2023.
Expand Down Expand Up @@ -52,93 +52,19 @@ public Command stopIntakeCommand() {
/**
* Runs a command to score a gamepiece.
*
* @param type the type of the score you want to make
* @param scoringState the state to run the intake in
* @param expectedPiece the type of gamepiece to expect when scoring
* @return a command that scores a gamepiece
*/
public Command intakeScoreCommand(IntakeScoreType type, IntakeGamepieces expectedPiece) {
return run(() -> {
switch (type) {
case MID_CONE -> {
Commands.runOnce(() -> outtakeCommand(IntakeConstants.OuttakeSpeeds.MID_CONE), this)
.andThen(Commands.waitSeconds(0.5))
.andThen(stopIntakeCommand());
}

case MID_CONE_TIPPED -> {
Commands.runOnce(
() -> outtakeCommand(IntakeConstants.OuttakeSpeeds.MID_CONE_TIPPED), this)
.andThen(Commands.waitSeconds(0.5))
.andThen(stopIntakeCommand());
}

case MID_CUBE -> {
Commands.runOnce(() -> outtakeCommand(IntakeConstants.OuttakeSpeeds.MID_CUBE), this)
.andThen(Commands.waitSeconds(0.5))
.andThen(stopIntakeCommand());
}

case MID_CUBE_AUTO -> {
Commands.runOnce(
() -> outtakeCommand(IntakeConstants.OuttakeSpeeds.MID_CUBE_AUTO), this)
.andThen(Commands.waitSeconds(0.5))
.andThen(stopIntakeCommand());
}

case HIGH_CONE -> {
Commands.runOnce(() -> outtakeCommand(IntakeConstants.OuttakeSpeeds.HIGH_CONE), this)
.andThen(Commands.waitSeconds(0.5))
.andThen(stopIntakeCommand());
}

case HIGH_CONE_AUTO -> {
Commands.runOnce(
() -> outtakeCommand(IntakeConstants.OuttakeSpeeds.HIGH_CONE_AUTO), this)
.andThen(Commands.waitSeconds(0.5))
.andThen(stopIntakeCommand());
}
public Command intakeScoreCommand(ScoringState scoringState, IntakeGamepieces expectedGamepiece) {
SmartDashboard.putString("INTAKE STATE", scoringState.getStateName());

case HIGH_CUBE -> {
Commands.runOnce(() -> outtakeCommand(IntakeConstants.OuttakeSpeeds.HIGH_CUBE), this)
.andThen(Commands.waitSeconds(0.5))
.andThen(stopIntakeCommand());
}

case HIGH_CUBE_AUTO -> {
Commands.runOnce(
() -> outtakeCommand(IntakeConstants.OuttakeSpeeds.HIGH_CUBE_AUTO), this)
.andThen(Commands.waitSeconds(0.5))
.andThen(stopIntakeCommand());
}

case LOW -> {
if (expectedPiece.equals(IntakeGamepieces.CUBE)) {
Commands.runOnce(() -> outtakeCommand(IntakeConstants.OuttakeSpeeds.LOW_CUBE), this)
.andThen(Commands.waitSeconds(1))
.andThen(stopIntakeCommand());
} else {
Commands.runOnce(() -> outtakeCommand(IntakeConstants.OuttakeSpeeds.LOW_CONE), this)
.andThen(Commands.waitSeconds(1))
.andThen(stopIntakeCommand());
}
}

case LOW_AUTO -> {
if (expectedPiece.equals(IntakeGamepieces.CUBE)) {
Commands.runOnce(
() -> outtakeCommand(IntakeConstants.OuttakeSpeeds.LOW_CUBE_AUTO), this)
.andThen(Commands.waitSeconds(1))
.andThen(stopIntakeCommand());
} else {
Commands.runOnce(
() -> outtakeCommand(IntakeConstants.OuttakeSpeeds.LOW_CONE_AUTO), this)
.andThen(Commands.waitSeconds(1))
.andThen(stopIntakeCommand());
}
}
}
})
.andThen(stopIntakeCommand());
return run(() -> {
Commands.runOnce(
() -> outtakeCommand(scoringState.getOuttakeSpeed(expectedGamepiece)), this)
.andThen(Commands.waitSeconds(0.5))
.andThen(stopIntakeCommand());
}).andThen(stopIntakeCommand());
}

/**
Expand Down
61 changes: 61 additions & 0 deletions src/main/java/frc/robot/subsystems/intake/states/ScoringState.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package frc.robot.subsystems.intake.states;

import frc.robot.subsystems.intake.enums.IntakeGamepieces;

public abstract class ScoringState {
double outtakeSpeed;
double cubeOuttakeSpeed;
double coneOuttakeSpeed;

String stateName;

/**
* Creates a scoring state with the same outtake speed for cubes and cones
* @param outtakeSpeed The speed that should be used to outtake the gamepiece
* @param stateName The name of the scoring state that should be used for logging
*/
protected ScoringState(double outtakeSpeed, String stateName) {
this.outtakeSpeed = outtakeSpeed;
this.stateName = stateName;
}

/**
* Creates a scoring state with different outtake speeds for cubes and cones
* @param cubeOuttakeSpeed The speed that should be used to outtake the cube gamepiece
* @param coneOuttakeSpeed The speed that should be used to outtake the cone gamepiece
* @param stateName The name of the scoring state that should be used for logging
*/
protected ScoringState(double cubeOuttakeSpeed, double coneOuttakeSpeed, String stateName) {
this.cubeOuttakeSpeed = cubeOuttakeSpeed;
this.coneOuttakeSpeed = coneOuttakeSpeed;
this.stateName = stateName;
}

/**
* Gets the name of the scoring state
* @return The name of the scoring state
*/
public String getStateName() {
return this.stateName;
}

/**
* Gets the outtake speed for the scoring state depending on the gamepiece that is expected to be scored
* @return The outtake speed for the scoring state
*/
public double getOuttakeSpeed(IntakeGamepieces expectedGamepiece) {
if (expectedGamepiece == null) {
return this.outtakeSpeed;
}

// Based on the gamepiece that is expected to be scored, return the appropriate outtake speed
switch(expectedGamepiece) {
case CUBE:
return this.cubeOuttakeSpeed;
case CONE:
return this.coneOuttakeSpeed;
default:
return 0.0;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package frc.robot.subsystems.intake.states.scoring.cone;

import frc.robot.subsystems.intake.IntakeConstants;
import frc.robot.subsystems.intake.states.ScoringState;

public class HighCone extends ScoringState {

HighCone() {
super(IntakeConstants.OuttakeSpeeds.HIGH_CONE, "High Cone");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package frc.robot.subsystems.intake.states.scoring.cone;

import frc.robot.subsystems.intake.IntakeConstants;
import frc.robot.subsystems.intake.states.ScoringState;

public class HighConeAuto extends ScoringState {

HighConeAuto() {
super(IntakeConstants.OuttakeSpeeds.HIGH_CONE_AUTO, "High Cone Auto");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package frc.robot.subsystems.intake.states.scoring.cone;

import frc.robot.subsystems.intake.IntakeConstants;
import frc.robot.subsystems.intake.states.ScoringState;

public class MidCone extends ScoringState {

MidCone() {
super(IntakeConstants.OuttakeSpeeds.MID_CONE, "Mid Cone");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package frc.robot.subsystems.intake.states.scoring.cone;

import frc.robot.subsystems.intake.IntakeConstants;
import frc.robot.subsystems.intake.states.ScoringState;

public class MidConeTipped extends ScoringState {

MidConeTipped() {
super(IntakeConstants.OuttakeSpeeds.MID_CONE_TIPPED, "Mid Cone Tipped");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package frc.robot.subsystems.intake.states.scoring.cube;

import frc.robot.subsystems.intake.IntakeConstants;
import frc.robot.subsystems.intake.states.ScoringState;

public class HighCube extends ScoringState {

HighCube() {
super(IntakeConstants.OuttakeSpeeds.HIGH_CUBE, "High Cube");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package frc.robot.subsystems.intake.states.scoring.cube;

import frc.robot.subsystems.intake.IntakeConstants;
import frc.robot.subsystems.intake.states.ScoringState;

public class HighCubeAuto extends ScoringState {

HighCubeAuto() {
super(IntakeConstants.OuttakeSpeeds.HIGH_CUBE, "High Cube Auto");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package frc.robot.subsystems.intake.states.scoring.cube;

import frc.robot.subsystems.intake.IntakeConstants;
import frc.robot.subsystems.intake.states.ScoringState;

public class MidCube extends ScoringState {

MidCube() {
super(IntakeConstants.OuttakeSpeeds.MID_CUBE, "Mid Cube");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package frc.robot.subsystems.intake.states.scoring.cube;

import frc.robot.subsystems.intake.IntakeConstants;
import frc.robot.subsystems.intake.states.ScoringState;

public class MidCubeAuto extends ScoringState {

MidCubeAuto() {
super(IntakeConstants.OuttakeSpeeds.MID_CUBE, "Mid Cube Auto");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package frc.robot.subsystems.intake.states.scoring.level;

import frc.robot.subsystems.intake.IntakeConstants;
import frc.robot.subsystems.intake.states.ScoringState;

public class Low extends ScoringState {

Low() {
super(IntakeConstants.OuttakeSpeeds.LOW_CUBE, IntakeConstants.OuttakeSpeeds.LOW_CONE, "Low");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package frc.robot.subsystems.intake.states.scoring.level;

import frc.robot.subsystems.intake.IntakeConstants;
import frc.robot.subsystems.intake.states.ScoringState;

public class LowAuto extends ScoringState {

LowAuto() {
super(IntakeConstants.OuttakeSpeeds.LOW_CUBE_AUTO, IntakeConstants.OuttakeSpeeds.LOW_CONE_AUTO, "Low Auto");
}
}

0 comments on commit f05e5fc

Please sign in to comment.