@@ -172,10 +172,25 @@ public int getPort(String key, int def) {
172172 * Uses SmartDashboard and math to calculate a *great* default kD
173173 */
174174 public double calcDefkD () {
175- double timeConstant = Robot .getConst ("Omega Max" , 5330 ) * Robot .getConst ("Mass of Robot" , 54.4311 )
175+ /*
176+ * timeConstant is proportional to max speed of the shaft (which is the max
177+ * speed of the cim divided by the gear reduction), half the mass (because the
178+ * half of the drivetrain only has to support half of the robot), and radius of
179+ * the drivetrain wheels squared. It's inversely proportional to the stall
180+ * torque of the shaft, which is found by multiplying the stall torque of the
181+ * motor with the gear reduction.
182+ */
183+ double gearReduction = Robot .getBool ("High Gear" , false ) ? Robot .getConst ("High Gear Gear Reduction" , 5.392 )
184+ : Robot .getConst ("Low Gear Gear Reduction" , 12.255 );
185+ double timeConstant = Robot .getConst ("Omega Max" , 5330 ) / gearReduction
186+ * Robot .getConst ("Mass of Robot" , 54.4311 ) * Robot .getConst ("Radius of Drivetrain Wheel" , 0.0635 )
176187 * Robot .getConst ("Radius of Drivetrain Wheel" , 0.0635 )
177- * Robot . getConst ( "Radius of Drivetrain Wheel" , 0.0635 ) / Robot .getConst ("Stall Torque" , 2.41 );
188+ / ( Robot .getConst ("Stall Torque" , 2.41 ) * gearReduction );
178189 double cycleTime = Robot .getConst ("Code cycle time" , 0.1 );
190+ /*
191+ * The denominator of kD is 1-(e ^ -cycleTime / timeConstant). The numerator is
192+ * one.
193+ */
179194 double denominator = 1 - Math .pow (Math .E , -1 * cycleTime / timeConstant );
180195 return 1 / denominator ;
181196 }
0 commit comments