-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathLift.java
164 lines (131 loc) · 3.71 KB
/
Lift.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
154
155
156
157
158
159
160
161
162
163
164
package org.usfirst.frc.team4534.robot;
import edu.wpi.first.wpilibj.DigitalInput;
import edu.wpi.first.wpilibj.Jaguar;
import org.usfirst.frc.team4534.robot.AccelerativeJoystick;
public class Lift {
Jaguar liftMotor;
DigitalInput LM_TOP,LM_BOTTOM;
AccelerativeJoystick joystick;
int upButton,downButton,stopButton;
private final Double LIFT_SPEED = 0.3;
private final Double LIFT_INCREMENT = 0.05;
public enum LiftState {
MOVING_UP,
UP,
MOVING_DOWN,
DOWN,
EMERGENCY_STOPPED
}
private LiftState currentLiftState;
public Lift(Jaguar liftMotor, DigitalInput LM_TOP, DigitalInput LM_BOTTOM, AccelerativeJoystick joystick, int upButton, int downButton, int stopButton) {
//TODO:Constructor
this.liftMotor = liftMotor;
this.LM_TOP = LM_TOP;
this.LM_BOTTOM = LM_BOTTOM;
this.joystick = joystick;
this.upButton = upButton;
this.downButton = downButton;
this.stopButton = stopButton;
//assume the lift is down
this.currentLiftState = LiftState.DOWN;
}
public LiftState getCurrentLiftState() {
return currentLiftState;
}
private boolean touchingLimitUp() {
return LM_TOP.get();
}
private boolean touchingLimitDown() {
return LM_BOTTOM.get();
}
public void moveUp() {
double speed = .3;
if (joystick.getRawAxis(2) != 0) {
speed = .2;
}
if (joystick.getRawAxis(3) != 0) {
speed = .5;
}
System.out.println("lift.moveUp() " + speed);
if (!touchingLimitUp()) {
liftMotor.set(speed);
currentLiftState = LiftState.MOVING_UP;
} else {
liftMotor.set(0.0);
currentLiftState = LiftState.UP;
}
}
public void moveDown() {
double speed = .3;
if (joystick.getRawAxis(2) != 0) {
speed = .2;
}
if (joystick.getRawAxis(3) != 0) {
speed = .6;
}
System.out.println("lift.moveDown() -" + speed);
if (!touchingLimitDown()) {
liftMotor.set(-speed);
currentLiftState = LiftState.MOVING_DOWN;
} else {
liftMotor.set(0.0);
currentLiftState = LiftState.DOWN;
}
}
public void move() {
double moveVal = joystick.getAcceleratedUpDownButtons(0, upButton, downButton, LIFT_INCREMENT, LIFT_SPEED);
if (!touchingLimitUp() && !touchingLimitDown()) {
liftMotor.set(moveVal);
System.out.println("Lift moving: " + moveVal);
} else {
liftMotor.set(0.0);
}
}
public void emergencyStop() {
liftMotor.set(0.0);
currentLiftState = LiftState.EMERGENCY_STOPPED;
}
public void poll() {
poll(false);
}
public void poll(boolean autoMode) {
//This function needs to be called continuously to ensure the lift shuts off when it does
//SAFETY FIRST, check if the e-stop button is pressed
if(joystick.getRawButton(stopButton)) {
emergencyStop();
} else {
if (!autoMode) {
//move();
}
}
if(joystick.getRawButton(upButton)) {
moveUp();
} else if(joystick.getRawButton(downButton)) {
moveDown();
}/* else {
liftMotor.set(0.0);
}*/
if(joystick.getRawAxis(3) != 0.0 && !touchingLimitUp() && !touchingLimitDown()) {
if(currentLiftState == LiftState.MOVING_UP) {
liftMotor.set(LIFT_SPEED+0.2);
} else if(currentLiftState == LiftState.MOVING_DOWN){
liftMotor.set(-(LIFT_SPEED+0.2));
}
} else if(!touchingLimitUp() && !touchingLimitDown()){
if(currentLiftState == LiftState.MOVING_UP) {
liftMotor.set(LIFT_SPEED);
} else if(currentLiftState == LiftState.MOVING_DOWN){
liftMotor.set(-LIFT_SPEED);
}
}
//next, check if the limit switches are pressed
if(touchingLimitUp() && currentLiftState == LiftState.MOVING_UP) {
liftMotor.set(0.0);
currentLiftState = LiftState.UP;
}
if(touchingLimitDown() && currentLiftState == LiftState.MOVING_DOWN) {
liftMotor.set(0.0);
currentLiftState = LiftState.DOWN;
}
}
}