11package frc .robot .subsystems .grabber ;
22
3+ import edu .wpi .first .wpilibj2 .command .SubsystemBase ;
34import static edu .wpi .first .units .Units .Milliseconds ;
45import static edu .wpi .first .units .Units .Rotations ;
56import static edu .wpi .first .units .Units .Seconds ;
1213import edu .wpi .first .units .measure .Voltage ;
1314import edu .wpi .first .wpilibj .Alert ;
1415import edu .wpi .first .wpilibj .Alert .AlertType ;
15- import edu .wpi .first .wpilibj2 .command .SubsystemBase ;
1616import edu .wpi .first .wpilibj2 .command .Command ;
17+ import edu .wpi .first .wpilibj2 .command .Commands ;
18+ import edu .wpi .first .wpilibj2 .command .sysid .SysIdRoutine ;
19+ import frc .robot .subsystems .grabber .GrabberIO .GrabberIOInputs ;
20+
1721
1822public class GrabberSubsystem extends SubsystemBase {
23+ public enum GrabberStates {
24+ Collecting ,
25+ Stationary ,
26+ Ejecting ,
27+ Grabbing
28+ }
29+ private final GrabberIO io_ ;
30+ //Figure out grabber target rotation
31+ //Using 1 as a placeholder for now
32+ private Angle target_grabber = Rotations .of (1 );
33+ private final GrabberIOInputs inputs_ ;
34+ private GrabberStates states ;
35+ public int ejectswitch ;
36+
37+ //Constructor
38+ public GrabberSubsystem (GrabberIO io ){
39+ io = io_ ;
40+ ejectswitch =0 ;
41+ inputs_ = new GrabberIOInputs ();
42+ target_grabber = Rotations .zero ();
43+ states = GrabberStates .Stationary ;
44+ }
45+
46+
47+ @ Override
48+
49+ public void periodic (){
50+ io_ .updateInputs (inputs_ );
51+ Logger .processInputs ("Grabber" , inputs_ );
52+ Logger .recordOutput ("Grabber/angle/target" , target_grabber );
53+ if (states == GrabberStates .Stationary ){
54+ if (hasCoralBool ()==false ){
55+ collectCoral ();
56+ states =GrabberStates .Collecting ;
57+ }
58+ } else if (states ==GrabberStates .Collecting ){
59+ AlignCoral ();
60+ states =GrabberStates .Ejecting ;
61+ } else if (states == GrabberStates .Ejecting ){
62+ ejectCoral ();
63+ if (ejectswitch ==1 ){
64+ ejectAlgae ();
65+ states =GrabberStates .Stationary ;
66+ }
67+ states = GrabberStates .Grabbing ;
68+ } else if (states == GrabberStates .Grabbing ){
69+ grabAlgae ();
70+ ejectswitch =1 ;
71+ states = GrabberStates .Ejecting ;
72+ }
73+ }
1974
20- }
75+
76+ //Subsystem Methods
77+
78+ public boolean hasAlgaeBool (){
79+ if (inputs_ .algaeSensor1 || inputs_ .algaeSensor2 ){
80+ inputs_ .hasAlgae = true ;
81+ return true ;
82+ }
83+ return false ;
84+ }
85+ //ask "not"
86+ //Ask grabber angle
87+ public boolean hasCoralBool (){
88+ if (inputs_ .coralSensor ){
89+ inputs_ .hasCoral = true ;
90+ return true ;
91+ }
92+ return false ;
93+ }
94+
95+ public Command grabAlgae (){
96+ return runOnce (() -> {
97+ if (hasAlgaeBool ()==false ){
98+ io_ .setGrabberVoltage (Volts .of (1 ));
99+ if (hasAlgaeBool ()==true ){
100+ io_ .setGrabberVoltage (Volts .zero ());
101+ }
102+ }
103+ });
104+ }
105+
106+ public Command collectCoral (){
107+ return runOnce (() -> {
108+ if (hasCoralBool ()==false ){
109+ io_ .setGrabberVoltage (Volts .of (1 ));
110+ if (hasCoralBool ()==true ){
111+ io_ .setGrabberVoltage (Volts .zero ());
112+ }
113+ }
114+ });
115+ }
116+
117+ public Command ejectCoral (){
118+ return runOnce (() -> {
119+ if (hasCoralBool ()==true || hasCoralBool ()==false ){
120+ io_ .setGrabberVoltage (Volts .of (1.2 ));
121+ if (hasCoralBool ()==false ){
122+ io_ .setGrabberVoltage (Volts .zero ());
123+ }
124+ }
125+ });
126+ }
127+
128+ public Command AlignCoral (){
129+ return runOnce (() -> {
130+ if (hasCoralBool ()==true ){
131+ io_ .setGrabberVoltage (Volts .of (-1 ));
132+ if (hasCoralBool ()==false ){
133+ io_ .setGrabberVoltage (Volts .zero ());
134+ }
135+ }
136+ });
137+ }
138+
139+ public Command ejectAlgae (){
140+ return runOnce (() ->{
141+ if (hasAlgaeBool ()==true ){
142+ io_ .setGrabberVoltage (Volts .of (-1 ));
143+ if (hasAlgaeBool ()==false ){
144+ io_ .setGrabberVoltage (Volts .zero ());
145+ }
146+ }
147+ });
148+ }
149+ }
0 commit comments