From d28671c74335d19204b3fe4629c743f8e6f2efd9 Mon Sep 17 00:00:00 2001 From: GearBoxFox <98189655+GearBoxFox@users.noreply.github.com> Date: Thu, 7 Mar 2024 13:21:48 -0500 Subject: [PATCH 1/2] publish swerve states and poses in proper format --- src/main/java/frc/robot/Robot.java | 2 +- src/main/java/lib/logger/DataLogUtil.java | 40 ++++++++--------------- 2 files changed, 15 insertions(+), 27 deletions(-) diff --git a/src/main/java/frc/robot/Robot.java b/src/main/java/frc/robot/Robot.java index 075be444..9452b152 100644 --- a/src/main/java/frc/robot/Robot.java +++ b/src/main/java/frc/robot/Robot.java @@ -47,7 +47,7 @@ public void robotInit() { String logPath = "/media/sda1/aoede"; DataLogManager.start(logPath); - DriverStation.startDataLog(DataLogManager.getLog()); + DriverStation.startDataLog(DataLogManager.getLog());` SignalLogger.setPath(logPath); SignalLogger.start(); diff --git a/src/main/java/lib/logger/DataLogUtil.java b/src/main/java/lib/logger/DataLogUtil.java index ad2cf73c..4aee0de7 100644 --- a/src/main/java/lib/logger/DataLogUtil.java +++ b/src/main/java/lib/logger/DataLogUtil.java @@ -73,15 +73,13 @@ public void addString(String logName, Supplier updateChecker, boolean up } public void addPose2d(String logName, Supplier updateChecker, boolean updateNT) { - addDoubleArray(logName + "/translation", + addDoubleArray(logName, () -> new double[]{ updateChecker.get().getX(), - updateChecker.get().getY() + updateChecker.get().getY(), + updateChecker.get().getRotation().getRadians() }, updateNT); - addDouble(logName + "/rotation", - () -> updateChecker.get().getRotation().getDegrees(), - updateNT); } public void addPose2dArray(String logName, Supplier updateChecker, boolean updateNT) { @@ -94,15 +92,11 @@ public void addPose2dArray(String logName, Supplier updateChecker, boo } public void addPose3d(String logName, Supplier updateChecker, boolean updateNT) { - addDoubleArray(logName + "/translation", + addDoubleArray(logName, () -> new double[] { updateChecker.get().getX(), updateChecker.get().getY(), - updateChecker.get().getZ() - }, - updateNT); - addDoubleArray(logName + "/rotation", - () -> new double[] { + updateChecker.get().getZ(), updateChecker.get().getRotation().getQuaternion().getW(), updateChecker.get().getRotation().getQuaternion().getX(), updateChecker.get().getRotation().getQuaternion().getY(), @@ -120,22 +114,16 @@ public void addPose3dArray(String logName, Supplier updateChecker, boo } } - public void addSwerveModuleState(String logName, Supplier updateChecker, boolean updateNT) { - addDouble(logName + "/velocity", - () -> updateChecker.get().speedMetersPerSecond, - updateNT); - addDouble(logName + "/postion", - () -> updateChecker.get().angle.getRadians(), - updateNT); - } - public void addSwerveModuleStateArray(String logName, Supplier updateChecker, boolean updateNT) { - for (int i = 0; i < updateChecker.get().length; i++) { - int finalI = i; - addSwerveModuleState(logName + "/" + i, - () -> updateChecker.get()[finalI], - updateNT); - } + addDoubleArray(logName, () -> { + double[] stateArray = new double[8]; + for (int i = 0; i < updateChecker.get().length * 2; i += 2) { + stateArray[i] = updateChecker.get()[(int) (i / 2.0)].angle.getRadians(); + stateArray[i + 1] = updateChecker.get()[(int) (i / 2.0)].speedMetersPerSecond; + } + return stateArray; + }, + updateNT); } public void updateLogs() { From 3876ecba3f65d63ccaade0c7a55a8a7c25d66bba Mon Sep 17 00:00:00 2001 From: GearBoxFox <98189655+GearBoxFox@users.noreply.github.com> Date: Thu, 7 Mar 2024 13:24:30 -0500 Subject: [PATCH 2/2] string null safety for sonarqube --- src/main/java/lib/logger/DataLogUtil.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/java/lib/logger/DataLogUtil.java b/src/main/java/lib/logger/DataLogUtil.java index 4aee0de7..5a67af64 100644 --- a/src/main/java/lib/logger/DataLogUtil.java +++ b/src/main/java/lib/logger/DataLogUtil.java @@ -8,6 +8,7 @@ import java.util.ArrayList; import java.util.List; +import java.util.Objects; import java.util.function.BooleanSupplier; import java.util.function.DoubleSupplier; import java.util.function.Supplier; @@ -22,7 +23,7 @@ public class DataLogUtil { public static DataLogTable getTable(String name) { for (DataLogTable table : logTables) { - if (table.name == name) { + if (Objects.equals(table.name, name)) { return table; } }