Skip to content

Commit b92f05e

Browse files
authored
Merge pull request #120 from strykeforce/frost-hotfix
Frost hotfix
2 parents d04cb66 + f59814b commit b92f05e

File tree

7 files changed

+119
-9
lines changed

7 files changed

+119
-9
lines changed

src/main/deploy/paths/pieceTwoToDockPath.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
max_velocity = 1.5 #m/s
22
max_acceleration = 2.0 #m/s
33
start_velocity = 0.0 #m/s
4-
end_velocity = 1.0 #m/s
4+
end_velocity = 1.1 #m/s
55
is_reversed = false
66
target_yaw = 0.0 #degrees
77

src/main/java/frc/robot/Constants.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ public static Translation2d[] getWheelLocationMeters() {
229229

230230
public static final double kAutoBalanceSlowDriveVel = 0.35; // 0.6
231231
public static final double kAutoBalanceRecoveryDriveVel = 0.25;
232-
public static final double kAutoBalanceFinalDriveVel = 1.0; // 0.5 0.75
232+
public static final double kAutoBalanceFinalDriveVel = 1.1; // 0.5 0.75
233233
public static final double kAutoBalanceSlowdownTimeSec = 1.0; // 1.3-> 1.15
234234
public static final double kAutoBalanceStopThresholdDegrees = 1.5; // 1 0.6 1.5
235235
public static final double kAutoBalanceEdgeTriggerThreshold = 3; // 5

src/main/java/frc/robot/Robot.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ public void disabledPeriodic() {
7474
if (!mappedDriveJoystick) {
7575
String joystick = DriverStation.getJoystickName(0);
7676
if (lastJoystick != joystick) {
77-
System.out.println("Joystick Name: " + joystick);
77+
// System.out.println("Joystick Name: " + joystick);
7878
mappedDriveJoystick = m_robotContainer.configureDriverButtonBindings();
7979
}
8080
lastJoystick = joystick;

src/main/java/frc/robot/RobotContainer.java

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@
5858
import frc.robot.commands.robotState.ShuffleBoardHealthCheckIntakeCommandGroup;
5959
import frc.robot.commands.robotState.StowRobotCommand;
6060
import frc.robot.commands.robotState.ToggleIntakeCommand;
61+
import frc.robot.commands.robotState.ToggleVirtualSwitchCommand;
6162
import frc.robot.commands.shoulder.ShoulderSpeedCommand;
6263
import frc.robot.commands.shoulder.StopTwistCommand;
6364
import frc.robot.commands.shoulder.TwistShoulderCommand;
@@ -277,7 +278,7 @@ public boolean configureDriverButtonBindings() {
277278
success = true;
278279
break;
279280
default:
280-
logger.info("No joystick type {} defined", joystick);
281+
// logger.info("No joystick type {} defined", joystick);
281282
break;
282283
}
283284
return success;
@@ -516,7 +517,6 @@ private void configureMatchDashboard() {
516517
.addBoolean("Update With Vision True", () -> driveSubsystem.visionUpdates)
517518
.withSize(1, 1)
518519
.withPosition(4, 0);
519-
520520
Shuffleboard.getTab("Match")
521521
.addBoolean("IsRight", () -> robotStateSubsystem.getTargetCol() == TargetCol.RIGHT)
522522
.withSize(1, 1)
@@ -541,6 +541,22 @@ private void configureMatchDashboard() {
541541
.addBoolean("Is Navx Connected", () -> driveSubsystem.isNavxWorking())
542542
.withSize(1, 1)
543543
.withPosition(8, 1);
544+
Shuffleboard.getTab("Match")
545+
.addString("AutoSwitchPos", () -> autoSwitch.getSwitchPos())
546+
.withSize(1, 1)
547+
.withPosition(0, 2);
548+
Shuffleboard.getTab("Match")
549+
.add("VirtualAutonSwitch", autoSwitch.getSendableChooser())
550+
.withSize(1, 1)
551+
.withPosition(1, 2);
552+
Shuffleboard.getTab("Match")
553+
.add("ToggleVirtualSwitch", new ToggleVirtualSwitchCommand(autoSwitch))
554+
.withSize(1, 1)
555+
.withPosition(2, 2);
556+
Shuffleboard.getTab("Match")
557+
.addBoolean("VirtualSwitchUsed?", () -> autoSwitch.isUseVirtualSwitch())
558+
.withSize(1, 1)
559+
.withPosition(3, 2);
544560
}
545561

546562
private void configurePitDashboard() {
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package frc.robot.commands.robotState;
2+
3+
import edu.wpi.first.wpilibj2.command.InstantCommand;
4+
import frc.robot.subsystems.AutoSwitch;
5+
import org.slf4j.Logger;
6+
import org.slf4j.LoggerFactory;
7+
8+
public class ToggleVirtualSwitchCommand extends InstantCommand {
9+
private AutoSwitch autoSwitch;
10+
private static Logger logger;
11+
12+
public ToggleVirtualSwitchCommand(AutoSwitch autoSwitch) {
13+
this.autoSwitch = autoSwitch;
14+
logger = LoggerFactory.getLogger(ToggleVirtualSwitchCommand.class);
15+
}
16+
17+
@Override
18+
public void initialize() {
19+
autoSwitch.toggleVirtualSwitch();
20+
logger.info("toggledSwitch:command");
21+
}
22+
23+
@Override
24+
public boolean isFinished() {
25+
return true;
26+
}
27+
28+
@Override
29+
public boolean runsWhenDisabled() {
30+
return true;
31+
}
32+
}

src/main/java/frc/robot/subsystems/AutoSwitch.java

Lines changed: 53 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
import edu.wpi.first.wpilibj.DigitalInput;
44
import edu.wpi.first.wpilibj.DriverStation;
5+
import edu.wpi.first.wpilibj.smartdashboard.SendableChooser;
6+
import edu.wpi.first.wpilibj.smartdashboard.SmartDashboard;
57
import frc.robot.Constants.AutonConstants;
68
import frc.robot.commands.auto.AutoCommandInterface;
79
import frc.robot.commands.auto.DefaultAutoCommand;
@@ -19,17 +21,21 @@
1921
import frc.robot.commands.auto.TwoPieceWithDockAutoCommandGroup;
2022
import frc.robot.commands.auto.TwoPieceWithDockAutoMidCommandGroup;
2123
import java.util.ArrayList;
24+
import java.util.Set;
2225
import org.slf4j.Logger;
2326
import org.slf4j.LoggerFactory;
27+
import org.strykeforce.telemetry.measurable.MeasurableSubsystem;
28+
import org.strykeforce.telemetry.measurable.Measure;
2429
import org.strykeforce.thirdcoast.util.AutonSwitch;
2530

26-
public class AutoSwitch {
31+
public class AutoSwitch extends MeasurableSubsystem {
2732
private final AutonSwitch autoSwitch;
2833
private ArrayList<DigitalInput> switchInputs = new ArrayList<>();
2934
private int currAutoSwitchPos = -1;
3035
private int newAutoSwitchPos;
3136
private int autoSwitchStableCounts = 0;
3237
private Logger logger = LoggerFactory.getLogger(AutoSwitch.class);
38+
private static SendableChooser<Integer> sendableChooser = new SendableChooser<>();
3339

3440
private AutoCommandInterface autoCommand;
3541
private final RobotStateSubsystem robotStateSubsystem;
@@ -43,6 +49,7 @@ public class AutoSwitch {
4349
private final VisionSubsystem visionSubsystem;
4450
private final RGBlightsSubsystem rgBlightsSubsystem;
4551
AutoCommandInterface defaultCommand;
52+
private boolean useVirtualSwitch = false;
4653

4754
public AutoSwitch(
4855
RobotStateSubsystem robotStateSubsystem,
@@ -66,6 +73,21 @@ public AutoSwitch(
6673
this.visionSubsystem = visionSubsystem;
6774
this.rgBlightsSubsystem = rgBlightsSubsystem;
6875

76+
sendableChooser.addOption("00 Cone Lvl 3, Cube Lvl 3, Auto Balance", 0x00);
77+
sendableChooser.setDefaultOption("01 Cone Lvl 3, Cube Lvl 3", 0x01);
78+
sendableChooser.setDefaultOption("02 Same as #1 but scores cone mid", 0x02);
79+
sendableChooser.setDefaultOption("03 Cone lvl 3, Cube lvl 3, Cube lvl 2", 0x03);
80+
sendableChooser.setDefaultOption("10 Cone lvl 3, cube lvl 3, balance", 0x10);
81+
sendableChooser.setDefaultOption("11 Middle to dock", 0x11);
82+
sendableChooser.setDefaultOption("12 Middle to dock with mobility", 0x12);
83+
sendableChooser.setDefaultOption("20 Cone Lvl 3, Cube Lvl 3", 0x20);
84+
sendableChooser.setDefaultOption("21 FALLBACK - Cone Lvl 3, cube lvl 2 and 3", 0x21);
85+
sendableChooser.setDefaultOption("22 Cone Lvl3, Cube Lvl3", 0x22);
86+
sendableChooser.setDefaultOption("23 Cone Lvl 3, cube lvl 2 and 3", 0x23);
87+
sendableChooser.setDefaultOption("24 Cone Lvl 1, Cube Lvl 3 and 2", 0x24);
88+
sendableChooser.setDefaultOption("30 Do nothing", 0x30);
89+
SmartDashboard.putData("Auto Mode", sendableChooser);
90+
6991
defaultCommand =
7092
new DefaultAutoCommand(
7193
driveSubsystem, robotStateSubsystem, elevatorSubsystem, handSubsystem, armSubsystem);
@@ -100,7 +122,7 @@ public AutoCommandInterface getAutoCommand() {
100122

101123
private boolean hasSwitchChanged() {
102124
boolean changed = false;
103-
int switchPos = autoSwitch.position();
125+
int switchPos = useVirtualSwitch ? sendableChooser.getSelected() : autoSwitch.position();
104126

105127
if (switchPos != newAutoSwitchPos) {
106128
autoSwitchStableCounts = 0;
@@ -116,6 +138,28 @@ private boolean hasSwitchChanged() {
116138
return changed;
117139
}
118140

141+
public void toggleVirtualSwitch() {
142+
logger.info("toggledSwitch:function");
143+
if (useVirtualSwitch) {
144+
useVirtualSwitch = false;
145+
} else {
146+
useVirtualSwitch = true;
147+
}
148+
// useVirtualSwitch = useVirtualSwitch ? false : true;
149+
}
150+
151+
public String getSwitchPos() {
152+
return Integer.toHexString(currAutoSwitchPos);
153+
}
154+
155+
public boolean isUseVirtualSwitch() {
156+
return useVirtualSwitch;
157+
}
158+
159+
public SendableChooser<Integer> getSendableChooser() {
160+
return sendableChooser;
161+
}
162+
119163
private AutoCommandInterface getAutoCommand(int switchPos) {
120164
switch (switchPos) {
121165
// Non-Bump Side
@@ -292,4 +336,11 @@ private AutoCommandInterface getAutoCommand(int switchPos) {
292336
driveSubsystem, robotStateSubsystem, elevatorSubsystem, handSubsystem, armSubsystem);
293337
}
294338
}
339+
340+
@Override
341+
public Set<Measure> getMeasures() {
342+
return Set.of(
343+
new Measure("AutoSwitch", () -> currAutoSwitchPos),
344+
new Measure("usingVirtualSwitch", () -> this.useVirtualSwitch ? 1.0 : 0.0));
345+
}
295346
}

src/main/java/frc/robot/subsystems/DriveSubsystem.java

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -736,8 +736,19 @@ public void periodic() {
736736
} else {
737737
drive(0, 0, 0);
738738
xLock();
739-
logger.info("{} -> AUTO_BALANCE_FINISHED", currDriveState);
740-
currDriveState = DriveStates.AUTO_BALANCE_FINISHED;
739+
740+
logger.info(
741+
"AutoBalance Stop: Gyro Roll: {}, trigger Difference: {}",
742+
getGyroPitch(),
743+
Math.abs(avgStartingRoll) - Math.abs(getGyroPitch()));
744+
logger.info("{} -> AUTO_BALANCE_RECOVERY", currDriveState);
745+
currDriveState = DriveStates.AUTO_BALANCE_RECOVERY;
746+
747+
autoBalanceRecoveryTimer.reset();
748+
autoBalanceRecoveryTimer.start();
749+
recoveryStartingPitchSet = false;
750+
// logger.info("{} -> AUTO_BALANCE_FINISHED", currDriveState);
751+
// currDriveState = DriveStates.AUTO_BALANCE_FINISHED;
741752
}
742753
}
743754
break;

0 commit comments

Comments
 (0)