Advertisement
YTG123

Untitled

Dec 19th, 2024
32
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.89 KB | None | 0 0
  1. // IntakeRollersSubsystem.java
  2. package frc.robot.subsystems;
  3.  
  4. import edu.wpi.first.wpilibj2.command.Command;
  5. import edu.wpi.first.wpilibj2.command.FunctionalCommand;
  6. import edu.wpi.first.wpilibj2.command.SubsystemBase;
  7. import frc.robot.motors.DBugSparkMax;
  8.  
  9. public class IntakeRollersSubsystem extends SubsystemBase {
  10.     private final DBugSparkMax _motor;
  11.  
  12.     private static final int MOTOR_CANID = 1;
  13.  
  14.     public IntakeRollersSubsystem() {
  15.         _motor = DBugSparkMax.create(MOTOR_CANID);
  16.     }
  17.  
  18.     public State getState() {
  19.         return State.fromValue(_motor.get());
  20.     }
  21.  
  22.     public void setState(State target) {
  23.         _motor.set(target._value);
  24.     }
  25.  
  26.     public Command getSetStateCommand(State target) {
  27.         return new FunctionalCommand(
  28.             () -> setState(target),
  29.             () -> {},
  30.             _ignored -> {},
  31.             () -> getState() == target,
  32.             this
  33.         );
  34.     }
  35.  
  36.     public static enum State {
  37.         IN(1), OUT(-1), OFF(0),;
  38.  
  39.         private final double _value;
  40.  
  41.         State(double value) {
  42.             _value = value;
  43.         }
  44.  
  45.         private static State fromValue(double value) {
  46.             if (value > 0) return IN;
  47.             if (value < 0) return OUT;
  48.             return OFF;
  49.         }
  50.     }
  51. }
  52.  
  53. // RobotContainer.java
  54. // --snip--
  55.   private final IntakeRollersSubsystem m_intakeRollersSubsystem = new IntakeRollersSubsystem();
  56. // --snip--
  57.   public Command getCollectCommand() {
  58.     return m_elevatorSubsystem
  59.       .setStateCommand(ElevatorSubsystem.State.BOTTOM)
  60.       .andThen(m_intakeRollersSubsystem.getSetStateCommand(IntakeRollersSubsystem.State.IN))
  61.       .andThen(Commands.waitSeconds(2))
  62.       .andThen(
  63.         m_elevatorSubsystem.setStateCommand(ElevatorSubsystem.State.TOP)
  64.           .alongWith(m_intakeRollersSubsystem.getSetStateCommand(IntakeRollersSubsystem.State.OUT))
  65.       );
  66.   }
  67. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement