-
Notifications
You must be signed in to change notification settings - Fork 0
/
GlyphLift.java
91 lines (75 loc) · 2.14 KB
/
GlyphLift.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
package org.firstinspires.ftc.teamcode.Subsystems;
import com.qualcomm.robotcore.hardware.DcMotor;
import com.qualcomm.robotcore.hardware.DigitalChannel;
import com.qualcomm.robotcore.hardware.HardwareMap;
/**
* Created by John Paul Ashour on 11/13/2016.
*/
public class GlyphLift {
private DcMotor lift;
private DigitalChannel liftTouch;
private enum GlyphLiftEnum {
LIFTING,
RETRACTING,
STOPPED
}
private GlyphLiftEnum glyphLiftState;
public GlyphLift(String lift, String touchSensor, HardwareMap hardwareMap) {
this.lift = hardwareMap.dcMotor.get(lift);
liftTouch = hardwareMap.get(DigitalChannel.class, touchSensor);
liftTouch.setMode(DigitalChannel.Mode.INPUT);
stop();
}
public boolean isFullyRetracted() {
return !liftTouch.getState();
}
/**
* Runs Glyph Lift up
*/
public void lift() {
lift.setPower(1.0);
glyphLiftState = GlyphLiftEnum.LIFTING;
}
/**
* Runs Glyph Lift down
*/
public void retract() {
if (isFullyRetracted()) {
stop();
reset();
} else {
lift.setPower(-1.0);
glyphLiftState = GlyphLiftEnum.RETRACTING;
}
}
/**
* Stops Glyph Lift motion and holds current position
*/
public void stop() {
lift.setPower(0);
glyphLiftState = GlyphLiftEnum.STOPPED;
}
private void reset() {
lift.setMode(DcMotor.RunMode.STOP_AND_RESET_ENCODER);
lift.setMode(DcMotor.RunMode.RUN_USING_ENCODER);
}
@Override
public String toString() {
switch (glyphLiftState) {
case LIFTING:
return "Lifting";
case RETRACTING:
return "Retracting";
case STOPPED:
String telemetry;
if (isFullyRetracted()) {
telemetry = "Stopped: Fully Retracted";
} else {
telemetry = "Stopped: Not Fully Retracted";
}
return telemetry;
default:
return "Unknown";
}
}
}