@@ -112,7 +112,7 @@ public RobotMap() {
112112 dtLeft = new SpeedControllerGroup (dtLeftMaster , dtLeftSlave );
113113
114114 leftVelocityController = new VelocityPIDController (Robot .getConst ("VelocityLeftkP" , 1 ),
115- Robot .getConst ("VelocityLeftkI" , 0 ), Robot .getConst ("VelocityLeftkD" , 0 ),
115+ Robot .getConst ("VelocityLeftkI" , 0 ), Robot .getConst ("VelocityLeftkD" , calcDefkD () ),
116116 1 / Robot .getConst ("Max Low Speed" , 84 ), leftEncRate , dtLeft );
117117 leftVelocityController .enable ();
118118 leftVelocityController .setInputRange (-Robot .getConst ("Max High Speed" , 204 ),
@@ -134,7 +134,7 @@ public RobotMap() {
134134 dtRight = new SpeedControllerGroup (dtRightMaster , dtRightSlave );
135135
136136 rightVelocityController = new VelocityPIDController (Robot .getConst ("VelocityRightkP" , 1 ),
137- Robot .getConst ("VelocityRightkI" , 0 ), Robot .getConst ("VelocityRightkD" , 0 ),
137+ Robot .getConst ("VelocityRightkI" , 0 ), Robot .getConst ("VelocityRightkD" , calcDefkD () ),
138138 1 / Robot .getConst ("Max Low Speed" , 84 ), rightEncRate , dtRight );
139139 rightVelocityController .enable ();
140140 rightVelocityController .setInputRange (-Robot .getConst ("Max High Speed" , 204 ),
@@ -168,4 +168,15 @@ public int getPort(String key, int def) {
168168 return (int ) SmartDashboard .getNumber ("Port/" + key , def );
169169 }
170170
171+ /**
172+ * Uses SmartDashboard and math to calculate a *great* default kD
173+ */
174+ public double calcDefkD () {
175+ double timeConstant = Robot .getConst ("Omega Max" , 5330 ) * Robot .getConst ("Mass of Robot" , 54.4311 )
176+ * Robot .getConst ("Radius of Drivetrain Wheel" , 0.0635 )
177+ * Robot .getConst ("Radius of Drivetrain Wheel" , 0.0635 ) / Robot .getConst ("Stall Torque" , 2.41 );
178+ double cycleTime = Robot .getConst ("Code cycle time" , 0.1 );
179+ double denominator = 1 - Math .pow (Math .E , -1 * cycleTime / timeConstant );
180+ return 1 / denominator ;
181+ }
171182}
0 commit comments