-
Notifications
You must be signed in to change notification settings - Fork 0
/
Intake.java
153 lines (129 loc) · 4.75 KB
/
Intake.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
package com.team841.offseason2023.Superstructure;
import com.ctre.phoenix.motorcontrol.ControlMode;
import com.ctre.phoenix.motorcontrol.NeutralMode;
import com.ctre.phoenix.motorcontrol.SupplyCurrentLimitConfiguration;
import com.ctre.phoenix.motorcontrol.can.TalonFX;
import com.team841.offseason2023.Constants.Constants;
import com.team841.offseason2023.Constants.SC;
import com.team841.offseason2023.Constants.SubsystemManifest;
import com.team841.offseason2023.Superstructure.factory.SuperstructureFactoryBeta;
import com.team841.offseason2023.states.States;
import edu.wpi.first.wpilibj.smartdashboard.SmartDashboard;
import edu.wpi.first.wpilibj2.command.*;
public class Intake extends SubsystemBase {
private final TalonFX IntakeMotor = new TalonFX(Constants.CANid.IntakeTalon);
private final SuperstructureFactoryBeta factory = SubsystemManifest.factory;
private Double thresh = 0.0;
private boolean notTransition = true;
private Double timer = Double.NaN;
// public GamePiece gamePiece = GamePiece.Empty;
public Intake() {
IntakeMotor.configFactoryDefault();
IntakeMotor.configSupplyCurrentLimit(new SupplyCurrentLimitConfiguration(true, 30, 0, 0));
IntakeMotor.setNeutralMode(NeutralMode.Brake);
}
/**
* Intake Cone / Throw Cube
*
* <p>public void toggleIntakeIn()
*
* @param: none
*/
public void toggleIntakeIn() {
if (IntakeMotor.getMotorOutputPercent() == 0) {
this.IntakeMotor.set(ControlMode.PercentOutput, SC.Intake.teleopPower);
this.thresh = SC.Intake.ConeCThresh;
this.timer = Double.NaN;
} else if (IntakeMotor.getMotorOutputPercent() < 0) {
this.IntakeMotor.set(ControlMode.PercentOutput, SC.Intake.teleopPower);
this.thresh = SC.Intake.ConeCThresh;
this.timer = 0.0;
this.notTransition = false;
} else {
IntakeMotor.set(ControlMode.PercentOutput, 0);
this.thresh = 0.0;
this.timer = Double.NaN;
}
}
/**
* Intake Cube / Throw Cone
*
* <p>public void toggleIntakeOut()
*
* @param: none
*/
public void toggleIntakeOut() {
if (IntakeMotor.getMotorOutputPercent() == 0) {
this.IntakeMotor.set(ControlMode.PercentOutput, -SC.Intake.teleopPower);
this.thresh = SC.Intake.CubeCThresh;
this.timer = Double.NaN;
} else if (IntakeMotor.getMotorOutputPercent() > 0) {
this.IntakeMotor.set(ControlMode.PercentOutput, -SC.Intake.teleopPower);
this.thresh = SC.Intake.ConeCThresh;
this.timer = 0.0;
this.notTransition = false;
} else {
this.IntakeMotor.set(ControlMode.PercentOutput, 0);
this.thresh = 0.0;
this.timer = Double.NaN;
}
}
/**
* Stop Intake Motor
*
* @param: none
*/
public void stopMotor() {
this.IntakeMotor.set(ControlMode.PercentOutput, 0);
this.thresh = 0.0;
this.timer = Double.NaN;
}
@Override
public void periodic() {
if (this.timer >= 0.0) {
timer += 1.0;
if (timer >= 20.0) {
notTransition = true;
timer = Double.NaN;
return;
}
}
if (SC.superstructureState == States.Ground
&& notTransition
&& IntakeMotor.getSupplyCurrent() > thresh) {
factory.moveHome().schedule();
}
SmartDashboard.putBoolean("Intake spinning", this.IntakeMotor.getMotorOutputPercent() != 0);
}
public GamePiece pickedUp() {
if (IntakeMotor.getSupplyCurrent() < thresh) {
return GamePiece.Empty;
} else {
return this.thresh == SC.Intake.CubeCThresh ? GamePiece.Cube : GamePiece.Cone;
}
}
public CommandBase IntakeCube() {
return new InstantCommand(
() -> this.IntakeMotor.set(ControlMode.PercentOutput, -SC.Intake.teleopPower))
.withInterruptBehavior(Command.InterruptionBehavior.kCancelSelf)
.handleInterrupt(() -> this.IntakeMotor.set(ControlMode.PercentOutput, 0));
}
public CommandBase ThrowCube() {
return new InstantCommand(
() -> this.IntakeMotor.set(ControlMode.PercentOutput, SC.Intake.teleopPower))
.withInterruptBehavior(Command.InterruptionBehavior.kCancelSelf)
.handleInterrupt(() -> this.IntakeMotor.set(ControlMode.PercentOutput, 0));
}
public CommandBase IntakeCone() {
return new InstantCommand(
() -> this.IntakeMotor.set(ControlMode.PercentOutput, SC.Intake.teleopPower))
.withInterruptBehavior(Command.InterruptionBehavior.kCancelSelf)
.handleInterrupt(() -> this.IntakeMotor.set(ControlMode.PercentOutput, 0));
}
public CommandBase ThrowCone() {
return new InstantCommand(
() -> this.IntakeMotor.set(ControlMode.PercentOutput, -SC.Intake.teleopPower))
.withInterruptBehavior(Command.InterruptionBehavior.kCancelSelf)
.handleInterrupt(() -> this.IntakeMotor.set(ControlMode.PercentOutput, 0));
}
}