Skip to content

Commit 720ffd6

Browse files
committed
Some clean up to make it easier to understand
1 parent 9be6196 commit 720ffd6

File tree

2 files changed

+38
-28
lines changed

2 files changed

+38
-28
lines changed

src/main/java/frc/robot/Constants.java

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,10 @@
66

77
import edu.wpi.first.math.VecBuilder;
88
import edu.wpi.first.math.Vector;
9+
import edu.wpi.first.math.geometry.Pose3d;
10+
import edu.wpi.first.math.geometry.Rotation3d;
911
import edu.wpi.first.math.geometry.Translation2d;
12+
import edu.wpi.first.math.geometry.Translation3d;
1013
import edu.wpi.first.math.kinematics.SwerveDriveKinematics;
1114
import edu.wpi.first.math.numbers.N3;
1215

@@ -92,12 +95,10 @@ public static final class DriveConstants {
9295
}
9396

9497
public static final class VisionConstants {
95-
public static final double kF = 0.3048;
96-
public static final double kS = 0.254;
97-
public static final double kU = 0;
98-
public static final double kR = 0;
99-
public static final double kP = 0;
100-
public static final double kY = 0;
98+
public static final Pose3d kCamPos = new Pose3d(
99+
new Translation3d(0.3048,0.254,0),
100+
new Rotation3d(0,0,0)
101+
);
101102

102103
public static final double kMaxAmbiguityNonMega = 0.7;
103104
public static final double kMaxDistNonMega = 3;

src/main/java/frc/robot/subsystems/VisionSubsystem.java

Lines changed: 31 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -20,18 +20,26 @@
2020
public class VisionSubsystem extends SubsystemBase {
2121
ArrayList<Pair<SwerveDrivePoseEstimator, AHRS>> m_estimators = new ArrayList<>();
2222

23-
private double m_dy;
24-
private double m_dp;
25-
private double m_dr;
26-
private double m_dt;
23+
// Rate: Change over time
24+
private double m_yawRate;
25+
private double m_pitchRate;
26+
private double m_rollRate;
27+
private double m_deltaTime;
2728

2829
/** Creates a new VisionSubsystem. */
2930
public VisionSubsystem() {
30-
LimelightHelpers.setCameraPose_RobotSpace(VisionConstants.kLimelightName, VisionConstants.kF, VisionConstants.kS,
31-
VisionConstants.kU, VisionConstants.kR, VisionConstants.kP, VisionConstants.kY);
31+
LimelightHelpers.setCameraPose_RobotSpace(
32+
VisionConstants.kLimelightName,
33+
VisionConstants.kCamPos.getX(),
34+
VisionConstants.kCamPos.getY(),
35+
VisionConstants.kCamPos.getZ(),
36+
VisionConstants.kCamPos.getRotation().getX(),
37+
VisionConstants.kCamPos.getRotation().getY(),
38+
VisionConstants.kCamPos.getRotation().getZ()
39+
);
3240
LimelightHelpers.SetIMUMode(VisionConstants.kLimelightName, VisionConstants.kIMUType_sync);
3341

34-
m_dy = m_dp = m_dr = m_dt = 0;
42+
m_yawRate = m_pitchRate = m_rollRate = m_deltaTime = 0;
3543
}
3644

3745
@Override
@@ -50,26 +58,27 @@ public void setIMUMode(int mode) {
5058
}
5159

5260
private void estimatePose(SwerveDrivePoseEstimator estimator, AHRS ahrs) {
53-
// calculate deltas
54-
m_dt = ahrs.getLastSensorTimestamp() - m_dt;
55-
if (m_dt > VisionConstants.kdtThreshold) {
56-
m_dy = m_dp = m_dr = m_dt = 0;
61+
// calculate deltas and rates of rotation
62+
m_deltaTime = ahrs.getLastSensorTimestamp() - m_deltaTime;
63+
if (m_deltaTime > VisionConstants.kdtThreshold) {
64+
m_yawRate = m_pitchRate = m_rollRate = m_deltaTime = 0;
5765
} else {
58-
m_dy = MathUtil.inputModulus(ahrs.getYaw() - m_dy, -180, 180) / m_dt;
59-
m_dp = MathUtil.inputModulus(ahrs.getPitch() - m_dp, -180, 180) / m_dt;
60-
m_dr = MathUtil.inputModulus(ahrs.getRoll() - m_dr, -180, 180) / m_dt;
66+
m_yawRate = MathUtil.inputModulus(ahrs.getYaw() - m_yawRate, -180, 180) / m_deltaTime;
67+
m_pitchRate = MathUtil.inputModulus(ahrs.getPitch() - m_pitchRate, -180, 180) / m_deltaTime;
68+
m_rollRate = MathUtil.inputModulus(ahrs.getRoll() - m_rollRate, -180, 180) / m_deltaTime;
6169
}
6270

6371
// calculate pose
72+
// WPILIB assumes origin on blue side
6473
LimelightHelpers.SetRobotOrientation(VisionConstants.kLimelightName,
65-
estimator.getEstimatedPosition().getRotation().getDegrees(), m_dy, ahrs.getPitch(), m_dp, ahrs.getRoll(), m_dr);
66-
PoseEstimate estimate = LimelightHelpers.getBotPoseEstimate_wpiBlue_MegaTag2(VisionConstants.kLimelightName); // WPILib
67-
// Ecosystem
68-
// (including
69-
// pathplanner)
70-
// assumes
71-
// origin on
72-
// blue side
74+
estimator.getEstimatedPosition().getRotation().getDegrees(),
75+
m_yawRate,
76+
ahrs.getPitch(),
77+
m_pitchRate,
78+
ahrs.getRoll(),
79+
m_rollRate
80+
);
81+
PoseEstimate estimate = LimelightHelpers.getBotPoseEstimate_wpiBlue_MegaTag2(VisionConstants.kLimelightName);
7382

7483
if (estimate == null) {
7584
DriverStation.reportError("Bad limelight data: wrong packet size", false);

0 commit comments

Comments
 (0)