@@ -51,8 +51,9 @@ public class Drive extends SubsystemBase implements PidTunerObject {
51
51
// NavX parameters
52
52
private double m_desiredHeading = 0.0 ;
53
53
private boolean m_useHeadingCorrection = true ;
54
- private static final double HEADING_PID_P = 0.007 ; // was 0.030 in 2019 for HIGH_GEAR; was 0.007 in early 2020
55
- private static final double HEADING_PID_D = 0.080 ; // was 0.04 in 2019
54
+ private static final double HEADING_PID_P = 0.010 ; // was 0.007 at GSD; was 0.030 in 2019 for HIGH_GEAR
55
+ private static final double HEADING_PID_I = 0.000 ; // was 0.000 at GSD; was 0.000 in 2019
56
+ private static final double HEADING_PID_D = 0.080 ; // was 0.080 at GSD; was 0.04 in 2019
56
57
private static final double kToleranceDegreesPIDControl = 0.2 ;
57
58
58
59
// Drive parameters
@@ -97,8 +98,8 @@ public Drive() {
97
98
m_HeadingError = new PIDHeadingError ();
98
99
m_HeadingError .m_Error = 0.0 ;
99
100
m_HeadingCorrection = new PIDHeadingCorrection ();
100
- m_HeadingPid = new PIDController (HEADING_PID_P , 0.000 , HEADING_PID_D , m_HeadingError , m_HeadingCorrection ,
101
- 0.020 /* period in seconds */ );
101
+ m_HeadingPid = new PIDController (HEADING_PID_P , HEADING_PID_I , HEADING_PID_D , m_HeadingError ,
102
+ m_HeadingCorrection , 0.020 /* period in seconds */ );
102
103
m_HeadingPid .setInputRange (-180.0f , 180.0f );
103
104
m_HeadingPid .setContinuous (true ); // treats the input range as "continous" with wrap-around
104
105
m_HeadingPid .setOutputRange (-.50 , .50 ); // set the maximum power to correct twist
@@ -110,6 +111,26 @@ public Drive() {
110
111
rightFrontTalon .setNeutralMode (NeutralMode .Coast );
111
112
rightRearTalon .setNeutralMode (NeutralMode .Coast );
112
113
114
+ // configure output voltages
115
+ leftFrontTalon .configNominalOutputVoltage (+0.0f , -0.0f );
116
+ leftRearTalon .configNominalOutputVoltage (+0.0f , -0.0f );
117
+ rightFrontTalon .configNominalOutputVoltage (+0.0f , -0.0f );
118
+ rightRearTalon .configNominalOutputVoltage (+0.0f , -0.0f );
119
+ leftFrontTalon .configPeakOutputVoltage (+12.0 , -12.0 );
120
+ leftRearTalon .configPeakOutputVoltage (+12.0 , -12.0 );
121
+ rightFrontTalon .configPeakOutputVoltage (+12.0 , -12.0 );
122
+ rightRearTalon .configPeakOutputVoltage (+12.0 , -12.0 );
123
+
124
+ // configure current limits
125
+ // enabled = true
126
+ // 40 = limit (amps)
127
+ // 60 = trigger_threshold (amps)
128
+ // 0.5 = threshold time(s)
129
+ leftFrontTalon .configSupplyCurrentLimit (new SupplyCurrentLimitConfiguration (true , 40 , 60 , 0.5 ));
130
+ leftRearTalon .configSupplyCurrentLimit (new SupplyCurrentLimitConfiguration (true , 40 , 60 , 0.5 ));
131
+ rightFrontTalon .configSupplyCurrentLimit (new SupplyCurrentLimitConfiguration (true , 40 , 60 , 0.5 ));
132
+ rightRearTalon .configSupplyCurrentLimit (new SupplyCurrentLimitConfiguration (true , 40 , 60 , 0.5 ));
133
+
113
134
// set rear talons to follow their respective front talons
114
135
leftRearTalon .follow (leftFrontTalon );
115
136
rightRearTalon .follow (rightFrontTalon );
@@ -247,13 +268,6 @@ public void setHeadingCorrectionMode(final boolean useHeadingCorrection) {
247
268
}
248
269
249
270
private void resetAndEnableHeadingPID () {
250
- // if (Robot.shifter.getGear() == Shifter.HIGH_GEAR) {
251
- m_HeadingPid .setP (HEADING_PID_P );
252
- // } else
253
- // {
254
- // low gear
255
- // m_HeadingPid.setP(HEADING_PID_P_FOR_LOW_GEAR);
256
- // }
257
271
m_HeadingPid .reset ();
258
272
m_HeadingPid .enable ();
259
273
}
@@ -606,6 +620,8 @@ private double maintainHeading() {
606
620
607
621
// check for major heading changes and take action to prevent
608
622
// integral windup if there is a major heading error
623
+ // TODO: In 2020, this code was causing "wandering" with non-zero HEADING_PID_I.
624
+ // Worked around issue by setting HEADING_PID_I = 0
609
625
if (Math .abs (m_HeadingError .m_Error ) > 10.0 ) {
610
626
if (!m_HeadingPidPreventWindup ) {
611
627
m_HeadingPid .setI (0.0 );
@@ -614,7 +630,7 @@ private double maintainHeading() {
614
630
}
615
631
} else {
616
632
m_HeadingPidPreventWindup = false ;
617
- m_HeadingPid .setI (0.001 );
633
+ m_HeadingPid .setI (HEADING_PID_I );
618
634
}
619
635
620
636
return headingCorrection ;
@@ -676,6 +692,11 @@ public void updateSmartDashboard() {
676
692
SmartDashboard .putNumber ("Left Talon Output Voltage" , leftFrontTalon .getMotorOutputVoltage ());
677
693
SmartDashboard .putNumber ("Right Talon Output Voltage" , rightFrontTalon .getMotorOutputVoltage ());
678
694
695
+ SmartDashboard .putNumber ("LF Falcon Supply Current" , leftFrontTalon .getSupplyCurrent ());
696
+ SmartDashboard .putNumber ("LR Falcon Supply Current" , leftRearTalon .getSupplyCurrent ());
697
+ SmartDashboard .putNumber ("RF Falcon Supply Current" , rightFrontTalon .getSupplyCurrent ());
698
+ SmartDashboard .putNumber ("RR Falcon Supply Current" , rightRearTalon .getSupplyCurrent ());
699
+
679
700
SmartDashboard .putBoolean ("Closed Loop Mode" , m_closedLoopMode );
680
701
SmartDashboard .putBoolean ("Speed Racer Drive Mode" , m_speedRacerDriveMode );
681
702
0 commit comments