Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,24 @@
# build file
.gradle
build

# Compiled class file
*.class

# Log file
*.log

# BlueJ files
*.ctxt

# Mobile Tools for Java (J2ME)
.mtj.tmp/

# Package Files
*.zip
*.tar.gz
*.rar

# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
hs_err_pid*
replay_pid*
Binary file removed bin/main/frc/FSLib2025/math/LinearRegression.class
Binary file not shown.
Binary file removed bin/main/frc/FSLib2025/math/Maths.class
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file removed bin/main/frc/FSLib2025/swerve/SwerveModuleConfig.class
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file removed bin/main/frc/FSLib2025/util/LocalADStarAK.class
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file removed bin/main/frc/FSLib2025/vision/LimelightHelpers.class
Binary file not shown.
Binary file removed bin/main/frc/robot/Constants$RobotConstants.class
Binary file not shown.
Binary file not shown.
Binary file removed bin/main/frc/robot/Constants$SwerveConstants.class
Binary file not shown.
Binary file removed bin/main/frc/robot/Constants.class
Binary file not shown.
Binary file removed bin/main/frc/robot/Main.class
Binary file not shown.
Binary file removed bin/main/frc/robot/Robot.class
Binary file not shown.
Binary file removed bin/main/frc/robot/RobotContainer.class
Binary file not shown.
Binary file removed bin/main/frc/robot/commands/TeleopSwerve.class
Binary file not shown.
Binary file removed bin/main/frc/robot/subsystems/Elevator.class
Binary file not shown.
Binary file removed bin/main/frc/robot/subsystems/Grabber.class
Binary file not shown.
Binary file removed bin/main/frc/robot/subsystems/Intake.class
Binary file not shown.
Binary file removed bin/main/frc/robot/subsystems/LED.class
Binary file not shown.
Binary file removed bin/main/frc/robot/subsystems/Swerve.class
Binary file not shown.
Binary file removed bin/main/frc/robot/subsystems/SwerveModule.class
Binary file not shown.
15 changes: 8 additions & 7 deletions src/main/java/frc/FSLib2025/math/LinearRegression.java
Original file line number Diff line number Diff line change
@@ -1,22 +1,23 @@
package frc.FSLib2025.math;

