Skip to content

Commit

Permalink
refractered the maths helper classes
Browse files Browse the repository at this point in the history
  • Loading branch information
Ltcc0 committed Jul 8, 2024
1 parent d18ba3f commit e0e9975
Show file tree
Hide file tree
Showing 9 changed files with 23 additions and 52 deletions.
4 changes: 2 additions & 2 deletions src/main/java/frc/robot/tests/WheelsCalibrationCTRE.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import edu.wpi.first.wpilibj2.command.InstantCommand;
import frc.robot.Constants;
import frc.robot.utils.Config.MapleConfigFile;
import frc.robot.utils.Math.AngleHelpers;
import frc.robot.utils.MapleMaths.Angles;

import static frc.robot.Constants.WheelCalibrationConfigs.WheelToBeCalibrated;

Expand Down Expand Up @@ -68,7 +68,7 @@ public void testPeriodic() {
}

private double getCanCoderReadingRadian(CANcoder canCoder) {
return AngleHelpers.simplifyAngle(canCoder.getAbsolutePosition().getValue() * Math.PI * 2);
return Angles.simplifyAngle(canCoder.getAbsolutePosition().getValue() * Math.PI * 2);
}

private void writeConfigurationFile() {
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/frc/robot/utils/MapleJoystickDriveInput.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import edu.wpi.first.wpilibj.XboxController;
import edu.wpi.first.wpilibj2.command.button.CommandXboxController;
import frc.robot.Constants;
import frc.robot.utils.Math.LookUpTable;
import frc.robot.utils.MapleMaths.CommonMath;

import java.util.function.DoubleSupplier;

Expand Down Expand Up @@ -71,7 +71,7 @@ public double getRotationalSpeedFromJoystick(double maxAngularVelocityRadPerSec)
* @param otherAxisValue the value of the other axis on the stick
* */
private static double applySmartDeadBand(double axisValue, double otherAxisValue) {
final double deadBand = LookUpTable.linearInterpretationWithBounding(
final double deadBand = CommonMath.linearInterpretationWithBounding(
0, Constants.DriveConfigs.deadBandWhenOtherAxisEmpty,
1, Constants.DriveConfigs.deadBandWhenOtherAxisFull,
Math.abs(otherAxisValue)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package frc.robot.utils.Math;
package frc.robot.utils.MapleMaths;

public class AngleHelpers {
public class Angles {
/**
* simplify an angle into the range 0-360 degrees
*
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package frc.robot.utils.Math; // package frc.robot.Helpers.MathHelpers;
package frc.robot.utils.MapleMaths; // package frc.robot.Helpers.MathHelpers;
//
/// **
// * Bézier curve with four points
Expand Down
11 changes: 11 additions & 0 deletions src/main/java/frc/robot/utils/MapleMaths/CommonMath.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package frc.robot.utils.MapleMaths;

public class CommonMath {
public static double linearInterpretationWithBounding(double x1, double y1, double x2, double y2, double x) {
final double minX = Math.min(x1, x2), maxX = Math.max(x1, x2);
return linearInterpretation(x1, y1, x2, y2, Math.min(maxX, Math.max(minX, x)));
}
public static double linearInterpretation(double x1, double y1, double x2, double y2, double x) {
return y1 + (x - x1) * (y2 - y1) / (x2 - x1);
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package frc.robot.utils.Math; // package frc.robot.Helpers.MathHelpers;
package frc.robot.utils.MapleMaths; // package frc.robot.Helpers.MathHelpers;
//
/// *
// * https://developer.mozilla.org/en-US/docs/Web/CSS/easing-function
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package frc.robot.utils.Math;
package frc.robot.utils.MapleMaths;

public final class StatisticsHelpers {
public final class Statistics {
public static double getMean(double[] dataSet) {
double sum = 0;
for (double data : dataSet) sum += data;
Expand Down
39 changes: 0 additions & 39 deletions src/main/java/frc/robot/utils/Math/LookUpTable.java

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package frc.robot.utils.MechanismControl;

import frc.robot.utils.Math.AngleHelpers;
import frc.robot.utils.Math.LookUpTable;
import frc.robot.utils.MapleMaths.Angles;
import org.littletonrobotics.junction.Logger;

/**
Expand Down Expand Up @@ -32,7 +31,7 @@ public double getMotorPower(double mechanismVelocity, double mechanismPosition)
mechanismPosition + mechanismVelocity * profile.mechanismDecelerationTime,
error =
profile.isMechanismInCycle
? AngleHelpers.getActualDifference(mechanismPositionWithDerivative, desiredPosition)
? Angles.getActualDifference(mechanismPositionWithDerivative, desiredPosition)
: desiredPosition - mechanismPositionWithDerivative;
if (Math.abs(error) < profile.errorTolerance) return 0;
final double
Expand Down

0 comments on commit e0e9975

Please sign in to comment.