11package frc .robot .subsystems .robotState ;
22
3- import java .util .Set ;
4-
5- import org .littletonrobotics .junction .Logger ;
6- import org .slf4j .LoggerFactory ;
7- import org .strykeforce .telemetry .TelemetryService ;
8- import org .strykeforce .telemetry .measurable .MeasurableSubsystem ;
9- import org .strykeforce .telemetry .measurable .Measure ;
10-
11- import edu .wpi .first .math .geometry .Pose2d ;
123import static edu .wpi .first .units .Units .Rotations ;
134import static edu .wpi .first .units .Units .RotationsPerSecond ;
5+
6+ import edu .wpi .first .math .geometry .Pose2d ;
147import edu .wpi .first .units .measure .Angle ;
158import edu .wpi .first .wpilibj .DriverStation .Alliance ;
169import edu .wpi .first .wpilibj .Timer ;
3730import frc .robot .subsystems .tagAlign .TagAlignSubsystem ;
3831import frc .robot .subsystems .tagAlign .TagAlignSubsystem .TagAlignStates ;
3932import frc .robot .subsystems .vision .VisionSubsystem ;
33+ import java .util .Set ;
4034import net .jafama .FastMath ;
35+ import org .littletonrobotics .junction .Logger ;
36+ import org .slf4j .LoggerFactory ;
37+ import org .strykeforce .telemetry .TelemetryService ;
38+ import org .strykeforce .telemetry .measurable .MeasurableSubsystem ;
39+ import org .strykeforce .telemetry .measurable .Measure ;
4140
4241public class RobotStateSubsystem extends MeasurableSubsystem {
4342 private org .slf4j .Logger logger = LoggerFactory .getLogger (this .getClass ());
@@ -174,7 +173,7 @@ public boolean hasAlgae() {
174173 }
175174
176175 public boolean safeMoveElevator () {
177- return !(coralSubsystem .getState () != CoralState .HAS_CORAL && funnelSubsystem .hasCoral () || algaeSubsystem . hasCoral () );
176+ return !(coralSubsystem .getState () != CoralState .HAS_CORAL && funnelSubsystem .hasCoral ());
178177 }
179178
180179 public void startupSequence () {
@@ -361,13 +360,12 @@ public void toAutonPrestage() {
361360 public void toFunnelLoad () {
362361
363362 if (scoringLevel == ScoringLevel .L1 ) {
364- setBiscuitTransferSlow (RobotConstants .kL1CoralLoadSetpoint , true );
365363 elevatorSubsystem .setPosition (RobotConstants .kElevatorL1LoadSetpoint );
366364 algaeSubsystem .intakeCoral ();
367365 funnelSubsystem .reverse ();
368366 coralSubsystem .stop ();
369367
370- setState (RobotStates .ALGAE_CORAL_LOAD , true );
368+ setState (RobotStates .TO_ALGAE_CORAL_LOAD , false );
371369 } else {
372370 setBiscuitTransfer (RobotConstants .kFunnelSetpoint , true );
373371 elevatorSubsystem .setPosition (RobotConstants .kElevatorFunnelSetpoint );
@@ -429,9 +427,7 @@ private void toReefAlign(boolean getAlgae, boolean drive) {
429427 if (drive ) {
430428 tagAlignSubsystem .start (
431429 allianceColor ,
432- scoreSide == ScoreSide .LEFT
433- || !hasCoral ()
434- || (wantAlgae && getAlgaeOnCycle ),
430+ scoreSide == ScoreSide .LEFT || !hasCoral () || (wantAlgae && getAlgaeOnCycle ),
435431 wantAlgae );
436432 setAutoPlacingLed (true );
437433 setState (RobotStates .REEF_ALIGN );
@@ -863,17 +859,27 @@ public void periodic() {
863859
864860 case PLACE_CORAL -> {
865861 if (!hasCoral () && scoringTimer .hasElapsed (RobotStateConstants .kCoralEjectTimer )) {
862+
866863 coralLoc = CoralLoc .NONE ;
867864 visionSubsystem .setYawUpdateCamera (-1 );
868865 setAutoPlacingLed (false );
869866 driveSubsystem .setIgnoreSticks (false );
870- toFunnelLoad ();
867+
868+ if (scoringLevel == ScoringLevel .L1
869+ && tagAlignSubsystem .getCurRadius (allianceColor )
870+ < RobotStateConstants .kL1CoralStowRadius ) {
871+ break ;
872+ }
873+ toStowSafe ();
871874 } else if (hasCoral ()) {
872875 coralLoc = CoralLoc .SCORING ;
873876 }
874877 }
875878
876879 case FUNNEL_LOAD -> {
880+ if (scoringLevel == ScoringLevel .L1 ) {
881+ toFunnelLoad ();
882+ }
877883 if (funnelSubsystem .hasCoral ()) {
878884 coralLoc = CoralLoc .FUNNEL ;
879885 }
@@ -885,8 +891,20 @@ public void periodic() {
885891 setState (RobotStates .LOADING_CORAL );
886892 }
887893 }
894+ case TO_ALGAE_CORAL_LOAD -> {
895+ if (scoringLevel != ScoringLevel .L1 ) {
896+ toFunnelLoad ();
897+ }
898+ if (elevatorSubsystem .isFinished ()) {
899+ setBiscuitTransfer (RobotConstants .kL1CoralLoadSetpoint , true );
900+ setState (RobotStates .ALGAE_CORAL_LOAD , true );
901+ }
902+ }
888903
889904 case ALGAE_CORAL_LOAD -> {
905+ if (scoringLevel != ScoringLevel .L1 ) {
906+ toFunnelLoad ();
907+ }
890908 if (algaeSubsystem .hasCoral ()) {
891909 coralLoc = CoralLoc .ALGAE ;
892910 toPrestage ();
@@ -927,9 +945,9 @@ public void periodic() {
927945 && scoringTimer .hasElapsed (RobotStateConstants .kAlgaeEjectTimer )) {
928946 Pose2d currentPose = driveSubsystem .getPoseMeters ();
929947 double distanceFromRelease =
930- FastMath .hypot (
931- currentPose .getX () - processorReleasePose .getX (),
932- currentPose .getY () - processorReleasePose .getY ());
948+ FastMath .sqrt (
949+ FastMath . pow ( currentPose .getX () - processorReleasePose .getX (), 2 )
950+ + FastMath . pow ( currentPose .getY () - processorReleasePose .getY (), 2 ));
933951 Logger .recordOutput ("RobotState/Processor Release Distance" , distanceFromRelease );
934952
935953 if (distanceFromRelease > RobotStateConstants .kProcessorStowRadius ) {
@@ -1020,6 +1038,7 @@ public enum RobotStates {
10201038 REMOVE_ALGAE ,
10211039 PLACE_CORAL ,
10221040 FUNNEL_LOAD ,
1041+ TO_ALGAE_CORAL_LOAD ,
10231042 ALGAE_CORAL_LOAD ,
10241043 LOADING_CORAL ,
10251044 PRESTAGE ,
0 commit comments