public class LinearRegression {

private double[][] data;

public LinearRegression (double[][] mapValues) {
public LinearRegression(double[][] mapValues) {
data = mapValues;
}

public double calculate (double xValues) {
public double calculate(double xValues) {
int index = 0;
for (double[] i : data) {
if(i[0] >= xValues) break;
if (i[0] >= xValues)
break;
index++;
}
double dx = xValues - data[index-1][0];
double x = data[index][0] - data[index-1][0];
return data[index-1][1] * (1-dx/x) + data[index][1] * dx/x;
double dx = xValues - data[index - 1][0];
double x = data[index][0] - data[index - 1][0];
return data[index - 1][1] * (1 - dx / x) + data[index][1] * dx / x;
}

}
10 changes: 5 additions & 5 deletions src/main/java/frc/FSLib2025/math/Maths.java
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
package frc.FSLib2025.math;

public class Maths {
public static boolean isWithin (double value, double min, double max) {

public static boolean isWithin(double value, double min, double max) {
return Math.max(min, value) == Math.min(value, max);
}
public static double clamp (double value, double min, double max) {

public static double clamp(double value, double min, double max) {
return Math.min(Math.max(value, min), max);
}

public static int clamp (int value, int min, int max) {
public static int clamp(int value, int min, int max) {
return Math.min(Math.max(value, min), max);
}

Expand Down
98 changes: 49 additions & 49 deletions src/main/java/frc/FSLib2025/swerve/OnboardModuleState.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,56 +5,56 @@

public class OnboardModuleState {

/**
* Minimize the change in heading the desired swerve module state would require
* by potentially
* reversing the direction the wheel spins. Customized from WPILib's version to
* include placing in
* appropriate scope for CTRE and REV onboard control as both controllers as of
* writing don't have
* support for continuous input.
*
* @param desiredState The desired state.
* @param currentAngle The current module angle.
*/
public static SwerveModuleState optimize(SwerveModuleState desiredState, Rotation2d currentAngle) {
double targetAngle = placeInAppropriate0To360Scope(currentAngle.getDegrees(), desiredState.angle.getDegrees());
double targetSpeed = desiredState.speedMetersPerSecond;
double delta = targetAngle - currentAngle.getDegrees();
if (Math.abs(delta) > 90) {
targetSpeed = -targetSpeed;
targetAngle = delta > 90 ? (targetAngle -= 180) : (targetAngle += 180);
/**
* Minimize the change in heading the desired swerve module state would require
* by potentially
* reversing the direction the wheel spins. Customized from WPILib's version to
* include placing in
* appropriate scope for CTRE and REV onboard control as both controllers as of
* writing don't have
* support for continuous input.
*
* @param desiredState The desired state.
* @param currentAngle The current module angle.
*/
public static SwerveModuleState optimize(SwerveModuleState desiredState, Rotation2d currentAngle) {
double targetAngle = placeInAppropriate0To360Scope(currentAngle.getDegrees(), desiredState.angle.getDegrees());
double targetSpeed = desiredState.speedMetersPerSecond;
double delta = targetAngle - currentAngle.getDegrees();
if (Math.abs(delta) > 90) {
targetSpeed = -targetSpeed;
targetAngle = delta > 90 ? (targetAngle -= 180) : (targetAngle += 180);
}
return new SwerveModuleState(targetSpeed, Rotation2d.fromDegrees(targetAngle));
}
return new SwerveModuleState(targetSpeed, Rotation2d.fromDegrees(targetAngle));
}

/**
* @param scopeReference Current Angle
* @param newAngle Target Angle
* @return Closest angle within scope
*/
private static double placeInAppropriate0To360Scope(double scopeReference, double newAngle) {
double lowerBound;
double upperBound;
double lowerOffset = scopeReference % 360;
if (lowerOffset >= 0) {
lowerBound = scopeReference - lowerOffset;
upperBound = scopeReference + (360 - lowerOffset);
} else {
upperBound = scopeReference - lowerOffset;
lowerBound = scopeReference - (360 + lowerOffset);
/**
* @param scopeReference Current Angle
* @param newAngle Target Angle
* @return Closest angle within scope
*/
private static double placeInAppropriate0To360Scope(double scopeReference, double newAngle) {
double lowerBound;
double upperBound;
double lowerOffset = scopeReference % 360;
if (lowerOffset >= 0) {
lowerBound = scopeReference - lowerOffset;
upperBound = scopeReference + (360 - lowerOffset);
} else {
upperBound = scopeReference - lowerOffset;
lowerBound = scopeReference - (360 + lowerOffset);
}
while (newAngle < lowerBound) {
newAngle += 360;
}
while (newAngle > upperBound) {
newAngle -= 360;
}
if (newAngle - scopeReference > 180) {
newAngle -= 360;
} else if (newAngle - scopeReference < -180) {
newAngle += 360;
}
return newAngle;
}
while (newAngle < lowerBound) {
newAngle += 360;
}
while (newAngle > upperBound) {
newAngle -= 360;
}
if (newAngle - scopeReference > 180) {
newAngle -= 360;
} else if (newAngle - scopeReference < -180) {
newAngle += 360;
}
return newAngle;
}
}
4 changes: 2 additions & 2 deletions src/main/java/frc/FSLib2025/swerve/SwerveModuleConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ public class SwerveModuleConfig {
public int AngleMotorId;
public int CancoderId;
public Rotation2d AngleOffset;
public SwerveModuleConfig (int driveMotorId, int angleMotorId, int cancoderId, Rotation2d angleOffset) {

public SwerveModuleConfig(int driveMotorId, int angleMotorId, int cancoderId, Rotation2d angleOffset) {
this.DriveMotorId = driveMotorId;
this.AngleMotorId = angleMotorId;
this.CancoderId = cancoderId;
Expand Down
Loading