-
Notifications
You must be signed in to change notification settings - Fork 35
/
Copy pathStingerClimbingStateMachine.java
104 lines (95 loc) · 4.01 KB
/
StingerClimbingStateMachine.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
package com.team254.frc2019.statemachines;
import com.team254.frc2019.Constants;
import com.team254.frc2019.subsystems.*;
/**
* Climbing state machine used at the San Francisco and Silicon Valley Regionals
* using the "stinger" mechanism
*/
public class StingerClimbingStateMachine {
private final double kDisableArmWristWaitTimeAfterKickstand = 0.2; // sec
private final double kWaitForDisableArmWrist = 0.2; // sec
private final double kElevatorThrottleDeadband = 0.1;
enum SystemState {
MOVING_TO_PRECLIMB, IN_PRECLIMB, CLIMBING, POST_CLIMB
}
private double mStateStartTime = 0;
private Superstructure mSuperStructure;
private Kickstand mKickstand;
private Drive mDrive;
private boolean mOverrideHigh = false;
SystemState mSystemState = SystemState.MOVING_TO_PRECLIMB;
public StingerClimbingStateMachine() {
mSuperStructure = Superstructure.getInstance();
mKickstand = Kickstand.getInstance();
mDrive = Drive.getInstance();
}
public synchronized void handle(double timestamp, boolean hangHighMode, double elevatorThrottle,
boolean triggerPostClimb) {
switch (mSystemState) {
case MOVING_TO_PRECLIMB:
if (hangHighMode || mOverrideHigh) {
SuperstructureCommands.goToPrepareForStingerClimb();
} else { // HAB level 2
SuperstructureCommands.goToPrepareForStingerClimbLow();
}
break;
case IN_PRECLIMB:
mKickstand.setEngaged();
mDrive.setHighGear(false);
if (timestamp - mStateStartTime > kDisableArmWristWaitTimeAfterKickstand) {
// Disable arm and wrist
mSuperStructure.setDisableArmAndWrist(true);
}
break;
case CLIMBING:
if (Math.abs(elevatorThrottle) > kElevatorThrottleDeadband) {
mSuperStructure.setUseElevatorManual(true);
if (hangHighMode && Elevator.getInstance().getPosition() < 5.0) {
Elevator.getInstance().updateSoftLimit((int) (24 * Constants.kElevatorConstants.kTicksPerUnitDistance));
}
}
break;
case POST_CLIMB:
mKickstand.setDisengaged();
if (timestamp - mStateStartTime > kDisableArmWristWaitTimeAfterKickstand) {
SuperstructureCommands.goToPrepareForStingerClimb();
mSuperStructure.setDisableArmAndWrist(false);
mSuperStructure.setUseElevatorManual(false);
}
break;
}
SystemState nextState = mSystemState;
switch (mSystemState) {
case MOVING_TO_PRECLIMB:
if (mSuperStructure.isAtDesiredState()) {
nextState = SystemState.IN_PRECLIMB;
}
break;
case IN_PRECLIMB:
if (timestamp - mStateStartTime >
kDisableArmWristWaitTimeAfterKickstand + kWaitForDisableArmWrist) {
if (true) {
//if (mTurret.atHomingLocation()) {
nextState = SystemState.CLIMBING;
}
}
break;
case CLIMBING:
if (!hangHighMode && triggerPostClimb) {
nextState = SystemState.POST_CLIMB;
}
break;
case POST_CLIMB:
if (timestamp - mStateStartTime > kDisableArmWristWaitTimeAfterKickstand) {
mOverrideHigh = true;
nextState = SystemState.MOVING_TO_PRECLIMB;
}
break;
}
if (nextState != mSystemState) {
mSystemState = nextState;
mStateStartTime = timestamp;
System.out.println("Transitioned from : " + mSystemState + " to " + nextState);
}
}
}