From faf2840b51a08c6e76249f34d699931fdb448af6 Mon Sep 17 00:00:00 2001 From: oh-yes-0-fps Date: Tue, 7 Jan 2025 12:47:52 -0500 Subject: [PATCH 1/3] Revert "[epilogue] Add a measure's symbol to its name when logged by Epilogue (#7535)" This reverts commit 469bb3290d2f3cfd0a90c572fc8ab01f2cd0be53. --- .../edu/wpi/first/epilogue/logging/EpilogueBackend.java | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/epilogue-runtime/src/main/java/edu/wpi/first/epilogue/logging/EpilogueBackend.java b/epilogue-runtime/src/main/java/edu/wpi/first/epilogue/logging/EpilogueBackend.java index 6759460fadd..f006a319dca 100644 --- a/epilogue-runtime/src/main/java/edu/wpi/first/epilogue/logging/EpilogueBackend.java +++ b/epilogue-runtime/src/main/java/edu/wpi/first/epilogue/logging/EpilogueBackend.java @@ -198,10 +198,9 @@ default void log(String identifier, Collection value, Struct struct) { * * @param identifier the identifier of the data field * @param value the new value of the data field - * @param the dimension of the unit */ - default void log(String identifier, Measure value) { - log(identifier, value, value.baseUnit()); + default void log(String identifier, Measure value) { + log(identifier, value.baseUnitMagnitude()); } /** @@ -213,7 +212,7 @@ default void log(String identifier, Measure value) { * @param the dimension of the unit */ default void log(String identifier, Measure value, U unit) { - log(identifier + " (" + unit.symbol() + ")", value.in(unit)); + log(identifier, value.in(unit)); } /** From d7fddd2d1cbdf610441b06fe671211fa1f0bc040 Mon Sep 17 00:00:00 2001 From: oh-yes-0-fps Date: Tue, 7 Jan 2025 14:10:37 -0500 Subject: [PATCH 2/3] add unit metadata to epilogue --- .../first/epilogue/logging/EpilogueBackend.java | 17 +++++++++++++++-- .../wpi/first/epilogue/logging/FileBackend.java | 14 ++++++++++++++ .../epilogue/logging/NTEpilogueBackend.java | 16 ++++++++++++++++ 3 files changed, 45 insertions(+), 2 deletions(-) diff --git a/epilogue-runtime/src/main/java/edu/wpi/first/epilogue/logging/EpilogueBackend.java b/epilogue-runtime/src/main/java/edu/wpi/first/epilogue/logging/EpilogueBackend.java index f006a319dca..ef366b582fa 100644 --- a/epilogue-runtime/src/main/java/edu/wpi/first/epilogue/logging/EpilogueBackend.java +++ b/epilogue-runtime/src/main/java/edu/wpi/first/epilogue/logging/EpilogueBackend.java @@ -193,14 +193,27 @@ default void log(String identifier, Collection value, Struct struct) { log(identifier, array, struct); } + /** + * Logs a unit's symbol. + * + * @param identifier the identifier of the data field + * @param value the new value of the data field + */ + default void log(String identifier, Unit value) { + log(identifier, value.symbol()); + } + /** * Logs a measurement's value in terms of its base unit. + * + *

If the base unit is different from a prior call with the same + * identifier the value will be ignored. * * @param identifier the identifier of the data field * @param value the new value of the data field */ - default void log(String identifier, Measure value) { - log(identifier, value.baseUnitMagnitude()); + default void log(String identifier, Measure value) { + log(identifier, value, value.baseUnit()); } /** diff --git a/epilogue-runtime/src/main/java/edu/wpi/first/epilogue/logging/FileBackend.java b/epilogue-runtime/src/main/java/edu/wpi/first/epilogue/logging/FileBackend.java index 2b5b6b2071b..80ef5aa8fa7 100644 --- a/epilogue-runtime/src/main/java/edu/wpi/first/epilogue/logging/FileBackend.java +++ b/epilogue-runtime/src/main/java/edu/wpi/first/epilogue/logging/FileBackend.java @@ -6,6 +6,8 @@ import static edu.wpi.first.util.ErrorMessages.requireNonNullParam; +import edu.wpi.first.units.Measure; +import edu.wpi.first.units.Unit; import edu.wpi.first.util.datalog.BooleanArrayLogEntry; import edu.wpi.first.util.datalog.BooleanLogEntry; import edu.wpi.first.util.datalog.DataLog; @@ -31,6 +33,7 @@ public class FileBackend implements EpilogueBackend { private final DataLog m_dataLog; private final Map m_entries = new HashMap<>(); private final Map m_subLoggers = new HashMap<>(); + private final Map m_units = new HashMap<>(); /** * Creates a new file-based backend. @@ -141,4 +144,15 @@ public void log(String identifier, S[] value, Struct struct) { m_dataLog.addSchema(struct); getEntry(identifier, (log, k) -> StructArrayLogEntry.create(log, k, struct)).append(value); } + + @Override + public void log(String identifier, Measure value, U unit) { + DoubleLogEntry entry = getEntry(identifier, DoubleLogEntry::new); + entry.append(value.in(unit)); + Unit cachedUnit = m_units.get(identifier); + if (m_units.containsKey(identifier) || !cachedUnit.equivalent(unit)) { + entry.setMetadata("{ \"unit\": \"" + unit.symbol() + "\" }"); + m_units.put(identifier, unit); + } + } } diff --git a/epilogue-runtime/src/main/java/edu/wpi/first/epilogue/logging/NTEpilogueBackend.java b/epilogue-runtime/src/main/java/edu/wpi/first/epilogue/logging/NTEpilogueBackend.java index cf381a2f021..678a45c38f8 100644 --- a/epilogue-runtime/src/main/java/edu/wpi/first/epilogue/logging/NTEpilogueBackend.java +++ b/epilogue-runtime/src/main/java/edu/wpi/first/epilogue/logging/NTEpilogueBackend.java @@ -19,6 +19,8 @@ import edu.wpi.first.networktables.StringPublisher; import edu.wpi.first.networktables.StructArrayPublisher; import edu.wpi.first.networktables.StructPublisher; +import edu.wpi.first.units.Measure; +import edu.wpi.first.units.Unit; import edu.wpi.first.util.struct.Struct; import java.util.HashMap; import java.util.Map; @@ -32,6 +34,7 @@ public class NTEpilogueBackend implements EpilogueBackend { private final Map m_publishers = new HashMap<>(); private final Map m_nestedBackends = new HashMap<>(); + private final Map m_units = new HashMap<>(); /** * Creates a logging backend that sends information to NetworkTables. @@ -164,4 +167,17 @@ public void log(String identifier, S[] value, Struct struct) { identifier, k -> m_nt.getStructArrayTopic(k, struct).publish())) .set(value); } + + @Override + public void log(String identifier, Measure value, U unit) { + DoublePublisher pub = (DoublePublisher) + m_publishers.computeIfAbsent( + identifier, k -> m_nt.getDoubleTopic(k).publish()); + pub.set(value.in(unit)); + Unit cachedUnit = m_units.get(identifier); + if (cachedUnit == null || !cachedUnit.equivalent(unit)) { + pub.getTopic().setProperty(identifier, identifier); + m_units.put(identifier, unit); + } + } } From 88b1c921f8f9df64e95797601fc46e69f156a644 Mon Sep 17 00:00:00 2001 From: oh-yes-0-fps Date: Tue, 7 Jan 2025 15:11:49 -0500 Subject: [PATCH 3/3] ran javaFormat --- .../edu/wpi/first/epilogue/logging/EpilogueBackend.java | 6 +++--- .../edu/wpi/first/epilogue/logging/NTEpilogueBackend.java | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/epilogue-runtime/src/main/java/edu/wpi/first/epilogue/logging/EpilogueBackend.java b/epilogue-runtime/src/main/java/edu/wpi/first/epilogue/logging/EpilogueBackend.java index ef366b582fa..dcd9f59585d 100644 --- a/epilogue-runtime/src/main/java/edu/wpi/first/epilogue/logging/EpilogueBackend.java +++ b/epilogue-runtime/src/main/java/edu/wpi/first/epilogue/logging/EpilogueBackend.java @@ -205,9 +205,9 @@ default void log(String identifier, Unit value) { /** * Logs a measurement's value in terms of its base unit. - * - *

If the base unit is different from a prior call with the same - * identifier the value will be ignored. + * + *

If the base unit is different from a prior call with the same identifier the value will be + * ignored. * * @param identifier the identifier of the data field * @param value the new value of the data field diff --git a/epilogue-runtime/src/main/java/edu/wpi/first/epilogue/logging/NTEpilogueBackend.java b/epilogue-runtime/src/main/java/edu/wpi/first/epilogue/logging/NTEpilogueBackend.java index 678a45c38f8..ab7363175c5 100644 --- a/epilogue-runtime/src/main/java/edu/wpi/first/epilogue/logging/NTEpilogueBackend.java +++ b/epilogue-runtime/src/main/java/edu/wpi/first/epilogue/logging/NTEpilogueBackend.java @@ -170,9 +170,9 @@ public void log(String identifier, S[] value, Struct struct) { @Override public void log(String identifier, Measure value, U unit) { - DoublePublisher pub = (DoublePublisher) - m_publishers.computeIfAbsent( - identifier, k -> m_nt.getDoubleTopic(k).publish()); + DoublePublisher pub = + (DoublePublisher) + m_publishers.computeIfAbsent(identifier, k -> m_nt.getDoubleTopic(k).publish()); pub.set(value.in(unit)); Unit cachedUnit = m_units.get(identifier); if (cachedUnit == null || !cachedUnit.equivalent(unit)) {