|
| 1 | +package org.firstinspires.ftc.twenty403.command; |
| 2 | + |
| 3 | +import android.util.Pair; |
| 4 | +import com.technototes.library.command.ChoiceCommand; |
| 5 | +import com.technototes.library.command.Command; |
| 6 | +import com.technototes.library.command.SequentialCommandGroup; |
| 7 | +import com.technototes.library.command.SimpleCommand; |
| 8 | +import com.technototes.library.command.SimpleRequiredCommand; |
| 9 | +import com.technototes.path.command.TrajectorySequenceCommand; |
| 10 | +import org.firstinspires.ftc.twenty403.Robot; |
| 11 | +import org.firstinspires.ftc.twenty403.command.autonomous.AutoConstants; |
| 12 | +// This one has been converted to a local command as an example |
| 13 | +// import org.firstinspires.ftc.twenty403.command.autonomous.right.AutoRightCycleLeft; |
| 14 | +import org.firstinspires.ftc.twenty403.command.autonomous.right.AutoRightCycleMiddle; |
| 15 | +import org.firstinspires.ftc.twenty403.command.autonomous.right.AutoRightCycleRight; |
| 16 | +import org.firstinspires.ftc.twenty403.subsystem.ClawSubsystem; |
| 17 | +import org.firstinspires.ftc.twenty403.subsystem.DrivebaseSubsystem; |
| 18 | +import org.firstinspires.ftc.twenty403.subsystem.LiftSubsystem; |
| 19 | + |
| 20 | +public class Commands { |
| 21 | + |
| 22 | + // If you prefer, we could name commands ClawOpen, instead of Claw.open (or Claw.Open) |
| 23 | + // In addition, every autonomous command that just extends a command type, and only |
| 24 | + // has a constructor could be moved into this format of command. |
| 25 | + // The onlyk problem I see is that this file would become problematic for merge conflicts |
| 26 | + // For an example: |
| 27 | + public static class Auto { |
| 28 | + |
| 29 | + public static class Right { |
| 30 | + |
| 31 | + public static Command ParkingSelectionCycle(Robot r) { |
| 32 | + return new ChoiceCommand( |
| 33 | + // Note that by putting these things in their respective static classes, |
| 34 | + // much of the auto code may be identical, as this "CycleLeft" function |
| 35 | + // is calling the Auto.Right.CycleLeft function. We could call it that |
| 36 | + // way if we wanted. I could also moving the Auto.Right into a completely |
| 37 | + // separate file, so they're invoked as "AutoCmds.Right.ParkingSelectionCycle" |
| 38 | + new Pair<>(r.visionSystem::left, CycleLeft(r)), |
| 39 | + new Pair<>(r.visionSystem::middle, new AutoRightCycleMiddle(r)), |
| 40 | + new Pair<>(r.visionSystem::right, new AutoRightCycleRight(r)) |
| 41 | + ); |
| 42 | + } |
| 43 | + |
| 44 | + public static Command CycleLeft(Robot r) { |
| 45 | + // This is instead of the AutoRightCycleLeft command |
| 46 | + // (it's literally a copy of the constructor of that thing) |
| 47 | + return new SequentialCommandGroup( |
| 48 | + new TrajectorySequenceCommand( |
| 49 | + r.drivebaseSubsystem, |
| 50 | + AutoConstants.Right.START_TO_W_JUNCTION |
| 51 | + ) |
| 52 | + .alongWith(Commands.Lift.highJunction(r.liftSubsystem)), |
| 53 | + Commands.Claw.open(r.clawSubsystem), |
| 54 | + new TrajectorySequenceCommand( |
| 55 | + r.drivebaseSubsystem, |
| 56 | + AutoConstants.Right.W_JUNCTION_TO_STACK_ONE |
| 57 | + ) |
| 58 | + .alongWith(Commands.Lift.collect(r.liftSubsystem)), |
| 59 | + Commands.Claw.close(r.clawSubsystem), |
| 60 | + new TrajectorySequenceCommand( |
| 61 | + r.drivebaseSubsystem, |
| 62 | + AutoConstants.Right.STACK_TO_W_JUNCTION_ONE |
| 63 | + ) |
| 64 | + .alongWith(Commands.Lift.highJunction(r.liftSubsystem)), |
| 65 | + Commands.Claw.open(r.clawSubsystem), |
| 66 | + new TrajectorySequenceCommand( |
| 67 | + r.drivebaseSubsystem, |
| 68 | + AutoConstants.Right.W_JUNCTION_TO_LEFT_PARK |
| 69 | + ) |
| 70 | + .alongWith(Commands.Lift.collect(r.liftSubsystem)) |
| 71 | + ); |
| 72 | + } |
| 73 | + } |
| 74 | + } |
| 75 | + |
| 76 | + public static class Claw { |
| 77 | + |
| 78 | + public static Command open(ClawSubsystem clawSubsystem) { |
| 79 | + return new SimpleRequiredCommand<>(clawSubsystem, ClawSubsystem::open); |
| 80 | + } |
| 81 | + |
| 82 | + public static Command close(ClawSubsystem clawSubsystem) { |
| 83 | + return new SimpleRequiredCommand<>(clawSubsystem, ClawSubsystem::close); |
| 84 | + } |
| 85 | + |
| 86 | + public static Command toggleAutoClose(ClawSubsystem claw) { |
| 87 | + return new SimpleRequiredCommand<>(claw, ClawSubsystem::toggleAutoClose); |
| 88 | + } |
| 89 | + } |
| 90 | + |
| 91 | + public static class Drive { |
| 92 | + |
| 93 | + public static Command fast(DrivebaseSubsystem drive) { |
| 94 | + return new SimpleCommand(drive::fast); |
| 95 | + } |
| 96 | + |
| 97 | + public static Command slow(DrivebaseSubsystem drive) { |
| 98 | + return new SimpleCommand(drive::slow); |
| 99 | + } |
| 100 | + |
| 101 | + public static Command zeroHeading(DrivebaseSubsystem drive) { |
| 102 | + return new SimpleCommand(drive::setExternalHeading, 0.0); |
| 103 | + } |
| 104 | + |
| 105 | + public static Command cancelTileRequest(DrivebaseSubsystem drive) { |
| 106 | + return new SimpleCommand(drive::requestCancelled); |
| 107 | + } |
| 108 | + } |
| 109 | + |
| 110 | + public static class Lift { |
| 111 | + |
| 112 | + public static Command moveUp(LiftSubsystem lift) { |
| 113 | + return new SimpleRequiredCommand<>(lift, LiftSubsystem::moveUp); |
| 114 | + } |
| 115 | + |
| 116 | + public static Command moveDown(LiftSubsystem lift) { |
| 117 | + return new SimpleRequiredCommand<>(lift, LiftSubsystem::moveDown); |
| 118 | + } |
| 119 | + |
| 120 | + public static Command moveUp_OVERRIDE(LiftSubsystem lift) { |
| 121 | + return new SimpleRequiredCommand<>(lift, LiftSubsystem::moveUp_OVERRIDE); |
| 122 | + } |
| 123 | + |
| 124 | + public static Command moveDown_OVERRIDE(LiftSubsystem lift) { |
| 125 | + return new SimpleRequiredCommand<>(lift, LiftSubsystem::moveDown_OVERRIDE); |
| 126 | + } |
| 127 | + |
| 128 | + public static Command collect(LiftSubsystem lift) { |
| 129 | + return new SimpleRequiredCommand<>(lift, LiftSubsystem::collect); |
| 130 | + } |
| 131 | + |
| 132 | + public static Command highJunction(LiftSubsystem lift) { |
| 133 | + return new SimpleRequiredCommand<>(lift, LiftSubsystem::highPole); |
| 134 | + } |
| 135 | + |
| 136 | + public static Command midJunction(LiftSubsystem lift) { |
| 137 | + return new SimpleRequiredCommand<>(lift, LiftSubsystem::midPole); |
| 138 | + } |
| 139 | + |
| 140 | + public static Command lowJunction(LiftSubsystem lift) { |
| 141 | + return new SimpleRequiredCommand<>(lift, LiftSubsystem::lowPole); |
| 142 | + } |
| 143 | + |
| 144 | + public static Command groundJunction(LiftSubsystem lift) { |
| 145 | + return new SimpleRequiredCommand<>(lift, LiftSubsystem::groundJunction); |
| 146 | + } |
| 147 | + |
| 148 | + public static Command intake(LiftSubsystem lift) { |
| 149 | + return new SimpleRequiredCommand<>(lift, LiftSubsystem::intakePos); |
| 150 | + } |
| 151 | + |
| 152 | + public static Command setNewZero(LiftSubsystem lift) { |
| 153 | + return new SimpleRequiredCommand<>(lift, LiftSubsystem::setNewZero); |
| 154 | + } |
| 155 | + } |
| 156 | +} |
0 commit comments