-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRobotState.java
More file actions
92 lines (69 loc) · 3.01 KB
/
Copy pathRobotState.java
File metadata and controls
92 lines (69 loc) · 3.01 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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
package frc.robot;
import static edu.wpi.first.units.Units.Meters;
import java.util.function.Supplier;
import org.littletonrobotics.junction.AutoLogOutput;
import org.littletonrobotics.junction.Logger;
import edu.wpi.first.math.geometry.Pose2d;
import edu.wpi.first.math.geometry.Rotation2d;
import edu.wpi.first.math.geometry.Translation2d;
import edu.wpi.first.units.measure.Distance;
import edu.wpi.first.wpilibj.DriverStation;
import edu.wpi.first.wpilibj.DriverStation.Alliance;
import frc.robot.subsystems.shooter.ShooterConstants;
import frc.robot.util.HubShiftUtil;
import frc.robot.util.LoggedTracer;
/**
* Object that calculates robot-wide values that change periodically,
* for example, distance to a field element.
*/
public class RobotState {
private static Supplier<Pose2d> pose = () -> Pose2d.kZero;
@AutoLogOutput
private static Distance hubDistance = Meters.zero();
private static Rotation2d rotationToHub = Rotation2d.kZero;
private static boolean inAllianceZone = false;
/**
* This method supplies the object with the information it needs for its calculations.
* @param poseSupplier
*/
public static void initialize(Supplier<Pose2d> poseSupplier) {
pose = poseSupplier;
}
/**
* This method gets called periodically so that the variables can update.
*/
public static void periodic() {
LoggedTracer.reset();
// Calculations!!!
Pose2d currentPose = pose.get();
Translation2d hubTranslation =
DriverStation.getAlliance().orElse(Alliance.Blue) == Alliance.Blue
? ShooterConstants.Positions.blueHubPose
: ShooterConstants.Positions.redHubPose;
hubDistance = Meters.of(pose.get().getTranslation().getDistance(hubTranslation));
Logger.recordOutput("RobotState/hubDistance", hubDistance) ;
Translation2d translationToHub = hubTranslation.minus(currentPose.getTranslation());
rotationToHub = new Rotation2d(translationToHub.getX(), translationToHub.getY());
Logger.recordOutput("RobotState/HubRotation", rotationToHub);
Logger.recordOutput("RobotState/AngleDelta", rotationToHub.minus(currentPose.getRotation()));
Distance allianceWall =
DriverStation.getAlliance().orElse(Alliance.Blue) == Alliance.Blue
? ShooterConstants.Positions.blueAllianceWall
: ShooterConstants.Positions.redAllianceWall;
inAllianceZone = currentPose.getMeasureX().minus(allianceWall).abs(Meters) < ShooterConstants.Positions.spinUpZone.in(Meters);
// Other logging
Logger.recordOutput("ShiftInfo", HubShiftUtil.getOfficialShiftInfo());
LoggedTracer.record("RobotState");
}
public static Distance hubDistance() {
return hubDistance;
}
@AutoLogOutput
public static Rotation2d rotationToHub() {
return rotationToHub;
}
@AutoLogOutput
public static boolean inAllianceZone() {
return inAllianceZone;
}
}