Skip to content

Commit

Permalink
Add NT offsets
Browse files Browse the repository at this point in the history
  • Loading branch information
rmheuer committed Nov 18, 2023
1 parent 43fd89a commit 7f1543e
Show file tree
Hide file tree
Showing 8 changed files with 23 additions and 210 deletions.
5 changes: 5 additions & 0 deletions Robot/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
hs_err_pid*
simgui.json
simgui-window.json
networktables.json
networktables.json.bak
1 change: 0 additions & 1 deletion Robot/networktables.json

This file was deleted.

107 changes: 0 additions & 107 deletions Robot/simgui-ds.json

This file was deleted.

69 changes: 0 additions & 69 deletions Robot/simgui-window.json

This file was deleted.

25 changes: 0 additions & 25 deletions Robot/simgui.json

This file was deleted.

8 changes: 7 additions & 1 deletion Robot/src/main/java/com/swrobotics/robot/NTData.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
package com.swrobotics.robot;

import com.swrobotics.lib.net.NTDouble;
import com.swrobotics.lib.net.NTEntry;

/**
* Class to store all tunable NetworkTables values in one place, to make it easier to hardcode the
* defaults in case of data loss.
*
* <p>Temporary values should not be here, this class is only for persistent data.
*/
public final class NTData {
// TODO: Put NetworkTables data here
public static final NTEntry<Double> FL_OFFSET = new NTDouble("Swerve/Modules/Front Left Offset", 0).setPersistent();
public static final NTEntry<Double> FR_OFFSET = new NTDouble("Swerve/Modules/Front Right Offset", 0).setPersistent();
public static final NTEntry<Double> BL_OFFSET = new NTDouble("Swerve/Modules/Back Left Offset", 0).setPersistent();
public static final NTEntry<Double> BR_OFFSET = new NTDouble("Swerve/Modules/Back Right Offset", 0).setPersistent();
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import com.kauailabs.navx.frc.AHRS;
import com.swrobotics.lib.field.FieldInfo;
import com.swrobotics.robot.NTData;
import com.swrobotics.robot.config.CANAllocation;
import edu.wpi.first.math.geometry.Pose2d;
import edu.wpi.first.math.geometry.Rotation2d;
import edu.wpi.first.math.geometry.Translation2d;
Expand All @@ -17,10 +19,10 @@
public final class SwerveDrive extends SubsystemBase {
private static final double HALF_SPACING = Units.inchesToMeters(20); // FIXME
private static final SimSwerveModule.Info[] INFOS = {
new SwerveModule.Info(9, 5, 1, HALF_SPACING, HALF_SPACING, "Front Left"),
new SwerveModule.Info(10, 6, 2, HALF_SPACING, -HALF_SPACING, "Front Right"),
new SwerveModule.Info(11, 7, 3, -HALF_SPACING, HALF_SPACING, "Back Left"),
new SwerveModule.Info(12, 8, 4, -HALF_SPACING, -HALF_SPACING, "Back Right")
new SwerveModule.Info(CANAllocation.SWERVE_FL, HALF_SPACING, HALF_SPACING, NTData.FL_OFFSET),
new SwerveModule.Info(CANAllocation.SWERVE_FR, HALF_SPACING, -HALF_SPACING, NTData.FR_OFFSET),
new SwerveModule.Info(CANAllocation.SWERVE_BL, -HALF_SPACING, HALF_SPACING, NTData.BL_OFFSET),
new SwerveModule.Info(CANAllocation.SWERVE_BR, -HALF_SPACING, -HALF_SPACING, NTData.BR_OFFSET)
};

private final AHRS gyro;
Expand Down Expand Up @@ -48,6 +50,7 @@ public SwerveDrive(FieldInfo fieldInfo) {
prevPositions = null;
}

// TODO: Better way of selecting between manual/auto input
public void drive(ChassisSpeeds robotRelSpeeds) {
SwerveModuleState[] targetStates = kinematics.getStates(robotRelSpeeds);
SwerveModulePosition[] positions = new SwerveModulePosition[modules.length];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.swrobotics.lib.net.NTDouble;
import com.swrobotics.lib.net.NTEntry;
import com.swrobotics.robot.config.CANAllocation;
import edu.wpi.first.math.geometry.Translation2d;
import edu.wpi.first.math.kinematics.SwerveModulePosition;
import edu.wpi.first.math.kinematics.SwerveModuleState;
Expand All @@ -12,10 +13,10 @@ record Info(
int driveId, int turnId, int encoderId,
Translation2d position,
NTEntry<Double> offset) {
public Info(int driveId, int turnId, int encoderId, double x, double y, String name) {
this(driveId, turnId, encoderId,
public Info(CANAllocation.SwerveIDs ids, double x, double y, NTEntry<Double> offset) {
this(ids.drive, ids.turn, ids.encoder,
new Translation2d(x, y),
new NTDouble("Swerve/Modules/" + name + " Offset", 0).setPersistent());
offset);
}
}

Expand Down

0 comments on commit 7f1543e

Please sign in to comment.