Skip to content

Commit d01872a

Browse files
Changes from first night after GSD event: (1) added current limits to drive motor code, (2) tuned heading correction code in drive to drive straight without wandering, and (3) added some "DriveStraightOnHeading()" commands to the driver pad "start" and "back" buttons for testing.
1 parent f2e2406 commit d01872a

File tree

3 files changed

+40
-17
lines changed

3 files changed

+40
-17
lines changed

src/main/java/org/mayheminc/robot2020/RobotContainer.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
import org.mayheminc.robot2020.autonomousroutines.*;
2121
import org.mayheminc.robot2020.commands.*;
22+
import org.mayheminc.robot2020.commands.DriveStraightOnHeading.DistanceUnits;
2223
import org.mayheminc.robot2020.subsystems.*;
2324

2425
/**
@@ -196,14 +197,15 @@ private void configureDriverPadButtons() {
196197
DRIVER_PAD.DRIVER_PAD_RED_BUTTON.whenPressed(new ShooterWheelSetVBus(0.0));
197198
DRIVER_PAD.DRIVER_PAD_YELLOW_BUTTON.whenPressed(new ShooterWheelSet(ShooterWheel.INITIATION_LINE_SPEED));
198199

199-
DRIVER_PAD.DRIVER_PAD_BACK_BUTTON.whileHeld(new DriveStraight(0.1));
200-
201200
DRIVER_PAD.DRIVER_PAD_LEFT_UPPER_TRIGGER_BUTTON.whenHeld(new ShooterFiringSequence(60.0));
202201
DRIVER_PAD.DRIVER_PAD_LEFT_UPPER_TRIGGER_BUTTON.whenReleased(new ShooterCeaseFire());
203202

204203
DRIVER_PAD.DRIVER_PAD_LEFT_LOWER_TRIGGER_BUTTON.whileHeld(new ShooterCloseFiringSequence(60.0));
205204
DRIVER_PAD.DRIVER_PAD_LEFT_LOWER_TRIGGER_BUTTON.whenReleased(new ShooterCeaseFire());
206205

206+
DRIVER_PAD.DRIVER_PAD_BACK_BUTTON.whenPressed(new DriveStraightOnHeading(-0.3, DistanceUnits.INCHES, 240, 0));
207+
DRIVER_PAD.DRIVER_PAD_START_BUTTON.whenPressed(new DriveStraightOnHeading(0.3, DistanceUnits.INCHES, 240, 0));
208+
207209
// DRIVER_PAD.DRIVER_PAD_LEFT_LOWER_TRIGGER_BUTTON.whileHeld(new
208210
// FeederSet(1.0));
209211

src/main/java/org/mayheminc/robot2020/autonomousroutines/StartBWTrench.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public StartBWTrench(double extraDistance) {
2626
addCommands(new StartBWShoot3());
2727

2828
// then, drive to the trench entrance (jog left a little to get there)
29-
addCommands(new DriveStraightOnHeading(0.4, DistanceUnits.INCHES, 46, 140));
29+
addCommands(new DriveStraightOnHeading(0.4, DistanceUnits.INCHES, 30, 140));
3030

3131
// pick up balls while heading down the trench.
3232
addCommands(new ParallelCommandGroup(
@@ -35,7 +35,7 @@ public StartBWTrench(double extraDistance) {
3535
// ensure the hood is down
3636
new HoodSetAbsWhileHeld(Hood.STARTING_POSITION),
3737
// drive the path under the control panel to the end
38-
new DriveStraightOnHeading(0.3, DistanceUnits.INCHES, 140 + extraDistance, 180)));
38+
new DriveStraightOnHeading(0.3, DistanceUnits.INCHES, 148 + extraDistance, 180)));
3939

4040
// now driven to the balls at far end of trench
4141
addCommands(new Wait(0.8), // wait for last two balls to get into robot
@@ -44,7 +44,7 @@ public StartBWTrench(double extraDistance) {
4444

4545
// after getting all three balls, go back to shooting position
4646
// first, make sure we drive straight out from under the control panel
47-
addCommands(new DriveStraightOnHeading(-0.6, DistanceUnits.INCHES, 8 + extraDistance, 180));
47+
addCommands(new DriveStraightOnHeading(-0.6, DistanceUnits.INCHES, 16 + extraDistance, 180));
4848
addCommands(new IntakeSetRollers(0.0)); // turn off the intake in case it has been stalled for a while
4949

5050
// drive diagonally over towards the shooting position, while turning on shooter

src/main/java/org/mayheminc/robot2020/subsystems/Drive.java

Lines changed: 33 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,9 @@ public class Drive extends SubsystemBase implements PidTunerObject {
5151
// NavX parameters
5252
private double m_desiredHeading = 0.0;
5353
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
5657
private static final double kToleranceDegreesPIDControl = 0.2;
5758

5859
// Drive parameters
@@ -97,8 +98,8 @@ public Drive() {
9798
m_HeadingError = new PIDHeadingError();
9899
m_HeadingError.m_Error = 0.0;
99100
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 */);
102103
m_HeadingPid.setInputRange(-180.0f, 180.0f);
103104
m_HeadingPid.setContinuous(true); // treats the input range as "continous" with wrap-around
104105
m_HeadingPid.setOutputRange(-.50, .50); // set the maximum power to correct twist
@@ -110,6 +111,26 @@ public Drive() {
110111
rightFrontTalon.setNeutralMode(NeutralMode.Coast);
111112
rightRearTalon.setNeutralMode(NeutralMode.Coast);
112113

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+
113134
// set rear talons to follow their respective front talons
114135
leftRearTalon.follow(leftFrontTalon);
115136
rightRearTalon.follow(rightFrontTalon);
@@ -247,13 +268,6 @@ public void setHeadingCorrectionMode(final boolean useHeadingCorrection) {
247268
}
248269

249270
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-
// }
257271
m_HeadingPid.reset();
258272
m_HeadingPid.enable();
259273
}
@@ -606,6 +620,8 @@ private double maintainHeading() {
606620

607621
// check for major heading changes and take action to prevent
608622
// 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
609625
if (Math.abs(m_HeadingError.m_Error) > 10.0) {
610626
if (!m_HeadingPidPreventWindup) {
611627
m_HeadingPid.setI(0.0);
@@ -614,7 +630,7 @@ private double maintainHeading() {
614630
}
615631
} else {
616632
m_HeadingPidPreventWindup = false;
617-
m_HeadingPid.setI(0.001);
633+
m_HeadingPid.setI(HEADING_PID_I);
618634
}
619635

620636
return headingCorrection;
@@ -676,6 +692,11 @@ public void updateSmartDashboard() {
676692
SmartDashboard.putNumber("Left Talon Output Voltage", leftFrontTalon.getMotorOutputVoltage());
677693
SmartDashboard.putNumber("Right Talon Output Voltage", rightFrontTalon.getMotorOutputVoltage());
678694

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+
679700
SmartDashboard.putBoolean("Closed Loop Mode", m_closedLoopMode);
680701
SmartDashboard.putBoolean("Speed Racer Drive Mode", m_speedRacerDriveMode);
681702

0 commit comments

Comments
 (0)