From 73dfb6b7ce5178f640b08cb53227f9b58577ffe0 Mon Sep 17 00:00:00 2001 From: Jade Turner Date: Mon, 10 Jun 2024 19:31:25 +0800 Subject: [PATCH 01/14] Fix build on nightly --- .gitignore | 4 ++++ .../org/littletonrobotics/urcl/URCLJNI.java | 24 ++++++++----------- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/.gitignore b/.gitignore index a332fb2..afba9e5 100644 --- a/.gitignore +++ b/.gitignore @@ -158,3 +158,7 @@ bin/ # End of https://www.gitignore.io/api/c++,java,linux,macos,gradle,windows,visualstudiocode + +# clangd +/.cache +compile_commands.json diff --git a/src/main/java/org/littletonrobotics/urcl/URCLJNI.java b/src/main/java/org/littletonrobotics/urcl/URCLJNI.java index 8ad75d4..fb3ed3d 100644 --- a/src/main/java/org/littletonrobotics/urcl/URCLJNI.java +++ b/src/main/java/org/littletonrobotics/urcl/URCLJNI.java @@ -8,6 +8,7 @@ package org.littletonrobotics.urcl; import java.io.IOException; +import java.lang.System; import java.nio.ByteBuffer; import java.util.concurrent.atomic.AtomicBoolean; @@ -18,7 +19,6 @@ */ public class URCLJNI { static boolean libraryLoaded = false; - static RuntimeLoader loader = null; /** * Helper class for determining whether or not to load the driver on static @@ -29,7 +29,7 @@ public static class Helper { /** * Get whether to load the driver on static init. - * + * * @return true if the driver will load on static init */ public static boolean getExtractOnStaticLoad() { @@ -38,7 +38,7 @@ public static boolean getExtractOnStaticLoad() { /** * Set whether to load the driver on static init. - * + * * @param load the new value */ public static void setExtractOnStaticLoad(boolean load) { @@ -49,9 +49,7 @@ public static void setExtractOnStaticLoad(boolean load) { static { if (Helper.getExtractOnStaticLoad()) { try { - loader = new RuntimeLoader<>("URCLDriver", RuntimeLoader.getDefaultExtractionRoot(), - URCLJNI.class); - loader.loadLibrary(); + RuntimeLoader.loadLibrary("URCLDriver"); } catch (IOException ex) { ex.printStackTrace(); System.exit(1); @@ -62,32 +60,30 @@ public static void setExtractOnStaticLoad(boolean load) { /** * Force load the library. - * + * * @throws java.io.IOException thrown if the native library cannot be found */ public static synchronized void forceLoad() throws IOException { if (libraryLoaded) { return; } - loader = new RuntimeLoader<>("URCLDriver", RuntimeLoader.getDefaultExtractionRoot(), - URCLJNI.class); - loader.loadLibrary(); + RuntimeLoader.loadLibrary("URCLDriver"); libraryLoaded = true; } /** Start logging. */ public static native void start(); - /** + /** * Get the shared buffer with persistent data. - * + * * @return The shared buffer */ public static native ByteBuffer getPersistentBuffer(); - /** + /** * Get the shared buffer with periodic data. - * + * * @return The shared buffer */ public static native ByteBuffer getPeriodicBuffer(); From dfa511cd6aeb3aace4f80a5bd81bb09f133f5391 Mon Sep 17 00:00:00 2001 From: Jade Turner Date: Mon, 10 Jun 2024 19:25:47 +0800 Subject: [PATCH 02/14] Add an option to run without NetworkTables Resolves https://github.com/Mechanical-Advantage/URCL/issues/5 --- .../java/org/littletonrobotics/urcl/URCL.java | 70 ++++++++++++++----- src/main/native/cpp/URCL.cpp | 35 ++++++++-- src/main/native/include/URCL.h | 31 ++++++-- 3 files changed, 110 insertions(+), 26 deletions(-) diff --git a/src/main/java/org/littletonrobotics/urcl/URCL.java b/src/main/java/org/littletonrobotics/urcl/URCL.java index 1025498..eea79b7 100644 --- a/src/main/java/org/littletonrobotics/urcl/URCL.java +++ b/src/main/java/org/littletonrobotics/urcl/URCL.java @@ -15,18 +15,21 @@ import edu.wpi.first.networktables.NetworkTableInstance; import edu.wpi.first.networktables.RawPublisher; +import edu.wpi.first.util.datalog.DataLog; +import edu.wpi.first.util.datalog.RawLogEntry; +import edu.wpi.first.wpilibj.DataLogManager; import edu.wpi.first.wpilibj.DriverStation; import edu.wpi.first.wpilibj.Notifier; /** *

URCL (Unofficial REV-Compatible Logger)

- * + * * This unofficial logger enables automatic capture of CAN traffic from REV * motor controllers to NetworkTables, viewable using AdvantageScope. See the * corresponding * AdvantageScope documentation for more details. - * + * *

