last nights changes

This commit is contained in:
Abhishrek05
2024-03-11 10:19:02 -06:00
parent 491c5ad30f
commit 19197b5850
2 changed files with 15 additions and 7 deletions
@@ -354,7 +354,7 @@ public class RobotContainer {
new JoystickButton(m_autoRecorderXbox, XboxController.RIGHT_BUMPER_BUTTON) new JoystickButton(m_autoRecorderXbox, XboxController.RIGHT_BUMPER_BUTTON)
.onTrue(new neoJoystickPlayback(m_robotSwerveDrive, .onTrue(new neoJoystickPlayback(m_robotSwerveDrive,
autoplaybackName.get(), () -> autoplaybackName.get(),
new VirtualController[]{getVirtualDriverController(), getVirtualOperatorController()}, new VirtualController[]{getVirtualDriverController(), getVirtualOperatorController()},
true, false)) true, false))
.onFalse(new InstantCommand()); .onFalse(new InstantCommand());
@@ -16,8 +16,8 @@ public class neoJoystickPlayback extends Command {
private final SwerveDrive swerve; private final SwerveDrive swerve;
private final VirtualController[] controllers; private final VirtualController[] controllers;
private final ArrayList<AutoRecordingFrame> frames = new ArrayList<>(); private final ArrayList<AutoRecordingFrame> frames = new ArrayList<>();
//private final Supplier<String> filenameGetter; private final Supplier<String> filenameGetter;
private final String filename; private String filename;
private int frame_index = 0; private int frame_index = 0;
private long startTime = 0; private long startTime = 0;
private long playbackTime = 0; private long playbackTime = 0;
@@ -29,21 +29,29 @@ public class neoJoystickPlayback extends Command {
private byte m_numControllers = 0; private byte m_numControllers = 0;
private short m_numFrames = -1; private short m_numFrames = -1;
public neoJoystickPlayback(SwerveDrive swerve, String filename, VirtualController[] controllers, boolean shouldfree, boolean instantload) { public neoJoystickPlayback(SwerveDrive swerve, Supplier<String> filenameGetter, VirtualController[] controllers, boolean shouldfree, boolean instantload) {
this.swerve = swerve; this.swerve = swerve;
this.filename = filename; this.filenameGetter = filenameGetter;
this.controllers = controllers; this.controllers = controllers;
this.m_shouldfree = shouldfree; this.m_shouldfree = shouldfree;
if (instantload) loadAuto(); if (instantload) loadAuto();
addRequirements(this.swerve); addRequirements(this.swerve);
} }
public neoJoystickPlayback(SwerveDrive swerve, String filename, VirtualController[] controllers, boolean shouldfree, boolean instantload) {
this(swerve, () -> filename, controllers, shouldfree, instantload);
}
public neoJoystickPlayback(SwerveDrive swerve, Supplier<String> filenameGetter, VirtualController[] controllers) {
this(swerve, filenameGetter, controllers, true, false);
}
public neoJoystickPlayback(SwerveDrive swerve, String filename, VirtualController[] controllers) { public neoJoystickPlayback(SwerveDrive swerve, String filename, VirtualController[] controllers) {
this(swerve, filename, controllers, true, false); this(swerve, () -> filename, controllers, true, false);
} }
public boolean loadAuto() { public boolean loadAuto() {
filename = filenameGetter.get();
try (FileInputStream stream = new FileInputStream("/home/lvuser/autos/" + filename)) { try (FileInputStream stream = new FileInputStream("/home/lvuser/autos/" + filename)) {
if (m_numFrames != -1 && m_numFrames == frames.size()) { if (m_numFrames != -1 && m_numFrames == frames.size()) {
System.out.println("AUTOPLAYBACK: Auto Already loaded."); System.out.println("AUTOPLAYBACK: Auto Already loaded.");
@@ -137,7 +145,7 @@ public class neoJoystickPlayback extends Command {
public void end(boolean interrupted) { public void end(boolean interrupted) {
for (VirtualController controller : controllers) controller.zeroControls(); for (VirtualController controller : controllers) controller.zeroControls();
swerve.stopModules(); swerve.stopModules();
if (m_shouldfree) frames.clear(); if (m_shouldfree) unloadAuto();
} }
@Override @Override