generated from Patribots4738/Swerve-Command-Based
-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathIntake.java
75 lines (59 loc) · 2.1 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
package frc.robot.subsystems;
import edu.wpi.first.math.MathUtil;
import edu.wpi.first.wpilibj2.command.Command;
import edu.wpi.first.wpilibj2.command.SubsystemBase;
import frc.robot.util.Constants.FieldConstants;
import frc.robot.util.Constants.IntakeConstants;
import frc.robot.util.rev.Neo;
import frc.robot.util.rev.SafeSpark.TelemetryPreference;
import monologue.Logged;
import monologue.Annotations.Log;
public class Intake extends SubsystemBase implements Logged {
private final Neo motor;
@Log
private double desiredSpeed = 0;
@Log
private boolean notePossession = FieldConstants.IS_SIMULATION;
public Intake() {
motor = new Neo(IntakeConstants.INTAKE_CAN_ID, false);
motor.setSmartCurrentLimit(IntakeConstants.INTAKE_CURRENT_LIMIT_AMPS);
motor.setTelemetryPreference(TelemetryPreference.NO_ENCODER);
}
public void setPercent(double desiredPercent) {
desiredPercent =
MathUtil.clamp(
desiredPercent,
IntakeConstants.INTAKE_PERCENT_LOWER_LIMIT,
IntakeConstants.INTAKE_PERCENT_UPPER_LIMIT);
if (desiredSpeed != desiredPercent) {
desiredSpeed = desiredPercent;
motor.set(desiredSpeed);
}
}
public Command setPercentCommand(double desiredPercent) {
return runOnce(() -> {
setPercent(desiredPercent);
});
}
public Command inCommand() {
return setPercentCommand(IntakeConstants.INTAKE_PERCENT);
}
public Command outCommand() {
return setPercentCommand(IntakeConstants.OUTTAKE_PERCENT);
}
public boolean isStopped() {
return desiredSpeed == 0;
}
public Command stopCommand() {
return setPercentCommand(IntakeConstants.STOP_PERCENT);
}
public Command setCoastMode() {
return runOnce(() -> motor.setCoastMode()).ignoringDisable(true);
}
public Command setBrakeMode() {
return runOnce(() -> motor.setBrakeMode()).ignoringDisable(true);
}
public double getDesiredSpeed() {
return desiredSpeed;
}
}