From 91fbfb7af372693e84ee74b8223c16a765a3d2f9 Mon Sep 17 00:00:00 2001 From: C4llSiqn Date: Tue, 12 Mar 2024 19:08:49 -0600 Subject: [PATCH] Java doc my NEO auto joystick system. --- .../commands/Swerve/neoJoystickPlayback.java | 42 +++++++++++++++++++ .../commands/Swerve/neoJoystickRecorder.java | 16 +++++++ .../utility/controller/VirtualController.java | 35 ++++++++++++++++ 3 files changed, 93 insertions(+) diff --git a/src/main/java/frc4388/robot/commands/Swerve/neoJoystickPlayback.java b/src/main/java/frc4388/robot/commands/Swerve/neoJoystickPlayback.java index a5ab006..8b5afdf 100644 --- a/src/main/java/frc4388/robot/commands/Swerve/neoJoystickPlayback.java +++ b/src/main/java/frc4388/robot/commands/Swerve/neoJoystickPlayback.java @@ -12,6 +12,11 @@ import frc4388.utility.UtilityStructs.AutoRecordingControllerFrame; import frc4388.utility.UtilityStructs.AutoRecordingFrame; import frc4388.utility.controller.VirtualController; + +/** + * The NEO autonomus playback system, designed based the old {@link JoystickPlayback} System but with {@link VirtualController}s + * @author Zachary Wilke + */ public class neoJoystickPlayback extends Command { private final SwerveDrive swerve; private final VirtualController[] controllers; @@ -29,6 +34,14 @@ public class neoJoystickPlayback extends Command { private byte m_numControllers = 0; private short m_numFrames = -1; + /** + * Creates an new NEO Joystick Playback with specifyed pramiters. + * @param swerve m_robotSwerveDrive + * @param filenameGetter a String Supplier, designed for quickly changing auto names in shuffle board. + * @param controllers an Order-Specific Array of Virtual controllers, index 0 means driver, index 1 means operator, etc. + * @param shouldfree Unloads the auto on compleation or intruption. + * @param instantload Load the auto on object instantiation + */ public neoJoystickPlayback(SwerveDrive swerve, Supplier filenameGetter, VirtualController[] controllers, boolean shouldfree, boolean instantload) { this.swerve = swerve; this.filenameGetter = filenameGetter; @@ -38,18 +51,44 @@ public class neoJoystickPlayback extends Command { if (instantload) loadAuto(); addRequirements(this.swerve); } + + /** + * Creates an new NEO Joystick Playback with specifyed pramiters. + * @param swerve m_robotSwerveDrive + * @param filename a String containing the name of the auto file you wish to playback. + * @param controllers an Order-Specific Array of Virtual controllers, index 0 means driver, index 1 means operator, etc. + * @param shouldfree unloads the auto on compleation or intruption. + * @param instantload load the auto on object instantiation + */ public neoJoystickPlayback(SwerveDrive swerve, String filename, VirtualController[] controllers, boolean shouldfree, boolean instantload) { this(swerve, () -> filename, controllers, shouldfree, instantload); } + /** + * Creates an new NEO Joystick Playback with specifyed pramiters. + * @param swerve m_robotSwerveDrive + * @param filenameGetter a String Supplier, designed for quickly changing auto names in shuffle board. + * @param controllers an Order-Specific Array of Virtual controllers, index 0 means driver, index 1 means operator, etc. + */ public neoJoystickPlayback(SwerveDrive swerve, Supplier filenameGetter, VirtualController[] controllers) { this(swerve, filenameGetter, controllers, true, false); } + /** + * Creates an new NEO Joystick Playback with specifyed pramiters. + * @param swerve m_robotSwerveDrive + * @param filename a String containing the name of the auto file you wish to playback. + * @param controllers an Order-Specific Array of Virtual controllers, index 0 means driver, index 1 means operator, etc. + */ public neoJoystickPlayback(SwerveDrive swerve, String filename, VirtualController[] controllers) { this(swerve, () -> filename, controllers, true, false); } + /** + * Load the auto file from disk into memory + * @return Returns true if loading was successful, else wise; return false + * @implNote if the auto is already loaded, it will return true. + */ public boolean loadAuto() { filename = filenameGetter.get(); try (FileInputStream stream = new FileInputStream("/home/lvuser/autos/" + filename)) { @@ -101,6 +140,9 @@ public class neoJoystickPlayback extends Command { } } + /** + * Unloads the auto. + */ public void unloadAuto() { System.out.println("AUTOPLAYBACK: Auto unloaded"); frames.clear(); diff --git a/src/main/java/frc4388/robot/commands/Swerve/neoJoystickRecorder.java b/src/main/java/frc4388/robot/commands/Swerve/neoJoystickRecorder.java index d1870ec..7f48a6c 100644 --- a/src/main/java/frc4388/robot/commands/Swerve/neoJoystickRecorder.java +++ b/src/main/java/frc4388/robot/commands/Swerve/neoJoystickRecorder.java @@ -13,6 +13,10 @@ import frc4388.utility.UtilityStructs.AutoRecordingControllerFrame; import frc4388.utility.UtilityStructs.AutoRecordingFrame; import frc4388.utility.controller.DeadbandedXboxController; +/** + * The NEO autonomus recording system, designed based the old {@link JoystickRecorder} System but with {@link frc4388.utility.controller.VirtualController VirtualController}s + * @author Zachary Wilke + */ public class neoJoystickRecorder extends Command { private final SwerveDrive swerve; private final XboxController[] controllers; @@ -21,6 +25,12 @@ public class neoJoystickRecorder extends Command { private long startTime = -1; private final ArrayList frames = new ArrayList<>(); + /** + * Creates an new NEO Joystick Playback with specifyed pramiters. + * @param swerve m_robotSwerveDrive + * @param controllers an Order-Specific Array of Virtual controllers, index 0 means driver, index 1 means operator, etc. + * @param filenameGetter a String Supplier, designed for quickly changing auto names in shuffle board. + */ public neoJoystickRecorder(SwerveDrive swerve, DeadbandedXboxController[] controllers, Supplier filenameGetter) { this.swerve = swerve; this.controllers = controllers; @@ -30,6 +40,12 @@ public class neoJoystickRecorder extends Command { addRequirements(this.swerve); } + /** + * Creates an new NEO Joystick Playback with specifyed pramiters. + * @param swerve m_robotSwerveDrive + * @param controllers an Order-Specific Array of Virtual controllers, index 0 means driver, index 1 means operator, etc. + * @param filename a String containing the name of the auto file you wish to playback. + */ public neoJoystickRecorder(SwerveDrive swerve, DeadbandedXboxController[] controllers, String filename) { this(swerve, controllers, () -> filename); } diff --git a/src/main/java/frc4388/utility/controller/VirtualController.java b/src/main/java/frc4388/utility/controller/VirtualController.java index 12e98cf..709bc1d 100644 --- a/src/main/java/frc4388/utility/controller/VirtualController.java +++ b/src/main/java/frc4388/utility/controller/VirtualController.java @@ -2,22 +2,39 @@ package frc4388.utility.controller; import edu.wpi.first.wpilibj.GenericHID; +/** + * A virtual controller that can be bound like an standard controller. + * @author Zachary Wilke + */ public class VirtualController extends GenericHID { private short m_buttonStates = 0; private short m_buttonStatesLastFrame = 0; private double[] m_axes = new double[6]; private short[] m_pov = new short[1]; + /** + * Create an virtual controller + * @param port virtual port (merely a formality). + */ public VirtualController(int port) { super(port); } + /** + * Set the curent inputs to the new frames. + * @param axes joystick axes, (i.e. joysticks and triggers). + * @param buttonFlags the bit packed button states. + * @param pov the array of dpads. + */ public void setFrame(double[] axes, short buttonFlags, short[] pov) { m_axes = axes; setOutputs(buttonFlags); m_pov = pov; } + /** + * Zero outs the controls. + */ public void zeroControls() { m_axes = new double[6]; m_buttonStates = 0; @@ -25,6 +42,12 @@ public class VirtualController extends GenericHID { m_pov = new short[1]; } + /** + * Gets the value of a bitflag from an int + * @param value int to search + * @param index index of bit + * @return if the bit is set + */ public static boolean getFlag(int value, int index) { return ((value & 1 << index) != 0); } @@ -90,6 +113,10 @@ public class VirtualController extends GenericHID { Hopefully this isn't a problem */ } + /** + * Use {@link VirtualController#setFrame} or {@link VirtualController#setOutputs}. + * this is an no-op overide. + */ @Override public void setOutput(int outputNumber, boolean value) { // do not use @@ -97,12 +124,20 @@ public class VirtualController extends GenericHID { //m_buttonStates[outputNumber - 1] = value; } + /** + * Set buttons from a packed int, if you want to set joysticks and dpad use {@link VirtualController#SetFrame} + */ @Override public void setOutputs(int value) { m_buttonStatesLastFrame = m_buttonStates; m_buttonStates = (short) value; } + /** + * Why are you Setting rumble on an virtual controller? + * @param type the rumble type (even though it won't do anything) + * @param value the rumble strength (always multiplyed by 0.0) + */ @Override public void setRumble(RumbleType type, double value) { System.out.println("Why are you Setting rumble on an virtual controller?");