2020public 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