Skip to content
This repository was archived by the owner on Sep 14, 2019. It is now read-only.

Commit d83e7c7

Browse files
committed
PID by math setup
implemented getLiftTimeConstant and methods in it for Lift still need to implement default constant values (using more math, see PIDMove constructor) commented out stuff in testPeriodic bc don't need them
1 parent 434360b commit d83e7c7

3 files changed

Lines changed: 64 additions & 7 deletions

File tree

Robot2018/src/org/usfirst/frc/team199/Robot2018/Robot.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,7 @@ public void testInit() {
290290
@Override
291291
public void testPeriodic() {
292292
// Scheduler.getInstance().run();
293-
lift.disable();
294-
lift.runMotor(SmartDashboard.getNumber("Voltage to Lift", 0));
293+
// lift.disable();
294+
// lift.runMotor(SmartDashboard.getNumber("Voltage to Lift", 0));
295295
}
296296
}

Robot2018/src/org/usfirst/frc/team199/Robot2018/RobotMap.java

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public class RobotMap {
4343
public static DigitalSource liftEncPort1;
4444
public static DigitalSource liftEncPort2;
4545

46-
//public static WPI_TalonSRX climberMotor;
46+
// public static WPI_TalonSRX climberMotor;
4747

4848
public static VictorSP leftIntakeMotor;
4949
public static VictorSP rightIntakeMotor;
@@ -123,7 +123,7 @@ private void configSPX(WPI_VictorSPX mc) {
123123

124124
public RobotMap() {
125125
pdp = new PowerDistributionPanel();
126-
126+
127127
liftMotorA = new WPI_VictorSPX(getPort("LiftVictorSPX", 5));
128128
configSPX(liftMotorA);
129129
liftMotorB = new WPI_TalonSRX(getPort("1LiftTalonSRX", 6));
@@ -252,7 +252,10 @@ public double getRadius() {
252252
return Robot.getConst("Radius of Drivetrain Wheel", 0.0635);
253253
}
254254

255-
public double getOmegaMax() {
255+
/**
256+
* @return the RPM max of a CIM
257+
*/
258+
public static double getOmegaMax() {
256259
return Robot.getConst("Omega Max", 5330);
257260
}
258261

@@ -264,7 +267,10 @@ public double getCycleTime() {
264267
return Robot.getConst("Code cycle time", 0.05);
265268
}
266269

267-
public double getStallTorque() {
270+
/**
271+
* @return the stall torque of a CIM
272+
*/
273+
public static double getStallTorque() {
268274
return Robot.getConst("Stall Torque", 2.41);
269275
}
270276

@@ -273,7 +279,12 @@ private double convertLbsTokG(double lbs) {
273279
return lbs * 0.45359237;
274280
}
275281

276-
private double convertNtokG(double newtons) {
282+
/**
283+
* @param the
284+
* weight (in Newtons)
285+
* @return the equivalent mass (in kg)
286+
*/
287+
public static double convertNtokG(double newtons) {
277288
// weight / accel due to grav = kg
278289
return newtons / 9.81;
279290
}

Robot2018/src/org/usfirst/frc/team199/Robot2018/subsystems/Lift.java

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,14 @@ public double getWiggleRoom() {
155155
return WIGGLE_ROOM;
156156
}
157157

158+
/**
159+
* @return the max speed of the lift
160+
*/
161+
public double getLiftMaxSpeed() {
162+
/** @todo find lift max speed and set default below */
163+
return Robot.getConst("Lift Max Speed", 0);
164+
}
165+
158166
/**
159167
* Uses AMT103 Encoder to detect the current lift height with respect to the
160168
* lift's min height (inches)
@@ -176,4 +184,42 @@ protected void usePIDOutput(double output) {
176184
out += Robot.getConst("Lift: Necessary Voltage", 0);
177185
runMotor(out);
178186
}
187+
188+
/**
189+
* Gets the time constant of the drivetrain, which is used to calculate PID
190+
* constants.
191+
*
192+
* @return time constant
193+
*/
194+
public double getLiftTimeConstant() {
195+
double gearReduction = getLiftGearRatio();
196+
double radius = getLiftRadius();
197+
double timeConstant = RobotMap.getOmegaMax() / gearReduction / 60 * 2 * Math.PI
198+
* RobotMap.convertNtokG(getLiftedWeight()) * radius * radius
199+
/ (RobotMap.getStallTorque() * gearReduction);
200+
return timeConstant;
201+
}
202+
203+
/**
204+
* @return the gear ratio of the lift gearbox
205+
*/
206+
public double getLiftGearRatio() {
207+
return Robot.getConst("Lift Gear Reduction", 10);
208+
}
209+
210+
/**
211+
* @return the lift sprocket's radius
212+
*/
213+
public double getLiftRadius() {
214+
// 15 tooth, #35 sprocket
215+
return Robot.getConst("Lift Sprocket Pitch Diam", 1.79) / 2;
216+
}
217+
218+
/**
219+
* @return the weight (in Newtons) of everything that is being lifted: intake,
220+
* lift components, NOT cube
221+
*/
222+
public double getLiftedWeight() {
223+
return Robot.getConst("Weight of Lifted Stuff", 342);
224+
}
179225
}

0 commit comments

Comments
 (0)