mirror of
https://github.com/Team4388/2024AcrossTheRidgebotiverse.git
synced 2026-06-08 16:28:03 -06:00
Java doc my NEO auto joystick system.
This commit is contained in:
@@ -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 <b>Order-Specific</b> 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<String> 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 <b>Order-Specific</b> 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 <b>Order-Specific</b> Array of Virtual controllers, index 0 means driver, index 1 means operator, etc.
|
||||
*/
|
||||
public neoJoystickPlayback(SwerveDrive swerve, Supplier<String> 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 <b>Order-Specific</b> 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();
|
||||
|
||||
@@ -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<AutoRecordingFrame> frames = new ArrayList<>();
|
||||
|
||||
/**
|
||||
* Creates an new NEO Joystick Playback with specifyed pramiters.
|
||||
* @param swerve m_robotSwerveDrive
|
||||
* @param controllers an <b>Order-Specific</b> 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<String> 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 <b>Order-Specific</b> 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);
|
||||
}
|
||||
|
||||
@@ -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?");
|
||||
|
||||
Reference in New Issue
Block a user