* As this library is not an official REV tool, support queries should be * directed to the URCL @@ -44,6 +47,10 @@ public class URCL { private static RawPublisher periodicPublisher; private static RawPublisher aliasesPublisher; private static Notifier notifier; + private static final DataLog datalog = DataLogManager.getLog(); + private static RawLogEntry persistentLogEntry = new RawLogEntry(datalog, "URCL/Raw/Persistent"); + private static RawLogEntry periodicLogEntry = new RawLogEntry(datalog, "/URCL/Raw/Periodic"); + private static RawLogEntry aliasLogEntry = new RawLogEntry(datalog, "/URCL/Raw/Aliases"); /** * Start capturing data from REV motor controllers to NetworkTables. This method @@ -56,10 +63,31 @@ public static void start() { /** * Start capturing data from REV motor controllers to NetworkTables. This method * should only be called once. - * + * + * @param withNT Whether or not to run with NetworkTables. + */ + public static void start(boolean withNT) { + start(Map.of(), withNT); + } + + /** + * Start capturing data from REV motor controllers to NetworkTables. This method + * should only be called once. + * * @param aliases The set of aliases mapping CAN IDs to names. */ public static void start(Map aliases) { + start(aliases, true); + } + + /** + * Start capturing data from REV motor controllers to NetworkTables. This method + * should only be called once. + * + * @param aliases The set of aliases mapping CAN IDs to names. + * @param withNT Whether or not to run with NetworkTables. + */ + public static void start(Map aliases, boolean withNT) { if (running) { DriverStation.reportError("URCL cannot be started multiple times", true); return; @@ -68,7 +96,7 @@ public static void start(Map aliases) { // Update aliases buffer updateAliasesBuffer(aliases); - + // Start driver URCLJNI.start(); persistentBuffer = URCLJNI.getPersistentBuffer(); @@ -76,22 +104,32 @@ public static void start(Map aliases) { persistentBuffer.order(ByteOrder.LITTLE_ENDIAN); periodicBuffer.order(ByteOrder.LITTLE_ENDIAN); - // Start publishers - persistentPublisher = NetworkTableInstance.getDefault() + if (withNT) { + // Start publishers + persistentPublisher = NetworkTableInstance.getDefault() .getRawTopic("/URCL/Raw/Persistent") .publish("URCLr2_persistent"); - periodicPublisher = NetworkTableInstance.getDefault() + periodicPublisher = NetworkTableInstance.getDefault() .getRawTopic("/URCL/Raw/Periodic") .publish("URCLr2_periodic"); - aliasesPublisher = NetworkTableInstance.getDefault() + aliasesPublisher = NetworkTableInstance.getDefault() .getRawTopic("/URCL/Raw/Aliases") .publish("URCLr2_aliases"); - notifier = new Notifier(() -> { - var data = getData(); - persistentPublisher.set(data[0]); - periodicPublisher.set(data[1]); - aliasesPublisher.set(data[2]); - }); + notifier = new Notifier(() -> { + var data = getData(); + persistentPublisher.set(data[0]); + periodicPublisher.set(data[1]); + aliasesPublisher.set(data[2]); + }); + } else { + notifier = new Notifier(() -> { + var data = getData(); + persistentLogEntry.append(data[0]); + periodicLogEntry.append(data[1]); + aliasLogEntry.append(data[2]); + }); + } + notifier.setName("URCL"); notifier.startPeriodic(period); } @@ -101,7 +139,7 @@ public static void start(Map aliases) { * AdvantageKit. This * method should only be called once. - * + * * @return The log supplier, to be called periodically */ public static Supplier startExternal() { @@ -113,7 +151,7 @@ public static Supplier startExternal() { * AdvantageKit. This * method should only be called once. - * + * * @param aliases The set of aliases mapping CAN IDs to names. * @return The log supplier, to be called periodically */ diff --git a/src/main/native/cpp/URCL.cpp b/src/main/native/cpp/URCL.cpp index 965f1bf..dd5bb9b 100644 --- a/src/main/native/cpp/URCL.cpp +++ b/src/main/native/cpp/URCL.cpp @@ -10,8 +10,10 @@ #include #include +#include #include #include +#include #include #include #include @@ -26,15 +28,15 @@ static constexpr auto period = 20_ms; bool URCL::running = false; char* URCL::persistentBuffer = nullptr; char* URCL::periodicBuffer = nullptr; -nt::RawPublisher URCL::persistentPublisher = +nt::RawPublisher URCL::persistentPublisher = nt::NetworkTableInstance::GetDefault() .GetRawTopic("/URCL/Raw/Persistent") .Publish("URCLr2_persistent"); -nt::RawPublisher URCL::periodicPublisher = +nt::RawPublisher URCL::periodicPublisher = nt::NetworkTableInstance::GetDefault() .GetRawTopic("/URCL/Raw/Periodic") .Publish("URCLr2_periodic"); -nt::RawPublisher URCL::aliasesPublisher = +nt::RawPublisher URCL::aliasesPublisher = nt::NetworkTableInstance::GetDefault() .GetRawTopic("/URCL/Raw/Aliases") .Publish("URCLr2_aliases"); @@ -45,7 +47,18 @@ void URCL::Start() { URCL::Start(aliases); } +void URCL::Start(bool withNT) { + std::map aliases; + URCL::Start(aliases, withNT); +} + void URCL::Start(std::map aliases) { + URCL::Start(aliases, true); +} + +void URCL::Start(std::map aliases, bool withNT) { + URCL::withNT = withNT; + if (running) { FRC_ReportError(frc::err::Error, "{}", "URCL cannot be started multiple times"); return; @@ -77,6 +90,11 @@ void URCL::Start(std::map aliases) { persistentBuffer = URCLDriver_getPersistentBuffer(); periodicBuffer = URCLDriver_getPeriodicBuffer(); + persistentLogEntry = wpi::log::RawLogEntry{frc::DataLogManager::GetLog(), "/URCL/Raw/Persistent"}; + periodicLogEntry = wpi::log::RawLogEntry{frc::DataLogManager::GetLog(), "/URCL/Raw/Periodic"}; + aliasesLogEntry = wpi::log::RawLogEntry{frc::DataLogManager::GetLog(), "/URCL/Raw/Aliases"}; + aliasesLogEntry.Append(aliasesVector); + // Start notifier notifier.SetName("URCL"); notifier.StartPeriodic(period); @@ -92,6 +110,11 @@ void URCL::Periodic() { std::vector periodicVector(periodicSize); std::memcpy(persistentVector.data(), persistentBuffer + 4, persistentVector.size()); std::memcpy(periodicVector.data(), periodicBuffer + 4, periodicVector.size()); - persistentPublisher.Set(persistentVector); - periodicPublisher.Set(periodicVector); -} \ No newline at end of file + if (withNT) { + persistentPublisher.Set(persistentVector); + periodicPublisher.Set(periodicVector); + } else { + persistentLogEntry.Append(persistentVector); + periodicLogEntry.Append(periodicVector); + } +} diff --git a/src/main/native/include/URCL.h b/src/main/native/include/URCL.h index c514451..a649480 100644 --- a/src/main/native/include/URCL.h +++ b/src/main/native/include/URCL.h @@ -7,17 +7,19 @@ #pragma once +#include "frc/DataLogManager.h" +#include "wpi/DataLog.h" #include #include /** * URCL (Unofficial REV-Compatible Logger) - * + * * This unofficial logger enables automatic capture of CAN traffic from REV * motor controllers to NetworkTables, viewable using AdvantageScope. See the * corresponding AdvantageScope documentation for more details: * https://github.com/Mechanical-Advantage/AdvantageScope/blob/main/docs/REV-LOGGING.md - * + * * As this library is not an official REV tool, support queries should be * directed to the URCL issues page or software@team6328.org * rather than REV's support contact. @@ -35,19 +37,40 @@ class URCL final { /** * Start capturing data from REV motor controllers to NetworkTables. This method * should only be called once. - * + * + * @param withNT Whether or not to run with NetworkTables. + */ + static void Start(bool withNT); + + /** + * Start capturing data from REV motor controllers to NetworkTables. This method + * should only be called once. + * * @param aliases The set of aliases mapping CAN IDs to names. */ static void Start(std::map aliases); + /** + * Start capturing data from REV motor controllers to NetworkTables. This method + * should only be called once. + * + * @param aliases The set of aliases mapping CAN IDs to names. + * @param withNT Whether or not to run with NetworkTables. + */ + static void Start(std::map aliases, bool withNT); + private: static void Periodic(); static bool running; + static bool withNT; static char* persistentBuffer; static char* periodicBuffer; static nt::RawPublisher persistentPublisher; static nt::RawPublisher periodicPublisher; static nt::RawPublisher aliasesPublisher; + static wpi::log::RawLogEntry persistentLogEntry; + static wpi::log::RawLogEntry periodicLogEntry; + static wpi::log::RawLogEntry aliasesLogEntry; static frc::Notifier notifier; -}; \ No newline at end of file +}; From 8ff55123509aa39949881dc6d301a9edfe2ab2b7 Mon Sep 17 00:00:00 2001 From: Jade Turner Date: Mon, 10 Jun 2024 20:07:45 +0800 Subject: [PATCH 03/14] Update to 2024.2.0 --- URCL.json | 14 +++++++------- publish.gradle | 2 +- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/URCL.json b/URCL.json index 33cc527..8b55d5c 100644 --- a/URCL.json +++ b/URCL.json @@ -1,25 +1,25 @@ { "fileName": "URCL.json", "name": "URCL", - "version": "2024.1.0", + "version": "2024.2.0", "frcYear": "2024", "uuid": "84246d17-a797-4d1e-bd9f-c59cd8d2477c", "mavenUrls": [ - "https://raw.githubusercontent.com/Mechanical-Advantage/URCL/2024.1.0" + "https://raw.githubusercontent.com/Mechanical-Advantage/URCL/2024.2.0" ], "jsonUrl": "https://raw.githubusercontent.com/Mechanical-Advantage/URCL/maven/URCL.json", "javaDependencies": [ { "groupId": "org.littletonrobotics.urcl", "artifactId": "URCL-java", - "version": "2024.1.0" + "version": "2024.2.0" } ], "jniDependencies": [ { "groupId": "org.littletonrobotics.urcl", "artifactId": "URCL-driver", - "version": "2024.1.0", + "version": "2024.2.0", "skipInvalidPlatforms": true, "isJar": false, "validPlatforms": [ @@ -34,7 +34,7 @@ { "groupId": "org.littletonrobotics.urcl", "artifactId": "URCL-cpp", - "version": "2024.1.0", + "version": "2024.2.0", "libName": "URCL", "headerClassifier": "headers", "sharedLibrary": false, @@ -49,7 +49,7 @@ { "groupId": "org.littletonrobotics.urcl", "artifactId": "URCL-driver", - "version": "2024.1.0", + "version": "2024.2.0", "libName": "URCLDriver", "headerClassifier": "headers", "sharedLibrary": false, @@ -62,4 +62,4 @@ ] } ] -} \ No newline at end of file +} diff --git a/publish.gradle b/publish.gradle index c223312..35e0cd1 100644 --- a/publish.gradle +++ b/publish.gradle @@ -2,7 +2,7 @@ apply plugin: 'maven-publish' ext.licenseFile = files("$rootDir/LICENSE.txt") -def pubVersion = '2024.1.0' +def pubVersion = '2024.2.0' def outputsFolder = file("$buildDir/outputs") From d1c0f3af87b1ec5946ea2ba288372f7230e6563d Mon Sep 17 00:00:00 2001 From: Jade Turner Date: Wed, 7 Aug 2024 14:30:49 +0800 Subject: [PATCH 04/14] fix --- src/main/java/org/littletonrobotics/urcl/URCL.java | 6 +++--- src/main/native/cpp/URCL.cpp | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/main/java/org/littletonrobotics/urcl/URCL.java b/src/main/java/org/littletonrobotics/urcl/URCL.java index eea79b7..e219b13 100644 --- a/src/main/java/org/littletonrobotics/urcl/URCL.java +++ b/src/main/java/org/littletonrobotics/urcl/URCL.java @@ -48,9 +48,9 @@ public class URCL { private static RawPublisher aliasesPublisher; private static Notifier notifier; private static final DataLog datalog = DataLogManager.getLog(); - private static RawLogEntry persistentLogEntry = new RawLogEntry(datalog, "URCL/Raw/Persistent"); - private static RawLogEntry periodicLogEntry = new RawLogEntry(datalog, "/URCL/Raw/Periodic"); - private static RawLogEntry aliasLogEntry = new RawLogEntry(datalog, "/URCL/Raw/Aliases"); + private static RawLogEntry persistentLogEntry = new RawLogEntry(datalog, "URCL/Raw/Persistent", "", "URCLr2_persistent"); + private static RawLogEntry periodicLogEntry = new RawLogEntry(datalog, "/URCL/Raw/Periodic", "", "URCLr2_periodic"); + private static RawLogEntry aliasLogEntry = new RawLogEntry(datalog, "/URCL/Raw/Aliases", "", "URCLr2_aliases"); /** * Start capturing data from REV motor controllers to NetworkTables. This method diff --git a/src/main/native/cpp/URCL.cpp b/src/main/native/cpp/URCL.cpp index dd5bb9b..cb29176 100644 --- a/src/main/native/cpp/URCL.cpp +++ b/src/main/native/cpp/URCL.cpp @@ -90,9 +90,9 @@ void URCL::Start(std::map aliases, bool withNT) { persistentBuffer = URCLDriver_getPersistentBuffer(); periodicBuffer = URCLDriver_getPeriodicBuffer(); - persistentLogEntry = wpi::log::RawLogEntry{frc::DataLogManager::GetLog(), "/URCL/Raw/Persistent"}; - periodicLogEntry = wpi::log::RawLogEntry{frc::DataLogManager::GetLog(), "/URCL/Raw/Periodic"}; - aliasesLogEntry = wpi::log::RawLogEntry{frc::DataLogManager::GetLog(), "/URCL/Raw/Aliases"}; + persistentLogEntry = wpi::log::RawLogEntry{frc::DataLogManager::GetLog(), "/URCL/Raw/Persistent", "", "URCLr2_persistent"}; + periodicLogEntry = wpi::log::RawLogEntry{frc::DataLogManager::GetLog(), "/URCL/Raw/Periodic", "", "URCLr2_periodic"}; + aliasesLogEntry = wpi::log::RawLogEntry{frc::DataLogManager::GetLog(), "/URCL/Raw/Aliases", "", "URCLr2_aliases"}; aliasesLogEntry.Append(aliasesVector); // Start notifier From d5645b632900e4513f2038cf8f55fa846424d296 Mon Sep 17 00:00:00 2001 From: Jade Turner Date: Sun, 11 Aug 2024 10:50:32 +0800 Subject: [PATCH 05/14] fix --- URCL.json | 12 +-- publish.gradle | 2 +- .../java/org/littletonrobotics/urcl/URCL.java | 99 +++++++++++-------- src/main/native/cpp/URCL.cpp | 61 +++++++----- 4 files changed, 100 insertions(+), 74 deletions(-) diff --git a/URCL.json b/URCL.json index 8b55d5c..cd66abf 100644 --- a/URCL.json +++ b/URCL.json @@ -1,25 +1,25 @@ { "fileName": "URCL.json", "name": "URCL", - "version": "2024.2.0", + "version": "2024.1.0", "frcYear": "2024", "uuid": "84246d17-a797-4d1e-bd9f-c59cd8d2477c", "mavenUrls": [ - "https://raw.githubusercontent.com/Mechanical-Advantage/URCL/2024.2.0" + "https://raw.githubusercontent.com/Mechanical-Advantage/URCL/2024.1.0" ], "jsonUrl": "https://raw.githubusercontent.com/Mechanical-Advantage/URCL/maven/URCL.json", "javaDependencies": [ { "groupId": "org.littletonrobotics.urcl", "artifactId": "URCL-java", - "version": "2024.2.0" + "version": "2024.1.0" } ], "jniDependencies": [ { "groupId": "org.littletonrobotics.urcl", "artifactId": "URCL-driver", - "version": "2024.2.0", + "version": "2024.1.0", "skipInvalidPlatforms": true, "isJar": false, "validPlatforms": [ @@ -34,7 +34,7 @@ { "groupId": "org.littletonrobotics.urcl", "artifactId": "URCL-cpp", - "version": "2024.2.0", + "version": "2024.1.0", "libName": "URCL", "headerClassifier": "headers", "sharedLibrary": false, @@ -49,7 +49,7 @@ { "groupId": "org.littletonrobotics.urcl", "artifactId": "URCL-driver", - "version": "2024.2.0", + "version": "2024.1.0", "libName": "URCLDriver", "headerClassifier": "headers", "sharedLibrary": false, diff --git a/publish.gradle b/publish.gradle index 35e0cd1..c223312 100644 --- a/publish.gradle +++ b/publish.gradle @@ -2,7 +2,7 @@ apply plugin: 'maven-publish' ext.licenseFile = files("$rootDir/LICENSE.txt") -def pubVersion = '2024.2.0' +def pubVersion = '2024.1.0' def outputsFolder = file("$buildDir/outputs") diff --git a/src/main/java/org/littletonrobotics/urcl/URCL.java b/src/main/java/org/littletonrobotics/urcl/URCL.java index e219b13..0fbdbdf 100644 --- a/src/main/java/org/littletonrobotics/urcl/URCL.java +++ b/src/main/java/org/littletonrobotics/urcl/URCL.java @@ -48,7 +48,8 @@ public class URCL { private static RawPublisher aliasesPublisher; private static Notifier notifier; private static final DataLog datalog = DataLogManager.getLog(); - private static RawLogEntry persistentLogEntry = new RawLogEntry(datalog, "URCL/Raw/Persistent", "", "URCLr2_persistent"); + private static RawLogEntry persistentLogEntry = new RawLogEntry(datalog, "URCL/Raw/Persistent", "", + "URCLr2_persistent"); private static RawLogEntry periodicLogEntry = new RawLogEntry(datalog, "/URCL/Raw/Periodic", "", "URCLr2_periodic"); private static RawLogEntry aliasLogEntry = new RawLogEntry(datalog, "/URCL/Raw/Aliases", "", "URCLr2_aliases"); @@ -61,13 +62,13 @@ public static void start() { } /** - * Start capturing data from REV motor controllers to NetworkTables. This method + * Start capturing data from REV motor controllers to a Datalog. This method * should only be called once. * - * @param withNT Whether or not to run with NetworkTables. + * @param log the DataLog to log to. */ - public static void start(boolean withNT) { - start(Map.of(), withNT); + public static void start(DataLog log) { + start(Map.of(), log); } /** @@ -77,17 +78,6 @@ public static void start(boolean withNT) { * @param aliases The set of aliases mapping CAN IDs to names. */ public static void start(Map aliases) { - start(aliases, true); - } - - /** - * Start capturing data from REV motor controllers to NetworkTables. This method - * should only be called once. - * - * @param aliases The set of aliases mapping CAN IDs to names. - * @param withNT Whether or not to run with NetworkTables. - */ - public static void start(Map aliases, boolean withNT) { if (running) { DriverStation.reportError("URCL cannot be started multiple times", true); return; @@ -104,32 +94,61 @@ public static void start(Map aliases, boolean withNT) { persistentBuffer.order(ByteOrder.LITTLE_ENDIAN); periodicBuffer.order(ByteOrder.LITTLE_ENDIAN); - if (withNT) { - // Start publishers - persistentPublisher = NetworkTableInstance.getDefault() + // Start publishers + persistentPublisher = NetworkTableInstance.getDefault() .getRawTopic("/URCL/Raw/Persistent") .publish("URCLr2_persistent"); - periodicPublisher = NetworkTableInstance.getDefault() + periodicPublisher = NetworkTableInstance.getDefault() .getRawTopic("/URCL/Raw/Periodic") .publish("URCLr2_periodic"); - aliasesPublisher = NetworkTableInstance.getDefault() + aliasesPublisher = NetworkTableInstance.getDefault() .getRawTopic("/URCL/Raw/Aliases") .publish("URCLr2_aliases"); - notifier = new Notifier(() -> { - var data = getData(); - persistentPublisher.set(data[0]); - periodicPublisher.set(data[1]); - aliasesPublisher.set(data[2]); - }); - } else { - notifier = new Notifier(() -> { - var data = getData(); - persistentLogEntry.append(data[0]); - periodicLogEntry.append(data[1]); - aliasLogEntry.append(data[2]); - }); + notifier = new Notifier(() -> { + var data = getData(); + persistentPublisher.set(data[0]); + periodicPublisher.set(data[1]); + aliasesPublisher.set(data[2]); + }); + notifier.setName("URCL"); + notifier.startPeriodic(period); + } + + /** + * Start capturing data from REV motor controllers to a DataLog. This method + * should only be called once. + * + * @param aliases The set of aliases mapping CAN IDs to names. + * @param log the DataLog to log to. Note using a DataLog means it will not + * log to NetworkTables. + */ + public static void start(Map aliases, DataLog log) { + if (running) { + DriverStation.reportError("URCL cannot be started multiple times", true); + return; } + running = true; + + // Update aliases buffer + updateAliasesBuffer(aliases); + + // Start driver + URCLJNI.start(); + persistentBuffer = URCLJNI.getPersistentBuffer(); + periodicBuffer = URCLJNI.getPeriodicBuffer(); + persistentBuffer.order(ByteOrder.LITTLE_ENDIAN); + periodicBuffer.order(ByteOrder.LITTLE_ENDIAN); + persistentLogEntry = new RawLogEntry(datalog, "URCL/Raw/Persistent", "", + "URCLr2_persistent"); + periodicLogEntry = new RawLogEntry(datalog, "/URCL/Raw/Periodic", "", "URCLr2_periodic"); + aliasLogEntry = new RawLogEntry(datalog, "/URCL/Raw/Aliases", "", "URCLr2_aliases"); + notifier = new Notifier(() -> { + var data = getData(); + persistentLogEntry.append(data[0]); + periodicLogEntry.append(data[1]); + aliasLogEntry.append(data[2]); + }); notifier.setName("URCL"); notifier.startPeriodic(period); } @@ -159,9 +178,9 @@ public static Supplier startExternal(Map aliases) if (running) { DriverStation.reportError("URCL cannot be started multiple times", true); ByteBuffer[] emptyOutput = new ByteBuffer[] { - ByteBuffer.allocate(0), - ByteBuffer.allocate(0), - ByteBuffer.allocate(0) + ByteBuffer.allocate(0), + ByteBuffer.allocate(0), + ByteBuffer.allocate(0) }; return () -> emptyOutput; } @@ -205,9 +224,9 @@ private static ByteBuffer[] getData() { int persistentSize = persistentBuffer.getInt(0); int periodicSize = periodicBuffer.getInt(0); return new ByteBuffer[] { - persistentBuffer.slice(4, persistentSize), - periodicBuffer.slice(4, periodicSize), - aliasesBuffer + persistentBuffer.slice(4, persistentSize), + periodicBuffer.slice(4, periodicSize), + aliasesBuffer }; } } diff --git a/src/main/native/cpp/URCL.cpp b/src/main/native/cpp/URCL.cpp index cb29176..cb88f5e 100644 --- a/src/main/native/cpp/URCL.cpp +++ b/src/main/native/cpp/URCL.cpp @@ -8,38 +8,37 @@ #include "URCL.h" #include "URCLDriver.h" +#include +#include #include #include -#include +#include +#include #include #include -#include -#include -#include -#include -#include #include #include -#include -#include +#include +#include +#include +#include static constexpr auto period = 20_ms; bool URCL::running = false; -char* URCL::persistentBuffer = nullptr; -char* URCL::periodicBuffer = nullptr; +char *URCL::persistentBuffer = nullptr; +char *URCL::periodicBuffer = nullptr; nt::RawPublisher URCL::persistentPublisher = - nt::NetworkTableInstance::GetDefault() - .GetRawTopic("/URCL/Raw/Persistent") - .Publish("URCLr2_persistent"); + nt::NetworkTableInstance::GetDefault() + .GetRawTopic("/URCL/Raw/Persistent") + .Publish("URCLr2_persistent"); nt::RawPublisher URCL::periodicPublisher = - nt::NetworkTableInstance::GetDefault() - .GetRawTopic("/URCL/Raw/Periodic") - .Publish("URCLr2_periodic"); -nt::RawPublisher URCL::aliasesPublisher = - nt::NetworkTableInstance::GetDefault() - .GetRawTopic("/URCL/Raw/Aliases") - .Publish("URCLr2_aliases"); + nt::NetworkTableInstance::GetDefault() + .GetRawTopic("/URCL/Raw/Periodic") + .Publish("URCLr2_periodic"); +nt::RawPublisher URCL::aliasesPublisher = nt::NetworkTableInstance::GetDefault() + .GetRawTopic("/URCL/Raw/Aliases") + .Publish("URCLr2_aliases"); frc::Notifier URCL::notifier{URCL::Periodic}; void URCL::Start() { @@ -60,7 +59,8 @@ void URCL::Start(std::map aliases, bool withNT) { URCL::withNT = withNT; if (running) { - FRC_ReportError(frc::err::Error, "{}", "URCL cannot be started multiple times"); + FRC_ReportError(frc::err::Error, "{}", + "URCL cannot be started multiple times"); return; } @@ -68,7 +68,7 @@ void URCL::Start(std::map aliases, bool withNT) { std::ostringstream aliasesBuilder; aliasesBuilder << "{"; bool firstEntry = true; - for (auto const& [key, value] : aliases) { + for (auto const &[key, value] : aliases) { if (!firstEntry) { aliasesBuilder << ","; } @@ -82,7 +82,8 @@ void URCL::Start(std::map aliases, bool withNT) { aliasesBuilder << "}"; std::string aliasesString = aliasesBuilder.str(); std::vector aliasesVector(aliasesString.size()); - std::memcpy(aliasesVector.data(), aliasesString.c_str(), aliasesString.size()); + std::memcpy(aliasesVector.data(), aliasesString.c_str(), + aliasesString.size()); aliasesPublisher.Set(aliasesVector); // Start driver @@ -90,9 +91,14 @@ void URCL::Start(std::map aliases, bool withNT) { persistentBuffer = URCLDriver_getPersistentBuffer(); periodicBuffer = URCLDriver_getPeriodicBuffer(); - persistentLogEntry = wpi::log::RawLogEntry{frc::DataLogManager::GetLog(), "/URCL/Raw/Persistent", "", "URCLr2_persistent"}; - periodicLogEntry = wpi::log::RawLogEntry{frc::DataLogManager::GetLog(), "/URCL/Raw/Periodic", "", "URCLr2_periodic"}; - aliasesLogEntry = wpi::log::RawLogEntry{frc::DataLogManager::GetLog(), "/URCL/Raw/Aliases", "", "URCLr2_aliases"}; + persistentLogEntry = + wpi::log::RawLogEntry{frc::DataLogManager::GetLog(), + "/URCL/Raw/Persistent", "", "URCLr2_persistent"}; + periodicLogEntry = + wpi::log::RawLogEntry{frc::DataLogManager::GetLog(), "/URCL/Raw/Periodic", + "", "URCLr2_periodic"}; + aliasesLogEntry = wpi::log::RawLogEntry{ + frc::DataLogManager::GetLog(), "/URCL/Raw/Aliases", "", "URCLr2_aliases"}; aliasesLogEntry.Append(aliasesVector); // Start notifier @@ -108,7 +114,8 @@ void URCL::Periodic() { std::memcpy(&periodicSize, periodicBuffer, 4); std::vector persistentVector(persistentSize); std::vector periodicVector(periodicSize); - std::memcpy(persistentVector.data(), persistentBuffer + 4, persistentVector.size()); + std::memcpy(persistentVector.data(), persistentBuffer + 4, + persistentVector.size()); std::memcpy(periodicVector.data(), periodicBuffer + 4, periodicVector.size()); if (withNT) { persistentPublisher.Set(persistentVector); From 270d2ade82d4bca41019a1867209a904d93965d6 Mon Sep 17 00:00:00 2001 From: Jade Turner Date: Sun, 11 Aug 2024 11:42:39 +0800 Subject: [PATCH 06/14] lol --- src/main/java/org/littletonrobotics/urcl/URCL.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/org/littletonrobotics/urcl/URCL.java b/src/main/java/org/littletonrobotics/urcl/URCL.java index 0fbdbdf..536ab2f 100644 --- a/src/main/java/org/littletonrobotics/urcl/URCL.java +++ b/src/main/java/org/littletonrobotics/urcl/URCL.java @@ -48,7 +48,7 @@ public class URCL { private static RawPublisher aliasesPublisher; private static Notifier notifier; private static final DataLog datalog = DataLogManager.getLog(); - private static RawLogEntry persistentLogEntry = new RawLogEntry(datalog, "URCL/Raw/Persistent", "", + private static RawLogEntry persistentLogEntry = new RawLogEntry(datalog, "/URCL/Raw/Persistent", "", "URCLr2_persistent"); private static RawLogEntry periodicLogEntry = new RawLogEntry(datalog, "/URCL/Raw/Periodic", "", "URCLr2_periodic"); private static RawLogEntry aliasLogEntry = new RawLogEntry(datalog, "/URCL/Raw/Aliases", "", "URCLr2_aliases"); From f791b0cf3e3a67a6bbcb74e16dbeb1bf5deababb Mon Sep 17 00:00:00 2001 From: Jade Turner Date: Sun, 11 Aug 2024 11:43:54 +0800 Subject: [PATCH 07/14] fix --- src/main/java/org/littletonrobotics/urcl/URCL.java | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/src/main/java/org/littletonrobotics/urcl/URCL.java b/src/main/java/org/littletonrobotics/urcl/URCL.java index 536ab2f..daf5c21 100644 --- a/src/main/java/org/littletonrobotics/urcl/URCL.java +++ b/src/main/java/org/littletonrobotics/urcl/URCL.java @@ -47,11 +47,9 @@ public class URCL { private static RawPublisher periodicPublisher; private static RawPublisher aliasesPublisher; private static Notifier notifier; - private static final DataLog datalog = DataLogManager.getLog(); - private static RawLogEntry persistentLogEntry = new RawLogEntry(datalog, "/URCL/Raw/Persistent", "", - "URCLr2_persistent"); - private static RawLogEntry periodicLogEntry = new RawLogEntry(datalog, "/URCL/Raw/Periodic", "", "URCLr2_periodic"); - private static RawLogEntry aliasLogEntry = new RawLogEntry(datalog, "/URCL/Raw/Aliases", "", "URCLr2_aliases"); + private static RawLogEntry persistentLogEntry; + private static RawLogEntry periodicLogEntry; + private static RawLogEntry aliasLogEntry; /** * Start capturing data from REV motor controllers to NetworkTables. This method @@ -139,10 +137,10 @@ public static void start(Map aliases, DataLog log) { persistentBuffer.order(ByteOrder.LITTLE_ENDIAN); periodicBuffer.order(ByteOrder.LITTLE_ENDIAN); - persistentLogEntry = new RawLogEntry(datalog, "URCL/Raw/Persistent", "", + persistentLogEntry = new RawLogEntry(log, "URCL/Raw/Persistent", "", "URCLr2_persistent"); - periodicLogEntry = new RawLogEntry(datalog, "/URCL/Raw/Periodic", "", "URCLr2_periodic"); - aliasLogEntry = new RawLogEntry(datalog, "/URCL/Raw/Aliases", "", "URCLr2_aliases"); + periodicLogEntry = new RawLogEntry(log, "/URCL/Raw/Periodic", "", "URCLr2_periodic"); + aliasLogEntry = new RawLogEntry(log, "/URCL/Raw/Aliases", "", "URCLr2_aliases"); notifier = new Notifier(() -> { var data = getData(); persistentLogEntry.append(data[0]); From 72a5ec666c0f13d8d529413821609f4643b0ee95 Mon Sep 17 00:00:00 2001 From: Jade Turner Date: Tue, 20 Aug 2024 21:47:48 +0800 Subject: [PATCH 08/14] Revert "Fix build on nightly" This reverts commit 73dfb6b7ce5178f640b08cb53227f9b58577ffe0. --- .gitignore | 4 ---- .../org/littletonrobotics/urcl/URCLJNI.java | 24 +++++++++++-------- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/.gitignore b/.gitignore index afba9e5..a332fb2 100644 --- a/.gitignore +++ b/.gitignore @@ -158,7 +158,3 @@ bin/ # End of https://www.gitignore.io/api/c++,java,linux,macos,gradle,windows,visualstudiocode - -# clangd -/.cache -compile_commands.json diff --git a/src/main/java/org/littletonrobotics/urcl/URCLJNI.java b/src/main/java/org/littletonrobotics/urcl/URCLJNI.java index fb3ed3d..8ad75d4 100644 --- a/src/main/java/org/littletonrobotics/urcl/URCLJNI.java +++ b/src/main/java/org/littletonrobotics/urcl/URCLJNI.java @@ -8,7 +8,6 @@ package org.littletonrobotics.urcl; import java.io.IOException; -import java.lang.System; import java.nio.ByteBuffer; import java.util.concurrent.atomic.AtomicBoolean; @@ -19,6 +18,7 @@ */ public class URCLJNI { static boolean libraryLoaded = false; + static RuntimeLoader loader = null; /** * Helper class for determining whether or not to load the driver on static @@ -29,7 +29,7 @@ public static class Helper { /** * Get whether to load the driver on static init. - * + * * @return true if the driver will load on static init */ public static boolean getExtractOnStaticLoad() { @@ -38,7 +38,7 @@ public static boolean getExtractOnStaticLoad() { /** * Set whether to load the driver on static init. - * + * * @param load the new value */ public static void setExtractOnStaticLoad(boolean load) { @@ -49,7 +49,9 @@ public static void setExtractOnStaticLoad(boolean load) { static { if (Helper.getExtractOnStaticLoad()) { try { - RuntimeLoader.loadLibrary("URCLDriver"); + loader = new RuntimeLoader<>("URCLDriver", RuntimeLoader.getDefaultExtractionRoot(), + URCLJNI.class); + loader.loadLibrary(); } catch (IOException ex) { ex.printStackTrace(); System.exit(1); @@ -60,30 +62,32 @@ public static void setExtractOnStaticLoad(boolean load) { /** * Force load the library. - * + * * @throws java.io.IOException thrown if the native library cannot be found */ public static synchronized void forceLoad() throws IOException { if (libraryLoaded) { return; } - RuntimeLoader.loadLibrary("URCLDriver"); + loader = new RuntimeLoader<>("URCLDriver", RuntimeLoader.getDefaultExtractionRoot(), + URCLJNI.class); + loader.loadLibrary(); libraryLoaded = true; } /** Start logging. */ public static native void start(); - /** + /** * Get the shared buffer with persistent data. - * + * * @return The shared buffer */ public static native ByteBuffer getPersistentBuffer(); - /** + /** * Get the shared buffer with periodic data. - * + * * @return The shared buffer */ public static native ByteBuffer getPeriodicBuffer(); From 1052f156173ac6cc41786a9b346a9943071f0651 Mon Sep 17 00:00:00 2001 From: Jade Turner Date: Wed, 21 Aug 2024 12:09:44 +0800 Subject: [PATCH 09/14] Reapply "Fix build on nightly" This reverts commit 72a5ec666c0f13d8d529413821609f4643b0ee95. --- .gitignore | 4 ++++ .../org/littletonrobotics/urcl/URCLJNI.java | 24 ++++++++----------- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/.gitignore b/.gitignore index a332fb2..afba9e5 100644 --- a/.gitignore +++ b/.gitignore @@ -158,3 +158,7 @@ bin/ # End of https://www.gitignore.io/api/c++,java,linux,macos,gradle,windows,visualstudiocode + +# clangd +/.cache +compile_commands.json diff --git a/src/main/java/org/littletonrobotics/urcl/URCLJNI.java b/src/main/java/org/littletonrobotics/urcl/URCLJNI.java index 8ad75d4..fb3ed3d 100644 --- a/src/main/java/org/littletonrobotics/urcl/URCLJNI.java +++ b/src/main/java/org/littletonrobotics/urcl/URCLJNI.java @@ -8,6 +8,7 @@ package org.littletonrobotics.urcl; import java.io.IOException; +import java.lang.System; import java.nio.ByteBuffer; import java.util.concurrent.atomic.AtomicBoolean; @@ -18,7 +19,6 @@ */ public class URCLJNI { static boolean libraryLoaded = false; - static RuntimeLoader loader = null; /** * Helper class for determining whether or not to load the driver on static @@ -29,7 +29,7 @@ public static class Helper { /** * Get whether to load the driver on static init. - * + * * @return true if the driver will load on static init */ public static boolean getExtractOnStaticLoad() { @@ -38,7 +38,7 @@ public static boolean getExtractOnStaticLoad() { /** * Set whether to load the driver on static init. - * + * * @param load the new value */ public static void setExtractOnStaticLoad(boolean load) { @@ -49,9 +49,7 @@ public static void setExtractOnStaticLoad(boolean load) { static { if (Helper.getExtractOnStaticLoad()) { try { - loader = new RuntimeLoader<>("URCLDriver", RuntimeLoader.getDefaultExtractionRoot(), - URCLJNI.class); - loader.loadLibrary(); + RuntimeLoader.loadLibrary("URCLDriver"); } catch (IOException ex) { ex.printStackTrace(); System.exit(1); @@ -62,32 +60,30 @@ public static void setExtractOnStaticLoad(boolean load) { /** * Force load the library. - * + * * @throws java.io.IOException thrown if the native library cannot be found */ public static synchronized void forceLoad() throws IOException { if (libraryLoaded) { return; } - loader = new RuntimeLoader<>("URCLDriver", RuntimeLoader.getDefaultExtractionRoot(), - URCLJNI.class); - loader.loadLibrary(); + RuntimeLoader.loadLibrary("URCLDriver"); libraryLoaded = true; } /** Start logging. */ public static native void start(); - /** + /** * Get the shared buffer with persistent data. - * + * * @return The shared buffer */ public static native ByteBuffer getPersistentBuffer(); - /** + /** * Get the shared buffer with periodic data. - * + * * @return The shared buffer */ public static native ByteBuffer getPeriodicBuffer(); From 884ed96400ef03d4a846368c5a25a3c3b03b34d9 Mon Sep 17 00:00:00 2001 From: Jade Turner Date: Mon, 2 Sep 2024 18:46:54 +0800 Subject: [PATCH 10/14] use update and fix cpp --- build.gradle | 18 +-- config.gradle | 2 +- .../java/org/littletonrobotics/urcl/URCL.java | 5 +- src/main/native/cpp/URCL.cpp | 113 +++++++++++++----- src/main/native/include/URCL.h | 11 +- 5 files changed, 98 insertions(+), 51 deletions(-) diff --git a/build.gradle b/build.gradle index ca99b7b..48ff2ad 100644 --- a/build.gradle +++ b/build.gradle @@ -21,19 +21,19 @@ apply from: 'config.gradle' // Apply Java configuration dependencies { - implementation 'edu.wpi.first.cscore:cscore-java:2024.+' - implementation 'edu.wpi.first.cameraserver:cameraserver-java:2024.+' - implementation 'edu.wpi.first.ntcore:ntcore-java:2024.+' - implementation 'edu.wpi.first.wpilibj:wpilibj-java:2024.+' - implementation 'edu.wpi.first.wpiutil:wpiutil-java:2024.+' - implementation 'edu.wpi.first.wpimath:wpimath-java:2024.+' - implementation 'edu.wpi.first.wpiunits:wpiunits-java:2024.+' - implementation 'edu.wpi.first.hal:hal-java:2024.+' + implementation 'edu.wpi.first.cscore:cscore-java:2025.+' + implementation 'edu.wpi.first.cameraserver:cameraserver-java:2025.+' + implementation 'edu.wpi.first.ntcore:ntcore-java:2025.+' + implementation 'edu.wpi.first.wpilibj:wpilibj-java:2025.+' + implementation 'edu.wpi.first.wpiutil:wpiutil-java:2025.+' + implementation 'edu.wpi.first.wpimath:wpimath-java:2025.+' + implementation 'edu.wpi.first.wpiunits:wpiunits-java:2025.+' + implementation 'edu.wpi.first.hal:hal-java:2025.+' implementation "org.ejml:ejml-simple:0.43.1" implementation "com.fasterxml.jackson.core:jackson-annotations:2.12.4" implementation "com.fasterxml.jackson.core:jackson-core:2.12.4" implementation "com.fasterxml.jackson.core:jackson-databind:2.12.4" - implementation 'edu.wpi.first.thirdparty.frc2024.opencv:opencv-java:4.8.0-2' + // implementation 'edu.wpi.first.thirdparty.frc2024.opencv:opencv-java:4.8.0-2' } // Set up exports properly diff --git a/config.gradle b/config.gradle index 0c88342..a47e6d3 100644 --- a/config.gradle +++ b/config.gradle @@ -6,7 +6,7 @@ nativeUtils.withCrossRoboRIO() nativeUtils { wpi { configureDependencies { - wpiVersion = "2024.+" + wpiVersion = "2025.+" opencvYear = "frc2024" googleTestYear = "frc2024" niLibVersion = "2024.2.1" diff --git a/src/main/java/org/littletonrobotics/urcl/URCL.java b/src/main/java/org/littletonrobotics/urcl/URCL.java index daf5c21..b90e562 100644 --- a/src/main/java/org/littletonrobotics/urcl/URCL.java +++ b/src/main/java/org/littletonrobotics/urcl/URCL.java @@ -17,7 +17,6 @@ import edu.wpi.first.networktables.RawPublisher; import edu.wpi.first.util.datalog.DataLog; import edu.wpi.first.util.datalog.RawLogEntry; -import edu.wpi.first.wpilibj.DataLogManager; import edu.wpi.first.wpilibj.DriverStation; import edu.wpi.first.wpilibj.Notifier; @@ -143,9 +142,9 @@ public static void start(Map aliases, DataLog log) { aliasLogEntry = new RawLogEntry(log, "/URCL/Raw/Aliases", "", "URCLr2_aliases"); notifier = new Notifier(() -> { var data = getData(); - persistentLogEntry.append(data[0]); + persistentLogEntry.update(data[0]); periodicLogEntry.append(data[1]); - aliasLogEntry.append(data[2]); + aliasLogEntry.update(data[2]); }); notifier.setName("URCL"); notifier.startPeriodic(period); diff --git a/src/main/native/cpp/URCL.cpp b/src/main/native/cpp/URCL.cpp index cb88f5e..eaf4822 100644 --- a/src/main/native/cpp/URCL.cpp +++ b/src/main/native/cpp/URCL.cpp @@ -46,18 +46,65 @@ void URCL::Start() { URCL::Start(aliases); } -void URCL::Start(bool withNT) { - std::map aliases; - URCL::Start(aliases, withNT); -} - void URCL::Start(std::map aliases) { - URCL::Start(aliases, true); + if (running) { + FRC_ReportError(frc::err::Error, "{}", + "URCL cannot be started multiple times"); + return; + } + + // Publish aliases + std::ostringstream aliasesBuilder; + aliasesBuilder << "{"; + bool firstEntry = true; + for (auto const &[key, value] : aliases) { + if (!firstEntry) { + aliasesBuilder << ","; + } + firstEntry = false; + aliasesBuilder << "\""; + aliasesBuilder << key; + aliasesBuilder << "\":\""; + aliasesBuilder << value; + aliasesBuilder << "\""; + } + aliasesBuilder << "}"; + std::string aliasesString = aliasesBuilder.str(); + std::vector aliasesVector(aliasesString.size()); + std::memcpy(aliasesVector.data(), aliasesString.c_str(), + aliasesString.size()); + aliasesPublisher.Set(aliasesVector); + + // Start driver + URCLDriver_start(); + persistentBuffer = URCLDriver_getPersistentBuffer(); + periodicBuffer = URCLDriver_getPeriodicBuffer(); + + aliasesLogEntry.Append(aliasesVector); + + // Start publishers + persistentPublisher = nt::NetworkTableInstance::GetDefault() + .GetRawTopic("/URCL/Raw/Persistent") + .Publish("URCLr2_persistent"); + periodicPublisher = nt::NetworkTableInstance::GetDefault() + .GetRawTopic("/URCL/Raw/Periodic") + .Publish("URCLr2_periodic"); + aliasesPublisher = nt::NetworkTableInstance::GetDefault() + .GetRawTopic("/URCL/Raw/Aliases") + .Publish("URCLr2_aliases"); + + // Start notifier + notifier.SetName("URCL"); + notifier.StartPeriodic(period); } -void URCL::Start(std::map aliases, bool withNT) { - URCL::withNT = withNT; +void URCL::Start(wpi::log::DataLog &log) { + std::map aliases; + URCL::Start(aliases, log); +} +void URCL::Start(std::map aliases, + wpi::log::DataLog &log) { if (running) { FRC_ReportError(frc::err::Error, "{}", "URCL cannot be started multiple times"); @@ -91,14 +138,12 @@ void URCL::Start(std::map aliases, bool withNT) { persistentBuffer = URCLDriver_getPersistentBuffer(); periodicBuffer = URCLDriver_getPeriodicBuffer(); - persistentLogEntry = - wpi::log::RawLogEntry{frc::DataLogManager::GetLog(), - "/URCL/Raw/Persistent", "", "URCLr2_persistent"}; + persistentLogEntry = wpi::log::RawLogEntry{log, "/URCL/Raw/Persistent", "", + "URCLr2_persistent"}; periodicLogEntry = - wpi::log::RawLogEntry{frc::DataLogManager::GetLog(), "/URCL/Raw/Periodic", - "", "URCLr2_periodic"}; - aliasesLogEntry = wpi::log::RawLogEntry{ - frc::DataLogManager::GetLog(), "/URCL/Raw/Aliases", "", "URCLr2_aliases"}; + wpi::log::RawLogEntry{log, "/URCL/Raw/Periodic", "", "URCLr2_periodic"}; + aliasesLogEntry = + wpi::log::RawLogEntry{log, "/URCL/Raw/Aliases", "", "URCLr2_aliases"}; aliasesLogEntry.Append(aliasesVector); // Start notifier @@ -107,21 +152,25 @@ void URCL::Start(std::map aliases, bool withNT) { } void URCL::Periodic() { - URCLDriver_read(); - uint32_t persistentSize; - uint32_t periodicSize; - std::memcpy(&persistentSize, persistentBuffer, 4); - std::memcpy(&periodicSize, periodicBuffer, 4); - std::vector persistentVector(persistentSize); - std::vector periodicVector(periodicSize); - std::memcpy(persistentVector.data(), persistentBuffer + 4, - persistentVector.size()); - std::memcpy(periodicVector.data(), periodicBuffer + 4, periodicVector.size()); - if (withNT) { - persistentPublisher.Set(persistentVector); - periodicPublisher.Set(periodicVector); - } else { - persistentLogEntry.Append(persistentVector); - periodicLogEntry.Append(periodicVector); - } + URCLDriver_read(); + uint32_t persistentSize; + uint32_t periodicSize; + std::memcpy(&persistentSize, persistentBuffer, 4); + std::memcpy(&periodicSize, periodicBuffer, 4); + std::vector persistentVector(persistentSize); + std::vector periodicVector(periodicSize); + std::memcpy(persistentVector.data(), persistentBuffer + 4, + persistentVector.size()); + std::memcpy(periodicVector.data(), periodicBuffer + 4, + periodicVector.size()); + + if (persistentPublisher && periodicPublisher) { + persistentPublisher.Set(persistentVector); + periodicPublisher.Set(periodicVector); + } + + if (persistentLogEntry && periodicLogEntry) { + persistentLogEntry.Update(persistentVector); + periodicLogEntry.Update(periodicVector); + } } diff --git a/src/main/native/include/URCL.h b/src/main/native/include/URCL.h index a649480..0d949cd 100644 --- a/src/main/native/include/URCL.h +++ b/src/main/native/include/URCL.h @@ -35,12 +35,12 @@ class URCL final { static void Start(); /** - * Start capturing data from REV motor controllers to NetworkTables. This method + * Start capturing data from REV motor controllers to a DataLog. This method * should only be called once. * - * @param withNT Whether or not to run with NetworkTables. + * @param log The DataLog object to log to. */ - static void Start(bool withNT); + static void Start(wpi::log::DataLog& log); /** * Start capturing data from REV motor controllers to NetworkTables. This method @@ -51,19 +51,18 @@ class URCL final { static void Start(std::map aliases); /** - * Start capturing data from REV motor controllers to NetworkTables. This method + * Start capturing data from REV motor controllers to a DataLog. This method * should only be called once. * * @param aliases The set of aliases mapping CAN IDs to names. * @param withNT Whether or not to run with NetworkTables. */ - static void Start(std::map aliases, bool withNT); + static void Start(std::map aliases, wpi::log::DataLog& log); private: static void Periodic(); static bool running; - static bool withNT; static char* persistentBuffer; static char* periodicBuffer; static nt::RawPublisher persistentPublisher; From 78d0202649c9adddc4afcc3fb00bc98ec57f956a Mon Sep 17 00:00:00 2001 From: Jade Turner Date: Tue, 3 Sep 2024 21:32:09 +0800 Subject: [PATCH 11/14] review --- src/main/native/cpp/URCL.cpp | 15 +++------------ 1 file changed, 3 insertions(+), 12 deletions(-) diff --git a/src/main/native/cpp/URCL.cpp b/src/main/native/cpp/URCL.cpp index eaf4822..124a976 100644 --- a/src/main/native/cpp/URCL.cpp +++ b/src/main/native/cpp/URCL.cpp @@ -28,17 +28,6 @@ static constexpr auto period = 20_ms; bool URCL::running = false; char *URCL::persistentBuffer = nullptr; char *URCL::periodicBuffer = nullptr; -nt::RawPublisher URCL::persistentPublisher = - nt::NetworkTableInstance::GetDefault() - .GetRawTopic("/URCL/Raw/Persistent") - .Publish("URCLr2_persistent"); -nt::RawPublisher URCL::periodicPublisher = - nt::NetworkTableInstance::GetDefault() - .GetRawTopic("/URCL/Raw/Periodic") - .Publish("URCLr2_periodic"); -nt::RawPublisher URCL::aliasesPublisher = nt::NetworkTableInstance::GetDefault() - .GetRawTopic("/URCL/Raw/Aliases") - .Publish("URCLr2_aliases"); frc::Notifier URCL::notifier{URCL::Periodic}; void URCL::Start() { @@ -73,7 +62,6 @@ void URCL::Start(std::map aliases) { std::vector aliasesVector(aliasesString.size()); std::memcpy(aliasesVector.data(), aliasesString.c_str(), aliasesString.size()); - aliasesPublisher.Set(aliasesVector); // Start driver URCLDriver_start(); @@ -93,6 +81,8 @@ void URCL::Start(std::map aliases) { .GetRawTopic("/URCL/Raw/Aliases") .Publish("URCLr2_aliases"); + aliasesPublisher.Set(aliasesVector); + // Start notifier notifier.SetName("URCL"); notifier.StartPeriodic(period); @@ -144,6 +134,7 @@ void URCL::Start(std::map aliases, wpi::log::RawLogEntry{log, "/URCL/Raw/Periodic", "", "URCLr2_periodic"}; aliasesLogEntry = wpi::log::RawLogEntry{log, "/URCL/Raw/Aliases", "", "URCLr2_aliases"}; + aliasesLogEntry.Append(aliasesVector); // Start notifier From 6f692144fb730e37f4e4d3b56529b4d8c30bf0ab Mon Sep 17 00:00:00 2001 From: Jade Turner Date: Tue, 3 Sep 2024 21:33:41 +0800 Subject: [PATCH 12/14] fix --- src/main/native/cpp/URCL.cpp | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/main/native/cpp/URCL.cpp b/src/main/native/cpp/URCL.cpp index 124a976..8e9e768 100644 --- a/src/main/native/cpp/URCL.cpp +++ b/src/main/native/cpp/URCL.cpp @@ -68,8 +68,6 @@ void URCL::Start(std::map aliases) { persistentBuffer = URCLDriver_getPersistentBuffer(); periodicBuffer = URCLDriver_getPeriodicBuffer(); - aliasesLogEntry.Append(aliasesVector); - // Start publishers persistentPublisher = nt::NetworkTableInstance::GetDefault() .GetRawTopic("/URCL/Raw/Persistent") @@ -121,7 +119,6 @@ void URCL::Start(std::map aliases, std::vector aliasesVector(aliasesString.size()); std::memcpy(aliasesVector.data(), aliasesString.c_str(), aliasesString.size()); - aliasesPublisher.Set(aliasesVector); // Start driver URCLDriver_start(); From 77690b5f3654a63198999917942c8d6509940cbd Mon Sep 17 00:00:00 2001 From: Jonah <47046556+jwbonner@users.noreply.github.com> Date: Tue, 3 Sep 2024 09:51:30 -0400 Subject: [PATCH 13/14] Update macOS runner --- .github/workflows/ci.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 7d5ac6e..76d4170 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -34,7 +34,7 @@ jobs: build-host: env: - MACOSX_DEPLOYMENT_TARGET: 12 + MACOSX_DEPLOYMENT_TARGET: 13 strategy: fail-fast: false matrix: @@ -42,9 +42,9 @@ jobs: - os: windows-2022 artifact-name: Win64 architecture: x64 - - os: macos-12 + - os: macos-14 artifact-name: macOS - architecture: x64 + architecture: aarch64 name: "Build - ${{ matrix.artifact-name }}" runs-on: ${{ matrix.os }} steps: From 3f29cdc869c6b1f6d41f53c33d8491f98e316e55 Mon Sep 17 00:00:00 2001 From: Jonah <47046556+jwbonner@users.noreply.github.com> Date: Tue, 3 Sep 2024 10:07:39 -0400 Subject: [PATCH 14/14] Declare missing symbols --- src/main/native/cpp/URCL.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/main/native/cpp/URCL.cpp b/src/main/native/cpp/URCL.cpp index 8e9e768..b176139 100644 --- a/src/main/native/cpp/URCL.cpp +++ b/src/main/native/cpp/URCL.cpp @@ -28,6 +28,12 @@ static constexpr auto period = 20_ms; bool URCL::running = false; char *URCL::persistentBuffer = nullptr; char *URCL::periodicBuffer = nullptr; +nt::RawPublisher URCL::persistentPublisher; +nt::RawPublisher URCL::periodicPublisher; +nt::RawPublisher URCL::aliasesPublisher; +wpi::log::RawLogEntry URCL::persistentLogEntry; +wpi::log::RawLogEntry URCL::periodicLogEntry; +wpi::log::RawLogEntry URCL::aliasesLogEntry; frc::Notifier URCL::notifier{URCL::Periodic}; void URCL::Start() {