From 73c962ef8d12f9d048965e1b124687237222f65e Mon Sep 17 00:00:00 2001 From: Nummun14 <142012009+Nummun14@users.noreply.github.com> Date: Mon, 18 Nov 2024 19:01:00 +0200 Subject: [PATCH 01/61] started cleaning was in the middle of TalonFX --- .../trigon/commands/ExecuteEndCommand.java | 2 +- .../hardware/misc/KeyboardController.java | 3 + .../trigon/hardware/misc/XboxController.java | 3 + .../misc/simplesensor/SimpleSensor.java | 79 ++++++++++++++++--- .../simplesensor/io/DutyCycleSensorIO.java | 3 +- .../phoenix6/talonfx/TalonFXMotor.java | 77 ++++++++++++++++++ 6 files changed, 151 insertions(+), 16 deletions(-) diff --git a/src/main/java/org/trigon/commands/ExecuteEndCommand.java b/src/main/java/org/trigon/commands/ExecuteEndCommand.java index 626f2a46..68862960 100644 --- a/src/main/java/org/trigon/commands/ExecuteEndCommand.java +++ b/src/main/java/org/trigon/commands/ExecuteEndCommand.java @@ -18,4 +18,4 @@ public ExecuteEndCommand(Runnable onExecute, Runnable onEnd, SubsystemBase... re super(() -> { }, onExecute, (interrupted) -> onEnd.run(), () -> false, requirements); } -} +} \ No newline at end of file diff --git a/src/main/java/org/trigon/hardware/misc/KeyboardController.java b/src/main/java/org/trigon/hardware/misc/KeyboardController.java index dc07bc47..384dc08f 100644 --- a/src/main/java/org/trigon/hardware/misc/KeyboardController.java +++ b/src/main/java/org/trigon/hardware/misc/KeyboardController.java @@ -3,6 +3,9 @@ import edu.wpi.first.wpilibj2.command.button.Trigger; import org.littletonrobotics.junction.networktables.LoggedDashboardBoolean; +/** + * A class that represents a keyboard controller. Used to get input from the keyboard. + */ public class KeyboardController { private final LoggedDashboardBoolean esc, f1, f2, f3, f4, f5, f6, f7, f8, f9, f10, diff --git a/src/main/java/org/trigon/hardware/misc/XboxController.java b/src/main/java/org/trigon/hardware/misc/XboxController.java index 9bfd49c0..9e0870a1 100644 --- a/src/main/java/org/trigon/hardware/misc/XboxController.java +++ b/src/main/java/org/trigon/hardware/misc/XboxController.java @@ -5,6 +5,9 @@ import edu.wpi.first.wpilibj2.command.WaitCommand; import edu.wpi.first.wpilibj2.command.button.CommandXboxController; +/** + * A class that represents an Xbox controller. Used to get the values of the sticks and buttons on the controller. + */ public class XboxController extends CommandXboxController { private int exponent = 1; private double deadband = 0; diff --git a/src/main/java/org/trigon/hardware/misc/simplesensor/SimpleSensor.java b/src/main/java/org/trigon/hardware/misc/simplesensor/SimpleSensor.java index f10baa3d..44684500 100644 --- a/src/main/java/org/trigon/hardware/misc/simplesensor/SimpleSensor.java +++ b/src/main/java/org/trigon/hardware/misc/simplesensor/SimpleSensor.java @@ -9,6 +9,9 @@ import java.util.function.DoubleSupplier; +/** + * A class the represents a sensor, with support for analog, digital, and duty cycle sensors. + */ public class SimpleSensor { private final String name; private final SimpleSensorIO sensorIO; @@ -17,6 +20,13 @@ public class SimpleSensor { scalingSlope = 1, scalingInterceptPoint = 0; + /** + * Creates a new analog sensor. + * + * @param channel The channel of the sensor. + * @param name The name of the sensor. + * @return The new sensor. + */ public static SimpleSensor createAnalogSensor(int channel, String name) { final SimpleSensor nonRealSensor = createNonRealSensor(name); if (nonRealSensor != null) @@ -24,6 +34,13 @@ public static SimpleSensor createAnalogSensor(int channel, String name) { return new SimpleSensor(new AnalogSensorIO(channel), name); } + /** + * Creates a new digital sensor. + * + * @param channel The channel of the sensor. + * @param name The name of the sensor. + * @return The new sensor. + */ public static SimpleSensor createDigitalSensor(int channel, String name) { final SimpleSensor nonRealSensor = createNonRealSensor(name); if (nonRealSensor != null) @@ -31,6 +48,13 @@ public static SimpleSensor createDigitalSensor(int channel, String name) { return new SimpleSensor(new DigitalSensorIO(channel), name); } + /** + * Creates a new duty cycle sensor. + * + * @param channel The channel of the sensor. + * @param name The name of the sensor. + * @return The new sensor. + */ public static SimpleSensor createDutyCycleSensor(int channel, String name) { final SimpleSensor nonRealSensor = createNonRealSensor(name); if (nonRealSensor != null) @@ -38,42 +62,71 @@ public static SimpleSensor createDutyCycleSensor(int channel, String name) { return new SimpleSensor(new DutyCycleSensorIO(channel), name); } - private static SimpleSensor createNonRealSensor(String name) { - if (RobotHardwareStats.isReplay()) - return new SimpleSensor(new SimpleSensorIO(), name); - if (RobotHardwareStats.isSimulation()) - return new SimpleSensor(new SimpleSensorSimulationIO(), name); - return null; - } - - private SimpleSensor(SimpleSensorIO sensorIO, String name) { - this.sensorIO = sensorIO; - this.name = name; - } - + /** + * Sets the scaling constants for the sensor. Used to convert the raw sensor value to a more useful unit. + * + * @param scalingSlope The slope of the scaling line. + * @param scalingInterceptPoint The y-intercept of the scaling line. + */ public void setScalingConstants(double scalingSlope, double scalingInterceptPoint) { this.scalingSlope = scalingSlope; this.scalingInterceptPoint = scalingInterceptPoint; } + /** + * Gets the value of the sensor. + * + * @return The value of the sensor. + */ public double getValue() { return sensorInputs.value; } + /** + * Gets the binary value of the sensor. + * + * @return The binary value of the sensor. + */ public boolean getBinaryValue() { return sensorInputs.value > 0; } + /** + * Gets the scaled value using the scaling constants. + * + * @return The scaled value. + */ public double getScaledValue() { return (sensorInputs.value * scalingSlope) + scalingInterceptPoint; } + /** + * Sets the simulation supplier for the sensor. + * + * @param simulationValueSupplier The simulation supplier. + */ public void setSimulationSupplier(DoubleSupplier simulationValueSupplier) { sensorIO.setSimulationSupplier(simulationValueSupplier); } + /** + * Updates the sensor inputs and logs them. + */ public void updateSensor() { sensorIO.updateInputs(sensorInputs); Logger.processInputs("SimpleSensors/" + name, sensorInputs); } + + private static SimpleSensor createNonRealSensor(String name) { + if (RobotHardwareStats.isReplay()) + return new SimpleSensor(new SimpleSensorIO(), name); + if (RobotHardwareStats.isSimulation()) + return new SimpleSensor(new SimpleSensorSimulationIO(), name); + return null; + } + + private SimpleSensor(SimpleSensorIO sensorIO, String name) { + this.sensorIO = sensorIO; + this.name = name; + } } diff --git a/src/main/java/org/trigon/hardware/misc/simplesensor/io/DutyCycleSensorIO.java b/src/main/java/org/trigon/hardware/misc/simplesensor/io/DutyCycleSensorIO.java index c0ac0345..3f332f94 100644 --- a/src/main/java/org/trigon/hardware/misc/simplesensor/io/DutyCycleSensorIO.java +++ b/src/main/java/org/trigon/hardware/misc/simplesensor/io/DutyCycleSensorIO.java @@ -15,5 +15,4 @@ public DutyCycleSensorIO(int channel) { public void updateInputs(SimpleSensorInputsAutoLogged inputs) { inputs.value = dutyCycle.getHighTimeNanoseconds(); } -} - +} \ No newline at end of file diff --git a/src/main/java/org/trigon/hardware/phoenix6/talonfx/TalonFXMotor.java b/src/main/java/org/trigon/hardware/phoenix6/talonfx/TalonFXMotor.java index bf0b786a..4a802444 100644 --- a/src/main/java/org/trigon/hardware/phoenix6/talonfx/TalonFXMotor.java +++ b/src/main/java/org/trigon/hardware/phoenix6/talonfx/TalonFXMotor.java @@ -11,16 +11,32 @@ import org.trigon.hardware.phoenix6.talonfx.io.SimulationTalonFXIO; import org.trigon.hardware.simulation.MotorPhysicsSimulation; +/** + * A class that represents a Talon FX motor. Used to control the motor and get the values of the motor. + */ public class TalonFXMotor { private final String motorName; private final TalonFXIO motorIO; private final Phoenix6Inputs motorInputs; private final int id; + /** + * Creates a new Talon FX motor. + * + * @param id the motor ID + * @param motorName the name of the motor + */ public TalonFXMotor(int id, String motorName) { this(id, motorName, ""); } + /** + * Creates a new Talon FX motor. + * + * @param id the motor ID + * @param motorName the name of the motor + * @param canbus the canivore name + */ public TalonFXMotor(int id, String motorName, String canbus) { this.motorName = motorName; this.motorIO = generateIO(id, canbus); @@ -29,19 +45,38 @@ public TalonFXMotor(int id, String motorName, String canbus) { motorIO.optimizeBusUsage(); } + /** + * Updates the motor, and logs the inputs. + */ public void update() { motorIO.updateMotor(); Logger.processInputs("Motors/" + motorName, motorInputs); } + /** + * Gets the ID of the motor. + * + * @return the ID of the motor + */ public int getID() { return id; } + /** + * Sets the physics simulation of the motor. + * + * @param physicsSimulation the simulation + */ public void setPhysicsSimulation(MotorPhysicsSimulation physicsSimulation) { motorIO.setPhysicsSimulation(physicsSimulation); } + /** + * Applies the configurations to the motor, in simulation and real life. + * + * @param realConfiguration configuration to be used in real life + * @param simulationConfiguration configuration to be used in simulation + */ public void applyConfigurations(TalonFXConfiguration realConfiguration, TalonFXConfiguration simulationConfiguration) { if (RobotHardwareStats.isSimulation()) motorIO.applyConfiguration(simulationConfiguration); @@ -49,36 +84,78 @@ public void applyConfigurations(TalonFXConfiguration realConfiguration, TalonFXC motorIO.applyConfiguration(realConfiguration); } + /** + * Applies the configuration to be used both in real life and in simulation. + * + * @param simulationAndRealConfiguration the configuration + */ public void applyConfiguration(TalonFXConfiguration simulationAndRealConfiguration) { motorIO.applyConfiguration(simulationAndRealConfiguration); } + /** + * Applies the configuration to be used in real life. + * + * @param realConfiguration the configuration + */ public void applyRealConfiguration(TalonFXConfiguration realConfiguration) { if (!RobotHardwareStats.isSimulation()) motorIO.applyConfiguration(realConfiguration); } + /** + * Applies the configuration to be used in simulation. + * + * @param simulationConfiguration the configuration + */ public void applySimulationConfiguration(TalonFXConfiguration simulationConfiguration) { if (RobotHardwareStats.isSimulation()) motorIO.applyConfiguration(simulationConfiguration); } + /** + * Stops the motor. + */ public void stopMotor() { motorIO.stopMotor(); } + /** + * Gets a signal from the motor. + * + * @param signal the type of signal to get + * @return the signal + */ public double getSignal(TalonFXSignal signal) { return motorInputs.getSignal(signal.name); } + /** + * Gets a threaded signal from the motor. + * + * @param signal the type of signal to get + * @return the signal + */ public double[] getThreadedSignal(TalonFXSignal signal) { return motorInputs.getThreadedSignal(signal.name); } + /** + * Registers a signal to the motor. + * + * @param signal the signal to register + * @param updateFrequencyHertz the frequency to update the signal + */ public void registerSignal(TalonFXSignal signal, double updateFrequencyHertz) { motorInputs.registerSignal(motorSignalToStatusSignal(signal), updateFrequencyHertz); } + /** + * Registers a threaded signal to the motor. + * + * @param signal the signal to register + * @param updateFrequencyHertz the frequency to update the signal + */ public void registerThreadedSignal(TalonFXSignal signal, double updateFrequencyHertz) { motorInputs.registerThreadedSignal(motorSignalToStatusSignal(signal), updateFrequencyHertz); } From 48b1fef9ca66edd977f7d33e0048ccb918ca119e Mon Sep 17 00:00:00 2001 From: Nummun14 <142012009+Nummun14@users.noreply.github.com> Date: Tue, 19 Nov 2024 13:19:00 +0200 Subject: [PATCH 02/61] added a BUNCH more jDocs. (I'm litterally falling asleep rn) just finished MirrorablePose2d --- .../trigon/hardware/RobotHardwareStats.java | 34 +++- .../org/trigon/hardware/SignalThreadBase.java | 21 +++ .../org/trigon/hardware/SignalUtilities.java | 9 + .../phoenix6/talonfx/TalonFXMotor.java | 15 ++ .../phoenix6/talonfx/TalonFXSignal.java | 3 + .../trigon/hardware/rev/spark/SparkMotor.java | 170 ++++++++++++++++-- .../hardware/rev/spark/SparkSignal.java | 3 + .../trigon/hardware/rev/spark/SparkType.java | 3 + .../sparkecnoder/AbsoluteSparkEncoder.java | 23 +++ .../sparkecnoder/RelativeSparkEncoder.java | 23 +++ .../simulation/ElevatorSimulation.java | 39 +++- .../simulation/FlywheelSimulation.java | 42 ++++- .../hardware/simulation/GyroSimulation.java | 21 ++- .../simulation/SimpleMotorSimulation.java | 36 +++- .../SingleJointedArmSimulation.java | 40 ++++- .../mirrorable/MirrorablePose2d.java | 24 ++- 16 files changed, 480 insertions(+), 26 deletions(-) diff --git a/src/main/java/org/trigon/hardware/RobotHardwareStats.java b/src/main/java/org/trigon/hardware/RobotHardwareStats.java index e3507c73..e4906241 100644 --- a/src/main/java/org/trigon/hardware/RobotHardwareStats.java +++ b/src/main/java/org/trigon/hardware/RobotHardwareStats.java @@ -1,37 +1,69 @@ package org.trigon.hardware; +/** + * A class that contains stats about the robot hardware. + */ public class RobotHardwareStats { private static boolean IS_SIMULATION = false; private static boolean IS_REPLAY = false; private static double PERIODIC_TIME_SECONDS = 0.02; + /** + * Sets the current robot stats. + * + * @param isReal whether the robot is real + * @param replayType the replay type + */ public static void setCurrentRobotStats(boolean isReal, ReplayType replayType) { if (isReal || replayType.equals(ReplayType.NONE)) { IS_SIMULATION = !isReal; IS_REPLAY = false; return; } - + IS_SIMULATION = replayType.equals(ReplayType.SIMULATION_REPLAY); IS_REPLAY = true; } + /** + * Sets the periodic time in seconds. + * + * @param periodicTimeSeconds the periodic time in seconds + */ public static void setPeriodicTimeSeconds(double periodicTimeSeconds) { PERIODIC_TIME_SECONDS = periodicTimeSeconds; } + /** + * Gets the periodic time in seconds. + * + * @return the periodic time in seconds + */ public static double getPeriodicTimeSeconds() { return PERIODIC_TIME_SECONDS; } + /** + * Gets whether the robot is in replay mode. + * + * @return whether the robot is in replay mode + */ public static boolean isReplay() { return IS_REPLAY; } + /** + * Gets whether the robot is in simulation mode. + * + * @return whether the robot is in simulation mode + */ public static boolean isSimulation() { return IS_SIMULATION; } + /** + * An enum that represents the replay type. + */ public enum ReplayType { NONE, SIMULATION_REPLAY, diff --git a/src/main/java/org/trigon/hardware/SignalThreadBase.java b/src/main/java/org/trigon/hardware/SignalThreadBase.java index 42767e86..3e16e65f 100644 --- a/src/main/java/org/trigon/hardware/SignalThreadBase.java +++ b/src/main/java/org/trigon/hardware/SignalThreadBase.java @@ -7,6 +7,9 @@ import java.util.concurrent.ArrayBlockingQueue; import java.util.concurrent.locks.ReentrantLock; +/** + * A class that represents a base for a signal thread. + */ public class SignalThreadBase extends Thread { public static final ReentrantLock SIGNALS_LOCK = new ReentrantLock(); protected final Queue timestamps = new ArrayBlockingQueue<>(100); @@ -14,14 +17,27 @@ public class SignalThreadBase extends Thread { private final String name; protected double odometryFrequencyHertz = 50; + /** + * Creates a new SignalThreadBase. + * + * @param name The name of the thread + */ public SignalThreadBase(String name) { this.name = name; } + /** + * Sets the odometry frequency in hertz. + * + * @param odometryFrequencyHertz The odometry frequency in hertz + */ public void setOdometryFrequencyHertz(double odometryFrequencyHertz) { this.odometryFrequencyHertz = odometryFrequencyHertz; } + /** + * Updates the latest timestamps, and processes the inputs. + */ public void updateLatestTimestamps() { if (!RobotHardwareStats.isReplay()) { threadInputs.timestamps = timestamps.stream().mapToDouble(Double::doubleValue).toArray(); @@ -30,6 +46,11 @@ public void updateLatestTimestamps() { Logger.processInputs(name, threadInputs); } + /** + * Gets the latest timestamps. + * + * @return The latest timestamps + */ public double[] getLatestTimestamps() { return threadInputs.timestamps; } diff --git a/src/main/java/org/trigon/hardware/SignalUtilities.java b/src/main/java/org/trigon/hardware/SignalUtilities.java index ec51d487..763ec0d1 100644 --- a/src/main/java/org/trigon/hardware/SignalUtilities.java +++ b/src/main/java/org/trigon/hardware/SignalUtilities.java @@ -1,6 +1,15 @@ package org.trigon.hardware; +/** + * A class that contains utility methods for signals. + */ public class SignalUtilities { + /** + * Converts an enum name to a signal name. + * + * @param enumName The enum name + * @return The signal name + */ public static String enumNameToSignalName(String enumName) { final String lowercaseName = enumName.toLowerCase(); final String nameNoUnderscore = lowercaseName.replace("_", ""); diff --git a/src/main/java/org/trigon/hardware/phoenix6/talonfx/TalonFXMotor.java b/src/main/java/org/trigon/hardware/phoenix6/talonfx/TalonFXMotor.java index 4a802444..84ba2849 100644 --- a/src/main/java/org/trigon/hardware/phoenix6/talonfx/TalonFXMotor.java +++ b/src/main/java/org/trigon/hardware/phoenix6/talonfx/TalonFXMotor.java @@ -160,14 +160,29 @@ public void registerThreadedSignal(TalonFXSignal signal, double updateFrequencyH motorInputs.registerThreadedSignal(motorSignalToStatusSignal(signal), updateFrequencyHertz); } + /** + * Sends a request to the motor. + * + * @param request the request to send + */ public void setControl(ControlRequest request) { motorIO.setControl(request); } + /** + * Sets the motor's current position. + * + * @param positionRotations the position to set + */ public void setPosition(double positionRotations) { motorIO.setPosition(positionRotations); } + /** + * Sets the motors Neutral Mode. + * + * @param brake should the motor brake + */ public void setBrake(boolean brake) { motorIO.setBrake(brake); } diff --git a/src/main/java/org/trigon/hardware/phoenix6/talonfx/TalonFXSignal.java b/src/main/java/org/trigon/hardware/phoenix6/talonfx/TalonFXSignal.java index 51ca6f3e..99037aa9 100644 --- a/src/main/java/org/trigon/hardware/phoenix6/talonfx/TalonFXSignal.java +++ b/src/main/java/org/trigon/hardware/phoenix6/talonfx/TalonFXSignal.java @@ -6,6 +6,9 @@ import java.util.function.Function; +/** + * An enum that represents the different signals that can be gotten from a Talon FX motor. + */ public enum TalonFXSignal { POSITION(TalonFX::getPosition), VELOCITY(TalonFX::getVelocity), diff --git a/src/main/java/org/trigon/hardware/rev/spark/SparkMotor.java b/src/main/java/org/trigon/hardware/rev/spark/SparkMotor.java index 35db9722..a6790b6a 100644 --- a/src/main/java/org/trigon/hardware/rev/spark/SparkMotor.java +++ b/src/main/java/org/trigon/hardware/rev/spark/SparkMotor.java @@ -12,12 +12,23 @@ import java.util.concurrent.CompletableFuture; +/** + * A class the represents a Spark motor. Used to control and read data from a Spark motor. + */ public class SparkMotor { private final String motorName; private final SparkIO motorIO; private final SparkInputs motorInputs; private final int id; + /** + * Creates a new Spark motor. + * + * @param id the motor ID + * @param sparkType the type of Spark motor + * @param motorName the name of the motor + * @param simulationMotor the motor to be used in simulation + */ public SparkMotor(int id, SparkType sparkType, String motorName, DCMotor simulationMotor) { this.id = id; this.motorName = motorName; @@ -25,98 +36,223 @@ public SparkMotor(int id, SparkType sparkType, String motorName, DCMotor simulat motorIO = createSparkIO(id, sparkType, simulationMotor); } + /** + * Processes the inputs of the motor. + */ public void update() { Logger.processInputs("Motors/" + motorName, motorInputs); } + /** + * Gets the ID of the motor. + * + * @return the ID + */ public int getID() { return id; } + /** + * Registers a signal to be read from the motor. + * + * @param signal the signal to be read + */ public void registerSignal(SparkSignal signal) { this.registerSignal(signal, false); } + /** + * Registers a signal to be read from the motor. + * + * @param signal the signal to be read + * @param isThreaded whether the signal should be read in a separate thread + */ public void registerSignal(SparkSignal signal, boolean isThreaded) { final SparkStatusSignal statusSignal = signal.getStatusSignal(motorIO.getMotor(), motorIO.getEncoder()); - if (isThreaded) + if (isThreaded) { motorInputs.registerThreadedSignal(statusSignal); - else - motorInputs.registerSignal(statusSignal); + return; + } + motorInputs.registerSignal(statusSignal); } + /** + * Gets a signal from the motor. + * + * @param signal the signal to get + * @return the signal + */ public double getSignal(SparkSignal signal) { return motorInputs.getSignal(signal.name); } - public void getThreadedSignal(SparkSignal signal) { - motorInputs.getThreadedSignal(signal.name); + /** + * Gets a threaded signal from the motor. + * + * @param signal the signal to get + * @return the signal + */ + public double[] getThreadedSignal(SparkSignal signal) { + return motorInputs.getThreadedSignal(signal.name); } - public void setReference(double value, CANSparkBase.ControlType ctrl) { - motorIO.setReference(value, ctrl); + /** + * Sends a request to the motor. + * + * @param value the value to set + * @param controlType the control type + */ + public void setReference(double value, CANSparkBase.ControlType controlType) { + motorIO.setReference(value, controlType); } - public void setReference(double value, CANSparkBase.ControlType ctrl, int pidSlot) { - motorIO.setReference(value, ctrl, pidSlot); + /** + * Sends a request to the motor. + * + * @param value the value to set + * @param controlType the control type + * @param pidSlot the PID slot to use + */ + public void setReference(double value, CANSparkBase.ControlType controlType, int pidSlot) { + motorIO.setReference(value, controlType, pidSlot); } - public void setReference(double value, CANSparkBase.ControlType ctrl, int pidSlot, double arbFeedForward) { - motorIO.setReference(value, ctrl, pidSlot, arbFeedForward); + /** + * Sends a request to the motor. + * + * @param value the value to set + * @param controlType the control type + * @param pidSlot the PID slot to use + * @param arbFeedForward the feed forward value + */ + public void setReference(double value, CANSparkBase.ControlType controlType, int pidSlot, double arbFeedForward) { + motorIO.setReference(value, controlType, pidSlot, arbFeedForward); } - public void setReference(double value, CANSparkBase.ControlType ctrl, int pidSlot, double arbFeedForward, SparkPIDController.ArbFFUnits arbFFUnits) { - motorIO.setReference(value, ctrl, pidSlot, arbFeedForward, arbFFUnits); + /** + * Sends a request to the motor. + * + * @param value the value to set + * @param controlType the control type + * @param pidSlot the PID slot to use + * @param arbFeedForward the feed forward value + * @param arbFeedForwardUnits the units of the feed forward value + */ + public void setReference(double value, CANSparkBase.ControlType controlType, int pidSlot, double arbFeedForward, SparkPIDController.ArbFFUnits arbFeedForwardUnits) { + motorIO.setReference(value, controlType, pidSlot, arbFeedForward, arbFeedForwardUnits); } + /** + * Set the rate of transmission for periodic frames from the SPARK motor. + * + * @param frame the frame to set the period for + * @param periodMs the period in milliseconds + */ public void setPeriodicFramePeriod(CANSparkLowLevel.PeriodicFrame frame, int periodMs) { motorIO.setPeriodicFramePeriod(frame, periodMs); } + /** + * Stops the motor. + */ public void stopMotor() { motorIO.stopMotor(); } + /** + * Sets the motors neutral value. + * + * @param brake should the motor brake + */ public void setBrake(boolean brake) { motorIO.setBrake(brake); } + /** + * Sets the motors inverted value. + * + * @param inverted should the motor be inverted + */ public void setInverted(boolean inverted) { motorIO.setInverted(inverted); } + /** + * Enables and sets the voltage compensation. + * + * @param voltage the voltage to set + */ public void enableVoltageCompensation(double voltage) { motorIO.enableVoltageCompensation(voltage); } + /** + * Sets the ramp rate for closed loop control. + * + * @param rampRate the ramp rate to set + */ public void setClosedLoopRampRate(double rampRate) { motorIO.setClosedLoopRampRate(rampRate); } - public void setSmartCurrentLimit(int limit) { - motorIO.setSmartCurrentLimit(limit); + /** + * Sets the smart current limitAmperes in amperes. + * + * @param limitAmperes the limitAmperes to set + */ + public void setSmartCurrentLimit(int limitAmperes) { + motorIO.setSmartCurrentLimit(limitAmperes); } + /** + * Sets the ramp rate for open loop control. + * + * @param rampRate the ramp rate to set + */ public void setOpenLoopRampRate(double rampRate) { motorIO.setOpenLoopRampRate(rampRate); } + /** + * Sets the PID values for the motor. + * + * @param p the proportional value + * @param i the integral value + * @param d the derivative value + */ public void setPID(double p, double i, double d) { motorIO.setPID(p, i, d); } + /** + * Sets the conversion factor for values received the motor. + * + * @param conversionsFactor the conversion factor to set + */ public void setConversionsFactor(double conversionsFactor) { motorIO.setConversionsFactor(conversionsFactor); } + /** + * Restores the motor settings to factory defaults. + */ public void restoreFactoryDefaults() { motorIO.restoreFactoryDefaults(); } - public void enablePIDWrapping(double minInput, double maxInput) { - motorIO.enablePIDWrapping(minInput, maxInput); + /** + * Enables PID wrapping. + * + * @param minimumInput the minimum input + * @param maximumInput the maximum input + */ + public void enablePIDWrapping(double minimumInput, double maximumInput) { + motorIO.enablePIDWrapping(minimumInput, maximumInput); } + /** + * Writes all settings to flash + */ public void burnFlash() { CompletableFuture.runAsync(() -> { Timer.delay(5); diff --git a/src/main/java/org/trigon/hardware/rev/spark/SparkSignal.java b/src/main/java/org/trigon/hardware/rev/spark/SparkSignal.java index 34e042d2..c92fd2a0 100644 --- a/src/main/java/org/trigon/hardware/rev/spark/SparkSignal.java +++ b/src/main/java/org/trigon/hardware/rev/spark/SparkSignal.java @@ -7,6 +7,9 @@ import java.util.function.Function; +/** + * Enum for the different signals that can be read from a Spark motor. + */ public enum SparkSignal { POSITION(null, SparkEncoder::getPositionRotations), VELOCITY(null, SparkEncoder::getVelocityRotationsPerSecond), diff --git a/src/main/java/org/trigon/hardware/rev/spark/SparkType.java b/src/main/java/org/trigon/hardware/rev/spark/SparkType.java index 8a88a200..88d3ff80 100644 --- a/src/main/java/org/trigon/hardware/rev/spark/SparkType.java +++ b/src/main/java/org/trigon/hardware/rev/spark/SparkType.java @@ -6,6 +6,9 @@ import java.util.function.Function; +/** + * Enum for the different types of Spark motors. + */ public enum SparkType { SPARK_MAX((id -> new CANSparkMax(id, CANSparkMax.MotorType.kBrushless))), SPARK_FLEW((id -> new CANSparkFlex(id, CANSparkMax.MotorType.kBrushless))); diff --git a/src/main/java/org/trigon/hardware/rev/sparkecnoder/AbsoluteSparkEncoder.java b/src/main/java/org/trigon/hardware/rev/sparkecnoder/AbsoluteSparkEncoder.java index db867a79..fd8ce0a3 100644 --- a/src/main/java/org/trigon/hardware/rev/sparkecnoder/AbsoluteSparkEncoder.java +++ b/src/main/java/org/trigon/hardware/rev/sparkecnoder/AbsoluteSparkEncoder.java @@ -2,22 +2,45 @@ import com.revrobotics.SparkAbsoluteEncoder; +/** + * A class that represents an absolute encoder on a Spark MAX motor controller. + */ public class AbsoluteSparkEncoder extends SparkEncoder { private final SparkAbsoluteEncoder encoder; + /** + * Creates a new AbsoluteSparkEncoder. + * + * @param encoder The SparkAbsoluteEncoder to use. + */ public AbsoluteSparkEncoder(SparkAbsoluteEncoder encoder) { this.encoder = encoder; setConversionsFactor(1); } + /** + * Gets the position of the encoder in rotations. + * + * @return The position of the encoder in rotations. + */ public double getPositionRotations() { return encoder.getPosition(); } + /** + * Gets the velocity of the encoder in rotations per second. + * + * @return The velocity of the encoder in rotations per second. + */ public double getVelocityRotationsPerSecond() { return encoder.getVelocity(); } + /** + * Sets the conversion factor for values received the encoder. + * + * @param conversionsFactor The conversion factor to use. + */ @Override public void setConversionsFactor(double conversionsFactor) { encoder.setPositionConversionFactor(conversionsFactor); diff --git a/src/main/java/org/trigon/hardware/rev/sparkecnoder/RelativeSparkEncoder.java b/src/main/java/org/trigon/hardware/rev/sparkecnoder/RelativeSparkEncoder.java index 6e59a061..7a67def8 100644 --- a/src/main/java/org/trigon/hardware/rev/sparkecnoder/RelativeSparkEncoder.java +++ b/src/main/java/org/trigon/hardware/rev/sparkecnoder/RelativeSparkEncoder.java @@ -2,22 +2,45 @@ import com.revrobotics.RelativeEncoder; +/** + * A class that represents a relative encoder on a Spark MAX motor controller. + */ public class RelativeSparkEncoder extends SparkEncoder { private final RelativeEncoder encoder; + /** + * Creates a new RelativeSparkEncoder. + * + * @param encoder The RelativeEncoder to use. + */ public RelativeSparkEncoder(RelativeEncoder encoder) { this.encoder = encoder; setConversionsFactor(1); } + /** + * Gets the position of the encoder in rotations. + * + * @return The position of the encoder in rotations. + */ public double getPositionRotations() { return encoder.getPosition(); } + /** + * Gets the velocity of the encoder in rotations per second. + * + * @return The velocity of the encoder in rotations per second. + */ public double getVelocityRotationsPerSecond() { return encoder.getVelocity(); } + /** + * Sets the conversion factor for values received the encoder. + * + * @param conversionsFactor The conversion factor to use. + */ @Override public void setConversionsFactor(double conversionsFactor) { encoder.setPositionConversionFactor(conversionsFactor); diff --git a/src/main/java/org/trigon/hardware/simulation/ElevatorSimulation.java b/src/main/java/org/trigon/hardware/simulation/ElevatorSimulation.java index 68a57822..5e12e7b5 100644 --- a/src/main/java/org/trigon/hardware/simulation/ElevatorSimulation.java +++ b/src/main/java/org/trigon/hardware/simulation/ElevatorSimulation.java @@ -5,11 +5,25 @@ import org.trigon.hardware.RobotHardwareStats; import org.trigon.utilities.Conversions; +/** + * A class that represents a simulation of an elevator mechanism. + */ public class ElevatorSimulation extends MotorPhysicsSimulation { private final ElevatorSim elevatorSimulation; private final double retractedHeightMeters; private final double diameterMeters; + /** + * Creates a new ElevatorSimulation. + * + * @param gearbox The motor used to move the elevator + * @param gearRatio The gear ratio + * @param carriageMassKilograms The mass of the elevator carriage in kilograms + * @param drumRadiusMeters The radius of the drum in meters + * @param retractedHeightMeters The height of the elevator when retracted in meters + * @param maximumHeightMeters The maximum height of the elevator in meters + * @param simulateGravity Whether to simulate gravity + */ public ElevatorSimulation(DCMotor gearbox, double gearRatio, double carriageMassKilograms, double drumRadiusMeters, double retractedHeightMeters, double maximumHeightMeters, boolean simulateGravity) { super(gearRatio); diameterMeters = drumRadiusMeters + drumRadiusMeters; @@ -26,28 +40,51 @@ public ElevatorSimulation(DCMotor gearbox, double gearRatio, double carriageMass ); } + /** + * Gets the current draw of the elevator in amperes. + * + * @return The current in amperes + */ @Override public double getCurrent() { return elevatorSimulation.getCurrentDrawAmps(); } + /** + * Gets the position of the elevator in meters. + * + * @return The position in meters + */ @Override public double getSystemPositionRotations() { return Conversions.distanceToRotations(elevatorSimulation.getPositionMeters() - retractedHeightMeters, diameterMeters); } + /** + * Gets the velocity of the elevator in meters per second. + * + * @return The velocity in meters per second + */ @Override public double getSystemVelocityRotationsPerSecond() { return Conversions.distanceToRotations(elevatorSimulation.getVelocityMetersPerSecond(), diameterMeters); } + /** + * Sets the input voltage of the elevator. + * + * @param voltage The voltage to set + */ @Override public void setInputVoltage(double voltage) { elevatorSimulation.setInputVoltage(voltage); } + /** + * Updates the elevator simulation. + */ @Override public void updateMotor() { elevatorSimulation.update(RobotHardwareStats.getPeriodicTimeSeconds()); } -} +} \ No newline at end of file diff --git a/src/main/java/org/trigon/hardware/simulation/FlywheelSimulation.java b/src/main/java/org/trigon/hardware/simulation/FlywheelSimulation.java index 650339c6..25db7742 100644 --- a/src/main/java/org/trigon/hardware/simulation/FlywheelSimulation.java +++ b/src/main/java/org/trigon/hardware/simulation/FlywheelSimulation.java @@ -6,41 +6,81 @@ import edu.wpi.first.wpilibj.simulation.FlywheelSim; import org.trigon.hardware.RobotHardwareStats; - +/** + * A class the represents a simulation of a flywheel mechanism. + */ public class FlywheelSimulation extends MotorPhysicsSimulation { private final FlywheelSim flywheelSimulation; private double lastPositionRadians = 0; + /** + * Creates a new FlywheelSimulation. + * + * @param gearbox The motor used to control the flywheel + * @param gearRatio The gear ratio + * @param momentOfInertia The moment of inertia of the flywheel + */ public FlywheelSimulation(DCMotor gearbox, double gearRatio, double momentOfInertia) { super(gearRatio); flywheelSimulation = new FlywheelSim(gearbox, gearRatio, momentOfInertia); } + /** + * Creates a new FlywheelSimulation. + * + * @param gearbox The motor used to control the flywheel + * @param gearRatio The gear ratio + * @param kv The velocity gain of the flywheel + * @param ka The acceleration gain of the flywheel + */ public FlywheelSimulation(DCMotor gearbox, double gearRatio, double kv, double ka) { super(gearRatio); flywheelSimulation = new FlywheelSim(LinearSystemId.identifyVelocitySystem(kv, ka), gearbox, gearRatio); } + /** + * Gets the current draw of the flywheel in amperes. + * + * @return The current in amperes + */ @Override public double getCurrent() { return flywheelSimulation.getCurrentDrawAmps(); } + /** + * Gets the position of the flywheel in rotations. + * + * @return The position in rotations + */ @Override public double getSystemPositionRotations() { return Units.radiansToRotations(lastPositionRadians); } + /** + * Gets the velocity of the flywheel in rotations per second. + * + * @return The velocity in rotations per second + */ @Override public double getSystemVelocityRotationsPerSecond() { return Units.radiansToRotations(flywheelSimulation.getAngularVelocityRadPerSec()); } + /** + * Sets the input voltage of the flywheel. + * + * @param voltage The input voltage + */ @Override public void setInputVoltage(double voltage) { flywheelSimulation.setInputVoltage(voltage); } + /** + * Updates the flywheel simulation. + */ @Override public void updateMotor() { flywheelSimulation.update(RobotHardwareStats.getPeriodicTimeSeconds()); diff --git a/src/main/java/org/trigon/hardware/simulation/GyroSimulation.java b/src/main/java/org/trigon/hardware/simulation/GyroSimulation.java index c063cb68..6cea52d8 100644 --- a/src/main/java/org/trigon/hardware/simulation/GyroSimulation.java +++ b/src/main/java/org/trigon/hardware/simulation/GyroSimulation.java @@ -2,18 +2,37 @@ import edu.wpi.first.math.geometry.Rotation2d; +/** + * A class that represents a simulation of a gyro sensor. + */ public class GyroSimulation { private double simulationRadians = 0; + /** + * Gets the yaw of the gyro in degrees. + * + * @return The yaw in degrees + */ public double getGyroYawDegrees() { return Math.toDegrees(simulationRadians); } + /** + * Updates the gyro simulation. + * + * @param omegaRadiansPerSecond The angular velocity of the gyro in radians per second + * @param timeSeconds The time in seconds + */ public void update(double omegaRadiansPerSecond, double timeSeconds) { simulationRadians += omegaRadiansPerSecond * timeSeconds; } + /** + * Sets the yaw of the gyro. + * + * @param heading The yaw to set + */ public void setYaw(Rotation2d heading) { simulationRadians = heading.getRadians(); } -} +} \ No newline at end of file diff --git a/src/main/java/org/trigon/hardware/simulation/SimpleMotorSimulation.java b/src/main/java/org/trigon/hardware/simulation/SimpleMotorSimulation.java index ab03df11..46bd0422 100644 --- a/src/main/java/org/trigon/hardware/simulation/SimpleMotorSimulation.java +++ b/src/main/java/org/trigon/hardware/simulation/SimpleMotorSimulation.java @@ -5,37 +5,69 @@ import edu.wpi.first.wpilibj.simulation.DCMotorSim; import org.trigon.hardware.RobotHardwareStats; - +/** + * A class that represents a simulation of a simple motor mechanism. + */ public class SimpleMotorSimulation extends MotorPhysicsSimulation { private final DCMotorSim motorSimulation; + /** + * Creates a new SimpleMotorSimulation. + * + * @param gearbox The type of motor + * @param gearRatio The gear ratio + * @param momentOfInertia The motors moment of inertia + */ public SimpleMotorSimulation(DCMotor gearbox, double gearRatio, double momentOfInertia) { super(gearRatio); motorSimulation = new DCMotorSim(gearbox, gearRatio, momentOfInertia); } + /** + * Gets the current draw of the motor in amperes. + * + * @return The current in amperes + */ @Override public double getCurrent() { return motorSimulation.getCurrentDrawAmps(); } + /** + * Gets the position of the motor in rotations. + * + * @return The position in rotations + */ @Override public double getSystemPositionRotations() { return Units.radiansToRotations(motorSimulation.getAngularPositionRad()); } + /** + * Gets the velocity of the motor in rotations per second. + * + * @return The velocity in rotations per second + */ @Override public double getSystemVelocityRotationsPerSecond() { return Units.radiansToRotations(motorSimulation.getAngularVelocityRadPerSec()); } + /** + * Sets the input voltage of the motor. + * + * @param voltage The voltage to set + */ @Override public void setInputVoltage(double voltage) { motorSimulation.setInputVoltage(voltage); } + /** + * Updates the motor simulation. + */ @Override public void updateMotor() { motorSimulation.update(RobotHardwareStats.getPeriodicTimeSeconds()); } -} +} \ No newline at end of file diff --git a/src/main/java/org/trigon/hardware/simulation/SingleJointedArmSimulation.java b/src/main/java/org/trigon/hardware/simulation/SingleJointedArmSimulation.java index 4907808a..9e4c394d 100644 --- a/src/main/java/org/trigon/hardware/simulation/SingleJointedArmSimulation.java +++ b/src/main/java/org/trigon/hardware/simulation/SingleJointedArmSimulation.java @@ -6,10 +6,23 @@ import edu.wpi.first.wpilibj.simulation.SingleJointedArmSim; import org.trigon.hardware.RobotHardwareStats; - +/** + * A class that represents a simulation of a single jointed arm mechanism. + */ public class SingleJointedArmSimulation extends MotorPhysicsSimulation { private final SingleJointedArmSim armSimulation; + /** + * Creates a new SingleJointedArmSimulation. + * + * @param gearbox The motor used to control the arm + * @param gearRatio The gear ratio + * @param armLengthMeters The length of the arm in meters + * @param armMassKilograms The mass of the arm in kilograms + * @param minimumAngle The minimum angle of the arm + * @param maximumAngle The maximum angle of the arm + * @param simulateGravity Whether to simulate gravity + */ public SingleJointedArmSimulation(DCMotor gearbox, double gearRatio, double armLengthMeters, double armMassKilograms, Rotation2d minimumAngle, Rotation2d maximumAngle, boolean simulateGravity) { super(gearRatio); armSimulation = new SingleJointedArmSim( @@ -24,28 +37,51 @@ public SingleJointedArmSimulation(DCMotor gearbox, double gearRatio, double armL ); } + /** + * Gets the current draw of the arm in amperes. + * + * @return The current in amperes + */ @Override public double getCurrent() { return armSimulation.getCurrentDrawAmps(); } + /** + * Gets the position of the arm in rotations. + * + * @return The position in rotations + */ @Override public double getSystemPositionRotations() { return Units.radiansToRotations(armSimulation.getAngleRads()); } + /** + * Gets the velocity of the arm in rotations per second. + * + * @return The velocity in rotations per second + */ @Override public double getSystemVelocityRotationsPerSecond() { return Units.radiansToRotations(armSimulation.getVelocityRadPerSec()); } + /** + * Sets the input voltage of the arm. + * + * @param voltage The voltage to set + */ @Override public void setInputVoltage(double voltage) { armSimulation.setInputVoltage(voltage); } + /** + * Updates the arm simulation. + */ @Override public void updateMotor() { armSimulation.update(RobotHardwareStats.getPeriodicTimeSeconds()); } -} +} \ No newline at end of file diff --git a/src/main/java/org/trigon/utilities/mirrorable/MirrorablePose2d.java b/src/main/java/org/trigon/utilities/mirrorable/MirrorablePose2d.java index 84d2602f..5e6724ba 100644 --- a/src/main/java/org/trigon/utilities/mirrorable/MirrorablePose2d.java +++ b/src/main/java/org/trigon/utilities/mirrorable/MirrorablePose2d.java @@ -4,20 +4,42 @@ import edu.wpi.first.math.geometry.Rotation2d; import edu.wpi.first.math.geometry.Translation2d; - +/** + * A class that represents a {@link Pose2d} that can be mirrored. + */ public class MirrorablePose2d extends Mirrorable { public MirrorablePose2d(Pose2d nonMirroredPose, boolean mirrorWhenRedAlliance) { super(nonMirroredPose, mirrorWhenRedAlliance); } + /** + * Creates a new MirrorablePose2d with the given x, y, and rotation. + * + * @param x The x value of the pose. + * @param y The y value of the pose. + * @param rotation The rotation of the pose. + * @param mirrorWhenRedAlliance Whether to mirror the pose when the robot is on the red alliance. + */ public MirrorablePose2d(double x, double y, Rotation2d rotation, boolean mirrorWhenRedAlliance) { this(new Pose2d(x, y, rotation), mirrorWhenRedAlliance); } + /** + * Creates a new MirrorablePose2d with the given translation and rotation. + * + * @param translation2d The translation of the pose. + * @param rotation The rotation of the pose. + * @param mirrorWhenRedAlliance Whether to mirror the pose when the robot is on the red alliance. + */ public MirrorablePose2d(Translation2d translation2d, double rotation, boolean mirrorWhenRedAlliance) { this(new Pose2d(translation2d, new Rotation2d(rotation)), mirrorWhenRedAlliance); } + /** + * Gets the rotation value of the pose. + * + * @return the rotation value of the pose. + */ public MirrorableRotation2d getRotation() { return new MirrorableRotation2d(nonMirroredObject.getRotation(), mirrorWhenRedAlliance); } From 772ff20ad4609319f9d437ed521efd5b92e9db6a Mon Sep 17 00:00:00 2001 From: Nummun14 <142012009+Nummun14@users.noreply.github.com> Date: Tue, 19 Nov 2024 14:57:36 +0200 Subject: [PATCH 03/61] finished adding jDocs --- .../java/org/trigon/utilities/Conversions.java | 3 +++ .../org/trigon/utilities/LimelightHelpers.java | 2 -- .../mirrorable/MirrorableRotation2d.java | 9 +++++++++ .../mirrorable/MirrorableTranslation3d.java | 18 +++++++++++++++++- 4 files changed, 29 insertions(+), 3 deletions(-) diff --git a/src/main/java/org/trigon/utilities/Conversions.java b/src/main/java/org/trigon/utilities/Conversions.java index f9da79cc..26a46baf 100644 --- a/src/main/java/org/trigon/utilities/Conversions.java +++ b/src/main/java/org/trigon/utilities/Conversions.java @@ -2,6 +2,9 @@ import edu.wpi.first.math.trajectory.TrapezoidProfile; +/** + * A class that contains various conversion methods. + */ public class Conversions { public static final double MAG_TICKS = 4096, diff --git a/src/main/java/org/trigon/utilities/LimelightHelpers.java b/src/main/java/org/trigon/utilities/LimelightHelpers.java index c1654207..f39c485d 100644 --- a/src/main/java/org/trigon/utilities/LimelightHelpers.java +++ b/src/main/java/org/trigon/utilities/LimelightHelpers.java @@ -21,10 +21,8 @@ import java.util.concurrent.ConcurrentHashMap; public class LimelightHelpers { - private static final Map doubleArrayEntries = new ConcurrentHashMap<>(); - public static class LimelightTarget_Retro { @JsonProperty("t6c_ts") diff --git a/src/main/java/org/trigon/utilities/mirrorable/MirrorableRotation2d.java b/src/main/java/org/trigon/utilities/mirrorable/MirrorableRotation2d.java index fe459f77..da0b0ce6 100644 --- a/src/main/java/org/trigon/utilities/mirrorable/MirrorableRotation2d.java +++ b/src/main/java/org/trigon/utilities/mirrorable/MirrorableRotation2d.java @@ -2,11 +2,20 @@ import edu.wpi.first.math.geometry.Rotation2d; +/** + * A class that represents a {@link Rotation2d} that can be mirrored. + */ public class MirrorableRotation2d extends Mirrorable { public MirrorableRotation2d(Rotation2d nonMirroredRotation, boolean mirrorWhenRedAlliance) { super(nonMirroredRotation, mirrorWhenRedAlliance); } + /** + * Creates a new MirrorableRotation2d with the given rotation value. + * + * @param radians the value of the angle in radians + * @param mirrorWhenRedAlliance whether to mirror the object when the robot is on the red alliance + */ public MirrorableRotation2d(double radians, boolean mirrorWhenRedAlliance) { this(new Rotation2d(radians), mirrorWhenRedAlliance); } diff --git a/src/main/java/org/trigon/utilities/mirrorable/MirrorableTranslation3d.java b/src/main/java/org/trigon/utilities/mirrorable/MirrorableTranslation3d.java index cb919d3b..13226309 100644 --- a/src/main/java/org/trigon/utilities/mirrorable/MirrorableTranslation3d.java +++ b/src/main/java/org/trigon/utilities/mirrorable/MirrorableTranslation3d.java @@ -2,12 +2,28 @@ import edu.wpi.first.math.geometry.Translation3d; - +/** + * A class that represents a {@link Translation3d} that can be mirrored. + */ public class MirrorableTranslation3d extends Mirrorable { + /** + * Creates a new MirrorableTranslation3d with the given translation. + * + * @param nonMirroredTranslation the translation to mirror + * @param mirrorWhenRedAlliance whether to mirror the object when the robot is on the red alliance + */ public MirrorableTranslation3d(Translation3d nonMirroredTranslation, boolean mirrorWhenRedAlliance) { super(nonMirroredTranslation, mirrorWhenRedAlliance); } + /** + * Creates a new MirrorableTranslation3d with the given x, y, and z values. + * + * @param x the x value of the translation + * @param y the y value of the translation + * @param z the z value of the translation + * @param mirrorWhenRedAlliance whether to mirror the object when the robot is on the red alliance + */ public MirrorableTranslation3d(double x, double y, double z, boolean mirrorWhenRedAlliance) { this(new Translation3d(x, y, z), mirrorWhenRedAlliance); } From 8590e74dae2eb92b08ca34ae7b158844ca73efc4 Mon Sep 17 00:00:00 2001 From: Nummun14 <142012009+Nummun14@users.noreply.github.com> Date: Wed, 20 Nov 2024 21:12:12 +0200 Subject: [PATCH 04/61] grammer sucks --- .../org/trigon/hardware/RobotHardwareStats.java | 6 +++--- .../hardware/misc/KeyboardController.java | 2 +- .../trigon/hardware/misc/XboxController.java | 2 +- .../misc/simplesensor/SimpleSensor.java | 4 ++-- .../hardware/phoenix6/talonfx/TalonFXMotor.java | 12 ++++++------ .../phoenix6/talonfx/TalonFXSignal.java | 2 +- .../trigon/hardware/rev/spark/SparkMotor.java | 17 +++++++++-------- .../trigon/hardware/rev/spark/SparkSignal.java | 2 +- .../trigon/hardware/rev/spark/SparkType.java | 2 +- .../hardware/simulation/ElevatorSimulation.java | 14 +++++++------- .../hardware/simulation/FlywheelSimulation.java | 16 ++++++++-------- .../hardware/simulation/GyroSimulation.java | 6 +++--- .../simulation/SimpleMotorSimulation.java | 6 +++--- .../simulation/SingleJointedArmSimulation.java | 14 +++++++------- .../java/org/trigon/utilities/Conversions.java | 2 +- .../utilities/mirrorable/MirrorablePose2d.java | 16 ++++++++-------- .../mirrorable/MirrorableRotation2d.java | 10 +++++----- .../mirrorable/MirrorableTranslation3d.java | 8 ++++---- 18 files changed, 71 insertions(+), 70 deletions(-) diff --git a/src/main/java/org/trigon/hardware/RobotHardwareStats.java b/src/main/java/org/trigon/hardware/RobotHardwareStats.java index e4906241..91c5a340 100644 --- a/src/main/java/org/trigon/hardware/RobotHardwareStats.java +++ b/src/main/java/org/trigon/hardware/RobotHardwareStats.java @@ -12,7 +12,7 @@ public class RobotHardwareStats { * Sets the current robot stats. * * @param isReal whether the robot is real - * @param replayType the replay type + * @param replayType the type of replay */ public static void setCurrentRobotStats(boolean isReal, ReplayType replayType) { if (isReal || replayType.equals(ReplayType.NONE)) { @@ -55,14 +55,14 @@ public static boolean isReplay() { /** * Gets whether the robot is in simulation mode. * - * @return whether the robot is in simulation mode + * @return whether the robot is running in simulation */ public static boolean isSimulation() { return IS_SIMULATION; } /** - * An enum that represents the replay type. + * An enum that represents type of replay. */ public enum ReplayType { NONE, diff --git a/src/main/java/org/trigon/hardware/misc/KeyboardController.java b/src/main/java/org/trigon/hardware/misc/KeyboardController.java index 384dc08f..0abb7c5a 100644 --- a/src/main/java/org/trigon/hardware/misc/KeyboardController.java +++ b/src/main/java/org/trigon/hardware/misc/KeyboardController.java @@ -4,7 +4,7 @@ import org.littletonrobotics.junction.networktables.LoggedDashboardBoolean; /** - * A class that represents a keyboard controller. Used to get input from the keyboard. + * A class that represents a keyboard controller. Used to get input a keyboard. */ public class KeyboardController { private final LoggedDashboardBoolean diff --git a/src/main/java/org/trigon/hardware/misc/XboxController.java b/src/main/java/org/trigon/hardware/misc/XboxController.java index 9e0870a1..cf89809a 100644 --- a/src/main/java/org/trigon/hardware/misc/XboxController.java +++ b/src/main/java/org/trigon/hardware/misc/XboxController.java @@ -6,7 +6,7 @@ import edu.wpi.first.wpilibj2.command.button.CommandXboxController; /** - * A class that represents an Xbox controller. Used to get the values of the sticks and buttons on the controller. + * A class that represents an Xbox controller. Used to get the values of the sticks and buttons on a controller. */ public class XboxController extends CommandXboxController { private int exponent = 1; diff --git a/src/main/java/org/trigon/hardware/misc/simplesensor/SimpleSensor.java b/src/main/java/org/trigon/hardware/misc/simplesensor/SimpleSensor.java index 44684500..973c2d5b 100644 --- a/src/main/java/org/trigon/hardware/misc/simplesensor/SimpleSensor.java +++ b/src/main/java/org/trigon/hardware/misc/simplesensor/SimpleSensor.java @@ -83,7 +83,7 @@ public double getValue() { } /** - * Gets the binary value of the sensor. + * Gets the binary value of the sensor. A binary value is a boolean value that is true if the sensor has a value greater than 0. * * @return The binary value of the sensor. */ @@ -110,7 +110,7 @@ public void setSimulationSupplier(DoubleSupplier simulationValueSupplier) { } /** - * Updates the sensor inputs and logs them. + * Updates and logs the sensor's inputs. */ public void updateSensor() { sensorIO.updateInputs(sensorInputs); diff --git a/src/main/java/org/trigon/hardware/phoenix6/talonfx/TalonFXMotor.java b/src/main/java/org/trigon/hardware/phoenix6/talonfx/TalonFXMotor.java index 84ba2849..b3a53094 100644 --- a/src/main/java/org/trigon/hardware/phoenix6/talonfx/TalonFXMotor.java +++ b/src/main/java/org/trigon/hardware/phoenix6/talonfx/TalonFXMotor.java @@ -12,7 +12,7 @@ import org.trigon.hardware.simulation.MotorPhysicsSimulation; /** - * A class that represents a Talon FX motor. Used to control the motor and get the values of the motor. + * A class that represents a Talon FX motor. Used to control and and get the values of the motor. */ public class TalonFXMotor { private final String motorName; @@ -46,7 +46,7 @@ public TalonFXMotor(int id, String motorName, String canbus) { } /** - * Updates the motor, and logs the inputs. + * Updates the motor and logs the inputs. */ public void update() { motorIO.updateMotor(); @@ -72,7 +72,7 @@ public void setPhysicsSimulation(MotorPhysicsSimulation physicsSimulation) { } /** - * Applies the configurations to the motor, in simulation and real life. + * Applies both the real and simulation configurations to the motor * * @param realConfiguration configuration to be used in real life * @param simulationConfiguration configuration to be used in simulation @@ -161,7 +161,7 @@ public void registerThreadedSignal(TalonFXSignal signal, double updateFrequencyH } /** - * Sends a request to the motor. + * Sends a control request to the motor. * * @param request the request to send */ @@ -170,7 +170,7 @@ public void setControl(ControlRequest request) { } /** - * Sets the motor's current position. + * Sets the motor's current position in rotations. * * @param positionRotations the position to set */ @@ -179,7 +179,7 @@ public void setPosition(double positionRotations) { } /** - * Sets the motors Neutral Mode. + * Sets the motors neutral Mode. * * @param brake should the motor brake */ diff --git a/src/main/java/org/trigon/hardware/phoenix6/talonfx/TalonFXSignal.java b/src/main/java/org/trigon/hardware/phoenix6/talonfx/TalonFXSignal.java index 99037aa9..fe0f47ac 100644 --- a/src/main/java/org/trigon/hardware/phoenix6/talonfx/TalonFXSignal.java +++ b/src/main/java/org/trigon/hardware/phoenix6/talonfx/TalonFXSignal.java @@ -7,7 +7,7 @@ import java.util.function.Function; /** - * An enum that represents the different signals that can be gotten from a Talon FX motor. + * An enum that represents the different signals that can be sent from a TalonFX motor. */ public enum TalonFXSignal { POSITION(TalonFX::getPosition), diff --git a/src/main/java/org/trigon/hardware/rev/spark/SparkMotor.java b/src/main/java/org/trigon/hardware/rev/spark/SparkMotor.java index a6790b6a..d927a917 100644 --- a/src/main/java/org/trigon/hardware/rev/spark/SparkMotor.java +++ b/src/main/java/org/trigon/hardware/rev/spark/SparkMotor.java @@ -143,10 +143,11 @@ public void setReference(double value, CANSparkBase.ControlType controlType, int } /** - * Set the rate of transmission for periodic frames from the SPARK motor. + * Sets the transmission period for a specific periodic frame on the motor controller. + * This method adjusts the rate at which the controller sends the frame, but the change is not saved permanently and will reset on powerup. * - * @param frame the frame to set the period for - * @param periodMs the period in milliseconds + * @param frame The periodic frame to modify + * @param periodMs The new transmission period in milliseconds. */ public void setPeriodicFramePeriod(CANSparkLowLevel.PeriodicFrame frame, int periodMs) { motorIO.setPeriodicFramePeriod(frame, periodMs); @@ -160,7 +161,7 @@ public void stopMotor() { } /** - * Sets the motors neutral value. + * Sets the motors neutral mode. * * @param brake should the motor brake */ @@ -169,7 +170,7 @@ public void setBrake(boolean brake) { } /** - * Sets the motors inverted value. + * Sets the motor's inverted value. * * @param inverted should the motor be inverted */ @@ -180,7 +181,7 @@ public void setInverted(boolean inverted) { /** * Enables and sets the voltage compensation. * - * @param voltage the voltage to set + * @param voltage the voltage compensation to set */ public void enableVoltageCompensation(double voltage) { motorIO.enableVoltageCompensation(voltage); @@ -251,7 +252,7 @@ public void enablePIDWrapping(double minimumInput, double maximumInput) { } /** - * Writes all settings to flash + * Saves the current motor controller configuration to non-volatile memory to retain settings after power cycles. */ public void burnFlash() { CompletableFuture.runAsync(() -> { @@ -267,4 +268,4 @@ private SparkIO createSparkIO(int id, SparkType sparkType, DCMotor simulationMot return new SimulationSparkIO(id, simulationMotor); return new RealSparkIO(id, sparkType); } -} +} \ No newline at end of file diff --git a/src/main/java/org/trigon/hardware/rev/spark/SparkSignal.java b/src/main/java/org/trigon/hardware/rev/spark/SparkSignal.java index c92fd2a0..2b5aad09 100644 --- a/src/main/java/org/trigon/hardware/rev/spark/SparkSignal.java +++ b/src/main/java/org/trigon/hardware/rev/spark/SparkSignal.java @@ -8,7 +8,7 @@ import java.util.function.Function; /** - * Enum for the different signals that can be read from a Spark motor. + * An enum that represents the different signals that can be sent from a Spark motor. */ public enum SparkSignal { POSITION(null, SparkEncoder::getPositionRotations), diff --git a/src/main/java/org/trigon/hardware/rev/spark/SparkType.java b/src/main/java/org/trigon/hardware/rev/spark/SparkType.java index 88d3ff80..944dd937 100644 --- a/src/main/java/org/trigon/hardware/rev/spark/SparkType.java +++ b/src/main/java/org/trigon/hardware/rev/spark/SparkType.java @@ -7,7 +7,7 @@ import java.util.function.Function; /** - * Enum for the different types of Spark motors. + * An enum that represents the different types of Spark motors. */ public enum SparkType { SPARK_MAX((id -> new CANSparkMax(id, CANSparkMax.MotorType.kBrushless))), diff --git a/src/main/java/org/trigon/hardware/simulation/ElevatorSimulation.java b/src/main/java/org/trigon/hardware/simulation/ElevatorSimulation.java index 5e12e7b5..0fd20745 100644 --- a/src/main/java/org/trigon/hardware/simulation/ElevatorSimulation.java +++ b/src/main/java/org/trigon/hardware/simulation/ElevatorSimulation.java @@ -16,13 +16,13 @@ public class ElevatorSimulation extends MotorPhysicsSimulation { /** * Creates a new ElevatorSimulation. * - * @param gearbox The motor used to move the elevator - * @param gearRatio The gear ratio - * @param carriageMassKilograms The mass of the elevator carriage in kilograms - * @param drumRadiusMeters The radius of the drum in meters - * @param retractedHeightMeters The height of the elevator when retracted in meters - * @param maximumHeightMeters The maximum height of the elevator in meters - * @param simulateGravity Whether to simulate gravity + * @param gearbox the motor used to move the elevator + * @param gearRatio the motor's gear ratio + * @param carriageMassKilograms the mass of the elevator carriage in kilograms + * @param drumRadiusMeters the radius of the drum in meters + * @param retractedHeightMeters the height of the elevator when retracted in meters + * @param maximumHeightMeters the maximum height of the elevator in meters + * @param simulateGravity whether to simulate gravity */ public ElevatorSimulation(DCMotor gearbox, double gearRatio, double carriageMassKilograms, double drumRadiusMeters, double retractedHeightMeters, double maximumHeightMeters, boolean simulateGravity) { super(gearRatio); diff --git a/src/main/java/org/trigon/hardware/simulation/FlywheelSimulation.java b/src/main/java/org/trigon/hardware/simulation/FlywheelSimulation.java index 25db7742..7ef2a5b3 100644 --- a/src/main/java/org/trigon/hardware/simulation/FlywheelSimulation.java +++ b/src/main/java/org/trigon/hardware/simulation/FlywheelSimulation.java @@ -16,9 +16,9 @@ public class FlywheelSimulation extends MotorPhysicsSimulation { /** * Creates a new FlywheelSimulation. * - * @param gearbox The motor used to control the flywheel - * @param gearRatio The gear ratio - * @param momentOfInertia The moment of inertia of the flywheel + * @param gearbox the motor used to control the flywheel + * @param gearRatio the motor's gear ratio + * @param momentOfInertia the moment of inertia of the flywheel */ public FlywheelSimulation(DCMotor gearbox, double gearRatio, double momentOfInertia) { super(gearRatio); @@ -28,10 +28,10 @@ public FlywheelSimulation(DCMotor gearbox, double gearRatio, double momentOfIner /** * Creates a new FlywheelSimulation. * - * @param gearbox The motor used to control the flywheel - * @param gearRatio The gear ratio - * @param kv The velocity gain of the flywheel - * @param ka The acceleration gain of the flywheel + * @param gearbox the motor used to control the flywheel + * @param gearRatio the motor's gear ratio + * @param kv voltage needed to maintain constant velocity + * @param ka voltage needed to induce a specific acceleration */ public FlywheelSimulation(DCMotor gearbox, double gearRatio, double kv, double ka) { super(gearRatio); @@ -41,7 +41,7 @@ public FlywheelSimulation(DCMotor gearbox, double gearRatio, double kv, double k /** * Gets the current draw of the flywheel in amperes. * - * @return The current in amperes + * @return the current in amperes */ @Override public double getCurrent() { diff --git a/src/main/java/org/trigon/hardware/simulation/GyroSimulation.java b/src/main/java/org/trigon/hardware/simulation/GyroSimulation.java index 6cea52d8..c3bc2c66 100644 --- a/src/main/java/org/trigon/hardware/simulation/GyroSimulation.java +++ b/src/main/java/org/trigon/hardware/simulation/GyroSimulation.java @@ -18,10 +18,10 @@ public double getGyroYawDegrees() { } /** - * Updates the gyro simulation. + * Updates the simulation's current angle in radians based on the angular velocity. * - * @param omegaRadiansPerSecond The angular velocity of the gyro in radians per second - * @param timeSeconds The time in seconds + * @param omegaRadiansPerSecond the angular velocity in radians per second + * @param timeSeconds the time elapsed in seconds since the last update */ public void update(double omegaRadiansPerSecond, double timeSeconds) { simulationRadians += omegaRadiansPerSecond * timeSeconds; diff --git a/src/main/java/org/trigon/hardware/simulation/SimpleMotorSimulation.java b/src/main/java/org/trigon/hardware/simulation/SimpleMotorSimulation.java index 46bd0422..4d5df46a 100644 --- a/src/main/java/org/trigon/hardware/simulation/SimpleMotorSimulation.java +++ b/src/main/java/org/trigon/hardware/simulation/SimpleMotorSimulation.java @@ -14,9 +14,9 @@ public class SimpleMotorSimulation extends MotorPhysicsSimulation { /** * Creates a new SimpleMotorSimulation. * - * @param gearbox The type of motor - * @param gearRatio The gear ratio - * @param momentOfInertia The motors moment of inertia + * @param gearbox the type of motor + * @param gearRatio the motor's gear ratio + * @param momentOfInertia the motor's moment of inertia */ public SimpleMotorSimulation(DCMotor gearbox, double gearRatio, double momentOfInertia) { super(gearRatio); diff --git a/src/main/java/org/trigon/hardware/simulation/SingleJointedArmSimulation.java b/src/main/java/org/trigon/hardware/simulation/SingleJointedArmSimulation.java index 9e4c394d..290266f7 100644 --- a/src/main/java/org/trigon/hardware/simulation/SingleJointedArmSimulation.java +++ b/src/main/java/org/trigon/hardware/simulation/SingleJointedArmSimulation.java @@ -15,13 +15,13 @@ public class SingleJointedArmSimulation extends MotorPhysicsSimulation { /** * Creates a new SingleJointedArmSimulation. * - * @param gearbox The motor used to control the arm - * @param gearRatio The gear ratio - * @param armLengthMeters The length of the arm in meters - * @param armMassKilograms The mass of the arm in kilograms - * @param minimumAngle The minimum angle of the arm - * @param maximumAngle The maximum angle of the arm - * @param simulateGravity Whether to simulate gravity + * @param gearbox the motor used to control the arm + * @param gearRatio the motor's gear ratio + * @param armLengthMeters the length of the arm in meters + * @param armMassKilograms the mass of the arm in kilograms + * @param minimumAngle the minimum angle of the arm + * @param maximumAngle the maximum angle of the arm + * @param simulateGravity a boolean indicating whether to simulate gravity */ public SingleJointedArmSimulation(DCMotor gearbox, double gearRatio, double armLengthMeters, double armMassKilograms, Rotation2d minimumAngle, Rotation2d maximumAngle, boolean simulateGravity) { super(gearRatio); diff --git a/src/main/java/org/trigon/utilities/Conversions.java b/src/main/java/org/trigon/utilities/Conversions.java index 26a46baf..790da24f 100644 --- a/src/main/java/org/trigon/utilities/Conversions.java +++ b/src/main/java/org/trigon/utilities/Conversions.java @@ -3,7 +3,7 @@ import edu.wpi.first.math.trajectory.TrapezoidProfile; /** - * A class that contains various conversion methods. + * A class that contains various methods for unit conversions. */ public class Conversions { public static final double diff --git a/src/main/java/org/trigon/utilities/mirrorable/MirrorablePose2d.java b/src/main/java/org/trigon/utilities/mirrorable/MirrorablePose2d.java index 5e6724ba..ef94df99 100644 --- a/src/main/java/org/trigon/utilities/mirrorable/MirrorablePose2d.java +++ b/src/main/java/org/trigon/utilities/mirrorable/MirrorablePose2d.java @@ -5,7 +5,7 @@ import edu.wpi.first.math.geometry.Translation2d; /** - * A class that represents a {@link Pose2d} that can be mirrored. + * A class that represents a {@link Pose2d} that can be mirrored. Reversing its position and orientation. */ public class MirrorablePose2d extends Mirrorable { public MirrorablePose2d(Pose2d nonMirroredPose, boolean mirrorWhenRedAlliance) { @@ -15,10 +15,10 @@ public MirrorablePose2d(Pose2d nonMirroredPose, boolean mirrorWhenRedAlliance) { /** * Creates a new MirrorablePose2d with the given x, y, and rotation. * - * @param x The x value of the pose. - * @param y The y value of the pose. - * @param rotation The rotation of the pose. - * @param mirrorWhenRedAlliance Whether to mirror the pose when the robot is on the red alliance. + * @param x the x value of the pose. + * @param y the y value of the pose. + * @param rotation the rotation of the pose. + * @param mirrorWhenRedAlliance a boolean indicating whether to mirror the pose when the robot is on the red alliance. */ public MirrorablePose2d(double x, double y, Rotation2d rotation, boolean mirrorWhenRedAlliance) { this(new Pose2d(x, y, rotation), mirrorWhenRedAlliance); @@ -27,9 +27,9 @@ public MirrorablePose2d(double x, double y, Rotation2d rotation, boolean mirrorW /** * Creates a new MirrorablePose2d with the given translation and rotation. * - * @param translation2d The translation of the pose. - * @param rotation The rotation of the pose. - * @param mirrorWhenRedAlliance Whether to mirror the pose when the robot is on the red alliance. + * @param translation2d the translation of the pose. + * @param rotation the rotation of the pose. + * @param mirrorWhenRedAlliance a boolean indicating whether to mirror the pose when the robot is on the red alliance. */ public MirrorablePose2d(Translation2d translation2d, double rotation, boolean mirrorWhenRedAlliance) { this(new Pose2d(translation2d, new Rotation2d(rotation)), mirrorWhenRedAlliance); diff --git a/src/main/java/org/trigon/utilities/mirrorable/MirrorableRotation2d.java b/src/main/java/org/trigon/utilities/mirrorable/MirrorableRotation2d.java index da0b0ce6..0afc4a3e 100644 --- a/src/main/java/org/trigon/utilities/mirrorable/MirrorableRotation2d.java +++ b/src/main/java/org/trigon/utilities/mirrorable/MirrorableRotation2d.java @@ -3,7 +3,7 @@ import edu.wpi.first.math.geometry.Rotation2d; /** - * A class that represents a {@link Rotation2d} that can be mirrored. + * A class that represents a {@link Rotation2d} that can be mirrored. Reversing its orientation. */ public class MirrorableRotation2d extends Mirrorable { public MirrorableRotation2d(Rotation2d nonMirroredRotation, boolean mirrorWhenRedAlliance) { @@ -14,7 +14,7 @@ public MirrorableRotation2d(Rotation2d nonMirroredRotation, boolean mirrorWhenRe * Creates a new MirrorableRotation2d with the given rotation value. * * @param radians the value of the angle in radians - * @param mirrorWhenRedAlliance whether to mirror the object when the robot is on the red alliance + * @param mirrorWhenRedAlliance a boolean indicating whether to mirror the object when the robot is on the red alliance */ public MirrorableRotation2d(double radians, boolean mirrorWhenRedAlliance) { this(new Rotation2d(radians), mirrorWhenRedAlliance); @@ -24,7 +24,7 @@ public MirrorableRotation2d(double radians, boolean mirrorWhenRedAlliance) { * Constructs and returns a MirrorableRotation2d with the given degree value. * * @param degrees the value of the angle in degrees - * @param mirrorWhenRedAlliance whether to mirror the object when the robot is on the red alliance + * @param mirrorWhenRedAlliance a boolean indicating whether to mirror the object when the robot is on the red alliance * @return the rotation object with the desired angle value */ public static MirrorableRotation2d fromDegrees(double degrees, boolean mirrorWhenRedAlliance) { @@ -35,7 +35,7 @@ public static MirrorableRotation2d fromDegrees(double degrees, boolean mirrorWhe * Constructs and returns a MirrorableRotation2d with the given radian value. * * @param radians the value of the angle in radians - * @param mirrorWhenRedAlliance whether to mirror the object when the robot is on the red alliance + * @param mirrorWhenRedAlliance a boolean indicating whether to mirror the object when the robot is on the red alliance * @return the rotation object with the desired angle value */ public static MirrorableRotation2d fromRadians(double radians, boolean mirrorWhenRedAlliance) { @@ -46,7 +46,7 @@ public static MirrorableRotation2d fromRadians(double radians, boolean mirrorWhe * Constructs and returns a MirrorableRotation2d with the given number of rotations. * * @param rotations the value of the angle in rotations - * @param mirrorWhenRedAlliance whether to mirror the object when the robot is on the red alliance + * @param mirrorWhenRedAlliance a boolean indicating whether to mirror the object when the robot is on the red alliance * @return the rotation object with the desired angle value */ public static MirrorableRotation2d fromRotations(double rotations, boolean mirrorWhenRedAlliance) { diff --git a/src/main/java/org/trigon/utilities/mirrorable/MirrorableTranslation3d.java b/src/main/java/org/trigon/utilities/mirrorable/MirrorableTranslation3d.java index 13226309..0ad8fd86 100644 --- a/src/main/java/org/trigon/utilities/mirrorable/MirrorableTranslation3d.java +++ b/src/main/java/org/trigon/utilities/mirrorable/MirrorableTranslation3d.java @@ -3,14 +3,14 @@ import edu.wpi.first.math.geometry.Translation3d; /** - * A class that represents a {@link Translation3d} that can be mirrored. + * A class that represents a {@link Translation3d} that can be mirrored. Reversing its position. */ public class MirrorableTranslation3d extends Mirrorable { /** * Creates a new MirrorableTranslation3d with the given translation. * * @param nonMirroredTranslation the translation to mirror - * @param mirrorWhenRedAlliance whether to mirror the object when the robot is on the red alliance + * @param mirrorWhenRedAlliance a boolean indicating whether to mirror the object when the robot is on the red alliance */ public MirrorableTranslation3d(Translation3d nonMirroredTranslation, boolean mirrorWhenRedAlliance) { super(nonMirroredTranslation, mirrorWhenRedAlliance); @@ -22,7 +22,7 @@ public MirrorableTranslation3d(Translation3d nonMirroredTranslation, boolean mir * @param x the x value of the translation * @param y the y value of the translation * @param z the z value of the translation - * @param mirrorWhenRedAlliance whether to mirror the object when the robot is on the red alliance + * @param mirrorWhenRedAlliance a boolean indicating whether to mirror the object when the robot is on the red alliance */ public MirrorableTranslation3d(double x, double y, double z, boolean mirrorWhenRedAlliance) { this(new Translation3d(x, y, z), mirrorWhenRedAlliance); @@ -36,4 +36,4 @@ protected Translation3d mirror(Translation3d translation) { translation.getZ() ); } -} +} \ No newline at end of file From 8fd094b416bbdff0628d5c4af3f1a3aed01e384b Mon Sep 17 00:00:00 2001 From: Nummun14 <142012009+Nummun14@users.noreply.github.com> Date: Thu, 21 Nov 2024 20:46:49 +0200 Subject: [PATCH 05/61] updated libraries and adapted code to it --- build.gradle | 2 +- .../trigon/hardware/rev/spark/SparkIO.java | 47 ++----- .../trigon/hardware/rev/spark/SparkMotor.java | 115 +++--------------- .../hardware/rev/spark/SparkSignal.java | 14 +-- .../trigon/hardware/rev/spark/SparkType.java | 14 +-- .../hardware/rev/spark/io/RealSparkIO.java | 80 +++--------- .../rev/spark/io/SimulationSparkIO.java | 82 ++++--------- .../sparkecnoder/AbsoluteSparkEncoder.java | 16 +-- .../sparkecnoder/RelativeSparkEncoder.java | 14 +-- .../rev/sparkecnoder/SparkEncoder.java | 12 +- .../simulation/FlywheelSimulation.java | 22 ++-- .../simulation/SimpleMotorSimulation.java | 12 +- vendordeps/AdvantageKit.json | 2 +- ...on => PathplannerLib-2025.0.0-beta-4.json} | 14 +-- ...enix5.json => Phoenix5-5.34.0-beta-2.json} | 28 ++--- ...enix6.json => Phoenix6-25.0.0-beta-2.json} | 91 +++++++------- ...EVLib.json => REVLib-2025.0.0-beta-2.json} | 16 +-- vendordeps/WPILibNewCommands.json | 2 +- 18 files changed, 181 insertions(+), 402 deletions(-) rename vendordeps/{PathplannerLib.json => PathplannerLib-2025.0.0-beta-4.json} (80%) rename vendordeps/{Phoenix5.json => Phoenix5-5.34.0-beta-2.json} (88%) rename vendordeps/{Phoenix6.json => Phoenix6-25.0.0-beta-2.json} (85%) rename vendordeps/{REVLib.json => REVLib-2025.0.0-beta-2.json} (87%) diff --git a/build.gradle b/build.gradle index 532d3821..35584017 100644 --- a/build.gradle +++ b/build.gradle @@ -1,7 +1,7 @@ plugins { id "java" id "maven-publish" - id "edu.wpi.first.GradleRIO" version "2024.3.2" + id "edu.wpi.first.GradleRIO" version "2025.1.1-beta-1" id "edu.wpi.first.WpilibTools" version "1.3.0" } diff --git a/src/main/java/org/trigon/hardware/rev/spark/SparkIO.java b/src/main/java/org/trigon/hardware/rev/spark/SparkIO.java index 3332921d..51e2c469 100644 --- a/src/main/java/org/trigon/hardware/rev/spark/SparkIO.java +++ b/src/main/java/org/trigon/hardware/rev/spark/SparkIO.java @@ -1,63 +1,36 @@ package org.trigon.hardware.rev.spark; -import com.revrobotics.CANSparkBase; -import com.revrobotics.CANSparkLowLevel; -import com.revrobotics.SparkPIDController; +import com.revrobotics.spark.SparkBase; +import com.revrobotics.spark.SparkClosedLoopController; +import com.revrobotics.spark.config.SparkMaxConfig; import org.trigon.hardware.rev.sparkecnoder.SparkEncoder; public class SparkIO { - public void setReference(double value, CANSparkBase.ControlType ctrl) { + public void setReference(double value, SparkBase.ControlType ctrl) { } - public void setReference(double value, CANSparkBase.ControlType ctrl, int pidSlot) { + public void setReference(double value, SparkBase.ControlType ctrl, int pidSlot) { } - public void setReference(double value, CANSparkBase.ControlType ctrl, int pidSlot, double arbFeedForward) { + public void setReference(double value, SparkBase.ControlType ctrl, int pidSlot, double arbFeedForward) { } - public void setReference(double value, CANSparkBase.ControlType ctrl, int pidSlot, double arbFeedForward, SparkPIDController.ArbFFUnits arbFFUnits) { + public void setReference(double value, SparkBase.ControlType ctrl, int pidSlot, double arbFeedForward, SparkClosedLoopController.ArbFFUnits arbFFUnits) { } - public void setPeriodicFramePeriod(CANSparkLowLevel.PeriodicFrame frame, int periodMs) { + public void setPeriodicFrameTimeout(int periodMs) { } public void stopMotor() { } - public void setBrake(boolean brake) { + public void configure(SparkMaxConfig configuration, SparkBase.ResetMode resetMode, SparkBase.PersistMode persistMode) { } public void setInverted(boolean inverted) { } - public void enableVoltageCompensation(double voltage) { - } - - public void setClosedLoopRampRate(double rampRate) { - } - - public void setOpenLoopRampRate(double rampRate) { - } - - public void setSmartCurrentLimit(int limit) { - } - - public void setConversionsFactor(double conversionsFactor) { - } - - public void setPID(double p, double i, double d) { - } - - public void restoreFactoryDefaults() { - } - - public void burnFlash() { - } - - public void enablePIDWrapping(double minInput, double maxInput) { - } - - public CANSparkBase getMotor() { + public SparkBase getMotor() { return null; } diff --git a/src/main/java/org/trigon/hardware/rev/spark/SparkMotor.java b/src/main/java/org/trigon/hardware/rev/spark/SparkMotor.java index d927a917..3748fb68 100644 --- a/src/main/java/org/trigon/hardware/rev/spark/SparkMotor.java +++ b/src/main/java/org/trigon/hardware/rev/spark/SparkMotor.java @@ -1,17 +1,14 @@ package org.trigon.hardware.rev.spark; -import com.revrobotics.CANSparkBase; -import com.revrobotics.CANSparkLowLevel; -import com.revrobotics.SparkPIDController; +import com.revrobotics.spark.SparkBase; +import com.revrobotics.spark.SparkClosedLoopController; +import com.revrobotics.spark.config.SparkMaxConfig; import edu.wpi.first.math.system.plant.DCMotor; -import edu.wpi.first.wpilibj.Timer; import org.littletonrobotics.junction.Logger; import org.trigon.hardware.RobotHardwareStats; import org.trigon.hardware.rev.spark.io.RealSparkIO; import org.trigon.hardware.rev.spark.io.SimulationSparkIO; -import java.util.concurrent.CompletableFuture; - /** * A class the represents a Spark motor. Used to control and read data from a Spark motor. */ @@ -102,7 +99,7 @@ public double[] getThreadedSignal(SparkSignal signal) { * @param value the value to set * @param controlType the control type */ - public void setReference(double value, CANSparkBase.ControlType controlType) { + public void setReference(double value, SparkBase.ControlType controlType) { motorIO.setReference(value, controlType); } @@ -113,7 +110,7 @@ public void setReference(double value, CANSparkBase.ControlType controlType) { * @param controlType the control type * @param pidSlot the PID slot to use */ - public void setReference(double value, CANSparkBase.ControlType controlType, int pidSlot) { + public void setReference(double value, SparkBase.ControlType controlType, int pidSlot) { motorIO.setReference(value, controlType, pidSlot); } @@ -125,7 +122,7 @@ public void setReference(double value, CANSparkBase.ControlType controlType, int * @param pidSlot the PID slot to use * @param arbFeedForward the feed forward value */ - public void setReference(double value, CANSparkBase.ControlType controlType, int pidSlot, double arbFeedForward) { + public void setReference(double value, SparkBase.ControlType controlType, int pidSlot, double arbFeedForward) { motorIO.setReference(value, controlType, pidSlot, arbFeedForward); } @@ -138,7 +135,7 @@ public void setReference(double value, CANSparkBase.ControlType controlType, int * @param arbFeedForward the feed forward value * @param arbFeedForwardUnits the units of the feed forward value */ - public void setReference(double value, CANSparkBase.ControlType controlType, int pidSlot, double arbFeedForward, SparkPIDController.ArbFFUnits arbFeedForwardUnits) { + public void setReference(double value, SparkBase.ControlType controlType, int pidSlot, double arbFeedForward, SparkClosedLoopController.ArbFFUnits arbFeedForwardUnits) { motorIO.setReference(value, controlType, pidSlot, arbFeedForward, arbFeedForwardUnits); } @@ -146,11 +143,10 @@ public void setReference(double value, CANSparkBase.ControlType controlType, int * Sets the transmission period for a specific periodic frame on the motor controller. * This method adjusts the rate at which the controller sends the frame, but the change is not saved permanently and will reset on powerup. * - * @param frame The periodic frame to modify * @param periodMs The new transmission period in milliseconds. */ - public void setPeriodicFramePeriod(CANSparkLowLevel.PeriodicFrame frame, int periodMs) { - motorIO.setPeriodicFramePeriod(frame, periodMs); + public void setPeriodicFramePeriod(int periodMs) { + motorIO.setPeriodicFrameTimeout(periodMs); } /** @@ -160,15 +156,6 @@ public void stopMotor() { motorIO.stopMotor(); } - /** - * Sets the motors neutral mode. - * - * @param brake should the motor brake - */ - public void setBrake(boolean brake) { - motorIO.setBrake(brake); - } - /** * Sets the motor's inverted value. * @@ -179,86 +166,14 @@ public void setInverted(boolean inverted) { } /** - * Enables and sets the voltage compensation. - * - * @param voltage the voltage compensation to set - */ - public void enableVoltageCompensation(double voltage) { - motorIO.enableVoltageCompensation(voltage); - } - - /** - * Sets the ramp rate for closed loop control. - * - * @param rampRate the ramp rate to set - */ - public void setClosedLoopRampRate(double rampRate) { - motorIO.setClosedLoopRampRate(rampRate); - } - - /** - * Sets the smart current limitAmperes in amperes. - * - * @param limitAmperes the limitAmperes to set - */ - public void setSmartCurrentLimit(int limitAmperes) { - motorIO.setSmartCurrentLimit(limitAmperes); - } - - /** - * Sets the ramp rate for open loop control. - * - * @param rampRate the ramp rate to set - */ - public void setOpenLoopRampRate(double rampRate) { - motorIO.setOpenLoopRampRate(rampRate); - } - - /** - * Sets the PID values for the motor. - * - * @param p the proportional value - * @param i the integral value - * @param d the derivative value - */ - public void setPID(double p, double i, double d) { - motorIO.setPID(p, i, d); - } - - /** - * Sets the conversion factor for values received the motor. - * - * @param conversionsFactor the conversion factor to set - */ - public void setConversionsFactor(double conversionsFactor) { - motorIO.setConversionsFactor(conversionsFactor); - } - - /** - * Restores the motor settings to factory defaults. - */ - public void restoreFactoryDefaults() { - motorIO.restoreFactoryDefaults(); - } - - /** - * Enables PID wrapping. + * Applies the configuration to the motor. * - * @param minimumInput the minimum input - * @param maximumInput the maximum input - */ - public void enablePIDWrapping(double minimumInput, double maximumInput) { - motorIO.enablePIDWrapping(minimumInput, maximumInput); - } - - /** - * Saves the current motor controller configuration to non-volatile memory to retain settings after power cycles. + * @param configuration the configuration to apply + * @param resetMode whether to reset safe parameters before setting the configuration + * @param persistMode whether to persist the parameters after setting the configuration */ - public void burnFlash() { - CompletableFuture.runAsync(() -> { - Timer.delay(5); - motorIO.burnFlash(); - }); + public void configure(SparkMaxConfig configuration, SparkBase.ResetMode resetMode, SparkBase.PersistMode persistMode) { + motorIO.configure(configuration, resetMode, persistMode); } private SparkIO createSparkIO(int id, SparkType sparkType, DCMotor simulationMotor) { diff --git a/src/main/java/org/trigon/hardware/rev/spark/SparkSignal.java b/src/main/java/org/trigon/hardware/rev/spark/SparkSignal.java index 2b5aad09..5873bf49 100644 --- a/src/main/java/org/trigon/hardware/rev/spark/SparkSignal.java +++ b/src/main/java/org/trigon/hardware/rev/spark/SparkSignal.java @@ -1,6 +1,6 @@ package org.trigon.hardware.rev.spark; -import com.revrobotics.CANSparkBase; +import com.revrobotics.spark.SparkBase; import org.trigon.hardware.RobotHardwareStats; import org.trigon.hardware.SignalUtilities; import org.trigon.hardware.rev.sparkecnoder.SparkEncoder; @@ -13,21 +13,21 @@ public enum SparkSignal { POSITION(null, SparkEncoder::getPositionRotations), VELOCITY(null, SparkEncoder::getVelocityRotationsPerSecond), - OUTPUT_CURRENT(CANSparkBase::getOutputCurrent, null), - APPLIED_OUTPUT(CANSparkBase::getAppliedOutput, null), - BUS_VOLTAGE(CANSparkBase::getBusVoltage, null); + OUTPUT_CURRENT(SparkBase::getOutputCurrent, null), + APPLIED_OUTPUT(SparkBase::getAppliedOutput, null), + BUS_VOLTAGE(SparkBase::getBusVoltage, null); final String name; - final Function motorSignalFunction; + final Function motorSignalFunction; final Function encoderSignalFunction; - SparkSignal(Function motorSignalFunction, Function encoderSignalFunction) { + SparkSignal(Function motorSignalFunction, Function encoderSignalFunction) { this.name = SignalUtilities.enumNameToSignalName(name()); this.motorSignalFunction = motorSignalFunction; this.encoderSignalFunction = encoderSignalFunction; } - public SparkStatusSignal getStatusSignal(CANSparkBase spark, SparkEncoder encoder) { + public SparkStatusSignal getStatusSignal(SparkBase spark, SparkEncoder encoder) { if (RobotHardwareStats.isReplay() || spark == null || encoder == null) return null; if (motorSignalFunction != null) diff --git a/src/main/java/org/trigon/hardware/rev/spark/SparkType.java b/src/main/java/org/trigon/hardware/rev/spark/SparkType.java index 944dd937..60231ca8 100644 --- a/src/main/java/org/trigon/hardware/rev/spark/SparkType.java +++ b/src/main/java/org/trigon/hardware/rev/spark/SparkType.java @@ -1,8 +1,8 @@ package org.trigon.hardware.rev.spark; -import com.revrobotics.CANSparkBase; -import com.revrobotics.CANSparkFlex; -import com.revrobotics.CANSparkMax; +import com.revrobotics.spark.SparkBase; +import com.revrobotics.spark.SparkFlex; +import com.revrobotics.spark.SparkMax; import java.util.function.Function; @@ -10,12 +10,12 @@ * An enum that represents the different types of Spark motors. */ public enum SparkType { - SPARK_MAX((id -> new CANSparkMax(id, CANSparkMax.MotorType.kBrushless))), - SPARK_FLEW((id -> new CANSparkFlex(id, CANSparkMax.MotorType.kBrushless))); + SPARK_MAX((id -> new SparkMax(id, SparkMax.MotorType.kBrushless))), + SPARK_FLEW((id -> new SparkFlex(id, SparkMax.MotorType.kBrushless))); - public final Function sparkCreator; + public final Function sparkCreator; - SparkType(Function sparkCreator) { + SparkType(Function sparkCreator) { this.sparkCreator = sparkCreator; } } diff --git a/src/main/java/org/trigon/hardware/rev/spark/io/RealSparkIO.java b/src/main/java/org/trigon/hardware/rev/spark/io/RealSparkIO.java index 948b2d65..21dd4cb1 100644 --- a/src/main/java/org/trigon/hardware/rev/spark/io/RealSparkIO.java +++ b/src/main/java/org/trigon/hardware/rev/spark/io/RealSparkIO.java @@ -1,31 +1,30 @@ package org.trigon.hardware.rev.spark.io; -import com.revrobotics.CANSparkBase; -import com.revrobotics.CANSparkLowLevel; -import com.revrobotics.CANSparkMax; -import com.revrobotics.SparkPIDController; +import com.revrobotics.spark.SparkBase; +import com.revrobotics.spark.SparkClosedLoopController; +import com.revrobotics.spark.config.SparkMaxConfig; import org.trigon.hardware.rev.spark.SparkIO; import org.trigon.hardware.rev.spark.SparkType; import org.trigon.hardware.rev.sparkecnoder.SparkEncoder; public class RealSparkIO extends SparkIO { - private final CANSparkBase motor; - private final SparkPIDController pidController; + private final SparkBase motor; + private final SparkClosedLoopController pidController; private final SparkEncoder encoder; public RealSparkIO(int id, SparkType sparkType) { motor = sparkType.sparkCreator.apply(id); - pidController = motor.getPIDController(); + pidController = motor.getClosedLoopController(); encoder = SparkEncoder.createEncoder(motor); } @Override - public void setReference(double value, CANSparkBase.ControlType ctrl) { + public void setReference(double value, SparkBase.ControlType ctrl) { pidController.setReference(value, ctrl); } @Override - public void setReference(double value, CANSparkBase.ControlType ctrl, int pidSlot) { + public void setReference(double value, SparkBase.ControlType ctrl, int pidSlot) { pidController.setReference(value, ctrl, pidSlot); } @@ -35,7 +34,7 @@ public SparkEncoder getEncoder() { } @Override - public CANSparkBase getMotor() { + public SparkBase getMotor() { return motor; } @@ -45,76 +44,27 @@ public void stopMotor() { } @Override - public void setPeriodicFramePeriod(CANSparkLowLevel.PeriodicFrame frame, int periodMs) { - motor.setPeriodicFramePeriod(frame, periodMs); + public void setPeriodicFrameTimeout(int periodMs) { + motor.setPeriodicFrameTimeout(periodMs); } @Override - public void setReference(double value, CANSparkBase.ControlType ctrl, int pidSlot, double arbFeedForward) { + public void setReference(double value, SparkBase.ControlType ctrl, int pidSlot, double arbFeedForward) { pidController.setReference(value, ctrl, pidSlot, arbFeedForward); } @Override - public void setReference(double value, CANSparkBase.ControlType ctrl, int pidSlot, double arbFeedForward, SparkPIDController.ArbFFUnits arbFFUnits) { + public void setReference(double value, SparkBase.ControlType ctrl, int pidSlot, double arbFeedForward, SparkClosedLoopController.ArbFFUnits arbFFUnits) { pidController.setReference(value, ctrl, pidSlot, arbFeedForward, arbFFUnits); } @Override - public void setBrake(boolean brake) { - motor.setIdleMode(brake ? CANSparkMax.IdleMode.kBrake : CANSparkMax.IdleMode.kCoast); + public void configure(SparkMaxConfig configuration, SparkBase.ResetMode resetMode, SparkBase.PersistMode persistMode) { + motor.configure(configuration, resetMode, persistMode); } @Override public void setInverted(boolean inverted) { motor.setInverted(inverted); } - - @Override - public void enableVoltageCompensation(double voltage) { - motor.enableVoltageCompensation(voltage); - } - - @Override - public void setClosedLoopRampRate(double rampRate) { - motor.setClosedLoopRampRate(rampRate); - } - - @Override - public void setSmartCurrentLimit(int limit) { - motor.setSmartCurrentLimit(limit); - } - - @Override - public void setOpenLoopRampRate(double rampRate) { - motor.setOpenLoopRampRate(rampRate); - } - - @Override - public void setPID(double p, double i, double d) { - pidController.setP(p); - pidController.setI(i); - pidController.setD(d); - } - - @Override - public void setConversionsFactor(double conversionsFactor) { - encoder.setConversionsFactor(conversionsFactor); - } - - @Override - public void restoreFactoryDefaults() { - motor.restoreFactoryDefaults(); - } - - @Override - public void burnFlash() { - motor.burnFlash(); - } - - @Override - public void enablePIDWrapping(double minInput, double maxInput) { - pidController.setPositionPIDWrappingEnabled(true); - pidController.setPositionPIDWrappingMinInput(minInput); - pidController.setPositionPIDWrappingMaxInput(maxInput); - } } diff --git a/src/main/java/org/trigon/hardware/rev/spark/io/SimulationSparkIO.java b/src/main/java/org/trigon/hardware/rev/spark/io/SimulationSparkIO.java index c1aae211..851f2f8b 100644 --- a/src/main/java/org/trigon/hardware/rev/spark/io/SimulationSparkIO.java +++ b/src/main/java/org/trigon/hardware/rev/spark/io/SimulationSparkIO.java @@ -1,29 +1,34 @@ package org.trigon.hardware.rev.spark.io; -import com.revrobotics.*; +import com.revrobotics.sim.SparkMaxSim; +import com.revrobotics.spark.SparkBase; +import com.revrobotics.spark.SparkClosedLoopController; +import com.revrobotics.spark.SparkMax; +import com.revrobotics.spark.config.SparkMaxConfig; import edu.wpi.first.math.system.plant.DCMotor; import org.trigon.hardware.rev.spark.SparkIO; import org.trigon.hardware.rev.sparkecnoder.SparkEncoder; public class SimulationSparkIO extends SparkIO { - private final CANSparkMax motor; - private final SparkPIDController pidController; + private final SparkMax motor; + private final SparkClosedLoopController pidController; private final SparkEncoder encoder; + private final SparkMaxSim simulation; public SimulationSparkIO(int id, DCMotor gearbox) { - motor = new CANSparkMax(id, CANSparkMax.MotorType.kBrushless); - REVPhysicsSim.getInstance().addSparkMax(motor, gearbox); - pidController = motor.getPIDController(); + motor = new SparkMax(id, SparkMax.MotorType.kBrushless); + simulation = new SparkMaxSim(motor, DCMotor.getNeo550(1)); + pidController = motor.getClosedLoopController(); encoder = SparkEncoder.createRelativeEncoder(motor); } @Override - public void setReference(double value, CANSparkBase.ControlType ctrl) { + public void setReference(double value, SparkBase.ControlType ctrl) { pidController.setReference(value, ctrl); } @Override - public void setReference(double value, CANSparkBase.ControlType ctrl, int pidSlot) { + public void setReference(double value, SparkBase.ControlType ctrl, int pidSlot) { pidController.setReference(value, ctrl, pidSlot); } @@ -33,27 +38,28 @@ public SparkEncoder getEncoder() { } @Override - public CANSparkBase getMotor() { + public SparkBase getMotor() { return motor; } @Override public void stopMotor() { motor.stopMotor(); + simulation.setAppliedOutput(0); } @Override - public void setPeriodicFramePeriod(CANSparkLowLevel.PeriodicFrame frame, int periodMs) { - motor.setPeriodicFramePeriod(frame, periodMs); + public void setPeriodicFrameTimeout(int periodMs) { + motor.setPeriodicFrameTimeout(periodMs); } @Override - public void setReference(double value, CANSparkBase.ControlType ctrl, int pidSlot, double arbFeedForward) { + public void setReference(double value, SparkBase.ControlType ctrl, int pidSlot, double arbFeedForward) { pidController.setReference(value, ctrl, pidSlot, arbFeedForward); } @Override - public void setReference(double value, CANSparkBase.ControlType ctrl, int pidSlot, double arbFeedForward, SparkPIDController.ArbFFUnits arbFFUnits) { + public void setReference(double value, SparkBase.ControlType ctrl, int pidSlot, double arbFeedForward, SparkClosedLoopController.ArbFFUnits arbFFUnits) { pidController.setReference(value, ctrl, pidSlot, arbFeedForward, arbFFUnits); } @@ -63,51 +69,7 @@ public void setInverted(boolean inverted) { } @Override - public void enableVoltageCompensation(double voltage) { - motor.enableVoltageCompensation(voltage); + public void configure(SparkMaxConfig configuration, SparkBase.ResetMode resetMode, SparkBase.PersistMode persistMode) { + motor.configure(configuration, resetMode, persistMode); } - - @Override - public void setClosedLoopRampRate(double rampRate) { - motor.setClosedLoopRampRate(rampRate); - } - - @Override - public void setSmartCurrentLimit(int limit) { - motor.setSmartCurrentLimit(limit); - } - - @Override - public void setOpenLoopRampRate(double rampRate) { - motor.setOpenLoopRampRate(rampRate); - } - - @Override - public void setPID(double p, double i, double d) { - pidController.setP(p); - pidController.setI(i); - pidController.setD(d); - } - - @Override - public void setConversionsFactor(double conversionsFactor) { - encoder.setConversionsFactor(conversionsFactor); - } - - @Override - public void restoreFactoryDefaults() { - motor.restoreFactoryDefaults(); - } - - @Override - public void burnFlash() { - motor.burnFlash(); - } - - @Override - public void enablePIDWrapping(double minInput, double maxInput) { - pidController.setPositionPIDWrappingEnabled(true); - pidController.setPositionPIDWrappingMinInput(minInput); - pidController.setPositionPIDWrappingMaxInput(maxInput); - } -} +} \ No newline at end of file diff --git a/src/main/java/org/trigon/hardware/rev/sparkecnoder/AbsoluteSparkEncoder.java b/src/main/java/org/trigon/hardware/rev/sparkecnoder/AbsoluteSparkEncoder.java index fd8ce0a3..0167f679 100644 --- a/src/main/java/org/trigon/hardware/rev/sparkecnoder/AbsoluteSparkEncoder.java +++ b/src/main/java/org/trigon/hardware/rev/sparkecnoder/AbsoluteSparkEncoder.java @@ -1,6 +1,6 @@ package org.trigon.hardware.rev.sparkecnoder; -import com.revrobotics.SparkAbsoluteEncoder; +import com.revrobotics.spark.SparkAbsoluteEncoder; /** * A class that represents an absolute encoder on a Spark MAX motor controller. @@ -15,7 +15,6 @@ public class AbsoluteSparkEncoder extends SparkEncoder { */ public AbsoluteSparkEncoder(SparkAbsoluteEncoder encoder) { this.encoder = encoder; - setConversionsFactor(1); } /** @@ -35,15 +34,4 @@ public double getPositionRotations() { public double getVelocityRotationsPerSecond() { return encoder.getVelocity(); } - - /** - * Sets the conversion factor for values received the encoder. - * - * @param conversionsFactor The conversion factor to use. - */ - @Override - public void setConversionsFactor(double conversionsFactor) { - encoder.setPositionConversionFactor(conversionsFactor); - encoder.setVelocityConversionFactor(conversionsFactor / 60); - } -} +} \ No newline at end of file diff --git a/src/main/java/org/trigon/hardware/rev/sparkecnoder/RelativeSparkEncoder.java b/src/main/java/org/trigon/hardware/rev/sparkecnoder/RelativeSparkEncoder.java index 7a67def8..21be7b2c 100644 --- a/src/main/java/org/trigon/hardware/rev/sparkecnoder/RelativeSparkEncoder.java +++ b/src/main/java/org/trigon/hardware/rev/sparkecnoder/RelativeSparkEncoder.java @@ -15,7 +15,6 @@ public class RelativeSparkEncoder extends SparkEncoder { */ public RelativeSparkEncoder(RelativeEncoder encoder) { this.encoder = encoder; - setConversionsFactor(1); } /** @@ -35,15 +34,4 @@ public double getPositionRotations() { public double getVelocityRotationsPerSecond() { return encoder.getVelocity(); } - - /** - * Sets the conversion factor for values received the encoder. - * - * @param conversionsFactor The conversion factor to use. - */ - @Override - public void setConversionsFactor(double conversionsFactor) { - encoder.setPositionConversionFactor(conversionsFactor); - encoder.setVelocityConversionFactor(conversionsFactor / 60); - } -} +} \ No newline at end of file diff --git a/src/main/java/org/trigon/hardware/rev/sparkecnoder/SparkEncoder.java b/src/main/java/org/trigon/hardware/rev/sparkecnoder/SparkEncoder.java index a187c75c..a63c4f99 100644 --- a/src/main/java/org/trigon/hardware/rev/sparkecnoder/SparkEncoder.java +++ b/src/main/java/org/trigon/hardware/rev/sparkecnoder/SparkEncoder.java @@ -1,10 +1,10 @@ package org.trigon.hardware.rev.sparkecnoder; -import com.revrobotics.CANSparkBase; -import com.revrobotics.SparkAbsoluteEncoder; +import com.revrobotics.spark.SparkAbsoluteEncoder; +import com.revrobotics.spark.SparkBase; public abstract class SparkEncoder { - public static SparkEncoder createEncoder(CANSparkBase spark) { + public static SparkEncoder createEncoder(SparkBase spark) { final SparkAbsoluteEncoder absoluteEncoder = spark.getAbsoluteEncoder(); if (absoluteEncoder != null) return new AbsoluteSparkEncoder(absoluteEncoder); @@ -12,13 +12,11 @@ public static SparkEncoder createEncoder(CANSparkBase spark) { return new RelativeSparkEncoder(spark.getEncoder()); } - public static SparkEncoder createRelativeEncoder(CANSparkBase spark) { + public static SparkEncoder createRelativeEncoder(SparkBase spark) { return new RelativeSparkEncoder(spark.getEncoder()); } public abstract double getPositionRotations(); public abstract double getVelocityRotationsPerSecond(); - - public abstract void setConversionsFactor(double conversionsFactor); -} +} \ No newline at end of file diff --git a/src/main/java/org/trigon/hardware/simulation/FlywheelSimulation.java b/src/main/java/org/trigon/hardware/simulation/FlywheelSimulation.java index 7ef2a5b3..3964a4c2 100644 --- a/src/main/java/org/trigon/hardware/simulation/FlywheelSimulation.java +++ b/src/main/java/org/trigon/hardware/simulation/FlywheelSimulation.java @@ -16,26 +16,26 @@ public class FlywheelSimulation extends MotorPhysicsSimulation { /** * Creates a new FlywheelSimulation. * - * @param gearbox the motor used to control the flywheel - * @param gearRatio the motor's gear ratio - * @param momentOfInertia the moment of inertia of the flywheel + * @param gearbox the motor used to control the flywheel + * @param gearRatio the motor's gear ratio + * @param kv voltage needed to maintain constant velocity + * @param ka voltage needed to induce a specific acceleration */ - public FlywheelSimulation(DCMotor gearbox, double gearRatio, double momentOfInertia) { + public FlywheelSimulation(DCMotor gearbox, double gearRatio, double kv, double ka) { super(gearRatio); - flywheelSimulation = new FlywheelSim(gearbox, gearRatio, momentOfInertia); + flywheelSimulation = new FlywheelSim(LinearSystemId.identifyVelocitySystem(kv, ka), gearbox, gearRatio); } /** * Creates a new FlywheelSimulation. * - * @param gearbox the motor used to control the flywheel - * @param gearRatio the motor's gear ratio - * @param kv voltage needed to maintain constant velocity - * @param ka voltage needed to induce a specific acceleration + * @param gearbox the motor used to control the flywheel + * @param gearRatio the motor's gear ratio + * @param momentOfInertia the flywheel's moment of inertia */ - public FlywheelSimulation(DCMotor gearbox, double gearRatio, double kv, double ka) { + public FlywheelSimulation(DCMotor gearbox, double gearRatio, double momentOfInertia) { super(gearRatio); - flywheelSimulation = new FlywheelSim(LinearSystemId.identifyVelocitySystem(kv, ka), gearbox, gearRatio); + flywheelSimulation = new FlywheelSim(LinearSystemId.createFlywheelSystem(gearbox, momentOfInertia, gearRatio), gearbox, gearRatio); } /** diff --git a/src/main/java/org/trigon/hardware/simulation/SimpleMotorSimulation.java b/src/main/java/org/trigon/hardware/simulation/SimpleMotorSimulation.java index 4d5df46a..c3b78f8d 100644 --- a/src/main/java/org/trigon/hardware/simulation/SimpleMotorSimulation.java +++ b/src/main/java/org/trigon/hardware/simulation/SimpleMotorSimulation.java @@ -1,6 +1,7 @@ package org.trigon.hardware.simulation; import edu.wpi.first.math.system.plant.DCMotor; +import edu.wpi.first.math.system.plant.LinearSystemId; import edu.wpi.first.math.util.Units; import edu.wpi.first.wpilibj.simulation.DCMotorSim; import org.trigon.hardware.RobotHardwareStats; @@ -14,13 +15,14 @@ public class SimpleMotorSimulation extends MotorPhysicsSimulation { /** * Creates a new SimpleMotorSimulation. * - * @param gearbox the type of motor - * @param gearRatio the motor's gear ratio - * @param momentOfInertia the motor's moment of inertia + * @param gearbox The gearbox of the motor + * @param gearRatio The gear ratio of the motor + * @param kv voltage needed to maintain constant velocity + * @param ka voltage needed to induce a specific acceleration */ - public SimpleMotorSimulation(DCMotor gearbox, double gearRatio, double momentOfInertia) { + public SimpleMotorSimulation(DCMotor gearbox, double gearRatio, double kv, double ka) { super(gearRatio); - motorSimulation = new DCMotorSim(gearbox, gearRatio, momentOfInertia); + motorSimulation = new DCMotorSim(LinearSystemId.createDCMotorSystem(kv, ka), gearbox, gearRatio); } /** diff --git a/vendordeps/AdvantageKit.json b/vendordeps/AdvantageKit.json index 63dacbb5..d9b69032 100644 --- a/vendordeps/AdvantageKit.json +++ b/vendordeps/AdvantageKit.json @@ -3,7 +3,7 @@ "name": "AdvantageKit", "version": "3.2.1", "uuid": "d820cc26-74e3-11ec-90d6-0242ac120003", - "frcYear": "2024", + "frcYear": "2025", "mavenUrls": [], "jsonUrl": "https://github.com/Mechanical-Advantage/AdvantageKit/releases/latest/download/AdvantageKit.json", "javaDependencies": [ diff --git a/vendordeps/PathplannerLib.json b/vendordeps/PathplannerLib-2025.0.0-beta-4.json similarity index 80% rename from vendordeps/PathplannerLib.json rename to vendordeps/PathplannerLib-2025.0.0-beta-4.json index 6dc648db..de2782ee 100644 --- a/vendordeps/PathplannerLib.json +++ b/vendordeps/PathplannerLib-2025.0.0-beta-4.json @@ -1,18 +1,18 @@ { - "fileName": "PathplannerLib.json", + "fileName": "PathplannerLib-2025.0.0-beta-4.json", "name": "PathplannerLib", - "version": "2024.2.8", + "version": "2025.0.0-beta-4", "uuid": "1b42324f-17c6-4875-8e77-1c312bc8c786", - "frcYear": "2024", + "frcYear": "2025", "mavenUrls": [ "https://3015rangerrobotics.github.io/pathplannerlib/repo" ], - "jsonUrl": "https://3015rangerrobotics.github.io/pathplannerlib/PathplannerLib.json", + "jsonUrl": "https://3015rangerrobotics.github.io/pathplannerlib/PathplannerLib-beta.json", "javaDependencies": [ { "groupId": "com.pathplanner.lib", "artifactId": "PathplannerLib-java", - "version": "2024.2.8" + "version": "2025.0.0-beta-4" } ], "jniDependencies": [], @@ -20,15 +20,15 @@ { "groupId": "com.pathplanner.lib", "artifactId": "PathplannerLib-cpp", - "version": "2024.2.8", + "version": "2025.0.0-beta-4", "libName": "PathplannerLib", "headerClassifier": "headers", "sharedLibrary": false, "skipInvalidPlatforms": true, "binaryPlatforms": [ "windowsx86-64", - "linuxx86-64", "osxuniversal", + "linuxx86-64", "linuxathena", "linuxarm32", "linuxarm64" diff --git a/vendordeps/Phoenix5.json b/vendordeps/Phoenix5-5.34.0-beta-2.json similarity index 88% rename from vendordeps/Phoenix5.json rename to vendordeps/Phoenix5-5.34.0-beta-2.json index ff7359e1..e27638b2 100644 --- a/vendordeps/Phoenix5.json +++ b/vendordeps/Phoenix5-5.34.0-beta-2.json @@ -1,13 +1,13 @@ { - "fileName": "Phoenix5.json", + "fileName": "Phoenix5-5.34.0-beta-2.json", "name": "CTRE-Phoenix (v5)", - "version": "5.33.1", - "frcYear": 2024, + "version": "5.34.0-beta-2", + "frcYear": "2025", "uuid": "ab676553-b602-441f-a38d-f1296eff6537", "mavenUrls": [ "https://maven.ctr-electronics.com/release/" ], - "jsonUrl": "https://maven.ctr-electronics.com/release/com/ctre/phoenix/Phoenix5-frc2024-latest.json", + "jsonUrl": "https://maven.ctr-electronics.com/release/com/ctre/phoenix/Phoenix5-frc2025-beta-latest.json", "requires": [ { "uuid": "e995de00-2c64-4df5-8831-c1441420ff19", @@ -20,19 +20,19 @@ { "groupId": "com.ctre.phoenix", "artifactId": "api-java", - "version": "5.33.1" + "version": "5.34.0-beta-2" }, { "groupId": "com.ctre.phoenix", "artifactId": "wpiapi-java", - "version": "5.33.1" + "version": "5.34.0-beta-2" } ], "jniDependencies": [ { "groupId": "com.ctre.phoenix", "artifactId": "cci", - "version": "5.33.1", + "version": "5.34.0-beta-2", "isJar": false, "skipInvalidPlatforms": true, "validPlatforms": [ @@ -45,7 +45,7 @@ { "groupId": "com.ctre.phoenix.sim", "artifactId": "cci-sim", - "version": "5.33.1", + "version": "5.34.0-beta-2", "isJar": false, "skipInvalidPlatforms": true, "validPlatforms": [ @@ -60,7 +60,7 @@ { "groupId": "com.ctre.phoenix", "artifactId": "wpiapi-cpp", - "version": "5.33.1", + "version": "5.34.0-beta-2", "libName": "CTRE_Phoenix_WPI", "headerClassifier": "headers", "sharedLibrary": true, @@ -75,7 +75,7 @@ { "groupId": "com.ctre.phoenix", "artifactId": "api-cpp", - "version": "5.33.1", + "version": "5.34.0-beta-2", "libName": "CTRE_Phoenix", "headerClassifier": "headers", "sharedLibrary": true, @@ -90,7 +90,7 @@ { "groupId": "com.ctre.phoenix", "artifactId": "cci", - "version": "5.33.1", + "version": "5.34.0-beta-2", "libName": "CTRE_PhoenixCCI", "headerClassifier": "headers", "sharedLibrary": true, @@ -105,7 +105,7 @@ { "groupId": "com.ctre.phoenix.sim", "artifactId": "wpiapi-cpp-sim", - "version": "5.33.1", + "version": "5.34.0-beta-2", "libName": "CTRE_Phoenix_WPISim", "headerClassifier": "headers", "sharedLibrary": true, @@ -120,7 +120,7 @@ { "groupId": "com.ctre.phoenix.sim", "artifactId": "api-cpp-sim", - "version": "5.33.1", + "version": "5.34.0-beta-2", "libName": "CTRE_PhoenixSim", "headerClassifier": "headers", "sharedLibrary": true, @@ -135,7 +135,7 @@ { "groupId": "com.ctre.phoenix.sim", "artifactId": "cci-sim", - "version": "5.33.1", + "version": "5.34.0-beta-2", "libName": "CTRE_PhoenixCCISim", "headerClassifier": "headers", "sharedLibrary": true, diff --git a/vendordeps/Phoenix6.json b/vendordeps/Phoenix6-25.0.0-beta-2.json similarity index 85% rename from vendordeps/Phoenix6.json rename to vendordeps/Phoenix6-25.0.0-beta-2.json index 03223850..c56e61ae 100644 --- a/vendordeps/Phoenix6.json +++ b/vendordeps/Phoenix6-25.0.0-beta-2.json @@ -1,32 +1,50 @@ { - "fileName": "Phoenix6.json", + "fileName": "Phoenix6-25.0.0-beta-2.json", "name": "CTRE-Phoenix (v6)", - "version": "24.3.0", - "frcYear": 2024, + "version": "25.0.0-beta-2", + "frcYear": "2025", "uuid": "e995de00-2c64-4df5-8831-c1441420ff19", "mavenUrls": [ "https://maven.ctr-electronics.com/release/" ], - "jsonUrl": "https://maven.ctr-electronics.com/release/com/ctre/phoenix6/latest/Phoenix6-frc2024-latest.json", + "jsonUrl": "https://maven.ctr-electronics.com/release/com/ctre/phoenix6/latest/Phoenix6-frc2025-beta-latest.json", "conflictsWith": [ { "uuid": "3fcf3402-e646-4fa6-971e-18afe8173b1a", "errorMessage": "The combined Phoenix-6-And-5 vendordep is no longer supported. Please remove the vendordep and instead add both the latest Phoenix 6 vendordep and Phoenix 5 vendordep.", "offlineFileName": "Phoenix6And5.json" + }, + { + "uuid": "e7900d8d-826f-4dca-a1ff-182f658e98af", + "errorMessage": "Users can not have both the replay and regular Phoenix 6 vendordeps in their robot program.", + "offlineFileName": "Phoenix6-replay-frc2025-beta-latest.json" } ], "javaDependencies": [ { "groupId": "com.ctre.phoenix6", "artifactId": "wpiapi-java", - "version": "24.3.0" + "version": "25.0.0-beta-2" } ], "jniDependencies": [ + { + "groupId": "com.ctre.phoenix6", + "artifactId": "api-cpp", + "version": "25.0.0-beta-2", + "isJar": false, + "skipInvalidPlatforms": true, + "validPlatforms": [ + "windowsx86-64", + "linuxx86-64", + "linuxathena" + ], + "simMode": "hwsim" + }, { "groupId": "com.ctre.phoenix6", "artifactId": "tools", - "version": "24.3.0", + "version": "25.0.0-beta-2", "isJar": false, "skipInvalidPlatforms": true, "validPlatforms": [ @@ -38,8 +56,8 @@ }, { "groupId": "com.ctre.phoenix6.sim", - "artifactId": "tools-sim", - "version": "24.3.0", + "artifactId": "api-cpp-sim", + "version": "25.0.0-beta-2", "isJar": false, "skipInvalidPlatforms": true, "validPlatforms": [ @@ -51,8 +69,8 @@ }, { "groupId": "com.ctre.phoenix6.sim", - "artifactId": "simTalonSRX", - "version": "24.3.0", + "artifactId": "tools-sim", + "version": "25.0.0-beta-2", "isJar": false, "skipInvalidPlatforms": true, "validPlatforms": [ @@ -64,8 +82,8 @@ }, { "groupId": "com.ctre.phoenix6.sim", - "artifactId": "simTalonFX", - "version": "24.3.0", + "artifactId": "simTalonSRX", + "version": "25.0.0-beta-2", "isJar": false, "skipInvalidPlatforms": true, "validPlatforms": [ @@ -78,7 +96,7 @@ { "groupId": "com.ctre.phoenix6.sim", "artifactId": "simVictorSPX", - "version": "24.3.0", + "version": "25.0.0-beta-2", "isJar": false, "skipInvalidPlatforms": true, "validPlatforms": [ @@ -91,7 +109,7 @@ { "groupId": "com.ctre.phoenix6.sim", "artifactId": "simPigeonIMU", - "version": "24.3.0", + "version": "25.0.0-beta-2", "isJar": false, "skipInvalidPlatforms": true, "validPlatforms": [ @@ -104,7 +122,7 @@ { "groupId": "com.ctre.phoenix6.sim", "artifactId": "simCANCoder", - "version": "24.3.0", + "version": "25.0.0-beta-2", "isJar": false, "skipInvalidPlatforms": true, "validPlatforms": [ @@ -117,7 +135,7 @@ { "groupId": "com.ctre.phoenix6.sim", "artifactId": "simProTalonFX", - "version": "24.3.0", + "version": "25.0.0-beta-2", "isJar": false, "skipInvalidPlatforms": true, "validPlatforms": [ @@ -130,7 +148,7 @@ { "groupId": "com.ctre.phoenix6.sim", "artifactId": "simProCANcoder", - "version": "24.3.0", + "version": "25.0.0-beta-2", "isJar": false, "skipInvalidPlatforms": true, "validPlatforms": [ @@ -143,7 +161,7 @@ { "groupId": "com.ctre.phoenix6.sim", "artifactId": "simProPigeon2", - "version": "24.3.0", + "version": "25.0.0-beta-2", "isJar": false, "skipInvalidPlatforms": true, "validPlatforms": [ @@ -158,7 +176,7 @@ { "groupId": "com.ctre.phoenix6", "artifactId": "wpiapi-cpp", - "version": "24.3.0", + "version": "25.0.0-beta-2", "libName": "CTRE_Phoenix6_WPI", "headerClassifier": "headers", "sharedLibrary": true, @@ -173,7 +191,7 @@ { "groupId": "com.ctre.phoenix6", "artifactId": "tools", - "version": "24.3.0", + "version": "25.0.0-beta-2", "libName": "CTRE_PhoenixTools", "headerClassifier": "headers", "sharedLibrary": true, @@ -188,7 +206,7 @@ { "groupId": "com.ctre.phoenix6.sim", "artifactId": "wpiapi-cpp-sim", - "version": "24.3.0", + "version": "25.0.0-beta-2", "libName": "CTRE_Phoenix6_WPISim", "headerClassifier": "headers", "sharedLibrary": true, @@ -203,7 +221,7 @@ { "groupId": "com.ctre.phoenix6.sim", "artifactId": "tools-sim", - "version": "24.3.0", + "version": "25.0.0-beta-2", "libName": "CTRE_PhoenixTools_Sim", "headerClassifier": "headers", "sharedLibrary": true, @@ -218,7 +236,7 @@ { "groupId": "com.ctre.phoenix6.sim", "artifactId": "simTalonSRX", - "version": "24.3.0", + "version": "25.0.0-beta-2", "libName": "CTRE_SimTalonSRX", "headerClassifier": "headers", "sharedLibrary": true, @@ -230,25 +248,10 @@ ], "simMode": "swsim" }, - { - "groupId": "com.ctre.phoenix6.sim", - "artifactId": "simTalonFX", - "version": "24.3.0", - "libName": "CTRE_SimTalonFX", - "headerClassifier": "headers", - "sharedLibrary": true, - "skipInvalidPlatforms": true, - "binaryPlatforms": [ - "windowsx86-64", - "linuxx86-64", - "osxuniversal" - ], - "simMode": "swsim" - }, { "groupId": "com.ctre.phoenix6.sim", "artifactId": "simVictorSPX", - "version": "24.3.0", + "version": "25.0.0-beta-2", "libName": "CTRE_SimVictorSPX", "headerClassifier": "headers", "sharedLibrary": true, @@ -263,7 +266,7 @@ { "groupId": "com.ctre.phoenix6.sim", "artifactId": "simPigeonIMU", - "version": "24.3.0", + "version": "25.0.0-beta-2", "libName": "CTRE_SimPigeonIMU", "headerClassifier": "headers", "sharedLibrary": true, @@ -278,7 +281,7 @@ { "groupId": "com.ctre.phoenix6.sim", "artifactId": "simCANCoder", - "version": "24.3.0", + "version": "25.0.0-beta-2", "libName": "CTRE_SimCANCoder", "headerClassifier": "headers", "sharedLibrary": true, @@ -293,7 +296,7 @@ { "groupId": "com.ctre.phoenix6.sim", "artifactId": "simProTalonFX", - "version": "24.3.0", + "version": "25.0.0-beta-2", "libName": "CTRE_SimProTalonFX", "headerClassifier": "headers", "sharedLibrary": true, @@ -308,7 +311,7 @@ { "groupId": "com.ctre.phoenix6.sim", "artifactId": "simProCANcoder", - "version": "24.3.0", + "version": "25.0.0-beta-2", "libName": "CTRE_SimProCANcoder", "headerClassifier": "headers", "sharedLibrary": true, @@ -323,7 +326,7 @@ { "groupId": "com.ctre.phoenix6.sim", "artifactId": "simProPigeon2", - "version": "24.3.0", + "version": "25.0.0-beta-2", "libName": "CTRE_SimProPigeon2", "headerClassifier": "headers", "sharedLibrary": true, diff --git a/vendordeps/REVLib.json b/vendordeps/REVLib-2025.0.0-beta-2.json similarity index 87% rename from vendordeps/REVLib.json rename to vendordeps/REVLib-2025.0.0-beta-2.json index f85acd40..85f61514 100644 --- a/vendordeps/REVLib.json +++ b/vendordeps/REVLib-2025.0.0-beta-2.json @@ -1,25 +1,25 @@ { - "fileName": "REVLib.json", + "fileName": "REVLib-2025.0.0-beta-2.json", "name": "REVLib", - "version": "2024.2.4", - "frcYear": "2024", + "version": "2025.0.0-beta-2", + "frcYear": "2025", "uuid": "3f48eb8c-50fe-43a6-9cb7-44c86353c4cb", "mavenUrls": [ "https://maven.revrobotics.com/" ], - "jsonUrl": "https://software-metadata.revrobotics.com/REVLib-2024.json", + "jsonUrl": "https://software-metadata.revrobotics.com/REVLib-2025.json", "javaDependencies": [ { "groupId": "com.revrobotics.frc", "artifactId": "REVLib-java", - "version": "2024.2.4" + "version": "2025.0.0-beta-2" } ], "jniDependencies": [ { "groupId": "com.revrobotics.frc", "artifactId": "REVLib-driver", - "version": "2024.2.4", + "version": "2025.0.0-beta-2", "skipInvalidPlatforms": true, "isJar": false, "validPlatforms": [ @@ -37,7 +37,7 @@ { "groupId": "com.revrobotics.frc", "artifactId": "REVLib-cpp", - "version": "2024.2.4", + "version": "2025.0.0-beta-2", "libName": "REVLib", "headerClassifier": "headers", "sharedLibrary": false, @@ -55,7 +55,7 @@ { "groupId": "com.revrobotics.frc", "artifactId": "REVLib-driver", - "version": "2024.2.4", + "version": "2025.0.0-beta-2", "libName": "REVLibDriver", "headerClassifier": "headers", "sharedLibrary": false, diff --git a/vendordeps/WPILibNewCommands.json b/vendordeps/WPILibNewCommands.json index e3e494e9..8a818594 100644 --- a/vendordeps/WPILibNewCommands.json +++ b/vendordeps/WPILibNewCommands.json @@ -3,7 +3,7 @@ "name": "WPILib-New-Commands", "version": "1.0.0", "uuid": "111e20f7-815e-48f8-9dd6-e675ce75b266", - "frcYear": 2024, + "frcYear": 2025, "mavenUrls": [], "jsonUrl": "", "javaDependencies": [ From 9641ef3937c176d458ec2014fdbf6d02de835066 Mon Sep 17 00:00:00 2001 From: Nummun14 <142012009+Nummun14@users.noreply.github.com> Date: Fri, 22 Nov 2024 14:34:56 +0200 Subject: [PATCH 06/61] javadocs are annoying. So is REV. So am I. --- .../trigon/hardware/RobotHardwareStats.java | 10 ++--- .../hardware/misc/KeyboardController.java | 2 +- .../misc/simplesensor/SimpleSensor.java | 2 +- .../phoenix6/talonfx/TalonFXMotor.java | 18 ++++----- .../trigon/hardware/rev/spark/SparkMotor.java | 18 ++++----- .../rev/spark/io/SimulationSparkIO.java | 2 +- .../simulation/ElevatorSimulation.java | 4 +- .../simulation/FlywheelSimulation.java | 2 +- .../SingleJointedArmSimulation.java | 4 +- .../utilities/mirrorable/Mirrorable.java | 10 ++--- .../mirrorable/MirrorablePose2d.java | 30 +++++++-------- .../mirrorable/MirrorableRotation2d.java | 38 +++++++++---------- .../mirrorable/MirrorableTranslation3d.java | 22 +++++------ 13 files changed, 81 insertions(+), 81 deletions(-) diff --git a/src/main/java/org/trigon/hardware/RobotHardwareStats.java b/src/main/java/org/trigon/hardware/RobotHardwareStats.java index 91c5a340..faa4a9c2 100644 --- a/src/main/java/org/trigon/hardware/RobotHardwareStats.java +++ b/src/main/java/org/trigon/hardware/RobotHardwareStats.java @@ -1,7 +1,7 @@ package org.trigon.hardware; /** - * A class that contains stats about the robot hardware. + * A class that contains stats about the robot's hardware. */ public class RobotHardwareStats { private static boolean IS_SIMULATION = false; @@ -11,7 +11,7 @@ public class RobotHardwareStats { /** * Sets the current robot stats. * - * @param isReal whether the robot is real + * @param isReal a boolean indicating whether the robot is real * @param replayType the type of replay */ public static void setCurrentRobotStats(boolean isReal, ReplayType replayType) { @@ -44,7 +44,7 @@ public static double getPeriodicTimeSeconds() { } /** - * Gets whether the robot is in replay mode. + * Checks if the robot is in replay mode. * * @return whether the robot is in replay mode */ @@ -53,7 +53,7 @@ public static boolean isReplay() { } /** - * Gets whether the robot is in simulation mode. + * Checks if the robot is running in simulation. * * @return whether the robot is running in simulation */ @@ -62,7 +62,7 @@ public static boolean isSimulation() { } /** - * An enum that represents type of replay. + * An enum that represents the type of replay. */ public enum ReplayType { NONE, diff --git a/src/main/java/org/trigon/hardware/misc/KeyboardController.java b/src/main/java/org/trigon/hardware/misc/KeyboardController.java index 0abb7c5a..97cd273d 100644 --- a/src/main/java/org/trigon/hardware/misc/KeyboardController.java +++ b/src/main/java/org/trigon/hardware/misc/KeyboardController.java @@ -4,7 +4,7 @@ import org.littletonrobotics.junction.networktables.LoggedDashboardBoolean; /** - * A class that represents a keyboard controller. Used to get input a keyboard. + * A class that represents a keyboard controller. Used to get input from a keyboard. */ public class KeyboardController { private final LoggedDashboardBoolean diff --git a/src/main/java/org/trigon/hardware/misc/simplesensor/SimpleSensor.java b/src/main/java/org/trigon/hardware/misc/simplesensor/SimpleSensor.java index 973c2d5b..26f91598 100644 --- a/src/main/java/org/trigon/hardware/misc/simplesensor/SimpleSensor.java +++ b/src/main/java/org/trigon/hardware/misc/simplesensor/SimpleSensor.java @@ -92,7 +92,7 @@ public boolean getBinaryValue() { } /** - * Gets the scaled value using the scaling constants. + * Gets the scaled value from the sensor using the scaling constants. * * @return The scaled value. */ diff --git a/src/main/java/org/trigon/hardware/phoenix6/talonfx/TalonFXMotor.java b/src/main/java/org/trigon/hardware/phoenix6/talonfx/TalonFXMotor.java index b3a53094..cb1dc369 100644 --- a/src/main/java/org/trigon/hardware/phoenix6/talonfx/TalonFXMotor.java +++ b/src/main/java/org/trigon/hardware/phoenix6/talonfx/TalonFXMotor.java @@ -12,7 +12,7 @@ import org.trigon.hardware.simulation.MotorPhysicsSimulation; /** - * A class that represents a Talon FX motor. Used to control and and get the values of the motor. + * A class that represents a Talon FX motor. Used to control and get the values of the motor. */ public class TalonFXMotor { private final String motorName; @@ -23,7 +23,7 @@ public class TalonFXMotor { /** * Creates a new Talon FX motor. * - * @param id the motor ID + * @param id the motor's ID * @param motorName the name of the motor */ public TalonFXMotor(int id, String motorName) { @@ -33,9 +33,9 @@ public TalonFXMotor(int id, String motorName) { /** * Creates a new Talon FX motor. * - * @param id the motor ID + * @param id the motor's ID * @param motorName the name of the motor - * @param canbus the canivore name + * @param canbus the canivore's name */ public TalonFXMotor(int id, String motorName, String canbus) { this.motorName = motorName; @@ -133,7 +133,7 @@ public double getSignal(TalonFXSignal signal) { /** * Gets a threaded signal from the motor. * - * @param signal the type of signal to get + * @param signal the type of threaded signal to get * @return the signal */ public double[] getThreadedSignal(TalonFXSignal signal) { @@ -144,7 +144,7 @@ public double[] getThreadedSignal(TalonFXSignal signal) { * Registers a signal to the motor. * * @param signal the signal to register - * @param updateFrequencyHertz the frequency to update the signal + * @param updateFrequencyHertz The frequency at which the signal will be updated */ public void registerSignal(TalonFXSignal signal, double updateFrequencyHertz) { motorInputs.registerSignal(motorSignalToStatusSignal(signal), updateFrequencyHertz); @@ -153,8 +153,8 @@ public void registerSignal(TalonFXSignal signal, double updateFrequencyHertz) { /** * Registers a threaded signal to the motor. * - * @param signal the signal to register - * @param updateFrequencyHertz the frequency to update the signal + * @param signal the threaded signal to register + * @param updateFrequencyHertz The frequency at which the threaded signal will be updated */ public void registerThreadedSignal(TalonFXSignal signal, double updateFrequencyHertz) { motorInputs.registerThreadedSignal(motorSignalToStatusSignal(signal), updateFrequencyHertz); @@ -179,7 +179,7 @@ public void setPosition(double positionRotations) { } /** - * Sets the motors neutral Mode. + * Sets the motors neutral mode. * * @param brake should the motor brake */ diff --git a/src/main/java/org/trigon/hardware/rev/spark/SparkMotor.java b/src/main/java/org/trigon/hardware/rev/spark/SparkMotor.java index 3748fb68..2dfa9333 100644 --- a/src/main/java/org/trigon/hardware/rev/spark/SparkMotor.java +++ b/src/main/java/org/trigon/hardware/rev/spark/SparkMotor.java @@ -21,7 +21,7 @@ public class SparkMotor { /** * Creates a new Spark motor. * - * @param id the motor ID + * @param id the motor's ID * @param sparkType the type of Spark motor * @param motorName the name of the motor * @param simulationMotor the motor to be used in simulation @@ -50,9 +50,9 @@ public int getID() { } /** - * Registers a signal to be read from the motor. + * Registers a signal to be logged from the motor. * - * @param signal the signal to be read + * @param signal the signal to be registered */ public void registerSignal(SparkSignal signal) { this.registerSignal(signal, false); @@ -86,8 +86,8 @@ public double getSignal(SparkSignal signal) { /** * Gets a threaded signal from the motor. * - * @param signal the signal to get - * @return the signal + * @param signal the threaded signal to get + * @return the threaded signal */ public double[] getThreadedSignal(SparkSignal signal) { return motorInputs.getThreadedSignal(signal.name); @@ -96,7 +96,7 @@ public double[] getThreadedSignal(SparkSignal signal) { /** * Sends a request to the motor. * - * @param value the value to set + * @param value the value to set depending on the control type * @param controlType the control type */ public void setReference(double value, SparkBase.ControlType controlType) { @@ -106,7 +106,7 @@ public void setReference(double value, SparkBase.ControlType controlType) { /** * Sends a request to the motor. * - * @param value the value to set + * @param value the value to set depending on the control type * @param controlType the control type * @param pidSlot the PID slot to use */ @@ -129,7 +129,7 @@ public void setReference(double value, SparkBase.ControlType controlType, int pi /** * Sends a request to the motor. * - * @param value the value to set + * @param value the value to set depending on the control type * @param controlType the control type * @param pidSlot the PID slot to use * @param arbFeedForward the feed forward value @@ -143,7 +143,7 @@ public void setReference(double value, SparkBase.ControlType controlType, int pi * Sets the transmission period for a specific periodic frame on the motor controller. * This method adjusts the rate at which the controller sends the frame, but the change is not saved permanently and will reset on powerup. * - * @param periodMs The new transmission period in milliseconds. + * @param periodMs the new transmission period in milliseconds */ public void setPeriodicFramePeriod(int periodMs) { motorIO.setPeriodicFrameTimeout(periodMs); diff --git a/src/main/java/org/trigon/hardware/rev/spark/io/SimulationSparkIO.java b/src/main/java/org/trigon/hardware/rev/spark/io/SimulationSparkIO.java index 851f2f8b..0cc4fefb 100644 --- a/src/main/java/org/trigon/hardware/rev/spark/io/SimulationSparkIO.java +++ b/src/main/java/org/trigon/hardware/rev/spark/io/SimulationSparkIO.java @@ -17,7 +17,7 @@ public class SimulationSparkIO extends SparkIO { public SimulationSparkIO(int id, DCMotor gearbox) { motor = new SparkMax(id, SparkMax.MotorType.kBrushless); - simulation = new SparkMaxSim(motor, DCMotor.getNeo550(1)); + simulation = new SparkMaxSim(motor, gearbox); pidController = motor.getClosedLoopController(); encoder = SparkEncoder.createRelativeEncoder(motor); } diff --git a/src/main/java/org/trigon/hardware/simulation/ElevatorSimulation.java b/src/main/java/org/trigon/hardware/simulation/ElevatorSimulation.java index 0fd20745..7e626f32 100644 --- a/src/main/java/org/trigon/hardware/simulation/ElevatorSimulation.java +++ b/src/main/java/org/trigon/hardware/simulation/ElevatorSimulation.java @@ -16,13 +16,13 @@ public class ElevatorSimulation extends MotorPhysicsSimulation { /** * Creates a new ElevatorSimulation. * - * @param gearbox the motor used to move the elevator + * @param gearbox the motor(s) used to move the elevator * @param gearRatio the motor's gear ratio * @param carriageMassKilograms the mass of the elevator carriage in kilograms * @param drumRadiusMeters the radius of the drum in meters * @param retractedHeightMeters the height of the elevator when retracted in meters * @param maximumHeightMeters the maximum height of the elevator in meters - * @param simulateGravity whether to simulate gravity + * @param simulateGravity a boolean indicating whether to simulate gravity */ public ElevatorSimulation(DCMotor gearbox, double gearRatio, double carriageMassKilograms, double drumRadiusMeters, double retractedHeightMeters, double maximumHeightMeters, boolean simulateGravity) { super(gearRatio); diff --git a/src/main/java/org/trigon/hardware/simulation/FlywheelSimulation.java b/src/main/java/org/trigon/hardware/simulation/FlywheelSimulation.java index 3964a4c2..b4f0698b 100644 --- a/src/main/java/org/trigon/hardware/simulation/FlywheelSimulation.java +++ b/src/main/java/org/trigon/hardware/simulation/FlywheelSimulation.java @@ -16,7 +16,7 @@ public class FlywheelSimulation extends MotorPhysicsSimulation { /** * Creates a new FlywheelSimulation. * - * @param gearbox the motor used to control the flywheel + * @param gearbox the motor(s) used to control the flywheel * @param gearRatio the motor's gear ratio * @param kv voltage needed to maintain constant velocity * @param ka voltage needed to induce a specific acceleration diff --git a/src/main/java/org/trigon/hardware/simulation/SingleJointedArmSimulation.java b/src/main/java/org/trigon/hardware/simulation/SingleJointedArmSimulation.java index 290266f7..cdee69b0 100644 --- a/src/main/java/org/trigon/hardware/simulation/SingleJointedArmSimulation.java +++ b/src/main/java/org/trigon/hardware/simulation/SingleJointedArmSimulation.java @@ -15,13 +15,13 @@ public class SingleJointedArmSimulation extends MotorPhysicsSimulation { /** * Creates a new SingleJointedArmSimulation. * - * @param gearbox the motor used to control the arm + * @param gearbox the motor(s) used to control the arm * @param gearRatio the motor's gear ratio * @param armLengthMeters the length of the arm in meters * @param armMassKilograms the mass of the arm in kilograms * @param minimumAngle the minimum angle of the arm * @param maximumAngle the maximum angle of the arm - * @param simulateGravity a boolean indicating whether to simulate gravity + * @param simulateGravity whether to simulate gravity */ public SingleJointedArmSimulation(DCMotor gearbox, double gearRatio, double armLengthMeters, double armMassKilograms, Rotation2d minimumAngle, Rotation2d maximumAngle, boolean simulateGravity) { super(gearRatio); diff --git a/src/main/java/org/trigon/utilities/mirrorable/Mirrorable.java b/src/main/java/org/trigon/utilities/mirrorable/Mirrorable.java index 5b0db870..7586aaa6 100644 --- a/src/main/java/org/trigon/utilities/mirrorable/Mirrorable.java +++ b/src/main/java/org/trigon/utilities/mirrorable/Mirrorable.java @@ -35,13 +35,13 @@ public abstract class Mirrorable { /** * Creates a new mirrorable object. * - * @param nonMirroredObject the object when the robot is on the blue alliance, or the non-mirrored object - * @param mirrorWhenRedAlliance whether to mirror the object when the robot is on the red alliance + * @param nonMirroredObject the object when the robot is on the blue alliance, or the non-mirrored object + * @param shouldMirrorWhenRedAlliance whether to mirror the object when the robot is on the red alliance */ - protected Mirrorable(T nonMirroredObject, boolean mirrorWhenRedAlliance) { + protected Mirrorable(T nonMirroredObject, boolean shouldMirrorWhenRedAlliance) { this.nonMirroredObject = nonMirroredObject; this.mirroredObject = mirror(nonMirroredObject); - this.mirrorWhenRedAlliance = mirrorWhenRedAlliance; + this.mirrorWhenRedAlliance = shouldMirrorWhenRedAlliance; } /** @@ -75,4 +75,4 @@ public T get() { * @return the mirrored object */ protected abstract T mirror(T object); -} +} \ No newline at end of file diff --git a/src/main/java/org/trigon/utilities/mirrorable/MirrorablePose2d.java b/src/main/java/org/trigon/utilities/mirrorable/MirrorablePose2d.java index ef94df99..7d95b390 100644 --- a/src/main/java/org/trigon/utilities/mirrorable/MirrorablePose2d.java +++ b/src/main/java/org/trigon/utilities/mirrorable/MirrorablePose2d.java @@ -5,34 +5,34 @@ import edu.wpi.first.math.geometry.Translation2d; /** - * A class that represents a {@link Pose2d} that can be mirrored. Reversing its position and orientation. + * A class that represents a {@link Pose2d} that can be mirrored, reversing its position and orientation across the center of the field when the robot is on the red alliance. */ public class MirrorablePose2d extends Mirrorable { - public MirrorablePose2d(Pose2d nonMirroredPose, boolean mirrorWhenRedAlliance) { - super(nonMirroredPose, mirrorWhenRedAlliance); + public MirrorablePose2d(Pose2d nonMirroredPose, boolean shouldMirrorWhenRedAlliance) { + super(nonMirroredPose, shouldMirrorWhenRedAlliance); } /** * Creates a new MirrorablePose2d with the given x, y, and rotation. * - * @param x the x value of the pose. - * @param y the y value of the pose. - * @param rotation the rotation of the pose. - * @param mirrorWhenRedAlliance a boolean indicating whether to mirror the pose when the robot is on the red alliance. + * @param x the x value of the pose. + * @param y the y value of the pose. + * @param rotation the rotation of the pose. + * @param shouldMirrorWhenRedAlliance should the pose be mirrored when the robot is on the red alliance */ - public MirrorablePose2d(double x, double y, Rotation2d rotation, boolean mirrorWhenRedAlliance) { - this(new Pose2d(x, y, rotation), mirrorWhenRedAlliance); + public MirrorablePose2d(double x, double y, Rotation2d rotation, boolean shouldMirrorWhenRedAlliance) { + this(new Pose2d(x, y, rotation), shouldMirrorWhenRedAlliance); } /** * Creates a new MirrorablePose2d with the given translation and rotation. * - * @param translation2d the translation of the pose. - * @param rotation the rotation of the pose. - * @param mirrorWhenRedAlliance a boolean indicating whether to mirror the pose when the robot is on the red alliance. + * @param translation2d the translation of the pose. + * @param rotation the rotation of the pose. + * @param shouldMirrorWhenRedAlliance should the pose be mirrored when the robot is on the red alliance */ - public MirrorablePose2d(Translation2d translation2d, double rotation, boolean mirrorWhenRedAlliance) { - this(new Pose2d(translation2d, new Rotation2d(rotation)), mirrorWhenRedAlliance); + public MirrorablePose2d(Translation2d translation2d, double rotation, boolean shouldMirrorWhenRedAlliance) { + this(new Pose2d(translation2d, new Rotation2d(rotation)), shouldMirrorWhenRedAlliance); } /** @@ -52,4 +52,4 @@ protected Pose2d mirror(Pose2d pose) { HALF_ROTATION.minus(pose.getRotation()) ); } -} +} \ No newline at end of file diff --git a/src/main/java/org/trigon/utilities/mirrorable/MirrorableRotation2d.java b/src/main/java/org/trigon/utilities/mirrorable/MirrorableRotation2d.java index 0afc4a3e..5b3d720d 100644 --- a/src/main/java/org/trigon/utilities/mirrorable/MirrorableRotation2d.java +++ b/src/main/java/org/trigon/utilities/mirrorable/MirrorableRotation2d.java @@ -3,54 +3,54 @@ import edu.wpi.first.math.geometry.Rotation2d; /** - * A class that represents a {@link Rotation2d} that can be mirrored. Reversing its orientation. + * A class that represents a {@link Rotation2d} that can be mirrored, Reversing its orientation across the center of the field when the robot is on the red alliance. */ public class MirrorableRotation2d extends Mirrorable { - public MirrorableRotation2d(Rotation2d nonMirroredRotation, boolean mirrorWhenRedAlliance) { - super(nonMirroredRotation, mirrorWhenRedAlliance); + public MirrorableRotation2d(Rotation2d nonMirroredRotation, boolean shouldMirrorWhenRedAlliance) { + super(nonMirroredRotation, shouldMirrorWhenRedAlliance); } /** * Creates a new MirrorableRotation2d with the given rotation value. * - * @param radians the value of the angle in radians - * @param mirrorWhenRedAlliance a boolean indicating whether to mirror the object when the robot is on the red alliance + * @param radians the value of the angle in radians + * @param shouldMirrorWhenRedAlliance should the rotation be mirrored when the robot is on the red alliance */ - public MirrorableRotation2d(double radians, boolean mirrorWhenRedAlliance) { - this(new Rotation2d(radians), mirrorWhenRedAlliance); + public MirrorableRotation2d(double radians, boolean shouldMirrorWhenRedAlliance) { + this(new Rotation2d(radians), shouldMirrorWhenRedAlliance); } /** * Constructs and returns a MirrorableRotation2d with the given degree value. * - * @param degrees the value of the angle in degrees - * @param mirrorWhenRedAlliance a boolean indicating whether to mirror the object when the robot is on the red alliance + * @param degrees the value of the angle in degrees + * @param shouldMirrorWhenRedAlliance should the rotation be mirrored when the robot is on the red alliance * @return the rotation object with the desired angle value */ - public static MirrorableRotation2d fromDegrees(double degrees, boolean mirrorWhenRedAlliance) { - return new MirrorableRotation2d(Rotation2d.fromDegrees(degrees), mirrorWhenRedAlliance); + public static MirrorableRotation2d fromDegrees(double degrees, boolean shouldMirrorWhenRedAlliance) { + return new MirrorableRotation2d(Rotation2d.fromDegrees(degrees), shouldMirrorWhenRedAlliance); } /** * Constructs and returns a MirrorableRotation2d with the given radian value. * - * @param radians the value of the angle in radians - * @param mirrorWhenRedAlliance a boolean indicating whether to mirror the object when the robot is on the red alliance + * @param radians the value of the angle in radians + * @param shouldMirrorWhenRedAlliance should the rotation be mirrored when the robot is on the red alliance * @return the rotation object with the desired angle value */ - public static MirrorableRotation2d fromRadians(double radians, boolean mirrorWhenRedAlliance) { - return new MirrorableRotation2d(Rotation2d.fromRadians(radians), mirrorWhenRedAlliance); + public static MirrorableRotation2d fromRadians(double radians, boolean shouldMirrorWhenRedAlliance) { + return new MirrorableRotation2d(Rotation2d.fromRadians(radians), shouldMirrorWhenRedAlliance); } /** * Constructs and returns a MirrorableRotation2d with the given number of rotations. * - * @param rotations the value of the angle in rotations - * @param mirrorWhenRedAlliance a boolean indicating whether to mirror the object when the robot is on the red alliance + * @param rotations the value of the angle in rotations + * @param shouldMirrorWhenRedAlliance should the rotation be mirrored when the robot is on the red alliance * @return the rotation object with the desired angle value */ - public static MirrorableRotation2d fromRotations(double rotations, boolean mirrorWhenRedAlliance) { - return new MirrorableRotation2d(Rotation2d.fromRotations(rotations), mirrorWhenRedAlliance); + public static MirrorableRotation2d fromRotations(double rotations, boolean shouldMirrorWhenRedAlliance) { + return new MirrorableRotation2d(Rotation2d.fromRotations(rotations), shouldMirrorWhenRedAlliance); } @Override diff --git a/src/main/java/org/trigon/utilities/mirrorable/MirrorableTranslation3d.java b/src/main/java/org/trigon/utilities/mirrorable/MirrorableTranslation3d.java index 0ad8fd86..9bd30e92 100644 --- a/src/main/java/org/trigon/utilities/mirrorable/MirrorableTranslation3d.java +++ b/src/main/java/org/trigon/utilities/mirrorable/MirrorableTranslation3d.java @@ -3,29 +3,29 @@ import edu.wpi.first.math.geometry.Translation3d; /** - * A class that represents a {@link Translation3d} that can be mirrored. Reversing its position. + * A class that represents a {@link Translation3d} that can be mirrored reversing its position across the center of the field when the robot is on the red alliance. */ public class MirrorableTranslation3d extends Mirrorable { /** * Creates a new MirrorableTranslation3d with the given translation. * - * @param nonMirroredTranslation the translation to mirror - * @param mirrorWhenRedAlliance a boolean indicating whether to mirror the object when the robot is on the red alliance + * @param nonMirroredTranslation the translation to mirror + * @param shouldMirrorWhenRedAlliance should the position be mirrored when the robot is on the red alliance */ - public MirrorableTranslation3d(Translation3d nonMirroredTranslation, boolean mirrorWhenRedAlliance) { - super(nonMirroredTranslation, mirrorWhenRedAlliance); + public MirrorableTranslation3d(Translation3d nonMirroredTranslation, boolean shouldMirrorWhenRedAlliance) { + super(nonMirroredTranslation, shouldMirrorWhenRedAlliance); } /** * Creates a new MirrorableTranslation3d with the given x, y, and z values. * - * @param x the x value of the translation - * @param y the y value of the translation - * @param z the z value of the translation - * @param mirrorWhenRedAlliance a boolean indicating whether to mirror the object when the robot is on the red alliance + * @param x the x value of the translation + * @param y the y value of the translation + * @param z the z value of the translation + * @param shouldMirrorWhenRedAlliance should the position be mirrored when the robot is on the red alliance */ - public MirrorableTranslation3d(double x, double y, double z, boolean mirrorWhenRedAlliance) { - this(new Translation3d(x, y, z), mirrorWhenRedAlliance); + public MirrorableTranslation3d(double x, double y, double z, boolean shouldMirrorWhenRedAlliance) { + this(new Translation3d(x, y, z), shouldMirrorWhenRedAlliance); } @Override From 3bc9934d7f18aeee600de07a9dcfc8a2fab023ca Mon Sep 17 00:00:00 2001 From: Nummun14 <142012009+Nummun14@users.noreply.github.com> Date: Sun, 24 Nov 2024 14:36:41 +0200 Subject: [PATCH 07/61] "Javadocs are actually quite fun" - Ezra Gryn 2024 --- src/main/java/org/trigon/hardware/RobotHardwareStats.java | 6 +++--- src/main/java/org/trigon/hardware/rev/spark/SparkMotor.java | 6 +++--- .../java/org/trigon/hardware/rev/spark/io/RealSparkIO.java | 2 +- .../java/org/trigon/utilities/mirrorable/Mirrorable.java | 2 +- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/main/java/org/trigon/hardware/RobotHardwareStats.java b/src/main/java/org/trigon/hardware/RobotHardwareStats.java index faa4a9c2..b527dcfc 100644 --- a/src/main/java/org/trigon/hardware/RobotHardwareStats.java +++ b/src/main/java/org/trigon/hardware/RobotHardwareStats.java @@ -11,7 +11,7 @@ public class RobotHardwareStats { /** * Sets the current robot stats. * - * @param isReal a boolean indicating whether the robot is real + * @param isReal whether the robot is real or simulation * @param replayType the type of replay */ public static void setCurrentRobotStats(boolean isReal, ReplayType replayType) { @@ -46,7 +46,7 @@ public static double getPeriodicTimeSeconds() { /** * Checks if the robot is in replay mode. * - * @return whether the robot is in replay mode + * @return whether the robot is in replay mode or not */ public static boolean isReplay() { return IS_REPLAY; @@ -55,7 +55,7 @@ public static boolean isReplay() { /** * Checks if the robot is running in simulation. * - * @return whether the robot is running in simulation + * @return whether the robot is running in simulation or not */ public static boolean isSimulation() { return IS_SIMULATION; diff --git a/src/main/java/org/trigon/hardware/rev/spark/SparkMotor.java b/src/main/java/org/trigon/hardware/rev/spark/SparkMotor.java index 2dfa9333..9ad0540c 100644 --- a/src/main/java/org/trigon/hardware/rev/spark/SparkMotor.java +++ b/src/main/java/org/trigon/hardware/rev/spark/SparkMotor.java @@ -62,7 +62,7 @@ public void registerSignal(SparkSignal signal) { * Registers a signal to be read from the motor. * * @param signal the signal to be read - * @param isThreaded whether the signal should be read in a separate thread + * @param isThreaded whether the signal should be read in a separate thread or not */ public void registerSignal(SparkSignal signal, boolean isThreaded) { final SparkStatusSignal statusSignal = signal.getStatusSignal(motorIO.getMotor(), motorIO.getEncoder()); @@ -169,8 +169,8 @@ public void setInverted(boolean inverted) { * Applies the configuration to the motor. * * @param configuration the configuration to apply - * @param resetMode whether to reset safe parameters before setting the configuration - * @param persistMode whether to persist the parameters after setting the configuration + * @param resetMode whether to reset safe parameters before setting the configuration or not + * @param persistMode whether to persist the parameters after setting the configuration or not */ public void configure(SparkMaxConfig configuration, SparkBase.ResetMode resetMode, SparkBase.PersistMode persistMode) { motorIO.configure(configuration, resetMode, persistMode); diff --git a/src/main/java/org/trigon/hardware/rev/spark/io/RealSparkIO.java b/src/main/java/org/trigon/hardware/rev/spark/io/RealSparkIO.java index 21dd4cb1..7f8fd5c2 100644 --- a/src/main/java/org/trigon/hardware/rev/spark/io/RealSparkIO.java +++ b/src/main/java/org/trigon/hardware/rev/spark/io/RealSparkIO.java @@ -67,4 +67,4 @@ public void configure(SparkMaxConfig configuration, SparkBase.ResetMode resetMod public void setInverted(boolean inverted) { motor.setInverted(inverted); } -} +} \ No newline at end of file diff --git a/src/main/java/org/trigon/utilities/mirrorable/Mirrorable.java b/src/main/java/org/trigon/utilities/mirrorable/Mirrorable.java index 7586aaa6..4562d544 100644 --- a/src/main/java/org/trigon/utilities/mirrorable/Mirrorable.java +++ b/src/main/java/org/trigon/utilities/mirrorable/Mirrorable.java @@ -36,7 +36,7 @@ public abstract class Mirrorable { * Creates a new mirrorable object. * * @param nonMirroredObject the object when the robot is on the blue alliance, or the non-mirrored object - * @param shouldMirrorWhenRedAlliance whether to mirror the object when the robot is on the red alliance + * @param shouldMirrorWhenRedAlliance whether the object should be mirrored when the robot is on the red alliance */ protected Mirrorable(T nonMirroredObject, boolean shouldMirrorWhenRedAlliance) { this.nonMirroredObject = nonMirroredObject; From f4b54ed877c96df2eac96232a776e146b87fcbab Mon Sep 17 00:00:00 2001 From: Nummun14 <142012009+Nummun14@users.noreply.github.com> Date: Mon, 25 Nov 2024 13:10:05 +0200 Subject: [PATCH 08/61] =?UTF-8?q?erm=20actually=F0=9F=A4=93?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/org/trigon/hardware/RobotHardwareStats.java | 2 +- .../org/trigon/hardware/simulation/ElevatorSimulation.java | 2 +- .../org/trigon/hardware/simulation/FlywheelSimulation.java | 4 ++-- .../org/trigon/hardware/simulation/SimpleMotorSimulation.java | 4 ++-- .../hardware/simulation/SingleJointedArmSimulation.java | 4 ++-- .../org/trigon/utilities/mirrorable/MirrorableRotation2d.java | 2 +- .../trigon/utilities/mirrorable/MirrorableTranslation3d.java | 2 +- 7 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/main/java/org/trigon/hardware/RobotHardwareStats.java b/src/main/java/org/trigon/hardware/RobotHardwareStats.java index b527dcfc..0cf8221c 100644 --- a/src/main/java/org/trigon/hardware/RobotHardwareStats.java +++ b/src/main/java/org/trigon/hardware/RobotHardwareStats.java @@ -11,7 +11,7 @@ public class RobotHardwareStats { /** * Sets the current robot stats. * - * @param isReal whether the robot is real or simulation + * @param isReal whether the robot is real or a simulation * @param replayType the type of replay */ public static void setCurrentRobotStats(boolean isReal, ReplayType replayType) { diff --git a/src/main/java/org/trigon/hardware/simulation/ElevatorSimulation.java b/src/main/java/org/trigon/hardware/simulation/ElevatorSimulation.java index 7e626f32..9068df7c 100644 --- a/src/main/java/org/trigon/hardware/simulation/ElevatorSimulation.java +++ b/src/main/java/org/trigon/hardware/simulation/ElevatorSimulation.java @@ -17,7 +17,7 @@ public class ElevatorSimulation extends MotorPhysicsSimulation { * Creates a new ElevatorSimulation. * * @param gearbox the motor(s) used to move the elevator - * @param gearRatio the motor's gear ratio + * @param gearRatio the gearbox's gear ratio * @param carriageMassKilograms the mass of the elevator carriage in kilograms * @param drumRadiusMeters the radius of the drum in meters * @param retractedHeightMeters the height of the elevator when retracted in meters diff --git a/src/main/java/org/trigon/hardware/simulation/FlywheelSimulation.java b/src/main/java/org/trigon/hardware/simulation/FlywheelSimulation.java index b4f0698b..cc8a2188 100644 --- a/src/main/java/org/trigon/hardware/simulation/FlywheelSimulation.java +++ b/src/main/java/org/trigon/hardware/simulation/FlywheelSimulation.java @@ -17,7 +17,7 @@ public class FlywheelSimulation extends MotorPhysicsSimulation { * Creates a new FlywheelSimulation. * * @param gearbox the motor(s) used to control the flywheel - * @param gearRatio the motor's gear ratio + * @param gearRatio the gearbox's gear ratio * @param kv voltage needed to maintain constant velocity * @param ka voltage needed to induce a specific acceleration */ @@ -30,7 +30,7 @@ public FlywheelSimulation(DCMotor gearbox, double gearRatio, double kv, double k * Creates a new FlywheelSimulation. * * @param gearbox the motor used to control the flywheel - * @param gearRatio the motor's gear ratio + * @param gearRatio the gearbox's gear ratio * @param momentOfInertia the flywheel's moment of inertia */ public FlywheelSimulation(DCMotor gearbox, double gearRatio, double momentOfInertia) { diff --git a/src/main/java/org/trigon/hardware/simulation/SimpleMotorSimulation.java b/src/main/java/org/trigon/hardware/simulation/SimpleMotorSimulation.java index c3b78f8d..7c445d5c 100644 --- a/src/main/java/org/trigon/hardware/simulation/SimpleMotorSimulation.java +++ b/src/main/java/org/trigon/hardware/simulation/SimpleMotorSimulation.java @@ -15,8 +15,8 @@ public class SimpleMotorSimulation extends MotorPhysicsSimulation { /** * Creates a new SimpleMotorSimulation. * - * @param gearbox The gearbox of the motor - * @param gearRatio The gear ratio of the motor + * @param gearbox The gearbox of the motor(s) + * @param gearRatio The gearbox's gear ratio * @param kv voltage needed to maintain constant velocity * @param ka voltage needed to induce a specific acceleration */ diff --git a/src/main/java/org/trigon/hardware/simulation/SingleJointedArmSimulation.java b/src/main/java/org/trigon/hardware/simulation/SingleJointedArmSimulation.java index cdee69b0..a611de22 100644 --- a/src/main/java/org/trigon/hardware/simulation/SingleJointedArmSimulation.java +++ b/src/main/java/org/trigon/hardware/simulation/SingleJointedArmSimulation.java @@ -16,12 +16,12 @@ public class SingleJointedArmSimulation extends MotorPhysicsSimulation { * Creates a new SingleJointedArmSimulation. * * @param gearbox the motor(s) used to control the arm - * @param gearRatio the motor's gear ratio + * @param gearRatio the gearbox's gear ratio * @param armLengthMeters the length of the arm in meters * @param armMassKilograms the mass of the arm in kilograms * @param minimumAngle the minimum angle of the arm * @param maximumAngle the maximum angle of the arm - * @param simulateGravity whether to simulate gravity + * @param simulateGravity whether to simulate gravity or not */ public SingleJointedArmSimulation(DCMotor gearbox, double gearRatio, double armLengthMeters, double armMassKilograms, Rotation2d minimumAngle, Rotation2d maximumAngle, boolean simulateGravity) { super(gearRatio); diff --git a/src/main/java/org/trigon/utilities/mirrorable/MirrorableRotation2d.java b/src/main/java/org/trigon/utilities/mirrorable/MirrorableRotation2d.java index 5b3d720d..8227901b 100644 --- a/src/main/java/org/trigon/utilities/mirrorable/MirrorableRotation2d.java +++ b/src/main/java/org/trigon/utilities/mirrorable/MirrorableRotation2d.java @@ -3,7 +3,7 @@ import edu.wpi.first.math.geometry.Rotation2d; /** - * A class that represents a {@link Rotation2d} that can be mirrored, Reversing its orientation across the center of the field when the robot is on the red alliance. + * A class that represents a {@link Rotation2d} that can be mirrored, reversing its orientation across the center of the field when the robot is on the red alliance. */ public class MirrorableRotation2d extends Mirrorable { public MirrorableRotation2d(Rotation2d nonMirroredRotation, boolean shouldMirrorWhenRedAlliance) { diff --git a/src/main/java/org/trigon/utilities/mirrorable/MirrorableTranslation3d.java b/src/main/java/org/trigon/utilities/mirrorable/MirrorableTranslation3d.java index 9bd30e92..122ae60c 100644 --- a/src/main/java/org/trigon/utilities/mirrorable/MirrorableTranslation3d.java +++ b/src/main/java/org/trigon/utilities/mirrorable/MirrorableTranslation3d.java @@ -3,7 +3,7 @@ import edu.wpi.first.math.geometry.Translation3d; /** - * A class that represents a {@link Translation3d} that can be mirrored reversing its position across the center of the field when the robot is on the red alliance. + * A class that represents a {@link Translation3d} that can be mirrored by reversing its position across the center of the field when the robot is on the red alliance. */ public class MirrorableTranslation3d extends Mirrorable { /** From d659a547915b6f51cf70330f6c82f51b416b2fd0 Mon Sep 17 00:00:00 2001 From: Nummun14 <142012009+Nummun14@users.noreply.github.com> Date: Tue, 26 Nov 2024 13:02:52 +0200 Subject: [PATCH 09/61] JAVADOCS!!! and mirroable fix --- .../trigon/hardware/RobotHardwareStats.java | 16 ++--- .../org/trigon/hardware/SignalThreadBase.java | 7 +- .../org/trigon/hardware/SignalUtilities.java | 41 ----------- .../trigon/hardware/misc/XboxController.java | 2 +- .../misc/simplesensor/SimpleSensor.java | 70 ++++++++++--------- .../hardware/phoenix6/Phoenix6Inputs.java | 2 +- .../phoenix6/Phoenix6SignalThread.java | 16 ++++- .../phoenix6/cancoder/CANcoderSignal.java | 4 +- .../phoenix6/pigeon2/Pigeon2Signal.java | 4 +- .../phoenix6/talonfx/TalonFXMotor.java | 20 +++--- .../phoenix6/talonfx/TalonFXSignal.java | 4 +- .../hardware/rev/spark/SparkSignal.java | 4 +- .../hardware/rev/spark/SparkSignalThread.java | 12 +++- .../org/trigon/utilities/StringUtilities.java | 27 +++++++ .../utilities/mirrorable/Mirrorable.java | 8 +-- .../mirrorable/MirrorablePose2d.java | 2 +- 16 files changed, 126 insertions(+), 113 deletions(-) delete mode 100644 src/main/java/org/trigon/hardware/SignalUtilities.java create mode 100644 src/main/java/org/trigon/utilities/StringUtilities.java diff --git a/src/main/java/org/trigon/hardware/RobotHardwareStats.java b/src/main/java/org/trigon/hardware/RobotHardwareStats.java index 0cf8221c..677a5772 100644 --- a/src/main/java/org/trigon/hardware/RobotHardwareStats.java +++ b/src/main/java/org/trigon/hardware/RobotHardwareStats.java @@ -9,9 +9,10 @@ public class RobotHardwareStats { private static double PERIODIC_TIME_SECONDS = 0.02; /** - * Sets the current robot stats. + * Sets the current robot stats. This should be called in the robot's init method. + * We use this structure to avoid using static variables in the Robot class. * - * @param isReal whether the robot is real or a simulation + * @param isReal whether the robot is real or a simulation. This should be taken from the Robot class. * @param replayType the type of replay */ public static void setCurrentRobotStats(boolean isReal, ReplayType replayType) { @@ -26,7 +27,7 @@ public static void setCurrentRobotStats(boolean isReal, ReplayType replayType) { } /** - * Sets the periodic time in seconds. + * Sets how frequently the periodic method is called in seconds. * * @param periodicTimeSeconds the periodic time in seconds */ @@ -35,8 +36,6 @@ public static void setPeriodicTimeSeconds(double periodicTimeSeconds) { } /** - * Gets the periodic time in seconds. - * * @return the periodic time in seconds */ public static double getPeriodicTimeSeconds() { @@ -44,8 +43,6 @@ public static double getPeriodicTimeSeconds() { } /** - * Checks if the robot is in replay mode. - * * @return whether the robot is in replay mode or not */ public static boolean isReplay() { @@ -53,8 +50,6 @@ public static boolean isReplay() { } /** - * Checks if the robot is running in simulation. - * * @return whether the robot is running in simulation or not */ public static boolean isSimulation() { @@ -63,6 +58,9 @@ public static boolean isSimulation() { /** * An enum that represents the type of replay. + * NONE - the robot is not in replay mode + * SIMULATION_REPLAY - the robot is in simulation replay mode + * REAL_REPLAY - the robot is in real replay mode */ public enum ReplayType { NONE, diff --git a/src/main/java/org/trigon/hardware/SignalThreadBase.java b/src/main/java/org/trigon/hardware/SignalThreadBase.java index 3e16e65f..b840ef44 100644 --- a/src/main/java/org/trigon/hardware/SignalThreadBase.java +++ b/src/main/java/org/trigon/hardware/SignalThreadBase.java @@ -28,6 +28,9 @@ public SignalThreadBase(String name) { /** * Sets the odometry frequency in hertz. + * The odometry frequency determines how often the robot's position and motion data are updated. + * A higher frequency will result in more frequent updates, but may also demand more processing power. + * Only used for Spark motors. * * @param odometryFrequencyHertz The odometry frequency in hertz */ @@ -47,7 +50,7 @@ public void updateLatestTimestamps() { } /** - * Gets the latest timestamps. + * Gets the latest timestamps when events occurred within the thread's execution. * * @return The latest timestamps */ @@ -59,4 +62,4 @@ public double[] getLatestTimestamps() { public static class ThreadInputs { public double[] timestamps; } -} +} \ No newline at end of file diff --git a/src/main/java/org/trigon/hardware/SignalUtilities.java b/src/main/java/org/trigon/hardware/SignalUtilities.java deleted file mode 100644 index 763ec0d1..00000000 --- a/src/main/java/org/trigon/hardware/SignalUtilities.java +++ /dev/null @@ -1,41 +0,0 @@ -package org.trigon.hardware; - -/** - * A class that contains utility methods for signals. - */ -public class SignalUtilities { - /** - * Converts an enum name to a signal name. - * - * @param enumName The enum name - * @return The signal name - */ - public static String enumNameToSignalName(String enumName) { - final String lowercaseName = enumName.toLowerCase(); - final String nameNoUnderscore = lowercaseName.replace("_", ""); - final char[] camelCaseNameChars = new char[nameNoUnderscore.length()]; - - boolean wasLastUnderscore = false; - camelCaseNameChars[0] = Character.toUpperCase(lowercaseName.charAt(0)); - int lastIndex = 1; - for (int i = 1; i < lowercaseName.length(); i++) { - final char currentChar = lowercaseName.charAt(i); - - if (currentChar == '_') { - wasLastUnderscore = true; - continue; - } - - if (wasLastUnderscore) { - wasLastUnderscore = false; - camelCaseNameChars[lastIndex] = Character.toUpperCase(currentChar); - } else { - camelCaseNameChars[lastIndex] = currentChar; - } - - lastIndex++; - } - - return new String(camelCaseNameChars); - } -} diff --git a/src/main/java/org/trigon/hardware/misc/XboxController.java b/src/main/java/org/trigon/hardware/misc/XboxController.java index cf89809a..89345a64 100644 --- a/src/main/java/org/trigon/hardware/misc/XboxController.java +++ b/src/main/java/org/trigon/hardware/misc/XboxController.java @@ -6,7 +6,7 @@ import edu.wpi.first.wpilibj2.command.button.CommandXboxController; /** - * A class that represents an Xbox controller. Used to get the values of the sticks and buttons on a controller. + * A class that represents an Xbox controller. Used to get the values of the sticks and buttons on a controller, with the option of a deadband and exponentiation. */ public class XboxController extends CommandXboxController { private int exponent = 1; diff --git a/src/main/java/org/trigon/hardware/misc/simplesensor/SimpleSensor.java b/src/main/java/org/trigon/hardware/misc/simplesensor/SimpleSensor.java index 26f91598..746f14d4 100644 --- a/src/main/java/org/trigon/hardware/misc/simplesensor/SimpleSensor.java +++ b/src/main/java/org/trigon/hardware/misc/simplesensor/SimpleSensor.java @@ -23,9 +23,9 @@ public class SimpleSensor { /** * Creates a new analog sensor. * - * @param channel The channel of the sensor. - * @param name The name of the sensor. - * @return The new sensor. + * @param channel the channel of the sensor + * @param name the name of the sensor + * @return the new sensor */ public static SimpleSensor createAnalogSensor(int channel, String name) { final SimpleSensor nonRealSensor = createNonRealSensor(name); @@ -37,9 +37,9 @@ public static SimpleSensor createAnalogSensor(int channel, String name) { /** * Creates a new digital sensor. * - * @param channel The channel of the sensor. - * @param name The name of the sensor. - * @return The new sensor. + * @param channel the channel of the sensor + * @param name the name of the sensor + * @return the new sensor */ public static SimpleSensor createDigitalSensor(int channel, String name) { final SimpleSensor nonRealSensor = createNonRealSensor(name); @@ -51,9 +51,9 @@ public static SimpleSensor createDigitalSensor(int channel, String name) { /** * Creates a new duty cycle sensor. * - * @param channel The channel of the sensor. - * @param name The name of the sensor. - * @return The new sensor. + * @param channel the channel of the sensor + * @param name the name of the sensor + * @return the new sensor */ public static SimpleSensor createDutyCycleSensor(int channel, String name) { final SimpleSensor nonRealSensor = createNonRealSensor(name); @@ -63,10 +63,29 @@ public static SimpleSensor createDutyCycleSensor(int channel, String name) { } /** - * Sets the scaling constants for the sensor. Used to convert the raw sensor value to a more useful unit. + * Creates a non-real sensor to be used if the robot is in replay or simulation. * - * @param scalingSlope The slope of the scaling line. - * @param scalingInterceptPoint The y-intercept of the scaling line. + * @param name the name of the sensor + * @return the non-real sensor + */ + private static SimpleSensor createNonRealSensor(String name) { + if (RobotHardwareStats.isReplay()) + return new SimpleSensor(new SimpleSensorIO(), name); + if (RobotHardwareStats.isSimulation()) + return new SimpleSensor(new SimpleSensorSimulationIO(), name); + return null; + } + + private SimpleSensor(SimpleSensorIO sensorIO, String name) { + this.sensorIO = sensorIO; + this.name = name; + } + + /** + * Sets the scaling constants for the sensor. Used in {@link SimpleSensor#getScaledValue()} to convert the raw sensor value to a more useful unit. + * + * @param scalingSlope the slope of the scaling line + * @param scalingInterceptPoint the y-intercept of the scaling line */ public void setScalingConstants(double scalingSlope, double scalingInterceptPoint) { this.scalingSlope = scalingSlope; @@ -74,9 +93,7 @@ public void setScalingConstants(double scalingSlope, double scalingInterceptPoin } /** - * Gets the value of the sensor. - * - * @return The value of the sensor. + * @return the value from the sensor */ public double getValue() { return sensorInputs.value; @@ -85,7 +102,7 @@ public double getValue() { /** * Gets the binary value of the sensor. A binary value is a boolean value that is true if the sensor has a value greater than 0. * - * @return The binary value of the sensor. + * @return the binary value of the sensor */ public boolean getBinaryValue() { return sensorInputs.value > 0; @@ -94,16 +111,16 @@ public boolean getBinaryValue() { /** * Gets the scaled value from the sensor using the scaling constants. * - * @return The scaled value. + * @return the scaled value */ public double getScaledValue() { return (sensorInputs.value * scalingSlope) + scalingInterceptPoint; } /** - * Sets the simulation supplier for the sensor. + * Sets the simulation supplier for the sensor. This supplier is used to get the value of the sensor in simulation. * - * @param simulationValueSupplier The simulation supplier. + * @param simulationValueSupplier the simulation supplier */ public void setSimulationSupplier(DoubleSupplier simulationValueSupplier) { sensorIO.setSimulationSupplier(simulationValueSupplier); @@ -116,17 +133,4 @@ public void updateSensor() { sensorIO.updateInputs(sensorInputs); Logger.processInputs("SimpleSensors/" + name, sensorInputs); } - - private static SimpleSensor createNonRealSensor(String name) { - if (RobotHardwareStats.isReplay()) - return new SimpleSensor(new SimpleSensorIO(), name); - if (RobotHardwareStats.isSimulation()) - return new SimpleSensor(new SimpleSensorSimulationIO(), name); - return null; - } - - private SimpleSensor(SimpleSensorIO sensorIO, String name) { - this.sensorIO = sensorIO; - this.name = name; - } -} +} \ No newline at end of file diff --git a/src/main/java/org/trigon/hardware/phoenix6/Phoenix6Inputs.java b/src/main/java/org/trigon/hardware/phoenix6/Phoenix6Inputs.java index 4db0b965..cf5c92f6 100644 --- a/src/main/java/org/trigon/hardware/phoenix6/Phoenix6Inputs.java +++ b/src/main/java/org/trigon/hardware/phoenix6/Phoenix6Inputs.java @@ -72,4 +72,4 @@ private void addSignalToSignalsArray(BaseStatusSignal statusSignal) { newSignals[signals.length] = statusSignal; signals = newSignals; } -} +} \ No newline at end of file diff --git a/src/main/java/org/trigon/hardware/phoenix6/Phoenix6SignalThread.java b/src/main/java/org/trigon/hardware/phoenix6/Phoenix6SignalThread.java index 72387129..b827fab8 100644 --- a/src/main/java/org/trigon/hardware/phoenix6/Phoenix6SignalThread.java +++ b/src/main/java/org/trigon/hardware/phoenix6/Phoenix6SignalThread.java @@ -25,7 +25,9 @@ import java.util.concurrent.ArrayBlockingQueue; import java.util.concurrent.locks.ReentrantLock; - +/** + * Provides an interface for asynchronously reading high-frequency measurements to a set of queues. + */ public class Phoenix6SignalThread extends SignalThreadBase { public static ReentrantLock SIGNALS_LOCK = new ReentrantLock(); private final List> queues = new ArrayList<>(); @@ -33,10 +35,12 @@ public class Phoenix6SignalThread extends SignalThreadBase { private static Phoenix6SignalThread INSTANCE = null; + /** + * @return The instance of the Phoenix6SignalThread + */ public static Phoenix6SignalThread getInstance() { - if (INSTANCE == null) { + if (INSTANCE == null) INSTANCE = new Phoenix6SignalThread(); - } return INSTANCE; } @@ -49,6 +53,12 @@ private Phoenix6SignalThread() { start(); } + /** + * Registers a signal to be read asynchronously. + * + * @param signal The signal to register + * @return The queue that the signal's values will be written to + */ public Queue registerSignal(BaseStatusSignal signal) { Queue queue = new ArrayBlockingQueue<>(100); SIGNALS_LOCK.lock(); diff --git a/src/main/java/org/trigon/hardware/phoenix6/cancoder/CANcoderSignal.java b/src/main/java/org/trigon/hardware/phoenix6/cancoder/CANcoderSignal.java index a31ee82e..29382891 100644 --- a/src/main/java/org/trigon/hardware/phoenix6/cancoder/CANcoderSignal.java +++ b/src/main/java/org/trigon/hardware/phoenix6/cancoder/CANcoderSignal.java @@ -2,7 +2,7 @@ import com.ctre.phoenix6.BaseStatusSignal; import com.ctre.phoenix6.hardware.CANcoder; -import org.trigon.hardware.SignalUtilities; +import org.trigon.utilities.StringUtilities; import java.util.function.Function; @@ -14,7 +14,7 @@ public enum CANcoderSignal { final Function signalFunction; CANcoderSignal(Function signalFunction) { - this.name = SignalUtilities.enumNameToSignalName(name()); + this.name = StringUtilities.toCamelCase(name()); this.signalFunction = signalFunction; } } diff --git a/src/main/java/org/trigon/hardware/phoenix6/pigeon2/Pigeon2Signal.java b/src/main/java/org/trigon/hardware/phoenix6/pigeon2/Pigeon2Signal.java index b6a80983..6b2d667f 100644 --- a/src/main/java/org/trigon/hardware/phoenix6/pigeon2/Pigeon2Signal.java +++ b/src/main/java/org/trigon/hardware/phoenix6/pigeon2/Pigeon2Signal.java @@ -3,7 +3,7 @@ import com.ctre.phoenix6.BaseStatusSignal; import com.ctre.phoenix6.hardware.Pigeon2; import com.ctre.phoenix6.hardware.core.CorePigeon2; -import org.trigon.hardware.SignalUtilities; +import org.trigon.utilities.StringUtilities; import java.util.function.Function; @@ -19,7 +19,7 @@ public enum Pigeon2Signal { final Function signalFunction; Pigeon2Signal(Function signalFunction) { - this.name = SignalUtilities.enumNameToSignalName(name()); + this.name = StringUtilities.toCamelCase(name()); this.signalFunction = signalFunction; } } diff --git a/src/main/java/org/trigon/hardware/phoenix6/talonfx/TalonFXMotor.java b/src/main/java/org/trigon/hardware/phoenix6/talonfx/TalonFXMotor.java index cb1dc369..a6da92e8 100644 --- a/src/main/java/org/trigon/hardware/phoenix6/talonfx/TalonFXMotor.java +++ b/src/main/java/org/trigon/hardware/phoenix6/talonfx/TalonFXMotor.java @@ -12,7 +12,9 @@ import org.trigon.hardware.simulation.MotorPhysicsSimulation; /** - * A class that represents a Talon FX motor. Used to control and get the values of the motor. + * A class that represents a Talon FX motor controller. + * This class provides a structured interface to control and monitor Talon FX motors both in real-world deployment, and physics-based simulation. + * It incorporates features for signal management, configuration handling, and threaded processing to ensure efficient and robust motor control */ public class TalonFXMotor { private final String motorName; @@ -21,7 +23,7 @@ public class TalonFXMotor { private final int id; /** - * Creates a new Talon FX motor. + * Creates a new TalonFX motor. * * @param id the motor's ID * @param motorName the name of the motor @@ -31,7 +33,7 @@ public TalonFXMotor(int id, String motorName) { } /** - * Creates a new Talon FX motor. + * Creates a new TalonFX motor. * * @param id the motor's ID * @param motorName the name of the motor @@ -63,7 +65,7 @@ public int getID() { } /** - * Sets the physics simulation of the motor. + * Sets the physics simulation of the motor. Needed for the motor to be used in simulation with accurate physics. * * @param physicsSimulation the simulation */ @@ -72,7 +74,7 @@ public void setPhysicsSimulation(MotorPhysicsSimulation physicsSimulation) { } /** - * Applies both the real and simulation configurations to the motor + * Applies both the real and simulation configurations to the motor. * * @param realConfiguration configuration to be used in real life * @param simulationConfiguration configuration to be used in simulation @@ -94,7 +96,7 @@ public void applyConfiguration(TalonFXConfiguration simulationAndRealConfigurati } /** - * Applies the configuration to be used in real life. + * Applies the configuration to be used when {@link RobotHardwareStats#isSimulation()} is false. * * @param realConfiguration the configuration */ @@ -152,6 +154,8 @@ public void registerSignal(TalonFXSignal signal, double updateFrequencyHertz) { /** * Registers a threaded signal to the motor. + * Threaded signals use threading to process certain signals separately, keeping them running smoothly in the background. + * This avoids slowing down the main program, unlike simpler signals that run directly in it. * * @param signal the threaded signal to register * @param updateFrequencyHertz The frequency at which the threaded signal will be updated @@ -181,7 +185,7 @@ public void setPosition(double positionRotations) { /** * Sets the motors neutral mode. * - * @param brake should the motor brake + * @param brake true if the motor should brake, false if it should coast */ public void setBrake(boolean brake) { motorIO.setBrake(brake); @@ -202,4 +206,4 @@ private TalonFXIO generateIO(int id, String canbus) { return new SimulationTalonFXIO(id); return new RealTalonFXIO(id, canbus); } -} +} \ No newline at end of file diff --git a/src/main/java/org/trigon/hardware/phoenix6/talonfx/TalonFXSignal.java b/src/main/java/org/trigon/hardware/phoenix6/talonfx/TalonFXSignal.java index fe0f47ac..7702ea70 100644 --- a/src/main/java/org/trigon/hardware/phoenix6/talonfx/TalonFXSignal.java +++ b/src/main/java/org/trigon/hardware/phoenix6/talonfx/TalonFXSignal.java @@ -2,7 +2,7 @@ import com.ctre.phoenix6.BaseStatusSignal; import com.ctre.phoenix6.hardware.TalonFX; -import org.trigon.hardware.SignalUtilities; +import org.trigon.utilities.StringUtilities; import java.util.function.Function; @@ -26,7 +26,7 @@ public enum TalonFXSignal { final Function signalFunction; TalonFXSignal(Function signalFunction) { - this.name = SignalUtilities.enumNameToSignalName(name()); + this.name = StringUtilities.toCamelCase(name()); this.signalFunction = signalFunction; } } \ No newline at end of file diff --git a/src/main/java/org/trigon/hardware/rev/spark/SparkSignal.java b/src/main/java/org/trigon/hardware/rev/spark/SparkSignal.java index 5873bf49..b0a96029 100644 --- a/src/main/java/org/trigon/hardware/rev/spark/SparkSignal.java +++ b/src/main/java/org/trigon/hardware/rev/spark/SparkSignal.java @@ -2,8 +2,8 @@ import com.revrobotics.spark.SparkBase; import org.trigon.hardware.RobotHardwareStats; -import org.trigon.hardware.SignalUtilities; import org.trigon.hardware.rev.sparkecnoder.SparkEncoder; +import org.trigon.utilities.StringUtilities; import java.util.function.Function; @@ -22,7 +22,7 @@ public enum SparkSignal { final Function encoderSignalFunction; SparkSignal(Function motorSignalFunction, Function encoderSignalFunction) { - this.name = SignalUtilities.enumNameToSignalName(name()); + this.name = StringUtilities.toCamelCase(name()); this.motorSignalFunction = motorSignalFunction; this.encoderSignalFunction = encoderSignalFunction; } diff --git a/src/main/java/org/trigon/hardware/rev/spark/SparkSignalThread.java b/src/main/java/org/trigon/hardware/rev/spark/SparkSignalThread.java index be860b73..c210fa5f 100644 --- a/src/main/java/org/trigon/hardware/rev/spark/SparkSignalThread.java +++ b/src/main/java/org/trigon/hardware/rev/spark/SparkSignalThread.java @@ -35,10 +35,12 @@ public class SparkSignalThread extends SignalThreadBase { private final List> queues = new ArrayList<>(); private static SparkSignalThread instance = null; + /** + * @return The instance of the SparkSignalThread + */ public static SparkSignalThread getInstance() { - if (instance == null) { + if (instance == null) instance = new SparkSignalThread(); - } return instance; } @@ -51,6 +53,12 @@ private SparkSignalThread() { } } + /** + * Registers a signal to be read asynchronously. + * + * @param signal The signal to register + * @return The queue that the signal's values will be written to + */ public Queue registerSignal(DoubleSupplier signal) { Queue queue = new ArrayBlockingQueue<>(100); SIGNALS_LOCK.lock(); diff --git a/src/main/java/org/trigon/utilities/StringUtilities.java b/src/main/java/org/trigon/utilities/StringUtilities.java new file mode 100644 index 00000000..d83665bf --- /dev/null +++ b/src/main/java/org/trigon/utilities/StringUtilities.java @@ -0,0 +1,27 @@ +package org.trigon.utilities; + +/** + * A class that contains utility methods for strings. + */ +public class StringUtilities { + /** + * Converts a string to camel case. + * + * @param input the string to convert + * @return the string in camel case + */ + public static String toCamelCase(String input) { + String[] parts = input.split("_"); + StringBuilder camelCase = new StringBuilder(); + + for (int i = 0; i < parts.length; i++) { + String part = parts[i].toLowerCase(); + if (i == 0) + camelCase.append(part); + else + camelCase.append(Character.toUpperCase(part.charAt(0))).append(part.substring(1)); + } + + return camelCase.toString(); + } +} \ No newline at end of file diff --git a/src/main/java/org/trigon/utilities/mirrorable/Mirrorable.java b/src/main/java/org/trigon/utilities/mirrorable/Mirrorable.java index 4562d544..81b90348 100644 --- a/src/main/java/org/trigon/utilities/mirrorable/Mirrorable.java +++ b/src/main/java/org/trigon/utilities/mirrorable/Mirrorable.java @@ -22,13 +22,13 @@ public abstract class Mirrorable { private static boolean IS_RED_ALLIANCE = isRedAlliance(); protected final T nonMirroredObject, mirroredObject; - protected final boolean mirrorWhenRedAlliance; + protected final boolean shouldMirrorWhenRedAlliance; static { UPDATE_ALLIANCE_TIMER.start(); new Trigger(() -> UPDATE_ALLIANCE_TIMER.advanceIfElapsed(0.5)).onTrue( - new InstantCommand(() -> IS_RED_ALLIANCE = notCachedIsRedAlliance()) + new InstantCommand(() -> IS_RED_ALLIANCE = notCachedIsRedAlliance()).ignoringDisable(true) ); } @@ -41,7 +41,7 @@ public abstract class Mirrorable { protected Mirrorable(T nonMirroredObject, boolean shouldMirrorWhenRedAlliance) { this.nonMirroredObject = nonMirroredObject; this.mirroredObject = mirror(nonMirroredObject); - this.mirrorWhenRedAlliance = shouldMirrorWhenRedAlliance; + this.shouldMirrorWhenRedAlliance = shouldMirrorWhenRedAlliance; } /** @@ -65,7 +65,7 @@ private static boolean notCachedIsRedAlliance() { * Otherwise, the non-mirrored object is returned. */ public T get() { - return isRedAlliance() && mirrorWhenRedAlliance ? mirroredObject : nonMirroredObject; + return isRedAlliance() && shouldMirrorWhenRedAlliance ? mirroredObject : nonMirroredObject; } /** diff --git a/src/main/java/org/trigon/utilities/mirrorable/MirrorablePose2d.java b/src/main/java/org/trigon/utilities/mirrorable/MirrorablePose2d.java index 7d95b390..f8288434 100644 --- a/src/main/java/org/trigon/utilities/mirrorable/MirrorablePose2d.java +++ b/src/main/java/org/trigon/utilities/mirrorable/MirrorablePose2d.java @@ -41,7 +41,7 @@ public MirrorablePose2d(Translation2d translation2d, double rotation, boolean sh * @return the rotation value of the pose. */ public MirrorableRotation2d getRotation() { - return new MirrorableRotation2d(nonMirroredObject.getRotation(), mirrorWhenRedAlliance); + return new MirrorableRotation2d(nonMirroredObject.getRotation(), shouldMirrorWhenRedAlliance); } @Override From a31891ed41fa93085d27ca6200d5f0e6abedfb08 Mon Sep 17 00:00:00 2001 From: Nummun14 <142012009+Nummun14@users.noreply.github.com> Date: Tue, 26 Nov 2024 19:42:53 +0200 Subject: [PATCH 10/61] updated wpilib tools --- build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.gradle b/build.gradle index 35584017..b502789b 100644 --- a/build.gradle +++ b/build.gradle @@ -2,7 +2,7 @@ plugins { id "java" id "maven-publish" id "edu.wpi.first.GradleRIO" version "2025.1.1-beta-1" - id "edu.wpi.first.WpilibTools" version "1.3.0" + id "edu.wpi.first.WpilibTools" version "2.1.0" } java { From 8f37adeb58414f963bcfbd045d9446fa9ada77c3 Mon Sep 17 00:00:00 2001 From: Nummun14 <142012009+Nummun14@users.noreply.github.com> Date: Wed, 27 Nov 2024 16:23:54 +0200 Subject: [PATCH 11/61] maybe firxed SimpleMotorSimulation? (I know the jdoc isn't good, I'll fix it soon) --- .../hardware/simulation/SimpleMotorSimulation.java | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/main/java/org/trigon/hardware/simulation/SimpleMotorSimulation.java b/src/main/java/org/trigon/hardware/simulation/SimpleMotorSimulation.java index 7c445d5c..2d0834c4 100644 --- a/src/main/java/org/trigon/hardware/simulation/SimpleMotorSimulation.java +++ b/src/main/java/org/trigon/hardware/simulation/SimpleMotorSimulation.java @@ -15,14 +15,15 @@ public class SimpleMotorSimulation extends MotorPhysicsSimulation { /** * Creates a new SimpleMotorSimulation. * - * @param gearbox The gearbox of the motor(s) - * @param gearRatio The gearbox's gear ratio - * @param kv voltage needed to maintain constant velocity - * @param ka voltage needed to induce a specific acceleration + * @param gearbox The gearbox of the motor(s) + * @param gearRatio The gearbox's gear ratio + * @param kv voltage needed to maintain constant velocity + * @param ka voltage needed to induce a specific acceleration + * @param measurementStdDevs The standard deviations of the measurements */ - public SimpleMotorSimulation(DCMotor gearbox, double gearRatio, double kv, double ka) { + public SimpleMotorSimulation(DCMotor gearbox, double gearRatio, double kv, double ka, double... measurementStdDevs) { super(gearRatio); - motorSimulation = new DCMotorSim(LinearSystemId.createDCMotorSystem(kv, ka), gearbox, gearRatio); + motorSimulation = new DCMotorSim(LinearSystemId.createDCMotorSystem(kv, ka), gearbox, measurementStdDevs); } /** From 7a119a50e4dee615fc03429aefdd996de0f39e12 Mon Sep 17 00:00:00 2001 From: Nummun14 <142012009+Nummun14@users.noreply.github.com> Date: Wed, 27 Nov 2024 17:53:47 +0200 Subject: [PATCH 12/61] did a bit of the review, will soon finish it --- .../trigon/hardware/RobotHardwareStats.java | 14 +++++++--- .../org/trigon/hardware/SignalThreadBase.java | 8 +++--- .../misc/simplesensor/SimpleSensor.java | 3 ++- .../hardware/phoenix6/Phoenix6Inputs.java | 3 ++- .../phoenix6/Phoenix6SignalThread.java | 13 +++++---- .../phoenix6/cancoder/CANcoderSignal.java | 4 +-- .../phoenix6/pigeon2/Pigeon2Signal.java | 4 +-- .../phoenix6/talonfx/TalonFXMotor.java | 12 +++------ .../phoenix6/talonfx/TalonFXSignal.java | 4 +-- .../hardware/rev/spark/SparkSignal.java | 4 +-- .../hardware/rev/spark/SparkSignalThread.java | 9 +++---- .../org/trigon/utilities/Conversions.java | 23 +++++++++++++++- .../org/trigon/utilities/StringUtilities.java | 27 ------------------- .../mirrorable/MirrorablePose2d.java | 2 +- 14 files changed, 62 insertions(+), 68 deletions(-) delete mode 100644 src/main/java/org/trigon/utilities/StringUtilities.java diff --git a/src/main/java/org/trigon/hardware/RobotHardwareStats.java b/src/main/java/org/trigon/hardware/RobotHardwareStats.java index 677a5772..79c21d71 100644 --- a/src/main/java/org/trigon/hardware/RobotHardwareStats.java +++ b/src/main/java/org/trigon/hardware/RobotHardwareStats.java @@ -12,7 +12,7 @@ public class RobotHardwareStats { * Sets the current robot stats. This should be called in the robot's init method. * We use this structure to avoid using static variables in the Robot class. * - * @param isReal whether the robot is real or a simulation. This should be taken from the Robot class. + * @param isReal whether the robot is real or a simulation. This should be taken from the Robot class * @param replayType the type of replay */ public static void setCurrentRobotStats(boolean isReal, ReplayType replayType) { @@ -58,13 +58,19 @@ public static boolean isSimulation() { /** * An enum that represents the type of replay. - * NONE - the robot is not in replay mode - * SIMULATION_REPLAY - the robot is in simulation replay mode - * REAL_REPLAY - the robot is in real replay mode */ public enum ReplayType { + /** + * The robot is not in replay mode + */ NONE, + /** + * The robot is in simulation replay mode + */ SIMULATION_REPLAY, + /** + * The robot is in real replay mode + */ REAL_REPLAY } } \ No newline at end of file diff --git a/src/main/java/org/trigon/hardware/SignalThreadBase.java b/src/main/java/org/trigon/hardware/SignalThreadBase.java index b840ef44..ff630038 100644 --- a/src/main/java/org/trigon/hardware/SignalThreadBase.java +++ b/src/main/java/org/trigon/hardware/SignalThreadBase.java @@ -15,7 +15,7 @@ public class SignalThreadBase extends Thread { protected final Queue timestamps = new ArrayBlockingQueue<>(100); private final ThreadInputsAutoLogged threadInputs = new ThreadInputsAutoLogged(); private final String name; - protected double odometryFrequencyHertz = 50; + protected double threadFrequencyHertz = 50; /** * Creates a new SignalThreadBase. @@ -32,10 +32,10 @@ public SignalThreadBase(String name) { * A higher frequency will result in more frequent updates, but may also demand more processing power. * Only used for Spark motors. * - * @param odometryFrequencyHertz The odometry frequency in hertz + * @param odometryFrequencyHertz the odometry frequency in hertz */ - public void setOdometryFrequencyHertz(double odometryFrequencyHertz) { - this.odometryFrequencyHertz = odometryFrequencyHertz; + public void setThreadFrequencyHertz(double odometryFrequencyHertz) { + this.threadFrequencyHertz = odometryFrequencyHertz; } /** diff --git a/src/main/java/org/trigon/hardware/misc/simplesensor/SimpleSensor.java b/src/main/java/org/trigon/hardware/misc/simplesensor/SimpleSensor.java index 746f14d4..f7818355 100644 --- a/src/main/java/org/trigon/hardware/misc/simplesensor/SimpleSensor.java +++ b/src/main/java/org/trigon/hardware/misc/simplesensor/SimpleSensor.java @@ -63,7 +63,8 @@ public static SimpleSensor createDutyCycleSensor(int channel, String name) { } /** - * Creates a non-real sensor to be used if the robot is in replay or simulation. + * Creates a non-real sensor to be used if the robot is in replay or simulation. Returns null if the robot is real. + * This is used in the create methods to avoid creating a real sensor when the robot is in replay or simulation. * * @param name the name of the sensor * @return the non-real sensor diff --git a/src/main/java/org/trigon/hardware/phoenix6/Phoenix6Inputs.java b/src/main/java/org/trigon/hardware/phoenix6/Phoenix6Inputs.java index cf5c92f6..81789302 100644 --- a/src/main/java/org/trigon/hardware/phoenix6/Phoenix6Inputs.java +++ b/src/main/java/org/trigon/hardware/phoenix6/Phoenix6Inputs.java @@ -35,7 +35,8 @@ public void registerThreadedSignal(BaseStatusSignal statusSignal, double updateF return; registerSignal(statusSignal, updateFrequencyHertz); - statusSignal.setUpdateFrequency(50); + if (RobotHardwareStats.isSimulation()) + statusSignal.setUpdateFrequency(50); signalToThreadedQueue.put(statusSignal.getName() + "_Threaded", signalThread.registerSignal(statusSignal)); } diff --git a/src/main/java/org/trigon/hardware/phoenix6/Phoenix6SignalThread.java b/src/main/java/org/trigon/hardware/phoenix6/Phoenix6SignalThread.java index b827fab8..92646a25 100644 --- a/src/main/java/org/trigon/hardware/phoenix6/Phoenix6SignalThread.java +++ b/src/main/java/org/trigon/hardware/phoenix6/Phoenix6SignalThread.java @@ -14,6 +14,7 @@ package org.trigon.hardware.phoenix6; import com.ctre.phoenix6.BaseStatusSignal; +import com.ctre.phoenix6.StatusCode; import edu.wpi.first.wpilibj.Timer; import org.littletonrobotics.junction.Logger; import org.trigon.hardware.RobotHardwareStats; @@ -35,9 +36,6 @@ public class Phoenix6SignalThread extends SignalThreadBase { private static Phoenix6SignalThread INSTANCE = null; - /** - * @return The instance of the Phoenix6SignalThread - */ public static Phoenix6SignalThread getInstance() { if (INSTANCE == null) INSTANCE = new Phoenix6SignalThread(); @@ -56,8 +54,8 @@ private Phoenix6SignalThread() { /** * Registers a signal to be read asynchronously. * - * @param signal The signal to register - * @return The queue that the signal's values will be written to + * @param signal the signal to register + * @return the queue that the signal's values will be written to */ public Queue registerSignal(BaseStatusSignal signal) { Queue queue = new ArrayBlockingQueue<>(100); @@ -80,8 +78,9 @@ public void run() { } private void updateValues() { - BaseStatusSignal.waitForAll(RobotHardwareStats.getPeriodicTimeSeconds(), signals); - final double updateTimestamp = (Logger.getRealTimestamp() / 1.0e6) - signals[0].getTimestamp().getLatency(); + if (BaseStatusSignal.waitForAll(RobotHardwareStats.getPeriodicTimeSeconds(), signals) != StatusCode.OK) + return; + final double updateTimestamp = (Logger.getRealTimestamp() / 1e6) - signals[0].getTimestamp().getLatency(); SIGNALS_LOCK.lock(); try { diff --git a/src/main/java/org/trigon/hardware/phoenix6/cancoder/CANcoderSignal.java b/src/main/java/org/trigon/hardware/phoenix6/cancoder/CANcoderSignal.java index 29382891..3ec7714c 100644 --- a/src/main/java/org/trigon/hardware/phoenix6/cancoder/CANcoderSignal.java +++ b/src/main/java/org/trigon/hardware/phoenix6/cancoder/CANcoderSignal.java @@ -2,7 +2,7 @@ import com.ctre.phoenix6.BaseStatusSignal; import com.ctre.phoenix6.hardware.CANcoder; -import org.trigon.utilities.StringUtilities; +import org.trigon.utilities.Conversions; import java.util.function.Function; @@ -14,7 +14,7 @@ public enum CANcoderSignal { final Function signalFunction; CANcoderSignal(Function signalFunction) { - this.name = StringUtilities.toCamelCase(name()); + this.name = Conversions.snakeCaseToCamelCase(name()); this.signalFunction = signalFunction; } } diff --git a/src/main/java/org/trigon/hardware/phoenix6/pigeon2/Pigeon2Signal.java b/src/main/java/org/trigon/hardware/phoenix6/pigeon2/Pigeon2Signal.java index 6b2d667f..886fc369 100644 --- a/src/main/java/org/trigon/hardware/phoenix6/pigeon2/Pigeon2Signal.java +++ b/src/main/java/org/trigon/hardware/phoenix6/pigeon2/Pigeon2Signal.java @@ -3,7 +3,7 @@ import com.ctre.phoenix6.BaseStatusSignal; import com.ctre.phoenix6.hardware.Pigeon2; import com.ctre.phoenix6.hardware.core.CorePigeon2; -import org.trigon.utilities.StringUtilities; +import org.trigon.utilities.Conversions; import java.util.function.Function; @@ -19,7 +19,7 @@ public enum Pigeon2Signal { final Function signalFunction; Pigeon2Signal(Function signalFunction) { - this.name = StringUtilities.toCamelCase(name()); + this.name = Conversions.snakeCaseToCamelCase(name()); this.signalFunction = signalFunction; } } diff --git a/src/main/java/org/trigon/hardware/phoenix6/talonfx/TalonFXMotor.java b/src/main/java/org/trigon/hardware/phoenix6/talonfx/TalonFXMotor.java index a6da92e8..53b9d4c9 100644 --- a/src/main/java/org/trigon/hardware/phoenix6/talonfx/TalonFXMotor.java +++ b/src/main/java/org/trigon/hardware/phoenix6/talonfx/TalonFXMotor.java @@ -12,9 +12,10 @@ import org.trigon.hardware.simulation.MotorPhysicsSimulation; /** - * A class that represents a Talon FX motor controller. + * A class that represents a TalonFX motor controller. * This class provides a structured interface to control and monitor Talon FX motors both in real-world deployment, and physics-based simulation. * It incorporates features for signal management, configuration handling, and threaded processing to ensure efficient and robust motor control + * It's incorporated with advantage kit logging. */ public class TalonFXMotor { private final String motorName; @@ -48,18 +49,13 @@ public TalonFXMotor(int id, String motorName, String canbus) { } /** - * Updates the motor and logs the inputs. + * Updates the motor and logs its inputs. */ public void update() { motorIO.updateMotor(); Logger.processInputs("Motors/" + motorName, motorInputs); } - /** - * Gets the ID of the motor. - * - * @return the ID of the motor - */ public int getID() { return id; } @@ -146,7 +142,7 @@ public double[] getThreadedSignal(TalonFXSignal signal) { * Registers a signal to the motor. * * @param signal the signal to register - * @param updateFrequencyHertz The frequency at which the signal will be updated + * @param updateFrequencyHertz the frequency at which the signal will be updated */ public void registerSignal(TalonFXSignal signal, double updateFrequencyHertz) { motorInputs.registerSignal(motorSignalToStatusSignal(signal), updateFrequencyHertz); diff --git a/src/main/java/org/trigon/hardware/phoenix6/talonfx/TalonFXSignal.java b/src/main/java/org/trigon/hardware/phoenix6/talonfx/TalonFXSignal.java index 7702ea70..c9223441 100644 --- a/src/main/java/org/trigon/hardware/phoenix6/talonfx/TalonFXSignal.java +++ b/src/main/java/org/trigon/hardware/phoenix6/talonfx/TalonFXSignal.java @@ -2,7 +2,7 @@ import com.ctre.phoenix6.BaseStatusSignal; import com.ctre.phoenix6.hardware.TalonFX; -import org.trigon.utilities.StringUtilities; +import org.trigon.utilities.Conversions; import java.util.function.Function; @@ -26,7 +26,7 @@ public enum TalonFXSignal { final Function signalFunction; TalonFXSignal(Function signalFunction) { - this.name = StringUtilities.toCamelCase(name()); + this.name = Conversions.snakeCaseToCamelCase(name()); this.signalFunction = signalFunction; } } \ No newline at end of file diff --git a/src/main/java/org/trigon/hardware/rev/spark/SparkSignal.java b/src/main/java/org/trigon/hardware/rev/spark/SparkSignal.java index b0a96029..26084ba1 100644 --- a/src/main/java/org/trigon/hardware/rev/spark/SparkSignal.java +++ b/src/main/java/org/trigon/hardware/rev/spark/SparkSignal.java @@ -3,7 +3,7 @@ import com.revrobotics.spark.SparkBase; import org.trigon.hardware.RobotHardwareStats; import org.trigon.hardware.rev.sparkecnoder.SparkEncoder; -import org.trigon.utilities.StringUtilities; +import org.trigon.utilities.Conversions; import java.util.function.Function; @@ -22,7 +22,7 @@ public enum SparkSignal { final Function encoderSignalFunction; SparkSignal(Function motorSignalFunction, Function encoderSignalFunction) { - this.name = StringUtilities.toCamelCase(name()); + this.name = Conversions.snakeCaseToCamelCase(name()); this.motorSignalFunction = motorSignalFunction; this.encoderSignalFunction = encoderSignalFunction; } diff --git a/src/main/java/org/trigon/hardware/rev/spark/SparkSignalThread.java b/src/main/java/org/trigon/hardware/rev/spark/SparkSignalThread.java index c210fa5f..dc90bad0 100644 --- a/src/main/java/org/trigon/hardware/rev/spark/SparkSignalThread.java +++ b/src/main/java/org/trigon/hardware/rev/spark/SparkSignalThread.java @@ -35,9 +35,6 @@ public class SparkSignalThread extends SignalThreadBase { private final List> queues = new ArrayList<>(); private static SparkSignalThread instance = null; - /** - * @return The instance of the SparkSignalThread - */ public static SparkSignalThread getInstance() { if (instance == null) instance = new SparkSignalThread(); @@ -49,15 +46,15 @@ private SparkSignalThread() { if (ACTIVE) { Notifier notifier = new Notifier(this::periodic); notifier.setName("SparkSignalThread"); - notifier.startPeriodic(1.0 / super.odometryFrequencyHertz); + notifier.startPeriodic(1.0 / super.threadFrequencyHertz); } } /** * Registers a signal to be read asynchronously. * - * @param signal The signal to register - * @return The queue that the signal's values will be written to + * @param signal the signal to register + * @return the queue that the signal's values will be written to */ public Queue registerSignal(DoubleSupplier signal) { Queue queue = new ArrayBlockingQueue<>(100); diff --git a/src/main/java/org/trigon/utilities/Conversions.java b/src/main/java/org/trigon/utilities/Conversions.java index 790da24f..c9e4e349 100644 --- a/src/main/java/org/trigon/utilities/Conversions.java +++ b/src/main/java/org/trigon/utilities/Conversions.java @@ -238,4 +238,25 @@ public static double compensatedPowerToVoltage(double power, double saturation) public static TrapezoidProfile.Constraints scaleConstraints(TrapezoidProfile.Constraints constraints, double percentage) { return new TrapezoidProfile.Constraints(constraints.maxVelocity * (percentage / 100), constraints.maxAcceleration * (percentage / 100)); } -} + + /** + * Converts a string in SNAKE_CASE to camelCase. + * + * @param input the string to convert + * @return the string in camel case + */ + public static String snakeCaseToCamelCase(String input) { + String[] parts = input.split("_"); + StringBuilder camelCase = new StringBuilder(); + + for (int i = 0; i < parts.length; i++) { + String part = parts[i].toLowerCase(); + if (i == 0) + camelCase.append(part); + else + camelCase.append(Character.toUpperCase(part.charAt(0))).append(part.substring(1)); + } + + return camelCase.toString(); + } +} \ No newline at end of file diff --git a/src/main/java/org/trigon/utilities/StringUtilities.java b/src/main/java/org/trigon/utilities/StringUtilities.java deleted file mode 100644 index d83665bf..00000000 --- a/src/main/java/org/trigon/utilities/StringUtilities.java +++ /dev/null @@ -1,27 +0,0 @@ -package org.trigon.utilities; - -/** - * A class that contains utility methods for strings. - */ -public class StringUtilities { - /** - * Converts a string to camel case. - * - * @param input the string to convert - * @return the string in camel case - */ - public static String toCamelCase(String input) { - String[] parts = input.split("_"); - StringBuilder camelCase = new StringBuilder(); - - for (int i = 0; i < parts.length; i++) { - String part = parts[i].toLowerCase(); - if (i == 0) - camelCase.append(part); - else - camelCase.append(Character.toUpperCase(part.charAt(0))).append(part.substring(1)); - } - - return camelCase.toString(); - } -} \ No newline at end of file diff --git a/src/main/java/org/trigon/utilities/mirrorable/MirrorablePose2d.java b/src/main/java/org/trigon/utilities/mirrorable/MirrorablePose2d.java index f8288434..952e40e8 100644 --- a/src/main/java/org/trigon/utilities/mirrorable/MirrorablePose2d.java +++ b/src/main/java/org/trigon/utilities/mirrorable/MirrorablePose2d.java @@ -36,7 +36,7 @@ public MirrorablePose2d(Translation2d translation2d, double rotation, boolean sh } /** - * Gets the rotation value of the pose. + * Gets the rotation value of the pose. The pose will be mirrored if the robot is on the red alliance and {@link #shouldMirrorWhenRedAlliance} is true. * * @return the rotation value of the pose. */ From 26760937a60d8c35f0d57f40e24bf142e5d288ab Mon Sep 17 00:00:00 2001 From: Nummun14 <142012009+Nummun14@users.noreply.github.com> Date: Wed, 27 Nov 2024 18:00:54 +0200 Subject: [PATCH 13/61] removed this for ezra (Your welcome, good luck on the math test :)) --- .../hardware/simulation/SimpleMotorSimulation.java | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/src/main/java/org/trigon/hardware/simulation/SimpleMotorSimulation.java b/src/main/java/org/trigon/hardware/simulation/SimpleMotorSimulation.java index 2d0834c4..9fe294b8 100644 --- a/src/main/java/org/trigon/hardware/simulation/SimpleMotorSimulation.java +++ b/src/main/java/org/trigon/hardware/simulation/SimpleMotorSimulation.java @@ -15,15 +15,14 @@ public class SimpleMotorSimulation extends MotorPhysicsSimulation { /** * Creates a new SimpleMotorSimulation. * - * @param gearbox The gearbox of the motor(s) - * @param gearRatio The gearbox's gear ratio - * @param kv voltage needed to maintain constant velocity - * @param ka voltage needed to induce a specific acceleration - * @param measurementStdDevs The standard deviations of the measurements + * @param gearbox The gearbox of the motor(s) + * @param gearRatio The gearbox's gear ratio + * @param kv voltage needed to maintain constant velocity + * @param ka voltage needed to induce a specific acceleration */ - public SimpleMotorSimulation(DCMotor gearbox, double gearRatio, double kv, double ka, double... measurementStdDevs) { + public SimpleMotorSimulation(DCMotor gearbox, double gearRatio, double kv, double ka) { super(gearRatio); - motorSimulation = new DCMotorSim(LinearSystemId.createDCMotorSystem(kv, ka), gearbox, measurementStdDevs); + motorSimulation = new DCMotorSim(LinearSystemId.createDCMotorSystem(kv, ka), gearbox); } /** From 6fa773d0c8268d0a875a625d61af786bba208bc0 Mon Sep 17 00:00:00 2001 From: Nummun14 <142012009+Nummun14@users.noreply.github.com> Date: Wed, 27 Nov 2024 18:13:15 +0200 Subject: [PATCH 14/61] sim thing --- .../java/org/trigon/hardware/rev/spark/SparkIO.java | 5 ++++- .../org/trigon/hardware/rev/spark/SparkMotor.java | 7 +++++++ .../hardware/rev/spark/io/SimulationSparkIO.java | 13 +++++++++---- 3 files changed, 20 insertions(+), 5 deletions(-) diff --git a/src/main/java/org/trigon/hardware/rev/spark/SparkIO.java b/src/main/java/org/trigon/hardware/rev/spark/SparkIO.java index 51e2c469..58b8e110 100644 --- a/src/main/java/org/trigon/hardware/rev/spark/SparkIO.java +++ b/src/main/java/org/trigon/hardware/rev/spark/SparkIO.java @@ -30,6 +30,9 @@ public void configure(SparkMaxConfig configuration, SparkBase.ResetMode resetMod public void setInverted(boolean inverted) { } + public void updateSimulation() { + } + public SparkBase getMotor() { return null; } @@ -37,4 +40,4 @@ public SparkBase getMotor() { public SparkEncoder getEncoder() { return null; } -} +} \ No newline at end of file diff --git a/src/main/java/org/trigon/hardware/rev/spark/SparkMotor.java b/src/main/java/org/trigon/hardware/rev/spark/SparkMotor.java index 9ad0540c..f72dc471 100644 --- a/src/main/java/org/trigon/hardware/rev/spark/SparkMotor.java +++ b/src/main/java/org/trigon/hardware/rev/spark/SparkMotor.java @@ -176,6 +176,13 @@ public void configure(SparkMaxConfig configuration, SparkBase.ResetMode resetMod motorIO.configure(configuration, resetMode, persistMode); } + /** + * Updates the motor simulation. Only used in simulation. Should be called periodically. + */ + public void updateSimulation() { + motorIO.updateSimulation(); + } + private SparkIO createSparkIO(int id, SparkType sparkType, DCMotor simulationMotor) { if (RobotHardwareStats.isReplay()) return new SparkIO(); diff --git a/src/main/java/org/trigon/hardware/rev/spark/io/SimulationSparkIO.java b/src/main/java/org/trigon/hardware/rev/spark/io/SimulationSparkIO.java index 0cc4fefb..329e64cd 100644 --- a/src/main/java/org/trigon/hardware/rev/spark/io/SimulationSparkIO.java +++ b/src/main/java/org/trigon/hardware/rev/spark/io/SimulationSparkIO.java @@ -1,11 +1,12 @@ package org.trigon.hardware.rev.spark.io; -import com.revrobotics.sim.SparkMaxSim; import com.revrobotics.spark.SparkBase; import com.revrobotics.spark.SparkClosedLoopController; import com.revrobotics.spark.SparkMax; +import com.revrobotics.spark.SparkSim; import com.revrobotics.spark.config.SparkMaxConfig; import edu.wpi.first.math.system.plant.DCMotor; +import edu.wpi.first.wpilibj.Timer; import org.trigon.hardware.rev.spark.SparkIO; import org.trigon.hardware.rev.sparkecnoder.SparkEncoder; @@ -13,11 +14,11 @@ public class SimulationSparkIO extends SparkIO { private final SparkMax motor; private final SparkClosedLoopController pidController; private final SparkEncoder encoder; - private final SparkMaxSim simulation; + private final SparkSim simulation; public SimulationSparkIO(int id, DCMotor gearbox) { motor = new SparkMax(id, SparkMax.MotorType.kBrushless); - simulation = new SparkMaxSim(motor, gearbox); + simulation = new SparkSim(motor, gearbox); pidController = motor.getClosedLoopController(); encoder = SparkEncoder.createRelativeEncoder(motor); } @@ -45,7 +46,6 @@ public SparkBase getMotor() { @Override public void stopMotor() { motor.stopMotor(); - simulation.setAppliedOutput(0); } @Override @@ -68,6 +68,11 @@ public void setInverted(boolean inverted) { motor.setInverted(inverted); } + @Override + public void updateSimulation() { + simulation.iterate(motor.getAbsoluteEncoder().getVelocity(), motor.getBusVoltage(), Timer.getFPGATimestamp()); + } + @Override public void configure(SparkMaxConfig configuration, SparkBase.ResetMode resetMode, SparkBase.PersistMode persistMode) { motor.configure(configuration, resetMode, persistMode); From 8f0c459f59f4840292f03244c741c8f54f30645e Mon Sep 17 00:00:00 2001 From: Nummun14 <142012009+Nummun14@users.noreply.github.com> Date: Thu, 28 Nov 2024 16:27:49 +0200 Subject: [PATCH 15/61] "Explain more" --- .../java/org/trigon/hardware/BaseInputs.java | 18 ++++ .../trigon/hardware/RobotHardwareStats.java | 3 +- .../org/trigon/hardware/SignalThreadBase.java | 13 +-- .../hardware/phoenix6/Phoenix6Inputs.java | 18 ++++ .../phoenix6/Phoenix6SignalThread.java | 2 +- .../phoenix6/talonfx/TalonFXMotor.java | 9 +- .../hardware/rev/spark/SparkInputs.java | 16 ++++ .../simulation/FlywheelSimulation.java | 89 ------------------- 8 files changed, 69 insertions(+), 99 deletions(-) delete mode 100644 src/main/java/org/trigon/hardware/simulation/FlywheelSimulation.java diff --git a/src/main/java/org/trigon/hardware/BaseInputs.java b/src/main/java/org/trigon/hardware/BaseInputs.java index 0ef4de2d..ee2f5e98 100644 --- a/src/main/java/org/trigon/hardware/BaseInputs.java +++ b/src/main/java/org/trigon/hardware/BaseInputs.java @@ -11,6 +11,11 @@ public abstract class BaseInputs implements LoggableInputs { private final String name; private double lastErrorTimestamp = 0; + /** + * Creates a new BaseInputs instance. + * + * @param name the name of the instance + */ public BaseInputs(String name) { this.name = name; } @@ -20,6 +25,12 @@ public void fromLog(LogTable table) { latestTable = table; } + /** + * Gets a signal. + * + * @param signalName the name of the signal + * @return the signal + */ public double getSignal(String signalName) { if (latestTable == null) { if (shouldPrintError()) @@ -37,6 +48,13 @@ public double getSignal(String signalName) { return value.getDouble(); } + /** + * Gets a threaded signal. + * Threaded signals use threading to process certain signals separately, keeping them running smoothly in the background. + * + * @param signalName the name of the threaded signal + * @return the threaded signal + */ public double[] getThreadedSignal(String signalName) { if (latestTable == null) { if (shouldPrintError()) diff --git a/src/main/java/org/trigon/hardware/RobotHardwareStats.java b/src/main/java/org/trigon/hardware/RobotHardwareStats.java index 79c21d71..508bfe9e 100644 --- a/src/main/java/org/trigon/hardware/RobotHardwareStats.java +++ b/src/main/java/org/trigon/hardware/RobotHardwareStats.java @@ -10,6 +10,7 @@ public class RobotHardwareStats { /** * Sets the current robot stats. This should be called in the robot's init method. + * If isReal is true both simulation and replay will be false, otherwise they will be set according to the replay type. * We use this structure to avoid using static variables in the Robot class. * * @param isReal whether the robot is real or a simulation. This should be taken from the Robot class @@ -27,7 +28,7 @@ public static void setCurrentRobotStats(boolean isReal, ReplayType replayType) { } /** - * Sets how frequently the periodic method is called in seconds. + * Sets how frequently the periodic method is called in seconds. Used for calling methods periodically. * * @param periodicTimeSeconds the periodic time in seconds */ diff --git a/src/main/java/org/trigon/hardware/SignalThreadBase.java b/src/main/java/org/trigon/hardware/SignalThreadBase.java index ff630038..80fb236f 100644 --- a/src/main/java/org/trigon/hardware/SignalThreadBase.java +++ b/src/main/java/org/trigon/hardware/SignalThreadBase.java @@ -9,6 +9,7 @@ /** * A class that represents a base for a signal thread. + * Signal threads are specialized threads that run at a specific frequency to handle updating signals. */ public class SignalThreadBase extends Thread { public static final ReentrantLock SIGNALS_LOCK = new ReentrantLock(); @@ -27,15 +28,15 @@ public SignalThreadBase(String name) { } /** - * Sets the odometry frequency in hertz. - * The odometry frequency determines how often the robot's position and motion data are updated. + * Sets the thread frequency in hertz. + * The thread frequency determines how often the robot's position and motion data are updated. * A higher frequency will result in more frequent updates, but may also demand more processing power. * Only used for Spark motors. * - * @param odometryFrequencyHertz the odometry frequency in hertz + * @param threadFrequencyHertz the odometry frequency in hertz */ - public void setThreadFrequencyHertz(double odometryFrequencyHertz) { - this.threadFrequencyHertz = odometryFrequencyHertz; + public void setThreadFrequencyHertz(double threadFrequencyHertz) { + this.threadFrequencyHertz = threadFrequencyHertz; } /** @@ -50,7 +51,7 @@ public void updateLatestTimestamps() { } /** - * Gets the latest timestamps when events occurred within the thread's execution. + * Gets the latest timestamps when events signals were updated. * * @return The latest timestamps */ diff --git a/src/main/java/org/trigon/hardware/phoenix6/Phoenix6Inputs.java b/src/main/java/org/trigon/hardware/phoenix6/Phoenix6Inputs.java index 81789302..2b455dc6 100644 --- a/src/main/java/org/trigon/hardware/phoenix6/Phoenix6Inputs.java +++ b/src/main/java/org/trigon/hardware/phoenix6/Phoenix6Inputs.java @@ -15,6 +15,11 @@ public class Phoenix6Inputs extends BaseInputs { private final Phoenix6SignalThread signalThread = Phoenix6SignalThread.getInstance(); private BaseStatusSignal[] signals = new BaseStatusSignal[0]; + /** + * Creates a new Phoenix6Inputs instance. + * + * @param name the name of the instance + */ public Phoenix6Inputs(String name) { super(name); } @@ -30,6 +35,13 @@ public void toLog(LogTable table) { latestTable = table; } + /** + * Registers a threaded signal. + * Threaded signals use threading to process certain signals separately, keeping them running smoothly in the background. + * + * @param statusSignal the signal + * @param updateFrequencyHertz the update frequency in hertz + */ public void registerThreadedSignal(BaseStatusSignal statusSignal, double updateFrequencyHertz) { if (statusSignal == null || RobotHardwareStats.isReplay()) return; @@ -40,6 +52,12 @@ public void registerThreadedSignal(BaseStatusSignal statusSignal, double updateF signalToThreadedQueue.put(statusSignal.getName() + "_Threaded", signalThread.registerSignal(statusSignal)); } + /** + * Registers a signal. + * + * @param statusSignal the signal + * @param updateFrequencyHertz the update frequency in hertz + */ public void registerSignal(BaseStatusSignal statusSignal, double updateFrequencyHertz) { if (statusSignal == null || RobotHardwareStats.isReplay()) return; diff --git a/src/main/java/org/trigon/hardware/phoenix6/Phoenix6SignalThread.java b/src/main/java/org/trigon/hardware/phoenix6/Phoenix6SignalThread.java index 92646a25..a8044f55 100644 --- a/src/main/java/org/trigon/hardware/phoenix6/Phoenix6SignalThread.java +++ b/src/main/java/org/trigon/hardware/phoenix6/Phoenix6SignalThread.java @@ -27,7 +27,7 @@ import java.util.concurrent.locks.ReentrantLock; /** - * Provides an interface for asynchronously reading high-frequency measurements to a set of queues. + * Provides an interface for asynchronously reading high-frequency measurements to a set of queues for Phoenix 6. */ public class Phoenix6SignalThread extends SignalThreadBase { public static ReentrantLock SIGNALS_LOCK = new ReentrantLock(); diff --git a/src/main/java/org/trigon/hardware/phoenix6/talonfx/TalonFXMotor.java b/src/main/java/org/trigon/hardware/phoenix6/talonfx/TalonFXMotor.java index 53b9d4c9..406604a1 100644 --- a/src/main/java/org/trigon/hardware/phoenix6/talonfx/TalonFXMotor.java +++ b/src/main/java/org/trigon/hardware/phoenix6/talonfx/TalonFXMotor.java @@ -13,9 +13,9 @@ /** * A class that represents a TalonFX motor controller. - * This class provides a structured interface to control and monitor Talon FX motors both in real-world deployment, and physics-based simulation. + * This class provides a structured interface to control and monitor TalonFX motors both in real-world deployment, and physics-based simulation. * It incorporates features for signal management, configuration handling, and threaded processing to ensure efficient and robust motor control - * It's incorporated with advantage kit logging. + * It's also fully integrated with AdvantageKit logging. */ public class TalonFXMotor { private final String motorName; @@ -71,6 +71,7 @@ public void setPhysicsSimulation(MotorPhysicsSimulation physicsSimulation) { /** * Applies both the real and simulation configurations to the motor. + * Having two different configurations allows for tuning motor behavior in simulation which might not perfectly mimic real life performance. * * @param realConfiguration configuration to be used in real life * @param simulationConfiguration configuration to be used in simulation @@ -93,6 +94,7 @@ public void applyConfiguration(TalonFXConfiguration simulationAndRealConfigurati /** * Applies the configuration to be used when {@link RobotHardwareStats#isSimulation()} is false. + * Having two different configurations allows for tuning motor behavior in simulation which might not perfectly mimic real life performance. * * @param realConfiguration the configuration */ @@ -103,6 +105,7 @@ public void applyRealConfiguration(TalonFXConfiguration realConfiguration) { /** * Applies the configuration to be used in simulation. + * Having two different configurations allows for tuning motor behavior in simulation which might not perfectly mimic real life performance. * * @param simulationConfiguration the configuration */ @@ -130,6 +133,7 @@ public double getSignal(TalonFXSignal signal) { /** * Gets a threaded signal from the motor. + * Threaded signals use threading to process certain signals separately, keeping them running smoothly in the background. * * @param signal the type of threaded signal to get * @return the signal @@ -152,6 +156,7 @@ public void registerSignal(TalonFXSignal signal, double updateFrequencyHertz) { * Registers a threaded signal to the motor. * Threaded signals use threading to process certain signals separately, keeping them running smoothly in the background. * This avoids slowing down the main program, unlike simpler signals that run directly in it. + * This is also used for signals that need to be updated more frequently like for odometry. * * @param signal the threaded signal to register * @param updateFrequencyHertz The frequency at which the threaded signal will be updated diff --git a/src/main/java/org/trigon/hardware/rev/spark/SparkInputs.java b/src/main/java/org/trigon/hardware/rev/spark/SparkInputs.java index 0c080530..c0e9a895 100644 --- a/src/main/java/org/trigon/hardware/rev/spark/SparkInputs.java +++ b/src/main/java/org/trigon/hardware/rev/spark/SparkInputs.java @@ -13,6 +13,11 @@ public class SparkInputs extends BaseInputs { private final SparkSignalThread signalThread = SparkSignalThread.getInstance(); private SparkStatusSignal[] signals = new SparkStatusSignal[0]; + /** + * Creates a new SparkInputs instance. + * + * @param name the name of the instance + */ public SparkInputs(String name) { super(name); } @@ -28,6 +33,11 @@ public void toLog(LogTable table) { latestTable = table; } + /** + * Registers a signal. + * + * @param statusSignal the signal to register + */ public void registerSignal(SparkStatusSignal statusSignal) { if (statusSignal == null || RobotHardwareStats.isReplay()) return; @@ -35,6 +45,12 @@ public void registerSignal(SparkStatusSignal statusSignal) { addSignalToSignalsArray(statusSignal); } + /** + * Registers a threaded signal. + * Threaded signals use threading to process certain signals separately, keeping them running smoothly in the background. + * + * @param statusSignal the threaded signal to register + */ public void registerThreadedSignal(SparkStatusSignal statusSignal) { if (statusSignal == null || RobotHardwareStats.isReplay()) return; diff --git a/src/main/java/org/trigon/hardware/simulation/FlywheelSimulation.java b/src/main/java/org/trigon/hardware/simulation/FlywheelSimulation.java deleted file mode 100644 index cc8a2188..00000000 --- a/src/main/java/org/trigon/hardware/simulation/FlywheelSimulation.java +++ /dev/null @@ -1,89 +0,0 @@ -package org.trigon.hardware.simulation; - -import edu.wpi.first.math.system.plant.DCMotor; -import edu.wpi.first.math.system.plant.LinearSystemId; -import edu.wpi.first.math.util.Units; -import edu.wpi.first.wpilibj.simulation.FlywheelSim; -import org.trigon.hardware.RobotHardwareStats; - -/** - * A class the represents a simulation of a flywheel mechanism. - */ -public class FlywheelSimulation extends MotorPhysicsSimulation { - private final FlywheelSim flywheelSimulation; - private double lastPositionRadians = 0; - - /** - * Creates a new FlywheelSimulation. - * - * @param gearbox the motor(s) used to control the flywheel - * @param gearRatio the gearbox's gear ratio - * @param kv voltage needed to maintain constant velocity - * @param ka voltage needed to induce a specific acceleration - */ - public FlywheelSimulation(DCMotor gearbox, double gearRatio, double kv, double ka) { - super(gearRatio); - flywheelSimulation = new FlywheelSim(LinearSystemId.identifyVelocitySystem(kv, ka), gearbox, gearRatio); - } - - /** - * Creates a new FlywheelSimulation. - * - * @param gearbox the motor used to control the flywheel - * @param gearRatio the gearbox's gear ratio - * @param momentOfInertia the flywheel's moment of inertia - */ - public FlywheelSimulation(DCMotor gearbox, double gearRatio, double momentOfInertia) { - super(gearRatio); - flywheelSimulation = new FlywheelSim(LinearSystemId.createFlywheelSystem(gearbox, momentOfInertia, gearRatio), gearbox, gearRatio); - } - - /** - * Gets the current draw of the flywheel in amperes. - * - * @return the current in amperes - */ - @Override - public double getCurrent() { - return flywheelSimulation.getCurrentDrawAmps(); - } - - /** - * Gets the position of the flywheel in rotations. - * - * @return The position in rotations - */ - @Override - public double getSystemPositionRotations() { - return Units.radiansToRotations(lastPositionRadians); - } - - /** - * Gets the velocity of the flywheel in rotations per second. - * - * @return The velocity in rotations per second - */ - @Override - public double getSystemVelocityRotationsPerSecond() { - return Units.radiansToRotations(flywheelSimulation.getAngularVelocityRadPerSec()); - } - - /** - * Sets the input voltage of the flywheel. - * - * @param voltage The input voltage - */ - @Override - public void setInputVoltage(double voltage) { - flywheelSimulation.setInputVoltage(voltage); - } - - /** - * Updates the flywheel simulation. - */ - @Override - public void updateMotor() { - flywheelSimulation.update(RobotHardwareStats.getPeriodicTimeSeconds()); - lastPositionRadians = lastPositionRadians + flywheelSimulation.getAngularVelocityRadPerSec() * RobotHardwareStats.getPeriodicTimeSeconds(); - } -} From 93ca69c030bc75bb167710a07dc92691c1b5960d Mon Sep 17 00:00:00 2001 From: Nummun14 <142012009+Nummun14@users.noreply.github.com> Date: Thu, 28 Nov 2024 16:39:34 +0200 Subject: [PATCH 16/61] improve simplemotorsim jdoc --- .../org/trigon/hardware/simulation/SimpleMotorSimulation.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/org/trigon/hardware/simulation/SimpleMotorSimulation.java b/src/main/java/org/trigon/hardware/simulation/SimpleMotorSimulation.java index 9fe294b8..99628afb 100644 --- a/src/main/java/org/trigon/hardware/simulation/SimpleMotorSimulation.java +++ b/src/main/java/org/trigon/hardware/simulation/SimpleMotorSimulation.java @@ -7,7 +7,7 @@ import org.trigon.hardware.RobotHardwareStats; /** - * A class that represents a simulation of a simple motor mechanism. + * A class that represents a simulation of a simple motor mechanism, such as flywheels and turret mechanisms. */ public class SimpleMotorSimulation extends MotorPhysicsSimulation { private final DCMotorSim motorSimulation; From 19a0eec3a853ebcf837d521131f6a492a5354aa0 Mon Sep 17 00:00:00 2001 From: Nummun14 <142012009+Nummun14@users.noreply.github.com> Date: Thu, 28 Nov 2024 18:03:28 +0200 Subject: [PATCH 17/61] maybe improved spark sim logic --- .../talonfx/io/SimulationTalonFXIO.java | 2 +- .../trigon/hardware/rev/spark/SparkIO.java | 4 +++ .../trigon/hardware/rev/spark/SparkMotor.java | 19 +++++++----- .../rev/spark/io/SimulationSparkIO.java | 30 ++++++++++++------- 4 files changed, 35 insertions(+), 20 deletions(-) diff --git a/src/main/java/org/trigon/hardware/phoenix6/talonfx/io/SimulationTalonFXIO.java b/src/main/java/org/trigon/hardware/phoenix6/talonfx/io/SimulationTalonFXIO.java index d623f055..40cf98c2 100644 --- a/src/main/java/org/trigon/hardware/phoenix6/talonfx/io/SimulationTalonFXIO.java +++ b/src/main/java/org/trigon/hardware/phoenix6/talonfx/io/SimulationTalonFXIO.java @@ -70,4 +70,4 @@ public void setPhysicsSimulation(MotorPhysicsSimulation physicsSimulation) { public TalonFX getTalonFX() { return talonFX; } -} +} \ No newline at end of file diff --git a/src/main/java/org/trigon/hardware/rev/spark/SparkIO.java b/src/main/java/org/trigon/hardware/rev/spark/SparkIO.java index 58b8e110..f3b8dd5f 100644 --- a/src/main/java/org/trigon/hardware/rev/spark/SparkIO.java +++ b/src/main/java/org/trigon/hardware/rev/spark/SparkIO.java @@ -3,6 +3,7 @@ import com.revrobotics.spark.SparkBase; import com.revrobotics.spark.SparkClosedLoopController; import com.revrobotics.spark.config.SparkMaxConfig; +import edu.wpi.first.math.system.plant.DCMotor; import org.trigon.hardware.rev.sparkecnoder.SparkEncoder; public class SparkIO { @@ -33,6 +34,9 @@ public void setInverted(boolean inverted) { public void updateSimulation() { } + public void setSimulationGearbox(DCMotor gearbox) { + } + public SparkBase getMotor() { return null; } diff --git a/src/main/java/org/trigon/hardware/rev/spark/SparkMotor.java b/src/main/java/org/trigon/hardware/rev/spark/SparkMotor.java index f72dc471..db978539 100644 --- a/src/main/java/org/trigon/hardware/rev/spark/SparkMotor.java +++ b/src/main/java/org/trigon/hardware/rev/spark/SparkMotor.java @@ -21,16 +21,15 @@ public class SparkMotor { /** * Creates a new Spark motor. * - * @param id the motor's ID - * @param sparkType the type of Spark motor - * @param motorName the name of the motor - * @param simulationMotor the motor to be used in simulation + * @param id the motor's ID + * @param sparkType the type of Spark motor + * @param motorName the name of the motor */ - public SparkMotor(int id, SparkType sparkType, String motorName, DCMotor simulationMotor) { + public SparkMotor(int id, SparkType sparkType, String motorName) { this.id = id; this.motorName = motorName; motorInputs = new SparkInputs(motorName); - motorIO = createSparkIO(id, sparkType, simulationMotor); + motorIO = createSparkIO(id, sparkType); } /** @@ -183,11 +182,15 @@ public void updateSimulation() { motorIO.updateSimulation(); } - private SparkIO createSparkIO(int id, SparkType sparkType, DCMotor simulationMotor) { + public void setSimulationGearbox(DCMotor gearbox) { + motorIO.setSimulationGearbox(gearbox); + } + + private SparkIO createSparkIO(int id, SparkType sparkType) { if (RobotHardwareStats.isReplay()) return new SparkIO(); if (RobotHardwareStats.isSimulation()) - return new SimulationSparkIO(id, simulationMotor); + return new SimulationSparkIO(id); return new RealSparkIO(id, sparkType); } } \ No newline at end of file diff --git a/src/main/java/org/trigon/hardware/rev/spark/io/SimulationSparkIO.java b/src/main/java/org/trigon/hardware/rev/spark/io/SimulationSparkIO.java index 329e64cd..1ecbb446 100644 --- a/src/main/java/org/trigon/hardware/rev/spark/io/SimulationSparkIO.java +++ b/src/main/java/org/trigon/hardware/rev/spark/io/SimulationSparkIO.java @@ -14,23 +14,22 @@ public class SimulationSparkIO extends SparkIO { private final SparkMax motor; private final SparkClosedLoopController pidController; private final SparkEncoder encoder; - private final SparkSim simulation; + private SparkSim simulation; - public SimulationSparkIO(int id, DCMotor gearbox) { + public SimulationSparkIO(int id) { motor = new SparkMax(id, SparkMax.MotorType.kBrushless); - simulation = new SparkSim(motor, gearbox); pidController = motor.getClosedLoopController(); encoder = SparkEncoder.createRelativeEncoder(motor); } @Override - public void setReference(double value, SparkBase.ControlType ctrl) { - pidController.setReference(value, ctrl); + public void setReference(double value, SparkBase.ControlType controlType) { + pidController.setReference(value, controlType); } @Override - public void setReference(double value, SparkBase.ControlType ctrl, int pidSlot) { - pidController.setReference(value, ctrl, pidSlot); + public void setReference(double value, SparkBase.ControlType controlType, int pidSlot) { + pidController.setReference(value, controlType, pidSlot); } @Override @@ -54,13 +53,13 @@ public void setPeriodicFrameTimeout(int periodMs) { } @Override - public void setReference(double value, SparkBase.ControlType ctrl, int pidSlot, double arbFeedForward) { - pidController.setReference(value, ctrl, pidSlot, arbFeedForward); + public void setReference(double value, SparkBase.ControlType controlType, int pidSlot, double arbFeedForward) { + pidController.setReference(value, controlType, pidSlot, arbFeedForward); } @Override - public void setReference(double value, SparkBase.ControlType ctrl, int pidSlot, double arbFeedForward, SparkClosedLoopController.ArbFFUnits arbFFUnits) { - pidController.setReference(value, ctrl, pidSlot, arbFeedForward, arbFFUnits); + public void setReference(double value, SparkBase.ControlType controlType, int pidSlot, double arbFeedForward, SparkClosedLoopController.ArbFFUnits arbFFUnits) { + pidController.setReference(value, controlType, pidSlot, arbFeedForward, arbFFUnits); } @Override @@ -70,11 +69,20 @@ public void setInverted(boolean inverted) { @Override public void updateSimulation() { + if (simulation == null) + return; simulation.iterate(motor.getAbsoluteEncoder().getVelocity(), motor.getBusVoltage(), Timer.getFPGATimestamp()); + simulation.setAppliedOutput(motor.getAppliedOutput()); + simulation.setMotorCurrent(motor.getOutputCurrent()); } @Override public void configure(SparkMaxConfig configuration, SparkBase.ResetMode resetMode, SparkBase.PersistMode persistMode) { motor.configure(configuration, resetMode, persistMode); } + + @Override + public void setSimulationGearbox(DCMotor gearbox) { + simulation = new SparkSim(motor, gearbox); + } } \ No newline at end of file From e7cd066f8b55f297dc88781e9772834396e027c8 Mon Sep 17 00:00:00 2001 From: Nummun14 <142012009+Nummun14@users.noreply.github.com> Date: Thu, 28 Nov 2024 18:10:39 +0200 Subject: [PATCH 18/61] made config better --- src/main/java/org/trigon/hardware/rev/spark/SparkIO.java | 4 ++-- src/main/java/org/trigon/hardware/rev/spark/SparkMotor.java | 4 ++-- .../java/org/trigon/hardware/rev/spark/io/RealSparkIO.java | 4 ++-- .../org/trigon/hardware/rev/spark/io/SimulationSparkIO.java | 4 ++-- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/main/java/org/trigon/hardware/rev/spark/SparkIO.java b/src/main/java/org/trigon/hardware/rev/spark/SparkIO.java index f3b8dd5f..0f1d25a0 100644 --- a/src/main/java/org/trigon/hardware/rev/spark/SparkIO.java +++ b/src/main/java/org/trigon/hardware/rev/spark/SparkIO.java @@ -2,7 +2,7 @@ import com.revrobotics.spark.SparkBase; import com.revrobotics.spark.SparkClosedLoopController; -import com.revrobotics.spark.config.SparkMaxConfig; +import com.revrobotics.spark.config.SparkBaseConfig; import edu.wpi.first.math.system.plant.DCMotor; import org.trigon.hardware.rev.sparkecnoder.SparkEncoder; @@ -25,7 +25,7 @@ public void setPeriodicFrameTimeout(int periodMs) { public void stopMotor() { } - public void configure(SparkMaxConfig configuration, SparkBase.ResetMode resetMode, SparkBase.PersistMode persistMode) { + public void configure(SparkBaseConfig configuration, SparkBase.ResetMode resetMode, SparkBase.PersistMode persistMode) { } public void setInverted(boolean inverted) { diff --git a/src/main/java/org/trigon/hardware/rev/spark/SparkMotor.java b/src/main/java/org/trigon/hardware/rev/spark/SparkMotor.java index db978539..9eba1fda 100644 --- a/src/main/java/org/trigon/hardware/rev/spark/SparkMotor.java +++ b/src/main/java/org/trigon/hardware/rev/spark/SparkMotor.java @@ -2,7 +2,7 @@ import com.revrobotics.spark.SparkBase; import com.revrobotics.spark.SparkClosedLoopController; -import com.revrobotics.spark.config.SparkMaxConfig; +import com.revrobotics.spark.config.SparkBaseConfig; import edu.wpi.first.math.system.plant.DCMotor; import org.littletonrobotics.junction.Logger; import org.trigon.hardware.RobotHardwareStats; @@ -171,7 +171,7 @@ public void setInverted(boolean inverted) { * @param resetMode whether to reset safe parameters before setting the configuration or not * @param persistMode whether to persist the parameters after setting the configuration or not */ - public void configure(SparkMaxConfig configuration, SparkBase.ResetMode resetMode, SparkBase.PersistMode persistMode) { + public void configure(SparkBaseConfig configuration, SparkBase.ResetMode resetMode, SparkBase.PersistMode persistMode) { motorIO.configure(configuration, resetMode, persistMode); } diff --git a/src/main/java/org/trigon/hardware/rev/spark/io/RealSparkIO.java b/src/main/java/org/trigon/hardware/rev/spark/io/RealSparkIO.java index 7f8fd5c2..17806838 100644 --- a/src/main/java/org/trigon/hardware/rev/spark/io/RealSparkIO.java +++ b/src/main/java/org/trigon/hardware/rev/spark/io/RealSparkIO.java @@ -2,7 +2,7 @@ import com.revrobotics.spark.SparkBase; import com.revrobotics.spark.SparkClosedLoopController; -import com.revrobotics.spark.config.SparkMaxConfig; +import com.revrobotics.spark.config.SparkBaseConfig; import org.trigon.hardware.rev.spark.SparkIO; import org.trigon.hardware.rev.spark.SparkType; import org.trigon.hardware.rev.sparkecnoder.SparkEncoder; @@ -59,7 +59,7 @@ public void setReference(double value, SparkBase.ControlType ctrl, int pidSlot, } @Override - public void configure(SparkMaxConfig configuration, SparkBase.ResetMode resetMode, SparkBase.PersistMode persistMode) { + public void configure(SparkBaseConfig configuration, SparkBase.ResetMode resetMode, SparkBase.PersistMode persistMode) { motor.configure(configuration, resetMode, persistMode); } diff --git a/src/main/java/org/trigon/hardware/rev/spark/io/SimulationSparkIO.java b/src/main/java/org/trigon/hardware/rev/spark/io/SimulationSparkIO.java index 1ecbb446..d039df47 100644 --- a/src/main/java/org/trigon/hardware/rev/spark/io/SimulationSparkIO.java +++ b/src/main/java/org/trigon/hardware/rev/spark/io/SimulationSparkIO.java @@ -4,7 +4,7 @@ import com.revrobotics.spark.SparkClosedLoopController; import com.revrobotics.spark.SparkMax; import com.revrobotics.spark.SparkSim; -import com.revrobotics.spark.config.SparkMaxConfig; +import com.revrobotics.spark.config.SparkBaseConfig; import edu.wpi.first.math.system.plant.DCMotor; import edu.wpi.first.wpilibj.Timer; import org.trigon.hardware.rev.spark.SparkIO; @@ -77,7 +77,7 @@ public void updateSimulation() { } @Override - public void configure(SparkMaxConfig configuration, SparkBase.ResetMode resetMode, SparkBase.PersistMode persistMode) { + public void configure(SparkBaseConfig configuration, SparkBase.ResetMode resetMode, SparkBase.PersistMode persistMode) { motor.configure(configuration, resetMode, persistMode); } From b56e3a7deec755d99d92ad9d6e5fc3755d1fc699 Mon Sep 17 00:00:00 2001 From: Nummun14 <142012009+Nummun14@users.noreply.github.com> Date: Thu, 28 Nov 2024 19:08:00 +0200 Subject: [PATCH 19/61] jdocs and sim logic --- .../org/trigon/hardware/SignalThreadBase.java | 6 ++--- .../phoenix6/talonfx/TalonFXMotor.java | 5 ++-- .../trigon/hardware/rev/spark/SparkMotor.java | 5 ---- .../rev/spark/io/SimulationSparkIO.java | 6 ++--- .../sparkecnoder/AbsoluteSparkEncoder.java | 6 ++--- .../sparkecnoder/RelativeSparkEncoder.java | 6 ++--- .../rev/sparkecnoder/SparkEncoder.java | 6 +++++ .../simulation/ElevatorSimulation.java | 14 +++------- .../hardware/simulation/GyroSimulation.java | 6 ++--- .../simulation/SimpleMotorSimulation.java | 26 ++++++++++++------- .../SingleJointedArmSimulation.java | 14 +++------- 11 files changed, 46 insertions(+), 54 deletions(-) diff --git a/src/main/java/org/trigon/hardware/SignalThreadBase.java b/src/main/java/org/trigon/hardware/SignalThreadBase.java index 80fb236f..445069de 100644 --- a/src/main/java/org/trigon/hardware/SignalThreadBase.java +++ b/src/main/java/org/trigon/hardware/SignalThreadBase.java @@ -21,7 +21,7 @@ public class SignalThreadBase extends Thread { /** * Creates a new SignalThreadBase. * - * @param name The name of the thread + * @param name the name of the thread */ public SignalThreadBase(String name) { this.name = name; @@ -51,9 +51,9 @@ public void updateLatestTimestamps() { } /** - * Gets the latest timestamps when events signals were updated. + * Gets the latest timestamps when signals were updated. * - * @return The latest timestamps + * @return the latest timestamps */ public double[] getLatestTimestamps() { return threadInputs.timestamps; diff --git a/src/main/java/org/trigon/hardware/phoenix6/talonfx/TalonFXMotor.java b/src/main/java/org/trigon/hardware/phoenix6/talonfx/TalonFXMotor.java index 406604a1..1343f912 100644 --- a/src/main/java/org/trigon/hardware/phoenix6/talonfx/TalonFXMotor.java +++ b/src/main/java/org/trigon/hardware/phoenix6/talonfx/TalonFXMotor.java @@ -52,7 +52,8 @@ public TalonFXMotor(int id, String motorName, String canbus) { * Updates the motor and logs its inputs. */ public void update() { - motorIO.updateMotor(); + if (RobotHardwareStats.isSimulation()) + motorIO.updateMotor(); Logger.processInputs("Motors/" + motorName, motorInputs); } @@ -159,7 +160,7 @@ public void registerSignal(TalonFXSignal signal, double updateFrequencyHertz) { * This is also used for signals that need to be updated more frequently like for odometry. * * @param signal the threaded signal to register - * @param updateFrequencyHertz The frequency at which the threaded signal will be updated + * @param updateFrequencyHertz the frequency at which the threaded signal will be updated */ public void registerThreadedSignal(TalonFXSignal signal, double updateFrequencyHertz) { motorInputs.registerThreadedSignal(motorSignalToStatusSignal(signal), updateFrequencyHertz); diff --git a/src/main/java/org/trigon/hardware/rev/spark/SparkMotor.java b/src/main/java/org/trigon/hardware/rev/spark/SparkMotor.java index 9eba1fda..26cb1d43 100644 --- a/src/main/java/org/trigon/hardware/rev/spark/SparkMotor.java +++ b/src/main/java/org/trigon/hardware/rev/spark/SparkMotor.java @@ -39,11 +39,6 @@ public void update() { Logger.processInputs("Motors/" + motorName, motorInputs); } - /** - * Gets the ID of the motor. - * - * @return the ID - */ public int getID() { return id; } diff --git a/src/main/java/org/trigon/hardware/rev/spark/io/SimulationSparkIO.java b/src/main/java/org/trigon/hardware/rev/spark/io/SimulationSparkIO.java index d039df47..e8c02898 100644 --- a/src/main/java/org/trigon/hardware/rev/spark/io/SimulationSparkIO.java +++ b/src/main/java/org/trigon/hardware/rev/spark/io/SimulationSparkIO.java @@ -6,7 +6,7 @@ import com.revrobotics.spark.SparkSim; import com.revrobotics.spark.config.SparkBaseConfig; import edu.wpi.first.math.system.plant.DCMotor; -import edu.wpi.first.wpilibj.Timer; +import org.trigon.hardware.RobotHardwareStats; import org.trigon.hardware.rev.spark.SparkIO; import org.trigon.hardware.rev.sparkecnoder.SparkEncoder; @@ -71,9 +71,7 @@ public void setInverted(boolean inverted) { public void updateSimulation() { if (simulation == null) return; - simulation.iterate(motor.getAbsoluteEncoder().getVelocity(), motor.getBusVoltage(), Timer.getFPGATimestamp()); - simulation.setAppliedOutput(motor.getAppliedOutput()); - simulation.setMotorCurrent(motor.getOutputCurrent()); + simulation.iterate(motor.getAbsoluteEncoder().getVelocity(), motor.getBusVoltage(), RobotHardwareStats.getPeriodicTimeSeconds()); } @Override diff --git a/src/main/java/org/trigon/hardware/rev/sparkecnoder/AbsoluteSparkEncoder.java b/src/main/java/org/trigon/hardware/rev/sparkecnoder/AbsoluteSparkEncoder.java index 0167f679..d59ce03a 100644 --- a/src/main/java/org/trigon/hardware/rev/sparkecnoder/AbsoluteSparkEncoder.java +++ b/src/main/java/org/trigon/hardware/rev/sparkecnoder/AbsoluteSparkEncoder.java @@ -11,7 +11,7 @@ public class AbsoluteSparkEncoder extends SparkEncoder { /** * Creates a new AbsoluteSparkEncoder. * - * @param encoder The SparkAbsoluteEncoder to use. + * @param encoder the SparkAbsoluteEncoder to use. */ public AbsoluteSparkEncoder(SparkAbsoluteEncoder encoder) { this.encoder = encoder; @@ -20,7 +20,7 @@ public AbsoluteSparkEncoder(SparkAbsoluteEncoder encoder) { /** * Gets the position of the encoder in rotations. * - * @return The position of the encoder in rotations. + * @return the position of the encoder in rotations. */ public double getPositionRotations() { return encoder.getPosition(); @@ -29,7 +29,7 @@ public double getPositionRotations() { /** * Gets the velocity of the encoder in rotations per second. * - * @return The velocity of the encoder in rotations per second. + * @return the velocity of the encoder in rotations per second. */ public double getVelocityRotationsPerSecond() { return encoder.getVelocity(); diff --git a/src/main/java/org/trigon/hardware/rev/sparkecnoder/RelativeSparkEncoder.java b/src/main/java/org/trigon/hardware/rev/sparkecnoder/RelativeSparkEncoder.java index 21be7b2c..d129458d 100644 --- a/src/main/java/org/trigon/hardware/rev/sparkecnoder/RelativeSparkEncoder.java +++ b/src/main/java/org/trigon/hardware/rev/sparkecnoder/RelativeSparkEncoder.java @@ -11,7 +11,7 @@ public class RelativeSparkEncoder extends SparkEncoder { /** * Creates a new RelativeSparkEncoder. * - * @param encoder The RelativeEncoder to use. + * @param encoder the RelativeEncoder to use. */ public RelativeSparkEncoder(RelativeEncoder encoder) { this.encoder = encoder; @@ -20,7 +20,7 @@ public RelativeSparkEncoder(RelativeEncoder encoder) { /** * Gets the position of the encoder in rotations. * - * @return The position of the encoder in rotations. + * @return the position of the encoder in rotations. */ public double getPositionRotations() { return encoder.getPosition(); @@ -29,7 +29,7 @@ public double getPositionRotations() { /** * Gets the velocity of the encoder in rotations per second. * - * @return The velocity of the encoder in rotations per second. + * @return the velocity of the encoder in rotations per second. */ public double getVelocityRotationsPerSecond() { return encoder.getVelocity(); diff --git a/src/main/java/org/trigon/hardware/rev/sparkecnoder/SparkEncoder.java b/src/main/java/org/trigon/hardware/rev/sparkecnoder/SparkEncoder.java index a63c4f99..5d49aa12 100644 --- a/src/main/java/org/trigon/hardware/rev/sparkecnoder/SparkEncoder.java +++ b/src/main/java/org/trigon/hardware/rev/sparkecnoder/SparkEncoder.java @@ -4,6 +4,12 @@ import com.revrobotics.spark.SparkBase; public abstract class SparkEncoder { + /** + * Creates a new Spark encoder. + * + * @param spark the Spark motor + * @return the Spark encoder + */ public static SparkEncoder createEncoder(SparkBase spark) { final SparkAbsoluteEncoder absoluteEncoder = spark.getAbsoluteEncoder(); if (absoluteEncoder != null) diff --git a/src/main/java/org/trigon/hardware/simulation/ElevatorSimulation.java b/src/main/java/org/trigon/hardware/simulation/ElevatorSimulation.java index 9068df7c..993bb9ca 100644 --- a/src/main/java/org/trigon/hardware/simulation/ElevatorSimulation.java +++ b/src/main/java/org/trigon/hardware/simulation/ElevatorSimulation.java @@ -41,9 +41,7 @@ public ElevatorSimulation(DCMotor gearbox, double gearRatio, double carriageMass } /** - * Gets the current draw of the elevator in amperes. - * - * @return The current in amperes + * @return the current in amperes */ @Override public double getCurrent() { @@ -51,9 +49,7 @@ public double getCurrent() { } /** - * Gets the position of the elevator in meters. - * - * @return The position in meters + * @return the position in meters */ @Override public double getSystemPositionRotations() { @@ -61,9 +57,7 @@ public double getSystemPositionRotations() { } /** - * Gets the velocity of the elevator in meters per second. - * - * @return The velocity in meters per second + * @return the velocity in meters per second */ @Override public double getSystemVelocityRotationsPerSecond() { @@ -73,7 +67,7 @@ public double getSystemVelocityRotationsPerSecond() { /** * Sets the input voltage of the elevator. * - * @param voltage The voltage to set + * @param voltage the voltage to set */ @Override public void setInputVoltage(double voltage) { diff --git a/src/main/java/org/trigon/hardware/simulation/GyroSimulation.java b/src/main/java/org/trigon/hardware/simulation/GyroSimulation.java index c3bc2c66..021cfd21 100644 --- a/src/main/java/org/trigon/hardware/simulation/GyroSimulation.java +++ b/src/main/java/org/trigon/hardware/simulation/GyroSimulation.java @@ -9,9 +9,7 @@ public class GyroSimulation { private double simulationRadians = 0; /** - * Gets the yaw of the gyro in degrees. - * - * @return The yaw in degrees + * @return the yaw in degrees */ public double getGyroYawDegrees() { return Math.toDegrees(simulationRadians); @@ -30,7 +28,7 @@ public void update(double omegaRadiansPerSecond, double timeSeconds) { /** * Sets the yaw of the gyro. * - * @param heading The yaw to set + * @param heading the yaw to set */ public void setYaw(Rotation2d heading) { simulationRadians = heading.getRadians(); diff --git a/src/main/java/org/trigon/hardware/simulation/SimpleMotorSimulation.java b/src/main/java/org/trigon/hardware/simulation/SimpleMotorSimulation.java index 99628afb..7e91c446 100644 --- a/src/main/java/org/trigon/hardware/simulation/SimpleMotorSimulation.java +++ b/src/main/java/org/trigon/hardware/simulation/SimpleMotorSimulation.java @@ -12,6 +12,18 @@ public class SimpleMotorSimulation extends MotorPhysicsSimulation { private final DCMotorSim motorSimulation; + /** + * Creates a new SimpleMotorSimulation. + * + * @param gearbox the gearbox of the motor(s) + * @param gearRatio the gearbox's gear ratio + * @param momentOfInertia the moment of inertia of the motor(s) + */ + public SimpleMotorSimulation(DCMotor gearbox, double gearRatio, double momentOfInertia) { + super(gearRatio); + motorSimulation = new DCMotorSim(LinearSystemId.createDCMotorSystem(gearbox, momentOfInertia, gearRatio), gearbox); + } + /** * Creates a new SimpleMotorSimulation. * @@ -26,9 +38,7 @@ public SimpleMotorSimulation(DCMotor gearbox, double gearRatio, double kv, doubl } /** - * Gets the current draw of the motor in amperes. - * - * @return The current in amperes + * @return the current in amperes */ @Override public double getCurrent() { @@ -36,9 +46,7 @@ public double getCurrent() { } /** - * Gets the position of the motor in rotations. - * - * @return The position in rotations + * @return the position in rotations */ @Override public double getSystemPositionRotations() { @@ -46,9 +54,7 @@ public double getSystemPositionRotations() { } /** - * Gets the velocity of the motor in rotations per second. - * - * @return The velocity in rotations per second + * @return the velocity in rotations per second */ @Override public double getSystemVelocityRotationsPerSecond() { @@ -58,7 +64,7 @@ public double getSystemVelocityRotationsPerSecond() { /** * Sets the input voltage of the motor. * - * @param voltage The voltage to set + * @param voltage the voltage to set */ @Override public void setInputVoltage(double voltage) { diff --git a/src/main/java/org/trigon/hardware/simulation/SingleJointedArmSimulation.java b/src/main/java/org/trigon/hardware/simulation/SingleJointedArmSimulation.java index a611de22..48847b65 100644 --- a/src/main/java/org/trigon/hardware/simulation/SingleJointedArmSimulation.java +++ b/src/main/java/org/trigon/hardware/simulation/SingleJointedArmSimulation.java @@ -38,9 +38,7 @@ public SingleJointedArmSimulation(DCMotor gearbox, double gearRatio, double armL } /** - * Gets the current draw of the arm in amperes. - * - * @return The current in amperes + * @return the current in amperes */ @Override public double getCurrent() { @@ -48,9 +46,7 @@ public double getCurrent() { } /** - * Gets the position of the arm in rotations. - * - * @return The position in rotations + * @return the position in rotations */ @Override public double getSystemPositionRotations() { @@ -58,9 +54,7 @@ public double getSystemPositionRotations() { } /** - * Gets the velocity of the arm in rotations per second. - * - * @return The velocity in rotations per second + * @return the velocity in rotations per second */ @Override public double getSystemVelocityRotationsPerSecond() { @@ -70,7 +64,7 @@ public double getSystemVelocityRotationsPerSecond() { /** * Sets the input voltage of the arm. * - * @param voltage The voltage to set + * @param voltage the voltage to set */ @Override public void setInputVoltage(double voltage) { From 2fcaf24a56643d91cb77e577128e9ee9f9e07b00 Mon Sep 17 00:00:00 2001 From: Nummun14 <142012009+Nummun14@users.noreply.github.com> Date: Thu, 28 Nov 2024 20:37:40 +0200 Subject: [PATCH 20/61] improve mechanism constructers --- .../trigon/hardware/rev/spark/io/SimulationSparkIO.java | 2 +- .../utilities/mechanisms/ArmElevatorMechanism2d.java | 5 +++-- .../mechanisms/DoubleJointedArmMechanism2d.java | 9 +++++---- .../trigon/utilities/mechanisms/ElevatorMechanism2d.java | 5 +++-- .../mechanisms/SingleJointedArmMechanism2d.java | 7 ++++--- 5 files changed, 16 insertions(+), 12 deletions(-) diff --git a/src/main/java/org/trigon/hardware/rev/spark/io/SimulationSparkIO.java b/src/main/java/org/trigon/hardware/rev/spark/io/SimulationSparkIO.java index e8c02898..1d35572c 100644 --- a/src/main/java/org/trigon/hardware/rev/spark/io/SimulationSparkIO.java +++ b/src/main/java/org/trigon/hardware/rev/spark/io/SimulationSparkIO.java @@ -71,7 +71,7 @@ public void setInverted(boolean inverted) { public void updateSimulation() { if (simulation == null) return; - simulation.iterate(motor.getAbsoluteEncoder().getVelocity(), motor.getBusVoltage(), RobotHardwareStats.getPeriodicTimeSeconds()); + simulation.iterate(motor.getAbsoluteEncoder().getVelocity(), 12, RobotHardwareStats.getPeriodicTimeSeconds()); } @Override diff --git a/src/main/java/org/trigon/utilities/mechanisms/ArmElevatorMechanism2d.java b/src/main/java/org/trigon/utilities/mechanisms/ArmElevatorMechanism2d.java index b15e57fb..ce050f9d 100644 --- a/src/main/java/org/trigon/utilities/mechanisms/ArmElevatorMechanism2d.java +++ b/src/main/java/org/trigon/utilities/mechanisms/ArmElevatorMechanism2d.java @@ -4,6 +4,7 @@ import edu.wpi.first.wpilibj.smartdashboard.Mechanism2d; import edu.wpi.first.wpilibj.smartdashboard.MechanismLigament2d; import edu.wpi.first.wpilibj.smartdashboard.MechanismRoot2d; +import edu.wpi.first.wpilibj.util.Color; import edu.wpi.first.wpilibj.util.Color8Bit; import org.littletonrobotics.junction.Logger; @@ -26,12 +27,12 @@ public class ArmElevatorMechanism2d { * @param minimumLength the minimum length of the elevator * @param mechanismColor the color of the mechanism */ - public ArmElevatorMechanism2d(String name, double maximumLength, double minimumLength, Color8Bit mechanismColor) { + public ArmElevatorMechanism2d(String name, double maximumLength, double minimumLength, Color mechanismColor) { this.key = "Mechanisms/" + name; this.minimumLength = minimumLength; this.mechanism = new Mechanism2d(2 * maximumLength, 2 * maximumLength); final MechanismRoot2d root = mechanism.getRoot("Root", maximumLength, maximumLength); - this.currentPositionLigament = root.append(new MechanismLigament2d("ZCurrentPositionLigament", 0, 0, MechanismConstants.MECHANISM_LINE_WIDTH, mechanismColor)); + this.currentPositionLigament = root.append(new MechanismLigament2d("ZCurrentPositionLigament", 0, 0, MechanismConstants.MECHANISM_LINE_WIDTH, new Color8Bit(mechanismColor))); this.targetPositionLigament = root.append(new MechanismLigament2d("TargetPositionLigament", 0, 0, MechanismConstants.TARGET_ELEVATOR_POSITION_LIGAMENT_WIDTH, MechanismConstants.GRAY)); } diff --git a/src/main/java/org/trigon/utilities/mechanisms/DoubleJointedArmMechanism2d.java b/src/main/java/org/trigon/utilities/mechanisms/DoubleJointedArmMechanism2d.java index 005f9419..31965717 100644 --- a/src/main/java/org/trigon/utilities/mechanisms/DoubleJointedArmMechanism2d.java +++ b/src/main/java/org/trigon/utilities/mechanisms/DoubleJointedArmMechanism2d.java @@ -4,6 +4,7 @@ import edu.wpi.first.wpilibj.smartdashboard.Mechanism2d; import edu.wpi.first.wpilibj.smartdashboard.MechanismLigament2d; import edu.wpi.first.wpilibj.smartdashboard.MechanismRoot2d; +import edu.wpi.first.wpilibj.util.Color; import edu.wpi.first.wpilibj.util.Color8Bit; import org.littletonrobotics.junction.Logger; @@ -25,7 +26,7 @@ public class DoubleJointedArmMechanism2d { * @param key the key of the mechanism * @param mechanismColor the color of the mechanism */ - public DoubleJointedArmMechanism2d(String key, Color8Bit mechanismColor) { + public DoubleJointedArmMechanism2d(String key, Color mechanismColor) { this(key, MechanismConstants.MECHANISM_LINE_LENGTH, MechanismConstants.MECHANISM_LINE_LENGTH, mechanismColor); } @@ -37,14 +38,14 @@ public DoubleJointedArmMechanism2d(String key, Color8Bit mechanismColor) { * @param secondJointLength the length of the second joint * @param mechanismColor the color of the mechanism */ - public DoubleJointedArmMechanism2d(String name, double firstJointLength, double secondJointLength, Color8Bit mechanismColor) { + public DoubleJointedArmMechanism2d(String name, double firstJointLength, double secondJointLength, Color mechanismColor) { this.key = "Mechanisms/" + name; final double mechanismMiddle = MechanismConstants.LIGAMENT_END_TO_EDGE_RATIO * (firstJointLength + secondJointLength); this.mechanism = new Mechanism2d(2 * mechanismMiddle, 2 * mechanismMiddle); final MechanismRoot2d root = mechanism.getRoot("Root", mechanismMiddle, mechanismMiddle); - this.currentPositionFirstLigament = root.append(new MechanismLigament2d("ZCurrentPositionFirstLigament", firstJointLength, 0, MechanismConstants.MECHANISM_LINE_WIDTH, mechanismColor)); - this.currentPositionSecondLigament = currentPositionFirstLigament.append(new MechanismLigament2d("ZCurrentPositionSecondLigament", secondJointLength, 0, MechanismConstants.MECHANISM_LINE_WIDTH, mechanismColor)); + this.currentPositionFirstLigament = root.append(new MechanismLigament2d("ZCurrentPositionFirstLigament", firstJointLength, 0, MechanismConstants.MECHANISM_LINE_WIDTH, new Color8Bit(mechanismColor))); + this.currentPositionSecondLigament = currentPositionFirstLigament.append(new MechanismLigament2d("ZCurrentPositionSecondLigament", secondJointLength, 0, MechanismConstants.MECHANISM_LINE_WIDTH, new Color8Bit(mechanismColor))); this.targetPositionFirstLigament = root.append(new MechanismLigament2d("TargetPositionFirstLigament", firstJointLength, 0, MechanismConstants.MECHANISM_LINE_WIDTH, MechanismConstants.GRAY)); this.targetPositionSecondLigament = targetPositionFirstLigament.append(new MechanismLigament2d("TargetPositionSecondLigament", secondJointLength, 0, MechanismConstants.MECHANISM_LINE_WIDTH, MechanismConstants.GRAY)); } diff --git a/src/main/java/org/trigon/utilities/mechanisms/ElevatorMechanism2d.java b/src/main/java/org/trigon/utilities/mechanisms/ElevatorMechanism2d.java index ddce4aa3..2d157228 100644 --- a/src/main/java/org/trigon/utilities/mechanisms/ElevatorMechanism2d.java +++ b/src/main/java/org/trigon/utilities/mechanisms/ElevatorMechanism2d.java @@ -3,6 +3,7 @@ import edu.wpi.first.wpilibj.smartdashboard.Mechanism2d; import edu.wpi.first.wpilibj.smartdashboard.MechanismLigament2d; import edu.wpi.first.wpilibj.smartdashboard.MechanismRoot2d; +import edu.wpi.first.wpilibj.util.Color; import edu.wpi.first.wpilibj.util.Color8Bit; import org.littletonrobotics.junction.Logger; @@ -25,13 +26,13 @@ public class ElevatorMechanism2d { * @param minimumLength the minimum length of the elevator * @param mechanismColor the color of the mechanism */ - public ElevatorMechanism2d(String name, double maximumLength, double minimumLength, Color8Bit mechanismColor) { + public ElevatorMechanism2d(String name, double maximumLength, double minimumLength, Color mechanismColor) { this.key = "Mechanisms/" + name; this.minimumLength = minimumLength; this.mechanism = new Mechanism2d(maximumLength, maximumLength); final MechanismRoot2d currentPositionRoot = mechanism.getRoot("Root", 0.5 * maximumLength, 0); - this.currentPositionLigament = currentPositionRoot.append(new MechanismLigament2d("ZCurrentPositionLigament", minimumLength, MechanismConstants.ELEVATOR_MECHANISM_STARTING_ANGLE, MechanismConstants.MECHANISM_LINE_WIDTH, mechanismColor)); + this.currentPositionLigament = currentPositionRoot.append(new MechanismLigament2d("ZCurrentPositionLigament", minimumLength, MechanismConstants.ELEVATOR_MECHANISM_STARTING_ANGLE, MechanismConstants.MECHANISM_LINE_WIDTH, new Color8Bit(mechanismColor))); this.targetPositionLigament = currentPositionRoot.append(new MechanismLigament2d("TargetPositionLigament", minimumLength, MechanismConstants.ELEVATOR_MECHANISM_STARTING_ANGLE, MechanismConstants.TARGET_ELEVATOR_POSITION_LIGAMENT_WIDTH, MechanismConstants.GRAY)); } diff --git a/src/main/java/org/trigon/utilities/mechanisms/SingleJointedArmMechanism2d.java b/src/main/java/org/trigon/utilities/mechanisms/SingleJointedArmMechanism2d.java index 448c1897..05c2a4f3 100644 --- a/src/main/java/org/trigon/utilities/mechanisms/SingleJointedArmMechanism2d.java +++ b/src/main/java/org/trigon/utilities/mechanisms/SingleJointedArmMechanism2d.java @@ -4,6 +4,7 @@ import edu.wpi.first.wpilibj.smartdashboard.Mechanism2d; import edu.wpi.first.wpilibj.smartdashboard.MechanismLigament2d; import edu.wpi.first.wpilibj.smartdashboard.MechanismRoot2d; +import edu.wpi.first.wpilibj.util.Color; import edu.wpi.first.wpilibj.util.Color8Bit; import org.littletonrobotics.junction.Logger; @@ -23,7 +24,7 @@ public class SingleJointedArmMechanism2d { * @param key the key of the mechanism * @param mechanismColor the color of the mechanism */ - public SingleJointedArmMechanism2d(String key, Color8Bit mechanismColor) { + public SingleJointedArmMechanism2d(String key, Color mechanismColor) { this(key, MechanismConstants.MECHANISM_LINE_LENGTH, mechanismColor); } @@ -34,12 +35,12 @@ public SingleJointedArmMechanism2d(String key, Color8Bit mechanismColor) { * @param armLength the length of the arm * @param mechanismColor the color of the mechanism */ - public SingleJointedArmMechanism2d(String name, double armLength, Color8Bit mechanismColor) { + public SingleJointedArmMechanism2d(String name, double armLength, Color mechanismColor) { this.key = "Mechanisms/" + name; final double mechanismMiddle = MechanismConstants.LIGAMENT_END_TO_EDGE_RATIO * armLength; this.mechanism = new Mechanism2d(2 * mechanismMiddle, 2 * mechanismMiddle); final MechanismRoot2d root = mechanism.getRoot("Root", mechanismMiddle, mechanismMiddle); - this.currentPositionLigament = root.append(new MechanismLigament2d("ZCurrentPositionLigament", armLength, 0, MechanismConstants.MECHANISM_LINE_WIDTH, mechanismColor)); + this.currentPositionLigament = root.append(new MechanismLigament2d("ZCurrentPositionLigament", armLength, 0, MechanismConstants.MECHANISM_LINE_WIDTH, new Color8Bit(mechanismColor))); this.targetPositionLigament = root.append(new MechanismLigament2d("TargetPositionLigament", armLength, 0, MechanismConstants.MECHANISM_LINE_WIDTH, MechanismConstants.GRAY)); } From 602383be88b11b312414141f803f0b96eeb240d7 Mon Sep 17 00:00:00 2001 From: Nummun14 <142012009+Nummun14@users.noreply.github.com> Date: Thu, 28 Nov 2024 21:04:08 +0200 Subject: [PATCH 21/61] REVSucksConstants --- .../hardware/rev/spark/io/SimulationSparkIO.java | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/main/java/org/trigon/hardware/rev/spark/io/SimulationSparkIO.java b/src/main/java/org/trigon/hardware/rev/spark/io/SimulationSparkIO.java index 1d35572c..dee1fbf2 100644 --- a/src/main/java/org/trigon/hardware/rev/spark/io/SimulationSparkIO.java +++ b/src/main/java/org/trigon/hardware/rev/spark/io/SimulationSparkIO.java @@ -1,5 +1,6 @@ package org.trigon.hardware.rev.spark.io; +import com.revrobotics.sim.SparkAbsoluteEncoderSim; import com.revrobotics.spark.SparkBase; import com.revrobotics.spark.SparkClosedLoopController; import com.revrobotics.spark.SparkMax; @@ -14,12 +15,14 @@ public class SimulationSparkIO extends SparkIO { private final SparkMax motor; private final SparkClosedLoopController pidController; private final SparkEncoder encoder; - private SparkSim simulation; + private final SparkAbsoluteEncoderSim absoluteEncoderSimulation; + private SparkSim motorSimulation = null; public SimulationSparkIO(int id) { motor = new SparkMax(id, SparkMax.MotorType.kBrushless); pidController = motor.getClosedLoopController(); encoder = SparkEncoder.createRelativeEncoder(motor); + absoluteEncoderSimulation = new SparkAbsoluteEncoderSim(motor); } @Override @@ -69,9 +72,10 @@ public void setInverted(boolean inverted) { @Override public void updateSimulation() { - if (simulation == null) + if (motorSimulation == null) return; - simulation.iterate(motor.getAbsoluteEncoder().getVelocity(), 12, RobotHardwareStats.getPeriodicTimeSeconds()); + absoluteEncoderSimulation.iterate(encoder.getVelocityRotationsPerSecond(), RobotHardwareStats.getPeriodicTimeSeconds()); + motorSimulation.iterate(absoluteEncoderSimulation.getVelocity(), 12, RobotHardwareStats.getPeriodicTimeSeconds()); } @Override @@ -81,6 +85,6 @@ public void configure(SparkBaseConfig configuration, SparkBase.ResetMode resetMo @Override public void setSimulationGearbox(DCMotor gearbox) { - simulation = new SparkSim(motor, gearbox); + motorSimulation = new SparkSim(motor, gearbox); } } \ No newline at end of file From 320ebe2fd053921b268273d2a33f8250acab1ec1 Mon Sep 17 00:00:00 2001 From: Nummun14 <142012009+Nummun14@users.noreply.github.com> Date: Thu, 28 Nov 2024 21:17:28 +0200 Subject: [PATCH 22/61] spark sim still isn't working. (but I'm hoOolding on(epic is playing in the background))) --- .../java/org/trigon/hardware/rev/spark/SparkMotor.java | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/src/main/java/org/trigon/hardware/rev/spark/SparkMotor.java b/src/main/java/org/trigon/hardware/rev/spark/SparkMotor.java index 26cb1d43..62b5ba0e 100644 --- a/src/main/java/org/trigon/hardware/rev/spark/SparkMotor.java +++ b/src/main/java/org/trigon/hardware/rev/spark/SparkMotor.java @@ -37,6 +37,7 @@ public SparkMotor(int id, SparkType sparkType, String motorName) { */ public void update() { Logger.processInputs("Motors/" + motorName, motorInputs); + motorIO.updateSimulation(); } public int getID() { @@ -170,13 +171,6 @@ public void configure(SparkBaseConfig configuration, SparkBase.ResetMode resetMo motorIO.configure(configuration, resetMode, persistMode); } - /** - * Updates the motor simulation. Only used in simulation. Should be called periodically. - */ - public void updateSimulation() { - motorIO.updateSimulation(); - } - public void setSimulationGearbox(DCMotor gearbox) { motorIO.setSimulationGearbox(gearbox); } From f8971889480a60eae265d595bc86a63b2aca4462 Mon Sep 17 00:00:00 2001 From: Nummun14 <142012009+Nummun14@users.noreply.github.com> Date: Fri, 29 Nov 2024 14:22:46 +0200 Subject: [PATCH 23/61] javadocs suck, spit, stop, and setPosition --- .../java/org/trigon/hardware/BaseInputs.java | 6 ++-- .../trigon/hardware/RobotHardwareStats.java | 2 +- .../hardware/phoenix6/Phoenix6Inputs.java | 12 ++++--- .../phoenix6/Phoenix6SignalThread.java | 4 +-- .../phoenix6/talonfx/TalonFXMotor.java | 4 +-- .../trigon/hardware/rev/spark/SparkIO.java | 5 +-- .../hardware/rev/spark/SparkInputs.java | 4 +-- .../trigon/hardware/rev/spark/SparkMotor.java | 33 +++++++++---------- .../hardware/rev/spark/SparkSignalThread.java | 5 +-- .../hardware/rev/spark/io/RealSparkIO.java | 4 +-- .../rev/spark/io/SimulationSparkIO.java | 11 +++++-- .../rev/sparkecnoder/SparkEncoder.java | 2 +- .../org/trigon/utilities/Conversions.java | 6 ++-- 13 files changed, 53 insertions(+), 45 deletions(-) diff --git a/src/main/java/org/trigon/hardware/BaseInputs.java b/src/main/java/org/trigon/hardware/BaseInputs.java index ee2f5e98..28c32859 100644 --- a/src/main/java/org/trigon/hardware/BaseInputs.java +++ b/src/main/java/org/trigon/hardware/BaseInputs.java @@ -14,7 +14,7 @@ public abstract class BaseInputs implements LoggableInputs { /** * Creates a new BaseInputs instance. * - * @param name the name of the instance + * @param name the name of the instance. Used for error messages. */ public BaseInputs(String name) { this.name = name; @@ -26,7 +26,7 @@ public void fromLog(LogTable table) { } /** - * Gets a signal. + * Gets a signal from the inputs. * * @param signalName the name of the signal * @return the signal @@ -50,7 +50,7 @@ public double getSignal(String signalName) { /** * Gets a threaded signal. - * Threaded signals use threading to process certain signals separately, keeping them running smoothly in the background. + * Threaded signals use threading to process certain signals separately. Should be used for odometry and other fast signals. * * @param signalName the name of the threaded signal * @return the threaded signal diff --git a/src/main/java/org/trigon/hardware/RobotHardwareStats.java b/src/main/java/org/trigon/hardware/RobotHardwareStats.java index 508bfe9e..67bb1817 100644 --- a/src/main/java/org/trigon/hardware/RobotHardwareStats.java +++ b/src/main/java/org/trigon/hardware/RobotHardwareStats.java @@ -28,7 +28,7 @@ public static void setCurrentRobotStats(boolean isReal, ReplayType replayType) { } /** - * Sets how frequently the periodic method is called in seconds. Used for calling methods periodically. + * Sets how frequently the simulation is updated. * * @param periodicTimeSeconds the periodic time in seconds */ diff --git a/src/main/java/org/trigon/hardware/phoenix6/Phoenix6Inputs.java b/src/main/java/org/trigon/hardware/phoenix6/Phoenix6Inputs.java index 2b455dc6..15d31c26 100644 --- a/src/main/java/org/trigon/hardware/phoenix6/Phoenix6Inputs.java +++ b/src/main/java/org/trigon/hardware/phoenix6/Phoenix6Inputs.java @@ -38,16 +38,18 @@ public void toLog(LogTable table) { /** * Registers a threaded signal. * Threaded signals use threading to process certain signals separately, keeping them running smoothly in the background. + * This avoids slowing down the main program, unlike simpler signals that run directly in it. + * This is also used for signals that need to be updated at a high frequency like for odometry. * - * @param statusSignal the signal - * @param updateFrequencyHertz the update frequency in hertz + * @param statusSignal the threaded signal to register + * @param updateFrequencyHertz the frequency at which the threaded signal will be updated */ public void registerThreadedSignal(BaseStatusSignal statusSignal, double updateFrequencyHertz) { if (statusSignal == null || RobotHardwareStats.isReplay()) return; registerSignal(statusSignal, updateFrequencyHertz); - if (RobotHardwareStats.isSimulation()) + if (RobotHardwareStats.isSimulation()) // needed for simulation to work statusSignal.setUpdateFrequency(50); signalToThreadedQueue.put(statusSignal.getName() + "_Threaded", signalThread.registerSignal(statusSignal)); } @@ -55,8 +57,8 @@ public void registerThreadedSignal(BaseStatusSignal statusSignal, double updateF /** * Registers a signal. * - * @param statusSignal the signal - * @param updateFrequencyHertz the update frequency in hertz + * @param statusSignal the signal to register + * @param updateFrequencyHertz the frequency at which the signal will be updated */ public void registerSignal(BaseStatusSignal statusSignal, double updateFrequencyHertz) { if (statusSignal == null || RobotHardwareStats.isReplay()) diff --git a/src/main/java/org/trigon/hardware/phoenix6/Phoenix6SignalThread.java b/src/main/java/org/trigon/hardware/phoenix6/Phoenix6SignalThread.java index a8044f55..7e17e198 100644 --- a/src/main/java/org/trigon/hardware/phoenix6/Phoenix6SignalThread.java +++ b/src/main/java/org/trigon/hardware/phoenix6/Phoenix6SignalThread.java @@ -27,7 +27,7 @@ import java.util.concurrent.locks.ReentrantLock; /** - * Provides an interface for asynchronously reading high-frequency measurements to a set of queues for Phoenix 6. + * Provides an interface for asynchronously reading high-frequency measurements to a set of queues for Phoenix 6. Used for getting values from status signals. */ public class Phoenix6SignalThread extends SignalThreadBase { public static ReentrantLock SIGNALS_LOCK = new ReentrantLock(); @@ -52,7 +52,7 @@ private Phoenix6SignalThread() { } /** - * Registers a signal to be read asynchronously. + * Registers a status signal to be read. * * @param signal the signal to register * @return the queue that the signal's values will be written to diff --git a/src/main/java/org/trigon/hardware/phoenix6/talonfx/TalonFXMotor.java b/src/main/java/org/trigon/hardware/phoenix6/talonfx/TalonFXMotor.java index 1343f912..463e1195 100644 --- a/src/main/java/org/trigon/hardware/phoenix6/talonfx/TalonFXMotor.java +++ b/src/main/java/org/trigon/hardware/phoenix6/talonfx/TalonFXMotor.java @@ -134,7 +134,7 @@ public double getSignal(TalonFXSignal signal) { /** * Gets a threaded signal from the motor. - * Threaded signals use threading to process certain signals separately, keeping them running smoothly in the background. + * Threaded signals use threading to process certain signals separately. This is used for signals that need to be updated at a higher frequency such as odometry. * * @param signal the type of threaded signal to get * @return the signal @@ -157,7 +157,7 @@ public void registerSignal(TalonFXSignal signal, double updateFrequencyHertz) { * Registers a threaded signal to the motor. * Threaded signals use threading to process certain signals separately, keeping them running smoothly in the background. * This avoids slowing down the main program, unlike simpler signals that run directly in it. - * This is also used for signals that need to be updated more frequently like for odometry. + * This is also used for signals that need to be updated at a high frequency like for odometry. * * @param signal the threaded signal to register * @param updateFrequencyHertz the frequency at which the threaded signal will be updated diff --git a/src/main/java/org/trigon/hardware/rev/spark/SparkIO.java b/src/main/java/org/trigon/hardware/rev/spark/SparkIO.java index 0f1d25a0..16c78371 100644 --- a/src/main/java/org/trigon/hardware/rev/spark/SparkIO.java +++ b/src/main/java/org/trigon/hardware/rev/spark/SparkIO.java @@ -5,6 +5,7 @@ import com.revrobotics.spark.config.SparkBaseConfig; import edu.wpi.first.math.system.plant.DCMotor; import org.trigon.hardware.rev.sparkecnoder.SparkEncoder; +import org.trigon.hardware.simulation.MotorPhysicsSimulation; public class SparkIO { public void setReference(double value, SparkBase.ControlType ctrl) { @@ -19,7 +20,7 @@ public void setReference(double value, SparkBase.ControlType ctrl, int pidSlot, public void setReference(double value, SparkBase.ControlType ctrl, int pidSlot, double arbFeedForward, SparkClosedLoopController.ArbFFUnits arbFFUnits) { } - public void setPeriodicFrameTimeout(int periodMs) { + public void setPeriodicFrameTimeout(int timeoutMs) { } public void stopMotor() { @@ -34,7 +35,7 @@ public void setInverted(boolean inverted) { public void updateSimulation() { } - public void setSimulationGearbox(DCMotor gearbox) { + public void setPhysicsSimulation(MotorPhysicsSimulation physicsSimulation, DCMotor gearbox) { } public SparkBase getMotor() { diff --git a/src/main/java/org/trigon/hardware/rev/spark/SparkInputs.java b/src/main/java/org/trigon/hardware/rev/spark/SparkInputs.java index c0e9a895..d9020d86 100644 --- a/src/main/java/org/trigon/hardware/rev/spark/SparkInputs.java +++ b/src/main/java/org/trigon/hardware/rev/spark/SparkInputs.java @@ -47,7 +47,7 @@ public void registerSignal(SparkStatusSignal statusSignal) { /** * Registers a threaded signal. - * Threaded signals use threading to process certain signals separately, keeping them running smoothly in the background. + * Threaded signals use threading to process certain signals separately. Should be used for signals that need to be updated at a high frequency such as odometry. * * @param statusSignal the threaded signal to register */ @@ -56,7 +56,7 @@ public void registerThreadedSignal(SparkStatusSignal statusSignal) { return; registerSignal(statusSignal); - signalToThreadedQueue.put(statusSignal.getName() + "_Threaded", signalThread.registerSignal(statusSignal.getValueSupplier())); + signalToThreadedQueue.put(statusSignal.getName() + "_Threaded", signalThread.registerThreadedSignal(statusSignal.getValueSupplier())); } private void updateThreadedSignalsToTable(LogTable table) { diff --git a/src/main/java/org/trigon/hardware/rev/spark/SparkMotor.java b/src/main/java/org/trigon/hardware/rev/spark/SparkMotor.java index 62b5ba0e..6d1519e0 100644 --- a/src/main/java/org/trigon/hardware/rev/spark/SparkMotor.java +++ b/src/main/java/org/trigon/hardware/rev/spark/SparkMotor.java @@ -8,6 +8,7 @@ import org.trigon.hardware.RobotHardwareStats; import org.trigon.hardware.rev.spark.io.RealSparkIO; import org.trigon.hardware.rev.spark.io.SimulationSparkIO; +import org.trigon.hardware.simulation.MotorPhysicsSimulation; /** * A class the represents a Spark motor. Used to control and read data from a Spark motor. @@ -45,26 +46,23 @@ public int getID() { } /** - * Registers a signal to be logged from the motor. + * Registers a threaded signal to be logged from the motor. + * Threaded signals use threading to process certain signals separately. Should be used for signals that need to be updated at a high frequency such as odometry. * * @param signal the signal to be registered */ - public void registerSignal(SparkSignal signal) { - this.registerSignal(signal, false); + public void registerThreadedSignal(SparkSignal signal) { + final SparkStatusSignal statusSignal = signal.getStatusSignal(motorIO.getMotor(), motorIO.getEncoder()); + motorInputs.registerThreadedSignal(statusSignal); } /** * Registers a signal to be read from the motor. * - * @param signal the signal to be read - * @param isThreaded whether the signal should be read in a separate thread or not + * @param signal the signal to be read */ - public void registerSignal(SparkSignal signal, boolean isThreaded) { + public void registerSignal(SparkSignal signal) { final SparkStatusSignal statusSignal = signal.getStatusSignal(motorIO.getMotor(), motorIO.getEncoder()); - if (isThreaded) { - motorInputs.registerThreadedSignal(statusSignal); - return; - } motorInputs.registerSignal(statusSignal); } @@ -80,6 +78,7 @@ public double getSignal(SparkSignal signal) { /** * Gets a threaded signal from the motor. + * Threaded signals use threading to process certain signals separately. Should be used for signals that need to be updated at a high frequency such as odometry. * * @param signal the threaded signal to get * @return the threaded signal @@ -135,13 +134,13 @@ public void setReference(double value, SparkBase.ControlType controlType, int pi } /** - * Sets the transmission period for a specific periodic frame on the motor controller. - * This method adjusts the rate at which the controller sends the frame, but the change is not saved permanently and will reset on powerup. + * Set the amount of time to wait for a periodic status frame before returning a timeout error. + * This timeout will apply to all periodic status frames for the SPARK motor controller. * - * @param periodMs the new transmission period in milliseconds + * @param timeoutMs the new transmission period in milliseconds */ - public void setPeriodicFramePeriod(int periodMs) { - motorIO.setPeriodicFrameTimeout(periodMs); + public void setPeriodicFrameTimeout(int timeoutMs) { + motorIO.setPeriodicFrameTimeout(timeoutMs); } /** @@ -171,8 +170,8 @@ public void configure(SparkBaseConfig configuration, SparkBase.ResetMode resetMo motorIO.configure(configuration, resetMode, persistMode); } - public void setSimulationGearbox(DCMotor gearbox) { - motorIO.setSimulationGearbox(gearbox); + public void setPhysicsSimulation(MotorPhysicsSimulation physicsSimulation, DCMotor gearbox) { + motorIO.setPhysicsSimulation(physicsSimulation, gearbox); } private SparkIO createSparkIO(int id, SparkType sparkType) { diff --git a/src/main/java/org/trigon/hardware/rev/spark/SparkSignalThread.java b/src/main/java/org/trigon/hardware/rev/spark/SparkSignalThread.java index dc90bad0..c9bc2c16 100644 --- a/src/main/java/org/trigon/hardware/rev/spark/SparkSignalThread.java +++ b/src/main/java/org/trigon/hardware/rev/spark/SparkSignalThread.java @@ -51,12 +51,13 @@ private SparkSignalThread() { } /** - * Registers a signal to be read asynchronously. + * Registers a threaded signal to be read asynchronously. + * Threaded signals use threading to process certain signals separately. Should be used for signals that need to be updated at a high frequency such as odometry. * * @param signal the signal to register * @return the queue that the signal's values will be written to */ - public Queue registerSignal(DoubleSupplier signal) { + public Queue registerThreadedSignal(DoubleSupplier signal) { Queue queue = new ArrayBlockingQueue<>(100); SIGNALS_LOCK.lock(); try { diff --git a/src/main/java/org/trigon/hardware/rev/spark/io/RealSparkIO.java b/src/main/java/org/trigon/hardware/rev/spark/io/RealSparkIO.java index 17806838..b5087199 100644 --- a/src/main/java/org/trigon/hardware/rev/spark/io/RealSparkIO.java +++ b/src/main/java/org/trigon/hardware/rev/spark/io/RealSparkIO.java @@ -44,8 +44,8 @@ public void stopMotor() { } @Override - public void setPeriodicFrameTimeout(int periodMs) { - motor.setPeriodicFrameTimeout(periodMs); + public void setPeriodicFrameTimeout(int timeoutMs) { + motor.setPeriodicFrameTimeout(timeoutMs); } @Override diff --git a/src/main/java/org/trigon/hardware/rev/spark/io/SimulationSparkIO.java b/src/main/java/org/trigon/hardware/rev/spark/io/SimulationSparkIO.java index dee1fbf2..afe402f1 100644 --- a/src/main/java/org/trigon/hardware/rev/spark/io/SimulationSparkIO.java +++ b/src/main/java/org/trigon/hardware/rev/spark/io/SimulationSparkIO.java @@ -10,6 +10,7 @@ import org.trigon.hardware.RobotHardwareStats; import org.trigon.hardware.rev.spark.SparkIO; import org.trigon.hardware.rev.sparkecnoder.SparkEncoder; +import org.trigon.hardware.simulation.MotorPhysicsSimulation; public class SimulationSparkIO extends SparkIO { private final SparkMax motor; @@ -17,6 +18,7 @@ public class SimulationSparkIO extends SparkIO { private final SparkEncoder encoder; private final SparkAbsoluteEncoderSim absoluteEncoderSimulation; private SparkSim motorSimulation = null; + private MotorPhysicsSimulation physicsSimulation = null; public SimulationSparkIO(int id) { motor = new SparkMax(id, SparkMax.MotorType.kBrushless); @@ -51,8 +53,8 @@ public void stopMotor() { } @Override - public void setPeriodicFrameTimeout(int periodMs) { - motor.setPeriodicFrameTimeout(periodMs); + public void setPeriodicFrameTimeout(int timeoutMs) { + motor.setPeriodicFrameTimeout(timeoutMs); } @Override @@ -76,6 +78,8 @@ public void updateSimulation() { return; absoluteEncoderSimulation.iterate(encoder.getVelocityRotationsPerSecond(), RobotHardwareStats.getPeriodicTimeSeconds()); motorSimulation.iterate(absoluteEncoderSimulation.getVelocity(), 12, RobotHardwareStats.getPeriodicTimeSeconds()); + physicsSimulation.updateMotor(); + physicsSimulation.setInputVoltage(motorSimulation.getBusVoltage()); } @Override @@ -84,7 +88,8 @@ public void configure(SparkBaseConfig configuration, SparkBase.ResetMode resetMo } @Override - public void setSimulationGearbox(DCMotor gearbox) { + public void setPhysicsSimulation(MotorPhysicsSimulation physicsSimulation, DCMotor gearbox) { motorSimulation = new SparkSim(motor, gearbox); + this.physicsSimulation = physicsSimulation; } } \ No newline at end of file diff --git a/src/main/java/org/trigon/hardware/rev/sparkecnoder/SparkEncoder.java b/src/main/java/org/trigon/hardware/rev/sparkecnoder/SparkEncoder.java index 5d49aa12..b31bace2 100644 --- a/src/main/java/org/trigon/hardware/rev/sparkecnoder/SparkEncoder.java +++ b/src/main/java/org/trigon/hardware/rev/sparkecnoder/SparkEncoder.java @@ -5,7 +5,7 @@ public abstract class SparkEncoder { /** - * Creates a new Spark encoder. + * Creates a new Spark encoder. If the Spark motor has an absolute encoder, an AbsoluteSparkEncoder is created. Otherwise, a RelativeSparkEncoder is created. * * @param spark the Spark motor * @return the Spark encoder diff --git a/src/main/java/org/trigon/utilities/Conversions.java b/src/main/java/org/trigon/utilities/Conversions.java index c9e4e349..ffcb21f4 100644 --- a/src/main/java/org/trigon/utilities/Conversions.java +++ b/src/main/java/org/trigon/utilities/Conversions.java @@ -240,14 +240,14 @@ public static TrapezoidProfile.Constraints scaleConstraints(TrapezoidProfile.Con } /** - * Converts a string in SNAKE_CASE to camelCase. + * Converts a string from SNAKE_CASE to camelCase. * * @param input the string to convert * @return the string in camel case */ public static String snakeCaseToCamelCase(String input) { - String[] parts = input.split("_"); - StringBuilder camelCase = new StringBuilder(); + final String[] parts = input.split("_"); + final StringBuilder camelCase = new StringBuilder(); for (int i = 0; i < parts.length; i++) { String part = parts[i].toLowerCase(); From dd432bf08d7accdbe3f41c8eee3bdb40eb6f3d66 Mon Sep 17 00:00:00 2001 From: Yishai Levy <96019039+levyishai@users.noreply.github.com> Date: Fri, 29 Nov 2024 15:07:38 +0200 Subject: [PATCH 24/61] Removed annoying javadoc warnings --- build.gradle | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/build.gradle b/build.gradle index b502789b..f0c13a2d 100644 --- a/build.gradle +++ b/build.gradle @@ -1,5 +1,5 @@ plugins { - id "java" + id "java-library" id "maven-publish" id "edu.wpi.first.GradleRIO" version "2025.1.1-beta-1" id "edu.wpi.first.WpilibTools" version "2.1.0" @@ -51,6 +51,7 @@ wpi.java.configureTestTasks(test) // Configure string concat to always inline compile tasks.withType(JavaCompile) { options.compilerArgs.add '-XDstringConcat=inline' + javadoc.options.addStringOption('Xdoclint:none', '-quiet') } task sourcesJar(type: Jar, dependsOn: classes) { From df2019ad530e804e2ca3fbff06138e97028706ed Mon Sep 17 00:00:00 2001 From: Nummun14 <142012009+Nummun14@users.noreply.github.com> Date: Fri, 29 Nov 2024 16:09:49 +0200 Subject: [PATCH 25/61] threaded signal javadocs, and sim logic, will keep working on it later. Shabbat Shalom --- .../java/org/trigon/hardware/BaseInputs.java | 2 +- .../trigon/hardware/RobotHardwareStats.java | 1 + .../hardware/phoenix6/Phoenix6Inputs.java | 6 +- .../phoenix6/Phoenix6SignalThread.java | 2 +- .../phoenix6/talonfx/TalonFXMotor.java | 6 +- .../talonfx/io/SimulationTalonFXIO.java | 3 +- .../trigon/hardware/rev/spark/SparkIO.java | 6 +- .../hardware/rev/spark/SparkInputs.java | 2 +- .../trigon/hardware/rev/spark/SparkMotor.java | 64 +++++++++++++++++-- .../hardware/rev/spark/SparkSignalThread.java | 2 +- .../hardware/rev/spark/io/RealSparkIO.java | 8 +++ .../rev/spark/io/SimulationSparkIO.java | 21 +++--- .../simulation/ElevatorSimulation.java | 2 +- .../simulation/MotorPhysicsSimulation.java | 10 ++- .../simulation/SimpleMotorSimulation.java | 4 +- .../SingleJointedArmSimulation.java | 2 +- .../org/trigon/utilities/Conversions.java | 2 +- 17 files changed, 106 insertions(+), 37 deletions(-) diff --git a/src/main/java/org/trigon/hardware/BaseInputs.java b/src/main/java/org/trigon/hardware/BaseInputs.java index 28c32859..39faa89c 100644 --- a/src/main/java/org/trigon/hardware/BaseInputs.java +++ b/src/main/java/org/trigon/hardware/BaseInputs.java @@ -50,7 +50,7 @@ public double getSignal(String signalName) { /** * Gets a threaded signal. - * Threaded signals use threading to process certain signals separately. Should be used for odometry and other fast signals. + * Threaded signals use threading to process certain signals separately at a faster rate * * @param signalName the name of the threaded signal * @return the threaded signal diff --git a/src/main/java/org/trigon/hardware/RobotHardwareStats.java b/src/main/java/org/trigon/hardware/RobotHardwareStats.java index 67bb1817..12e6be74 100644 --- a/src/main/java/org/trigon/hardware/RobotHardwareStats.java +++ b/src/main/java/org/trigon/hardware/RobotHardwareStats.java @@ -4,6 +4,7 @@ * A class that contains stats about the robot's hardware. */ public class RobotHardwareStats { + public static final double SUPPLY_VOLTAGE = 12; private static boolean IS_SIMULATION = false; private static boolean IS_REPLAY = false; private static double PERIODIC_TIME_SECONDS = 0.02; diff --git a/src/main/java/org/trigon/hardware/phoenix6/Phoenix6Inputs.java b/src/main/java/org/trigon/hardware/phoenix6/Phoenix6Inputs.java index 15d31c26..354a2e37 100644 --- a/src/main/java/org/trigon/hardware/phoenix6/Phoenix6Inputs.java +++ b/src/main/java/org/trigon/hardware/phoenix6/Phoenix6Inputs.java @@ -37,9 +37,7 @@ public void toLog(LogTable table) { /** * Registers a threaded signal. - * Threaded signals use threading to process certain signals separately, keeping them running smoothly in the background. - * This avoids slowing down the main program, unlike simpler signals that run directly in it. - * This is also used for signals that need to be updated at a high frequency like for odometry. + * Threaded signals use threading to process certain signals separately at a faster rate. * * @param statusSignal the threaded signal to register * @param updateFrequencyHertz the frequency at which the threaded signal will be updated @@ -49,7 +47,7 @@ public void registerThreadedSignal(BaseStatusSignal statusSignal, double updateF return; registerSignal(statusSignal, updateFrequencyHertz); - if (RobotHardwareStats.isSimulation()) // needed for simulation to work + if (RobotHardwareStats.isSimulation()) // You can't run signals at a high frequency in simulation. A fast thread slows down the simulation. statusSignal.setUpdateFrequency(50); signalToThreadedQueue.put(statusSignal.getName() + "_Threaded", signalThread.registerSignal(statusSignal)); } diff --git a/src/main/java/org/trigon/hardware/phoenix6/Phoenix6SignalThread.java b/src/main/java/org/trigon/hardware/phoenix6/Phoenix6SignalThread.java index 7e17e198..148c6ab3 100644 --- a/src/main/java/org/trigon/hardware/phoenix6/Phoenix6SignalThread.java +++ b/src/main/java/org/trigon/hardware/phoenix6/Phoenix6SignalThread.java @@ -52,7 +52,7 @@ private Phoenix6SignalThread() { } /** - * Registers a status signal to be read. + * Registers a status signal to be read with a higher frequency. * * @param signal the signal to register * @return the queue that the signal's values will be written to diff --git a/src/main/java/org/trigon/hardware/phoenix6/talonfx/TalonFXMotor.java b/src/main/java/org/trigon/hardware/phoenix6/talonfx/TalonFXMotor.java index 463e1195..6514f3e3 100644 --- a/src/main/java/org/trigon/hardware/phoenix6/talonfx/TalonFXMotor.java +++ b/src/main/java/org/trigon/hardware/phoenix6/talonfx/TalonFXMotor.java @@ -134,7 +134,7 @@ public double getSignal(TalonFXSignal signal) { /** * Gets a threaded signal from the motor. - * Threaded signals use threading to process certain signals separately. This is used for signals that need to be updated at a higher frequency such as odometry. + * Threaded signals use threading to process certain signals separately at a faster rate. * * @param signal the type of threaded signal to get * @return the signal @@ -155,9 +155,7 @@ public void registerSignal(TalonFXSignal signal, double updateFrequencyHertz) { /** * Registers a threaded signal to the motor. - * Threaded signals use threading to process certain signals separately, keeping them running smoothly in the background. - * This avoids slowing down the main program, unlike simpler signals that run directly in it. - * This is also used for signals that need to be updated at a high frequency like for odometry. + * Threaded signals use threading to process certain signals separately at a faster rate. * * @param signal the threaded signal to register * @param updateFrequencyHertz the frequency at which the threaded signal will be updated diff --git a/src/main/java/org/trigon/hardware/phoenix6/talonfx/io/SimulationTalonFXIO.java b/src/main/java/org/trigon/hardware/phoenix6/talonfx/io/SimulationTalonFXIO.java index 40cf98c2..2729c0b0 100644 --- a/src/main/java/org/trigon/hardware/phoenix6/talonfx/io/SimulationTalonFXIO.java +++ b/src/main/java/org/trigon/hardware/phoenix6/talonfx/io/SimulationTalonFXIO.java @@ -6,6 +6,7 @@ import com.ctre.phoenix6.signals.FeedbackSensorSourceValue; import com.ctre.phoenix6.signals.InvertedValue; import com.ctre.phoenix6.sim.TalonFXSimState; +import org.trigon.hardware.RobotHardwareStats; import org.trigon.hardware.phoenix6.talonfx.TalonFXIO; import org.trigon.hardware.simulation.MotorPhysicsSimulation; @@ -17,7 +18,7 @@ public class SimulationTalonFXIO extends TalonFXIO { public SimulationTalonFXIO(int id) { this.talonFX = new TalonFX(id); this.motorSimState = talonFX.getSimState(); - motorSimState.setSupplyVoltage(12); + motorSimState.setSupplyVoltage(RobotHardwareStats.SUPPLY_VOLTAGE); } @Override diff --git a/src/main/java/org/trigon/hardware/rev/spark/SparkIO.java b/src/main/java/org/trigon/hardware/rev/spark/SparkIO.java index 16c78371..391f3b9f 100644 --- a/src/main/java/org/trigon/hardware/rev/spark/SparkIO.java +++ b/src/main/java/org/trigon/hardware/rev/spark/SparkIO.java @@ -3,7 +3,6 @@ import com.revrobotics.spark.SparkBase; import com.revrobotics.spark.SparkClosedLoopController; import com.revrobotics.spark.config.SparkBaseConfig; -import edu.wpi.first.math.system.plant.DCMotor; import org.trigon.hardware.rev.sparkecnoder.SparkEncoder; import org.trigon.hardware.simulation.MotorPhysicsSimulation; @@ -32,10 +31,13 @@ public void configure(SparkBaseConfig configuration, SparkBase.ResetMode resetMo public void setInverted(boolean inverted) { } + public void setBrake(boolean brake) { + } + public void updateSimulation() { } - public void setPhysicsSimulation(MotorPhysicsSimulation physicsSimulation, DCMotor gearbox) { + public void setPhysicsSimulation(MotorPhysicsSimulation physicsSimulation) { } public SparkBase getMotor() { diff --git a/src/main/java/org/trigon/hardware/rev/spark/SparkInputs.java b/src/main/java/org/trigon/hardware/rev/spark/SparkInputs.java index d9020d86..71bd87cf 100644 --- a/src/main/java/org/trigon/hardware/rev/spark/SparkInputs.java +++ b/src/main/java/org/trigon/hardware/rev/spark/SparkInputs.java @@ -47,7 +47,7 @@ public void registerSignal(SparkStatusSignal statusSignal) { /** * Registers a threaded signal. - * Threaded signals use threading to process certain signals separately. Should be used for signals that need to be updated at a high frequency such as odometry. + * Threaded signals use threading to process certain signals separately at a faster rate. * * @param statusSignal the threaded signal to register */ diff --git a/src/main/java/org/trigon/hardware/rev/spark/SparkMotor.java b/src/main/java/org/trigon/hardware/rev/spark/SparkMotor.java index 6d1519e0..704c3f85 100644 --- a/src/main/java/org/trigon/hardware/rev/spark/SparkMotor.java +++ b/src/main/java/org/trigon/hardware/rev/spark/SparkMotor.java @@ -3,7 +3,6 @@ import com.revrobotics.spark.SparkBase; import com.revrobotics.spark.SparkClosedLoopController; import com.revrobotics.spark.config.SparkBaseConfig; -import edu.wpi.first.math.system.plant.DCMotor; import org.littletonrobotics.junction.Logger; import org.trigon.hardware.RobotHardwareStats; import org.trigon.hardware.rev.spark.io.RealSparkIO; @@ -47,7 +46,7 @@ public int getID() { /** * Registers a threaded signal to be logged from the motor. - * Threaded signals use threading to process certain signals separately. Should be used for signals that need to be updated at a high frequency such as odometry. + * Threaded signals use threading to process certain signals separately at a faster rate. * * @param signal the signal to be registered */ @@ -78,7 +77,7 @@ public double getSignal(SparkSignal signal) { /** * Gets a threaded signal from the motor. - * Threaded signals use threading to process certain signals separately. Should be used for signals that need to be updated at a high frequency such as odometry. + * Threaded signals use threading to process certain signals separately at a faster rate. * * @param signal the threaded signal to get * @return the threaded signal @@ -160,18 +159,69 @@ public void setInverted(boolean inverted) { } /** - * Applies the configuration to the motor. + * Sets the motors neutral mode. + * + * @param brake true if the motor should brake, false if it should coast + */ + public void setBrake(boolean brake) { + motorIO.setBrake(brake); + } + + /** + * Applies both the real and simulation configurations to the motor. + * Having two different configurations allows for tuning motor behavior in simulation which might not perfectly mimic real life performance. + * + * @param realConfiguration configuration to be used in real life + * @param simulationConfiguration configuration to be used in simulation + * @param resetMode whether to reset safe parameters before setting the configuration or not + * @param persistMode whether to persist the parameters after setting the configuration or not + */ + public void applyConfigurations(SparkBaseConfig realConfiguration, SparkBaseConfig simulationConfiguration, SparkBase.ResetMode resetMode, SparkBase.PersistMode persistMode) { + if (RobotHardwareStats.isSimulation()) + motorIO.configure(simulationConfiguration, resetMode, persistMode); + else + motorIO.configure(realConfiguration, resetMode, persistMode); + } + + /** + * Applies the configuration to be used both in real life and in simulation. * * @param configuration the configuration to apply * @param resetMode whether to reset safe parameters before setting the configuration or not * @param persistMode whether to persist the parameters after setting the configuration or not */ - public void configure(SparkBaseConfig configuration, SparkBase.ResetMode resetMode, SparkBase.PersistMode persistMode) { + public void applyConfiguration(SparkBaseConfig configuration, SparkBase.ResetMode resetMode, SparkBase.PersistMode persistMode) { motorIO.configure(configuration, resetMode, persistMode); } - public void setPhysicsSimulation(MotorPhysicsSimulation physicsSimulation, DCMotor gearbox) { - motorIO.setPhysicsSimulation(physicsSimulation, gearbox); + /** + * Applies the configuration to be used when {@link RobotHardwareStats#isSimulation()} is false. + * Having two different configurations allows for tuning motor behavior in simulation which might not perfectly mimic real life performance. + * + * @param realConfiguration the configuration to apply + * @param resetMode whether to reset safe parameters before setting the configuration or not + * @param persistMode whether to persist the parameters after setting the configuration or not + */ + public void applyRealConfiguration(SparkBaseConfig realConfiguration, SparkBase.ResetMode resetMode, SparkBase.PersistMode persistMode) { + if (!RobotHardwareStats.isSimulation()) + motorIO.configure(realConfiguration, resetMode, persistMode); + } + + /** + * Applies the configuration to be used in simulation. + * Having two different configurations allows for tuning motor behavior in simulation which might not perfectly mimic real life performance. + * + * @param simulationConfiguration the configuration to apply + * @param resetMode whether to reset safe parameters before setting the configuration or not + * @param persistMode whether to persist the parameters after setting the configuration or not + */ + public void applySimulationConfiguration(SparkBaseConfig simulationConfiguration, SparkBase.ResetMode resetMode, SparkBase.PersistMode persistMode) { + if (RobotHardwareStats.isSimulation()) + motorIO.configure(simulationConfiguration, resetMode, persistMode); + } + + public void setPhysicsSimulation(MotorPhysicsSimulation physicsSimulation) { + motorIO.setPhysicsSimulation(physicsSimulation); } private SparkIO createSparkIO(int id, SparkType sparkType) { diff --git a/src/main/java/org/trigon/hardware/rev/spark/SparkSignalThread.java b/src/main/java/org/trigon/hardware/rev/spark/SparkSignalThread.java index c9bc2c16..2fe50e92 100644 --- a/src/main/java/org/trigon/hardware/rev/spark/SparkSignalThread.java +++ b/src/main/java/org/trigon/hardware/rev/spark/SparkSignalThread.java @@ -52,7 +52,7 @@ private SparkSignalThread() { /** * Registers a threaded signal to be read asynchronously. - * Threaded signals use threading to process certain signals separately. Should be used for signals that need to be updated at a high frequency such as odometry. + * Threaded signals use threading to process certain signals separately at a faster rate. * * @param signal the signal to register * @return the queue that the signal's values will be written to diff --git a/src/main/java/org/trigon/hardware/rev/spark/io/RealSparkIO.java b/src/main/java/org/trigon/hardware/rev/spark/io/RealSparkIO.java index b5087199..dd7eb66f 100644 --- a/src/main/java/org/trigon/hardware/rev/spark/io/RealSparkIO.java +++ b/src/main/java/org/trigon/hardware/rev/spark/io/RealSparkIO.java @@ -3,6 +3,7 @@ import com.revrobotics.spark.SparkBase; import com.revrobotics.spark.SparkClosedLoopController; import com.revrobotics.spark.config.SparkBaseConfig; +import com.revrobotics.spark.config.SparkMaxConfig; import org.trigon.hardware.rev.spark.SparkIO; import org.trigon.hardware.rev.spark.SparkType; import org.trigon.hardware.rev.sparkecnoder.SparkEncoder; @@ -67,4 +68,11 @@ public void configure(SparkBaseConfig configuration, SparkBase.ResetMode resetMo public void setInverted(boolean inverted) { motor.setInverted(inverted); } + + @Override + public void setBrake(boolean brake) { + SparkMaxConfig configuration = new SparkMaxConfig(); + configuration.idleMode(brake ? SparkMaxConfig.IdleMode.kBrake : SparkMaxConfig.IdleMode.kCoast); + motor.configure(configuration, SparkBase.ResetMode.kNoResetSafeParameters, SparkBase.PersistMode.kNoPersistParameters); + } } \ No newline at end of file diff --git a/src/main/java/org/trigon/hardware/rev/spark/io/SimulationSparkIO.java b/src/main/java/org/trigon/hardware/rev/spark/io/SimulationSparkIO.java index afe402f1..02c89195 100644 --- a/src/main/java/org/trigon/hardware/rev/spark/io/SimulationSparkIO.java +++ b/src/main/java/org/trigon/hardware/rev/spark/io/SimulationSparkIO.java @@ -1,12 +1,11 @@ package org.trigon.hardware.rev.spark.io; -import com.revrobotics.sim.SparkAbsoluteEncoderSim; import com.revrobotics.spark.SparkBase; import com.revrobotics.spark.SparkClosedLoopController; import com.revrobotics.spark.SparkMax; import com.revrobotics.spark.SparkSim; import com.revrobotics.spark.config.SparkBaseConfig; -import edu.wpi.first.math.system.plant.DCMotor; +import com.revrobotics.spark.config.SparkMaxConfig; import org.trigon.hardware.RobotHardwareStats; import org.trigon.hardware.rev.spark.SparkIO; import org.trigon.hardware.rev.sparkecnoder.SparkEncoder; @@ -16,7 +15,6 @@ public class SimulationSparkIO extends SparkIO { private final SparkMax motor; private final SparkClosedLoopController pidController; private final SparkEncoder encoder; - private final SparkAbsoluteEncoderSim absoluteEncoderSimulation; private SparkSim motorSimulation = null; private MotorPhysicsSimulation physicsSimulation = null; @@ -24,7 +22,6 @@ public SimulationSparkIO(int id) { motor = new SparkMax(id, SparkMax.MotorType.kBrushless); pidController = motor.getClosedLoopController(); encoder = SparkEncoder.createRelativeEncoder(motor); - absoluteEncoderSimulation = new SparkAbsoluteEncoderSim(motor); } @Override @@ -72,14 +69,20 @@ public void setInverted(boolean inverted) { motor.setInverted(inverted); } + @Override + public void setBrake(boolean brake) { + SparkMaxConfig configuration = new SparkMaxConfig(); + configuration.idleMode(brake ? SparkMaxConfig.IdleMode.kBrake : SparkMaxConfig.IdleMode.kCoast); + motor.configure(configuration, SparkBase.ResetMode.kNoResetSafeParameters, SparkBase.PersistMode.kNoPersistParameters); + } + @Override public void updateSimulation() { if (motorSimulation == null) return; - absoluteEncoderSimulation.iterate(encoder.getVelocityRotationsPerSecond(), RobotHardwareStats.getPeriodicTimeSeconds()); - motorSimulation.iterate(absoluteEncoderSimulation.getVelocity(), 12, RobotHardwareStats.getPeriodicTimeSeconds()); - physicsSimulation.updateMotor(); physicsSimulation.setInputVoltage(motorSimulation.getBusVoltage()); + physicsSimulation.updateMotor(); + motorSimulation.iterate(physicsSimulation.getSystemVelocityRotationsPerSecond(), RobotHardwareStats.SUPPLY_VOLTAGE, RobotHardwareStats.getPeriodicTimeSeconds()); } @Override @@ -88,8 +91,8 @@ public void configure(SparkBaseConfig configuration, SparkBase.ResetMode resetMo } @Override - public void setPhysicsSimulation(MotorPhysicsSimulation physicsSimulation, DCMotor gearbox) { - motorSimulation = new SparkSim(motor, gearbox); + public void setPhysicsSimulation(MotorPhysicsSimulation physicsSimulation) { + motorSimulation = new SparkSim(motor, physicsSimulation.getGearbox()); this.physicsSimulation = physicsSimulation; } } \ No newline at end of file diff --git a/src/main/java/org/trigon/hardware/simulation/ElevatorSimulation.java b/src/main/java/org/trigon/hardware/simulation/ElevatorSimulation.java index 993bb9ca..864dcf67 100644 --- a/src/main/java/org/trigon/hardware/simulation/ElevatorSimulation.java +++ b/src/main/java/org/trigon/hardware/simulation/ElevatorSimulation.java @@ -25,7 +25,7 @@ public class ElevatorSimulation extends MotorPhysicsSimulation { * @param simulateGravity a boolean indicating whether to simulate gravity */ public ElevatorSimulation(DCMotor gearbox, double gearRatio, double carriageMassKilograms, double drumRadiusMeters, double retractedHeightMeters, double maximumHeightMeters, boolean simulateGravity) { - super(gearRatio); + super(gearbox, gearRatio); diameterMeters = drumRadiusMeters + drumRadiusMeters; this.retractedHeightMeters = retractedHeightMeters; elevatorSimulation = new ElevatorSim( diff --git a/src/main/java/org/trigon/hardware/simulation/MotorPhysicsSimulation.java b/src/main/java/org/trigon/hardware/simulation/MotorPhysicsSimulation.java index ab661058..be484160 100644 --- a/src/main/java/org/trigon/hardware/simulation/MotorPhysicsSimulation.java +++ b/src/main/java/org/trigon/hardware/simulation/MotorPhysicsSimulation.java @@ -1,13 +1,17 @@ package org.trigon.hardware.simulation; +import edu.wpi.first.math.system.plant.DCMotor; + /** * An abstract class to simulate the physics of a motor. */ public abstract class MotorPhysicsSimulation { private final double gearRatio; + private final DCMotor gearbox; - MotorPhysicsSimulation(double gearRatio) { + MotorPhysicsSimulation(DCMotor gearbox, double gearRatio) { this.gearRatio = gearRatio; + this.gearbox = gearbox; } public double getRotorPositionRotations() { @@ -18,6 +22,10 @@ public double getRotorVelocityRotationsPerSecond() { return getSystemVelocityRotationsPerSecond() * gearRatio; } + public DCMotor getGearbox() { + return gearbox; + } + public abstract double getCurrent(); public abstract double getSystemPositionRotations(); diff --git a/src/main/java/org/trigon/hardware/simulation/SimpleMotorSimulation.java b/src/main/java/org/trigon/hardware/simulation/SimpleMotorSimulation.java index 7e91c446..cb564bab 100644 --- a/src/main/java/org/trigon/hardware/simulation/SimpleMotorSimulation.java +++ b/src/main/java/org/trigon/hardware/simulation/SimpleMotorSimulation.java @@ -20,7 +20,7 @@ public class SimpleMotorSimulation extends MotorPhysicsSimulation { * @param momentOfInertia the moment of inertia of the motor(s) */ public SimpleMotorSimulation(DCMotor gearbox, double gearRatio, double momentOfInertia) { - super(gearRatio); + super(gearbox, gearRatio); motorSimulation = new DCMotorSim(LinearSystemId.createDCMotorSystem(gearbox, momentOfInertia, gearRatio), gearbox); } @@ -33,7 +33,7 @@ public SimpleMotorSimulation(DCMotor gearbox, double gearRatio, double momentOfI * @param ka voltage needed to induce a specific acceleration */ public SimpleMotorSimulation(DCMotor gearbox, double gearRatio, double kv, double ka) { - super(gearRatio); + super(gearbox, gearRatio); motorSimulation = new DCMotorSim(LinearSystemId.createDCMotorSystem(kv, ka), gearbox); } diff --git a/src/main/java/org/trigon/hardware/simulation/SingleJointedArmSimulation.java b/src/main/java/org/trigon/hardware/simulation/SingleJointedArmSimulation.java index 48847b65..427605ee 100644 --- a/src/main/java/org/trigon/hardware/simulation/SingleJointedArmSimulation.java +++ b/src/main/java/org/trigon/hardware/simulation/SingleJointedArmSimulation.java @@ -24,7 +24,7 @@ public class SingleJointedArmSimulation extends MotorPhysicsSimulation { * @param simulateGravity whether to simulate gravity or not */ public SingleJointedArmSimulation(DCMotor gearbox, double gearRatio, double armLengthMeters, double armMassKilograms, Rotation2d minimumAngle, Rotation2d maximumAngle, boolean simulateGravity) { - super(gearRatio); + super(gearbox, gearRatio); armSimulation = new SingleJointedArmSim( gearbox, gearRatio, diff --git a/src/main/java/org/trigon/utilities/Conversions.java b/src/main/java/org/trigon/utilities/Conversions.java index ffcb21f4..9eef9f36 100644 --- a/src/main/java/org/trigon/utilities/Conversions.java +++ b/src/main/java/org/trigon/utilities/Conversions.java @@ -3,7 +3,7 @@ import edu.wpi.first.math.trajectory.TrapezoidProfile; /** - * A class that contains various methods for unit conversions. + * A class that contains various methods for unit and String conversions. */ public class Conversions { public static final double From c398a10e5837b9823aed3a5f99311cd291224933 Mon Sep 17 00:00:00 2001 From: Nummun14 <142012009+Nummun14@users.noreply.github.com> Date: Sat, 30 Nov 2024 19:12:27 +0200 Subject: [PATCH 26/61] imrproved spark encoder methods, and temporeraly removed mirroable bug fix --- .../org/trigon/hardware/rev/spark/SparkSignal.java | 4 ++-- .../rev/sparkecnoder/AbsoluteSparkEncoder.java | 12 ++++++------ .../rev/sparkecnoder/RelativeSparkEncoder.java | 14 +++++++------- .../hardware/rev/sparkecnoder/SparkEncoder.java | 4 ++-- .../trigon/utilities/mirrorable/Mirrorable.java | 2 +- 5 files changed, 18 insertions(+), 18 deletions(-) diff --git a/src/main/java/org/trigon/hardware/rev/spark/SparkSignal.java b/src/main/java/org/trigon/hardware/rev/spark/SparkSignal.java index 26084ba1..f2f1eda5 100644 --- a/src/main/java/org/trigon/hardware/rev/spark/SparkSignal.java +++ b/src/main/java/org/trigon/hardware/rev/spark/SparkSignal.java @@ -11,8 +11,8 @@ * An enum that represents the different signals that can be sent from a Spark motor. */ public enum SparkSignal { - POSITION(null, SparkEncoder::getPositionRotations), - VELOCITY(null, SparkEncoder::getVelocityRotationsPerSecond), + POSITION(null, SparkEncoder::getPosition), + VELOCITY(null, SparkEncoder::getVelocity), OUTPUT_CURRENT(SparkBase::getOutputCurrent, null), APPLIED_OUTPUT(SparkBase::getAppliedOutput, null), BUS_VOLTAGE(SparkBase::getBusVoltage, null); diff --git a/src/main/java/org/trigon/hardware/rev/sparkecnoder/AbsoluteSparkEncoder.java b/src/main/java/org/trigon/hardware/rev/sparkecnoder/AbsoluteSparkEncoder.java index d59ce03a..039fed3d 100644 --- a/src/main/java/org/trigon/hardware/rev/sparkecnoder/AbsoluteSparkEncoder.java +++ b/src/main/java/org/trigon/hardware/rev/sparkecnoder/AbsoluteSparkEncoder.java @@ -18,20 +18,20 @@ public AbsoluteSparkEncoder(SparkAbsoluteEncoder encoder) { } /** - * Gets the position of the encoder in rotations. + * Gets the position of the encoder in the unit set in the conversion factor. Rotations by default. * - * @return the position of the encoder in rotations. + * @return the position of the encoder */ - public double getPositionRotations() { + public double getPosition() { return encoder.getPosition(); } /** - * Gets the velocity of the encoder in rotations per second. + * Gets the position of the encoder in the unit set in the conversion factor. Rotations by default. * - * @return the velocity of the encoder in rotations per second. + * @return the position of the encoder */ - public double getVelocityRotationsPerSecond() { + public double getVelocity() { return encoder.getVelocity(); } } \ No newline at end of file diff --git a/src/main/java/org/trigon/hardware/rev/sparkecnoder/RelativeSparkEncoder.java b/src/main/java/org/trigon/hardware/rev/sparkecnoder/RelativeSparkEncoder.java index d129458d..8fbc99d3 100644 --- a/src/main/java/org/trigon/hardware/rev/sparkecnoder/RelativeSparkEncoder.java +++ b/src/main/java/org/trigon/hardware/rev/sparkecnoder/RelativeSparkEncoder.java @@ -11,27 +11,27 @@ public class RelativeSparkEncoder extends SparkEncoder { /** * Creates a new RelativeSparkEncoder. * - * @param encoder the RelativeEncoder to use. + * @param encoder the RelativeEncoder to use */ public RelativeSparkEncoder(RelativeEncoder encoder) { this.encoder = encoder; } /** - * Gets the position of the encoder in rotations. + * Gets the position of the encoder in the unit set in the conversion factor. Rotations by default. * - * @return the position of the encoder in rotations. + * @return the position of the encoder */ - public double getPositionRotations() { + public double getPosition() { return encoder.getPosition(); } /** - * Gets the velocity of the encoder in rotations per second. + * Gets the position of the encoder in the unit set in the conversion factor. Rotations by default. * - * @return the velocity of the encoder in rotations per second. + * @return the position of the encoder */ - public double getVelocityRotationsPerSecond() { + public double getVelocity() { return encoder.getVelocity(); } } \ No newline at end of file diff --git a/src/main/java/org/trigon/hardware/rev/sparkecnoder/SparkEncoder.java b/src/main/java/org/trigon/hardware/rev/sparkecnoder/SparkEncoder.java index b31bace2..4b586e72 100644 --- a/src/main/java/org/trigon/hardware/rev/sparkecnoder/SparkEncoder.java +++ b/src/main/java/org/trigon/hardware/rev/sparkecnoder/SparkEncoder.java @@ -22,7 +22,7 @@ public static SparkEncoder createRelativeEncoder(SparkBase spark) { return new RelativeSparkEncoder(spark.getEncoder()); } - public abstract double getPositionRotations(); + public abstract double getPosition(); - public abstract double getVelocityRotationsPerSecond(); + public abstract double getVelocity(); } \ No newline at end of file diff --git a/src/main/java/org/trigon/utilities/mirrorable/Mirrorable.java b/src/main/java/org/trigon/utilities/mirrorable/Mirrorable.java index 81b90348..dee73774 100644 --- a/src/main/java/org/trigon/utilities/mirrorable/Mirrorable.java +++ b/src/main/java/org/trigon/utilities/mirrorable/Mirrorable.java @@ -28,7 +28,7 @@ public abstract class Mirrorable { UPDATE_ALLIANCE_TIMER.start(); new Trigger(() -> UPDATE_ALLIANCE_TIMER.advanceIfElapsed(0.5)).onTrue( - new InstantCommand(() -> IS_RED_ALLIANCE = notCachedIsRedAlliance()).ignoringDisable(true) + new InstantCommand(() -> IS_RED_ALLIANCE = notCachedIsRedAlliance())//.ignoringDisable(true) ); } From d9213521a8236e3d7b805e967aa866639d318e64 Mon Sep 17 00:00:00 2001 From: Nummun14 <142012009+Nummun14@users.noreply.github.com> Date: Sat, 30 Nov 2024 19:43:56 +0200 Subject: [PATCH 27/61] added docs for cancoder and gyro, and cleaned up mirrorable --- .../phoenix6/cancoder/CANcoderEncoder.java | 89 +++++++++++++++++++ .../phoenix6/cancoder/CANcoderIO.java | 3 + .../phoenix6/cancoder/CANcoderSignal.java | 3 + .../phoenix6/cancoder/io/RealCANcoderIO.java | 5 ++ .../cancoder/io/SimulationCANcoderIO.java | 5 ++ .../phoenix6/pigeon2/Pigeon2Gyro.java | 24 +++++ .../utilities/mirrorable/Mirrorable.java | 20 ++++- 7 files changed, 145 insertions(+), 4 deletions(-) diff --git a/src/main/java/org/trigon/hardware/phoenix6/cancoder/CANcoderEncoder.java b/src/main/java/org/trigon/hardware/phoenix6/cancoder/CANcoderEncoder.java index 83e1d10d..248705ed 100644 --- a/src/main/java/org/trigon/hardware/phoenix6/cancoder/CANcoderEncoder.java +++ b/src/main/java/org/trigon/hardware/phoenix6/cancoder/CANcoderEncoder.java @@ -14,16 +14,32 @@ import java.util.function.DoubleSupplier; +/** + * A class that represents a CANcoder encoder. + */ public class CANcoderEncoder { private final String encoderName; private final CANcoderIO encoderIO; private final Phoenix6Inputs encoderInputs; private final int id; + /** + * Creates a new CANcoderEncoder. + * + * @param id the ID of the CANcoder + * @param encoderName the name of the encoder + */ public CANcoderEncoder(int id, String encoderName) { this(id, encoderName, ""); } + /** + * Creates a new CANcoderEncoder. + * + * @param id the ID of the CANcoder + * @param encoderName the name of the encoder + * @param canbus the canivore name + */ public CANcoderEncoder(int id, String encoderName, String canbus) { this.encoderName = encoderName; this.encoderIO = generateIO(id, canbus); @@ -32,6 +48,9 @@ public CANcoderEncoder(int id, String encoderName, String canbus) { encoderIO.optimizeBusUsage(); } + /** + * Updates the encoder and logs the inputs. Should be called periodically. + */ public void update() { encoderIO.updateEncoder(); Logger.processInputs("Encoders/" + encoderName, encoderInputs); @@ -41,14 +60,32 @@ public int getID() { return id; } + /** + * Sets the simulation inputs of the encoder from a TalonFX motor. + * + * @param motor the TalonFX motor to get the simulation inputs from + */ public void setSimulationInputsFromTalonFX(TalonFXMotor motor) { encoderIO.setSimulationInputSuppliers(() -> motor.getSignal(TalonFXSignal.POSITION), () -> motor.getSignal(TalonFXSignal.VELOCITY)); } + /** + * Sets the simulation inputs of the encoder from suppliers. + * + * @param positionSupplierRotations the supplier of the position in rotations + * @param velocitySupplierRotationsPerSecond the supplier of the velocity in rotations per second + */ public void setSimulationInputsSuppliers(DoubleSupplier positionSupplierRotations, DoubleSupplier velocitySupplierRotationsPerSecond) { encoderIO.setSimulationInputSuppliers(positionSupplierRotations, velocitySupplierRotationsPerSecond); } + /** + * Applies both the real and simulation configurations to the encoder. + * Having two different configurations allows for tuning encoder behavior in simulation which might not perfectly mimic real life performance. + * + * @param realConfiguration configuration to be used in real life + * @param simulationConfiguration configuration to be used in simulation + */ public void applyConfigurations(CANcoderConfiguration realConfiguration, CANcoderConfiguration simulationConfiguration) { if (RobotHardwareStats.isSimulation()) encoderIO.applyConfiguration(simulationConfiguration); @@ -56,36 +93,88 @@ public void applyConfigurations(CANcoderConfiguration realConfiguration, CANcode encoderIO.applyConfiguration(realConfiguration); } + /** + * Applies the configuration to be used both in real life and in simulation. + * + * @param simulationAndRealConfiguration the configuration + */ public void applyConfiguration(CANcoderConfiguration simulationAndRealConfiguration) { encoderIO.applyConfiguration(simulationAndRealConfiguration); } + /** + * Applies the configuration to be used when {@link RobotHardwareStats#isSimulation()} is false. + * Having two different configurations allows for tuning encoder behavior in simulation which might not perfectly mimic real life performance. + * + * @param realConfiguration the configuration + */ public void applyRealConfiguration(CANcoderConfiguration realConfiguration) { if (!RobotHardwareStats.isSimulation()) encoderIO.applyConfiguration(realConfiguration); } + /** + * Applies the configuration to be used in simulation. + * Having two different configurations allows for tuning encoder behavior in simulation which might not perfectly mimic real life performance. + * + * @param simulationConfiguration the configuration + */ public void applySimulationConfiguration(CANcoderConfiguration simulationConfiguration) { if (RobotHardwareStats.isSimulation()) encoderIO.applyConfiguration(simulationConfiguration); } + /** + * Gets the signal from the encoder. + * + * @param signal the type of signal to get + * @return the signal + */ public double getSignal(CANcoderSignal signal) { return encoderInputs.getSignal(signal.name); } + /** + * Gets the threaded signal from the encoder. + * Threaded signals use threading to process certain signals separately at a faster rate. + * + * @param signal the type of signal to get + * @return the threaded signal + */ public double[] getThreadedSignal(CANcoderSignal signal) { return encoderInputs.getThreadedSignal(signal.name); } + /** + * Registers a signal to be updated at a certain frequency. + * + * @param signal the signal to register + * @param updateFrequencyHertz the frequency at which the signal will be updated + */ public void registerSignal(CANcoderSignal signal, double updateFrequencyHertz) { encoderInputs.registerSignal(encoderSignalToStatusSignal(signal), updateFrequencyHertz); } + /** + * Registers a threaded signal to be updated at a certain frequency. + * Threaded signals use threading to process certain signals separately at a faster rate. + * + * @param signal the signal to register + * @param updateFrequencyHertz the frequency at which the signal will be updated + */ public void registerThreadedSignal(CANcoderSignal signal, double updateFrequencyHertz) { encoderInputs.registerThreadedSignal(encoderSignalToStatusSignal(signal), updateFrequencyHertz); } + /** + * Sets the current position of the encoder in rotations. + * + * @param positionRotations the position to be set in rotations + */ + public void setPosition(double positionRotations) { + encoderIO.setPosition(positionRotations); + } + private BaseStatusSignal encoderSignalToStatusSignal(CANcoderSignal signal) { final CANcoder cancoder = encoderIO.getCANcoder(); if (RobotHardwareStats.isReplay() || cancoder == null) diff --git a/src/main/java/org/trigon/hardware/phoenix6/cancoder/CANcoderIO.java b/src/main/java/org/trigon/hardware/phoenix6/cancoder/CANcoderIO.java index 015519f9..dd81561c 100644 --- a/src/main/java/org/trigon/hardware/phoenix6/cancoder/CANcoderIO.java +++ b/src/main/java/org/trigon/hardware/phoenix6/cancoder/CANcoderIO.java @@ -18,6 +18,9 @@ protected void optimizeBusUsage() { protected void setSimulationInputSuppliers(DoubleSupplier positionSupplierRotations, DoubleSupplier velocitySupplierRotationsPerSecond) { } + protected void setPosition(double positionRotations) { + } + protected CANcoder getCANcoder() { return null; } diff --git a/src/main/java/org/trigon/hardware/phoenix6/cancoder/CANcoderSignal.java b/src/main/java/org/trigon/hardware/phoenix6/cancoder/CANcoderSignal.java index 3ec7714c..df035ee7 100644 --- a/src/main/java/org/trigon/hardware/phoenix6/cancoder/CANcoderSignal.java +++ b/src/main/java/org/trigon/hardware/phoenix6/cancoder/CANcoderSignal.java @@ -6,6 +6,9 @@ import java.util.function.Function; +/** + * An enum that represents a signal that can be read from a CANcoder. + */ public enum CANcoderSignal { POSITION(CANcoder::getPosition), VELOCITY(CANcoder::getVelocity); diff --git a/src/main/java/org/trigon/hardware/phoenix6/cancoder/io/RealCANcoderIO.java b/src/main/java/org/trigon/hardware/phoenix6/cancoder/io/RealCANcoderIO.java index 85a79509..2d324b34 100644 --- a/src/main/java/org/trigon/hardware/phoenix6/cancoder/io/RealCANcoderIO.java +++ b/src/main/java/org/trigon/hardware/phoenix6/cancoder/io/RealCANcoderIO.java @@ -21,6 +21,11 @@ public void optimizeBusUsage() { cancoder.optimizeBusUtilization(); } + @Override + protected void setPosition(double positionRotations) { + cancoder.setPosition(positionRotations); + } + @Override public CANcoder getCANcoder() { return cancoder; diff --git a/src/main/java/org/trigon/hardware/phoenix6/cancoder/io/SimulationCANcoderIO.java b/src/main/java/org/trigon/hardware/phoenix6/cancoder/io/SimulationCANcoderIO.java index d0aac203..aa605ce9 100644 --- a/src/main/java/org/trigon/hardware/phoenix6/cancoder/io/SimulationCANcoderIO.java +++ b/src/main/java/org/trigon/hardware/phoenix6/cancoder/io/SimulationCANcoderIO.java @@ -43,6 +43,11 @@ public void optimizeBusUsage() { cancoder.optimizeBusUtilization(); } + @Override + protected void setPosition(double positionRotations) { + cancoder.setPosition(positionRotations); + } + @Override public CANcoder getCANcoder() { return cancoder; diff --git a/src/main/java/org/trigon/hardware/phoenix6/pigeon2/Pigeon2Gyro.java b/src/main/java/org/trigon/hardware/phoenix6/pigeon2/Pigeon2Gyro.java index c72a9f88..e35c630e 100644 --- a/src/main/java/org/trigon/hardware/phoenix6/pigeon2/Pigeon2Gyro.java +++ b/src/main/java/org/trigon/hardware/phoenix6/pigeon2/Pigeon2Gyro.java @@ -13,16 +13,32 @@ import java.util.function.DoubleSupplier; +/** + * A class that represents a Pigeon2 gyro. + */ public class Pigeon2Gyro { private final String gyroName; private final Pigeon2IO gyroIO; private final Phoenix6Inputs gyroInputs; private final int id; + /** + * Creates a new Pigeon2 gyro. + * + * @param id the gyro's ID + * @param gyroName the name of the gyro + */ public Pigeon2Gyro(int id, String gyroName) { this(id, gyroName, ""); } + /** + * Creates a new Pigeon2 gyro. + * + * @param id the gyro's ID + * @param gyroName the name of the gyro + * @param canbus the canivore's name + */ public Pigeon2Gyro(int id, String gyroName, String canbus) { this.gyroName = gyroName; this.gyroIO = generateIO(id, canbus); @@ -31,6 +47,9 @@ public Pigeon2Gyro(int id, String gyroName, String canbus) { gyroIO.optimizeBusUsage(); } + /** + * Updates the gyro and logs its inputs. Should be called periodically. + */ public void update() { gyroIO.updateGyro(); Logger.processInputs("Gyros/" + gyroName, gyroInputs); @@ -40,6 +59,11 @@ public int getID() { return id; } + /** + * Sets the yaw velocity supplier for simulation. + * + * @param yawVelocitySupplierDegreesPerSecond the yaw velocity supplier in degrees per second + */ public void setSimulationYawVelocitySupplier(DoubleSupplier yawVelocitySupplierDegreesPerSecond) { gyroIO.setSimulationYawVelocitySupplier(yawVelocitySupplierDegreesPerSecond); } diff --git a/src/main/java/org/trigon/utilities/mirrorable/Mirrorable.java b/src/main/java/org/trigon/utilities/mirrorable/Mirrorable.java index dee73774..515e1e60 100644 --- a/src/main/java/org/trigon/utilities/mirrorable/Mirrorable.java +++ b/src/main/java/org/trigon/utilities/mirrorable/Mirrorable.java @@ -3,6 +3,7 @@ import edu.wpi.first.math.geometry.Rotation2d; import edu.wpi.first.wpilibj.DriverStation; import edu.wpi.first.wpilibj.Timer; +import edu.wpi.first.wpilibj2.command.Command; import edu.wpi.first.wpilibj2.command.InstantCommand; import edu.wpi.first.wpilibj2.command.button.Trigger; @@ -26,10 +27,7 @@ public abstract class Mirrorable { static { UPDATE_ALLIANCE_TIMER.start(); - - new Trigger(() -> UPDATE_ALLIANCE_TIMER.advanceIfElapsed(0.5)).onTrue( - new InstantCommand(() -> IS_RED_ALLIANCE = notCachedIsRedAlliance())//.ignoringDisable(true) - ); + new Trigger(() -> UPDATE_ALLIANCE_TIMER.advanceIfElapsed(0.5)).onTrue(getUpdateAllianceCommand()); } /** @@ -44,6 +42,11 @@ protected Mirrorable(T nonMirroredObject, boolean shouldMirrorWhenRedAlliance) { this.shouldMirrorWhenRedAlliance = shouldMirrorWhenRedAlliance; } + public static void initializeMirrorable() { + UPDATE_ALLIANCE_TIMER.start(); + new Trigger(() -> UPDATE_ALLIANCE_TIMER.advanceIfElapsed(0.5)).onTrue(getUpdateAllianceCommand()); + } + /** * @return whether the robot is on the red alliance. This is cached every 0.5 seconds */ @@ -59,6 +62,15 @@ private static boolean notCachedIsRedAlliance() { return optionalAlliance.orElse(DriverStation.Alliance.Red).equals(DriverStation.Alliance.Red); } + /** + * Gets a command that updates the alliance. This is used to cache the alliance every 0.5 seconds. Ignoring disable is used to allow this command to run when the robot is disabled. + * + * @return the command + */ + private static Command getUpdateAllianceCommand() { + return new InstantCommand(() -> IS_RED_ALLIANCE = notCachedIsRedAlliance()).ignoringDisable(true); + } + /** * @return the current object. * If the robot is on the red alliance and the object should be mirrored, the mirrored object is returned. From 050783a2f22e22290213f15f867a036dd7a5881c Mon Sep 17 00:00:00 2001 From: Nummun14 <142012009+Nummun14@users.noreply.github.com> Date: Sat, 30 Nov 2024 20:01:37 +0200 Subject: [PATCH 28/61] corrected led naming --- .../misc/leds/AddressableLEDStrip.java | 8 ++++---- .../hardware/misc/leds/CANdleLEDStrip.java | 10 +++++----- .../trigon/hardware/misc/leds/LEDCommands.java | 18 +++++++++--------- .../rev/spark/io/SimulationSparkIO.java | 2 +- 4 files changed, 19 insertions(+), 19 deletions(-) diff --git a/src/main/java/org/trigon/hardware/misc/leds/AddressableLEDStrip.java b/src/main/java/org/trigon/hardware/misc/leds/AddressableLEDStrip.java index 0a0533f3..17b485f6 100644 --- a/src/main/java/org/trigon/hardware/misc/leds/AddressableLEDStrip.java +++ b/src/main/java/org/trigon/hardware/misc/leds/AddressableLEDStrip.java @@ -152,13 +152,13 @@ void rainbow(double brightness, double speed, boolean inverted) { @Override void sectionColor(Supplier[] colors) { final int amountOfSections = colors.length; - final int LEDsPerSection = (int) Math.floor(numberOfLEDs / amountOfSections); + final int ledsPerSection = (int) Math.floor(numberOfLEDs / amountOfSections); for (int i = 0; i < amountOfSections; i++) setLEDColors( inverted ? colors[amountOfSections - i - 1].get() : colors[i].get(), - LEDsPerSection * i, - i == amountOfSections - 1 ? numberOfLEDs - 1 : LEDsPerSection * (i + 1) - 1 + ledsPerSection * i, + i == amountOfSections - 1 ? numberOfLEDs - 1 : ledsPerSection * (i + 1) - 1 ); } @@ -186,7 +186,7 @@ private void setBreathingLEDs(Color color, int breathingLEDs, LarsonAnimation.Bo for (int i = 0; i < breathingLEDs; i++) { if (lastBreatheLED - i >= indexOffset && lastBreatheLED - i < indexOffset + numberOfLEDs) LED_BUFFER.setLED(lastBreatheLED - i, color); - + else if (lastBreatheLED - i < indexOffset + numberOfLEDs) { if (bounceMode.equals(LarsonAnimation.BounceMode.Back) || bounceMode.equals(LarsonAnimation.BounceMode.Center) && i > breathingLEDs / 2) return; diff --git a/src/main/java/org/trigon/hardware/misc/leds/CANdleLEDStrip.java b/src/main/java/org/trigon/hardware/misc/leds/CANdleLEDStrip.java index 1f3a6017..f6494bf9 100644 --- a/src/main/java/org/trigon/hardware/misc/leds/CANdleLEDStrip.java +++ b/src/main/java/org/trigon/hardware/misc/leds/CANdleLEDStrip.java @@ -140,19 +140,19 @@ void rainbow(double brightness, double speed, boolean inverted) { @Override void sectionColor(Supplier[] colors) { - final int LEDSPerSection = (int) Math.floor(numberOfLEDs / colors.length); - setSectionColor(colors.length, LEDSPerSection, colors); + final int ledsPerSection = (int) Math.floor(numberOfLEDs / colors.length); + setSectionColor(colors.length, ledsPerSection, colors); } - private void setSectionColor(int amountOfSections, int LEDSPerSection, Supplier[] colors) { + private void setSectionColor(int amountOfSections, int ledsPerSection, Supplier[] colors) { for (int i = 0; i < amountOfSections; i++) { CANDLE.setLEDs( (int) (inverted ? colors[amountOfSections - i - 1].get().red : colors[i].get().red), (int) (inverted ? colors[amountOfSections - i - 1].get().green : colors[i].get().green), (int) (inverted ? colors[amountOfSections - i - 1].get().blue : colors[i].get().blue), 0, - LEDSPerSection * i + indexOffset, - i == amountOfSections - 1 ? numberOfLEDs - 1 : LEDSPerSection * (i + 1) - 1 + ledsPerSection * i + indexOffset, + i == amountOfSections - 1 ? numberOfLEDs - 1 : ledsPerSection * (i + 1) - 1 ); } } diff --git a/src/main/java/org/trigon/hardware/misc/leds/LEDCommands.java b/src/main/java/org/trigon/hardware/misc/leds/LEDCommands.java index a798d404..9d7c2372 100644 --- a/src/main/java/org/trigon/hardware/misc/leds/LEDCommands.java +++ b/src/main/java/org/trigon/hardware/misc/leds/LEDCommands.java @@ -23,7 +23,7 @@ public static Command getStaticColorCommand(Color color, LEDStrip... ledStrips) return new StartEndCommand( () -> { runForLEDs((LEDStrip::clearLEDColors), ledStrips); - runForLEDs(LEDStrip -> LEDStrip.setCurrentAnimation(() -> LEDStrip.staticColor(color)), ledStrips); + runForLEDs(ledStrip -> ledStrip.setCurrentAnimation(() -> ledStrip.staticColor(color)), ledStrips); }, () -> runForLEDs(LEDStrip::clearLEDColors, ledStrips), ledStrips @@ -42,7 +42,7 @@ public static Command getBlinkingCommand(Color firstColor, double speed, LEDStri return new StartEndCommand( () -> { runForLEDs((LEDStrip::clearLEDColors), ledStrips); - runForLEDs(LEDStrip -> LEDStrip.setCurrentAnimation(() -> LEDStrip.blink(firstColor, speed)), ledStrips); + runForLEDs(ledStrip -> ledStrip.setCurrentAnimation(() -> ledStrip.blink(firstColor, speed)), ledStrips); }, () -> runForLEDs(LEDStrip::clearLEDColors, ledStrips), ledStrips @@ -64,7 +64,7 @@ public static Command getBreatheCommand(Color color, int amountOfBreathingLEDs, return new StartEndCommand( () -> { runForLEDs((LEDStrip::clearLEDColors), ledStrips); - runForLEDs(LEDStrip -> LEDStrip.setCurrentAnimation(() -> LEDStrip.breathe(color, amountOfBreathingLEDs, speed, inverted, bounceMode)), ledStrips); + runForLEDs(ledStrip -> ledStrip.setCurrentAnimation(() -> ledStrip.breathe(color, amountOfBreathingLEDs, speed, inverted, bounceMode)), ledStrips); }, () -> runForLEDs(LEDStrip::clearLEDColors, ledStrips), ledStrips @@ -84,7 +84,7 @@ public static Command getColorFlowCommand(Color color, double speed, boolean inv return new StartEndCommand( () -> { runForLEDs((LEDStrip::clearLEDColors), ledStrips); - runForLEDs(LEDStrip -> LEDStrip.setCurrentAnimation(() -> LEDStrip.colorFlow(color, speed, inverted)), ledStrips); + runForLEDs(ledStrip -> ledStrip.setCurrentAnimation(() -> ledStrip.colorFlow(color, speed, inverted)), ledStrips); }, () -> runForLEDs(LEDStrip::clearLEDColors, ledStrips), ledStrips @@ -103,7 +103,7 @@ public static Command getAlternateColorCommand(Color firstColor, Color secondCol return new StartEndCommand( () -> { runForLEDs((LEDStrip::clearLEDColors), ledStrips); - runForLEDs(LEDStrip -> LEDStrip.setCurrentAnimation(() -> LEDStrip.alternateColor(firstColor, secondColor)), ledStrips); + runForLEDs(ledStrip -> ledStrip.setCurrentAnimation(() -> ledStrip.alternateColor(firstColor, secondColor)), ledStrips); }, () -> runForLEDs(LEDStrip::clearLEDColors, ledStrips), ledStrips @@ -121,7 +121,7 @@ public static Command getSectionColorCommand(Supplier[] colors, LEDStrip. return new StartEndCommand( () -> { runForLEDs((LEDStrip::clearLEDColors), ledStrips); - runForLEDs(LEDStrip -> LEDStrip.setCurrentAnimation(() -> LEDStrip.sectionColor(colors)), ledStrips); + runForLEDs(ledStrip -> ledStrip.setCurrentAnimation(() -> ledStrip.sectionColor(colors)), ledStrips); }, () -> runForLEDs(LEDStrip::clearLEDColors, ledStrips), ledStrips @@ -141,7 +141,7 @@ public static Command getRainbowCommand(double brightness, double speed, boolean return new StartEndCommand( () -> { runForLEDs((LEDStrip::clearLEDColors), ledStrips); - runForLEDs(LEDStrip -> LEDStrip.setCurrentAnimation(() -> LEDStrip.rainbow(brightness, speed, inverted)), ledStrips); + runForLEDs(ledStrip -> ledStrip.setCurrentAnimation(() -> ledStrip.rainbow(brightness, speed, inverted)), ledStrips); }, () -> runForLEDs(LEDStrip::clearLEDColors, ledStrips), ledStrips @@ -149,7 +149,7 @@ public static Command getRainbowCommand(double brightness, double speed, boolean } private static void runForLEDs(Consumer action, LEDStrip... ledStrips) { - for (LEDStrip LEDStrip : ledStrips) - action.accept(LEDStrip); + for (LEDStrip ledStrip : ledStrips) + action.accept(ledStrip); } } \ No newline at end of file diff --git a/src/main/java/org/trigon/hardware/rev/spark/io/SimulationSparkIO.java b/src/main/java/org/trigon/hardware/rev/spark/io/SimulationSparkIO.java index 02c89195..73b6b50a 100644 --- a/src/main/java/org/trigon/hardware/rev/spark/io/SimulationSparkIO.java +++ b/src/main/java/org/trigon/hardware/rev/spark/io/SimulationSparkIO.java @@ -78,7 +78,7 @@ public void setBrake(boolean brake) { @Override public void updateSimulation() { - if (motorSimulation == null) + if (physicsSimulation == null) return; physicsSimulation.setInputVoltage(motorSimulation.getBusVoltage()); physicsSimulation.updateMotor(); From 8ed0e2027588140a7ba7ca976387e0c296500611 Mon Sep 17 00:00:00 2001 From: Nummun14 <142012009+Nummun14@users.noreply.github.com> Date: Sat, 30 Nov 2024 20:05:05 +0200 Subject: [PATCH 29/61] idea for mirrorable fix --- .../java/org/trigon/utilities/mirrorable/Mirrorable.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/main/java/org/trigon/utilities/mirrorable/Mirrorable.java b/src/main/java/org/trigon/utilities/mirrorable/Mirrorable.java index 515e1e60..0d7e5b5c 100644 --- a/src/main/java/org/trigon/utilities/mirrorable/Mirrorable.java +++ b/src/main/java/org/trigon/utilities/mirrorable/Mirrorable.java @@ -25,10 +25,10 @@ public abstract class Mirrorable { protected final T nonMirroredObject, mirroredObject; protected final boolean shouldMirrorWhenRedAlliance; - static { - UPDATE_ALLIANCE_TIMER.start(); - new Trigger(() -> UPDATE_ALLIANCE_TIMER.advanceIfElapsed(0.5)).onTrue(getUpdateAllianceCommand()); - } +// static { +// UPDATE_ALLIANCE_TIMER.start(); +// new Trigger(() -> UPDATE_ALLIANCE_TIMER.advanceIfElapsed(0.5)).onTrue(getUpdateAllianceCommand()); +// } /** * Creates a new mirrorable object. From c13cbe167f790ce68943807c85d4d4c641bd4ae6 Mon Sep 17 00:00:00 2001 From: Nummun14 <142012009+Nummun14@users.noreply.github.com> Date: Sat, 30 Nov 2024 20:59:59 +0200 Subject: [PATCH 30/61] cleaned up mirrorable solution --- .../org/trigon/utilities/mirrorable/Mirrorable.java | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/src/main/java/org/trigon/utilities/mirrorable/Mirrorable.java b/src/main/java/org/trigon/utilities/mirrorable/Mirrorable.java index 0d7e5b5c..d12d14e2 100644 --- a/src/main/java/org/trigon/utilities/mirrorable/Mirrorable.java +++ b/src/main/java/org/trigon/utilities/mirrorable/Mirrorable.java @@ -25,11 +25,6 @@ public abstract class Mirrorable { protected final T nonMirroredObject, mirroredObject; protected final boolean shouldMirrorWhenRedAlliance; -// static { -// UPDATE_ALLIANCE_TIMER.start(); -// new Trigger(() -> UPDATE_ALLIANCE_TIMER.advanceIfElapsed(0.5)).onTrue(getUpdateAllianceCommand()); -// } - /** * Creates a new mirrorable object. * @@ -42,7 +37,10 @@ protected Mirrorable(T nonMirroredObject, boolean shouldMirrorWhenRedAlliance) { this.shouldMirrorWhenRedAlliance = shouldMirrorWhenRedAlliance; } - public static void initializeMirrorable() { + /** + * Initializes the mirrorable object. This should be called once in robot container's constructor. + */ + public static void init() { UPDATE_ALLIANCE_TIMER.start(); new Trigger(() -> UPDATE_ALLIANCE_TIMER.advanceIfElapsed(0.5)).onTrue(getUpdateAllianceCommand()); } From cdc813e51d2e1ee1cfe5a068317fb6dfdf5c79e6 Mon Sep 17 00:00:00 2001 From: Nummun14 <142012009+Nummun14@users.noreply.github.com> Date: Sun, 1 Dec 2024 12:03:32 +0200 Subject: [PATCH 31/61] idea for mirrorable fix --- .../hardware/rev/spark/io/RealSparkIO.java | 16 ++++---- .../utilities/mirrorable/Mirrorable.java | 38 ++++++++++--------- 2 files changed, 29 insertions(+), 25 deletions(-) diff --git a/src/main/java/org/trigon/hardware/rev/spark/io/RealSparkIO.java b/src/main/java/org/trigon/hardware/rev/spark/io/RealSparkIO.java index dd7eb66f..2f53f313 100644 --- a/src/main/java/org/trigon/hardware/rev/spark/io/RealSparkIO.java +++ b/src/main/java/org/trigon/hardware/rev/spark/io/RealSparkIO.java @@ -20,13 +20,13 @@ public RealSparkIO(int id, SparkType sparkType) { } @Override - public void setReference(double value, SparkBase.ControlType ctrl) { - pidController.setReference(value, ctrl); + public void setReference(double value, SparkBase.ControlType controlType) { + pidController.setReference(value, controlType); } @Override - public void setReference(double value, SparkBase.ControlType ctrl, int pidSlot) { - pidController.setReference(value, ctrl, pidSlot); + public void setReference(double value, SparkBase.ControlType controlType, int pidSlot) { + pidController.setReference(value, controlType, pidSlot); } @Override @@ -50,13 +50,13 @@ public void setPeriodicFrameTimeout(int timeoutMs) { } @Override - public void setReference(double value, SparkBase.ControlType ctrl, int pidSlot, double arbFeedForward) { - pidController.setReference(value, ctrl, pidSlot, arbFeedForward); + public void setReference(double value, SparkBase.ControlType controlType, int pidSlot, double arbFeedForward) { + pidController.setReference(value, controlType, pidSlot, arbFeedForward); } @Override - public void setReference(double value, SparkBase.ControlType ctrl, int pidSlot, double arbFeedForward, SparkClosedLoopController.ArbFFUnits arbFFUnits) { - pidController.setReference(value, ctrl, pidSlot, arbFeedForward, arbFFUnits); + public void setReference(double value, SparkBase.ControlType controlType, int pidSlot, double arbFeedForward, SparkClosedLoopController.ArbFFUnits arbFeedForwardUnits) { + pidController.setReference(value, controlType, pidSlot, arbFeedForward, arbFeedForwardUnits); } @Override diff --git a/src/main/java/org/trigon/utilities/mirrorable/Mirrorable.java b/src/main/java/org/trigon/utilities/mirrorable/Mirrorable.java index d12d14e2..c408cead 100644 --- a/src/main/java/org/trigon/utilities/mirrorable/Mirrorable.java +++ b/src/main/java/org/trigon/utilities/mirrorable/Mirrorable.java @@ -18,13 +18,17 @@ public abstract class Mirrorable { protected static final Rotation2d HALF_ROTATION = new Rotation2d(Math.PI); protected static final double FIELD_LENGTH_METERS = 16.54175; - private static final Timer UPDATE_ALLIANCE_TIMER = new Timer(); - private static boolean IS_RED_ALLIANCE = isRedAlliance(); + private static boolean IS_RED_ALLIANCE; protected final T nonMirroredObject, mirroredObject; protected final boolean shouldMirrorWhenRedAlliance; + static { + UPDATE_ALLIANCE_TIMER.start(); + new Trigger(() -> UPDATE_ALLIANCE_TIMER.advanceIfElapsed(0.5)).onTrue(getUpdateAllianceCommand()); + } + /** * Creates a new mirrorable object. * @@ -37,13 +41,13 @@ protected Mirrorable(T nonMirroredObject, boolean shouldMirrorWhenRedAlliance) { this.shouldMirrorWhenRedAlliance = shouldMirrorWhenRedAlliance; } - /** - * Initializes the mirrorable object. This should be called once in robot container's constructor. - */ - public static void init() { - UPDATE_ALLIANCE_TIMER.start(); - new Trigger(() -> UPDATE_ALLIANCE_TIMER.advanceIfElapsed(0.5)).onTrue(getUpdateAllianceCommand()); - } +// /** +// * Initializes the mirrorable object. This should be called once in robot container's constructor. +// */ +// public static void init() { +// UPDATE_ALLIANCE_TIMER.start(); +// new Trigger(() -> UPDATE_ALLIANCE_TIMER.advanceIfElapsed(0.5)).onTrue(getUpdateAllianceCommand()); +// } /** * @return whether the robot is on the red alliance. This is cached every 0.5 seconds @@ -52,14 +56,6 @@ public static boolean isRedAlliance() { return IS_RED_ALLIANCE; } - /** - * @return whether the robot is on the red alliance. This is not cached - */ - private static boolean notCachedIsRedAlliance() { - final Optional optionalAlliance = DriverStation.getAlliance(); - return optionalAlliance.orElse(DriverStation.Alliance.Red).equals(DriverStation.Alliance.Red); - } - /** * Gets a command that updates the alliance. This is used to cache the alliance every 0.5 seconds. Ignoring disable is used to allow this command to run when the robot is disabled. * @@ -69,6 +65,14 @@ private static Command getUpdateAllianceCommand() { return new InstantCommand(() -> IS_RED_ALLIANCE = notCachedIsRedAlliance()).ignoringDisable(true); } + /** + * @return whether the robot is on the red alliance. This is not cached + */ + private static boolean notCachedIsRedAlliance() { + final Optional optionalAlliance = DriverStation.getAlliance(); + return optionalAlliance.orElse(DriverStation.Alliance.Red).equals(DriverStation.Alliance.Red); + } + /** * @return the current object. * If the robot is on the red alliance and the object should be mirrored, the mirrored object is returned. From ee011929a52845bcd8dd2519c3f78dc547c26391 Mon Sep 17 00:00:00 2001 From: Nummun14 <142012009+Nummun14@users.noreply.github.com> Date: Sun, 1 Dec 2024 14:44:07 +0200 Subject: [PATCH 32/61] =?UTF-8?q?=F0=9F=A5=B8=F0=9F=AB=A8=F0=9F=99=82?= =?UTF-8?q?=E2=80=8D=E2=86=94=EF=B8=8F=F0=9F=A4=92=F0=9F=A7=90mirrorable?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../org/trigon/utilities/mirrorable/Mirrorable.java | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) diff --git a/src/main/java/org/trigon/utilities/mirrorable/Mirrorable.java b/src/main/java/org/trigon/utilities/mirrorable/Mirrorable.java index c408cead..5ffc1c9d 100644 --- a/src/main/java/org/trigon/utilities/mirrorable/Mirrorable.java +++ b/src/main/java/org/trigon/utilities/mirrorable/Mirrorable.java @@ -19,8 +19,7 @@ public abstract class Mirrorable { protected static final Rotation2d HALF_ROTATION = new Rotation2d(Math.PI); protected static final double FIELD_LENGTH_METERS = 16.54175; private static final Timer UPDATE_ALLIANCE_TIMER = new Timer(); - - private static boolean IS_RED_ALLIANCE; + private static boolean IS_RED_ALLIANCE = notCachedIsRedAlliance(); protected final T nonMirroredObject, mirroredObject; protected final boolean shouldMirrorWhenRedAlliance; @@ -41,14 +40,6 @@ protected Mirrorable(T nonMirroredObject, boolean shouldMirrorWhenRedAlliance) { this.shouldMirrorWhenRedAlliance = shouldMirrorWhenRedAlliance; } -// /** -// * Initializes the mirrorable object. This should be called once in robot container's constructor. -// */ -// public static void init() { -// UPDATE_ALLIANCE_TIMER.start(); -// new Trigger(() -> UPDATE_ALLIANCE_TIMER.advanceIfElapsed(0.5)).onTrue(getUpdateAllianceCommand()); -// } - /** * @return whether the robot is on the red alliance. This is cached every 0.5 seconds */ From 3da0f222b867ea7d193e8e93803725a4c6f596c2 Mon Sep 17 00:00:00 2001 From: Nummun14 <142012009+Nummun14@users.noreply.github.com> Date: Sun, 1 Dec 2024 16:05:02 +0200 Subject: [PATCH 33/61] updated limelight helpers, fixed led jdocs, reverted to old mirrorable fix --- .../hardware/misc/leds/CANdleLEDStrip.java | 3 +- .../trigon/utilities/LimelightHelpers.java | 443 ++++++++++++++++-- .../utilities/mirrorable/Mirrorable.java | 34 +- 3 files changed, 422 insertions(+), 58 deletions(-) diff --git a/src/main/java/org/trigon/hardware/misc/leds/CANdleLEDStrip.java b/src/main/java/org/trigon/hardware/misc/leds/CANdleLEDStrip.java index f6494bf9..403cb2a2 100644 --- a/src/main/java/org/trigon/hardware/misc/leds/CANdleLEDStrip.java +++ b/src/main/java/org/trigon/hardware/misc/leds/CANdleLEDStrip.java @@ -15,7 +15,8 @@ public class CANdleLEDStrip extends LEDStrip { private final int animationSlot; /** - * Sets the CANdle instance to be used for controlling the LED strips. Must be set before using any LED strips. Should only be called once + * Sets the CANdle instance to be used for controlling the LED strips. Must be set before using any LED strips. Should only be called once. + * Should be configured before being set. * * @param candle the CANdle instance to be used */ diff --git a/src/main/java/org/trigon/utilities/LimelightHelpers.java b/src/main/java/org/trigon/utilities/LimelightHelpers.java index f39c485d..29a3ad94 100644 --- a/src/main/java/org/trigon/utilities/LimelightHelpers.java +++ b/src/main/java/org/trigon/utilities/LimelightHelpers.java @@ -1,4 +1,4 @@ -//LimelightHelpers v1.9 (REQUIRES 2024.9.1) +//LimelightHelpers v1.10 (REQUIRES LLOS 2024.9.1 OR LATER) package org.trigon.utilities; @@ -20,9 +20,17 @@ import java.util.concurrent.CompletableFuture; import java.util.concurrent.ConcurrentHashMap; +/** + * LimelightHelpers provides static methods and classes for interfacing with Limelight vision cameras in FRC. + * This library supports all Limelight features including AprilTag tracking, Neural Networks, and standard color/retroreflective tracking. + */ public class LimelightHelpers { + private static final Map doubleArrayEntries = new ConcurrentHashMap<>(); + /** + * Represents a Color/Retroreflective Target Result extracted from JSON Output + */ public static class LimelightTarget_Retro { @JsonProperty("t6c_ts") @@ -86,15 +94,21 @@ public Pose2d getTargetPose_RobotSpace2D() { @JsonProperty("tx") public double tx; - @JsonProperty("txp") - public double tx_pixels; - @JsonProperty("ty") public double ty; + @JsonProperty("txp") + public double tx_pixels; + @JsonProperty("typ") public double ty_pixels; + @JsonProperty("tx_nocross") + public double tx_nocrosshair; + + @JsonProperty("ty_nocross") + public double ty_nocrosshair; + @JsonProperty("ts") public double ts; @@ -108,6 +122,9 @@ public LimelightTarget_Retro() { } + /** + * Represents an AprilTag/Fiducial Target Result extracted from JSON Output + */ public static class LimelightTarget_Fiducial { @JsonProperty("fID") @@ -177,15 +194,21 @@ public Pose2d getTargetPose_RobotSpace2D() { @JsonProperty("tx") public double tx; - @JsonProperty("txp") - public double tx_pixels; - @JsonProperty("ty") public double ty; + @JsonProperty("txp") + public double tx_pixels; + @JsonProperty("typ") public double ty_pixels; + @JsonProperty("tx_nocross") + public double tx_nocrosshair; + + @JsonProperty("ty_nocross") + public double ty_nocrosshair; + @JsonProperty("ts") public double ts; @@ -198,10 +221,58 @@ public LimelightTarget_Fiducial() { } } + /** + * Represents a Barcode Target Result extracted from JSON Output + */ public static class LimelightTarget_Barcode { + /** + * Barcode family type (e.g. "QR", "DataMatrix", etc.) + */ + @JsonProperty("fam") + public String family; + + /** + * Gets the decoded data content of the barcode + */ + @JsonProperty("data") + public String data; + + @JsonProperty("txp") + public double tx_pixels; + + @JsonProperty("typ") + public double ty_pixels; + + @JsonProperty("tx") + public double tx; + + @JsonProperty("ty") + public double ty; + + @JsonProperty("tx_nocross") + public double tx_nocrosshair; + + @JsonProperty("ty_nocross") + public double ty_nocrosshair; + + @JsonProperty("ta") + public double ta; + + @JsonProperty("pts") + public double[][] corners; + + public LimelightTarget_Barcode() { + } + + public String getFamily() { + return family; + } } + /** + * Represents a Neural Classifier Pipeline Result extracted from JSON Output + */ public static class LimelightTarget_Classifier { @JsonProperty("class") @@ -232,6 +303,9 @@ public LimelightTarget_Classifier() { } } + /** + * Represents a Neural Detector Pipeline Result extracted from JSON Output + */ public static class LimelightTarget_Detector { @JsonProperty("class") @@ -249,19 +323,28 @@ public static class LimelightTarget_Detector { @JsonProperty("tx") public double tx; - @JsonProperty("txp") - public double tx_pixels; - @JsonProperty("ty") public double ty; + @JsonProperty("txp") + public double tx_pixels; + @JsonProperty("typ") public double ty_pixels; + @JsonProperty("tx_nocross") + public double tx_nocrosshair; + + @JsonProperty("ty_nocross") + public double ty_nocrosshair; + public LimelightTarget_Detector() { } } + /** + * Limelight Results object, parsed from a Limelight's JSON results output. + */ public static class LimelightResults { public String error; @@ -366,6 +449,9 @@ public LimelightResults() { } + /** + * Represents a Limelight Raw Fiducial result from Limelight's NetworkTables output. + */ public static class RawFiducial { public int id = 0; public double txnc = 0; @@ -387,6 +473,9 @@ public RawFiducial(int id, double txnc, double tync, double ta, double distToCam } } + /** + * Represents a Limelight Raw Neural Detector result from Limelight's NetworkTables output. + */ public static class RawDetection { public int classId = 0; public double txnc = 0; @@ -422,6 +511,9 @@ public RawDetection(int classId, double txnc, double tync, double ta, } } + /** + * Represents a 3D Pose Estimate. + */ public static class PoseEstimate { public Pose2d pose; public double timestampSeconds; @@ -430,10 +522,12 @@ public static class PoseEstimate { public double tagSpan; public double avgTagDist; public double avgTagArea; + public RawFiducial[] rawFiducials; + public boolean isMegaTag2; /** - * Makes a PoseEstimate object with default values + * Instantiates a PoseEstimate object with default values */ public PoseEstimate() { this.pose = new Pose2d(); @@ -444,11 +538,12 @@ public PoseEstimate() { this.avgTagDist = 0; this.avgTagArea = 0; this.rawFiducials = new RawFiducial[]{}; + this.isMegaTag2 = false; } public PoseEstimate(Pose2d pose, double timestampSeconds, double latency, int tagCount, double tagSpan, double avgTagDist, - double avgTagArea, RawFiducial[] rawFiducials) { + double avgTagArea, RawFiducial[] rawFiducials, boolean isMegaTag2) { this.pose = pose; this.timestampSeconds = timestampSeconds; @@ -458,6 +553,7 @@ public PoseEstimate(Pose2d pose, double timestampSeconds, double latency, this.avgTagDist = avgTagDist; this.avgTagArea = avgTagArea; this.rawFiducials = rawFiducials; + this.isMegaTag2 = isMegaTag2; } } @@ -476,6 +572,13 @@ static final String sanitizeName(String name) { return name; } + /** + * Takes a 6-length array of pose data and converts it to a Pose3d object. + * Array format: [x, y, z, roll, pitch, yaw] where angles are in degrees. + * + * @param inData Array containing pose data [x, y, z, roll, pitch, yaw] + * @return Pose3d object representing the pose, or empty Pose3d if invalid data + */ public static Pose3d toPose3D(double[] inData) { if (inData.length < 6) { //System.err.println("Bad LL 3D Pose Data!"); @@ -487,6 +590,14 @@ public static Pose3d toPose3D(double[] inData) { Units.degreesToRadians(inData[5]))); } + /** + * Takes a 6-length array of pose data and converts it to a Pose2d object. + * Uses only x, y, and yaw components, ignoring z, roll, and pitch. + * Array format: [x, y, z, roll, pitch, yaw] where angles are in degrees. + * + * @param inData Array containing pose data [x, y, z, roll, pitch, yaw] + * @return Pose2d object representing the pose, or empty Pose2d if invalid data + */ public static Pose2d toPose2D(double[] inData) { if (inData.length < 6) { //System.err.println("Bad LL 2D Pose Data!"); @@ -498,11 +609,12 @@ public static Pose2d toPose2D(double[] inData) { } /** - * Converts a Pose3d object to an array of doubles. + * Converts a Pose3d object to an array of doubles in the format [x, y, z, roll, pitch, yaw]. + * Translation components are in meters, rotation components are in degrees. * - * @param pose The Pose3d object to convert. - * @return The array of doubles representing the pose. - **/ + * @param pose The Pose3d object to convert + * @return A 6-element array containing [x, y, z, roll, pitch, yaw] + */ public static double[] pose3dToArray(Pose3d pose) { double[] result = new double[6]; result[0] = pose.getTranslation().getX(); @@ -515,11 +627,13 @@ public static double[] pose3dToArray(Pose3d pose) { } /** - * Converts a Pose2d object to an array of doubles. + * Converts a Pose2d object to an array of doubles in the format [x, y, z, roll, pitch, yaw]. + * Translation components are in meters, rotation components are in degrees. + * Note: z, roll, and pitch will be 0 since Pose2d only contains x, y, and yaw. * - * @param pose The Pose2d object to convert. - * @return The array of doubles representing the pose. - **/ + * @param pose The Pose2d object to convert + * @return A 6-element array containing [x, y, 0, 0, 0, yaw] + */ public static double[] pose2dToArray(Pose2d pose) { double[] result = new double[6]; result[0] = pose.getTranslation().getX(); @@ -538,7 +652,7 @@ private static double extractArrayEntry(double[] inData, int position) { return inData[position]; } - private static PoseEstimate getBotPoseEstimate(String limelightName, String entryName) { + private static PoseEstimate getBotPoseEstimate(String limelightName, String entryName, boolean isMegaTag2) { DoubleArrayEntry poseEntry = LimelightHelpers.getLimelightDoubleArrayEntry(limelightName, entryName); TimestampedDoubleArray tsValue = poseEntry.getAtomic(); @@ -580,10 +694,16 @@ private static PoseEstimate getBotPoseEstimate(String limelightName, String entr } } - return new PoseEstimate(pose, adjustedTimestamp, latency, tagCount, tagSpan, tagDist, tagArea, rawFiducials); + return new PoseEstimate(pose, adjustedTimestamp, latency, tagCount, tagSpan, tagDist, tagArea, rawFiducials, isMegaTag2); } - private static RawFiducial[] getRawFiducials(String limelightName) { + /** + * Gets the latest raw fiducial/AprilTag detection results from NetworkTables. + * + * @param limelightName Name/identifier of the Limelight + * @return Array of RawFiducial objects containing detection details + */ + public static RawFiducial[] getRawFiducials(String limelightName) { var entry = LimelightHelpers.getLimelightNTTableEntry(limelightName, "rawfiducials"); var rawFiducialArray = entry.getDoubleArray(new double[0]); int valsPerEntry = 7; @@ -610,10 +730,16 @@ private static RawFiducial[] getRawFiducials(String limelightName) { return rawFiducials; } + /** + * Gets the latest raw neural detector results from NetworkTables + * + * @param limelightName Name/identifier of the Limelight + * @return Array of RawDetection objects containing detection details + */ public static RawDetection[] getRawDetections(String limelightName) { var entry = LimelightHelpers.getLimelightNTTableEntry(limelightName, "rawdetections"); var rawDetectionArray = entry.getDoubleArray(new double[0]); - int valsPerEntry = 11; + int valsPerEntry = 12; if (rawDetectionArray.length % valsPerEntry != 0) { return new RawDetection[0]; } @@ -642,6 +768,13 @@ public static RawDetection[] getRawDetections(String limelightName) { return rawDetections; } + /** + * Prints detailed information about a PoseEstimate to standard output. + * Includes timestamp, latency, tag count, tag span, average tag distance, + * average tag area, and detailed information about each detected fiducial. + * + * @param pose The PoseEstimate object to print. If null, prints "No PoseEstimate available." + */ public static void printPoseEstimate(PoseEstimate pose) { if (pose == null) { System.out.println("No PoseEstimate available."); @@ -655,6 +788,7 @@ public static void printPoseEstimate(PoseEstimate pose) { System.out.printf("Tag Span: %.2f meters%n", pose.tagSpan); System.out.printf("Average Tag Distance: %.2f meters%n", pose.avgTagDist); System.out.printf("Average Tag Area: %.2f%% of image%n", pose.avgTagArea); + System.out.printf("Is MegaTag2: %b%n", pose.isMegaTag2); System.out.println(); if (pose.rawFiducials == null || pose.rawFiducials.length == 0) { @@ -677,6 +811,10 @@ public static void printPoseEstimate(PoseEstimate pose) { } } + public static Boolean validPoseEstimate(PoseEstimate pose) { + return pose != null && pose.rawFiducials != null && pose.rawFiducials.length != 0; + } + public static NetworkTable getLimelightNTTable(String tableName) { return NetworkTableInstance.getDefault().getTable(sanitizeName(tableName)); } @@ -737,23 +875,83 @@ public static URL getLimelightURLString(String tableName, String request) { ///// ///// + /** + * Does the Limelight have a valid target? + * + * @param limelightName Name of the Limelight camera ("" for default) + * @return True if a valid target is present, false otherwise + */ + public static boolean getTV(String limelightName) { + return 1.0 == getLimelightNTDouble(limelightName, "tv"); + } + + /** + * Gets the horizontal offset from the crosshair to the target in degrees. + * + * @param limelightName Name of the Limelight camera ("" for default) + * @return Horizontal offset angle in degrees + */ public static double getTX(String limelightName) { return getLimelightNTDouble(limelightName, "tx"); } + /** + * Gets the vertical offset from the crosshair to the target in degrees. + * + * @param limelightName Name of the Limelight camera ("" for default) + * @return Vertical offset angle in degrees + */ public static double getTY(String limelightName) { return getLimelightNTDouble(limelightName, "ty"); } + /** + * Gets the horizontal offset from the principal pixel/point to the target in degrees. This is the most accurate 2d metric if you are using a calibrated camera and you don't need adjustable crosshair functionality. + * + * @param limelightName Name of the Limelight camera ("" for default) + * @return Horizontal offset angle in degrees + */ + public static double getTXNC(String limelightName) { + return getLimelightNTDouble(limelightName, "txnc"); + } + + /** + * Gets the vertical offset from the principal pixel/point to the target in degrees. This is the most accurate 2d metric if you are using a calibrated camera and you don't need adjustable crosshair functionality. + * + * @param limelightName Name of the Limelight camera ("" for default) + * @return Vertical offset angle in degrees + */ + public static double getTYNC(String limelightName) { + return getLimelightNTDouble(limelightName, "tync"); + } + + /** + * Gets the target area as a percentage of the image (0-100%). + * + * @param limelightName Name of the Limelight camera ("" for default) + * @return Target area percentage (0-100) + */ public static double getTA(String limelightName) { return getLimelightNTDouble(limelightName, "ta"); } + /** + * T2D is an array that contains several targeting metrcis + * + * @param limelightName Name of the Limelight camera + * @return Array containing [targetValid, targetCount, targetLatency, captureLatency, tx, ty, txnc, tync, ta, tid, targetClassIndexDetector, + * targetClassIndexClassifier, targetLongSidePixels, targetShortSidePixels, targetHorizontalExtentPixels, targetVerticalExtentPixels, targetSkewDegrees] + */ public static double[] getT2DArray(String limelightName) { return getLimelightNTDoubleArray(limelightName, "t2d"); } - + /** + * Gets the number of targets currently detected. + * + * @param limelightName Name of the Limelight camera + * @return Number of detected targets + */ public static int getTargetCount(String limelightName) { double[] t2d = getT2DArray(limelightName); if (t2d.length == 17) { @@ -762,6 +960,12 @@ public static int getTargetCount(String limelightName) { return 0; } + /** + * Gets the classifier class index from the currently running neural classifier pipeline + * + * @param limelightName Name of the Limelight camera + * @return Class index from classifier pipeline + */ public static int getClassifierClassIndex(String limelightName) { double[] t2d = getT2DArray(limelightName); if (t2d.length == 17) { @@ -770,6 +974,12 @@ public static int getClassifierClassIndex(String limelightName) { return 0; } + /** + * Gets the detector class index from the primary result of the currently running neural detector pipeline. + * + * @param limelightName Name of the Limelight camera + * @return Class index from detector pipeline + */ public static int getDetectorClassIndex(String limelightName) { double[] t2d = getT2DArray(limelightName); if (t2d.length == 17) { @@ -778,31 +988,72 @@ public static int getDetectorClassIndex(String limelightName) { return 0; } + /** + * Gets the current neural classifier result class name. + * + * @param limelightName Name of the Limelight camera + * @return Class name string from classifier pipeline + */ public static String getClassifierClass(String limelightName) { return getLimelightNTString(limelightName, "tcclass"); } + /** + * Gets the primary neural detector result class name. + * + * @param limelightName Name of the Limelight camera + * @return Class name string from detector pipeline + */ public static String getDetectorClass(String limelightName) { return getLimelightNTString(limelightName, "tdclass"); } - + /** + * Gets the pipeline's processing latency contribution. + * + * @param limelightName Name of the Limelight camera + * @return Pipeline latency in milliseconds + */ public static double getLatency_Pipeline(String limelightName) { return getLimelightNTDouble(limelightName, "tl"); } + /** + * Gets the capture latency. + * + * @param limelightName Name of the Limelight camera + * @return Capture latency in milliseconds + */ public static double getLatency_Capture(String limelightName) { return getLimelightNTDouble(limelightName, "cl"); } + /** + * Gets the active pipeline index. + * + * @param limelightName Name of the Limelight camera + * @return Current pipeline index (0-9) + */ public static double getCurrentPipelineIndex(String limelightName) { return getLimelightNTDouble(limelightName, "getpipe"); } + /** + * Gets the current pipeline type. + * + * @param limelightName Name of the Limelight camera + * @return Pipeline type string (e.g. "retro", "apriltag", etc) + */ public static String getCurrentPipelineType(String limelightName) { return getLimelightNTString(limelightName, "getpipetype"); } + /** + * Gets the full JSON results dump. + * + * @param limelightName Name of the Limelight camera + * @return JSON string containing all current results + */ public static String getJSONDump(String limelightName) { return getLimelightNTString(limelightName, "json"); } @@ -892,36 +1143,78 @@ public static Pose3d getBotPose3d(String limelightName) { return toPose3D(poseArray); } + /** + * (Not Recommended) Gets the robot's 3D pose in the WPILib Red Alliance Coordinate System. + * + * @param limelightName Name/identifier of the Limelight + * @return Pose3d object representing the robot's position and orientation in Red Alliance field space + */ public static Pose3d getBotPose3d_wpiRed(String limelightName) { double[] poseArray = getLimelightNTDoubleArray(limelightName, "botpose_wpired"); return toPose3D(poseArray); } + /** + * (Recommended) Gets the robot's 3D pose in the WPILib Blue Alliance Coordinate System. + * + * @param limelightName Name/identifier of the Limelight + * @return Pose3d object representing the robot's position and orientation in Blue Alliance field space + */ public static Pose3d getBotPose3d_wpiBlue(String limelightName) { double[] poseArray = getLimelightNTDoubleArray(limelightName, "botpose_wpiblue"); return toPose3D(poseArray); } + /** + * Gets the robot's 3D pose with respect to the currently tracked target's coordinate system. + * + * @param limelightName Name/identifier of the Limelight + * @return Pose3d object representing the robot's position and orientation relative to the target + */ public static Pose3d getBotPose3d_TargetSpace(String limelightName) { double[] poseArray = getLimelightNTDoubleArray(limelightName, "botpose_targetspace"); return toPose3D(poseArray); } + /** + * Gets the camera's 3D pose with respect to the currently tracked target's coordinate system. + * + * @param limelightName Name/identifier of the Limelight + * @return Pose3d object representing the camera's position and orientation relative to the target + */ public static Pose3d getCameraPose3d_TargetSpace(String limelightName) { double[] poseArray = getLimelightNTDoubleArray(limelightName, "camerapose_targetspace"); return toPose3D(poseArray); } + /** + * Gets the target's 3D pose with respect to the camera's coordinate system. + * + * @param limelightName Name/identifier of the Limelight + * @return Pose3d object representing the target's position and orientation relative to the camera + */ public static Pose3d getTargetPose3d_CameraSpace(String limelightName) { double[] poseArray = getLimelightNTDoubleArray(limelightName, "targetpose_cameraspace"); return toPose3D(poseArray); } + /** + * Gets the target's 3D pose with respect to the robot's coordinate system. + * + * @param limelightName Name/identifier of the Limelight + * @return Pose3d object representing the target's position and orientation relative to the robot + */ public static Pose3d getTargetPose3d_RobotSpace(String limelightName) { double[] poseArray = getLimelightNTDoubleArray(limelightName, "targetpose_robotspace"); return toPose3D(poseArray); } + /** + * Gets the camera's 3D pose with respect to the robot's coordinate system. + * + * @param limelightName Name/identifier of the Limelight + * @return Pose3d object representing the camera's position and orientation relative to the robot + */ public static Pose3d getCameraPose3d_RobotSpace(String limelightName) { double[] poseArray = getLimelightNTDoubleArray(limelightName, "camerapose_robotspace"); return toPose3D(poseArray); @@ -941,25 +1234,24 @@ public static Pose2d getBotPose2d_wpiBlue(String limelightName) { } /** - * Gets the Pose2d and timestamp for use with WPILib pose estimator (addVisionMeasurement) when you are on the BLUE - * alliance + * Gets the MegaTag1 Pose2d and timestamp for use with WPILib pose estimator (addVisionMeasurement) in the WPILib Blue alliance coordinate system. * * @param limelightName * @return */ public static PoseEstimate getBotPoseEstimate_wpiBlue(String limelightName) { - return getBotPoseEstimate(limelightName, "botpose_wpiblue"); + return getBotPoseEstimate(limelightName, "botpose_wpiblue", false); } /** - * Gets the Pose2d and timestamp for use with WPILib pose estimator (addVisionMeasurement) when you are on the BLUE - * alliance + * Gets the MegaTag2 Pose2d and timestamp for use with WPILib pose estimator (addVisionMeasurement) in the WPILib Blue alliance coordinate system. + * Make sure you are calling setRobotOrientation() before calling this method. * * @param limelightName * @return */ public static PoseEstimate getBotPoseEstimate_wpiBlue_MegaTag2(String limelightName) { - return getBotPoseEstimate(limelightName, "botpose_orb_wpiblue"); + return getBotPoseEstimate(limelightName, "botpose_orb_wpiblue", true); } /** @@ -984,7 +1276,7 @@ public static Pose2d getBotPose2d_wpiRed(String limelightName) { * @return */ public static PoseEstimate getBotPoseEstimate_wpiRed(String limelightName) { - return getBotPoseEstimate(limelightName, "botpose_wpired"); + return getBotPoseEstimate(limelightName, "botpose_wpired", false); } /** @@ -995,7 +1287,7 @@ public static PoseEstimate getBotPoseEstimate_wpiRed(String limelightName) { * @return */ public static PoseEstimate getBotPoseEstimate_wpiRed_MegaTag2(String limelightName) { - return getBotPoseEstimate(limelightName, "botpose_orb_wpired"); + return getBotPoseEstimate(limelightName, "botpose_orb_wpired", true); } /** @@ -1012,9 +1304,6 @@ public static Pose2d getBotPose2d(String limelightName) { } - public static boolean getTV(String limelightName) { - return 1.0 == getLimelightNTDouble(limelightName, "tv"); - } ///// ///// @@ -1029,8 +1318,9 @@ public static void setPriorityTagID(String limelightName, int ID) { } /** - * The LEDs will be controlled by Limelight pipeline settings, and not by robot - * code. + * Sets LED mode to be controlled by the current pipeline. + * + * @param limelightName Name of the Limelight camera */ public static void setLEDMode_PipelineControl(String limelightName) { setLimelightNTDouble(limelightName, "ledMode", 0); @@ -1048,22 +1338,42 @@ public static void setLEDMode_ForceOn(String limelightName) { setLimelightNTDouble(limelightName, "ledMode", 3); } + /** + * Enables standard side-by-side stream mode. + * + * @param limelightName Name of the Limelight camera + */ public static void setStreamMode_Standard(String limelightName) { setLimelightNTDouble(limelightName, "stream", 0); } + /** + * Enables Picture-in-Picture mode with secondary stream in the corner. + * + * @param limelightName Name of the Limelight camera + */ public static void setStreamMode_PiPMain(String limelightName) { setLimelightNTDouble(limelightName, "stream", 1); } + /** + * Enables Picture-in-Picture mode with primary stream in the corner. + * + * @param limelightName Name of the Limelight camera + */ public static void setStreamMode_PiPSecondary(String limelightName) { setLimelightNTDouble(limelightName, "stream", 2); } /** - * Sets the crop window. The crop window in the UI must be completely open for - * dynamic cropping to work. + * Sets the crop window for the camera. The crop window in the UI must be completely open. + * + * @param limelightName Name of the Limelight camera + * @param cropXMin Minimum X value (-1 to 1) + * @param cropXMax Maximum X value (-1 to 1) + * @param cropYMin Minimum Y value (-1 to 1) + * @param cropYMax Maximum Y value (-1 to 1) */ public static void setCropWindow(String limelightName, double cropXMin, double cropXMax, double cropYMin, double cropYMax) { double[] entries = new double[4]; @@ -1085,6 +1395,17 @@ public static void setFiducial3DOffset(String limelightName, double offsetX, dou setLimelightNTDoubleArray(limelightName, "fiducial_offset_set", entries); } + /** + * Sets robot orientation values used by MegaTag2 localization algorithm. + * + * @param limelightName Name/identifier of the Limelight + * @param yaw Robot yaw in degrees. 0 = robot facing red alliance wall in FRC + * @param yawRate (Unnecessary) Angular velocity of robot yaw in degrees per second + * @param pitch (Unnecessary) Robot pitch in degrees + * @param pitchRate (Unnecessary) Angular velocity of robot pitch in degrees per second + * @param roll (Unnecessary) Robot roll in degrees + * @param rollRate (Unnecessary) Angular velocity of robot roll in degrees per second + */ public static void SetRobotOrientation(String limelightName, double yaw, double yawRate, double pitch, double pitchRate, double roll, double rollRate) { @@ -1114,7 +1435,15 @@ private static void SetRobotOrientation_INTERNAL(String limelightName, double ya } } - + /** + * Sets the 3D point-of-interest offset for the current fiducial pipeline. + * https://docs.limelightvision.io/docs/docs-limelight/pipeline-apriltag/apriltag-3d#point-of-interest-tracking + * + * @param limelightName Name/identifier of the Limelight + * @param x X offset in meters + * @param y Y offset in meters + * @param z Z offset in meters + */ public static void SetFidcuial3DOffset(String limelightName, double x, double y, double z) { @@ -1125,6 +1454,13 @@ public static void SetFidcuial3DOffset(String limelightName, double x, double y, setLimelightNTDoubleArray(limelightName, "fiducial_offset_set", entries); } + /** + * Overrides the valid AprilTag IDs that will be used for localization. + * Tags not in this list will be ignored for robot pose estimation. + * + * @param limelightName Name/identifier of the Limelight + * @param validIDs Array of valid AprilTag IDs to track + */ public static void SetFiducialIDFiltersOverride(String limelightName, int[] validIDs) { double[] validIDsDouble = new double[validIDs.length]; for (int i = 0; i < validIDs.length; i++) { @@ -1133,6 +1469,13 @@ public static void SetFiducialIDFiltersOverride(String limelightName, int[] vali setLimelightNTDoubleArray(limelightName, "fiducial_id_filters_set", validIDsDouble); } + /** + * Sets the downscaling factor for AprilTag detection. + * Increasing downscale can improve performance at the cost of potentially reduced detection range. + * + * @param limelightName Name/identifier of the Limelight + * @param downscale Downscale factor. Valid values: 1.0 (no downscale), 1.5, 2.0, 3.0, 4.0. Set to 0 for pipeline control. + */ public static void SetFiducialDownscalingOverride(String limelightName, float downscale) { int d = 0; // pipeline if (downscale == 1.0) { @@ -1153,6 +1496,17 @@ public static void SetFiducialDownscalingOverride(String limelightName, float do setLimelightNTDouble(limelightName, "fiducial_downscale_set", d); } + /** + * Sets the camera pose relative to the robot. + * + * @param limelightName Name of the Limelight camera + * @param forward Forward offset in meters + * @param side Side offset in meters + * @param up Up offset in meters + * @param roll Roll angle in degrees + * @param pitch Pitch angle in degrees + * @param yaw Yaw angle in degrees + */ public static void setCameraPose_RobotSpace(String limelightName, double forward, double side, double up, double roll, double pitch, double yaw) { double[] entries = new double[6]; entries[0] = forward; @@ -1209,7 +1563,10 @@ private static boolean SYNCH_TAKESNAPSHOT(String tableName, String snapshotName) } /** - * Parses Limelight's JSON results dump into a LimelightResults Object + * Gets the latest JSON results output and returns a LimelightResults object. + * + * @param limelightName Name of the Limelight camera + * @return LimelightResults object containing all current target data */ public static LimelightResults getLatestResults(String limelightName) { diff --git a/src/main/java/org/trigon/utilities/mirrorable/Mirrorable.java b/src/main/java/org/trigon/utilities/mirrorable/Mirrorable.java index 5ffc1c9d..f1d5c1a4 100644 --- a/src/main/java/org/trigon/utilities/mirrorable/Mirrorable.java +++ b/src/main/java/org/trigon/utilities/mirrorable/Mirrorable.java @@ -23,23 +23,16 @@ public abstract class Mirrorable { protected final T nonMirroredObject, mirroredObject; protected final boolean shouldMirrorWhenRedAlliance; - static { +// static { +// UPDATE_ALLIANCE_TIMER.start(); +// new Trigger(() -> UPDATE_ALLIANCE_TIMER.advanceIfElapsed(0.5)).onTrue(getUpdateAllianceCommand()); +// } + + public static void init() { UPDATE_ALLIANCE_TIMER.start(); new Trigger(() -> UPDATE_ALLIANCE_TIMER.advanceIfElapsed(0.5)).onTrue(getUpdateAllianceCommand()); } - /** - * Creates a new mirrorable object. - * - * @param nonMirroredObject the object when the robot is on the blue alliance, or the non-mirrored object - * @param shouldMirrorWhenRedAlliance whether the object should be mirrored when the robot is on the red alliance - */ - protected Mirrorable(T nonMirroredObject, boolean shouldMirrorWhenRedAlliance) { - this.nonMirroredObject = nonMirroredObject; - this.mirroredObject = mirror(nonMirroredObject); - this.shouldMirrorWhenRedAlliance = shouldMirrorWhenRedAlliance; - } - /** * @return whether the robot is on the red alliance. This is cached every 0.5 seconds */ @@ -65,9 +58,22 @@ private static boolean notCachedIsRedAlliance() { } /** - * @return the current object. + * Creates a new mirrorable object. + * + * @param nonMirroredObject the object when the robot is on the blue alliance, or the non-mirrored object + * @param shouldMirrorWhenRedAlliance whether the object should be mirrored when the robot is on the red alliance + */ + protected Mirrorable(T nonMirroredObject, boolean shouldMirrorWhenRedAlliance) { + this.nonMirroredObject = nonMirroredObject; + this.mirroredObject = mirror(nonMirroredObject); + this.shouldMirrorWhenRedAlliance = shouldMirrorWhenRedAlliance; + } + + /** * If the robot is on the red alliance and the object should be mirrored, the mirrored object is returned. * Otherwise, the non-mirrored object is returned. + * + * @return the current object */ public T get() { return isRedAlliance() && shouldMirrorWhenRedAlliance ? mirroredObject : nonMirroredObject; From c4fd20ac0b288d94e3c55b64684ad3419009350d Mon Sep 17 00:00:00 2001 From: Nummun14 <142012009+Nummun14@users.noreply.github.com> Date: Sun, 1 Dec 2024 17:30:51 +0200 Subject: [PATCH 34/61] cleaned up mirrorable, and spark. Still trying to figure out revSim --- .../hardware/misc/leds/CANdleLEDStrip.java | 2 +- .../trigon/hardware/rev/spark/SparkMotor.java | 5 +++++ .../hardware/rev/spark/io/RealSparkIO.java | 20 +++++++++--------- .../rev/spark/io/SimulationSparkIO.java | 21 ++++++++++--------- .../simulation/MotorPhysicsSimulation.java | 2 +- .../utilities/mirrorable/Mirrorable.java | 8 +++---- 6 files changed, 31 insertions(+), 27 deletions(-) diff --git a/src/main/java/org/trigon/hardware/misc/leds/CANdleLEDStrip.java b/src/main/java/org/trigon/hardware/misc/leds/CANdleLEDStrip.java index 403cb2a2..31a75257 100644 --- a/src/main/java/org/trigon/hardware/misc/leds/CANdleLEDStrip.java +++ b/src/main/java/org/trigon/hardware/misc/leds/CANdleLEDStrip.java @@ -16,7 +16,7 @@ public class CANdleLEDStrip extends LEDStrip { /** * Sets the CANdle instance to be used for controlling the LED strips. Must be set before using any LED strips. Should only be called once. - * Should be configured before being set. + * Must be configured before being set. * * @param candle the CANdle instance to be used */ diff --git a/src/main/java/org/trigon/hardware/rev/spark/SparkMotor.java b/src/main/java/org/trigon/hardware/rev/spark/SparkMotor.java index 704c3f85..7ec12142 100644 --- a/src/main/java/org/trigon/hardware/rev/spark/SparkMotor.java +++ b/src/main/java/org/trigon/hardware/rev/spark/SparkMotor.java @@ -220,6 +220,11 @@ public void applySimulationConfiguration(SparkBaseConfig simulationConfiguration motorIO.configure(simulationConfiguration, resetMode, persistMode); } + /** + * Sets the physics simulation to be used by the motor. Needs to be called for the motor to work in simulation. + * + * @param physicsSimulation the physics simulation to be used + */ public void setPhysicsSimulation(MotorPhysicsSimulation physicsSimulation) { motorIO.setPhysicsSimulation(physicsSimulation); } diff --git a/src/main/java/org/trigon/hardware/rev/spark/io/RealSparkIO.java b/src/main/java/org/trigon/hardware/rev/spark/io/RealSparkIO.java index 2f53f313..561a9f40 100644 --- a/src/main/java/org/trigon/hardware/rev/spark/io/RealSparkIO.java +++ b/src/main/java/org/trigon/hardware/rev/spark/io/RealSparkIO.java @@ -29,6 +29,16 @@ public void setReference(double value, SparkBase.ControlType controlType, int pi pidController.setReference(value, controlType, pidSlot); } + @Override + public void setReference(double value, SparkBase.ControlType controlType, int pidSlot, double arbFeedForward) { + pidController.setReference(value, controlType, pidSlot, arbFeedForward); + } + + @Override + public void setReference(double value, SparkBase.ControlType controlType, int pidSlot, double arbFeedForward, SparkClosedLoopController.ArbFFUnits arbFeedForwardUnits) { + pidController.setReference(value, controlType, pidSlot, arbFeedForward, arbFeedForwardUnits); + } + @Override public SparkEncoder getEncoder() { return encoder; @@ -49,16 +59,6 @@ public void setPeriodicFrameTimeout(int timeoutMs) { motor.setPeriodicFrameTimeout(timeoutMs); } - @Override - public void setReference(double value, SparkBase.ControlType controlType, int pidSlot, double arbFeedForward) { - pidController.setReference(value, controlType, pidSlot, arbFeedForward); - } - - @Override - public void setReference(double value, SparkBase.ControlType controlType, int pidSlot, double arbFeedForward, SparkClosedLoopController.ArbFFUnits arbFeedForwardUnits) { - pidController.setReference(value, controlType, pidSlot, arbFeedForward, arbFeedForwardUnits); - } - @Override public void configure(SparkBaseConfig configuration, SparkBase.ResetMode resetMode, SparkBase.PersistMode persistMode) { motor.configure(configuration, resetMode, persistMode); diff --git a/src/main/java/org/trigon/hardware/rev/spark/io/SimulationSparkIO.java b/src/main/java/org/trigon/hardware/rev/spark/io/SimulationSparkIO.java index 73b6b50a..880e2601 100644 --- a/src/main/java/org/trigon/hardware/rev/spark/io/SimulationSparkIO.java +++ b/src/main/java/org/trigon/hardware/rev/spark/io/SimulationSparkIO.java @@ -34,6 +34,16 @@ public void setReference(double value, SparkBase.ControlType controlType, int pi pidController.setReference(value, controlType, pidSlot); } + @Override + public void setReference(double value, SparkBase.ControlType controlType, int pidSlot, double arbFeedForward) { + pidController.setReference(value, controlType, pidSlot, arbFeedForward); + } + + @Override + public void setReference(double value, SparkBase.ControlType controlType, int pidSlot, double arbFeedForward, SparkClosedLoopController.ArbFFUnits arbFFUnits) { + pidController.setReference(value, controlType, pidSlot, arbFeedForward, arbFFUnits); + } + @Override public SparkEncoder getEncoder() { return encoder; @@ -54,16 +64,6 @@ public void setPeriodicFrameTimeout(int timeoutMs) { motor.setPeriodicFrameTimeout(timeoutMs); } - @Override - public void setReference(double value, SparkBase.ControlType controlType, int pidSlot, double arbFeedForward) { - pidController.setReference(value, controlType, pidSlot, arbFeedForward); - } - - @Override - public void setReference(double value, SparkBase.ControlType controlType, int pidSlot, double arbFeedForward, SparkClosedLoopController.ArbFFUnits arbFFUnits) { - pidController.setReference(value, controlType, pidSlot, arbFeedForward, arbFFUnits); - } - @Override public void setInverted(boolean inverted) { motor.setInverted(inverted); @@ -80,6 +80,7 @@ public void setBrake(boolean brake) { public void updateSimulation() { if (physicsSimulation == null) return; + physicsSimulation.setInputVoltage(motorSimulation.getBusVoltage()); physicsSimulation.updateMotor(); motorSimulation.iterate(physicsSimulation.getSystemVelocityRotationsPerSecond(), RobotHardwareStats.SUPPLY_VOLTAGE, RobotHardwareStats.getPeriodicTimeSeconds()); diff --git a/src/main/java/org/trigon/hardware/simulation/MotorPhysicsSimulation.java b/src/main/java/org/trigon/hardware/simulation/MotorPhysicsSimulation.java index be484160..4e70a186 100644 --- a/src/main/java/org/trigon/hardware/simulation/MotorPhysicsSimulation.java +++ b/src/main/java/org/trigon/hardware/simulation/MotorPhysicsSimulation.java @@ -35,4 +35,4 @@ public DCMotor getGearbox() { public abstract void setInputVoltage(double voltage); public abstract void updateMotor(); -} +} \ No newline at end of file diff --git a/src/main/java/org/trigon/utilities/mirrorable/Mirrorable.java b/src/main/java/org/trigon/utilities/mirrorable/Mirrorable.java index f1d5c1a4..8834109c 100644 --- a/src/main/java/org/trigon/utilities/mirrorable/Mirrorable.java +++ b/src/main/java/org/trigon/utilities/mirrorable/Mirrorable.java @@ -23,11 +23,9 @@ public abstract class Mirrorable { protected final T nonMirroredObject, mirroredObject; protected final boolean shouldMirrorWhenRedAlliance; -// static { -// UPDATE_ALLIANCE_TIMER.start(); -// new Trigger(() -> UPDATE_ALLIANCE_TIMER.advanceIfElapsed(0.5)).onTrue(getUpdateAllianceCommand()); -// } - + /** + * Initializes the mirrorable class. This should be called once in robot container's constructor. + */ public static void init() { UPDATE_ALLIANCE_TIMER.start(); new Trigger(() -> UPDATE_ALLIANCE_TIMER.advanceIfElapsed(0.5)).onTrue(getUpdateAllianceCommand()); From fc9740ad35844fc75f20072da214f4608a42f94e Mon Sep 17 00:00:00 2001 From: Nummun14 <142012009+Nummun14@users.noreply.github.com> Date: Sun, 1 Dec 2024 18:55:10 +0200 Subject: [PATCH 35/61] mirrorable, gyro, cancoder cleanup. SparkSim logic changes --- .../java/org/trigon/hardware/BaseInputs.java | 4 +-- .../phoenix6/cancoder/CANcoderEncoder.java | 2 +- .../phoenix6/pigeon2/Pigeon2Gyro.java | 3 ++- .../pigeon2/io/SimulationPigeon2IO.java | 8 +++--- .../trigon/hardware/rev/spark/SparkIO.java | 2 +- .../trigon/hardware/rev/spark/SparkMotor.java | 7 +++--- .../rev/spark/io/SimulationSparkIO.java | 25 ++++++++++++++++--- .../hardware/simulation/GyroSimulation.java | 8 +++--- .../utilities/mirrorable/Mirrorable.java | 3 ++- 9 files changed, 42 insertions(+), 20 deletions(-) diff --git a/src/main/java/org/trigon/hardware/BaseInputs.java b/src/main/java/org/trigon/hardware/BaseInputs.java index 39faa89c..edf8a9ab 100644 --- a/src/main/java/org/trigon/hardware/BaseInputs.java +++ b/src/main/java/org/trigon/hardware/BaseInputs.java @@ -14,7 +14,7 @@ public abstract class BaseInputs implements LoggableInputs { /** * Creates a new BaseInputs instance. * - * @param name the name of the instance. Used for error messages. + * @param name the name of the instance. Used for error messages */ public BaseInputs(String name) { this.name = name; @@ -50,7 +50,7 @@ public double getSignal(String signalName) { /** * Gets a threaded signal. - * Threaded signals use threading to process certain signals separately at a faster rate + * Threaded signals use threading to process certain signals separately at a faster rate. * * @param signalName the name of the threaded signal * @return the threaded signal diff --git a/src/main/java/org/trigon/hardware/phoenix6/cancoder/CANcoderEncoder.java b/src/main/java/org/trigon/hardware/phoenix6/cancoder/CANcoderEncoder.java index 248705ed..7406bff9 100644 --- a/src/main/java/org/trigon/hardware/phoenix6/cancoder/CANcoderEncoder.java +++ b/src/main/java/org/trigon/hardware/phoenix6/cancoder/CANcoderEncoder.java @@ -61,7 +61,7 @@ public int getID() { } /** - * Sets the simulation inputs of the encoder from a TalonFX motor. + * Sets the TalonFX motor used to supply the encoder's position and velocity values in simulation. * * @param motor the TalonFX motor to get the simulation inputs from */ diff --git a/src/main/java/org/trigon/hardware/phoenix6/pigeon2/Pigeon2Gyro.java b/src/main/java/org/trigon/hardware/phoenix6/pigeon2/Pigeon2Gyro.java index e35c630e..c13d684a 100644 --- a/src/main/java/org/trigon/hardware/phoenix6/pigeon2/Pigeon2Gyro.java +++ b/src/main/java/org/trigon/hardware/phoenix6/pigeon2/Pigeon2Gyro.java @@ -60,7 +60,8 @@ public int getID() { } /** - * Sets the yaw velocity supplier for simulation. + * Sets the yaw velocity supplier used in simulation. + * This is used to calculate the gyro's yaw in simulation by multiplying it by the time since the last update, and adding it to the total yaw. * * @param yawVelocitySupplierDegreesPerSecond the yaw velocity supplier in degrees per second */ diff --git a/src/main/java/org/trigon/hardware/phoenix6/pigeon2/io/SimulationPigeon2IO.java b/src/main/java/org/trigon/hardware/phoenix6/pigeon2/io/SimulationPigeon2IO.java index 78437fe7..425f8a58 100644 --- a/src/main/java/org/trigon/hardware/phoenix6/pigeon2/io/SimulationPigeon2IO.java +++ b/src/main/java/org/trigon/hardware/phoenix6/pigeon2/io/SimulationPigeon2IO.java @@ -14,7 +14,7 @@ public class SimulationPigeon2IO extends Pigeon2IO { private final Pigeon2 pigeon2; private final Pigeon2SimState simState; private final GyroSimulation gyroSimulation; - private DoubleSupplier yawVelocitySupplier = null; + private DoubleSupplier yawVelocitySupplierDegreesPerSecond = null; public SimulationPigeon2IO(int id) { this.pigeon2 = new Pigeon2(id); @@ -24,15 +24,15 @@ public SimulationPigeon2IO(int id) { @Override public void updateGyro() { - if (yawVelocitySupplier == null) + if (yawVelocitySupplierDegreesPerSecond == null) return; - gyroSimulation.update(yawVelocitySupplier.getAsDouble(), RobotHardwareStats.getPeriodicTimeSeconds()); + gyroSimulation.update(yawVelocitySupplierDegreesPerSecond.getAsDouble(), RobotHardwareStats.getPeriodicTimeSeconds()); simState.setRawYaw(gyroSimulation.getGyroYawDegrees()); } @Override public void setSimulationYawVelocitySupplier(DoubleSupplier yawVelocitySupplierDegreesPerSecond) { - this.yawVelocitySupplier = yawVelocitySupplierDegreesPerSecond; + this.yawVelocitySupplierDegreesPerSecond = yawVelocitySupplierDegreesPerSecond; } @Override diff --git a/src/main/java/org/trigon/hardware/rev/spark/SparkIO.java b/src/main/java/org/trigon/hardware/rev/spark/SparkIO.java index 391f3b9f..dcc08759 100644 --- a/src/main/java/org/trigon/hardware/rev/spark/SparkIO.java +++ b/src/main/java/org/trigon/hardware/rev/spark/SparkIO.java @@ -37,7 +37,7 @@ public void setBrake(boolean brake) { public void updateSimulation() { } - public void setPhysicsSimulation(MotorPhysicsSimulation physicsSimulation) { + public void setPhysicsSimulation(MotorPhysicsSimulation physicsSimulation, boolean isUsingAbsoluteEncoder) { } public SparkBase getMotor() { diff --git a/src/main/java/org/trigon/hardware/rev/spark/SparkMotor.java b/src/main/java/org/trigon/hardware/rev/spark/SparkMotor.java index 7ec12142..c15e8d0d 100644 --- a/src/main/java/org/trigon/hardware/rev/spark/SparkMotor.java +++ b/src/main/java/org/trigon/hardware/rev/spark/SparkMotor.java @@ -223,10 +223,11 @@ public void applySimulationConfiguration(SparkBaseConfig simulationConfiguration /** * Sets the physics simulation to be used by the motor. Needs to be called for the motor to work in simulation. * - * @param physicsSimulation the physics simulation to be used + * @param physicsSimulation the physics simulation to be used + * @param isUsingAbsoluteEncoder whether the motor is using a relative encoder or an absolute encoder */ - public void setPhysicsSimulation(MotorPhysicsSimulation physicsSimulation) { - motorIO.setPhysicsSimulation(physicsSimulation); + public void setPhysicsSimulation(MotorPhysicsSimulation physicsSimulation, boolean isUsingAbsoluteEncoder) { + motorIO.setPhysicsSimulation(physicsSimulation, isUsingAbsoluteEncoder); } private SparkIO createSparkIO(int id, SparkType sparkType) { diff --git a/src/main/java/org/trigon/hardware/rev/spark/io/SimulationSparkIO.java b/src/main/java/org/trigon/hardware/rev/spark/io/SimulationSparkIO.java index 880e2601..81398041 100644 --- a/src/main/java/org/trigon/hardware/rev/spark/io/SimulationSparkIO.java +++ b/src/main/java/org/trigon/hardware/rev/spark/io/SimulationSparkIO.java @@ -1,5 +1,7 @@ package org.trigon.hardware.rev.spark.io; +import com.revrobotics.sim.SparkAbsoluteEncoderSim; +import com.revrobotics.sim.SparkRelativeEncoderSim; import com.revrobotics.spark.SparkBase; import com.revrobotics.spark.SparkClosedLoopController; import com.revrobotics.spark.SparkMax; @@ -16,6 +18,8 @@ public class SimulationSparkIO extends SparkIO { private final SparkClosedLoopController pidController; private final SparkEncoder encoder; private SparkSim motorSimulation = null; + private SparkAbsoluteEncoderSim absoluteEncoderSimulation = null; + private SparkRelativeEncoderSim relativeEncoderSimulation = null; private MotorPhysicsSimulation physicsSimulation = null; public SimulationSparkIO(int id) { @@ -80,10 +84,16 @@ public void setBrake(boolean brake) { public void updateSimulation() { if (physicsSimulation == null) return; - + physicsSimulation.setInputVoltage(motorSimulation.getBusVoltage()); physicsSimulation.updateMotor(); - motorSimulation.iterate(physicsSimulation.getSystemVelocityRotationsPerSecond(), RobotHardwareStats.SUPPLY_VOLTAGE, RobotHardwareStats.getPeriodicTimeSeconds()); + + motorSimulation.iterate(physicsSimulation.getRotorVelocityRotationsPerSecond(), RobotHardwareStats.SUPPLY_VOLTAGE, RobotHardwareStats.getPeriodicTimeSeconds()); + if (isUsingAbsoluteEncoder()) { + absoluteEncoderSimulation.iterate(physicsSimulation.getSystemVelocityRotationsPerSecond(), RobotHardwareStats.getPeriodicTimeSeconds()); + return; + } + relativeEncoderSimulation.iterate(physicsSimulation.getRotorVelocityRotationsPerSecond(), RobotHardwareStats.getPeriodicTimeSeconds()); } @Override @@ -92,8 +102,17 @@ public void configure(SparkBaseConfig configuration, SparkBase.ResetMode resetMo } @Override - public void setPhysicsSimulation(MotorPhysicsSimulation physicsSimulation) { + public void setPhysicsSimulation(MotorPhysicsSimulation physicsSimulation, boolean isUsingAbsoluteEncoder) { motorSimulation = new SparkSim(motor, physicsSimulation.getGearbox()); this.physicsSimulation = physicsSimulation; + if (isUsingAbsoluteEncoder) { + absoluteEncoderSimulation = new SparkAbsoluteEncoderSim(motor); + return; + } + relativeEncoderSimulation = new SparkRelativeEncoderSim(motor); + } + + private boolean isUsingAbsoluteEncoder() { + return absoluteEncoderSimulation != null; } } \ No newline at end of file diff --git a/src/main/java/org/trigon/hardware/simulation/GyroSimulation.java b/src/main/java/org/trigon/hardware/simulation/GyroSimulation.java index 021cfd21..89fab2e5 100644 --- a/src/main/java/org/trigon/hardware/simulation/GyroSimulation.java +++ b/src/main/java/org/trigon/hardware/simulation/GyroSimulation.java @@ -6,13 +6,13 @@ * A class that represents a simulation of a gyro sensor. */ public class GyroSimulation { - private double simulationRadians = 0; + private double simulationYawRadians = 0; /** * @return the yaw in degrees */ public double getGyroYawDegrees() { - return Math.toDegrees(simulationRadians); + return Math.toDegrees(simulationYawRadians); } /** @@ -22,7 +22,7 @@ public double getGyroYawDegrees() { * @param timeSeconds the time elapsed in seconds since the last update */ public void update(double omegaRadiansPerSecond, double timeSeconds) { - simulationRadians += omegaRadiansPerSecond * timeSeconds; + simulationYawRadians += omegaRadiansPerSecond * timeSeconds; } /** @@ -31,6 +31,6 @@ public void update(double omegaRadiansPerSecond, double timeSeconds) { * @param heading the yaw to set */ public void setYaw(Rotation2d heading) { - simulationRadians = heading.getRadians(); + simulationYawRadians = heading.getRadians(); } } \ No newline at end of file diff --git a/src/main/java/org/trigon/utilities/mirrorable/Mirrorable.java b/src/main/java/org/trigon/utilities/mirrorable/Mirrorable.java index 8834109c..379e334d 100644 --- a/src/main/java/org/trigon/utilities/mirrorable/Mirrorable.java +++ b/src/main/java/org/trigon/utilities/mirrorable/Mirrorable.java @@ -21,10 +21,11 @@ public abstract class Mirrorable { private static final Timer UPDATE_ALLIANCE_TIMER = new Timer(); private static boolean IS_RED_ALLIANCE = notCachedIsRedAlliance(); protected final T nonMirroredObject, mirroredObject; + protected final boolean shouldMirrorWhenRedAlliance; /** - * Initializes the mirrorable class. This should be called once in robot container's constructor. + * Initializes the mirrorable class. This should be called once in robotContainer. */ public static void init() { UPDATE_ALLIANCE_TIMER.start(); From db6344a700f23be2b5c8962b87d1cb41ce7f2251 Mon Sep 17 00:00:00 2001 From: Nummun14 <142012009+Nummun14@users.noreply.github.com> Date: Sun, 1 Dec 2024 19:30:21 +0200 Subject: [PATCH 36/61] removed redundent if statement, and added temporary debugging stuff for sparksim --- .../hardware/phoenix6/talonfx/io/SimulationTalonFXIO.java | 6 ++---- .../org/trigon/hardware/rev/spark/io/SimulationSparkIO.java | 5 ++++- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/main/java/org/trigon/hardware/phoenix6/talonfx/io/SimulationTalonFXIO.java b/src/main/java/org/trigon/hardware/phoenix6/talonfx/io/SimulationTalonFXIO.java index 2729c0b0..fc66eb11 100644 --- a/src/main/java/org/trigon/hardware/phoenix6/talonfx/io/SimulationTalonFXIO.java +++ b/src/main/java/org/trigon/hardware/phoenix6/talonfx/io/SimulationTalonFXIO.java @@ -45,10 +45,8 @@ protected void setPosition(double positionRotations) { public void applyConfiguration(TalonFXConfiguration configuration) { configuration.MotorOutput.Inverted = InvertedValue.CounterClockwise_Positive; configuration.Feedback.FeedbackSensorSource = FeedbackSensorSourceValue.RotorSensor; - if (configuration.Feedback.RotorToSensorRatio != 1.0) { - configuration.Feedback.SensorToMechanismRatio *= configuration.Feedback.RotorToSensorRatio; - configuration.Feedback.RotorToSensorRatio = 1.0; - } + configuration.Feedback.SensorToMechanismRatio *= configuration.Feedback.RotorToSensorRatio; + configuration.Feedback.RotorToSensorRatio = 1.0; talonFX.getConfigurator().apply(configuration); } diff --git a/src/main/java/org/trigon/hardware/rev/spark/io/SimulationSparkIO.java b/src/main/java/org/trigon/hardware/rev/spark/io/SimulationSparkIO.java index 81398041..753d1700 100644 --- a/src/main/java/org/trigon/hardware/rev/spark/io/SimulationSparkIO.java +++ b/src/main/java/org/trigon/hardware/rev/spark/io/SimulationSparkIO.java @@ -85,8 +85,11 @@ public void updateSimulation() { if (physicsSimulation == null) return; - physicsSimulation.setInputVoltage(motorSimulation.getBusVoltage()); +// physicsSimulation.setInputVoltage(motorSimulation.getAppliedOutput()); + physicsSimulation.setInputVoltage(motor.getBusVoltage()); physicsSimulation.updateMotor(); + System.out.println(motor.getBusVoltage() + " motor bus voltage"); + System.out.println(motor.getAppliedOutput() + " motor applied output"); motorSimulation.iterate(physicsSimulation.getRotorVelocityRotationsPerSecond(), RobotHardwareStats.SUPPLY_VOLTAGE, RobotHardwareStats.getPeriodicTimeSeconds()); if (isUsingAbsoluteEncoder()) { From 1937b8bc4abb38dde54bd95ce29e0144368b46ca Mon Sep 17 00:00:00 2001 From: Nummun14 <142012009+Nummun14@users.noreply.github.com> Date: Mon, 2 Dec 2024 00:07:50 +0200 Subject: [PATCH 37/61] improved jdocs, and changed some SparkSim logic, still doesn't work though --- .../phoenix6/pigeon2/Pigeon2Gyro.java | 2 +- .../talonfx/io/SimulationTalonFXIO.java | 25 +++++++++++++++---- .../rev/spark/io/SimulationSparkIO.java | 10 +++++--- .../hardware/simulation/GyroSimulation.java | 2 +- .../utilities/mirrorable/Mirrorable.java | 2 +- 5 files changed, 29 insertions(+), 12 deletions(-) diff --git a/src/main/java/org/trigon/hardware/phoenix6/pigeon2/Pigeon2Gyro.java b/src/main/java/org/trigon/hardware/phoenix6/pigeon2/Pigeon2Gyro.java index c13d684a..67ae621b 100644 --- a/src/main/java/org/trigon/hardware/phoenix6/pigeon2/Pigeon2Gyro.java +++ b/src/main/java/org/trigon/hardware/phoenix6/pigeon2/Pigeon2Gyro.java @@ -60,7 +60,7 @@ public int getID() { } /** - * Sets the yaw velocity supplier used in simulation. + * Sets the yaw velocity of the robot supplier used in simulation. * This is used to calculate the gyro's yaw in simulation by multiplying it by the time since the last update, and adding it to the total yaw. * * @param yawVelocitySupplierDegreesPerSecond the yaw velocity supplier in degrees per second diff --git a/src/main/java/org/trigon/hardware/phoenix6/talonfx/io/SimulationTalonFXIO.java b/src/main/java/org/trigon/hardware/phoenix6/talonfx/io/SimulationTalonFXIO.java index fc66eb11..d53e503e 100644 --- a/src/main/java/org/trigon/hardware/phoenix6/talonfx/io/SimulationTalonFXIO.java +++ b/src/main/java/org/trigon/hardware/phoenix6/talonfx/io/SimulationTalonFXIO.java @@ -43,11 +43,8 @@ protected void setPosition(double positionRotations) { @Override public void applyConfiguration(TalonFXConfiguration configuration) { - configuration.MotorOutput.Inverted = InvertedValue.CounterClockwise_Positive; - configuration.Feedback.FeedbackSensorSource = FeedbackSensorSourceValue.RotorSensor; - configuration.Feedback.SensorToMechanismRatio *= configuration.Feedback.RotorToSensorRatio; - configuration.Feedback.RotorToSensorRatio = 1.0; - talonFX.getConfigurator().apply(configuration); + final TalonFXConfiguration adaptedConfiguration = adaptConfigurationToSimulation(configuration); + talonFX.getConfigurator().apply(adaptedConfiguration); } @Override @@ -69,4 +66,22 @@ public void setPhysicsSimulation(MotorPhysicsSimulation physicsSimulation) { public TalonFX getTalonFX() { return talonFX; } + + /** + * Adapts the configuration for simulation. There are some setting that don't work well in simulation and need to be adapted. + * The inverted value doesn't affect the simulation, and it can sometimes cause problems so it is always set to CounterClockwise_Positive. + * The feedback sensor source is set to RotorSensor to avoid delays from using a CANCoder that gets its data from the motor anyway. + * We don't use the SensorToMechanismRatio for the same reason as it is only used for remote encoders. + * However, if someone did set a SensorToMechanismRatio, we still want to use it as the gear ratio so we multiply it by the SensorToMechanismRatio. + * + * @param configuration The configuration to adapt + * @return The adapted configuration + */ + private TalonFXConfiguration adaptConfigurationToSimulation(TalonFXConfiguration configuration) { + configuration.MotorOutput.Inverted = InvertedValue.CounterClockwise_Positive; + configuration.Feedback.FeedbackSensorSource = FeedbackSensorSourceValue.RotorSensor; + configuration.Feedback.SensorToMechanismRatio *= configuration.Feedback.RotorToSensorRatio; + configuration.Feedback.RotorToSensorRatio = 1.0; + return configuration; + } } \ No newline at end of file diff --git a/src/main/java/org/trigon/hardware/rev/spark/io/SimulationSparkIO.java b/src/main/java/org/trigon/hardware/rev/spark/io/SimulationSparkIO.java index 753d1700..98efdc8d 100644 --- a/src/main/java/org/trigon/hardware/rev/spark/io/SimulationSparkIO.java +++ b/src/main/java/org/trigon/hardware/rev/spark/io/SimulationSparkIO.java @@ -25,7 +25,7 @@ public class SimulationSparkIO extends SparkIO { public SimulationSparkIO(int id) { motor = new SparkMax(id, SparkMax.MotorType.kBrushless); pidController = motor.getClosedLoopController(); - encoder = SparkEncoder.createRelativeEncoder(motor); + encoder = SparkEncoder.createEncoder(motor); } @Override @@ -106,13 +106,15 @@ public void configure(SparkBaseConfig configuration, SparkBase.ResetMode resetMo @Override public void setPhysicsSimulation(MotorPhysicsSimulation physicsSimulation, boolean isUsingAbsoluteEncoder) { - motorSimulation = new SparkSim(motor, physicsSimulation.getGearbox()); this.physicsSimulation = physicsSimulation; - if (isUsingAbsoluteEncoder) { + if (motorSimulation == null) + motorSimulation = new SparkSim(motor, physicsSimulation.getGearbox()); + if (isUsingAbsoluteEncoder && absoluteEncoderSimulation == null) { absoluteEncoderSimulation = new SparkAbsoluteEncoderSim(motor); return; } - relativeEncoderSimulation = new SparkRelativeEncoderSim(motor); + if (relativeEncoderSimulation == null) + relativeEncoderSimulation = new SparkRelativeEncoderSim(motor); } private boolean isUsingAbsoluteEncoder() { diff --git a/src/main/java/org/trigon/hardware/simulation/GyroSimulation.java b/src/main/java/org/trigon/hardware/simulation/GyroSimulation.java index 89fab2e5..32ff18c3 100644 --- a/src/main/java/org/trigon/hardware/simulation/GyroSimulation.java +++ b/src/main/java/org/trigon/hardware/simulation/GyroSimulation.java @@ -18,7 +18,7 @@ public double getGyroYawDegrees() { /** * Updates the simulation's current angle in radians based on the angular velocity. * - * @param omegaRadiansPerSecond the angular velocity in radians per second + * @param omegaRadiansPerSecond the angular velocity of the robot in radians per second * @param timeSeconds the time elapsed in seconds since the last update */ public void update(double omegaRadiansPerSecond, double timeSeconds) { diff --git a/src/main/java/org/trigon/utilities/mirrorable/Mirrorable.java b/src/main/java/org/trigon/utilities/mirrorable/Mirrorable.java index 379e334d..bcadd29d 100644 --- a/src/main/java/org/trigon/utilities/mirrorable/Mirrorable.java +++ b/src/main/java/org/trigon/utilities/mirrorable/Mirrorable.java @@ -25,7 +25,7 @@ public abstract class Mirrorable { protected final boolean shouldMirrorWhenRedAlliance; /** - * Initializes the mirrorable class. This should be called once in robotContainer. + * Initializes the mirrorable class. This should be called once in RobotContainer. */ public static void init() { UPDATE_ALLIANCE_TIMER.start(); From a69df8a78a94ba979990e6d23ccb5b97cee8ba45 Mon Sep 17 00:00:00 2001 From: Nummun14 <142012009+Nummun14@users.noreply.github.com> Date: Mon, 2 Dec 2024 10:47:28 +0200 Subject: [PATCH 38/61] jdoc and encoder sim --- .../hardware/phoenix6/talonfx/io/SimulationTalonFXIO.java | 6 +++--- .../trigon/hardware/rev/spark/io/SimulationSparkIO.java | 7 +++++-- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/src/main/java/org/trigon/hardware/phoenix6/talonfx/io/SimulationTalonFXIO.java b/src/main/java/org/trigon/hardware/phoenix6/talonfx/io/SimulationTalonFXIO.java index d53e503e..a739a260 100644 --- a/src/main/java/org/trigon/hardware/phoenix6/talonfx/io/SimulationTalonFXIO.java +++ b/src/main/java/org/trigon/hardware/phoenix6/talonfx/io/SimulationTalonFXIO.java @@ -69,13 +69,13 @@ public TalonFX getTalonFX() { /** * Adapts the configuration for simulation. There are some setting that don't work well in simulation and need to be adapted. - * The inverted value doesn't affect the simulation, and it can sometimes cause problems so it is always set to CounterClockwise_Positive. + * There's no reason to use the inverted value in simulation, and it can sometimes cause problems so it is always set to CounterClockwise_Positive. * The feedback sensor source is set to RotorSensor to avoid delays from using a CANCoder that gets its data from the motor anyway. * We don't use the SensorToMechanismRatio for the same reason as it is only used for remote encoders. * However, if someone did set a SensorToMechanismRatio, we still want to use it as the gear ratio so we multiply it by the SensorToMechanismRatio. * - * @param configuration The configuration to adapt - * @return The adapted configuration + * @param configuration the configuration to adapt + * @return the adapted configuration */ private TalonFXConfiguration adaptConfigurationToSimulation(TalonFXConfiguration configuration) { configuration.MotorOutput.Inverted = InvertedValue.CounterClockwise_Positive; diff --git a/src/main/java/org/trigon/hardware/rev/spark/io/SimulationSparkIO.java b/src/main/java/org/trigon/hardware/rev/spark/io/SimulationSparkIO.java index 98efdc8d..6c5e957f 100644 --- a/src/main/java/org/trigon/hardware/rev/spark/io/SimulationSparkIO.java +++ b/src/main/java/org/trigon/hardware/rev/spark/io/SimulationSparkIO.java @@ -16,7 +16,7 @@ public class SimulationSparkIO extends SparkIO { private final SparkMax motor; private final SparkClosedLoopController pidController; - private final SparkEncoder encoder; + private SparkEncoder encoder; private SparkSim motorSimulation = null; private SparkAbsoluteEncoderSim absoluteEncoderSimulation = null; private SparkRelativeEncoderSim relativeEncoderSimulation = null; @@ -111,10 +111,13 @@ public void setPhysicsSimulation(MotorPhysicsSimulation physicsSimulation, boole motorSimulation = new SparkSim(motor, physicsSimulation.getGearbox()); if (isUsingAbsoluteEncoder && absoluteEncoderSimulation == null) { absoluteEncoderSimulation = new SparkAbsoluteEncoderSim(motor); + encoder = SparkEncoder.createEncoder(motor); return; } - if (relativeEncoderSimulation == null) + if (relativeEncoderSimulation == null) { relativeEncoderSimulation = new SparkRelativeEncoderSim(motor); + encoder = SparkEncoder.createRelativeEncoder(motor); + } } private boolean isUsingAbsoluteEncoder() { From 5a080b6a8e729574ffc23e6bb05c12ea7f12f9fc Mon Sep 17 00:00:00 2001 From: Nummun14 <142012009+Nummun14@users.noreply.github.com> Date: Mon, 2 Dec 2024 12:52:53 +0200 Subject: [PATCH 39/61] sim encoder logic stuff. Sim still isn't working --- .../rev/spark/io/SimulationSparkIO.java | 25 +++++++++++++------ .../rev/sparkecnoder/SparkEncoder.java | 4 +++ 2 files changed, 22 insertions(+), 7 deletions(-) diff --git a/src/main/java/org/trigon/hardware/rev/spark/io/SimulationSparkIO.java b/src/main/java/org/trigon/hardware/rev/spark/io/SimulationSparkIO.java index 6c5e957f..405a6879 100644 --- a/src/main/java/org/trigon/hardware/rev/spark/io/SimulationSparkIO.java +++ b/src/main/java/org/trigon/hardware/rev/spark/io/SimulationSparkIO.java @@ -21,6 +21,7 @@ public class SimulationSparkIO extends SparkIO { private SparkAbsoluteEncoderSim absoluteEncoderSimulation = null; private SparkRelativeEncoderSim relativeEncoderSimulation = null; private MotorPhysicsSimulation physicsSimulation = null; + private boolean isUsingAbsoluteEncoder = false; public SimulationSparkIO(int id) { motor = new SparkMax(id, SparkMax.MotorType.kBrushless); @@ -107,20 +108,30 @@ public void configure(SparkBaseConfig configuration, SparkBase.ResetMode resetMo @Override public void setPhysicsSimulation(MotorPhysicsSimulation physicsSimulation, boolean isUsingAbsoluteEncoder) { this.physicsSimulation = physicsSimulation; + this.isUsingAbsoluteEncoder = isUsingAbsoluteEncoder; + if (motorSimulation == null) motorSimulation = new SparkSim(motor, physicsSimulation.getGearbox()); + if (isUsingAbsoluteEncoder && absoluteEncoderSimulation == null) { - absoluteEncoderSimulation = new SparkAbsoluteEncoderSim(motor); - encoder = SparkEncoder.createEncoder(motor); + createAbsoluteEncoderSimulation(); return; } - if (relativeEncoderSimulation == null) { - relativeEncoderSimulation = new SparkRelativeEncoderSim(motor); - encoder = SparkEncoder.createRelativeEncoder(motor); - } + if (relativeEncoderSimulation == null) + createRelativeEncoderSimulation(); + } + + private void createAbsoluteEncoderSimulation() { + absoluteEncoderSimulation = new SparkAbsoluteEncoderSim(motor); + encoder = SparkEncoder.createAbsoluteEncoder(motor); + } + + private void createRelativeEncoderSimulation() { + relativeEncoderSimulation = new SparkRelativeEncoderSim(motor); + encoder = SparkEncoder.createRelativeEncoder(motor); } private boolean isUsingAbsoluteEncoder() { - return absoluteEncoderSimulation != null; + return isUsingAbsoluteEncoder; } } \ No newline at end of file diff --git a/src/main/java/org/trigon/hardware/rev/sparkecnoder/SparkEncoder.java b/src/main/java/org/trigon/hardware/rev/sparkecnoder/SparkEncoder.java index 4b586e72..5d148dec 100644 --- a/src/main/java/org/trigon/hardware/rev/sparkecnoder/SparkEncoder.java +++ b/src/main/java/org/trigon/hardware/rev/sparkecnoder/SparkEncoder.java @@ -22,6 +22,10 @@ public static SparkEncoder createRelativeEncoder(SparkBase spark) { return new RelativeSparkEncoder(spark.getEncoder()); } + public static SparkEncoder createAbsoluteEncoder(SparkBase spark) { + return new AbsoluteSparkEncoder(spark.getAbsoluteEncoder()); + } + public abstract double getPosition(); public abstract double getVelocity(); From bebb7df17063bd8d2bc3a043c07b78898dfd8400 Mon Sep 17 00:00:00 2001 From: Nummun14 <142012009+Nummun14@users.noreply.github.com> Date: Mon, 2 Dec 2024 14:05:18 +0200 Subject: [PATCH 40/61] debugging --- .../hardware/rev/spark/io/SimulationSparkIO.java | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/main/java/org/trigon/hardware/rev/spark/io/SimulationSparkIO.java b/src/main/java/org/trigon/hardware/rev/spark/io/SimulationSparkIO.java index 405a6879..ad552277 100644 --- a/src/main/java/org/trigon/hardware/rev/spark/io/SimulationSparkIO.java +++ b/src/main/java/org/trigon/hardware/rev/spark/io/SimulationSparkIO.java @@ -26,7 +26,6 @@ public class SimulationSparkIO extends SparkIO { public SimulationSparkIO(int id) { motor = new SparkMax(id, SparkMax.MotorType.kBrushless); pidController = motor.getClosedLoopController(); - encoder = SparkEncoder.createEncoder(motor); } @Override @@ -45,8 +44,8 @@ public void setReference(double value, SparkBase.ControlType controlType, int pi } @Override - public void setReference(double value, SparkBase.ControlType controlType, int pidSlot, double arbFeedForward, SparkClosedLoopController.ArbFFUnits arbFFUnits) { - pidController.setReference(value, controlType, pidSlot, arbFeedForward, arbFFUnits); + public void setReference(double value, SparkBase.ControlType controlType, int pidSlot, double arbFeedForward, SparkClosedLoopController.ArbFFUnits arbFeedForwardUnits) { + pidController.setReference(value, controlType, pidSlot, arbFeedForward, arbFeedForwardUnits); } @Override @@ -87,10 +86,12 @@ public void updateSimulation() { return; // physicsSimulation.setInputVoltage(motorSimulation.getAppliedOutput()); - physicsSimulation.setInputVoltage(motor.getBusVoltage()); + physicsSimulation.setInputVoltage(motorSimulation.getBusVoltage() * motorSimulation.getAppliedOutput()); physicsSimulation.updateMotor(); System.out.println(motor.getBusVoltage() + " motor bus voltage"); + System.out.println(motorSimulation.getBusVoltage() + "motor simulation bus voltage"); System.out.println(motor.getAppliedOutput() + " motor applied output"); + System.out.println(motorSimulation.getAppliedOutput() + " motor simulation applied output"); motorSimulation.iterate(physicsSimulation.getRotorVelocityRotationsPerSecond(), RobotHardwareStats.SUPPLY_VOLTAGE, RobotHardwareStats.getPeriodicTimeSeconds()); if (isUsingAbsoluteEncoder()) { @@ -122,12 +123,12 @@ public void setPhysicsSimulation(MotorPhysicsSimulation physicsSimulation, boole } private void createAbsoluteEncoderSimulation() { - absoluteEncoderSimulation = new SparkAbsoluteEncoderSim(motor); + absoluteEncoderSimulation = motorSimulation.getAbsoluteEncoderSim(); encoder = SparkEncoder.createAbsoluteEncoder(motor); } private void createRelativeEncoderSimulation() { - relativeEncoderSimulation = new SparkRelativeEncoderSim(motor); + relativeEncoderSimulation = motorSimulation.getRelativeEncoderSim(); encoder = SparkEncoder.createRelativeEncoder(motor); } From b9159e98dccd17a725cd1876191ff042f788752c Mon Sep 17 00:00:00 2001 From: Nummun14 <142012009+Nummun14@users.noreply.github.com> Date: Mon, 2 Dec 2024 16:14:53 +0200 Subject: [PATCH 41/61] whitespaces and cleaning --- .../phoenix6/talonfx/io/SimulationTalonFXIO.java | 2 ++ .../hardware/rev/spark/io/SimulationSparkIO.java | 12 ++++++------ 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/src/main/java/org/trigon/hardware/phoenix6/talonfx/io/SimulationTalonFXIO.java b/src/main/java/org/trigon/hardware/phoenix6/talonfx/io/SimulationTalonFXIO.java index a739a260..95cbc21c 100644 --- a/src/main/java/org/trigon/hardware/phoenix6/talonfx/io/SimulationTalonFXIO.java +++ b/src/main/java/org/trigon/hardware/phoenix6/talonfx/io/SimulationTalonFXIO.java @@ -25,8 +25,10 @@ public SimulationTalonFXIO(int id) { public void updateMotor() { if (physicsSimulation == null) return; + physicsSimulation.setInputVoltage(motorSimState.getMotorVoltage()); physicsSimulation.updateMotor(); + motorSimState.setRawRotorPosition(physicsSimulation.getRotorPositionRotations()); motorSimState.setRotorVelocity(physicsSimulation.getRotorVelocityRotationsPerSecond()); } diff --git a/src/main/java/org/trigon/hardware/rev/spark/io/SimulationSparkIO.java b/src/main/java/org/trigon/hardware/rev/spark/io/SimulationSparkIO.java index ad552277..040d90c7 100644 --- a/src/main/java/org/trigon/hardware/rev/spark/io/SimulationSparkIO.java +++ b/src/main/java/org/trigon/hardware/rev/spark/io/SimulationSparkIO.java @@ -21,7 +21,6 @@ public class SimulationSparkIO extends SparkIO { private SparkAbsoluteEncoderSim absoluteEncoderSimulation = null; private SparkRelativeEncoderSim relativeEncoderSimulation = null; private MotorPhysicsSimulation physicsSimulation = null; - private boolean isUsingAbsoluteEncoder = false; public SimulationSparkIO(int id) { motor = new SparkMax(id, SparkMax.MotorType.kBrushless); @@ -75,7 +74,7 @@ public void setInverted(boolean inverted) { @Override public void setBrake(boolean brake) { - SparkMaxConfig configuration = new SparkMaxConfig(); + final SparkMaxConfig configuration = new SparkMaxConfig(); configuration.idleMode(brake ? SparkMaxConfig.IdleMode.kBrake : SparkMaxConfig.IdleMode.kCoast); motor.configure(configuration, SparkBase.ResetMode.kNoResetSafeParameters, SparkBase.PersistMode.kNoPersistParameters); } @@ -84,10 +83,10 @@ public void setBrake(boolean brake) { public void updateSimulation() { if (physicsSimulation == null) return; - -// physicsSimulation.setInputVoltage(motorSimulation.getAppliedOutput()); + physicsSimulation.setInputVoltage(motorSimulation.getBusVoltage() * motorSimulation.getAppliedOutput()); physicsSimulation.updateMotor(); + System.out.println(motor.getBusVoltage() + " motor bus voltage"); System.out.println(motorSimulation.getBusVoltage() + "motor simulation bus voltage"); System.out.println(motor.getAppliedOutput() + " motor applied output"); @@ -109,17 +108,18 @@ public void configure(SparkBaseConfig configuration, SparkBase.ResetMode resetMo @Override public void setPhysicsSimulation(MotorPhysicsSimulation physicsSimulation, boolean isUsingAbsoluteEncoder) { this.physicsSimulation = physicsSimulation; - this.isUsingAbsoluteEncoder = isUsingAbsoluteEncoder; if (motorSimulation == null) motorSimulation = new SparkSim(motor, physicsSimulation.getGearbox()); if (isUsingAbsoluteEncoder && absoluteEncoderSimulation == null) { createAbsoluteEncoderSimulation(); + relativeEncoderSimulation = null; return; } if (relativeEncoderSimulation == null) createRelativeEncoderSimulation(); + absoluteEncoderSimulation = null; } private void createAbsoluteEncoderSimulation() { @@ -133,6 +133,6 @@ private void createRelativeEncoderSimulation() { } private boolean isUsingAbsoluteEncoder() { - return isUsingAbsoluteEncoder; + return absoluteEncoderSimulation != null; } } \ No newline at end of file From 6eb137cb563f74c56039eda6bd6943ea82d93429 Mon Sep 17 00:00:00 2001 From: Nummun14 <142012009+Nummun14@users.noreply.github.com> Date: Mon, 2 Dec 2024 16:53:29 +0200 Subject: [PATCH 42/61] added debugging sout --- .../org/trigon/hardware/rev/spark/io/SimulationSparkIO.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/trigon/hardware/rev/spark/io/SimulationSparkIO.java b/src/main/java/org/trigon/hardware/rev/spark/io/SimulationSparkIO.java index 040d90c7..113c0c6a 100644 --- a/src/main/java/org/trigon/hardware/rev/spark/io/SimulationSparkIO.java +++ b/src/main/java/org/trigon/hardware/rev/spark/io/SimulationSparkIO.java @@ -83,7 +83,7 @@ public void setBrake(boolean brake) { public void updateSimulation() { if (physicsSimulation == null) return; - + physicsSimulation.setInputVoltage(motorSimulation.getBusVoltage() * motorSimulation.getAppliedOutput()); physicsSimulation.updateMotor(); @@ -113,6 +113,7 @@ public void setPhysicsSimulation(MotorPhysicsSimulation physicsSimulation, boole motorSimulation = new SparkSim(motor, physicsSimulation.getGearbox()); if (isUsingAbsoluteEncoder && absoluteEncoderSimulation == null) { + System.out.println("create absolute encoder simulation"); createAbsoluteEncoderSimulation(); relativeEncoderSimulation = null; return; From e656f2c29ababa4849e00f7c1a9a0b1d990b8c49 Mon Sep 17 00:00:00 2001 From: Nummun14 <142012009+Nummun14@users.noreply.github.com> Date: Mon, 2 Dec 2024 17:09:05 +0200 Subject: [PATCH 43/61] more souts --- .../org/trigon/hardware/rev/spark/io/SimulationSparkIO.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/main/java/org/trigon/hardware/rev/spark/io/SimulationSparkIO.java b/src/main/java/org/trigon/hardware/rev/spark/io/SimulationSparkIO.java index 113c0c6a..5e452e6e 100644 --- a/src/main/java/org/trigon/hardware/rev/spark/io/SimulationSparkIO.java +++ b/src/main/java/org/trigon/hardware/rev/spark/io/SimulationSparkIO.java @@ -125,7 +125,9 @@ public void setPhysicsSimulation(MotorPhysicsSimulation physicsSimulation, boole private void createAbsoluteEncoderSimulation() { absoluteEncoderSimulation = motorSimulation.getAbsoluteEncoderSim(); + System.out.println(absoluteEncoderSimulation.toString()); encoder = SparkEncoder.createAbsoluteEncoder(motor); + System.out.println(encoder); } private void createRelativeEncoderSimulation() { From 6a206a0b9e915ea6c58c8ae619794ff33f8fe5ea Mon Sep 17 00:00:00 2001 From: Nummun14 <142012009+Nummun14@users.noreply.github.com> Date: Mon, 2 Dec 2024 18:30:53 +0200 Subject: [PATCH 44/61] logging --- .../hardware/rev/spark/io/SimulationSparkIO.java | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/main/java/org/trigon/hardware/rev/spark/io/SimulationSparkIO.java b/src/main/java/org/trigon/hardware/rev/spark/io/SimulationSparkIO.java index 5e452e6e..57d27be3 100644 --- a/src/main/java/org/trigon/hardware/rev/spark/io/SimulationSparkIO.java +++ b/src/main/java/org/trigon/hardware/rev/spark/io/SimulationSparkIO.java @@ -8,6 +8,7 @@ import com.revrobotics.spark.SparkSim; import com.revrobotics.spark.config.SparkBaseConfig; import com.revrobotics.spark.config.SparkMaxConfig; +import org.littletonrobotics.junction.Logger; import org.trigon.hardware.RobotHardwareStats; import org.trigon.hardware.rev.spark.SparkIO; import org.trigon.hardware.rev.sparkecnoder.SparkEncoder; @@ -87,10 +88,8 @@ public void updateSimulation() { physicsSimulation.setInputVoltage(motorSimulation.getBusVoltage() * motorSimulation.getAppliedOutput()); physicsSimulation.updateMotor(); - System.out.println(motor.getBusVoltage() + " motor bus voltage"); - System.out.println(motorSimulation.getBusVoltage() + "motor simulation bus voltage"); - System.out.println(motor.getAppliedOutput() + " motor applied output"); - System.out.println(motorSimulation.getAppliedOutput() + " motor simulation applied output"); + Logger.recordOutput("motor simulation applied output", motorSimulation.getAppliedOutput()); + Logger.recordOutput("velocity" + motor.getDeviceId(), physicsSimulation.getRotorVelocityRotationsPerSecond()); motorSimulation.iterate(physicsSimulation.getRotorVelocityRotationsPerSecond(), RobotHardwareStats.SUPPLY_VOLTAGE, RobotHardwareStats.getPeriodicTimeSeconds()); if (isUsingAbsoluteEncoder()) { @@ -115,12 +114,10 @@ public void setPhysicsSimulation(MotorPhysicsSimulation physicsSimulation, boole if (isUsingAbsoluteEncoder && absoluteEncoderSimulation == null) { System.out.println("create absolute encoder simulation"); createAbsoluteEncoderSimulation(); - relativeEncoderSimulation = null; return; } if (relativeEncoderSimulation == null) createRelativeEncoderSimulation(); - absoluteEncoderSimulation = null; } private void createAbsoluteEncoderSimulation() { @@ -128,11 +125,13 @@ private void createAbsoluteEncoderSimulation() { System.out.println(absoluteEncoderSimulation.toString()); encoder = SparkEncoder.createAbsoluteEncoder(motor); System.out.println(encoder); + relativeEncoderSimulation = null; } private void createRelativeEncoderSimulation() { relativeEncoderSimulation = motorSimulation.getRelativeEncoderSim(); encoder = SparkEncoder.createRelativeEncoder(motor); + absoluteEncoderSimulation = null; } private boolean isUsingAbsoluteEncoder() { From c23adcd21c61fd064b6a966d8e304cb343cd2c0c Mon Sep 17 00:00:00 2001 From: Nummun14 <142012009+Nummun14@users.noreply.github.com> Date: Mon, 2 Dec 2024 18:33:45 +0200 Subject: [PATCH 45/61] id --- .../org/trigon/hardware/rev/spark/io/SimulationSparkIO.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/org/trigon/hardware/rev/spark/io/SimulationSparkIO.java b/src/main/java/org/trigon/hardware/rev/spark/io/SimulationSparkIO.java index 57d27be3..02a5ae35 100644 --- a/src/main/java/org/trigon/hardware/rev/spark/io/SimulationSparkIO.java +++ b/src/main/java/org/trigon/hardware/rev/spark/io/SimulationSparkIO.java @@ -88,7 +88,7 @@ public void updateSimulation() { physicsSimulation.setInputVoltage(motorSimulation.getBusVoltage() * motorSimulation.getAppliedOutput()); physicsSimulation.updateMotor(); - Logger.recordOutput("motor simulation applied output", motorSimulation.getAppliedOutput()); + Logger.recordOutput("motor simulation applied output" + motor.getDeviceId(), motorSimulation.getAppliedOutput()); Logger.recordOutput("velocity" + motor.getDeviceId(), physicsSimulation.getRotorVelocityRotationsPerSecond()); motorSimulation.iterate(physicsSimulation.getRotorVelocityRotationsPerSecond(), RobotHardwareStats.SUPPLY_VOLTAGE, RobotHardwareStats.getPeriodicTimeSeconds()); From 63af5a55bea6c54b8203d395d7a580750a4bd2e0 Mon Sep 17 00:00:00 2001 From: Nummun14 <142012009+Nummun14@users.noreply.github.com> Date: Mon, 2 Dec 2024 18:46:49 +0200 Subject: [PATCH 46/61] print --- .../java/org/trigon/hardware/rev/spark/io/SimulationSparkIO.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/java/org/trigon/hardware/rev/spark/io/SimulationSparkIO.java b/src/main/java/org/trigon/hardware/rev/spark/io/SimulationSparkIO.java index 02a5ae35..cbce06c0 100644 --- a/src/main/java/org/trigon/hardware/rev/spark/io/SimulationSparkIO.java +++ b/src/main/java/org/trigon/hardware/rev/spark/io/SimulationSparkIO.java @@ -93,6 +93,7 @@ public void updateSimulation() { motorSimulation.iterate(physicsSimulation.getRotorVelocityRotationsPerSecond(), RobotHardwareStats.SUPPLY_VOLTAGE, RobotHardwareStats.getPeriodicTimeSeconds()); if (isUsingAbsoluteEncoder()) { + System.out.println("absolute encoder simulation iterate"); absoluteEncoderSimulation.iterate(physicsSimulation.getSystemVelocityRotationsPerSecond(), RobotHardwareStats.getPeriodicTimeSeconds()); return; } From f3eb6b404ef0a20ddeb1dc1f67732cf228e1be7c Mon Sep 17 00:00:00 2001 From: Nummun14 <142012009+Nummun14@users.noreply.github.com> Date: Mon, 2 Dec 2024 19:16:21 +0200 Subject: [PATCH 47/61] sout --- .../java/org/trigon/hardware/rev/spark/io/SimulationSparkIO.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/java/org/trigon/hardware/rev/spark/io/SimulationSparkIO.java b/src/main/java/org/trigon/hardware/rev/spark/io/SimulationSparkIO.java index cbce06c0..b436d31a 100644 --- a/src/main/java/org/trigon/hardware/rev/spark/io/SimulationSparkIO.java +++ b/src/main/java/org/trigon/hardware/rev/spark/io/SimulationSparkIO.java @@ -31,6 +31,7 @@ public SimulationSparkIO(int id) { @Override public void setReference(double value, SparkBase.ControlType controlType) { pidController.setReference(value, controlType); + System.out.println(value + "set reference"); } @Override From 4705de9dc0a116291c8b7ba9deb3e1b0546b9b2a Mon Sep 17 00:00:00 2001 From: Nummun14 <142012009+Nummun14@users.noreply.github.com> Date: Mon, 2 Dec 2024 19:32:51 +0200 Subject: [PATCH 48/61] * 60 --- .../hardware/rev/spark/io/SimulationSparkIO.java | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/src/main/java/org/trigon/hardware/rev/spark/io/SimulationSparkIO.java b/src/main/java/org/trigon/hardware/rev/spark/io/SimulationSparkIO.java index b436d31a..876fa2c8 100644 --- a/src/main/java/org/trigon/hardware/rev/spark/io/SimulationSparkIO.java +++ b/src/main/java/org/trigon/hardware/rev/spark/io/SimulationSparkIO.java @@ -30,23 +30,23 @@ public SimulationSparkIO(int id) { @Override public void setReference(double value, SparkBase.ControlType controlType) { - pidController.setReference(value, controlType); + motor.setVoltage(value); System.out.println(value + "set reference"); } @Override public void setReference(double value, SparkBase.ControlType controlType, int pidSlot) { - pidController.setReference(value, controlType, pidSlot); +// pidController.setReference(value, controlType, pidSlot); } @Override public void setReference(double value, SparkBase.ControlType controlType, int pidSlot, double arbFeedForward) { - pidController.setReference(value, controlType, pidSlot, arbFeedForward); +// pidController.setReference(value, controlType, pidSlot, arbFeedForward); } @Override public void setReference(double value, SparkBase.ControlType controlType, int pidSlot, double arbFeedForward, SparkClosedLoopController.ArbFFUnits arbFeedForwardUnits) { - pidController.setReference(value, controlType, pidSlot, arbFeedForward, arbFeedForwardUnits); +// pidController.setReference(value, controlType, pidSlot, arbFeedForward, arbFeedForwardUnits); } @Override @@ -92,13 +92,13 @@ public void updateSimulation() { Logger.recordOutput("motor simulation applied output" + motor.getDeviceId(), motorSimulation.getAppliedOutput()); Logger.recordOutput("velocity" + motor.getDeviceId(), physicsSimulation.getRotorVelocityRotationsPerSecond()); - motorSimulation.iterate(physicsSimulation.getRotorVelocityRotationsPerSecond(), RobotHardwareStats.SUPPLY_VOLTAGE, RobotHardwareStats.getPeriodicTimeSeconds()); + motorSimulation.iterate(physicsSimulation.getRotorVelocityRotationsPerSecond() * 60, RobotHardwareStats.SUPPLY_VOLTAGE, RobotHardwareStats.getPeriodicTimeSeconds()); if (isUsingAbsoluteEncoder()) { System.out.println("absolute encoder simulation iterate"); - absoluteEncoderSimulation.iterate(physicsSimulation.getSystemVelocityRotationsPerSecond(), RobotHardwareStats.getPeriodicTimeSeconds()); + absoluteEncoderSimulation.iterate(physicsSimulation.getSystemVelocityRotationsPerSecond() * 60, RobotHardwareStats.getPeriodicTimeSeconds()); return; } - relativeEncoderSimulation.iterate(physicsSimulation.getRotorVelocityRotationsPerSecond(), RobotHardwareStats.getPeriodicTimeSeconds()); + relativeEncoderSimulation.iterate(physicsSimulation.getRotorVelocityRotationsPerSecond() * 60, RobotHardwareStats.getPeriodicTimeSeconds()); } @Override @@ -126,7 +126,6 @@ private void createAbsoluteEncoderSimulation() { absoluteEncoderSimulation = motorSimulation.getAbsoluteEncoderSim(); System.out.println(absoluteEncoderSimulation.toString()); encoder = SparkEncoder.createAbsoluteEncoder(motor); - System.out.println(encoder); relativeEncoderSimulation = null; } From ce72ae138605d38ad6ca604156a2c534195b4c19 Mon Sep 17 00:00:00 2001 From: Nummun14 <142012009+Nummun14@users.noreply.github.com> Date: Mon, 2 Dec 2024 19:41:56 +0200 Subject: [PATCH 49/61] units. Also, Yishai you really never tested the code --- .../hardware/rev/spark/io/SimulationSparkIO.java | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/main/java/org/trigon/hardware/rev/spark/io/SimulationSparkIO.java b/src/main/java/org/trigon/hardware/rev/spark/io/SimulationSparkIO.java index 876fa2c8..e2dced3c 100644 --- a/src/main/java/org/trigon/hardware/rev/spark/io/SimulationSparkIO.java +++ b/src/main/java/org/trigon/hardware/rev/spark/io/SimulationSparkIO.java @@ -8,6 +8,7 @@ import com.revrobotics.spark.SparkSim; import com.revrobotics.spark.config.SparkBaseConfig; import com.revrobotics.spark.config.SparkMaxConfig; +import edu.wpi.first.math.system.plant.DCMotor; import org.littletonrobotics.junction.Logger; import org.trigon.hardware.RobotHardwareStats; import org.trigon.hardware.rev.spark.SparkIO; @@ -16,15 +17,16 @@ public class SimulationSparkIO extends SparkIO { private final SparkMax motor; + private final SparkSim motorSimulation; private final SparkClosedLoopController pidController; - private SparkEncoder encoder; - private SparkSim motorSimulation = null; + private SparkEncoder encoder = null; private SparkAbsoluteEncoderSim absoluteEncoderSimulation = null; private SparkRelativeEncoderSim relativeEncoderSimulation = null; private MotorPhysicsSimulation physicsSimulation = null; public SimulationSparkIO(int id) { motor = new SparkMax(id, SparkMax.MotorType.kBrushless); + motorSimulation = new SparkSim(motor, DCMotor.getBag(1)); // DCMotor.getBag(1) is a placeholder, we don't actually care about this since we always do link to setCurrent pidController = motor.getClosedLoopController(); } @@ -92,13 +94,14 @@ public void updateSimulation() { Logger.recordOutput("motor simulation applied output" + motor.getDeviceId(), motorSimulation.getAppliedOutput()); Logger.recordOutput("velocity" + motor.getDeviceId(), physicsSimulation.getRotorVelocityRotationsPerSecond()); - motorSimulation.iterate(physicsSimulation.getRotorVelocityRotationsPerSecond() * 60, RobotHardwareStats.SUPPLY_VOLTAGE, RobotHardwareStats.getPeriodicTimeSeconds()); + motorSimulation.iterate(physicsSimulation.getRotorVelocityRotationsPerSecond() * 60 * motor.configAccessor.encoder.getVelocityConversionFactor(), RobotHardwareStats.SUPPLY_VOLTAGE, RobotHardwareStats.getPeriodicTimeSeconds()); + motorSimulation.setMotorCurrent(physicsSimulation.getCurrent()); if (isUsingAbsoluteEncoder()) { System.out.println("absolute encoder simulation iterate"); - absoluteEncoderSimulation.iterate(physicsSimulation.getSystemVelocityRotationsPerSecond() * 60, RobotHardwareStats.getPeriodicTimeSeconds()); + absoluteEncoderSimulation.iterate(physicsSimulation.getSystemVelocityRotationsPerSecond() * 60 * motor.configAccessor.encoder.getVelocityConversionFactor(), RobotHardwareStats.getPeriodicTimeSeconds()); return; } - relativeEncoderSimulation.iterate(physicsSimulation.getRotorVelocityRotationsPerSecond() * 60, RobotHardwareStats.getPeriodicTimeSeconds()); + relativeEncoderSimulation.iterate(physicsSimulation.getRotorVelocityRotationsPerSecond() * 60 * motor.configAccessor.encoder.getVelocityConversionFactor(), RobotHardwareStats.getPeriodicTimeSeconds()); } @Override @@ -110,9 +113,6 @@ public void configure(SparkBaseConfig configuration, SparkBase.ResetMode resetMo public void setPhysicsSimulation(MotorPhysicsSimulation physicsSimulation, boolean isUsingAbsoluteEncoder) { this.physicsSimulation = physicsSimulation; - if (motorSimulation == null) - motorSimulation = new SparkSim(motor, physicsSimulation.getGearbox()); - if (isUsingAbsoluteEncoder && absoluteEncoderSimulation == null) { System.out.println("create absolute encoder simulation"); createAbsoluteEncoderSimulation(); From 5d6ce1d8462fb22ee7fcec6fc734a975621b5634 Mon Sep 17 00:00:00 2001 From: Nummun14 <142012009+Nummun14@users.noreply.github.com> Date: Mon, 2 Dec 2024 19:56:13 +0200 Subject: [PATCH 50/61] docs and logs --- src/main/java/org/trigon/hardware/RobotHardwareStats.java | 2 +- .../org/trigon/hardware/rev/spark/io/SimulationSparkIO.java | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/main/java/org/trigon/hardware/RobotHardwareStats.java b/src/main/java/org/trigon/hardware/RobotHardwareStats.java index 12e6be74..6ddb69dd 100644 --- a/src/main/java/org/trigon/hardware/RobotHardwareStats.java +++ b/src/main/java/org/trigon/hardware/RobotHardwareStats.java @@ -38,7 +38,7 @@ public static void setPeriodicTimeSeconds(double periodicTimeSeconds) { } /** - * @return the periodic time in seconds + * @return the periodic time in seconds set in {@link #setPeriodicTimeSeconds(double)} */ public static double getPeriodicTimeSeconds() { return PERIODIC_TIME_SECONDS; diff --git a/src/main/java/org/trigon/hardware/rev/spark/io/SimulationSparkIO.java b/src/main/java/org/trigon/hardware/rev/spark/io/SimulationSparkIO.java index e2dced3c..a28248bd 100644 --- a/src/main/java/org/trigon/hardware/rev/spark/io/SimulationSparkIO.java +++ b/src/main/java/org/trigon/hardware/rev/spark/io/SimulationSparkIO.java @@ -26,7 +26,7 @@ public class SimulationSparkIO extends SparkIO { public SimulationSparkIO(int id) { motor = new SparkMax(id, SparkMax.MotorType.kBrushless); - motorSimulation = new SparkSim(motor, DCMotor.getBag(1)); // DCMotor.getBag(1) is a placeholder, we don't actually care about this since we always do link to setCurrent + motorSimulation = new SparkSim(motor, DCMotor.getBag(1)); /** DCMotor.getBag(1) is a placeholder, we don't actually care about this since we always do link to {@link com.revrobotics.sim.SparkMaxSim#setMotorCurrent(double)} */ pidController = motor.getClosedLoopController(); } @@ -93,11 +93,12 @@ public void updateSimulation() { Logger.recordOutput("motor simulation applied output" + motor.getDeviceId(), motorSimulation.getAppliedOutput()); Logger.recordOutput("velocity" + motor.getDeviceId(), physicsSimulation.getRotorVelocityRotationsPerSecond()); + Logger.recordOutput("system velocity" + motor.getDeviceId(), physicsSimulation.getSystemVelocityRotationsPerSecond()); + Logger.recordOutput("rotor velocity" + motor.getDeviceId(), physicsSimulation.getRotorVelocityRotationsPerSecond()); motorSimulation.iterate(physicsSimulation.getRotorVelocityRotationsPerSecond() * 60 * motor.configAccessor.encoder.getVelocityConversionFactor(), RobotHardwareStats.SUPPLY_VOLTAGE, RobotHardwareStats.getPeriodicTimeSeconds()); motorSimulation.setMotorCurrent(physicsSimulation.getCurrent()); if (isUsingAbsoluteEncoder()) { - System.out.println("absolute encoder simulation iterate"); absoluteEncoderSimulation.iterate(physicsSimulation.getSystemVelocityRotationsPerSecond() * 60 * motor.configAccessor.encoder.getVelocityConversionFactor(), RobotHardwareStats.getPeriodicTimeSeconds()); return; } From aa951f67a2b24dc4eba247e93f0679122c7b1168 Mon Sep 17 00:00:00 2001 From: Nummun14 <142012009+Nummun14@users.noreply.github.com> Date: Mon, 2 Dec 2024 20:32:38 +0200 Subject: [PATCH 51/61] changed encoder logic stuff --- .../rev/spark/io/SimulationSparkIO.java | 32 +++++-------------- 1 file changed, 8 insertions(+), 24 deletions(-) diff --git a/src/main/java/org/trigon/hardware/rev/spark/io/SimulationSparkIO.java b/src/main/java/org/trigon/hardware/rev/spark/io/SimulationSparkIO.java index a28248bd..0a5e903a 100644 --- a/src/main/java/org/trigon/hardware/rev/spark/io/SimulationSparkIO.java +++ b/src/main/java/org/trigon/hardware/rev/spark/io/SimulationSparkIO.java @@ -1,7 +1,6 @@ package org.trigon.hardware.rev.spark.io; import com.revrobotics.sim.SparkAbsoluteEncoderSim; -import com.revrobotics.sim.SparkRelativeEncoderSim; import com.revrobotics.spark.SparkBase; import com.revrobotics.spark.SparkClosedLoopController; import com.revrobotics.spark.SparkMax; @@ -19,15 +18,16 @@ public class SimulationSparkIO extends SparkIO { private final SparkMax motor; private final SparkSim motorSimulation; private final SparkClosedLoopController pidController; + private final SparkAbsoluteEncoderSim absoluteEncoderSimulation; private SparkEncoder encoder = null; - private SparkAbsoluteEncoderSim absoluteEncoderSimulation = null; - private SparkRelativeEncoderSim relativeEncoderSimulation = null; private MotorPhysicsSimulation physicsSimulation = null; + private boolean isUsingAbsoluteEncoder = false; public SimulationSparkIO(int id) { motor = new SparkMax(id, SparkMax.MotorType.kBrushless); motorSimulation = new SparkSim(motor, DCMotor.getBag(1)); /** DCMotor.getBag(1) is a placeholder, we don't actually care about this since we always do link to {@link com.revrobotics.sim.SparkMaxSim#setMotorCurrent(double)} */ pidController = motor.getClosedLoopController(); + absoluteEncoderSimulation = motorSimulation.getAbsoluteEncoderSim(); } @Override @@ -102,7 +102,7 @@ public void updateSimulation() { absoluteEncoderSimulation.iterate(physicsSimulation.getSystemVelocityRotationsPerSecond() * 60 * motor.configAccessor.encoder.getVelocityConversionFactor(), RobotHardwareStats.getPeriodicTimeSeconds()); return; } - relativeEncoderSimulation.iterate(physicsSimulation.getRotorVelocityRotationsPerSecond() * 60 * motor.configAccessor.encoder.getVelocityConversionFactor(), RobotHardwareStats.getPeriodicTimeSeconds()); + absoluteEncoderSimulation.iterate(isUsingAbsoluteEncoder() ? physicsSimulation.getSystemVelocityRotationsPerSecond() : physicsSimulation.getRotorVelocityRotationsPerSecond() * 60 * motor.configAccessor.encoder.getVelocityConversionFactor(), RobotHardwareStats.getPeriodicTimeSeconds()); } @Override @@ -113,30 +113,14 @@ public void configure(SparkBaseConfig configuration, SparkBase.ResetMode resetMo @Override public void setPhysicsSimulation(MotorPhysicsSimulation physicsSimulation, boolean isUsingAbsoluteEncoder) { this.physicsSimulation = physicsSimulation; + this.isUsingAbsoluteEncoder = isUsingAbsoluteEncoder; - if (isUsingAbsoluteEncoder && absoluteEncoderSimulation == null) { - System.out.println("create absolute encoder simulation"); - createAbsoluteEncoderSimulation(); - return; - } - if (relativeEncoderSimulation == null) - createRelativeEncoderSimulation(); - } - - private void createAbsoluteEncoderSimulation() { - absoluteEncoderSimulation = motorSimulation.getAbsoluteEncoderSim(); - System.out.println(absoluteEncoderSimulation.toString()); - encoder = SparkEncoder.createAbsoluteEncoder(motor); - relativeEncoderSimulation = null; - } - - private void createRelativeEncoderSimulation() { - relativeEncoderSimulation = motorSimulation.getRelativeEncoderSim(); + if (isUsingAbsoluteEncoder) + encoder = SparkEncoder.createAbsoluteEncoder(motor); encoder = SparkEncoder.createRelativeEncoder(motor); - absoluteEncoderSimulation = null; } private boolean isUsingAbsoluteEncoder() { - return absoluteEncoderSimulation != null; + return isUsingAbsoluteEncoder; } } \ No newline at end of file From 9b34333fcf36696eacb2d309cd21549826aa449d Mon Sep 17 00:00:00 2001 From: Nummun14 <142012009+Nummun14@users.noreply.github.com> Date: Mon, 2 Dec 2024 20:45:25 +0200 Subject: [PATCH 52/61] camel case, and removed testing --- .../rev/spark/io/SimulationSparkIO.java | 19 ++++++------------- .../org/trigon/utilities/Conversions.java | 13 +++++-------- 2 files changed, 11 insertions(+), 21 deletions(-) diff --git a/src/main/java/org/trigon/hardware/rev/spark/io/SimulationSparkIO.java b/src/main/java/org/trigon/hardware/rev/spark/io/SimulationSparkIO.java index 0a5e903a..27cb138f 100644 --- a/src/main/java/org/trigon/hardware/rev/spark/io/SimulationSparkIO.java +++ b/src/main/java/org/trigon/hardware/rev/spark/io/SimulationSparkIO.java @@ -8,7 +8,6 @@ import com.revrobotics.spark.config.SparkBaseConfig; import com.revrobotics.spark.config.SparkMaxConfig; import edu.wpi.first.math.system.plant.DCMotor; -import org.littletonrobotics.junction.Logger; import org.trigon.hardware.RobotHardwareStats; import org.trigon.hardware.rev.spark.SparkIO; import org.trigon.hardware.rev.sparkecnoder.SparkEncoder; @@ -25,30 +24,29 @@ public class SimulationSparkIO extends SparkIO { public SimulationSparkIO(int id) { motor = new SparkMax(id, SparkMax.MotorType.kBrushless); - motorSimulation = new SparkSim(motor, DCMotor.getBag(1)); /** DCMotor.getBag(1) is a placeholder, we don't actually care about this since we always do link to {@link com.revrobotics.sim.SparkMaxSim#setMotorCurrent(double)} */ pidController = motor.getClosedLoopController(); + motorSimulation = new SparkSim(motor, DCMotor.getBag(1)); /** DCMotor.getBag(1) is a placeholder, we don't actually care about this since we always do link to {@link com.revrobotics.sim.SparkMaxSim#setMotorCurrent(double)} */ absoluteEncoderSimulation = motorSimulation.getAbsoluteEncoderSim(); } @Override public void setReference(double value, SparkBase.ControlType controlType) { - motor.setVoltage(value); - System.out.println(value + "set reference"); + pidController.setReference(value, controlType); } @Override public void setReference(double value, SparkBase.ControlType controlType, int pidSlot) { -// pidController.setReference(value, controlType, pidSlot); + pidController.setReference(value, controlType, pidSlot); } @Override public void setReference(double value, SparkBase.ControlType controlType, int pidSlot, double arbFeedForward) { -// pidController.setReference(value, controlType, pidSlot, arbFeedForward); + pidController.setReference(value, controlType, pidSlot, arbFeedForward); } @Override public void setReference(double value, SparkBase.ControlType controlType, int pidSlot, double arbFeedForward, SparkClosedLoopController.ArbFFUnits arbFeedForwardUnits) { -// pidController.setReference(value, controlType, pidSlot, arbFeedForward, arbFeedForwardUnits); + pidController.setReference(value, controlType, pidSlot, arbFeedForward, arbFeedForwardUnits); } @Override @@ -90,14 +88,9 @@ public void updateSimulation() { physicsSimulation.setInputVoltage(motorSimulation.getBusVoltage() * motorSimulation.getAppliedOutput()); physicsSimulation.updateMotor(); - - Logger.recordOutput("motor simulation applied output" + motor.getDeviceId(), motorSimulation.getAppliedOutput()); - Logger.recordOutput("velocity" + motor.getDeviceId(), physicsSimulation.getRotorVelocityRotationsPerSecond()); - Logger.recordOutput("system velocity" + motor.getDeviceId(), physicsSimulation.getSystemVelocityRotationsPerSecond()); - Logger.recordOutput("rotor velocity" + motor.getDeviceId(), physicsSimulation.getRotorVelocityRotationsPerSecond()); - motorSimulation.iterate(physicsSimulation.getRotorVelocityRotationsPerSecond() * 60 * motor.configAccessor.encoder.getVelocityConversionFactor(), RobotHardwareStats.SUPPLY_VOLTAGE, RobotHardwareStats.getPeriodicTimeSeconds()); motorSimulation.setMotorCurrent(physicsSimulation.getCurrent()); + if (isUsingAbsoluteEncoder()) { absoluteEncoderSimulation.iterate(physicsSimulation.getSystemVelocityRotationsPerSecond() * 60 * motor.configAccessor.encoder.getVelocityConversionFactor(), RobotHardwareStats.getPeriodicTimeSeconds()); return; diff --git a/src/main/java/org/trigon/utilities/Conversions.java b/src/main/java/org/trigon/utilities/Conversions.java index 9eef9f36..bc6e917f 100644 --- a/src/main/java/org/trigon/utilities/Conversions.java +++ b/src/main/java/org/trigon/utilities/Conversions.java @@ -240,21 +240,18 @@ public static TrapezoidProfile.Constraints scaleConstraints(TrapezoidProfile.Con } /** - * Converts a string from SNAKE_CASE to camelCase. + * Converts a string from SNAKE_CASE to CamelCase. * * @param input the string to convert - * @return the string in camel case + * @return the string in CamelCase */ public static String snakeCaseToCamelCase(String input) { final String[] parts = input.split("_"); final StringBuilder camelCase = new StringBuilder(); - for (int i = 0; i < parts.length; i++) { - String part = parts[i].toLowerCase(); - if (i == 0) - camelCase.append(part); - else - camelCase.append(Character.toUpperCase(part.charAt(0))).append(part.substring(1)); + for (String s : parts) { + final String part = s.toLowerCase(); + camelCase.append(Character.toUpperCase(part.charAt(0))).append(part.substring(1)); } return camelCase.toString(); From 4da3434b4ae78da33f68f9cbb5b801d10a979c5c Mon Sep 17 00:00:00 2001 From: Nummun14 <142012009+Nummun14@users.noreply.github.com> Date: Mon, 2 Dec 2024 21:17:10 +0200 Subject: [PATCH 53/61] cleaned up solution. SIM WORKS!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! --- .../trigon/hardware/rev/spark/SparkMotor.java | 26 +++++------ .../hardware/rev/spark/io/RealSparkIO.java | 8 ++-- .../rev/spark/io/SimulationSparkIO.java | 45 +++++++++++-------- .../org/trigon/utilities/Conversions.java | 7 ++- 4 files changed, 47 insertions(+), 39 deletions(-) diff --git a/src/main/java/org/trigon/hardware/rev/spark/SparkMotor.java b/src/main/java/org/trigon/hardware/rev/spark/SparkMotor.java index c15e8d0d..e9ddced5 100644 --- a/src/main/java/org/trigon/hardware/rev/spark/SparkMotor.java +++ b/src/main/java/org/trigon/hardware/rev/spark/SparkMotor.java @@ -110,26 +110,26 @@ public void setReference(double value, SparkBase.ControlType controlType, int pi /** * Sends a request to the motor. * - * @param value the value to set - * @param controlType the control type - * @param pidSlot the PID slot to use - * @param arbFeedForward the feed forward value + * @param value the value to set + * @param controlType the control type + * @param pidSlot the PID slot to use + * @param arbitraryFeedForward the feed forward value */ - public void setReference(double value, SparkBase.ControlType controlType, int pidSlot, double arbFeedForward) { - motorIO.setReference(value, controlType, pidSlot, arbFeedForward); + public void setReference(double value, SparkBase.ControlType controlType, int pidSlot, double arbitraryFeedForward) { + motorIO.setReference(value, controlType, pidSlot, arbitraryFeedForward); } /** * Sends a request to the motor. * - * @param value the value to set depending on the control type - * @param controlType the control type - * @param pidSlot the PID slot to use - * @param arbFeedForward the feed forward value - * @param arbFeedForwardUnits the units of the feed forward value + * @param value the value to set depending on the control type + * @param controlType the control type + * @param pidSlot the PID slot to use + * @param arbitraryFeedForward the feed forward value + * @param arbitraryFeedForwardUnits the units of the feed forward value */ - public void setReference(double value, SparkBase.ControlType controlType, int pidSlot, double arbFeedForward, SparkClosedLoopController.ArbFFUnits arbFeedForwardUnits) { - motorIO.setReference(value, controlType, pidSlot, arbFeedForward, arbFeedForwardUnits); + public void setReference(double value, SparkBase.ControlType controlType, int pidSlot, double arbitraryFeedForward, SparkClosedLoopController.ArbFFUnits arbitraryFeedForwardUnits) { + motorIO.setReference(value, controlType, pidSlot, arbitraryFeedForward, arbitraryFeedForwardUnits); } /** diff --git a/src/main/java/org/trigon/hardware/rev/spark/io/RealSparkIO.java b/src/main/java/org/trigon/hardware/rev/spark/io/RealSparkIO.java index 561a9f40..fe9dc968 100644 --- a/src/main/java/org/trigon/hardware/rev/spark/io/RealSparkIO.java +++ b/src/main/java/org/trigon/hardware/rev/spark/io/RealSparkIO.java @@ -30,13 +30,13 @@ public void setReference(double value, SparkBase.ControlType controlType, int pi } @Override - public void setReference(double value, SparkBase.ControlType controlType, int pidSlot, double arbFeedForward) { - pidController.setReference(value, controlType, pidSlot, arbFeedForward); + public void setReference(double value, SparkBase.ControlType controlType, int pidSlot, double arbitraryFeedForward) { + pidController.setReference(value, controlType, pidSlot, arbitraryFeedForward); } @Override - public void setReference(double value, SparkBase.ControlType controlType, int pidSlot, double arbFeedForward, SparkClosedLoopController.ArbFFUnits arbFeedForwardUnits) { - pidController.setReference(value, controlType, pidSlot, arbFeedForward, arbFeedForwardUnits); + public void setReference(double value, SparkBase.ControlType controlType, int pidSlot, double arbitraryFeedForward, SparkClosedLoopController.ArbFFUnits arbitraryFeedForwardUnits) { + pidController.setReference(value, controlType, pidSlot, arbitraryFeedForward, arbitraryFeedForwardUnits); } @Override diff --git a/src/main/java/org/trigon/hardware/rev/spark/io/SimulationSparkIO.java b/src/main/java/org/trigon/hardware/rev/spark/io/SimulationSparkIO.java index 27cb138f..310e01f8 100644 --- a/src/main/java/org/trigon/hardware/rev/spark/io/SimulationSparkIO.java +++ b/src/main/java/org/trigon/hardware/rev/spark/io/SimulationSparkIO.java @@ -12,6 +12,7 @@ import org.trigon.hardware.rev.spark.SparkIO; import org.trigon.hardware.rev.sparkecnoder.SparkEncoder; import org.trigon.hardware.simulation.MotorPhysicsSimulation; +import org.trigon.utilities.Conversions; public class SimulationSparkIO extends SparkIO { private final SparkMax motor; @@ -24,6 +25,7 @@ public class SimulationSparkIO extends SparkIO { public SimulationSparkIO(int id) { motor = new SparkMax(id, SparkMax.MotorType.kBrushless); + encoder = SparkEncoder.createAbsoluteEncoder(motor); pidController = motor.getClosedLoopController(); motorSimulation = new SparkSim(motor, DCMotor.getBag(1)); /** DCMotor.getBag(1) is a placeholder, we don't actually care about this since we always do link to {@link com.revrobotics.sim.SparkMaxSim#setMotorCurrent(double)} */ absoluteEncoderSimulation = motorSimulation.getAbsoluteEncoderSim(); @@ -40,13 +42,13 @@ public void setReference(double value, SparkBase.ControlType controlType, int pi } @Override - public void setReference(double value, SparkBase.ControlType controlType, int pidSlot, double arbFeedForward) { - pidController.setReference(value, controlType, pidSlot, arbFeedForward); + public void setReference(double value, SparkBase.ControlType controlType, int pidSlot, double arbitraryFeedForward) { + pidController.setReference(value, controlType, pidSlot, arbitraryFeedForward); } @Override - public void setReference(double value, SparkBase.ControlType controlType, int pidSlot, double arbFeedForward, SparkClosedLoopController.ArbFFUnits arbFeedForwardUnits) { - pidController.setReference(value, controlType, pidSlot, arbFeedForward, arbFeedForwardUnits); + public void setReference(double value, SparkBase.ControlType controlType, int pidSlot, double arbitraryFeedForward, SparkClosedLoopController.ArbFFUnits arbitraryFeedForwardUnits) { + pidController.setReference(value, controlType, pidSlot, arbitraryFeedForward, arbitraryFeedForwardUnits); } @Override @@ -86,16 +88,9 @@ public void updateSimulation() { if (physicsSimulation == null) return; - physicsSimulation.setInputVoltage(motorSimulation.getBusVoltage() * motorSimulation.getAppliedOutput()); - physicsSimulation.updateMotor(); - motorSimulation.iterate(physicsSimulation.getRotorVelocityRotationsPerSecond() * 60 * motor.configAccessor.encoder.getVelocityConversionFactor(), RobotHardwareStats.SUPPLY_VOLTAGE, RobotHardwareStats.getPeriodicTimeSeconds()); - motorSimulation.setMotorCurrent(physicsSimulation.getCurrent()); - - if (isUsingAbsoluteEncoder()) { - absoluteEncoderSimulation.iterate(physicsSimulation.getSystemVelocityRotationsPerSecond() * 60 * motor.configAccessor.encoder.getVelocityConversionFactor(), RobotHardwareStats.getPeriodicTimeSeconds()); - return; - } - absoluteEncoderSimulation.iterate(isUsingAbsoluteEncoder() ? physicsSimulation.getSystemVelocityRotationsPerSecond() : physicsSimulation.getRotorVelocityRotationsPerSecond() * 60 * motor.configAccessor.encoder.getVelocityConversionFactor(), RobotHardwareStats.getPeriodicTimeSeconds()); + updatePhysicsSimulation(); + updateMotorSimulation(); + updateEncoderSimulation(); } @Override @@ -107,13 +102,27 @@ public void configure(SparkBaseConfig configuration, SparkBase.ResetMode resetMo public void setPhysicsSimulation(MotorPhysicsSimulation physicsSimulation, boolean isUsingAbsoluteEncoder) { this.physicsSimulation = physicsSimulation; this.isUsingAbsoluteEncoder = isUsingAbsoluteEncoder; - - if (isUsingAbsoluteEncoder) - encoder = SparkEncoder.createAbsoluteEncoder(motor); - encoder = SparkEncoder.createRelativeEncoder(motor); } private boolean isUsingAbsoluteEncoder() { return isUsingAbsoluteEncoder; } + + private void updatePhysicsSimulation() { + physicsSimulation.setInputVoltage(motorSimulation.getBusVoltage() * motorSimulation.getAppliedOutput()); + physicsSimulation.updateMotor(); + } + + private void updateMotorSimulation() { + motorSimulation.iterate(getConversionFactor() * Conversions.perMinuteToPerSecond(physicsSimulation.getRotorVelocityRotationsPerSecond()), RobotHardwareStats.SUPPLY_VOLTAGE, RobotHardwareStats.getPeriodicTimeSeconds()); + motorSimulation.setMotorCurrent(physicsSimulation.getCurrent()); + } + + private void updateEncoderSimulation() { + absoluteEncoderSimulation.iterate(isUsingAbsoluteEncoder() ? getConversionFactor() * Conversions.perMinuteToPerSecond(physicsSimulation.getSystemVelocityRotationsPerSecond()) : getConversionFactor() * Conversions.perMinuteToPerSecond(physicsSimulation.getRotorVelocityRotationsPerSecond()), RobotHardwareStats.getPeriodicTimeSeconds()); + } + + private double getConversionFactor() { + return motor.configAccessor.encoder.getPositionConversionFactor(); + } } \ No newline at end of file diff --git a/src/main/java/org/trigon/utilities/Conversions.java b/src/main/java/org/trigon/utilities/Conversions.java index bc6e917f..e2a57ff2 100644 --- a/src/main/java/org/trigon/utilities/Conversions.java +++ b/src/main/java/org/trigon/utilities/Conversions.java @@ -249,11 +249,10 @@ public static String snakeCaseToCamelCase(String input) { final String[] parts = input.split("_"); final StringBuilder camelCase = new StringBuilder(); - for (String s : parts) { - final String part = s.toLowerCase(); - camelCase.append(Character.toUpperCase(part.charAt(0))).append(part.substring(1)); + for (String part : parts) { + final String lowerCasePart = part.toLowerCase(); + camelCase.append(Character.toUpperCase(lowerCasePart.charAt(0))).append(lowerCasePart.substring(1)); } - return camelCase.toString(); } } \ No newline at end of file From 6d6203b2ba270ab429e8e42c85746c514faaa22f Mon Sep 17 00:00:00 2001 From: Nummun14 <142012009+Nummun14@users.noreply.github.com> Date: Mon, 2 Dec 2024 21:46:09 +0200 Subject: [PATCH 54/61] cleaning, and made motor sim get system or rotor depending on the encoder --- .../java/org/trigon/hardware/rev/spark/io/RealSparkIO.java | 2 +- .../org/trigon/hardware/rev/spark/io/SimulationSparkIO.java | 6 +++--- src/main/java/org/trigon/utilities/Conversions.java | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/main/java/org/trigon/hardware/rev/spark/io/RealSparkIO.java b/src/main/java/org/trigon/hardware/rev/spark/io/RealSparkIO.java index fe9dc968..b37e7b77 100644 --- a/src/main/java/org/trigon/hardware/rev/spark/io/RealSparkIO.java +++ b/src/main/java/org/trigon/hardware/rev/spark/io/RealSparkIO.java @@ -71,7 +71,7 @@ public void setInverted(boolean inverted) { @Override public void setBrake(boolean brake) { - SparkMaxConfig configuration = new SparkMaxConfig(); + final SparkMaxConfig configuration = new SparkMaxConfig(); configuration.idleMode(brake ? SparkMaxConfig.IdleMode.kBrake : SparkMaxConfig.IdleMode.kCoast); motor.configure(configuration, SparkBase.ResetMode.kNoResetSafeParameters, SparkBase.PersistMode.kNoPersistParameters); } diff --git a/src/main/java/org/trigon/hardware/rev/spark/io/SimulationSparkIO.java b/src/main/java/org/trigon/hardware/rev/spark/io/SimulationSparkIO.java index 310e01f8..7207de87 100644 --- a/src/main/java/org/trigon/hardware/rev/spark/io/SimulationSparkIO.java +++ b/src/main/java/org/trigon/hardware/rev/spark/io/SimulationSparkIO.java @@ -27,7 +27,7 @@ public SimulationSparkIO(int id) { motor = new SparkMax(id, SparkMax.MotorType.kBrushless); encoder = SparkEncoder.createAbsoluteEncoder(motor); pidController = motor.getClosedLoopController(); - motorSimulation = new SparkSim(motor, DCMotor.getBag(1)); /** DCMotor.getBag(1) is a placeholder, we don't actually care about this since we always do link to {@link com.revrobotics.sim.SparkMaxSim#setMotorCurrent(double)} */ + motorSimulation = new SparkSim(motor, DCMotor.getBag(1)); /** DCMotor.getBag(1) is a placeholder, we don't actually care about this since we always do {@link com.revrobotics.sim.SparkMaxSim#setMotorCurrent} */ absoluteEncoderSimulation = motorSimulation.getAbsoluteEncoderSim(); } @@ -114,12 +114,12 @@ private void updatePhysicsSimulation() { } private void updateMotorSimulation() { - motorSimulation.iterate(getConversionFactor() * Conversions.perMinuteToPerSecond(physicsSimulation.getRotorVelocityRotationsPerSecond()), RobotHardwareStats.SUPPLY_VOLTAGE, RobotHardwareStats.getPeriodicTimeSeconds()); + motorSimulation.iterate(getConversionFactor() * (isUsingAbsoluteEncoder ? Conversions.perMinuteToPerSecond(physicsSimulation.getSystemVelocityRotationsPerSecond()) : Conversions.perMinuteToPerSecond(physicsSimulation.getRotorVelocityRotationsPerSecond())), RobotHardwareStats.SUPPLY_VOLTAGE, RobotHardwareStats.getPeriodicTimeSeconds()); motorSimulation.setMotorCurrent(physicsSimulation.getCurrent()); } private void updateEncoderSimulation() { - absoluteEncoderSimulation.iterate(isUsingAbsoluteEncoder() ? getConversionFactor() * Conversions.perMinuteToPerSecond(physicsSimulation.getSystemVelocityRotationsPerSecond()) : getConversionFactor() * Conversions.perMinuteToPerSecond(physicsSimulation.getRotorVelocityRotationsPerSecond()), RobotHardwareStats.getPeriodicTimeSeconds()); + absoluteEncoderSimulation.iterate(getConversionFactor() * (isUsingAbsoluteEncoder() ? Conversions.perMinuteToPerSecond(physicsSimulation.getSystemVelocityRotationsPerSecond()) : Conversions.perMinuteToPerSecond(physicsSimulation.getRotorVelocityRotationsPerSecond())), RobotHardwareStats.getPeriodicTimeSeconds()); } private double getConversionFactor() { diff --git a/src/main/java/org/trigon/utilities/Conversions.java b/src/main/java/org/trigon/utilities/Conversions.java index e2a57ff2..606d065a 100644 --- a/src/main/java/org/trigon/utilities/Conversions.java +++ b/src/main/java/org/trigon/utilities/Conversions.java @@ -3,7 +3,7 @@ import edu.wpi.first.math.trajectory.TrapezoidProfile; /** - * A class that contains various methods for unit and String conversions. + * A class that contains various methods for unit conversions, string conversions, and more. */ public class Conversions { public static final double From dd1f31c3593b03fdc82a43226dca04ec5528c55e Mon Sep 17 00:00:00 2001 From: Nummun14 <142012009+Nummun14@users.noreply.github.com> Date: Mon, 2 Dec 2024 22:05:09 +0200 Subject: [PATCH 55/61] cleaned velocity calc --- .../rev/spark/io/SimulationSparkIO.java | 20 ++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/src/main/java/org/trigon/hardware/rev/spark/io/SimulationSparkIO.java b/src/main/java/org/trigon/hardware/rev/spark/io/SimulationSparkIO.java index 7207de87..f7fadae7 100644 --- a/src/main/java/org/trigon/hardware/rev/spark/io/SimulationSparkIO.java +++ b/src/main/java/org/trigon/hardware/rev/spark/io/SimulationSparkIO.java @@ -19,9 +19,10 @@ public class SimulationSparkIO extends SparkIO { private final SparkSim motorSimulation; private final SparkClosedLoopController pidController; private final SparkAbsoluteEncoderSim absoluteEncoderSimulation; - private SparkEncoder encoder = null; + private final SparkEncoder encoder; private MotorPhysicsSimulation physicsSimulation = null; private boolean isUsingAbsoluteEncoder = false; + private double velocity = 0; public SimulationSparkIO(int id) { motor = new SparkMax(id, SparkMax.MotorType.kBrushless); @@ -88,6 +89,7 @@ public void updateSimulation() { if (physicsSimulation == null) return; + updateVelocity(); updatePhysicsSimulation(); updateMotorSimulation(); updateEncoderSimulation(); @@ -104,22 +106,26 @@ public void setPhysicsSimulation(MotorPhysicsSimulation physicsSimulation, boole this.isUsingAbsoluteEncoder = isUsingAbsoluteEncoder; } - private boolean isUsingAbsoluteEncoder() { - return isUsingAbsoluteEncoder; - } - private void updatePhysicsSimulation() { physicsSimulation.setInputVoltage(motorSimulation.getBusVoltage() * motorSimulation.getAppliedOutput()); physicsSimulation.updateMotor(); } private void updateMotorSimulation() { - motorSimulation.iterate(getConversionFactor() * (isUsingAbsoluteEncoder ? Conversions.perMinuteToPerSecond(physicsSimulation.getSystemVelocityRotationsPerSecond()) : Conversions.perMinuteToPerSecond(physicsSimulation.getRotorVelocityRotationsPerSecond())), RobotHardwareStats.SUPPLY_VOLTAGE, RobotHardwareStats.getPeriodicTimeSeconds()); + motorSimulation.iterate(velocity, RobotHardwareStats.SUPPLY_VOLTAGE, RobotHardwareStats.getPeriodicTimeSeconds()); motorSimulation.setMotorCurrent(physicsSimulation.getCurrent()); } private void updateEncoderSimulation() { - absoluteEncoderSimulation.iterate(getConversionFactor() * (isUsingAbsoluteEncoder() ? Conversions.perMinuteToPerSecond(physicsSimulation.getSystemVelocityRotationsPerSecond()) : Conversions.perMinuteToPerSecond(physicsSimulation.getRotorVelocityRotationsPerSecond())), RobotHardwareStats.getPeriodicTimeSeconds()); + absoluteEncoderSimulation.iterate(velocity, RobotHardwareStats.getPeriodicTimeSeconds()); + } + + private void updateVelocity() { + if (isUsingAbsoluteEncoder) { + velocity = getConversionFactor() * Conversions.perMinuteToPerSecond(physicsSimulation.getSystemVelocityRotationsPerSecond()); + return; + } + velocity = getConversionFactor() * Conversions.perMinuteToPerSecond(physicsSimulation.getRotorVelocityRotationsPerSecond()); } private double getConversionFactor() { From 2b7868616272b70d72568794d59d108de9b87736 Mon Sep 17 00:00:00 2001 From: Nummun14 <142012009+Nummun14@users.noreply.github.com> Date: Mon, 2 Dec 2024 22:08:49 +0200 Subject: [PATCH 56/61] no longer ew --- .../hardware/rev/spark/io/SimulationSparkIO.java | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/src/main/java/org/trigon/hardware/rev/spark/io/SimulationSparkIO.java b/src/main/java/org/trigon/hardware/rev/spark/io/SimulationSparkIO.java index f7fadae7..5bb3b16a 100644 --- a/src/main/java/org/trigon/hardware/rev/spark/io/SimulationSparkIO.java +++ b/src/main/java/org/trigon/hardware/rev/spark/io/SimulationSparkIO.java @@ -22,7 +22,6 @@ public class SimulationSparkIO extends SparkIO { private final SparkEncoder encoder; private MotorPhysicsSimulation physicsSimulation = null; private boolean isUsingAbsoluteEncoder = false; - private double velocity = 0; public SimulationSparkIO(int id) { motor = new SparkMax(id, SparkMax.MotorType.kBrushless); @@ -89,7 +88,6 @@ public void updateSimulation() { if (physicsSimulation == null) return; - updateVelocity(); updatePhysicsSimulation(); updateMotorSimulation(); updateEncoderSimulation(); @@ -112,20 +110,18 @@ private void updatePhysicsSimulation() { } private void updateMotorSimulation() { - motorSimulation.iterate(velocity, RobotHardwareStats.SUPPLY_VOLTAGE, RobotHardwareStats.getPeriodicTimeSeconds()); + motorSimulation.iterate(getVelocity(), RobotHardwareStats.SUPPLY_VOLTAGE, RobotHardwareStats.getPeriodicTimeSeconds()); motorSimulation.setMotorCurrent(physicsSimulation.getCurrent()); } private void updateEncoderSimulation() { - absoluteEncoderSimulation.iterate(velocity, RobotHardwareStats.getPeriodicTimeSeconds()); + absoluteEncoderSimulation.iterate(getVelocity(), RobotHardwareStats.getPeriodicTimeSeconds()); } - private void updateVelocity() { - if (isUsingAbsoluteEncoder) { - velocity = getConversionFactor() * Conversions.perMinuteToPerSecond(physicsSimulation.getSystemVelocityRotationsPerSecond()); - return; - } - velocity = getConversionFactor() * Conversions.perMinuteToPerSecond(physicsSimulation.getRotorVelocityRotationsPerSecond()); + private double getVelocity() { + if (isUsingAbsoluteEncoder) + return getConversionFactor() * Conversions.perMinuteToPerSecond(physicsSimulation.getSystemVelocityRotationsPerSecond()); + return getConversionFactor() * Conversions.perMinuteToPerSecond(physicsSimulation.getRotorVelocityRotationsPerSecond()); } private double getConversionFactor() { From f1c8acd59c62f0a31d31a2dd1a95c78bb35e2bd6 Mon Sep 17 00:00:00 2001 From: Nummun14 <142012009+Nummun14@users.noreply.github.com> Date: Mon, 2 Dec 2024 22:13:22 +0200 Subject: [PATCH 57/61] method name --- .../org/trigon/hardware/rev/spark/io/SimulationSparkIO.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/java/org/trigon/hardware/rev/spark/io/SimulationSparkIO.java b/src/main/java/org/trigon/hardware/rev/spark/io/SimulationSparkIO.java index 5bb3b16a..78f914e6 100644 --- a/src/main/java/org/trigon/hardware/rev/spark/io/SimulationSparkIO.java +++ b/src/main/java/org/trigon/hardware/rev/spark/io/SimulationSparkIO.java @@ -110,15 +110,15 @@ private void updatePhysicsSimulation() { } private void updateMotorSimulation() { - motorSimulation.iterate(getVelocity(), RobotHardwareStats.SUPPLY_VOLTAGE, RobotHardwareStats.getPeriodicTimeSeconds()); + motorSimulation.iterate(getPhysicsSimulationVelocityForMotorSimulation(), RobotHardwareStats.SUPPLY_VOLTAGE, RobotHardwareStats.getPeriodicTimeSeconds()); motorSimulation.setMotorCurrent(physicsSimulation.getCurrent()); } private void updateEncoderSimulation() { - absoluteEncoderSimulation.iterate(getVelocity(), RobotHardwareStats.getPeriodicTimeSeconds()); + absoluteEncoderSimulation.iterate(getPhysicsSimulationVelocityForMotorSimulation(), RobotHardwareStats.getPeriodicTimeSeconds()); } - private double getVelocity() { + private double getPhysicsSimulationVelocityForMotorSimulation() { if (isUsingAbsoluteEncoder) return getConversionFactor() * Conversions.perMinuteToPerSecond(physicsSimulation.getSystemVelocityRotationsPerSecond()); return getConversionFactor() * Conversions.perMinuteToPerSecond(physicsSimulation.getRotorVelocityRotationsPerSecond()); From 29b269124aba5dc0c2199ff1042bba5d9ee07706 Mon Sep 17 00:00:00 2001 From: Nummun14 <142012009+Nummun14@users.noreply.github.com> Date: Tue, 3 Dec 2024 11:08:29 +0200 Subject: [PATCH 58/61] javadocs --- .../hardware/phoenix6/cancoder/CANcoderEncoder.java | 4 ++-- .../rev/sparkecnoder/AbsoluteSparkEncoder.java | 10 ---------- .../rev/sparkecnoder/RelativeSparkEncoder.java | 10 ---------- .../trigon/hardware/rev/sparkecnoder/SparkEncoder.java | 10 ++++++++++ .../trigon/hardware/simulation/ElevatorSimulation.java | 2 +- .../hardware/simulation/SimpleMotorSimulation.java | 2 +- .../org/trigon/utilities/mirrorable/Mirrorable.java | 4 ++-- 7 files changed, 16 insertions(+), 26 deletions(-) diff --git a/src/main/java/org/trigon/hardware/phoenix6/cancoder/CANcoderEncoder.java b/src/main/java/org/trigon/hardware/phoenix6/cancoder/CANcoderEncoder.java index 7406bff9..1743c1b6 100644 --- a/src/main/java/org/trigon/hardware/phoenix6/cancoder/CANcoderEncoder.java +++ b/src/main/java/org/trigon/hardware/phoenix6/cancoder/CANcoderEncoder.java @@ -24,7 +24,7 @@ public class CANcoderEncoder { private final int id; /** - * Creates a new CANcoderEncoder. + * Creates a new CANcoder encoder. * * @param id the ID of the CANcoder * @param encoderName the name of the encoder @@ -34,7 +34,7 @@ public CANcoderEncoder(int id, String encoderName) { } /** - * Creates a new CANcoderEncoder. + * Creates a new CANcoder encoder. * * @param id the ID of the CANcoder * @param encoderName the name of the encoder diff --git a/src/main/java/org/trigon/hardware/rev/sparkecnoder/AbsoluteSparkEncoder.java b/src/main/java/org/trigon/hardware/rev/sparkecnoder/AbsoluteSparkEncoder.java index 039fed3d..4c0b556d 100644 --- a/src/main/java/org/trigon/hardware/rev/sparkecnoder/AbsoluteSparkEncoder.java +++ b/src/main/java/org/trigon/hardware/rev/sparkecnoder/AbsoluteSparkEncoder.java @@ -17,20 +17,10 @@ public AbsoluteSparkEncoder(SparkAbsoluteEncoder encoder) { this.encoder = encoder; } - /** - * Gets the position of the encoder in the unit set in the conversion factor. Rotations by default. - * - * @return the position of the encoder - */ public double getPosition() { return encoder.getPosition(); } - /** - * Gets the position of the encoder in the unit set in the conversion factor. Rotations by default. - * - * @return the position of the encoder - */ public double getVelocity() { return encoder.getVelocity(); } diff --git a/src/main/java/org/trigon/hardware/rev/sparkecnoder/RelativeSparkEncoder.java b/src/main/java/org/trigon/hardware/rev/sparkecnoder/RelativeSparkEncoder.java index 8fbc99d3..0e92c5cc 100644 --- a/src/main/java/org/trigon/hardware/rev/sparkecnoder/RelativeSparkEncoder.java +++ b/src/main/java/org/trigon/hardware/rev/sparkecnoder/RelativeSparkEncoder.java @@ -17,20 +17,10 @@ public RelativeSparkEncoder(RelativeEncoder encoder) { this.encoder = encoder; } - /** - * Gets the position of the encoder in the unit set in the conversion factor. Rotations by default. - * - * @return the position of the encoder - */ public double getPosition() { return encoder.getPosition(); } - /** - * Gets the position of the encoder in the unit set in the conversion factor. Rotations by default. - * - * @return the position of the encoder - */ public double getVelocity() { return encoder.getVelocity(); } diff --git a/src/main/java/org/trigon/hardware/rev/sparkecnoder/SparkEncoder.java b/src/main/java/org/trigon/hardware/rev/sparkecnoder/SparkEncoder.java index 5d148dec..1736da09 100644 --- a/src/main/java/org/trigon/hardware/rev/sparkecnoder/SparkEncoder.java +++ b/src/main/java/org/trigon/hardware/rev/sparkecnoder/SparkEncoder.java @@ -26,7 +26,17 @@ public static SparkEncoder createAbsoluteEncoder(SparkBase spark) { return new AbsoluteSparkEncoder(spark.getAbsoluteEncoder()); } + /** + * Gets the position of the encoder in the unit set by the conversion factor. Rotations by default. + * + * @return the position of the encoder + */ public abstract double getPosition(); + /** + * Gets the velocity of the encoder in the unit set by the conversion factor. Rotations by default. + * + * @return the velocity of the encoder + */ public abstract double getVelocity(); } \ No newline at end of file diff --git a/src/main/java/org/trigon/hardware/simulation/ElevatorSimulation.java b/src/main/java/org/trigon/hardware/simulation/ElevatorSimulation.java index 864dcf67..b03188e9 100644 --- a/src/main/java/org/trigon/hardware/simulation/ElevatorSimulation.java +++ b/src/main/java/org/trigon/hardware/simulation/ElevatorSimulation.java @@ -22,7 +22,7 @@ public class ElevatorSimulation extends MotorPhysicsSimulation { * @param drumRadiusMeters the radius of the drum in meters * @param retractedHeightMeters the height of the elevator when retracted in meters * @param maximumHeightMeters the maximum height of the elevator in meters - * @param simulateGravity a boolean indicating whether to simulate gravity + * @param simulateGravity a boolean indicating whether to simulate gravity or not */ public ElevatorSimulation(DCMotor gearbox, double gearRatio, double carriageMassKilograms, double drumRadiusMeters, double retractedHeightMeters, double maximumHeightMeters, boolean simulateGravity) { super(gearbox, gearRatio); diff --git a/src/main/java/org/trigon/hardware/simulation/SimpleMotorSimulation.java b/src/main/java/org/trigon/hardware/simulation/SimpleMotorSimulation.java index cb564bab..4b53eee5 100644 --- a/src/main/java/org/trigon/hardware/simulation/SimpleMotorSimulation.java +++ b/src/main/java/org/trigon/hardware/simulation/SimpleMotorSimulation.java @@ -7,7 +7,7 @@ import org.trigon.hardware.RobotHardwareStats; /** - * A class that represents a simulation of a simple motor mechanism, such as flywheels and turret mechanisms. + * A class that represents a simulation of a simple motor mechanism, such as flywheel and turret mechanisms. */ public class SimpleMotorSimulation extends MotorPhysicsSimulation { private final DCMotorSim motorSimulation; diff --git a/src/main/java/org/trigon/utilities/mirrorable/Mirrorable.java b/src/main/java/org/trigon/utilities/mirrorable/Mirrorable.java index bcadd29d..99cba2e0 100644 --- a/src/main/java/org/trigon/utilities/mirrorable/Mirrorable.java +++ b/src/main/java/org/trigon/utilities/mirrorable/Mirrorable.java @@ -40,7 +40,7 @@ public static boolean isRedAlliance() { } /** - * Gets a command that updates the alliance. This is used to cache the alliance every 0.5 seconds. Ignoring disable is used to allow this command to run when the robot is disabled. + * Gets a command that updates the alliance. This is used to cache the alliance every 0.5 seconds. Ignoring disable is used to update the alliance when the robot is disabled. * * @return the command */ @@ -60,7 +60,7 @@ private static boolean notCachedIsRedAlliance() { * Creates a new mirrorable object. * * @param nonMirroredObject the object when the robot is on the blue alliance, or the non-mirrored object - * @param shouldMirrorWhenRedAlliance whether the object should be mirrored when the robot is on the red alliance + * @param shouldMirrorWhenRedAlliance should the object should be mirrored when the robot is on the red alliance */ protected Mirrorable(T nonMirroredObject, boolean shouldMirrorWhenRedAlliance) { this.nonMirroredObject = nonMirroredObject; From de9590cd6b041a21f998cf44ab20628ed5974864 Mon Sep 17 00:00:00 2001 From: Nummun14 <142012009+Nummun14@users.noreply.github.com> Date: Tue, 3 Dec 2024 12:17:19 +0200 Subject: [PATCH 59/61] jdocs and "ecnoders --- .../java/org/trigon/hardware/phoenix6/Phoenix6SignalThread.java | 2 +- src/main/java/org/trigon/hardware/rev/spark/SparkIO.java | 2 +- src/main/java/org/trigon/hardware/rev/spark/SparkSignal.java | 2 +- src/main/java/org/trigon/hardware/rev/spark/io/RealSparkIO.java | 2 +- .../org/trigon/hardware/rev/spark/io/SimulationSparkIO.java | 2 +- .../{sparkecnoder => sparkencoder}/AbsoluteSparkEncoder.java | 2 +- .../{sparkecnoder => sparkencoder}/RelativeSparkEncoder.java | 2 +- .../rev/{sparkecnoder => sparkencoder}/SparkEncoder.java | 2 +- src/main/java/org/trigon/utilities/mirrorable/Mirrorable.java | 2 +- 9 files changed, 9 insertions(+), 9 deletions(-) rename src/main/java/org/trigon/hardware/rev/{sparkecnoder => sparkencoder}/AbsoluteSparkEncoder.java (93%) rename src/main/java/org/trigon/hardware/rev/{sparkecnoder => sparkencoder}/RelativeSparkEncoder.java (92%) rename src/main/java/org/trigon/hardware/rev/{sparkecnoder => sparkencoder}/SparkEncoder.java (96%) diff --git a/src/main/java/org/trigon/hardware/phoenix6/Phoenix6SignalThread.java b/src/main/java/org/trigon/hardware/phoenix6/Phoenix6SignalThread.java index 148c6ab3..547aa116 100644 --- a/src/main/java/org/trigon/hardware/phoenix6/Phoenix6SignalThread.java +++ b/src/main/java/org/trigon/hardware/phoenix6/Phoenix6SignalThread.java @@ -27,7 +27,7 @@ import java.util.concurrent.locks.ReentrantLock; /** - * Provides an interface for asynchronously reading high-frequency measurements to a set of queues for Phoenix 6. Used for getting values from status signals. + * An interface for asynchronously reading high-frequency signals into queues for Phoenix 6. Used to get values from status signals. */ public class Phoenix6SignalThread extends SignalThreadBase { public static ReentrantLock SIGNALS_LOCK = new ReentrantLock(); diff --git a/src/main/java/org/trigon/hardware/rev/spark/SparkIO.java b/src/main/java/org/trigon/hardware/rev/spark/SparkIO.java index dcc08759..5e63afe2 100644 --- a/src/main/java/org/trigon/hardware/rev/spark/SparkIO.java +++ b/src/main/java/org/trigon/hardware/rev/spark/SparkIO.java @@ -3,7 +3,7 @@ import com.revrobotics.spark.SparkBase; import com.revrobotics.spark.SparkClosedLoopController; import com.revrobotics.spark.config.SparkBaseConfig; -import org.trigon.hardware.rev.sparkecnoder.SparkEncoder; +import org.trigon.hardware.rev.sparkencoder.SparkEncoder; import org.trigon.hardware.simulation.MotorPhysicsSimulation; public class SparkIO { diff --git a/src/main/java/org/trigon/hardware/rev/spark/SparkSignal.java b/src/main/java/org/trigon/hardware/rev/spark/SparkSignal.java index f2f1eda5..f4f4762a 100644 --- a/src/main/java/org/trigon/hardware/rev/spark/SparkSignal.java +++ b/src/main/java/org/trigon/hardware/rev/spark/SparkSignal.java @@ -2,7 +2,7 @@ import com.revrobotics.spark.SparkBase; import org.trigon.hardware.RobotHardwareStats; -import org.trigon.hardware.rev.sparkecnoder.SparkEncoder; +import org.trigon.hardware.rev.sparkencoder.SparkEncoder; import org.trigon.utilities.Conversions; import java.util.function.Function; diff --git a/src/main/java/org/trigon/hardware/rev/spark/io/RealSparkIO.java b/src/main/java/org/trigon/hardware/rev/spark/io/RealSparkIO.java index b37e7b77..1797f2ce 100644 --- a/src/main/java/org/trigon/hardware/rev/spark/io/RealSparkIO.java +++ b/src/main/java/org/trigon/hardware/rev/spark/io/RealSparkIO.java @@ -6,7 +6,7 @@ import com.revrobotics.spark.config.SparkMaxConfig; import org.trigon.hardware.rev.spark.SparkIO; import org.trigon.hardware.rev.spark.SparkType; -import org.trigon.hardware.rev.sparkecnoder.SparkEncoder; +import org.trigon.hardware.rev.sparkencoder.SparkEncoder; public class RealSparkIO extends SparkIO { private final SparkBase motor; diff --git a/src/main/java/org/trigon/hardware/rev/spark/io/SimulationSparkIO.java b/src/main/java/org/trigon/hardware/rev/spark/io/SimulationSparkIO.java index 78f914e6..8f1ea862 100644 --- a/src/main/java/org/trigon/hardware/rev/spark/io/SimulationSparkIO.java +++ b/src/main/java/org/trigon/hardware/rev/spark/io/SimulationSparkIO.java @@ -10,7 +10,7 @@ import edu.wpi.first.math.system.plant.DCMotor; import org.trigon.hardware.RobotHardwareStats; import org.trigon.hardware.rev.spark.SparkIO; -import org.trigon.hardware.rev.sparkecnoder.SparkEncoder; +import org.trigon.hardware.rev.sparkencoder.SparkEncoder; import org.trigon.hardware.simulation.MotorPhysicsSimulation; import org.trigon.utilities.Conversions; diff --git a/src/main/java/org/trigon/hardware/rev/sparkecnoder/AbsoluteSparkEncoder.java b/src/main/java/org/trigon/hardware/rev/sparkencoder/AbsoluteSparkEncoder.java similarity index 93% rename from src/main/java/org/trigon/hardware/rev/sparkecnoder/AbsoluteSparkEncoder.java rename to src/main/java/org/trigon/hardware/rev/sparkencoder/AbsoluteSparkEncoder.java index 4c0b556d..063eb93e 100644 --- a/src/main/java/org/trigon/hardware/rev/sparkecnoder/AbsoluteSparkEncoder.java +++ b/src/main/java/org/trigon/hardware/rev/sparkencoder/AbsoluteSparkEncoder.java @@ -1,4 +1,4 @@ -package org.trigon.hardware.rev.sparkecnoder; +package org.trigon.hardware.rev.sparkencoder; import com.revrobotics.spark.SparkAbsoluteEncoder; diff --git a/src/main/java/org/trigon/hardware/rev/sparkecnoder/RelativeSparkEncoder.java b/src/main/java/org/trigon/hardware/rev/sparkencoder/RelativeSparkEncoder.java similarity index 92% rename from src/main/java/org/trigon/hardware/rev/sparkecnoder/RelativeSparkEncoder.java rename to src/main/java/org/trigon/hardware/rev/sparkencoder/RelativeSparkEncoder.java index 0e92c5cc..ae7452d9 100644 --- a/src/main/java/org/trigon/hardware/rev/sparkecnoder/RelativeSparkEncoder.java +++ b/src/main/java/org/trigon/hardware/rev/sparkencoder/RelativeSparkEncoder.java @@ -1,4 +1,4 @@ -package org.trigon.hardware.rev.sparkecnoder; +package org.trigon.hardware.rev.sparkencoder; import com.revrobotics.RelativeEncoder; diff --git a/src/main/java/org/trigon/hardware/rev/sparkecnoder/SparkEncoder.java b/src/main/java/org/trigon/hardware/rev/sparkencoder/SparkEncoder.java similarity index 96% rename from src/main/java/org/trigon/hardware/rev/sparkecnoder/SparkEncoder.java rename to src/main/java/org/trigon/hardware/rev/sparkencoder/SparkEncoder.java index 1736da09..ce24413d 100644 --- a/src/main/java/org/trigon/hardware/rev/sparkecnoder/SparkEncoder.java +++ b/src/main/java/org/trigon/hardware/rev/sparkencoder/SparkEncoder.java @@ -1,4 +1,4 @@ -package org.trigon.hardware.rev.sparkecnoder; +package org.trigon.hardware.rev.sparkencoder; import com.revrobotics.spark.SparkAbsoluteEncoder; import com.revrobotics.spark.SparkBase; diff --git a/src/main/java/org/trigon/utilities/mirrorable/Mirrorable.java b/src/main/java/org/trigon/utilities/mirrorable/Mirrorable.java index 99cba2e0..78dffa13 100644 --- a/src/main/java/org/trigon/utilities/mirrorable/Mirrorable.java +++ b/src/main/java/org/trigon/utilities/mirrorable/Mirrorable.java @@ -40,7 +40,7 @@ public static boolean isRedAlliance() { } /** - * Gets a command that updates the alliance. This is used to cache the alliance every 0.5 seconds. Ignoring disable is used to update the alliance when the robot is disabled. + * Gets a command that updates the alliance. This is used to cache the alliance every 0.5 seconds. Ignoring disable is used to update the current alliance when the robot is disabled. * * @return the command */ From 61f30f6fb7ffc91920b669cbdc2d53e5094ccf46 Mon Sep 17 00:00:00 2001 From: Nummun14 <142012009+Nummun14@users.noreply.github.com> Date: Tue, 3 Dec 2024 12:21:10 +0200 Subject: [PATCH 60/61] javadocs --- .../java/org/trigon/hardware/phoenix6/Phoenix6SignalThread.java | 2 +- src/main/java/org/trigon/utilities/mirrorable/Mirrorable.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/trigon/hardware/phoenix6/Phoenix6SignalThread.java b/src/main/java/org/trigon/hardware/phoenix6/Phoenix6SignalThread.java index 547aa116..b50213b4 100644 --- a/src/main/java/org/trigon/hardware/phoenix6/Phoenix6SignalThread.java +++ b/src/main/java/org/trigon/hardware/phoenix6/Phoenix6SignalThread.java @@ -27,7 +27,7 @@ import java.util.concurrent.locks.ReentrantLock; /** - * An interface for asynchronously reading high-frequency signals into queues for Phoenix 6. Used to get values from status signals. + * An interface for asynchronously reading high-frequency signals and adding them to queues for Phoenix 6. Used to get values from status signals. */ public class Phoenix6SignalThread extends SignalThreadBase { public static ReentrantLock SIGNALS_LOCK = new ReentrantLock(); diff --git a/src/main/java/org/trigon/utilities/mirrorable/Mirrorable.java b/src/main/java/org/trigon/utilities/mirrorable/Mirrorable.java index 78dffa13..4046f13c 100644 --- a/src/main/java/org/trigon/utilities/mirrorable/Mirrorable.java +++ b/src/main/java/org/trigon/utilities/mirrorable/Mirrorable.java @@ -40,7 +40,7 @@ public static boolean isRedAlliance() { } /** - * Gets a command that updates the alliance. This is used to cache the alliance every 0.5 seconds. Ignoring disable is used to update the current alliance when the robot is disabled. + * Gets a command that updates the current alliance. This is used to cache the alliance every 0.5 seconds. Ignoring disable is used to update the current alliance when the robot is disabled. * * @return the command */ From 422c7c62aa473e29b6007aee65e922448617399c Mon Sep 17 00:00:00 2001 From: Nummun14 <142012009+Nummun14@users.noreply.github.com> Date: Tue, 3 Dec 2024 17:06:45 +0200 Subject: [PATCH 61/61] docs and sim --- .../trigon/hardware/rev/sparkencoder/SparkEncoder.java | 2 +- .../trigon/hardware/simulation/ElevatorSimulation.java | 2 +- .../hardware/simulation/MotorPhysicsSimulation.java | 10 +--------- .../hardware/simulation/SimpleMotorSimulation.java | 4 ++-- .../simulation/SingleJointedArmSimulation.java | 2 +- 5 files changed, 6 insertions(+), 14 deletions(-) diff --git a/src/main/java/org/trigon/hardware/rev/sparkencoder/SparkEncoder.java b/src/main/java/org/trigon/hardware/rev/sparkencoder/SparkEncoder.java index ce24413d..4ae267cb 100644 --- a/src/main/java/org/trigon/hardware/rev/sparkencoder/SparkEncoder.java +++ b/src/main/java/org/trigon/hardware/rev/sparkencoder/SparkEncoder.java @@ -34,7 +34,7 @@ public static SparkEncoder createAbsoluteEncoder(SparkBase spark) { public abstract double getPosition(); /** - * Gets the velocity of the encoder in the unit set by the conversion factor. Rotations by default. + * Gets the velocity of the encoder in the unit set by the conversion factor. Rotations per minute by default. * * @return the velocity of the encoder */ diff --git a/src/main/java/org/trigon/hardware/simulation/ElevatorSimulation.java b/src/main/java/org/trigon/hardware/simulation/ElevatorSimulation.java index b03188e9..4cdda700 100644 --- a/src/main/java/org/trigon/hardware/simulation/ElevatorSimulation.java +++ b/src/main/java/org/trigon/hardware/simulation/ElevatorSimulation.java @@ -25,7 +25,7 @@ public class ElevatorSimulation extends MotorPhysicsSimulation { * @param simulateGravity a boolean indicating whether to simulate gravity or not */ public ElevatorSimulation(DCMotor gearbox, double gearRatio, double carriageMassKilograms, double drumRadiusMeters, double retractedHeightMeters, double maximumHeightMeters, boolean simulateGravity) { - super(gearbox, gearRatio); + super(gearRatio); diameterMeters = drumRadiusMeters + drumRadiusMeters; this.retractedHeightMeters = retractedHeightMeters; elevatorSimulation = new ElevatorSim( diff --git a/src/main/java/org/trigon/hardware/simulation/MotorPhysicsSimulation.java b/src/main/java/org/trigon/hardware/simulation/MotorPhysicsSimulation.java index 4e70a186..450a25eb 100644 --- a/src/main/java/org/trigon/hardware/simulation/MotorPhysicsSimulation.java +++ b/src/main/java/org/trigon/hardware/simulation/MotorPhysicsSimulation.java @@ -1,17 +1,13 @@ package org.trigon.hardware.simulation; -import edu.wpi.first.math.system.plant.DCMotor; - /** * An abstract class to simulate the physics of a motor. */ public abstract class MotorPhysicsSimulation { private final double gearRatio; - private final DCMotor gearbox; - MotorPhysicsSimulation(DCMotor gearbox, double gearRatio) { + MotorPhysicsSimulation(double gearRatio) { this.gearRatio = gearRatio; - this.gearbox = gearbox; } public double getRotorPositionRotations() { @@ -22,10 +18,6 @@ public double getRotorVelocityRotationsPerSecond() { return getSystemVelocityRotationsPerSecond() * gearRatio; } - public DCMotor getGearbox() { - return gearbox; - } - public abstract double getCurrent(); public abstract double getSystemPositionRotations(); diff --git a/src/main/java/org/trigon/hardware/simulation/SimpleMotorSimulation.java b/src/main/java/org/trigon/hardware/simulation/SimpleMotorSimulation.java index 4b53eee5..c06e9bcd 100644 --- a/src/main/java/org/trigon/hardware/simulation/SimpleMotorSimulation.java +++ b/src/main/java/org/trigon/hardware/simulation/SimpleMotorSimulation.java @@ -20,7 +20,7 @@ public class SimpleMotorSimulation extends MotorPhysicsSimulation { * @param momentOfInertia the moment of inertia of the motor(s) */ public SimpleMotorSimulation(DCMotor gearbox, double gearRatio, double momentOfInertia) { - super(gearbox, gearRatio); + super(gearRatio); motorSimulation = new DCMotorSim(LinearSystemId.createDCMotorSystem(gearbox, momentOfInertia, gearRatio), gearbox); } @@ -33,7 +33,7 @@ public SimpleMotorSimulation(DCMotor gearbox, double gearRatio, double momentOfI * @param ka voltage needed to induce a specific acceleration */ public SimpleMotorSimulation(DCMotor gearbox, double gearRatio, double kv, double ka) { - super(gearbox, gearRatio); + super(gearRatio); motorSimulation = new DCMotorSim(LinearSystemId.createDCMotorSystem(kv, ka), gearbox); } diff --git a/src/main/java/org/trigon/hardware/simulation/SingleJointedArmSimulation.java b/src/main/java/org/trigon/hardware/simulation/SingleJointedArmSimulation.java index 427605ee..48847b65 100644 --- a/src/main/java/org/trigon/hardware/simulation/SingleJointedArmSimulation.java +++ b/src/main/java/org/trigon/hardware/simulation/SingleJointedArmSimulation.java @@ -24,7 +24,7 @@ public class SingleJointedArmSimulation extends MotorPhysicsSimulation { * @param simulateGravity whether to simulate gravity or not */ public SingleJointedArmSimulation(DCMotor gearbox, double gearRatio, double armLengthMeters, double armMassKilograms, Rotation2d minimumAngle, Rotation2d maximumAngle, boolean simulateGravity) { - super(gearbox, gearRatio); + super(gearRatio); armSimulation = new SingleJointedArmSim( gearbox, gearRatio,