generated from StuyPulse/Phil
-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathClimb.java
More file actions
69 lines (51 loc) · 1.96 KB
/
Climb.java
File metadata and controls
69 lines (51 loc) · 1.96 KB
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
package com.stuypulse.robot.subsystems.climber;
import com.stuypulse.robot.constants.Constants;
import com.stuypulse.robot.constants.Settings;
import com.stuypulse.stuylib.math.SLMath;
import edu.wpi.first.math.geometry.Rotation2d;
import edu.wpi.first.wpilibj.smartdashboard.SmartDashboard;
import edu.wpi.first.wpilibj2.command.SubsystemBase;
public abstract class Climb extends SubsystemBase {
private static final Climb instance;
static {
instance = new ClimbImpl();
}
public static Climb getInstance() {
return instance;
}
public enum ClimbState {
DEFAULT(Settings.Climb.DEFAULT_ANGLE, Settings.Climb.DEFAULT_VOLTAGE),
STOW(Settings.Climb.STOW_ANGLE, Settings.Climb.STOW_VOLTAGE),
CLIMBING(Settings.Climb.CLIMBED_ANGLE, Settings.Climb.CLIMBING_VOLTAGE);
private Rotation2d targetAngle;
private double targetMotorSpeed;
private ClimbState(Rotation2d targetAngle, double targetMotorSpeed) {
this.targetAngle = Rotation2d.fromDegrees(
SLMath.clamp(targetAngle.getDegrees(), Constants.Climb.MIN_ANGLE.getDegrees(),
Constants.Climb.MAX_ANGLE.getDegrees()));
this.targetMotorSpeed = SLMath.clamp(targetMotorSpeed, -1.0, 1.0); // Motor speed can only be between -1 & 1
}
public Rotation2d getTargetAngle() {
return this.targetAngle;
}
public double getTargetMotorSpeed() {
return this.targetMotorSpeed;
}
}
private ClimbState state;
protected Climb() {
this.state = ClimbState.DEFAULT;
}
public ClimbState getState() {
return this.state;
}
public void setState(ClimbState state) {
this.state = state;
}
public abstract Rotation2d getCurrentAngle();
public abstract boolean atTargetAngle();
@Override
public void periodic() {
SmartDashboard.putString("Climb/State", state.toString());
}
}