-
Notifications
You must be signed in to change notification settings - Fork 35
/
Copy pathAutoSteerAndIntakeAction.java
64 lines (53 loc) · 2.2 KB
/
AutoSteerAndIntakeAction.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
package com.team254.frc2019.auto.actions;
import com.team254.frc2019.statemachines.EndEffectorStateMachine;
import com.team254.frc2019.statemachines.SuperstructureCommands;
import com.team254.frc2019.subsystems.Drive;
import com.team254.frc2019.subsystems.EndEffector;
import com.team254.frc2019.subsystems.Superstructure;
import com.team254.lib.geometry.Rotation2d;
import com.team254.lib.util.DelayedBoolean;
import com.team254.lib.util.DriveSignal;
import com.team254.lib.vision.AimingParameters;
import edu.wpi.first.wpilibj.Timer;
import java.util.Optional;
public class AutoSteerAndIntakeAction implements Action {
private static final Drive mDrive = Drive.getInstance();
private DelayedBoolean mHasDisk = null;
private boolean mFinished = false;
private boolean mIdleWhenDone = false;
private boolean mReverse = false;
private final double kThrottle = 0.3;
public AutoSteerAndIntakeAction(boolean reverse, boolean idleWhenDone) {
mIdleWhenDone = idleWhenDone;
mReverse = reverse;
}
@Override
public void start() {
mHasDisk = new DelayedBoolean(Timer.getFPGATimestamp(), 0.05);
SuperstructureCommands.goToPickupDiskFromWallFront();
EndEffector.getInstance().setWantedAction(EndEffectorStateMachine.WantedAction.INTAKE_DISK);
Superstructure.getInstance().setWantAutoAim(Rotation2d.fromDegrees(180.0),
true, 50);
}
@Override
public void update() {
Optional<AimingParameters> aimParams = Superstructure.getInstance().getLatestAimingParameters();
if (aimParams.isEmpty() || EndEffector.getInstance().hasDisk()) {
mDrive.setOpenLoop(DriveSignal.BRAKE);
} else {
mDrive.autoSteer(kThrottle * (mReverse ? -1.0 : 1.0), aimParams.get());
}
mFinished = mHasDisk.update(Timer.getFPGATimestamp(), EndEffector.getInstance().hasDisk());
}
@Override
public boolean isFinished() {
return mFinished;
}
@Override
public void done() {
if (mIdleWhenDone) {
EndEffector.getInstance().setWantedAction(EndEffectorStateMachine.WantedAction.IDLE);
}
Superstructure.getInstance().setWantRobotRelativeTurret();
}
}