diff --git a/.gitattributes b/.gitattributes index ab6ca853b10..e869fc8fa73 100644 --- a/.gitattributes +++ b/.gitattributes @@ -3,11 +3,10 @@ *.h text eol=lf *.inc text eol=lf *.java text eol=lf +*.jinja text eol=lf *.json text eol=lf *.md text eol=lf *.xml text eol=lf # Generated files -hal/src/generated/** linguist-generated -ntcore/src/generated/** linguist-generated -wpimath/src/generated/** linguist-generated +*/src/generated/** linguist-generated diff --git a/.github/workflows/command-robotpy-pr.yml b/.github/workflows/command-robotpy-pr.yml index 684daf9dded..7fa28eec1c5 100644 --- a/.github/workflows/command-robotpy-pr.yml +++ b/.github/workflows/command-robotpy-pr.yml @@ -1,7 +1,7 @@ name: Comment on PR for robotpy on: - pull_request: + pull_request_target: types: - opened paths: diff --git a/.github/workflows/pregenerate.yml b/.github/workflows/pregenerate.yml index 025f1b6a73a..8dc74bc4487 100644 --- a/.github/workflows/pregenerate.yml +++ b/.github/workflows/pregenerate.yml @@ -32,6 +32,8 @@ jobs: run: ./ntcore/generate_topics.py - name: Run wpimath run: ./wpimath/generate_numbers.py && ./wpimath/generate_quickbuf.py protoc protoc-gen-quickbuf-1.3.3-linux-x86_64.exe + - name: Run HIDs + run: ./wpilibj/generate_hids.py && ./wpilibc/generate_hids.py && ./wpilibNewCommands/generate_hids.py - name: Add untracked files to index so they count as changes run: git add -A - name: Check output diff --git a/.github/workflows/tools.yml b/.github/workflows/tools.yml new file mode 100644 index 00000000000..306eaceb533 --- /dev/null +++ b/.github/workflows/tools.yml @@ -0,0 +1,144 @@ +name: Tools + +on: [pull_request, push] + +concurrency: + group: ${{ github.workflow }}-${{ github.head_ref || github.ref }} + cancel-in-progress: true + +env: + YEAR: 2024 + +jobs: + build-artifacts: + name: "Build - WPILib" + runs-on: ubuntu-22.04 + env: + DISPLAY: ':10' + steps: + - name: Free Disk Space + uses: jlumbroso/free-disk-space@main + with: + tool-cache: false + android: true + dotnet: true + haskell: true + large-packages: false + docker-images: false + swap-storage: false + - uses: actions/checkout@v4 + with: + fetch-depth: 0 + - name: Build WPILib with Gradle + uses: addnab/docker-run-action@v3 + with: + image: wpilib/roborio-cross-ubuntu:2024-22.04 + options: -v ${{ github.workspace }}:/work -w /work -e GITHUB_REF -e CI -e DISPLAY + run: df . && rm -f semicolon_delimited_script && ./gradlew :wpilibc:publish :wpilibj:publish :wpilibNewCommands:publish :hal:publish :cameraserver:publish :ntcore:publish :cscore:publish :wpimath:publish :wpinet:publish :wpiutil:publish :apriltag:publish :wpiunits:publish :simulation:halsim_gui:publish :simulation:halsim_ds_socket:publish -x test -x Javadoc -x doxygen --build-cache && cp -r /root/releases/maven/development /work + - uses: actions/upload-artifact@v4 + with: + name: MavenArtifacts + path: | + development + retention-days: 1 + + Robotbuilder: + name: "Build - RobotBuilder" + needs: [build-artifacts] + runs-on: ubuntu-22.04 + env: + DISPLAY: ':10' + steps: + - uses: actions/checkout@v4 + with: + repository: wpilibsuite/robotbuilder + fetch-depth: 0 + - uses: actions/download-artifact@v4 + with: + name: MavenArtifacts + - name: Patch RobotBuilder to use local development + run: cd src/main/resources/export && echo "wpi.maven.useLocal = false" >> java/build.gradle && echo "wpi.maven.useFrcMavenLocalDevelopment = true" >> java/build.gradle && echo "wpi.versions.wpilibVersion = '$YEAR.424242.+'" >> java/build.gradle && echo "wpi.versions.wpimathVersion = '$YEAR.424242.+'" >> java/build.gradle && echo "wpi.maven.useLocal = false" >> cpp/build.gradle && echo "wpi.maven.useFrcMavenLocalDevelopment = true" >> cpp/build.gradle && echo "wpi.versions.wpilibVersion = '$YEAR.424242.+'" >> cpp/build.gradle && echo "wpi.versions.wpimathVersion = '$YEAR.424242.+'" >> cpp/build.gradle + - name: Install and run xvfb + run: sudo apt-get update && sudo apt-get install -y xvfb && Xvfb $DISPLAY & + - name: Move artifacts + run: mkdir -p ~/releases/maven/development && cp -r edu ~/releases/maven/development + - uses: actions/setup-java@v4 + with: + java-version: 17 + distribution: 'temurin' + - name: Build RobotBuilder with Gradle + run: ./gradlew build test --tests 'robotbuilder.exporters.*' -x htmlSanityCheck -PbuildServer -PreleaseMode ; cat build/test-results/test/TEST-robotbuilder.exporters.*.xml ; + - name: Summarize RobotBuilder Test Results + uses: EnricoMi/publish-unit-test-result-action@v2 + if: always() + with: + files: | + build/test-results/test/TEST*.xml + - uses: actions/upload-artifact@v4 + if: always() + with: + name: TestResults + path: | + build/reports/ + - uses: actions/upload-artifact@v4 + with: + name: RobotBuilder Build + path: | + build/libs/ + retention-days: 7 + + Shuffleboard: + name: "Build - Shuffleboard" + needs: [build-artifacts] + runs-on: ubuntu-22.04 + steps: + - uses: actions/checkout@v4 + with: + repository: wpilibsuite/shuffleboard + fetch-depth: 0 + - uses: actions/download-artifact@v4 + with: + name: MavenArtifacts + - uses: actions/setup-java@v4 + with: + java-version: 17 + distribution: 'temurin' + - name: Move artifacts + run: mkdir -p ~/releases/maven/development && cp -r edu ~/releases/maven/development + - name: Install dependencies + run: sudo apt-get install -y libgtk2.0-0 + - name: Build with Gradle + run: ./gradlew build -x Javadoc + - uses: actions/upload-artifact@v4 + with: + name: Shuffleboard Build + path: | + build/allOutputs/ + retention-days: 7 + + PathWeaver: + name: "Build - PathWeaver" + needs: [build-artifacts] + runs-on: ubuntu-22.04 + steps: + - uses: actions/checkout@v4 + with: + repository: wpilibsuite/PathWeaver + fetch-depth: 0 + - uses: actions/download-artifact@v4 + with: + name: MavenArtifacts + - uses: actions/setup-java@v4 + with: + java-version: 17 + distribution: 'temurin' + - name: Move artifacts + run: mkdir -p ~/releases/maven/development && cp -r edu ~/releases/maven/development + - name: Build with Gradle + run: ./gradlew build + - uses: actions/upload-artifact@v4 + with: + name: PathWeaver Build + path: | + build/allOutputs/ + retention-days: 7 diff --git a/.styleguide b/.styleguide index f67c100e088..de0e89797c7 100644 --- a/.styleguide +++ b/.styleguide @@ -20,6 +20,7 @@ generatedFileExclude { simulation/gz_msgs/src/include/simulation/gz_msgs/msgs\.h$ fieldImages/src/main/native/resources/ apriltag/src/test/resources/ + wpilibc/src/generated/ } repoRootNameOverride { diff --git a/apriltag/src/main/java/edu/wpi/first/apriltag/AprilTagFieldLayout.java b/apriltag/src/main/java/edu/wpi/first/apriltag/AprilTagFieldLayout.java index b17a9c69f22..3874f2bf201 100644 --- a/apriltag/src/main/java/edu/wpi/first/apriltag/AprilTagFieldLayout.java +++ b/apriltag/src/main/java/edu/wpi/first/apriltag/AprilTagFieldLayout.java @@ -281,11 +281,11 @@ public int hashCode() { private static class FieldDimensions { @SuppressWarnings("MemberName") @JsonProperty(value = "length") - public double fieldLength; + public final double fieldLength; @SuppressWarnings("MemberName") @JsonProperty(value = "width") - public double fieldWidth; + public final double fieldWidth; @JsonCreator() FieldDimensions( diff --git a/buildSrc/build.gradle b/buildSrc/build.gradle index a4f19e52b4e..9d0f6837844 100644 --- a/buildSrc/build.gradle +++ b/buildSrc/build.gradle @@ -9,5 +9,5 @@ repositories { } } dependencies { - implementation "edu.wpi.first:native-utils:2025.0.0" + implementation "edu.wpi.first:native-utils:2025.1.0" } diff --git a/cmake/modules/CompileWarnings.cmake b/cmake/modules/CompileWarnings.cmake index 5de103201e2..a37cd749c23 100644 --- a/cmake/modules/CompileWarnings.cmake +++ b/cmake/modules/CompileWarnings.cmake @@ -53,4 +53,9 @@ macro(wpilib_target_warnings target) ) target_compile_options(${target} PRIVATE -gz=zlib) endif() + + # Disable std::mutex constexpr constructor on MSCV; Workaround for MSVCP redist mismatch on GHA + if(MSVC) + target_compile_options(${target} PRIVATE /D_DISABLE_CONSTEXPR_MUTEX_CONSTRUCTOR) + endif() endmacro() diff --git a/cscore/src/main/java/edu/wpi/first/cscore/OpenCvLoader.java b/cscore/src/main/java/edu/wpi/first/cscore/OpenCvLoader.java index 1fb8fe65b90..c3bf916f3e2 100644 --- a/cscore/src/main/java/edu/wpi/first/cscore/OpenCvLoader.java +++ b/cscore/src/main/java/edu/wpi/first/cscore/OpenCvLoader.java @@ -15,7 +15,7 @@ public final class OpenCvLoader { static boolean libraryLoaded; /** Sets whether JNI should be loaded in the static block. */ - public static class Helper { + public static final class Helper { private static AtomicBoolean extractOnStaticLoad = new AtomicBoolean(true); /** diff --git a/cscore/src/main/java/edu/wpi/first/cscore/VideoListener.java b/cscore/src/main/java/edu/wpi/first/cscore/VideoListener.java index 80236b27719..e7697cdae27 100644 --- a/cscore/src/main/java/edu/wpi/first/cscore/VideoListener.java +++ b/cscore/src/main/java/edu/wpi/first/cscore/VideoListener.java @@ -64,7 +64,10 @@ public boolean isValid() { private static final ReentrantLock s_lock = new ReentrantLock(); private static final Map> s_listeners = new HashMap<>(); + + @SuppressWarnings("PMD.SingularField") private static Thread s_thread; + private static int s_poller; private static boolean s_waitQueue; private static final Condition s_waitQueueCond = s_lock.newCondition(); diff --git a/cscore/src/main/java/edu/wpi/first/cscore/VideoProperty.java b/cscore/src/main/java/edu/wpi/first/cscore/VideoProperty.java index 21a1b8fb312..cd063c38fcd 100644 --- a/cscore/src/main/java/edu/wpi/first/cscore/VideoProperty.java +++ b/cscore/src/main/java/edu/wpi/first/cscore/VideoProperty.java @@ -212,5 +212,5 @@ public String[] getChoices() { } int m_handle; - private Kind m_kind; + private final Kind m_kind; } diff --git a/developerRobot/build.gradle b/developerRobot/build.gradle index 96cf8c2a6de..684d0ae63d4 100644 --- a/developerRobot/build.gradle +++ b/developerRobot/build.gradle @@ -269,8 +269,6 @@ model { def filePath = it.tasks.install.installDirectory.get().toString() + File.separatorChar + 'lib' run.dependsOn it.tasks.install run.systemProperty 'java.library.path', filePath - run.environment 'LD_LIBRARY_PATH', filePath - run.environment 'DYLD_LIBRARY_PATH', filePath def installTask = it.tasks.install @@ -297,8 +295,6 @@ model { runTask.doFirst doFirstTask run.doFirst doFirstTask - run.workingDir filePath - found = true } } diff --git a/hal/src/generate/FRCNetComm.java.in b/hal/src/generate/FRCNetComm.java.in index e58a578e816..d8ce4ccacc8 100644 --- a/hal/src/generate/FRCNetComm.java.in +++ b/hal/src/generate/FRCNetComm.java.in @@ -9,6 +9,7 @@ package edu.wpi.first.hal; /** * JNI wrapper for library FRC_NetworkCommunication
. */ +@SuppressWarnings("PMD.MissingStaticMethodInNonInstantiatableClass") public final class FRCNetComm { /** * Resource type from UsageReporting. diff --git a/hal/src/generated/main/java/edu/wpi/first/hal/FRCNetComm.java b/hal/src/generated/main/java/edu/wpi/first/hal/FRCNetComm.java index 0814a3d0fc3..e3a2833e0ed 100644 --- a/hal/src/generated/main/java/edu/wpi/first/hal/FRCNetComm.java +++ b/hal/src/generated/main/java/edu/wpi/first/hal/FRCNetComm.java @@ -9,6 +9,7 @@ /** * JNI wrapper for library FRC_NetworkCommunication
. */ +@SuppressWarnings("PMD.MissingStaticMethodInNonInstantiatableClass") public final class FRCNetComm { /** * Resource type from UsageReporting. diff --git a/hal/src/main/java/edu/wpi/first/hal/HAL.java b/hal/src/main/java/edu/wpi/first/hal/HAL.java index 68cf0e8deed..88a799e4313 100644 --- a/hal/src/main/java/edu/wpi/first/hal/HAL.java +++ b/hal/src/main/java/edu/wpi/first/hal/HAL.java @@ -82,7 +82,7 @@ public final class HAL extends JNIWrapper { private static final List s_simPeriodicBefore = new ArrayList<>(); - public static class SimPeriodicBeforeCallback implements AutoCloseable { + public static final class SimPeriodicBeforeCallback implements AutoCloseable { private SimPeriodicBeforeCallback(Runnable r) { m_run = r; } @@ -128,7 +128,7 @@ public static void simPeriodicBefore() { private static final List s_simPeriodicAfter = new ArrayList<>(); - public static class SimPeriodicAfterCallback implements AutoCloseable { + public static final class SimPeriodicAfterCallback implements AutoCloseable { private SimPeriodicAfterCallback(Runnable r) { m_run = r; } diff --git a/ntcore/src/generate/main/java/NetworkTableEntry.java.jinja b/ntcore/src/generate/main/java/NetworkTableEntry.java.jinja index 8f4b887b301..ba6de81abe2 100644 --- a/ntcore/src/generate/main/java/NetworkTableEntry.java.jinja +++ b/ntcore/src/generate/main/java/NetworkTableEntry.java.jinja @@ -541,14 +541,7 @@ public final class NetworkTableEntry implements Publisher, Subscriber { @Override public boolean equals(Object other) { - if (other == this) { - return true; - } - if (!(other instanceof NetworkTableEntry)) { - return false; - } - - return m_handle == ((NetworkTableEntry) other).m_handle; + return other == this || other instanceof NetworkTableEntry entry && m_handle == entry.m_handle; } @Override diff --git a/ntcore/src/generate/main/java/NetworkTableInstance.java.jinja b/ntcore/src/generate/main/java/NetworkTableInstance.java.jinja index 718f5c6bb37..6ebc8798702 100644 --- a/ntcore/src/generate/main/java/NetworkTableInstance.java.jinja +++ b/ntcore/src/generate/main/java/NetworkTableInstance.java.jinja @@ -43,7 +43,6 @@ import us.hebi.quickbuf.ProtoMessage; * kept to the NetworkTableInstance returned by this function to keep it from being garbage * collected. */ -@SuppressWarnings("PMD.CouplingBetweenObjects") public final class NetworkTableInstance implements AutoCloseable { /** Client/server mode flag values (as returned by {@link #getNetworkMode()}). */ public enum NetworkMode { @@ -493,7 +492,10 @@ public final class NetworkTableInstance implements AutoCloseable { private static class ListenerStorage implements AutoCloseable { private final ReentrantLock m_lock = new ReentrantLock(); private final Map> m_listeners = new HashMap<>(); + + @SuppressWarnings("PMD.SingularField") private Thread m_thread; + private int m_poller; private boolean m_waitQueue; private final Event m_waitQueueEvent = new Event(); @@ -1239,10 +1241,7 @@ public final class NetworkTableInstance implements AutoCloseable { @Override public boolean equals(Object other) { - if (other == this) { - return true; - } - return other instanceof NetworkTableInstance inst && m_handle == inst.m_handle; + return other == this || other instanceof NetworkTableInstance inst && m_handle == inst.m_handle; } @Override diff --git a/ntcore/src/generate/main/java/NetworkTableValue.java.jinja b/ntcore/src/generate/main/java/NetworkTableValue.java.jinja index bc8e69cd07f..7d82b25b3be 100644 --- a/ntcore/src/generate/main/java/NetworkTableValue.java.jinja +++ b/ntcore/src/generate/main/java/NetworkTableValue.java.jinja @@ -154,12 +154,10 @@ public final class NetworkTableValue { {% endfor %} @Override public boolean equals(Object other) { - if (other == this) { - return true; - } - return other instanceof NetworkTableValue ntOther - && m_type == ntOther.m_type - && m_value.equals(ntOther.m_value); + return other == this + || other instanceof NetworkTableValue ntOther + && m_type == ntOther.m_type + && m_value.equals(ntOther.m_value); } @Override diff --git a/ntcore/src/generated/main/java/edu/wpi/first/networktables/NetworkTableEntry.java b/ntcore/src/generated/main/java/edu/wpi/first/networktables/NetworkTableEntry.java index 09926bff6ca..3b6491e0e26 100644 --- a/ntcore/src/generated/main/java/edu/wpi/first/networktables/NetworkTableEntry.java +++ b/ntcore/src/generated/main/java/edu/wpi/first/networktables/NetworkTableEntry.java @@ -942,14 +942,7 @@ public void unpublish() { @Override public boolean equals(Object other) { - if (other == this) { - return true; - } - if (!(other instanceof NetworkTableEntry)) { - return false; - } - - return m_handle == ((NetworkTableEntry) other).m_handle; + return other == this || other instanceof NetworkTableEntry entry && m_handle == entry.m_handle; } @Override diff --git a/ntcore/src/generated/main/java/edu/wpi/first/networktables/NetworkTableInstance.java b/ntcore/src/generated/main/java/edu/wpi/first/networktables/NetworkTableInstance.java index faf0c42cdd3..e7023d40433 100644 --- a/ntcore/src/generated/main/java/edu/wpi/first/networktables/NetworkTableInstance.java +++ b/ntcore/src/generated/main/java/edu/wpi/first/networktables/NetworkTableInstance.java @@ -43,7 +43,6 @@ * kept to the NetworkTableInstance returned by this function to keep it from being garbage * collected. */ -@SuppressWarnings("PMD.CouplingBetweenObjects") public final class NetworkTableInstance implements AutoCloseable { /** Client/server mode flag values (as returned by {@link #getNetworkMode()}). */ public enum NetworkMode { @@ -773,7 +772,10 @@ public NetworkTable getTable(String key) { private static class ListenerStorage implements AutoCloseable { private final ReentrantLock m_lock = new ReentrantLock(); private final Map> m_listeners = new HashMap<>(); + + @SuppressWarnings("PMD.SingularField") private Thread m_thread; + private int m_poller; private boolean m_waitQueue; private final Event m_waitQueueEvent = new Event(); @@ -1519,10 +1521,7 @@ public void addSchema(Struct struct) { @Override public boolean equals(Object other) { - if (other == this) { - return true; - } - return other instanceof NetworkTableInstance inst && m_handle == inst.m_handle; + return other == this || other instanceof NetworkTableInstance inst && m_handle == inst.m_handle; } @Override diff --git a/ntcore/src/generated/main/java/edu/wpi/first/networktables/NetworkTableValue.java b/ntcore/src/generated/main/java/edu/wpi/first/networktables/NetworkTableValue.java index db76312c5a3..78786bc6c78 100644 --- a/ntcore/src/generated/main/java/edu/wpi/first/networktables/NetworkTableValue.java +++ b/ntcore/src/generated/main/java/edu/wpi/first/networktables/NetworkTableValue.java @@ -646,12 +646,10 @@ public static NetworkTableValue makeStringArray(String[] value, long time) { @Override public boolean equals(Object other) { - if (other == this) { - return true; - } - return other instanceof NetworkTableValue ntOther - && m_type == ntOther.m_type - && m_value.equals(ntOther.m_value); + return other == this + || other instanceof NetworkTableValue ntOther + && m_type == ntOther.m_type + && m_value.equals(ntOther.m_value); } @Override diff --git a/ntcore/src/main/java/edu/wpi/first/networktables/NetworkTable.java b/ntcore/src/main/java/edu/wpi/first/networktables/NetworkTable.java index ddafeefe006..e3e3b258fa6 100644 --- a/ntcore/src/main/java/edu/wpi/first/networktables/NetworkTable.java +++ b/ntcore/src/main/java/edu/wpi/first/networktables/NetworkTable.java @@ -18,7 +18,6 @@ import us.hebi.quickbuf.ProtoMessage; /** A network table that knows its subtable path. */ -@SuppressWarnings("PMD.CouplingBetweenObjects") public final class NetworkTable { /** The path separator for sub-tables and keys. */ public static final char PATH_SEPARATOR = '/'; diff --git a/ntcore/src/main/java/edu/wpi/first/networktables/ProtobufTopic.java b/ntcore/src/main/java/edu/wpi/first/networktables/ProtobufTopic.java index 12da3568820..d707ca26417 100644 --- a/ntcore/src/main/java/edu/wpi/first/networktables/ProtobufTopic.java +++ b/ntcore/src/main/java/edu/wpi/first/networktables/ProtobufTopic.java @@ -164,12 +164,10 @@ public ProtobufEntry getEntry(T defaultValue, PubSubOption... options) { @Override public boolean equals(Object other) { - if (other == this) { - return true; - } - return other instanceof ProtobufTopic topic - && super.equals(topic) - && m_proto == topic.m_proto; + return other == this + || other instanceof ProtobufTopic topic + && super.equals(topic) + && m_proto == topic.m_proto; } @Override diff --git a/ntcore/src/main/java/edu/wpi/first/networktables/StructArrayTopic.java b/ntcore/src/main/java/edu/wpi/first/networktables/StructArrayTopic.java index 7aacd1d68a7..fb0516c1d36 100644 --- a/ntcore/src/main/java/edu/wpi/first/networktables/StructArrayTopic.java +++ b/ntcore/src/main/java/edu/wpi/first/networktables/StructArrayTopic.java @@ -164,12 +164,10 @@ public Struct getStruct() { @Override public boolean equals(Object other) { - if (other == this) { - return true; - } - return other instanceof StructArrayTopic topic - && super.equals(topic) - && m_struct == topic.m_struct; + return other == this + || other instanceof StructArrayTopic topic + && super.equals(topic) + && m_struct == topic.m_struct; } @Override diff --git a/ntcore/src/main/java/edu/wpi/first/networktables/StructTopic.java b/ntcore/src/main/java/edu/wpi/first/networktables/StructTopic.java index 8dcf2e6df82..2395d64201d 100644 --- a/ntcore/src/main/java/edu/wpi/first/networktables/StructTopic.java +++ b/ntcore/src/main/java/edu/wpi/first/networktables/StructTopic.java @@ -163,12 +163,10 @@ public Struct getStruct() { @Override public boolean equals(Object other) { - if (other == this) { - return true; - } - return other instanceof StructTopic topic - && super.equals(topic) - && m_struct == topic.m_struct; + return other == this + || other instanceof StructTopic topic + && super.equals(topic) + && m_struct == topic.m_struct; } @Override diff --git a/shared/config.gradle b/shared/config.gradle index 5acadb030bc..6c4f3942b42 100644 --- a/shared/config.gradle +++ b/shared/config.gradle @@ -16,7 +16,7 @@ nativeUtils { opencvYear = "frc2024" googleTestYear = "frc2024" niLibVersion = "2024.2.1" - opencvVersion = "4.8.0-2" + opencvVersion = "4.8.0-4" googleTestVersion = "1.14.0-1" } } @@ -34,15 +34,6 @@ nativeUtils.enableSourceLink() nativeUtils.wpi.addMacMinimumVersionArg() -nativeUtils.platformConfigs.each { - if (it.name.contains('osx')) { - it.linker.args << '-Wl,-rpath,\'@loader_path\'' - it.linker.args << "-headerpad_max_install_names" - } else if (it.name.contains('linux')) { - it.linker.args << '-Wl,-rpath,\'$ORIGIN\'' - } -} - // Compress debug info on Linux nativeUtils.platformConfigs.each { if (it.name.contains('linux')) { @@ -50,11 +41,6 @@ nativeUtils.platformConfigs.each { } } -// NativeUtils adds the following OpenCV warning suppression for Linux, but not -// for macOS -// https://github.com/opencv/opencv/issues/20269 -nativeUtils.platformConfigs.osxuniversal.cppCompiler.args.add("-Wno-deprecated-anon-enum-enum-conversion") - nativeUtils.platformConfigs.linuxathena.linker.args.add("-Wl,--fatal-warnings") model { diff --git a/shared/java/javastyle.gradle b/shared/java/javastyle.gradle index 41ddb47e6d0..ebea73b75dc 100644 --- a/shared/java/javastyle.gradle +++ b/shared/java/javastyle.gradle @@ -13,7 +13,7 @@ checkstyle { apply plugin: 'pmd' pmd { - toolVersion = '6.55.0' + toolVersion = '7.2.0' consoleOutput = true reportsDir = file("$project.buildDir/reports/pmd") ruleSetFiles = files(new File(rootDir, "styleguide/pmd-ruleset.xml")) diff --git a/shared/javacpp/setupBuild.gradle b/shared/javacpp/setupBuild.gradle index 1f3ff10acc1..fa4965a23dc 100644 --- a/shared/javacpp/setupBuild.gradle +++ b/shared/javacpp/setupBuild.gradle @@ -163,14 +163,8 @@ model { def filePath = it.tasks.install.installDirectory.get().toString() + File.separatorChar + 'lib' test.dependsOn it.tasks.install test.systemProperty 'java.library.path', filePath - test.environment 'LD_LIBRARY_PATH', filePath - test.environment 'DYLD_LIBRARY_PATH', filePath - test.workingDir filePath run.dependsOn it.tasks.install run.systemProperty 'java.library.path', filePath - run.environment 'LD_LIBRARY_PATH', filePath - run.environment 'DYLD_LIBRARY_PATH', filePath - run.workingDir filePath found = true } diff --git a/shared/jni/setupBuild.gradle b/shared/jni/setupBuild.gradle index fda467366e1..343b75eb4c6 100644 --- a/shared/jni/setupBuild.gradle +++ b/shared/jni/setupBuild.gradle @@ -314,14 +314,8 @@ model { } test.systemProperty 'java.library.path', filePath - test.environment 'LD_LIBRARY_PATH', filePath - test.environment 'DYLD_LIBRARY_PATH', filePath - test.workingDir filePath run.dependsOn it.tasks.install run.systemProperty 'java.library.path', filePath - run.environment 'LD_LIBRARY_PATH', filePath - run.environment 'DYLD_LIBRARY_PATH', filePath - run.workingDir filePath found = true } diff --git a/shared/opencv.gradle b/shared/opencv.gradle index 7f5e881998e..dec6793c03b 100644 --- a/shared/opencv.gradle +++ b/shared/opencv.gradle @@ -1,4 +1,4 @@ -def opencvVersion = '4.8.0-2' +def opencvVersion = '4.8.0-4' if (project.hasProperty('useCpp') && project.useCpp) { model { diff --git a/styleguide/checkstyle-suppressions.xml b/styleguide/checkstyle-suppressions.xml index f42b176a636..7644ea0563c 100644 --- a/styleguide/checkstyle-suppressions.xml +++ b/styleguide/checkstyle-suppressions.xml @@ -12,4 +12,6 @@ suppressions PUBLIC "-//Puppy Crawl//DTD Suppressions 1.1//EN" checks="(EmptyLineSeparator|LineLength|MissingJavadocMethod|ParameterName)" /> + diff --git a/styleguide/pmd-ruleset.xml b/styleguide/pmd-ruleset.xml index 1f6577e6f18..8553506b6fe 100644 --- a/styleguide/pmd-ruleset.xml +++ b/styleguide/pmd-ruleset.xml @@ -38,24 +38,28 @@ value=".*'.*Arguments\(\)'.*" /> + + + + + + + - + - - - @@ -67,10 +71,8 @@ - - @@ -86,7 +88,6 @@ - @@ -98,7 +99,7 @@ + language="java" class="net.sourceforge.pmd.lang.rule.xpath.XPathRule"> Use Objects.requireNonNull() instead of throwing a NullPointerException yourself. diff --git a/upstream_utils/eigen_patches/0001-Disable-warnings.patch b/upstream_utils/eigen_patches/0001-Disable-warnings.patch index 387e226697a..ace8aa06ace 100644 --- a/upstream_utils/eigen_patches/0001-Disable-warnings.patch +++ b/upstream_utils/eigen_patches/0001-Disable-warnings.patch @@ -15,7 +15,7 @@ index 32a427d852355a51dc4263d81498554ff4c3cbba..9f3e3f5b0f15518377c9a8283fd58081 // See: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=89325 #pragma GCC diagnostic ignored "-Wattributes" #endif -+#if __GNUC__ >= 11 && __GNUC__ <= 13 ++#if __GNUC__ >= 11 +#pragma GCC diagnostic ignored "-Wmaybe-uninitialized" +#endif +#if __GNUC__ >= 12 diff --git a/upstream_utils/sleipnir_patches/0001-Remove-using-enum-declarations.patch b/upstream_utils/sleipnir_patches/0001-Remove-using-enum-declarations.patch index 45ea997600a..21de50523fd 100644 --- a/upstream_utils/sleipnir_patches/0001-Remove-using-enum-declarations.patch +++ b/upstream_utils/sleipnir_patches/0001-Remove-using-enum-declarations.patch @@ -1,7 +1,7 @@ From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: Tyler Veness Date: Wed, 24 Apr 2024 15:56:06 -0700 -Subject: [PATCH 1/2] Remove "using enum" declarations +Subject: [PATCH 1/4] Remove "using enum" declarations --- include/sleipnir/autodiff/Expression.hpp | 161 +++++++----------- @@ -9,10 +9,10 @@ Subject: [PATCH 1/2] Remove "using enum" declarations 2 files changed, 73 insertions(+), 110 deletions(-) diff --git a/include/sleipnir/autodiff/Expression.hpp b/include/sleipnir/autodiff/Expression.hpp -index b60226ccffef9ac161727483ebca3d53df09dec2..fc503c10a209b4779e204e598d3bae45d27916cb 100644 +index 5b8dc5dca9bd685e6647e79f5fd4699bb9909853..802a8602a125251058cfe22447911999f035efad 100644 --- a/include/sleipnir/autodiff/Expression.hpp +++ b/include/sleipnir/autodiff/Expression.hpp -@@ -192,8 +192,6 @@ struct SLEIPNIR_DLLEXPORT Expression { +@@ -191,8 +191,6 @@ struct SLEIPNIR_DLLEXPORT Expression { */ friend SLEIPNIR_DLLEXPORT ExpressionPtr operator*(const ExpressionPtr& lhs, const ExpressionPtr& rhs) { @@ -21,7 +21,7 @@ index b60226ccffef9ac161727483ebca3d53df09dec2..fc503c10a209b4779e204e598d3bae45 // Prune expression if (lhs->IsConstant(0.0)) { // Return zero -@@ -208,20 +206,22 @@ struct SLEIPNIR_DLLEXPORT Expression { +@@ -207,20 +205,22 @@ struct SLEIPNIR_DLLEXPORT Expression { } // Evaluate constant @@ -50,7 +50,7 @@ index b60226ccffef9ac161727483ebca3d53df09dec2..fc503c10a209b4779e204e598d3bae45 } return MakeExpressionPtr( -@@ -247,8 +247,6 @@ struct SLEIPNIR_DLLEXPORT Expression { +@@ -246,8 +246,6 @@ struct SLEIPNIR_DLLEXPORT Expression { */ friend SLEIPNIR_DLLEXPORT ExpressionPtr operator/(const ExpressionPtr& lhs, const ExpressionPtr& rhs) { @@ -59,7 +59,7 @@ index b60226ccffef9ac161727483ebca3d53df09dec2..fc503c10a209b4779e204e598d3bae45 // Prune expression if (lhs->IsConstant(0.0)) { // Return zero -@@ -258,16 +256,17 @@ struct SLEIPNIR_DLLEXPORT Expression { +@@ -257,16 +255,17 @@ struct SLEIPNIR_DLLEXPORT Expression { } // Evaluate constant @@ -80,7 +80,7 @@ index b60226ccffef9ac161727483ebca3d53df09dec2..fc503c10a209b4779e204e598d3bae45 } return MakeExpressionPtr( -@@ -295,8 +294,6 @@ struct SLEIPNIR_DLLEXPORT Expression { +@@ -294,8 +293,6 @@ struct SLEIPNIR_DLLEXPORT Expression { */ friend SLEIPNIR_DLLEXPORT ExpressionPtr operator+(const ExpressionPtr& lhs, const ExpressionPtr& rhs) { @@ -89,7 +89,7 @@ index b60226ccffef9ac161727483ebca3d53df09dec2..fc503c10a209b4779e204e598d3bae45 // Prune expression if (lhs == nullptr || lhs->IsConstant(0.0)) { return rhs; -@@ -305,7 +302,8 @@ struct SLEIPNIR_DLLEXPORT Expression { +@@ -304,7 +301,8 @@ struct SLEIPNIR_DLLEXPORT Expression { } // Evaluate constant @@ -99,7 +99,7 @@ index b60226ccffef9ac161727483ebca3d53df09dec2..fc503c10a209b4779e204e598d3bae45 return MakeExpressionPtr(lhs->value + rhs->value); } -@@ -333,8 +331,6 @@ struct SLEIPNIR_DLLEXPORT Expression { +@@ -332,8 +330,6 @@ struct SLEIPNIR_DLLEXPORT Expression { */ friend SLEIPNIR_DLLEXPORT ExpressionPtr operator-(const ExpressionPtr& lhs, const ExpressionPtr& rhs) { @@ -108,7 +108,7 @@ index b60226ccffef9ac161727483ebca3d53df09dec2..fc503c10a209b4779e204e598d3bae45 // Prune expression if (lhs->IsConstant(0.0)) { if (rhs->IsConstant(0.0)) { -@@ -348,7 +344,8 @@ struct SLEIPNIR_DLLEXPORT Expression { +@@ -347,7 +343,8 @@ struct SLEIPNIR_DLLEXPORT Expression { } // Evaluate constant @@ -118,7 +118,7 @@ index b60226ccffef9ac161727483ebca3d53df09dec2..fc503c10a209b4779e204e598d3bae45 return MakeExpressionPtr(lhs->value - rhs->value); } -@@ -374,8 +371,6 @@ struct SLEIPNIR_DLLEXPORT Expression { +@@ -373,8 +370,6 @@ struct SLEIPNIR_DLLEXPORT Expression { * @param lhs Operand of unary minus. */ friend SLEIPNIR_DLLEXPORT ExpressionPtr operator-(const ExpressionPtr& lhs) { @@ -127,7 +127,7 @@ index b60226ccffef9ac161727483ebca3d53df09dec2..fc503c10a209b4779e204e598d3bae45 // Prune expression if (lhs->IsConstant(0.0)) { // Return zero -@@ -383,7 +378,7 @@ struct SLEIPNIR_DLLEXPORT Expression { +@@ -382,7 +377,7 @@ struct SLEIPNIR_DLLEXPORT Expression { } // Evaluate constant @@ -136,7 +136,7 @@ index b60226ccffef9ac161727483ebca3d53df09dec2..fc503c10a209b4779e204e598d3bae45 return MakeExpressionPtr(-lhs->value); } -@@ -465,8 +460,6 @@ inline void IntrusiveSharedPtrDecRefCount(Expression* expr) { +@@ -463,8 +458,6 @@ inline constexpr void IntrusiveSharedPtrDecRefCount(Expression* expr) { */ SLEIPNIR_DLLEXPORT inline ExpressionPtr abs( // NOLINT const ExpressionPtr& x) { @@ -145,7 +145,7 @@ index b60226ccffef9ac161727483ebca3d53df09dec2..fc503c10a209b4779e204e598d3bae45 // Prune expression if (x->IsConstant(0.0)) { // Return zero -@@ -474,12 +467,12 @@ SLEIPNIR_DLLEXPORT inline ExpressionPtr abs( // NOLINT +@@ -472,12 +465,12 @@ SLEIPNIR_DLLEXPORT inline ExpressionPtr abs( // NOLINT } // Evaluate constant @@ -160,7 +160,7 @@ index b60226ccffef9ac161727483ebca3d53df09dec2..fc503c10a209b4779e204e598d3bae45 [](double x, double, double parentAdjoint) { if (x < 0.0) { return -parentAdjoint; -@@ -510,20 +503,18 @@ SLEIPNIR_DLLEXPORT inline ExpressionPtr abs( // NOLINT +@@ -508,20 +501,18 @@ SLEIPNIR_DLLEXPORT inline ExpressionPtr abs( // NOLINT */ SLEIPNIR_DLLEXPORT inline ExpressionPtr acos( // NOLINT const ExpressionPtr& x) { @@ -183,7 +183,7 @@ index b60226ccffef9ac161727483ebca3d53df09dec2..fc503c10a209b4779e204e598d3bae45 [](double x, double, double parentAdjoint) { return -parentAdjoint / std::sqrt(1.0 - x * x); }, -@@ -542,8 +533,6 @@ SLEIPNIR_DLLEXPORT inline ExpressionPtr acos( // NOLINT +@@ -540,8 +531,6 @@ SLEIPNIR_DLLEXPORT inline ExpressionPtr acos( // NOLINT */ SLEIPNIR_DLLEXPORT inline ExpressionPtr asin( // NOLINT const ExpressionPtr& x) { @@ -192,7 +192,7 @@ index b60226ccffef9ac161727483ebca3d53df09dec2..fc503c10a209b4779e204e598d3bae45 // Prune expression if (x->IsConstant(0.0)) { // Return zero -@@ -551,12 +540,12 @@ SLEIPNIR_DLLEXPORT inline ExpressionPtr asin( // NOLINT +@@ -549,12 +538,12 @@ SLEIPNIR_DLLEXPORT inline ExpressionPtr asin( // NOLINT } // Evaluate constant @@ -207,7 +207,7 @@ index b60226ccffef9ac161727483ebca3d53df09dec2..fc503c10a209b4779e204e598d3bae45 [](double x, double, double parentAdjoint) { return parentAdjoint / std::sqrt(1.0 - x * x); }, -@@ -575,8 +564,6 @@ SLEIPNIR_DLLEXPORT inline ExpressionPtr asin( // NOLINT +@@ -573,8 +562,6 @@ SLEIPNIR_DLLEXPORT inline ExpressionPtr asin( // NOLINT */ SLEIPNIR_DLLEXPORT inline ExpressionPtr atan( // NOLINT const ExpressionPtr& x) { @@ -216,7 +216,7 @@ index b60226ccffef9ac161727483ebca3d53df09dec2..fc503c10a209b4779e204e598d3bae45 // Prune expression if (x->IsConstant(0.0)) { // Return zero -@@ -584,12 +571,12 @@ SLEIPNIR_DLLEXPORT inline ExpressionPtr atan( // NOLINT +@@ -582,12 +569,12 @@ SLEIPNIR_DLLEXPORT inline ExpressionPtr atan( // NOLINT } // Evaluate constant @@ -231,7 +231,7 @@ index b60226ccffef9ac161727483ebca3d53df09dec2..fc503c10a209b4779e204e598d3bae45 [](double x, double, double parentAdjoint) { return parentAdjoint / (1.0 + x * x); }, -@@ -608,8 +595,6 @@ SLEIPNIR_DLLEXPORT inline ExpressionPtr atan( // NOLINT +@@ -606,8 +593,6 @@ SLEIPNIR_DLLEXPORT inline ExpressionPtr atan( // NOLINT */ SLEIPNIR_DLLEXPORT inline ExpressionPtr atan2( // NOLINT const ExpressionPtr& y, const ExpressionPtr& x) { @@ -240,7 +240,7 @@ index b60226ccffef9ac161727483ebca3d53df09dec2..fc503c10a209b4779e204e598d3bae45 // Prune expression if (y->IsConstant(0.0)) { // Return zero -@@ -619,12 +604,14 @@ SLEIPNIR_DLLEXPORT inline ExpressionPtr atan2( // NOLINT +@@ -617,12 +602,14 @@ SLEIPNIR_DLLEXPORT inline ExpressionPtr atan2( // NOLINT } // Evaluate constant @@ -257,7 +257,7 @@ index b60226ccffef9ac161727483ebca3d53df09dec2..fc503c10a209b4779e204e598d3bae45 [](double y, double x, double parentAdjoint) { return parentAdjoint * x / (y * y + x * x); }, -@@ -649,20 +636,18 @@ SLEIPNIR_DLLEXPORT inline ExpressionPtr atan2( // NOLINT +@@ -647,20 +634,18 @@ SLEIPNIR_DLLEXPORT inline ExpressionPtr atan2( // NOLINT */ SLEIPNIR_DLLEXPORT inline ExpressionPtr cos( // NOLINT const ExpressionPtr& x) { @@ -280,7 +280,7 @@ index b60226ccffef9ac161727483ebca3d53df09dec2..fc503c10a209b4779e204e598d3bae45 [](double x, double, double parentAdjoint) { return -parentAdjoint * std::sin(x); }, -@@ -680,20 +665,18 @@ SLEIPNIR_DLLEXPORT inline ExpressionPtr cos( // NOLINT +@@ -678,20 +663,18 @@ SLEIPNIR_DLLEXPORT inline ExpressionPtr cos( // NOLINT */ SLEIPNIR_DLLEXPORT inline ExpressionPtr cosh( // NOLINT const ExpressionPtr& x) { @@ -303,7 +303,7 @@ index b60226ccffef9ac161727483ebca3d53df09dec2..fc503c10a209b4779e204e598d3bae45 [](double x, double, double parentAdjoint) { return parentAdjoint * std::sinh(x); }, -@@ -711,8 +694,6 @@ SLEIPNIR_DLLEXPORT inline ExpressionPtr cosh( // NOLINT +@@ -709,8 +692,6 @@ SLEIPNIR_DLLEXPORT inline ExpressionPtr cosh( // NOLINT */ SLEIPNIR_DLLEXPORT inline ExpressionPtr erf( // NOLINT const ExpressionPtr& x) { @@ -312,7 +312,7 @@ index b60226ccffef9ac161727483ebca3d53df09dec2..fc503c10a209b4779e204e598d3bae45 // Prune expression if (x->IsConstant(0.0)) { // Return zero -@@ -720,12 +701,12 @@ SLEIPNIR_DLLEXPORT inline ExpressionPtr erf( // NOLINT +@@ -718,12 +699,12 @@ SLEIPNIR_DLLEXPORT inline ExpressionPtr erf( // NOLINT } // Evaluate constant @@ -327,7 +327,7 @@ index b60226ccffef9ac161727483ebca3d53df09dec2..fc503c10a209b4779e204e598d3bae45 [](double x, double, double parentAdjoint) { return parentAdjoint * 2.0 * std::numbers::inv_sqrtpi * std::exp(-x * x); -@@ -746,20 +727,18 @@ SLEIPNIR_DLLEXPORT inline ExpressionPtr erf( // NOLINT +@@ -744,20 +725,18 @@ SLEIPNIR_DLLEXPORT inline ExpressionPtr erf( // NOLINT */ SLEIPNIR_DLLEXPORT inline ExpressionPtr exp( // NOLINT const ExpressionPtr& x) { @@ -350,7 +350,7 @@ index b60226ccffef9ac161727483ebca3d53df09dec2..fc503c10a209b4779e204e598d3bae45 [](double x, double, double parentAdjoint) { return parentAdjoint * std::exp(x); }, -@@ -778,8 +757,6 @@ SLEIPNIR_DLLEXPORT inline ExpressionPtr exp( // NOLINT +@@ -776,8 +755,6 @@ SLEIPNIR_DLLEXPORT inline ExpressionPtr exp( // NOLINT */ SLEIPNIR_DLLEXPORT inline ExpressionPtr hypot( // NOLINT const ExpressionPtr& x, const ExpressionPtr& y) { @@ -359,7 +359,7 @@ index b60226ccffef9ac161727483ebca3d53df09dec2..fc503c10a209b4779e204e598d3bae45 // Prune expression if (x->IsConstant(0.0)) { return y; -@@ -788,12 +765,14 @@ SLEIPNIR_DLLEXPORT inline ExpressionPtr hypot( // NOLINT +@@ -786,12 +763,14 @@ SLEIPNIR_DLLEXPORT inline ExpressionPtr hypot( // NOLINT } // Evaluate constant @@ -376,7 +376,7 @@ index b60226ccffef9ac161727483ebca3d53df09dec2..fc503c10a209b4779e204e598d3bae45 [](double x, double y, double parentAdjoint) { return parentAdjoint * x / std::hypot(x, y); }, -@@ -818,8 +797,6 @@ SLEIPNIR_DLLEXPORT inline ExpressionPtr hypot( // NOLINT +@@ -816,8 +795,6 @@ SLEIPNIR_DLLEXPORT inline ExpressionPtr hypot( // NOLINT */ SLEIPNIR_DLLEXPORT inline ExpressionPtr log( // NOLINT const ExpressionPtr& x) { @@ -385,7 +385,7 @@ index b60226ccffef9ac161727483ebca3d53df09dec2..fc503c10a209b4779e204e598d3bae45 // Prune expression if (x->IsConstant(0.0)) { // Return zero -@@ -827,12 +804,12 @@ SLEIPNIR_DLLEXPORT inline ExpressionPtr log( // NOLINT +@@ -825,12 +802,12 @@ SLEIPNIR_DLLEXPORT inline ExpressionPtr log( // NOLINT } // Evaluate constant @@ -400,7 +400,7 @@ index b60226ccffef9ac161727483ebca3d53df09dec2..fc503c10a209b4779e204e598d3bae45 [](double x, double, double parentAdjoint) { return parentAdjoint / x; }, [](const ExpressionPtr& x, const ExpressionPtr&, const ExpressionPtr& parentAdjoint) { return parentAdjoint / x; }, -@@ -846,8 +823,6 @@ SLEIPNIR_DLLEXPORT inline ExpressionPtr log( // NOLINT +@@ -844,8 +821,6 @@ SLEIPNIR_DLLEXPORT inline ExpressionPtr log( // NOLINT */ SLEIPNIR_DLLEXPORT inline ExpressionPtr log10( // NOLINT const ExpressionPtr& x) { @@ -409,7 +409,7 @@ index b60226ccffef9ac161727483ebca3d53df09dec2..fc503c10a209b4779e204e598d3bae45 // Prune expression if (x->IsConstant(0.0)) { // Return zero -@@ -855,12 +830,13 @@ SLEIPNIR_DLLEXPORT inline ExpressionPtr log10( // NOLINT +@@ -853,12 +828,13 @@ SLEIPNIR_DLLEXPORT inline ExpressionPtr log10( // NOLINT } // Evaluate constant @@ -425,7 +425,7 @@ index b60226ccffef9ac161727483ebca3d53df09dec2..fc503c10a209b4779e204e598d3bae45 [](double x, double, double parentAdjoint) { return parentAdjoint / (std::numbers::ln10 * x); }, -@@ -879,8 +855,6 @@ SLEIPNIR_DLLEXPORT inline ExpressionPtr log10( // NOLINT +@@ -877,8 +853,6 @@ SLEIPNIR_DLLEXPORT inline ExpressionPtr log10( // NOLINT */ SLEIPNIR_DLLEXPORT inline ExpressionPtr pow( // NOLINT const ExpressionPtr& base, const ExpressionPtr& power) { @@ -434,7 +434,7 @@ index b60226ccffef9ac161727483ebca3d53df09dec2..fc503c10a209b4779e204e598d3bae45 // Prune expression if (base->IsConstant(0.0)) { // Return zero -@@ -895,12 +869,15 @@ SLEIPNIR_DLLEXPORT inline ExpressionPtr pow( // NOLINT +@@ -893,12 +867,15 @@ SLEIPNIR_DLLEXPORT inline ExpressionPtr pow( // NOLINT } // Evaluate constant @@ -452,7 +452,7 @@ index b60226ccffef9ac161727483ebca3d53df09dec2..fc503c10a209b4779e204e598d3bae45 [](double base, double power) { return std::pow(base, power); }, [](double base, double power, double parentAdjoint) { return parentAdjoint * std::pow(base, power - 1) * power; -@@ -941,10 +918,8 @@ SLEIPNIR_DLLEXPORT inline ExpressionPtr pow( // NOLINT +@@ -939,10 +916,8 @@ SLEIPNIR_DLLEXPORT inline ExpressionPtr pow( // NOLINT * @param x The argument. */ SLEIPNIR_DLLEXPORT inline ExpressionPtr sign(const ExpressionPtr& x) { @@ -464,7 +464,7 @@ index b60226ccffef9ac161727483ebca3d53df09dec2..fc503c10a209b4779e204e598d3bae45 if (x->value < 0.0) { return MakeExpressionPtr(-1.0); } else if (x->value == 0.0) { -@@ -956,7 +931,7 @@ SLEIPNIR_DLLEXPORT inline ExpressionPtr sign(const ExpressionPtr& x) { +@@ -954,7 +929,7 @@ SLEIPNIR_DLLEXPORT inline ExpressionPtr sign(const ExpressionPtr& x) { } return MakeExpressionPtr( @@ -473,7 +473,7 @@ index b60226ccffef9ac161727483ebca3d53df09dec2..fc503c10a209b4779e204e598d3bae45 [](double x, double) { if (x < 0.0) { return -1.0; -@@ -982,8 +957,6 @@ SLEIPNIR_DLLEXPORT inline ExpressionPtr sign(const ExpressionPtr& x) { +@@ -980,8 +955,6 @@ SLEIPNIR_DLLEXPORT inline ExpressionPtr sign(const ExpressionPtr& x) { */ SLEIPNIR_DLLEXPORT inline ExpressionPtr sin( // NOLINT const ExpressionPtr& x) { @@ -482,7 +482,7 @@ index b60226ccffef9ac161727483ebca3d53df09dec2..fc503c10a209b4779e204e598d3bae45 // Prune expression if (x->IsConstant(0.0)) { // Return zero -@@ -991,12 +964,12 @@ SLEIPNIR_DLLEXPORT inline ExpressionPtr sin( // NOLINT +@@ -989,12 +962,12 @@ SLEIPNIR_DLLEXPORT inline ExpressionPtr sin( // NOLINT } // Evaluate constant @@ -497,7 +497,7 @@ index b60226ccffef9ac161727483ebca3d53df09dec2..fc503c10a209b4779e204e598d3bae45 [](double x, double, double parentAdjoint) { return parentAdjoint * std::cos(x); }, -@@ -1013,8 +986,6 @@ SLEIPNIR_DLLEXPORT inline ExpressionPtr sin( // NOLINT +@@ -1011,8 +984,6 @@ SLEIPNIR_DLLEXPORT inline ExpressionPtr sin( // NOLINT * @param x The argument. */ SLEIPNIR_DLLEXPORT inline ExpressionPtr sinh(const ExpressionPtr& x) { @@ -506,7 +506,7 @@ index b60226ccffef9ac161727483ebca3d53df09dec2..fc503c10a209b4779e204e598d3bae45 // Prune expression if (x->IsConstant(0.0)) { // Return zero -@@ -1022,12 +993,12 @@ SLEIPNIR_DLLEXPORT inline ExpressionPtr sinh(const ExpressionPtr& x) { +@@ -1020,12 +991,12 @@ SLEIPNIR_DLLEXPORT inline ExpressionPtr sinh(const ExpressionPtr& x) { } // Evaluate constant @@ -521,7 +521,7 @@ index b60226ccffef9ac161727483ebca3d53df09dec2..fc503c10a209b4779e204e598d3bae45 [](double x, double, double parentAdjoint) { return parentAdjoint * std::cosh(x); }, -@@ -1045,10 +1016,8 @@ SLEIPNIR_DLLEXPORT inline ExpressionPtr sinh(const ExpressionPtr& x) { +@@ -1043,10 +1014,8 @@ SLEIPNIR_DLLEXPORT inline ExpressionPtr sinh(const ExpressionPtr& x) { */ SLEIPNIR_DLLEXPORT inline ExpressionPtr sqrt( // NOLINT const ExpressionPtr& x) { @@ -533,7 +533,7 @@ index b60226ccffef9ac161727483ebca3d53df09dec2..fc503c10a209b4779e204e598d3bae45 if (x->value == 0.0) { // Return zero return x; -@@ -1060,7 +1029,7 @@ SLEIPNIR_DLLEXPORT inline ExpressionPtr sqrt( // NOLINT +@@ -1058,7 +1027,7 @@ SLEIPNIR_DLLEXPORT inline ExpressionPtr sqrt( // NOLINT } return MakeExpressionPtr( @@ -542,7 +542,7 @@ index b60226ccffef9ac161727483ebca3d53df09dec2..fc503c10a209b4779e204e598d3bae45 [](double x, double, double parentAdjoint) { return parentAdjoint / (2.0 * std::sqrt(x)); }, -@@ -1079,8 +1048,6 @@ SLEIPNIR_DLLEXPORT inline ExpressionPtr sqrt( // NOLINT +@@ -1077,8 +1046,6 @@ SLEIPNIR_DLLEXPORT inline ExpressionPtr sqrt( // NOLINT */ SLEIPNIR_DLLEXPORT inline ExpressionPtr tan( // NOLINT const ExpressionPtr& x) { @@ -551,7 +551,7 @@ index b60226ccffef9ac161727483ebca3d53df09dec2..fc503c10a209b4779e204e598d3bae45 // Prune expression if (x->IsConstant(0.0)) { // Return zero -@@ -1088,12 +1055,12 @@ SLEIPNIR_DLLEXPORT inline ExpressionPtr tan( // NOLINT +@@ -1086,12 +1053,12 @@ SLEIPNIR_DLLEXPORT inline ExpressionPtr tan( // NOLINT } // Evaluate constant @@ -566,7 +566,7 @@ index b60226ccffef9ac161727483ebca3d53df09dec2..fc503c10a209b4779e204e598d3bae45 [](double x, double, double parentAdjoint) { return parentAdjoint / (std::cos(x) * std::cos(x)); }, -@@ -1111,8 +1078,6 @@ SLEIPNIR_DLLEXPORT inline ExpressionPtr tan( // NOLINT +@@ -1109,8 +1076,6 @@ SLEIPNIR_DLLEXPORT inline ExpressionPtr tan( // NOLINT * @param x The argument. */ SLEIPNIR_DLLEXPORT inline ExpressionPtr tanh(const ExpressionPtr& x) { @@ -575,7 +575,7 @@ index b60226ccffef9ac161727483ebca3d53df09dec2..fc503c10a209b4779e204e598d3bae45 // Prune expression if (x->IsConstant(0.0)) { // Return zero -@@ -1120,12 +1085,12 @@ SLEIPNIR_DLLEXPORT inline ExpressionPtr tanh(const ExpressionPtr& x) { +@@ -1118,12 +1083,12 @@ SLEIPNIR_DLLEXPORT inline ExpressionPtr tanh(const ExpressionPtr& x) { } // Evaluate constant diff --git a/upstream_utils/sleipnir_patches/0002-Add-implicit-typename.patch b/upstream_utils/sleipnir_patches/0002-Add-implicit-typename.patch index 534c6c19bd9..5ba6fa5cf6d 100644 --- a/upstream_utils/sleipnir_patches/0002-Add-implicit-typename.patch +++ b/upstream_utils/sleipnir_patches/0002-Add-implicit-typename.patch @@ -1,14 +1,14 @@ From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: Tyler Veness Date: Mon, 29 Apr 2024 19:17:18 -0700 -Subject: [PATCH 2/2] Add implicit typename +Subject: [PATCH 2/4] Add implicit typename --- include/sleipnir/util/SmallVector.hpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/include/sleipnir/util/SmallVector.hpp b/include/sleipnir/util/SmallVector.hpp -index a4fd51931bb86b2b689805b2c4c5e0125cc560fc..e301b973f1dcd1f662bd9c9f8fd567053e5ee578 100644 +index 5e93ae49e659a29c49728d337323ebbcdd8790d3..dcf02c02b7f7fcfc32197d68f885174a1ae20307 100644 --- a/include/sleipnir/util/SmallVector.hpp +++ b/include/sleipnir/util/SmallVector.hpp @@ -152,8 +152,8 @@ class small_vector diff --git a/upstream_utils/sleipnir_patches/0003-Use-fmtlib.patch b/upstream_utils/sleipnir_patches/0003-Use-fmtlib.patch new file mode 100644 index 00000000000..23f507936ad --- /dev/null +++ b/upstream_utils/sleipnir_patches/0003-Use-fmtlib.patch @@ -0,0 +1,116 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Tyler Veness +Date: Wed, 29 May 2024 16:29:55 -0700 +Subject: [PATCH 3/4] Use fmtlib + +--- + include/.styleguide | 1 + + include/sleipnir/util/Assert.hpp | 5 +++-- + include/sleipnir/util/Print.hpp | 27 ++++++++++++++------------- + 3 files changed, 18 insertions(+), 15 deletions(-) + +diff --git a/include/.styleguide b/include/.styleguide +index f3b2f0cf9e60b3a86b9654ff2b381f9c48734ff6..8251a490677bcf5fd316d5303195b0fa4e599b75 100644 +--- a/include/.styleguide ++++ b/include/.styleguide +@@ -8,4 +8,5 @@ cppSrcFileInclude { + + includeOtherLibs { + ^Eigen/ ++ ^fmt/ + } +diff --git a/include/sleipnir/util/Assert.hpp b/include/sleipnir/util/Assert.hpp +index ba381ef8f48446e6d07b6d7973a8271cbda8fec9..9999544278c493f263c819811cb4fbcb407b04f1 100644 +--- a/include/sleipnir/util/Assert.hpp ++++ b/include/sleipnir/util/Assert.hpp +@@ -3,8 +3,9 @@ + #pragma once + + #ifdef JORMUNGANDR +-#include + #include ++ ++#include + /** + * Throw an exception in Python. + */ +@@ -12,7 +13,7 @@ + do { \ + if (!(condition)) { \ + throw std::invalid_argument( \ +- std::format("{}:{}: {}: Assertion `{}' failed.", __FILE__, __LINE__, \ ++ fmt::format("{}:{}: {}: Assertion `{}' failed.", __FILE__, __LINE__, \ + __func__, #condition)); \ + } \ + } while (0); +diff --git a/include/sleipnir/util/Print.hpp b/include/sleipnir/util/Print.hpp +index 339320bce6d017ca85025060ba445b2f025bb225..fcf2e69bfb5a081cd915bdded3caa80cd9c38518 100644 +--- a/include/sleipnir/util/Print.hpp ++++ b/include/sleipnir/util/Print.hpp +@@ -2,52 +2,53 @@ + + #pragma once + +-#include + #include + #include + ++#include ++ + namespace sleipnir { + + /** +- * Wrapper around std::print() that squelches write failure exceptions. ++ * Wrapper around fmt::print() that squelches write failure exceptions. + */ + template +-inline void print(std::format_string fmt, T&&... args) { ++inline void print(fmt::format_string fmt, T&&... args) { + try { +- std::print(fmt, std::forward(args)...); ++ fmt::print(fmt, std::forward(args)...); + } catch (const std::system_error&) { + } + } + + /** +- * Wrapper around std::print() that squelches write failure exceptions. ++ * Wrapper around fmt::print() that squelches write failure exceptions. + */ + template +-inline void print(std::FILE* f, std::format_string fmt, T&&... args) { ++inline void print(std::FILE* f, fmt::format_string fmt, T&&... args) { + try { +- std::print(f, fmt, std::forward(args)...); ++ fmt::print(f, fmt, std::forward(args)...); + } catch (const std::system_error&) { + } + } + + /** +- * Wrapper around std::println() that squelches write failure exceptions. ++ * Wrapper around fmt::println() that squelches write failure exceptions. + */ + template +-inline void println(std::format_string fmt, T&&... args) { ++inline void println(fmt::format_string fmt, T&&... args) { + try { +- std::println(fmt, std::forward(args)...); ++ fmt::println(fmt, std::forward(args)...); + } catch (const std::system_error&) { + } + } + + /** +- * Wrapper around std::println() that squelches write failure exceptions. ++ * Wrapper around fmt::println() that squelches write failure exceptions. + */ + template +-inline void println(std::FILE* f, std::format_string fmt, T&&... args) { ++inline void println(std::FILE* f, fmt::format_string fmt, T&&... args) { + try { +- std::println(f, fmt, std::forward(args)...); ++ fmt::println(f, fmt, std::forward(args)...); + } catch (const std::system_error&) { + } + } diff --git a/upstream_utils/sleipnir_patches/0004-Remove-unsupported-constexpr.patch b/upstream_utils/sleipnir_patches/0004-Remove-unsupported-constexpr.patch new file mode 100644 index 00000000000..d3907dd0747 --- /dev/null +++ b/upstream_utils/sleipnir_patches/0004-Remove-unsupported-constexpr.patch @@ -0,0 +1,42 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Tyler Veness +Date: Mon, 20 May 2024 09:01:54 -0700 +Subject: [PATCH 4/4] Remove unsupported constexpr + +--- + include/sleipnir/autodiff/Expression.hpp | 8 ++++---- + 1 file changed, 4 insertions(+), 4 deletions(-) + +diff --git a/include/sleipnir/autodiff/Expression.hpp b/include/sleipnir/autodiff/Expression.hpp +index 802a8602a125251058cfe22447911999f035efad..7aa715a0aa5f4560b4e16cf5f0458f1385b88c7d 100644 +--- a/include/sleipnir/autodiff/Expression.hpp ++++ b/include/sleipnir/autodiff/Expression.hpp +@@ -21,8 +21,8 @@ namespace sleipnir::detail { + + struct SLEIPNIR_DLLEXPORT Expression; + +-inline constexpr void IntrusiveSharedPtrIncRefCount(Expression* expr); +-inline constexpr void IntrusiveSharedPtrDecRefCount(Expression* expr); ++inline void IntrusiveSharedPtrIncRefCount(Expression* expr); ++inline void IntrusiveSharedPtrDecRefCount(Expression* expr); + + /** + * Typedef for intrusive shared pointer to Expression. +@@ -409,7 +409,7 @@ SLEIPNIR_DLLEXPORT inline ExpressionPtr sqrt(const ExpressionPtr& x); + * + * @param expr The shared pointer's managed object. + */ +-inline constexpr void IntrusiveSharedPtrIncRefCount(Expression* expr) { ++inline void IntrusiveSharedPtrIncRefCount(Expression* expr) { + ++expr->refCount; + } + +@@ -418,7 +418,7 @@ inline constexpr void IntrusiveSharedPtrIncRefCount(Expression* expr) { + * + * @param expr The shared pointer's managed object. + */ +-inline constexpr void IntrusiveSharedPtrDecRefCount(Expression* expr) { ++inline void IntrusiveSharedPtrDecRefCount(Expression* expr) { + // If a deeply nested tree is being deallocated all at once, calling the + // Expression destructor when expr's refcount reaches zero can cause a stack + // overflow. Instead, we iterate over its children to decrement their diff --git a/upstream_utils/update_llvm.py b/upstream_utils/update_llvm.py index d43527e3d18..28efee9cbe9 100755 --- a/upstream_utils/update_llvm.py +++ b/upstream_utils/update_llvm.py @@ -171,7 +171,7 @@ def overwrite_tests(wpiutil_root, llvm_root): def main(): - upstream_root = clone_repo("https://github.com/llvm/llvm-project", "llvmorg-18.1.1") + upstream_root = clone_repo("https://github.com/llvm/llvm-project", "llvmorg-18.1.7") wpilib_root = get_repo_root() wpiutil = os.path.join(wpilib_root, "wpiutil") diff --git a/upstream_utils/update_sleipnir.py b/upstream_utils/update_sleipnir.py index 3d58250abeb..942d1032e9b 100755 --- a/upstream_utils/update_sleipnir.py +++ b/upstream_utils/update_sleipnir.py @@ -15,8 +15,8 @@ def main(): upstream_root = clone_repo( "https://github.com/SleipnirGroup/Sleipnir", - # main on 2024-04-29 - "9bac50e0f6c1b9ae20e1f611fb7db2cc305ca4fc", + # main on 2024-06-05 + "57005c8b740ab163d3f7ef7e0c7c7c8774f4f925", shallow=False, ) wpilib_root = get_repo_root() @@ -27,6 +27,8 @@ def main(): for f in [ "0001-Remove-using-enum-declarations.patch", "0002-Add-implicit-typename.patch", + "0003-Use-fmtlib.patch", + "0004-Remove-unsupported-constexpr.patch", ]: git_am(os.path.join(wpilib_root, "upstream_utils/sleipnir_patches", f)) diff --git a/vcpkg-configuration.json b/vcpkg-configuration.json new file mode 100644 index 00000000000..0a4b403bf48 --- /dev/null +++ b/vcpkg-configuration.json @@ -0,0 +1,3 @@ +{ + "overlay-triplets": [ "./vcpkg-triplets" ] +} diff --git a/vcpkg-triplets/x64-windows-release.cmake b/vcpkg-triplets/x64-windows-release.cmake new file mode 100644 index 00000000000..8a7da5b9149 --- /dev/null +++ b/vcpkg-triplets/x64-windows-release.cmake @@ -0,0 +1,6 @@ +set(VCPKG_TARGET_ARCHITECTURE x64) +set(VCPKG_CRT_LINKAGE dynamic) +set(VCPKG_LIBRARY_LINKAGE dynamic) +set(VCPKG_BUILD_TYPE release) +set(VCPKG_CXX_FLAGS "/D_DISABLE_CONSTEXPR_MUTEX_CONSTRUCTOR") +set(VCPKG_C_FLAGS "") diff --git a/wpilibNewCommands/.styleguide b/wpilibNewCommands/.styleguide index 7c8d7a70fb7..feafd15406f 100644 --- a/wpilibNewCommands/.styleguide +++ b/wpilibNewCommands/.styleguide @@ -12,6 +12,10 @@ repoRootNameOverride { wpilib } +generatedFileExclude { + wpilibNewCommands/src/generated/ +} + includeOtherLibs { ^cameraserver/ ^cscore diff --git a/wpilibNewCommands/CMakeLists.txt b/wpilibNewCommands/CMakeLists.txt index cf17bd14274..5b82b2f5ff6 100644 --- a/wpilibNewCommands/CMakeLists.txt +++ b/wpilibNewCommands/CMakeLists.txt @@ -8,7 +8,7 @@ if(WITH_JAVA) find_package(Java REQUIRED) include(UseJava) - file(GLOB_RECURSE JAVA_SOURCES src/main/java/*.java) + file(GLOB_RECURSE JAVA_SOURCES src/main/java/*.java src/generated/main/java/*.java) add_jar( wpilibNewCommands_jar ${JAVA_SOURCES} @@ -39,7 +39,8 @@ if(WITH_JAVA_SOURCE) file(GLOB WPILIBNEWCOMMANDS_SOURCES src/main/java/edu/wpi/first/wpilibj2/command/*.java) file( GLOB WPILIBNEWCOMMANDS_BUTTON_SOURCES - src/main/java/edu/wpi/first/wpilibj2/command/button*.java + src/main/java/edu/wpi/first/wpilibj2/command/button/*.java + src/generated/main/java/edu/wpi/first/wpilibj2/command/button/*.java ) add_jar( wpilibNewCommands_src_jar @@ -55,7 +56,11 @@ if(WITH_JAVA_SOURCE) set_property(TARGET wpilibNewCommands_src_jar PROPERTY FOLDER "java") endif() -file(GLOB_RECURSE wpilibNewCommands_native_src src/main/native/cpp/*.cpp) +file( + GLOB_RECURSE wpilibNewCommands_native_src + src/main/native/cpp/*.cpp + src/generated/main/native/cpp/*.cpp +) add_library(wpilibNewCommands ${wpilibNewCommands_native_src}) set_target_properties(wpilibNewCommands PROPERTIES DEBUG_POSTFIX "d") set_property(TARGET wpilibNewCommands PROPERTY FOLDER "libraries") @@ -68,6 +73,7 @@ target_include_directories( wpilibNewCommands PUBLIC $ + $ $ ) diff --git a/wpilibNewCommands/build.gradle b/wpilibNewCommands/build.gradle index d60fcde1e4c..89ada857bfe 100644 --- a/wpilibNewCommands/build.gradle +++ b/wpilibNewCommands/build.gradle @@ -24,6 +24,8 @@ dependencies { testImplementation 'org.mockito:mockito-core:4.1.0' } +sourceSets.main.java.srcDir "${projectDir}/src/generated/main/java" + nativeUtils.exportsConfigs { wpilibNewCommands { x64ExcludeSymbols = [ @@ -43,7 +45,24 @@ nativeUtils.exportsConfigs { } model { - components {} + components { + "${nativeName}Base" { + it.sources.cpp { + source { + srcDirs 'src/generated/main/native/cpp' + include '**/*.cpp' + } + exportedHeaders { + srcDirs 'src/generated/main/native/include' + } + } + } + "${nativeName}" { + it.sources.cpp.exportedHeaders { + srcDirs 'src/generated/main/native/include' + } + } + } binaries { all { if (!it.buildable || !(it instanceof NativeBinarySpec)) { diff --git a/wpilibNewCommands/generate_hids.py b/wpilibNewCommands/generate_hids.py new file mode 100755 index 00000000000..8836253e5b7 --- /dev/null +++ b/wpilibNewCommands/generate_hids.py @@ -0,0 +1,88 @@ +#!/usr/bin/env python3 + +# Copyright (c) FIRST and other WPILib contributors. +# Open Source Software; you can modify and/or share it under the terms of +# the WPILib BSD license file in the root directory of this project. +import json +import os + +from jinja2 import Environment, FileSystemLoader + + +def write_controller_file(outPath, controllerName, contents): + if not os.path.exists(outPath): + os.makedirs(outPath) + + outpathname = f"{outPath}/{controllerName}" + + if os.path.exists(outpathname): + with open(outpathname, "r") as f: + if f.read() == contents: + return + + # File either doesn't exist or has different contents + with open(outpathname, "w", newline="\n") as f: + f.write(contents) + + +def main(): + dirname, _ = os.path.split(os.path.abspath(__file__)) + + with open("wpilibj/src/generate/hids.json") as f: + controllers = json.load(f) + + # Java files + env = Environment( + loader=FileSystemLoader( + f"{dirname}/src/generate/main/java/edu/wpi/first/wpilibj2/command/button" + ), + autoescape=False, + keep_trailing_newline=True, + ) + rootPath = ( + f"{dirname}/src/generated/main/java/edu/wpi/first/wpilibj2/command/button" + ) + template = env.get_template("commandhid.java.jinja") + for controller in controllers: + controllerName = os.path.basename( + f"Command{controller['ConsoleName']}Controller.java" + ) + output = template.render(controller) + write_controller_file(rootPath, controllerName, output) + + # C++ headers + env = Environment( + loader=FileSystemLoader( + f"{dirname}/src/generate/main/native/include/frc2/command/button" + ), + autoescape=False, + keep_trailing_newline=True, + ) + rootPath = f"{dirname}/src/generated/main/native/include/frc2/command/button" + template = env.get_template("commandhid.h.jinja") + for controller in controllers: + controllerName = os.path.basename( + f"Command{controller['ConsoleName']}Controller.h" + ) + output = template.render(controller) + write_controller_file(rootPath, controllerName, output) + + # C++ files + env = Environment( + loader=FileSystemLoader( + f"{dirname}/src/generate/main/native/cpp/frc2/command/button" + ), + autoescape=False, + ) + rootPath = f"{dirname}/src/generated/main/native/cpp/frc2/command/button" + template = env.get_template("commandhid.cpp.jinja") + for controller in controllers: + controllerName = os.path.basename( + f"Command{controller['ConsoleName']}Controller.cpp" + ) + output = template.render(controller) + write_controller_file(rootPath, controllerName, output) + + +if __name__ == "__main__": + main() diff --git a/wpilibNewCommands/src/generate/main/java/edu/wpi/first/wpilibj2/command/button/commandhid.java.jinja b/wpilibNewCommands/src/generate/main/java/edu/wpi/first/wpilibj2/command/button/commandhid.java.jinja new file mode 100644 index 00000000000..a13d673afd9 --- /dev/null +++ b/wpilibNewCommands/src/generate/main/java/edu/wpi/first/wpilibj2/command/button/commandhid.java.jinja @@ -0,0 +1,129 @@ +// Copyright (c) FIRST and other WPILib contributors. +// Open Source Software; you can modify and/or share it under the terms of +// the WPILib BSD license file in the root directory of this project. + +// THIS FILE WAS AUTO-GENERATED BY ./wpilibNewCommands/generate_hids.py. DO NOT MODIFY +{% macro capitalize_first(string) -%} +{{ string[0]|capitalize + string[1:] }} +{%- endmacro %} +package edu.wpi.first.wpilibj2.command.button; + +import edu.wpi.first.wpilibj.{{ ConsoleName }}Controller; +import edu.wpi.first.wpilibj.event.EventLoop; +import edu.wpi.first.wpilibj2.command.CommandScheduler; + +/** + * A version of {@link {{ ConsoleName }}Controller} with {@link Trigger} factories for command-based. + * + * @see {{ ConsoleName }}Controller + */ +@SuppressWarnings("MethodName") +public class Command{{ ConsoleName }}Controller extends CommandGenericHID { + private final {{ ConsoleName }}Controller m_hid; + + /** + * Construct an instance of a controller. + * + * @param port The port index on the Driver Station that the controller is plugged into. + */ + public Command{{ ConsoleName }}Controller(int port) { + super(port); + m_hid = new {{ ConsoleName }}Controller(port); + } + + /** + * Get the underlying GenericHID object. + * + * @return the wrapped GenericHID object + */ + @Override + public {{ ConsoleName }}Controller getHID() { + return m_hid; + } +{% for button in buttons %} + /** + * Constructs a Trigger instance around the {{ button.DocName|default(button.name) }} button's digital signal. + * + * @return a Trigger instance representing the {{ button.DocName|default(button.name) }} button's digital signal attached + * to the {@link CommandScheduler#getDefaultButtonLoop() default scheduler button loop}. + * @see #{{ button.name }}(EventLoop) + */ + public Trigger {{ button.name }}() { + return {{ button.name }}(CommandScheduler.getInstance().getDefaultButtonLoop()); + } + + /** + * Constructs a Trigger instance around the {{ button.DocName|default(button.name) }} button's digital signal. + * + * @param loop the event loop instance to attach the event to. + * @return a Trigger instance representing the {{ button.DocName|default(button.name) }} button's digital signal attached + * to the given loop. + */ + public Trigger {{ button.name }}(EventLoop loop) { + return m_hid.{{ button.name }}(loop).castTo(Trigger::new); + } +{% endfor -%} +{% for trigger in triggers -%} +{% if trigger.UseThresholdMethods %} + /** + * Constructs a Trigger instance around the axis value of the {{ trigger.DocName }}. The returned + * trigger will be true when the axis value is greater than {@code threshold}. + * + * @param threshold the minimum axis value for the returned {@link Trigger} to be true. This value + * should be in the range [0, 1] where 0 is the unpressed state of the axis. + * @param loop the event loop instance to attach the Trigger to. + * @return a Trigger instance that is true when the {{ trigger.DocName }}'s axis exceeds the provided + * threshold, attached to the given event loop + */ + public Trigger {{ trigger.name }}(double threshold, EventLoop loop) { + return m_hid.{{ trigger.name }}(threshold, loop).castTo(Trigger::new); + } + + /** + * Constructs a Trigger instance around the axis value of the {{ trigger.DocName }}. The returned + * trigger will be true when the axis value is greater than {@code threshold}. + * + * @param threshold the minimum axis value for the returned {@link Trigger} to be true. This value + * should be in the range [0, 1] where 0 is the unpressed state of the axis. + * @return a Trigger instance that is true when the {{ trigger.DocName }}'s axis exceeds the provided + * threshold, attached to the {@link CommandScheduler#getDefaultButtonLoop() default scheduler + * button loop}. + */ + public Trigger {{ trigger.name }}(double threshold) { + return {{ trigger.name }}(threshold, CommandScheduler.getInstance().getDefaultButtonLoop()); + } + + /** + * Constructs a Trigger instance around the axis value of the {{ trigger.DocName }}. The returned trigger + * will be true when the axis value is greater than 0.5. + * + * @return a Trigger instance that is true when the {{ trigger.DocName }}'s axis exceeds 0.5, attached to + * the {@link CommandScheduler#getDefaultButtonLoop() default scheduler button loop}. + */ + public Trigger {{ trigger.name }}() { + return {{ trigger.name }}(0.5); + } +{% endif -%} +{% endfor -%} +{% for stick in sticks %} + /** + * Get the {{ stick.NameParts[1] }} axis value of {{ stick.NameParts[0] }} side of the controller. + * + * @return The axis value. + */ + public double get{{ stick.NameParts|map("capitalize")|join }}() { + return m_hid.get{{ stick.NameParts|map("capitalize")|join }}(); + } +{% endfor -%} +{% for trigger in triggers %} + /** + * Get the {{ trigger.DocName }} axis value of the controller. Note that this axis is bound to the + * range of [0, 1] as opposed to the usual [-1, 1]. + * + * @return The axis value. + */ + public double get{{ capitalize_first(trigger.name) }}Axis() { + return m_hid.get{{ capitalize_first(trigger.name) }}Axis(); + } +{% endfor -%} +} diff --git a/wpilibNewCommands/src/generate/main/native/cpp/frc2/command/button/commandhid.cpp.jinja b/wpilibNewCommands/src/generate/main/native/cpp/frc2/command/button/commandhid.cpp.jinja new file mode 100644 index 00000000000..b6e5058598e --- /dev/null +++ b/wpilibNewCommands/src/generate/main/native/cpp/frc2/command/button/commandhid.cpp.jinja @@ -0,0 +1,41 @@ +// Copyright (c) FIRST and other WPILib contributors. +// Open Source Software; you can modify and/or share it under the terms of +// the WPILib BSD license file in the root directory of this project. + +// THIS FILE WAS AUTO-GENERATED BY ./wpilibNewCommands/generate_hids.py. DO NOT MODIFY +{% macro capitalize_first(string) -%} +{{ string[0]|capitalize + string[1:] }} +{%- endmacro %} +#include "frc2/command/button/Command{{ ConsoleName }}Controller.h" + +using namespace frc2; + +Command{{ ConsoleName }}Controller::Command{{ ConsoleName }}Controller(int port) + : CommandGenericHID(port), m_hid{frc::{{ ConsoleName }}Controller(port)} {} + +frc::{{ ConsoleName }}Controller& Command{{ ConsoleName }}Controller::GetHID() { + return m_hid; +} +{% for button in buttons %} +Trigger Command{{ ConsoleName }}Controller::{{ capitalize_first(button.name) }}(frc::EventLoop* loop) const { + return m_hid.{{ capitalize_first(button.name) }}(loop).CastTo(); +} +{% endfor -%} +{% for trigger in triggers -%} +{% if trigger.UseThresholdMethods %} +Trigger Command{{ ConsoleName }}Controller::{{ capitalize_first(trigger.name) }}(double threshold, + frc::EventLoop* loop) const { + return m_hid.{{ capitalize_first(trigger.name) }}(threshold, loop).CastTo(); +} +{% endif -%} +{% endfor -%} +{% for stick in sticks %} +double Command{{ ConsoleName }}Controller::Get{{ stick.NameParts|map("capitalize")|join }}() const { + return m_hid.Get{{ stick.NameParts|map("capitalize")|join }}(); +} +{% endfor -%} +{% for trigger in triggers %} +double Command{{ ConsoleName }}Controller::Get{{ capitalize_first(trigger.name) }}Axis() const { + return m_hid.Get{{ capitalize_first(trigger.name) }}Axis(); +} +{% endfor -%} diff --git a/wpilibNewCommands/src/generate/main/native/include/frc2/command/button/commandhid.h.jinja b/wpilibNewCommands/src/generate/main/native/include/frc2/command/button/commandhid.h.jinja new file mode 100644 index 00000000000..8e1d54074d5 --- /dev/null +++ b/wpilibNewCommands/src/generate/main/native/include/frc2/command/button/commandhid.h.jinja @@ -0,0 +1,92 @@ +// Copyright (c) FIRST and other WPILib contributors. +// Open Source Software; you can modify and/or share it under the terms of +// the WPILib BSD license file in the root directory of this project. + +// THIS FILE WAS AUTO-GENERATED BY ./wpilibNewCommands/generate_hids.py. DO NOT MODIFY +{% macro capitalize_first(string) -%} +{{ string[0]|capitalize + string[1:] }} +{%- endmacro %} +#pragma once +#include + +#include "frc2/command/button/Trigger.h" +#include "frc2/command/CommandScheduler.h" +#include "frc2/command/button/CommandGenericHID.h" + +namespace frc2 { +/** + * A version of {@link frc::{{ ConsoleName }}Controller} with {@link Trigger} factories for + * command-based. + * + * @see frc::{{ ConsoleName }}Controller + */ +class Command{{ ConsoleName }}Controller : public CommandGenericHID { + public: + /** + * Construct an instance of a controller. + * + * @param port The port index on the Driver Station that the controller is + * plugged into. + */ + explicit Command{{ ConsoleName }}Controller(int port); + + /** + * Get the underlying GenericHID object. + * + * @return the wrapped GenericHID object + */ + frc::{{ ConsoleName }}Controller& GetHID(); +{% for button in buttons %} + /** + * Constructs a Trigger instance around the {{ button.DocName|default(button.name) }} button's + * digital signal. + * + * @param loop the event loop instance to attach the event to. Defaults to the + * CommandScheduler's default loop. + * @return a Trigger instance representing the {{ button.DocName|default(button.name) }} button's + * digital signal attached to the given loop. + */ + Trigger {{ capitalize_first(button.name) }}(frc::EventLoop* loop = CommandScheduler::GetInstance() + .GetDefaultButtonLoop()) const; +{% endfor -%} +{% for trigger in triggers -%} +{% if trigger.UseThresholdMethods %} + /** + * Constructs a Trigger instance around the axis value of the {{ trigger.DocName }}. + * The returned Trigger will be true when the axis value is greater than + * {@code threshold}. + * + * @param threshold the minimum axis value for the returned Trigger to be + * true. This value should be in the range [0, 1] where 0 is the unpressed + * state of the axis. Defaults to 0.5. + * @param loop the event loop instance to attach the Trigger to. Defaults to + * the CommandScheduler's default loop. + * @return a Trigger instance that is true when the {{ trigger.DocName }}'s axis + * exceeds the provided threshold, attached to the given loop + */ + Trigger {{ capitalize_first(trigger.name) }}(double threshold = 0.5, + frc::EventLoop* loop = CommandScheduler::GetInstance() + .GetDefaultButtonLoop()) const; +{% endif -%} +{% endfor -%} +{% for stick in sticks %} + /** + * Get the {{ stick.NameParts[1] }} axis value of {{ stick.NameParts[0] }} side of the controller. + * + * @return The axis value. + */ + double Get{{ stick.NameParts|map("capitalize")|join }}() const; +{% endfor -%} +{% for trigger in triggers %} + /** + * Get the {{ trigger.DocName }} axis value of the controller. Note that this axis is bound + * to the range of [0, 1] as opposed to the usual [-1, 1]. + * + * @return The axis value. + */ + double Get{{ capitalize_first(trigger.name) }}Axis() const; +{% endfor %} + private: + frc::{{ ConsoleName }}Controller m_hid; +}; +} // namespace frc2 diff --git a/wpilibNewCommands/src/generated/main/java/edu/wpi/first/wpilibj2/command/button/CommandPS4Controller.java b/wpilibNewCommands/src/generated/main/java/edu/wpi/first/wpilibj2/command/button/CommandPS4Controller.java new file mode 100644 index 00000000000..150d1242286 --- /dev/null +++ b/wpilibNewCommands/src/generated/main/java/edu/wpi/first/wpilibj2/command/button/CommandPS4Controller.java @@ -0,0 +1,405 @@ +// Copyright (c) FIRST and other WPILib contributors. +// Open Source Software; you can modify and/or share it under the terms of +// the WPILib BSD license file in the root directory of this project. + +// THIS FILE WAS AUTO-GENERATED BY ./wpilibNewCommands/generate_hids.py. DO NOT MODIFY + +package edu.wpi.first.wpilibj2.command.button; + +import edu.wpi.first.wpilibj.PS4Controller; +import edu.wpi.first.wpilibj.event.EventLoop; +import edu.wpi.first.wpilibj2.command.CommandScheduler; + +/** + * A version of {@link PS4Controller} with {@link Trigger} factories for command-based. + * + * @see PS4Controller + */ +@SuppressWarnings("MethodName") +public class CommandPS4Controller extends CommandGenericHID { + private final PS4Controller m_hid; + + /** + * Construct an instance of a controller. + * + * @param port The port index on the Driver Station that the controller is plugged into. + */ + public CommandPS4Controller(int port) { + super(port); + m_hid = new PS4Controller(port); + } + + /** + * Get the underlying GenericHID object. + * + * @return the wrapped GenericHID object + */ + @Override + public PS4Controller getHID() { + return m_hid; + } + + /** + * Constructs a Trigger instance around the square button's digital signal. + * + * @return a Trigger instance representing the square button's digital signal attached + * to the {@link CommandScheduler#getDefaultButtonLoop() default scheduler button loop}. + * @see #square(EventLoop) + */ + public Trigger square() { + return square(CommandScheduler.getInstance().getDefaultButtonLoop()); + } + + /** + * Constructs a Trigger instance around the square button's digital signal. + * + * @param loop the event loop instance to attach the event to. + * @return a Trigger instance representing the square button's digital signal attached + * to the given loop. + */ + public Trigger square(EventLoop loop) { + return m_hid.square(loop).castTo(Trigger::new); + } + + /** + * Constructs a Trigger instance around the cross button's digital signal. + * + * @return a Trigger instance representing the cross button's digital signal attached + * to the {@link CommandScheduler#getDefaultButtonLoop() default scheduler button loop}. + * @see #cross(EventLoop) + */ + public Trigger cross() { + return cross(CommandScheduler.getInstance().getDefaultButtonLoop()); + } + + /** + * Constructs a Trigger instance around the cross button's digital signal. + * + * @param loop the event loop instance to attach the event to. + * @return a Trigger instance representing the cross button's digital signal attached + * to the given loop. + */ + public Trigger cross(EventLoop loop) { + return m_hid.cross(loop).castTo(Trigger::new); + } + + /** + * Constructs a Trigger instance around the circle button's digital signal. + * + * @return a Trigger instance representing the circle button's digital signal attached + * to the {@link CommandScheduler#getDefaultButtonLoop() default scheduler button loop}. + * @see #circle(EventLoop) + */ + public Trigger circle() { + return circle(CommandScheduler.getInstance().getDefaultButtonLoop()); + } + + /** + * Constructs a Trigger instance around the circle button's digital signal. + * + * @param loop the event loop instance to attach the event to. + * @return a Trigger instance representing the circle button's digital signal attached + * to the given loop. + */ + public Trigger circle(EventLoop loop) { + return m_hid.circle(loop).castTo(Trigger::new); + } + + /** + * Constructs a Trigger instance around the triangle button's digital signal. + * + * @return a Trigger instance representing the triangle button's digital signal attached + * to the {@link CommandScheduler#getDefaultButtonLoop() default scheduler button loop}. + * @see #triangle(EventLoop) + */ + public Trigger triangle() { + return triangle(CommandScheduler.getInstance().getDefaultButtonLoop()); + } + + /** + * Constructs a Trigger instance around the triangle button's digital signal. + * + * @param loop the event loop instance to attach the event to. + * @return a Trigger instance representing the triangle button's digital signal attached + * to the given loop. + */ + public Trigger triangle(EventLoop loop) { + return m_hid.triangle(loop).castTo(Trigger::new); + } + + /** + * Constructs a Trigger instance around the left trigger 1 button's digital signal. + * + * @return a Trigger instance representing the left trigger 1 button's digital signal attached + * to the {@link CommandScheduler#getDefaultButtonLoop() default scheduler button loop}. + * @see #L1(EventLoop) + */ + public Trigger L1() { + return L1(CommandScheduler.getInstance().getDefaultButtonLoop()); + } + + /** + * Constructs a Trigger instance around the left trigger 1 button's digital signal. + * + * @param loop the event loop instance to attach the event to. + * @return a Trigger instance representing the left trigger 1 button's digital signal attached + * to the given loop. + */ + public Trigger L1(EventLoop loop) { + return m_hid.L1(loop).castTo(Trigger::new); + } + + /** + * Constructs a Trigger instance around the right trigger 1 button's digital signal. + * + * @return a Trigger instance representing the right trigger 1 button's digital signal attached + * to the {@link CommandScheduler#getDefaultButtonLoop() default scheduler button loop}. + * @see #R1(EventLoop) + */ + public Trigger R1() { + return R1(CommandScheduler.getInstance().getDefaultButtonLoop()); + } + + /** + * Constructs a Trigger instance around the right trigger 1 button's digital signal. + * + * @param loop the event loop instance to attach the event to. + * @return a Trigger instance representing the right trigger 1 button's digital signal attached + * to the given loop. + */ + public Trigger R1(EventLoop loop) { + return m_hid.R1(loop).castTo(Trigger::new); + } + + /** + * Constructs a Trigger instance around the left trigger 2 button's digital signal. + * + * @return a Trigger instance representing the left trigger 2 button's digital signal attached + * to the {@link CommandScheduler#getDefaultButtonLoop() default scheduler button loop}. + * @see #L2(EventLoop) + */ + public Trigger L2() { + return L2(CommandScheduler.getInstance().getDefaultButtonLoop()); + } + + /** + * Constructs a Trigger instance around the left trigger 2 button's digital signal. + * + * @param loop the event loop instance to attach the event to. + * @return a Trigger instance representing the left trigger 2 button's digital signal attached + * to the given loop. + */ + public Trigger L2(EventLoop loop) { + return m_hid.L2(loop).castTo(Trigger::new); + } + + /** + * Constructs a Trigger instance around the right trigger 2 button's digital signal. + * + * @return a Trigger instance representing the right trigger 2 button's digital signal attached + * to the {@link CommandScheduler#getDefaultButtonLoop() default scheduler button loop}. + * @see #R2(EventLoop) + */ + public Trigger R2() { + return R2(CommandScheduler.getInstance().getDefaultButtonLoop()); + } + + /** + * Constructs a Trigger instance around the right trigger 2 button's digital signal. + * + * @param loop the event loop instance to attach the event to. + * @return a Trigger instance representing the right trigger 2 button's digital signal attached + * to the given loop. + */ + public Trigger R2(EventLoop loop) { + return m_hid.R2(loop).castTo(Trigger::new); + } + + /** + * Constructs a Trigger instance around the share button's digital signal. + * + * @return a Trigger instance representing the share button's digital signal attached + * to the {@link CommandScheduler#getDefaultButtonLoop() default scheduler button loop}. + * @see #share(EventLoop) + */ + public Trigger share() { + return share(CommandScheduler.getInstance().getDefaultButtonLoop()); + } + + /** + * Constructs a Trigger instance around the share button's digital signal. + * + * @param loop the event loop instance to attach the event to. + * @return a Trigger instance representing the share button's digital signal attached + * to the given loop. + */ + public Trigger share(EventLoop loop) { + return m_hid.share(loop).castTo(Trigger::new); + } + + /** + * Constructs a Trigger instance around the options button's digital signal. + * + * @return a Trigger instance representing the options button's digital signal attached + * to the {@link CommandScheduler#getDefaultButtonLoop() default scheduler button loop}. + * @see #options(EventLoop) + */ + public Trigger options() { + return options(CommandScheduler.getInstance().getDefaultButtonLoop()); + } + + /** + * Constructs a Trigger instance around the options button's digital signal. + * + * @param loop the event loop instance to attach the event to. + * @return a Trigger instance representing the options button's digital signal attached + * to the given loop. + */ + public Trigger options(EventLoop loop) { + return m_hid.options(loop).castTo(Trigger::new); + } + + /** + * Constructs a Trigger instance around the L3 (left stick) button's digital signal. + * + * @return a Trigger instance representing the L3 (left stick) button's digital signal attached + * to the {@link CommandScheduler#getDefaultButtonLoop() default scheduler button loop}. + * @see #L3(EventLoop) + */ + public Trigger L3() { + return L3(CommandScheduler.getInstance().getDefaultButtonLoop()); + } + + /** + * Constructs a Trigger instance around the L3 (left stick) button's digital signal. + * + * @param loop the event loop instance to attach the event to. + * @return a Trigger instance representing the L3 (left stick) button's digital signal attached + * to the given loop. + */ + public Trigger L3(EventLoop loop) { + return m_hid.L3(loop).castTo(Trigger::new); + } + + /** + * Constructs a Trigger instance around the R3 (right stick) button's digital signal. + * + * @return a Trigger instance representing the R3 (right stick) button's digital signal attached + * to the {@link CommandScheduler#getDefaultButtonLoop() default scheduler button loop}. + * @see #R3(EventLoop) + */ + public Trigger R3() { + return R3(CommandScheduler.getInstance().getDefaultButtonLoop()); + } + + /** + * Constructs a Trigger instance around the R3 (right stick) button's digital signal. + * + * @param loop the event loop instance to attach the event to. + * @return a Trigger instance representing the R3 (right stick) button's digital signal attached + * to the given loop. + */ + public Trigger R3(EventLoop loop) { + return m_hid.R3(loop).castTo(Trigger::new); + } + + /** + * Constructs a Trigger instance around the PlayStation button's digital signal. + * + * @return a Trigger instance representing the PlayStation button's digital signal attached + * to the {@link CommandScheduler#getDefaultButtonLoop() default scheduler button loop}. + * @see #PS(EventLoop) + */ + public Trigger PS() { + return PS(CommandScheduler.getInstance().getDefaultButtonLoop()); + } + + /** + * Constructs a Trigger instance around the PlayStation button's digital signal. + * + * @param loop the event loop instance to attach the event to. + * @return a Trigger instance representing the PlayStation button's digital signal attached + * to the given loop. + */ + public Trigger PS(EventLoop loop) { + return m_hid.PS(loop).castTo(Trigger::new); + } + + /** + * Constructs a Trigger instance around the touchpad button's digital signal. + * + * @return a Trigger instance representing the touchpad button's digital signal attached + * to the {@link CommandScheduler#getDefaultButtonLoop() default scheduler button loop}. + * @see #touchpad(EventLoop) + */ + public Trigger touchpad() { + return touchpad(CommandScheduler.getInstance().getDefaultButtonLoop()); + } + + /** + * Constructs a Trigger instance around the touchpad button's digital signal. + * + * @param loop the event loop instance to attach the event to. + * @return a Trigger instance representing the touchpad button's digital signal attached + * to the given loop. + */ + public Trigger touchpad(EventLoop loop) { + return m_hid.touchpad(loop).castTo(Trigger::new); + } + + /** + * Get the X axis value of left side of the controller. + * + * @return The axis value. + */ + public double getLeftX() { + return m_hid.getLeftX(); + } + + /** + * Get the Y axis value of left side of the controller. + * + * @return The axis value. + */ + public double getLeftY() { + return m_hid.getLeftY(); + } + + /** + * Get the X axis value of right side of the controller. + * + * @return The axis value. + */ + public double getRightX() { + return m_hid.getRightX(); + } + + /** + * Get the Y axis value of right side of the controller. + * + * @return The axis value. + */ + public double getRightY() { + return m_hid.getRightY(); + } + + /** + * Get the left trigger 2 axis value of the controller. Note that this axis is bound to the + * range of [0, 1] as opposed to the usual [-1, 1]. + * + * @return The axis value. + */ + public double getL2Axis() { + return m_hid.getL2Axis(); + } + + /** + * Get the right trigger 2 axis value of the controller. Note that this axis is bound to the + * range of [0, 1] as opposed to the usual [-1, 1]. + * + * @return The axis value. + */ + public double getR2Axis() { + return m_hid.getR2Axis(); + } +} diff --git a/wpilibNewCommands/src/generated/main/java/edu/wpi/first/wpilibj2/command/button/CommandPS5Controller.java b/wpilibNewCommands/src/generated/main/java/edu/wpi/first/wpilibj2/command/button/CommandPS5Controller.java new file mode 100644 index 00000000000..2f3d2718375 --- /dev/null +++ b/wpilibNewCommands/src/generated/main/java/edu/wpi/first/wpilibj2/command/button/CommandPS5Controller.java @@ -0,0 +1,405 @@ +// Copyright (c) FIRST and other WPILib contributors. +// Open Source Software; you can modify and/or share it under the terms of +// the WPILib BSD license file in the root directory of this project. + +// THIS FILE WAS AUTO-GENERATED BY ./wpilibNewCommands/generate_hids.py. DO NOT MODIFY + +package edu.wpi.first.wpilibj2.command.button; + +import edu.wpi.first.wpilibj.PS5Controller; +import edu.wpi.first.wpilibj.event.EventLoop; +import edu.wpi.first.wpilibj2.command.CommandScheduler; + +/** + * A version of {@link PS5Controller} with {@link Trigger} factories for command-based. + * + * @see PS5Controller + */ +@SuppressWarnings("MethodName") +public class CommandPS5Controller extends CommandGenericHID { + private final PS5Controller m_hid; + + /** + * Construct an instance of a controller. + * + * @param port The port index on the Driver Station that the controller is plugged into. + */ + public CommandPS5Controller(int port) { + super(port); + m_hid = new PS5Controller(port); + } + + /** + * Get the underlying GenericHID object. + * + * @return the wrapped GenericHID object + */ + @Override + public PS5Controller getHID() { + return m_hid; + } + + /** + * Constructs a Trigger instance around the square button's digital signal. + * + * @return a Trigger instance representing the square button's digital signal attached + * to the {@link CommandScheduler#getDefaultButtonLoop() default scheduler button loop}. + * @see #square(EventLoop) + */ + public Trigger square() { + return square(CommandScheduler.getInstance().getDefaultButtonLoop()); + } + + /** + * Constructs a Trigger instance around the square button's digital signal. + * + * @param loop the event loop instance to attach the event to. + * @return a Trigger instance representing the square button's digital signal attached + * to the given loop. + */ + public Trigger square(EventLoop loop) { + return m_hid.square(loop).castTo(Trigger::new); + } + + /** + * Constructs a Trigger instance around the cross button's digital signal. + * + * @return a Trigger instance representing the cross button's digital signal attached + * to the {@link CommandScheduler#getDefaultButtonLoop() default scheduler button loop}. + * @see #cross(EventLoop) + */ + public Trigger cross() { + return cross(CommandScheduler.getInstance().getDefaultButtonLoop()); + } + + /** + * Constructs a Trigger instance around the cross button's digital signal. + * + * @param loop the event loop instance to attach the event to. + * @return a Trigger instance representing the cross button's digital signal attached + * to the given loop. + */ + public Trigger cross(EventLoop loop) { + return m_hid.cross(loop).castTo(Trigger::new); + } + + /** + * Constructs a Trigger instance around the circle button's digital signal. + * + * @return a Trigger instance representing the circle button's digital signal attached + * to the {@link CommandScheduler#getDefaultButtonLoop() default scheduler button loop}. + * @see #circle(EventLoop) + */ + public Trigger circle() { + return circle(CommandScheduler.getInstance().getDefaultButtonLoop()); + } + + /** + * Constructs a Trigger instance around the circle button's digital signal. + * + * @param loop the event loop instance to attach the event to. + * @return a Trigger instance representing the circle button's digital signal attached + * to the given loop. + */ + public Trigger circle(EventLoop loop) { + return m_hid.circle(loop).castTo(Trigger::new); + } + + /** + * Constructs a Trigger instance around the triangle button's digital signal. + * + * @return a Trigger instance representing the triangle button's digital signal attached + * to the {@link CommandScheduler#getDefaultButtonLoop() default scheduler button loop}. + * @see #triangle(EventLoop) + */ + public Trigger triangle() { + return triangle(CommandScheduler.getInstance().getDefaultButtonLoop()); + } + + /** + * Constructs a Trigger instance around the triangle button's digital signal. + * + * @param loop the event loop instance to attach the event to. + * @return a Trigger instance representing the triangle button's digital signal attached + * to the given loop. + */ + public Trigger triangle(EventLoop loop) { + return m_hid.triangle(loop).castTo(Trigger::new); + } + + /** + * Constructs a Trigger instance around the left trigger 1 button's digital signal. + * + * @return a Trigger instance representing the left trigger 1 button's digital signal attached + * to the {@link CommandScheduler#getDefaultButtonLoop() default scheduler button loop}. + * @see #L1(EventLoop) + */ + public Trigger L1() { + return L1(CommandScheduler.getInstance().getDefaultButtonLoop()); + } + + /** + * Constructs a Trigger instance around the left trigger 1 button's digital signal. + * + * @param loop the event loop instance to attach the event to. + * @return a Trigger instance representing the left trigger 1 button's digital signal attached + * to the given loop. + */ + public Trigger L1(EventLoop loop) { + return m_hid.L1(loop).castTo(Trigger::new); + } + + /** + * Constructs a Trigger instance around the right trigger 1 button's digital signal. + * + * @return a Trigger instance representing the right trigger 1 button's digital signal attached + * to the {@link CommandScheduler#getDefaultButtonLoop() default scheduler button loop}. + * @see #R1(EventLoop) + */ + public Trigger R1() { + return R1(CommandScheduler.getInstance().getDefaultButtonLoop()); + } + + /** + * Constructs a Trigger instance around the right trigger 1 button's digital signal. + * + * @param loop the event loop instance to attach the event to. + * @return a Trigger instance representing the right trigger 1 button's digital signal attached + * to the given loop. + */ + public Trigger R1(EventLoop loop) { + return m_hid.R1(loop).castTo(Trigger::new); + } + + /** + * Constructs a Trigger instance around the left trigger 2 button's digital signal. + * + * @return a Trigger instance representing the left trigger 2 button's digital signal attached + * to the {@link CommandScheduler#getDefaultButtonLoop() default scheduler button loop}. + * @see #L2(EventLoop) + */ + public Trigger L2() { + return L2(CommandScheduler.getInstance().getDefaultButtonLoop()); + } + + /** + * Constructs a Trigger instance around the left trigger 2 button's digital signal. + * + * @param loop the event loop instance to attach the event to. + * @return a Trigger instance representing the left trigger 2 button's digital signal attached + * to the given loop. + */ + public Trigger L2(EventLoop loop) { + return m_hid.L2(loop).castTo(Trigger::new); + } + + /** + * Constructs a Trigger instance around the right trigger 2 button's digital signal. + * + * @return a Trigger instance representing the right trigger 2 button's digital signal attached + * to the {@link CommandScheduler#getDefaultButtonLoop() default scheduler button loop}. + * @see #R2(EventLoop) + */ + public Trigger R2() { + return R2(CommandScheduler.getInstance().getDefaultButtonLoop()); + } + + /** + * Constructs a Trigger instance around the right trigger 2 button's digital signal. + * + * @param loop the event loop instance to attach the event to. + * @return a Trigger instance representing the right trigger 2 button's digital signal attached + * to the given loop. + */ + public Trigger R2(EventLoop loop) { + return m_hid.R2(loop).castTo(Trigger::new); + } + + /** + * Constructs a Trigger instance around the create button's digital signal. + * + * @return a Trigger instance representing the create button's digital signal attached + * to the {@link CommandScheduler#getDefaultButtonLoop() default scheduler button loop}. + * @see #create(EventLoop) + */ + public Trigger create() { + return create(CommandScheduler.getInstance().getDefaultButtonLoop()); + } + + /** + * Constructs a Trigger instance around the create button's digital signal. + * + * @param loop the event loop instance to attach the event to. + * @return a Trigger instance representing the create button's digital signal attached + * to the given loop. + */ + public Trigger create(EventLoop loop) { + return m_hid.create(loop).castTo(Trigger::new); + } + + /** + * Constructs a Trigger instance around the options button's digital signal. + * + * @return a Trigger instance representing the options button's digital signal attached + * to the {@link CommandScheduler#getDefaultButtonLoop() default scheduler button loop}. + * @see #options(EventLoop) + */ + public Trigger options() { + return options(CommandScheduler.getInstance().getDefaultButtonLoop()); + } + + /** + * Constructs a Trigger instance around the options button's digital signal. + * + * @param loop the event loop instance to attach the event to. + * @return a Trigger instance representing the options button's digital signal attached + * to the given loop. + */ + public Trigger options(EventLoop loop) { + return m_hid.options(loop).castTo(Trigger::new); + } + + /** + * Constructs a Trigger instance around the L3 (left stick) button's digital signal. + * + * @return a Trigger instance representing the L3 (left stick) button's digital signal attached + * to the {@link CommandScheduler#getDefaultButtonLoop() default scheduler button loop}. + * @see #L3(EventLoop) + */ + public Trigger L3() { + return L3(CommandScheduler.getInstance().getDefaultButtonLoop()); + } + + /** + * Constructs a Trigger instance around the L3 (left stick) button's digital signal. + * + * @param loop the event loop instance to attach the event to. + * @return a Trigger instance representing the L3 (left stick) button's digital signal attached + * to the given loop. + */ + public Trigger L3(EventLoop loop) { + return m_hid.L3(loop).castTo(Trigger::new); + } + + /** + * Constructs a Trigger instance around the R3 (right stick) button's digital signal. + * + * @return a Trigger instance representing the R3 (right stick) button's digital signal attached + * to the {@link CommandScheduler#getDefaultButtonLoop() default scheduler button loop}. + * @see #R3(EventLoop) + */ + public Trigger R3() { + return R3(CommandScheduler.getInstance().getDefaultButtonLoop()); + } + + /** + * Constructs a Trigger instance around the R3 (right stick) button's digital signal. + * + * @param loop the event loop instance to attach the event to. + * @return a Trigger instance representing the R3 (right stick) button's digital signal attached + * to the given loop. + */ + public Trigger R3(EventLoop loop) { + return m_hid.R3(loop).castTo(Trigger::new); + } + + /** + * Constructs a Trigger instance around the PlayStation button's digital signal. + * + * @return a Trigger instance representing the PlayStation button's digital signal attached + * to the {@link CommandScheduler#getDefaultButtonLoop() default scheduler button loop}. + * @see #PS(EventLoop) + */ + public Trigger PS() { + return PS(CommandScheduler.getInstance().getDefaultButtonLoop()); + } + + /** + * Constructs a Trigger instance around the PlayStation button's digital signal. + * + * @param loop the event loop instance to attach the event to. + * @return a Trigger instance representing the PlayStation button's digital signal attached + * to the given loop. + */ + public Trigger PS(EventLoop loop) { + return m_hid.PS(loop).castTo(Trigger::new); + } + + /** + * Constructs a Trigger instance around the touchpad button's digital signal. + * + * @return a Trigger instance representing the touchpad button's digital signal attached + * to the {@link CommandScheduler#getDefaultButtonLoop() default scheduler button loop}. + * @see #touchpad(EventLoop) + */ + public Trigger touchpad() { + return touchpad(CommandScheduler.getInstance().getDefaultButtonLoop()); + } + + /** + * Constructs a Trigger instance around the touchpad button's digital signal. + * + * @param loop the event loop instance to attach the event to. + * @return a Trigger instance representing the touchpad button's digital signal attached + * to the given loop. + */ + public Trigger touchpad(EventLoop loop) { + return m_hid.touchpad(loop).castTo(Trigger::new); + } + + /** + * Get the X axis value of left side of the controller. + * + * @return The axis value. + */ + public double getLeftX() { + return m_hid.getLeftX(); + } + + /** + * Get the Y axis value of left side of the controller. + * + * @return The axis value. + */ + public double getLeftY() { + return m_hid.getLeftY(); + } + + /** + * Get the X axis value of right side of the controller. + * + * @return The axis value. + */ + public double getRightX() { + return m_hid.getRightX(); + } + + /** + * Get the Y axis value of right side of the controller. + * + * @return The axis value. + */ + public double getRightY() { + return m_hid.getRightY(); + } + + /** + * Get the left trigger 2 axis value of the controller. Note that this axis is bound to the + * range of [0, 1] as opposed to the usual [-1, 1]. + * + * @return The axis value. + */ + public double getL2Axis() { + return m_hid.getL2Axis(); + } + + /** + * Get the right trigger 2 axis value of the controller. Note that this axis is bound to the + * range of [0, 1] as opposed to the usual [-1, 1]. + * + * @return The axis value. + */ + public double getR2Axis() { + return m_hid.getR2Axis(); + } +} diff --git a/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/button/CommandStadiaController.java b/wpilibNewCommands/src/generated/main/java/edu/wpi/first/wpilibj2/command/button/CommandStadiaController.java similarity index 50% rename from wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/button/CommandStadiaController.java rename to wpilibNewCommands/src/generated/main/java/edu/wpi/first/wpilibj2/command/button/CommandStadiaController.java index 0d919e5caa9..90bc5d01785 100644 --- a/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/button/CommandStadiaController.java +++ b/wpilibNewCommands/src/generated/main/java/edu/wpi/first/wpilibj2/command/button/CommandStadiaController.java @@ -2,6 +2,8 @@ // Open Source Software; you can modify and/or share it under the terms of // the WPILib BSD license file in the root directory of this project. +// THIS FILE WAS AUTO-GENERATED BY ./wpilibNewCommands/generate_hids.py. DO NOT MODIFY + package edu.wpi.first.wpilibj2.command.button; import edu.wpi.first.wpilibj.StadiaController; @@ -38,333 +40,333 @@ public StadiaController getHID() { } /** - * Constructs an event instance around the left bumper's digital signal. + * Constructs a Trigger instance around the A button's digital signal. * - * @return an event instance representing the left bumper's digital signal attached to the {@link - * CommandScheduler#getDefaultButtonLoop() default scheduler button loop}. - * @see #leftBumper(EventLoop) + * @return a Trigger instance representing the A button's digital signal attached + * to the {@link CommandScheduler#getDefaultButtonLoop() default scheduler button loop}. + * @see #a(EventLoop) */ - public Trigger leftBumper() { - return leftBumper(CommandScheduler.getInstance().getDefaultButtonLoop()); + public Trigger a() { + return a(CommandScheduler.getInstance().getDefaultButtonLoop()); } /** - * Constructs an event instance around the left bumper's digital signal. + * Constructs a Trigger instance around the A button's digital signal. * * @param loop the event loop instance to attach the event to. - * @return an event instance representing the right bumper's digital signal attached to the given - * loop. + * @return a Trigger instance representing the A button's digital signal attached + * to the given loop. */ - public Trigger leftBumper(EventLoop loop) { - return m_hid.leftBumper(loop).castTo(Trigger::new); + public Trigger a(EventLoop loop) { + return m_hid.a(loop).castTo(Trigger::new); } /** - * Constructs an event instance around the right bumper's digital signal. + * Constructs a Trigger instance around the B button's digital signal. * - * @return an event instance representing the right bumper's digital signal attached to the {@link - * CommandScheduler#getDefaultButtonLoop() default scheduler button loop}. - * @see #rightBumper(EventLoop) + * @return a Trigger instance representing the B button's digital signal attached + * to the {@link CommandScheduler#getDefaultButtonLoop() default scheduler button loop}. + * @see #b(EventLoop) */ - public Trigger rightBumper() { - return rightBumper(CommandScheduler.getInstance().getDefaultButtonLoop()); + public Trigger b() { + return b(CommandScheduler.getInstance().getDefaultButtonLoop()); } /** - * Constructs an event instance around the right bumper's digital signal. + * Constructs a Trigger instance around the B button's digital signal. * * @param loop the event loop instance to attach the event to. - * @return an event instance representing the left bumper's digital signal attached to the given - * loop. + * @return a Trigger instance representing the B button's digital signal attached + * to the given loop. */ - public Trigger rightBumper(EventLoop loop) { - return m_hid.rightBumper(loop).castTo(Trigger::new); + public Trigger b(EventLoop loop) { + return m_hid.b(loop).castTo(Trigger::new); } /** - * Constructs an event instance around the left stick button's digital signal. + * Constructs a Trigger instance around the X button's digital signal. * - * @return an event instance representing the left stick button's digital signal attached to the - * {@link CommandScheduler#getDefaultButtonLoop() default scheduler button loop}. - * @see #leftStick(EventLoop) + * @return a Trigger instance representing the X button's digital signal attached + * to the {@link CommandScheduler#getDefaultButtonLoop() default scheduler button loop}. + * @see #x(EventLoop) */ - public Trigger leftStick() { - return leftStick(CommandScheduler.getInstance().getDefaultButtonLoop()); + public Trigger x() { + return x(CommandScheduler.getInstance().getDefaultButtonLoop()); } /** - * Constructs an event instance around the left stick button's digital signal. + * Constructs a Trigger instance around the X button's digital signal. * * @param loop the event loop instance to attach the event to. - * @return an event instance representing the left stick button's digital signal attached to the - * given loop. + * @return a Trigger instance representing the X button's digital signal attached + * to the given loop. */ - public Trigger leftStick(EventLoop loop) { - return m_hid.leftStick(loop).castTo(Trigger::new); + public Trigger x(EventLoop loop) { + return m_hid.x(loop).castTo(Trigger::new); } /** - * Constructs an event instance around the right stick button's digital signal. + * Constructs a Trigger instance around the Y button's digital signal. * - * @return an event instance representing the right stick button's digital signal attached to the - * {@link CommandScheduler#getDefaultButtonLoop() default scheduler button loop}. - * @see #rightStick(EventLoop) + * @return a Trigger instance representing the Y button's digital signal attached + * to the {@link CommandScheduler#getDefaultButtonLoop() default scheduler button loop}. + * @see #y(EventLoop) */ - public Trigger rightStick() { - return rightStick(CommandScheduler.getInstance().getDefaultButtonLoop()); + public Trigger y() { + return y(CommandScheduler.getInstance().getDefaultButtonLoop()); } /** - * Constructs an event instance around the right stick button's digital signal. + * Constructs a Trigger instance around the Y button's digital signal. * * @param loop the event loop instance to attach the event to. - * @return an event instance representing the right stick button's digital signal attached to the - * given loop. + * @return a Trigger instance representing the Y button's digital signal attached + * to the given loop. */ - public Trigger rightStick(EventLoop loop) { - return m_hid.rightStick(loop).castTo(Trigger::new); + public Trigger y(EventLoop loop) { + return m_hid.y(loop).castTo(Trigger::new); } /** - * Constructs an event instance around the right trigger button's digital signal. + * Constructs a Trigger instance around the left bumper button's digital signal. * - * @return an event instance representing the right trigger button's digital signal attached to - * the {@link CommandScheduler#getDefaultButtonLoop() default scheduler button loop}. - * @see #rightTrigger(EventLoop) + * @return a Trigger instance representing the left bumper button's digital signal attached + * to the {@link CommandScheduler#getDefaultButtonLoop() default scheduler button loop}. + * @see #leftBumper(EventLoop) */ - public Trigger rightTrigger() { - return rightTrigger(CommandScheduler.getInstance().getDefaultButtonLoop()); + public Trigger leftBumper() { + return leftBumper(CommandScheduler.getInstance().getDefaultButtonLoop()); } /** - * Constructs an event instance around the right trigger button's digital signal. + * Constructs a Trigger instance around the left bumper button's digital signal. * * @param loop the event loop instance to attach the event to. - * @return an event instance representing the right trigger button's digital signal attached to - * the given loop. + * @return a Trigger instance representing the left bumper button's digital signal attached + * to the given loop. */ - public Trigger rightTrigger(EventLoop loop) { - return m_hid.rightTrigger(loop).castTo(Trigger::new); + public Trigger leftBumper(EventLoop loop) { + return m_hid.leftBumper(loop).castTo(Trigger::new); } /** - * Constructs an event instance around the left trigger button's digital signal. + * Constructs a Trigger instance around the right bumper button's digital signal. * - * @return an event instance representing the left trigger button's digital signal attached to the - * {@link CommandScheduler#getDefaultButtonLoop() default scheduler button loop}. - * @see #leftTrigger(EventLoop) + * @return a Trigger instance representing the right bumper button's digital signal attached + * to the {@link CommandScheduler#getDefaultButtonLoop() default scheduler button loop}. + * @see #rightBumper(EventLoop) */ - public Trigger leftTrigger() { - return leftTrigger(CommandScheduler.getInstance().getDefaultButtonLoop()); + public Trigger rightBumper() { + return rightBumper(CommandScheduler.getInstance().getDefaultButtonLoop()); } /** - * Constructs an event instance around the left trigger button's digital signal. + * Constructs a Trigger instance around the right bumper button's digital signal. * * @param loop the event loop instance to attach the event to. - * @return an event instance representing the left trigger button's digital signal attached to the - * given loop. + * @return a Trigger instance representing the right bumper button's digital signal attached + * to the given loop. */ - public Trigger leftTrigger(EventLoop loop) { - return m_hid.leftTrigger(loop).castTo(Trigger::new); + public Trigger rightBumper(EventLoop loop) { + return m_hid.rightBumper(loop).castTo(Trigger::new); } /** - * Constructs an event instance around the A button's digital signal. + * Constructs a Trigger instance around the left stick button's digital signal. * - * @return an event instance representing the A button's digital signal attached to the {@link - * CommandScheduler#getDefaultButtonLoop() default scheduler button loop}. - * @see #a(EventLoop) + * @return a Trigger instance representing the left stick button's digital signal attached + * to the {@link CommandScheduler#getDefaultButtonLoop() default scheduler button loop}. + * @see #leftStick(EventLoop) */ - public Trigger a() { - return a(CommandScheduler.getInstance().getDefaultButtonLoop()); + public Trigger leftStick() { + return leftStick(CommandScheduler.getInstance().getDefaultButtonLoop()); } /** - * Constructs an event instance around the A button's digital signal. + * Constructs a Trigger instance around the left stick button's digital signal. * * @param loop the event loop instance to attach the event to. - * @return an event instance representing the A button's digital signal attached to the given - * loop. + * @return a Trigger instance representing the left stick button's digital signal attached + * to the given loop. */ - public Trigger a(EventLoop loop) { - return m_hid.a(loop).castTo(Trigger::new); + public Trigger leftStick(EventLoop loop) { + return m_hid.leftStick(loop).castTo(Trigger::new); } /** - * Constructs an event instance around the B button's digital signal. + * Constructs a Trigger instance around the right stick button's digital signal. * - * @return an event instance representing the B button's digital signal attached to the {@link - * CommandScheduler#getDefaultButtonLoop() default scheduler button loop}. - * @see #b(EventLoop) + * @return a Trigger instance representing the right stick button's digital signal attached + * to the {@link CommandScheduler#getDefaultButtonLoop() default scheduler button loop}. + * @see #rightStick(EventLoop) */ - public Trigger b() { - return b(CommandScheduler.getInstance().getDefaultButtonLoop()); + public Trigger rightStick() { + return rightStick(CommandScheduler.getInstance().getDefaultButtonLoop()); } /** - * Constructs an event instance around the B button's digital signal. + * Constructs a Trigger instance around the right stick button's digital signal. * * @param loop the event loop instance to attach the event to. - * @return an event instance representing the B button's digital signal attached to the given - * loop. + * @return a Trigger instance representing the right stick button's digital signal attached + * to the given loop. */ - public Trigger b(EventLoop loop) { - return m_hid.b(loop).castTo(Trigger::new); + public Trigger rightStick(EventLoop loop) { + return m_hid.rightStick(loop).castTo(Trigger::new); } /** - * Constructs an event instance around the X button's digital signal. + * Constructs a Trigger instance around the ellipses button's digital signal. * - * @return an event instance representing the X button's digital signal attached to the {@link - * CommandScheduler#getDefaultButtonLoop() default scheduler button loop}. - * @see #x(EventLoop) + * @return a Trigger instance representing the ellipses button's digital signal attached + * to the {@link CommandScheduler#getDefaultButtonLoop() default scheduler button loop}. + * @see #ellipses(EventLoop) */ - public Trigger x() { - return x(CommandScheduler.getInstance().getDefaultButtonLoop()); + public Trigger ellipses() { + return ellipses(CommandScheduler.getInstance().getDefaultButtonLoop()); } /** - * Constructs an event instance around the X button's digital signal. + * Constructs a Trigger instance around the ellipses button's digital signal. * * @param loop the event loop instance to attach the event to. - * @return an event instance representing the X button's digital signal attached to the given - * loop. + * @return a Trigger instance representing the ellipses button's digital signal attached + * to the given loop. */ - public Trigger x(EventLoop loop) { - return m_hid.x(loop).castTo(Trigger::new); + public Trigger ellipses(EventLoop loop) { + return m_hid.ellipses(loop).castTo(Trigger::new); } /** - * Constructs an event instance around the Y button's digital signal. + * Constructs a Trigger instance around the hamburger button's digital signal. * - * @return an event instance representing the Y button's digital signal attached to the {@link - * CommandScheduler#getDefaultButtonLoop() default scheduler button loop}. - * @see #y(EventLoop) + * @return a Trigger instance representing the hamburger button's digital signal attached + * to the {@link CommandScheduler#getDefaultButtonLoop() default scheduler button loop}. + * @see #hamburger(EventLoop) */ - public Trigger y() { - return y(CommandScheduler.getInstance().getDefaultButtonLoop()); + public Trigger hamburger() { + return hamburger(CommandScheduler.getInstance().getDefaultButtonLoop()); } /** - * Constructs an event instance around the Y button's digital signal. + * Constructs a Trigger instance around the hamburger button's digital signal. * * @param loop the event loop instance to attach the event to. - * @return an event instance representing the Y button's digital signal attached to the given - * loop. + * @return a Trigger instance representing the hamburger button's digital signal attached + * to the given loop. */ - public Trigger y(EventLoop loop) { - return m_hid.y(loop).castTo(Trigger::new); + public Trigger hamburger(EventLoop loop) { + return m_hid.hamburger(loop).castTo(Trigger::new); } /** - * Constructs an event instance around the ellipses button's digital signal. + * Constructs a Trigger instance around the stadia button's digital signal. * - * @return an event instance representing the ellipses button's digital signal attached to the - * {@link CommandScheduler#getDefaultButtonLoop() default scheduler button loop}. - * @see #ellipses(EventLoop) + * @return a Trigger instance representing the stadia button's digital signal attached + * to the {@link CommandScheduler#getDefaultButtonLoop() default scheduler button loop}. + * @see #stadia(EventLoop) */ - public Trigger ellipses() { - return ellipses(CommandScheduler.getInstance().getDefaultButtonLoop()); + public Trigger stadia() { + return stadia(CommandScheduler.getInstance().getDefaultButtonLoop()); } /** - * Constructs an event instance around the ellipses button's digital signal. + * Constructs a Trigger instance around the stadia button's digital signal. * * @param loop the event loop instance to attach the event to. - * @return an event instance representing the ellipses button's digital signal attached to the - * given loop. + * @return a Trigger instance representing the stadia button's digital signal attached + * to the given loop. */ - public Trigger ellipses(EventLoop loop) { - return m_hid.ellipses(loop).castTo(Trigger::new); + public Trigger stadia(EventLoop loop) { + return m_hid.stadia(loop).castTo(Trigger::new); } /** - * Constructs an event instance around the stadia button's digital signal. + * Constructs a Trigger instance around the right trigger button's digital signal. * - * @return an event instance representing the stadia button's digital signal attached to the - * {@link CommandScheduler#getDefaultButtonLoop() default scheduler button loop}. - * @see #stadia(EventLoop) + * @return a Trigger instance representing the right trigger button's digital signal attached + * to the {@link CommandScheduler#getDefaultButtonLoop() default scheduler button loop}. + * @see #rightTrigger(EventLoop) */ - public Trigger stadia() { - return stadia(CommandScheduler.getInstance().getDefaultButtonLoop()); + public Trigger rightTrigger() { + return rightTrigger(CommandScheduler.getInstance().getDefaultButtonLoop()); } /** - * Constructs an event instance around the stadia button's digital signal. + * Constructs a Trigger instance around the right trigger button's digital signal. * * @param loop the event loop instance to attach the event to. - * @return an event instance representing the stadia button's digital signal attached to the given - * loop. + * @return a Trigger instance representing the right trigger button's digital signal attached + * to the given loop. */ - public Trigger stadia(EventLoop loop) { - return m_hid.stadia(loop).castTo(Trigger::new); + public Trigger rightTrigger(EventLoop loop) { + return m_hid.rightTrigger(loop).castTo(Trigger::new); } /** - * Constructs an event instance around the google button's digital signal. + * Constructs a Trigger instance around the left trigger button's digital signal. * - * @return an event instance representing the google button's digital signal attached to the - * {@link CommandScheduler#getDefaultButtonLoop() default scheduler button loop}. - * @see #google(EventLoop) + * @return a Trigger instance representing the left trigger button's digital signal attached + * to the {@link CommandScheduler#getDefaultButtonLoop() default scheduler button loop}. + * @see #leftTrigger(EventLoop) */ - public Trigger google() { - return google(CommandScheduler.getInstance().getDefaultButtonLoop()); + public Trigger leftTrigger() { + return leftTrigger(CommandScheduler.getInstance().getDefaultButtonLoop()); } /** - * Constructs an event instance around the google button's digital signal. + * Constructs a Trigger instance around the left trigger button's digital signal. * * @param loop the event loop instance to attach the event to. - * @return an event instance representing the google button's digital signal attached to the given - * loop. + * @return a Trigger instance representing the left trigger button's digital signal attached + * to the given loop. */ - public Trigger google(EventLoop loop) { - return m_hid.google(loop).castTo(Trigger::new); + public Trigger leftTrigger(EventLoop loop) { + return m_hid.leftTrigger(loop).castTo(Trigger::new); } /** - * Constructs an event instance around the frame button's digital signal. + * Constructs a Trigger instance around the google button's digital signal. * - * @return an event instance representing the frame button's digital signal attached to the {@link - * CommandScheduler#getDefaultButtonLoop() default scheduler button loop}. - * @see #frame(EventLoop) + * @return a Trigger instance representing the google button's digital signal attached + * to the {@link CommandScheduler#getDefaultButtonLoop() default scheduler button loop}. + * @see #google(EventLoop) */ - public Trigger frame() { - return frame(CommandScheduler.getInstance().getDefaultButtonLoop()); + public Trigger google() { + return google(CommandScheduler.getInstance().getDefaultButtonLoop()); } /** - * Constructs an event instance around the frame button's digital signal. + * Constructs a Trigger instance around the google button's digital signal. * * @param loop the event loop instance to attach the event to. - * @return an event instance representing the frame button's digital signal attached to the given - * loop. + * @return a Trigger instance representing the google button's digital signal attached + * to the given loop. */ - public Trigger frame(EventLoop loop) { - return m_hid.frame(loop).castTo(Trigger::new); + public Trigger google(EventLoop loop) { + return m_hid.google(loop).castTo(Trigger::new); } /** - * Constructs an event instance around the hamburger button's digital signal. + * Constructs a Trigger instance around the frame button's digital signal. * - * @return an event instance representing the hamburger button's digital signal attached to the - * {@link CommandScheduler#getDefaultButtonLoop() default scheduler button loop}. - * @see #hamburger(EventLoop) + * @return a Trigger instance representing the frame button's digital signal attached + * to the {@link CommandScheduler#getDefaultButtonLoop() default scheduler button loop}. + * @see #frame(EventLoop) */ - public Trigger hamburger() { - return hamburger(CommandScheduler.getInstance().getDefaultButtonLoop()); + public Trigger frame() { + return frame(CommandScheduler.getInstance().getDefaultButtonLoop()); } /** - * Constructs an event instance around the hamburger button's digital signal. + * Constructs a Trigger instance around the frame button's digital signal. * * @param loop the event loop instance to attach the event to. - * @return an event instance representing the hamburger button's digital signal attached to the - * given loop. + * @return a Trigger instance representing the frame button's digital signal attached + * to the given loop. */ - public Trigger hamburger(EventLoop loop) { - return m_hid.hamburger(loop).castTo(Trigger::new); + public Trigger frame(EventLoop loop) { + return m_hid.frame(loop).castTo(Trigger::new); } /** diff --git a/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/button/CommandXboxController.java b/wpilibNewCommands/src/generated/main/java/edu/wpi/first/wpilibj2/command/button/CommandXboxController.java similarity index 62% rename from wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/button/CommandXboxController.java rename to wpilibNewCommands/src/generated/main/java/edu/wpi/first/wpilibj2/command/button/CommandXboxController.java index 6969c984688..0f6417674e9 100644 --- a/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/button/CommandXboxController.java +++ b/wpilibNewCommands/src/generated/main/java/edu/wpi/first/wpilibj2/command/button/CommandXboxController.java @@ -2,6 +2,8 @@ // Open Source Software; you can modify and/or share it under the terms of // the WPILib BSD license file in the root directory of this project. +// THIS FILE WAS AUTO-GENERATED BY ./wpilibNewCommands/generate_hids.py. DO NOT MODIFY + package edu.wpi.first.wpilibj2.command.button; import edu.wpi.first.wpilibj.XboxController; @@ -38,228 +40,228 @@ public XboxController getHID() { } /** - * Constructs an event instance around the left bumper's digital signal. + * Constructs a Trigger instance around the A button's digital signal. * - * @return an event instance representing the left bumper's digital signal attached to the {@link - * CommandScheduler#getDefaultButtonLoop() default scheduler button loop}. - * @see #leftBumper(EventLoop) + * @return a Trigger instance representing the A button's digital signal attached + * to the {@link CommandScheduler#getDefaultButtonLoop() default scheduler button loop}. + * @see #a(EventLoop) */ - public Trigger leftBumper() { - return leftBumper(CommandScheduler.getInstance().getDefaultButtonLoop()); + public Trigger a() { + return a(CommandScheduler.getInstance().getDefaultButtonLoop()); } /** - * Constructs an event instance around the left bumper's digital signal. + * Constructs a Trigger instance around the A button's digital signal. * * @param loop the event loop instance to attach the event to. - * @return an event instance representing the right bumper's digital signal attached to the given - * loop. + * @return a Trigger instance representing the A button's digital signal attached + * to the given loop. */ - public Trigger leftBumper(EventLoop loop) { - return m_hid.leftBumper(loop).castTo(Trigger::new); + public Trigger a(EventLoop loop) { + return m_hid.a(loop).castTo(Trigger::new); } /** - * Constructs an event instance around the right bumper's digital signal. + * Constructs a Trigger instance around the B button's digital signal. * - * @return an event instance representing the right bumper's digital signal attached to the {@link - * CommandScheduler#getDefaultButtonLoop() default scheduler button loop}. - * @see #rightBumper(EventLoop) + * @return a Trigger instance representing the B button's digital signal attached + * to the {@link CommandScheduler#getDefaultButtonLoop() default scheduler button loop}. + * @see #b(EventLoop) */ - public Trigger rightBumper() { - return rightBumper(CommandScheduler.getInstance().getDefaultButtonLoop()); + public Trigger b() { + return b(CommandScheduler.getInstance().getDefaultButtonLoop()); } /** - * Constructs an event instance around the right bumper's digital signal. + * Constructs a Trigger instance around the B button's digital signal. * * @param loop the event loop instance to attach the event to. - * @return an event instance representing the left bumper's digital signal attached to the given - * loop. + * @return a Trigger instance representing the B button's digital signal attached + * to the given loop. */ - public Trigger rightBumper(EventLoop loop) { - return m_hid.rightBumper(loop).castTo(Trigger::new); + public Trigger b(EventLoop loop) { + return m_hid.b(loop).castTo(Trigger::new); } /** - * Constructs an event instance around the left stick button's digital signal. + * Constructs a Trigger instance around the X button's digital signal. * - * @return an event instance representing the left stick button's digital signal attached to the - * {@link CommandScheduler#getDefaultButtonLoop() default scheduler button loop}. - * @see #leftStick(EventLoop) + * @return a Trigger instance representing the X button's digital signal attached + * to the {@link CommandScheduler#getDefaultButtonLoop() default scheduler button loop}. + * @see #x(EventLoop) */ - public Trigger leftStick() { - return leftStick(CommandScheduler.getInstance().getDefaultButtonLoop()); + public Trigger x() { + return x(CommandScheduler.getInstance().getDefaultButtonLoop()); } /** - * Constructs an event instance around the left stick button's digital signal. + * Constructs a Trigger instance around the X button's digital signal. * * @param loop the event loop instance to attach the event to. - * @return an event instance representing the left stick button's digital signal attached to the - * given loop. + * @return a Trigger instance representing the X button's digital signal attached + * to the given loop. */ - public Trigger leftStick(EventLoop loop) { - return m_hid.leftStick(loop).castTo(Trigger::new); + public Trigger x(EventLoop loop) { + return m_hid.x(loop).castTo(Trigger::new); } /** - * Constructs an event instance around the right stick button's digital signal. + * Constructs a Trigger instance around the Y button's digital signal. * - * @return an event instance representing the right stick button's digital signal attached to the - * {@link CommandScheduler#getDefaultButtonLoop() default scheduler button loop}. - * @see #rightStick(EventLoop) + * @return a Trigger instance representing the Y button's digital signal attached + * to the {@link CommandScheduler#getDefaultButtonLoop() default scheduler button loop}. + * @see #y(EventLoop) */ - public Trigger rightStick() { - return rightStick(CommandScheduler.getInstance().getDefaultButtonLoop()); + public Trigger y() { + return y(CommandScheduler.getInstance().getDefaultButtonLoop()); } /** - * Constructs an event instance around the right stick button's digital signal. + * Constructs a Trigger instance around the Y button's digital signal. * * @param loop the event loop instance to attach the event to. - * @return an event instance representing the right stick button's digital signal attached to the - * given loop. + * @return a Trigger instance representing the Y button's digital signal attached + * to the given loop. */ - public Trigger rightStick(EventLoop loop) { - return m_hid.rightStick(loop).castTo(Trigger::new); + public Trigger y(EventLoop loop) { + return m_hid.y(loop).castTo(Trigger::new); } /** - * Constructs an event instance around the A button's digital signal. + * Constructs a Trigger instance around the left bumper button's digital signal. * - * @return an event instance representing the A button's digital signal attached to the {@link - * CommandScheduler#getDefaultButtonLoop() default scheduler button loop}. - * @see #a(EventLoop) + * @return a Trigger instance representing the left bumper button's digital signal attached + * to the {@link CommandScheduler#getDefaultButtonLoop() default scheduler button loop}. + * @see #leftBumper(EventLoop) */ - public Trigger a() { - return a(CommandScheduler.getInstance().getDefaultButtonLoop()); + public Trigger leftBumper() { + return leftBumper(CommandScheduler.getInstance().getDefaultButtonLoop()); } /** - * Constructs an event instance around the A button's digital signal. + * Constructs a Trigger instance around the left bumper button's digital signal. * * @param loop the event loop instance to attach the event to. - * @return an event instance representing the A button's digital signal attached to the given - * loop. + * @return a Trigger instance representing the left bumper button's digital signal attached + * to the given loop. */ - public Trigger a(EventLoop loop) { - return m_hid.a(loop).castTo(Trigger::new); + public Trigger leftBumper(EventLoop loop) { + return m_hid.leftBumper(loop).castTo(Trigger::new); } /** - * Constructs an event instance around the B button's digital signal. + * Constructs a Trigger instance around the right bumper button's digital signal. * - * @return an event instance representing the B button's digital signal attached to the {@link - * CommandScheduler#getDefaultButtonLoop() default scheduler button loop}. - * @see #b(EventLoop) + * @return a Trigger instance representing the right bumper button's digital signal attached + * to the {@link CommandScheduler#getDefaultButtonLoop() default scheduler button loop}. + * @see #rightBumper(EventLoop) */ - public Trigger b() { - return b(CommandScheduler.getInstance().getDefaultButtonLoop()); + public Trigger rightBumper() { + return rightBumper(CommandScheduler.getInstance().getDefaultButtonLoop()); } /** - * Constructs an event instance around the B button's digital signal. + * Constructs a Trigger instance around the right bumper button's digital signal. * * @param loop the event loop instance to attach the event to. - * @return an event instance representing the B button's digital signal attached to the given - * loop. + * @return a Trigger instance representing the right bumper button's digital signal attached + * to the given loop. */ - public Trigger b(EventLoop loop) { - return m_hid.b(loop).castTo(Trigger::new); + public Trigger rightBumper(EventLoop loop) { + return m_hid.rightBumper(loop).castTo(Trigger::new); } /** - * Constructs an event instance around the X button's digital signal. + * Constructs a Trigger instance around the back button's digital signal. * - * @return an event instance representing the X button's digital signal attached to the {@link - * CommandScheduler#getDefaultButtonLoop() default scheduler button loop}. - * @see #x(EventLoop) + * @return a Trigger instance representing the back button's digital signal attached + * to the {@link CommandScheduler#getDefaultButtonLoop() default scheduler button loop}. + * @see #back(EventLoop) */ - public Trigger x() { - return x(CommandScheduler.getInstance().getDefaultButtonLoop()); + public Trigger back() { + return back(CommandScheduler.getInstance().getDefaultButtonLoop()); } /** - * Constructs an event instance around the X button's digital signal. + * Constructs a Trigger instance around the back button's digital signal. * * @param loop the event loop instance to attach the event to. - * @return an event instance representing the X button's digital signal attached to the given - * loop. + * @return a Trigger instance representing the back button's digital signal attached + * to the given loop. */ - public Trigger x(EventLoop loop) { - return m_hid.x(loop).castTo(Trigger::new); + public Trigger back(EventLoop loop) { + return m_hid.back(loop).castTo(Trigger::new); } /** - * Constructs an event instance around the Y button's digital signal. + * Constructs a Trigger instance around the start button's digital signal. * - * @return an event instance representing the Y button's digital signal attached to the {@link - * CommandScheduler#getDefaultButtonLoop() default scheduler button loop}. - * @see #y(EventLoop) + * @return a Trigger instance representing the start button's digital signal attached + * to the {@link CommandScheduler#getDefaultButtonLoop() default scheduler button loop}. + * @see #start(EventLoop) */ - public Trigger y() { - return y(CommandScheduler.getInstance().getDefaultButtonLoop()); + public Trigger start() { + return start(CommandScheduler.getInstance().getDefaultButtonLoop()); } /** - * Constructs an event instance around the Y button's digital signal. + * Constructs a Trigger instance around the start button's digital signal. * * @param loop the event loop instance to attach the event to. - * @return an event instance representing the Y button's digital signal attached to the given - * loop. + * @return a Trigger instance representing the start button's digital signal attached + * to the given loop. */ - public Trigger y(EventLoop loop) { - return m_hid.y(loop).castTo(Trigger::new); + public Trigger start(EventLoop loop) { + return m_hid.start(loop).castTo(Trigger::new); } /** - * Constructs an event instance around the start button's digital signal. + * Constructs a Trigger instance around the left stick button's digital signal. * - * @return an event instance representing the start button's digital signal attached to the {@link - * CommandScheduler#getDefaultButtonLoop() default scheduler button loop}. - * @see #start(EventLoop) + * @return a Trigger instance representing the left stick button's digital signal attached + * to the {@link CommandScheduler#getDefaultButtonLoop() default scheduler button loop}. + * @see #leftStick(EventLoop) */ - public Trigger start() { - return start(CommandScheduler.getInstance().getDefaultButtonLoop()); + public Trigger leftStick() { + return leftStick(CommandScheduler.getInstance().getDefaultButtonLoop()); } /** - * Constructs an event instance around the start button's digital signal. + * Constructs a Trigger instance around the left stick button's digital signal. * * @param loop the event loop instance to attach the event to. - * @return an event instance representing the start button's digital signal attached to the given - * loop. + * @return a Trigger instance representing the left stick button's digital signal attached + * to the given loop. */ - public Trigger start(EventLoop loop) { - return m_hid.start(loop).castTo(Trigger::new); + public Trigger leftStick(EventLoop loop) { + return m_hid.leftStick(loop).castTo(Trigger::new); } /** - * Constructs an event instance around the back button's digital signal. + * Constructs a Trigger instance around the right stick button's digital signal. * - * @return an event instance representing the back button's digital signal attached to the {@link - * CommandScheduler#getDefaultButtonLoop() default scheduler button loop}. - * @see #back(EventLoop) + * @return a Trigger instance representing the right stick button's digital signal attached + * to the {@link CommandScheduler#getDefaultButtonLoop() default scheduler button loop}. + * @see #rightStick(EventLoop) */ - public Trigger back() { - return back(CommandScheduler.getInstance().getDefaultButtonLoop()); + public Trigger rightStick() { + return rightStick(CommandScheduler.getInstance().getDefaultButtonLoop()); } /** - * Constructs an event instance around the back button's digital signal. + * Constructs a Trigger instance around the right stick button's digital signal. * * @param loop the event loop instance to attach the event to. - * @return an event instance representing the back button's digital signal attached to the given - * loop. + * @return a Trigger instance representing the right stick button's digital signal attached + * to the given loop. */ - public Trigger back(EventLoop loop) { - return m_hid.back(loop).castTo(Trigger::new); + public Trigger rightStick(EventLoop loop) { + return m_hid.rightStick(loop).castTo(Trigger::new); } /** - * Constructs a Trigger instance around the axis value of the left trigger. The returned trigger - * will be true when the axis value is greater than {@code threshold}. + * Constructs a Trigger instance around the axis value of the left trigger. The returned + * trigger will be true when the axis value is greater than {@code threshold}. * * @param threshold the minimum axis value for the returned {@link Trigger} to be true. This value * should be in the range [0, 1] where 0 is the unpressed state of the axis. @@ -272,8 +274,8 @@ public Trigger leftTrigger(double threshold, EventLoop loop) { } /** - * Constructs a Trigger instance around the axis value of the left trigger. The returned trigger - * will be true when the axis value is greater than {@code threshold}. + * Constructs a Trigger instance around the axis value of the left trigger. The returned + * trigger will be true when the axis value is greater than {@code threshold}. * * @param threshold the minimum axis value for the returned {@link Trigger} to be true. This value * should be in the range [0, 1] where 0 is the unpressed state of the axis. @@ -297,8 +299,8 @@ public Trigger leftTrigger() { } /** - * Constructs a Trigger instance around the axis value of the right trigger. The returned trigger - * will be true when the axis value is greater than {@code threshold}. + * Constructs a Trigger instance around the axis value of the right trigger. The returned + * trigger will be true when the axis value is greater than {@code threshold}. * * @param threshold the minimum axis value for the returned {@link Trigger} to be true. This value * should be in the range [0, 1] where 0 is the unpressed state of the axis. @@ -311,8 +313,8 @@ public Trigger rightTrigger(double threshold, EventLoop loop) { } /** - * Constructs a Trigger instance around the axis value of the right trigger. The returned trigger - * will be true when the axis value is greater than {@code threshold}. + * Constructs a Trigger instance around the axis value of the right trigger. The returned + * trigger will be true when the axis value is greater than {@code threshold}. * * @param threshold the minimum axis value for the returned {@link Trigger} to be true. This value * should be in the range [0, 1] where 0 is the unpressed state of the axis. @@ -372,7 +374,7 @@ public double getRightY() { } /** - * Get the left trigger (LT) axis value of the controller. Note that this axis is bound to the + * Get the left trigger axis value of the controller. Note that this axis is bound to the * range of [0, 1] as opposed to the usual [-1, 1]. * * @return The axis value. @@ -382,7 +384,7 @@ public double getLeftTriggerAxis() { } /** - * Get the right trigger (RT) axis value of the controller. Note that this axis is bound to the + * Get the right trigger axis value of the controller. Note that this axis is bound to the * range of [0, 1] as opposed to the usual [-1, 1]. * * @return The axis value. diff --git a/wpilibNewCommands/src/main/native/cpp/frc2/command/button/CommandPS4Controller.cpp b/wpilibNewCommands/src/generated/main/native/cpp/frc2/command/button/CommandPS4Controller.cpp similarity index 81% rename from wpilibNewCommands/src/main/native/cpp/frc2/command/button/CommandPS4Controller.cpp rename to wpilibNewCommands/src/generated/main/native/cpp/frc2/command/button/CommandPS4Controller.cpp index 8388682f8b3..e5418f845a8 100644 --- a/wpilibNewCommands/src/main/native/cpp/frc2/command/button/CommandPS4Controller.cpp +++ b/wpilibNewCommands/src/generated/main/native/cpp/frc2/command/button/CommandPS4Controller.cpp @@ -2,6 +2,8 @@ // Open Source Software; you can modify and/or share it under the terms of // the WPILib BSD license file in the root directory of this project. +// THIS FILE WAS AUTO-GENERATED BY ./wpilibNewCommands/generate_hids.py. DO NOT MODIFY + #include "frc2/command/button/CommandPS4Controller.h" using namespace frc2; @@ -45,6 +47,10 @@ Trigger CommandPS4Controller::R2(frc::EventLoop* loop) const { return m_hid.R2(loop).CastTo(); } +Trigger CommandPS4Controller::Share(frc::EventLoop* loop) const { + return m_hid.Share(loop).CastTo(); +} + Trigger CommandPS4Controller::Options(frc::EventLoop* loop) const { return m_hid.Options(loop).CastTo(); } @@ -65,26 +71,26 @@ Trigger CommandPS4Controller::Touchpad(frc::EventLoop* loop) const { return m_hid.Touchpad(loop).CastTo(); } -double CommandPS4Controller::GetR2Axis() { - return m_hid.GetR2Axis(); +double CommandPS4Controller::GetLeftX() const { + return m_hid.GetLeftX(); } -double CommandPS4Controller::GetL2Axis() { - return m_hid.GetL2Axis(); +double CommandPS4Controller::GetLeftY() const { + return m_hid.GetLeftY(); } -double CommandPS4Controller::GetRightY() { - return m_hid.GetRightY(); +double CommandPS4Controller::GetRightX() const { + return m_hid.GetRightX(); } -double CommandPS4Controller::GetLeftY() { - return m_hid.GetLeftY(); +double CommandPS4Controller::GetRightY() const { + return m_hid.GetRightY(); } -double CommandPS4Controller::GetRightX() { - return m_hid.GetRightX(); +double CommandPS4Controller::GetL2Axis() const { + return m_hid.GetL2Axis(); } -double CommandPS4Controller::GetLeftX() { - return m_hid.GetLeftX(); +double CommandPS4Controller::GetR2Axis() const { + return m_hid.GetR2Axis(); } diff --git a/wpilibNewCommands/src/main/native/cpp/frc2/command/button/CommandPS5Controller.cpp b/wpilibNewCommands/src/generated/main/native/cpp/frc2/command/button/CommandPS5Controller.cpp similarity index 81% rename from wpilibNewCommands/src/main/native/cpp/frc2/command/button/CommandPS5Controller.cpp rename to wpilibNewCommands/src/generated/main/native/cpp/frc2/command/button/CommandPS5Controller.cpp index d98cc237805..bb0c5b8e5b4 100644 --- a/wpilibNewCommands/src/main/native/cpp/frc2/command/button/CommandPS5Controller.cpp +++ b/wpilibNewCommands/src/generated/main/native/cpp/frc2/command/button/CommandPS5Controller.cpp @@ -2,6 +2,8 @@ // Open Source Software; you can modify and/or share it under the terms of // the WPILib BSD license file in the root directory of this project. +// THIS FILE WAS AUTO-GENERATED BY ./wpilibNewCommands/generate_hids.py. DO NOT MODIFY + #include "frc2/command/button/CommandPS5Controller.h" using namespace frc2; @@ -45,6 +47,10 @@ Trigger CommandPS5Controller::R2(frc::EventLoop* loop) const { return m_hid.R2(loop).CastTo(); } +Trigger CommandPS5Controller::Create(frc::EventLoop* loop) const { + return m_hid.Create(loop).CastTo(); +} + Trigger CommandPS5Controller::Options(frc::EventLoop* loop) const { return m_hid.Options(loop).CastTo(); } @@ -65,26 +71,26 @@ Trigger CommandPS5Controller::Touchpad(frc::EventLoop* loop) const { return m_hid.Touchpad(loop).CastTo(); } -double CommandPS5Controller::GetR2Axis() { - return m_hid.GetR2Axis(); +double CommandPS5Controller::GetLeftX() const { + return m_hid.GetLeftX(); } -double CommandPS5Controller::GetL2Axis() { - return m_hid.GetL2Axis(); +double CommandPS5Controller::GetLeftY() const { + return m_hid.GetLeftY(); } -double CommandPS5Controller::GetRightY() { - return m_hid.GetRightY(); +double CommandPS5Controller::GetRightX() const { + return m_hid.GetRightX(); } -double CommandPS5Controller::GetLeftY() { - return m_hid.GetLeftY(); +double CommandPS5Controller::GetRightY() const { + return m_hid.GetRightY(); } -double CommandPS5Controller::GetRightX() { - return m_hid.GetRightX(); +double CommandPS5Controller::GetL2Axis() const { + return m_hid.GetL2Axis(); } -double CommandPS5Controller::GetLeftX() { - return m_hid.GetLeftX(); +double CommandPS5Controller::GetR2Axis() const { + return m_hid.GetR2Axis(); } diff --git a/wpilibNewCommands/src/main/native/cpp/frc2/command/button/CommandStadiaController.cpp b/wpilibNewCommands/src/generated/main/native/cpp/frc2/command/button/CommandStadiaController.cpp similarity index 96% rename from wpilibNewCommands/src/main/native/cpp/frc2/command/button/CommandStadiaController.cpp rename to wpilibNewCommands/src/generated/main/native/cpp/frc2/command/button/CommandStadiaController.cpp index 6568b8253f0..ee032b1926c 100644 --- a/wpilibNewCommands/src/main/native/cpp/frc2/command/button/CommandStadiaController.cpp +++ b/wpilibNewCommands/src/generated/main/native/cpp/frc2/command/button/CommandStadiaController.cpp @@ -2,6 +2,8 @@ // Open Source Software; you can modify and/or share it under the terms of // the WPILib BSD license file in the root directory of this project. +// THIS FILE WAS AUTO-GENERATED BY ./wpilibNewCommands/generate_hids.py. DO NOT MODIFY + #include "frc2/command/button/CommandStadiaController.h" using namespace frc2; @@ -13,22 +15,6 @@ frc::StadiaController& CommandStadiaController::GetHID() { return m_hid; } -Trigger CommandStadiaController::LeftBumper(frc::EventLoop* loop) const { - return m_hid.LeftBumper(loop).CastTo(); -} - -Trigger CommandStadiaController::RightBumper(frc::EventLoop* loop) const { - return m_hid.RightBumper(loop).CastTo(); -} - -Trigger CommandStadiaController::LeftStick(frc::EventLoop* loop) const { - return m_hid.LeftStick(loop).CastTo(); -} - -Trigger CommandStadiaController::RightStick(frc::EventLoop* loop) const { - return m_hid.RightStick(loop).CastTo(); -} - Trigger CommandStadiaController::A(frc::EventLoop* loop) const { return m_hid.A(loop).CastTo(); } @@ -45,6 +31,22 @@ Trigger CommandStadiaController::Y(frc::EventLoop* loop) const { return m_hid.Y(loop).CastTo(); } +Trigger CommandStadiaController::LeftBumper(frc::EventLoop* loop) const { + return m_hid.LeftBumper(loop).CastTo(); +} + +Trigger CommandStadiaController::RightBumper(frc::EventLoop* loop) const { + return m_hid.RightBumper(loop).CastTo(); +} + +Trigger CommandStadiaController::LeftStick(frc::EventLoop* loop) const { + return m_hid.LeftStick(loop).CastTo(); +} + +Trigger CommandStadiaController::RightStick(frc::EventLoop* loop) const { + return m_hid.RightStick(loop).CastTo(); +} + Trigger CommandStadiaController::Ellipses(frc::EventLoop* loop) const { return m_hid.Ellipses(loop).CastTo(); } @@ -57,20 +59,20 @@ Trigger CommandStadiaController::Stadia(frc::EventLoop* loop) const { return m_hid.Stadia(loop).CastTo(); } -Trigger CommandStadiaController::Google(frc::EventLoop* loop) const { - return m_hid.Google(loop).CastTo(); -} - -Trigger CommandStadiaController::Frame(frc::EventLoop* loop) const { - return m_hid.Frame(loop).CastTo(); +Trigger CommandStadiaController::RightTrigger(frc::EventLoop* loop) const { + return m_hid.RightTrigger(loop).CastTo(); } Trigger CommandStadiaController::LeftTrigger(frc::EventLoop* loop) const { return m_hid.LeftTrigger(loop).CastTo(); } -Trigger CommandStadiaController::RightTrigger(frc::EventLoop* loop) const { - return m_hid.RightTrigger(loop).CastTo(); +Trigger CommandStadiaController::Google(frc::EventLoop* loop) const { + return m_hid.Google(loop).CastTo(); +} + +Trigger CommandStadiaController::Frame(frc::EventLoop* loop) const { + return m_hid.Frame(loop).CastTo(); } double CommandStadiaController::GetLeftX() const { diff --git a/wpilibNewCommands/src/main/native/cpp/frc2/command/button/CommandXboxController.cpp b/wpilibNewCommands/src/generated/main/native/cpp/frc2/command/button/CommandXboxController.cpp similarity index 81% rename from wpilibNewCommands/src/main/native/cpp/frc2/command/button/CommandXboxController.cpp rename to wpilibNewCommands/src/generated/main/native/cpp/frc2/command/button/CommandXboxController.cpp index 2e366d27e2b..39fa0154546 100644 --- a/wpilibNewCommands/src/main/native/cpp/frc2/command/button/CommandXboxController.cpp +++ b/wpilibNewCommands/src/generated/main/native/cpp/frc2/command/button/CommandXboxController.cpp @@ -2,6 +2,8 @@ // Open Source Software; you can modify and/or share it under the terms of // the WPILib BSD license file in the root directory of this project. +// THIS FILE WAS AUTO-GENERATED BY ./wpilibNewCommands/generate_hids.py. DO NOT MODIFY + #include "frc2/command/button/CommandXboxController.h" using namespace frc2; @@ -13,22 +15,6 @@ frc::XboxController& CommandXboxController::GetHID() { return m_hid; } -Trigger CommandXboxController::LeftBumper(frc::EventLoop* loop) const { - return m_hid.LeftBumper(loop).CastTo(); -} - -Trigger CommandXboxController::RightBumper(frc::EventLoop* loop) const { - return m_hid.RightBumper(loop).CastTo(); -} - -Trigger CommandXboxController::LeftStick(frc::EventLoop* loop) const { - return m_hid.LeftStick(loop).CastTo(); -} - -Trigger CommandXboxController::RightStick(frc::EventLoop* loop) const { - return m_hid.RightStick(loop).CastTo(); -} - Trigger CommandXboxController::A(frc::EventLoop* loop) const { return m_hid.A(loop).CastTo(); } @@ -45,6 +31,14 @@ Trigger CommandXboxController::Y(frc::EventLoop* loop) const { return m_hid.Y(loop).CastTo(); } +Trigger CommandXboxController::LeftBumper(frc::EventLoop* loop) const { + return m_hid.LeftBumper(loop).CastTo(); +} + +Trigger CommandXboxController::RightBumper(frc::EventLoop* loop) const { + return m_hid.RightBumper(loop).CastTo(); +} + Trigger CommandXboxController::Back(frc::EventLoop* loop) const { return m_hid.Back(loop).CastTo(); } @@ -53,36 +47,44 @@ Trigger CommandXboxController::Start(frc::EventLoop* loop) const { return m_hid.Start(loop).CastTo(); } +Trigger CommandXboxController::LeftStick(frc::EventLoop* loop) const { + return m_hid.LeftStick(loop).CastTo(); +} + +Trigger CommandXboxController::RightStick(frc::EventLoop* loop) const { + return m_hid.RightStick(loop).CastTo(); +} + Trigger CommandXboxController::LeftTrigger(double threshold, frc::EventLoop* loop) const { return m_hid.LeftTrigger(threshold, loop).CastTo(); } Trigger CommandXboxController::RightTrigger(double threshold, - frc::EventLoop* loop) const { + frc::EventLoop* loop) const { return m_hid.RightTrigger(threshold, loop).CastTo(); } -double CommandXboxController::GetRightTriggerAxis() { - return m_hid.GetRightTriggerAxis(); +double CommandXboxController::GetLeftX() const { + return m_hid.GetLeftX(); } -double CommandXboxController::GetLeftTriggerAxis() { - return m_hid.GetLeftTriggerAxis(); +double CommandXboxController::GetRightX() const { + return m_hid.GetRightX(); } -double CommandXboxController::GetRightY() { - return m_hid.GetRightY(); +double CommandXboxController::GetLeftY() const { + return m_hid.GetLeftY(); } -double CommandXboxController::GetLeftY() { - return m_hid.GetLeftY(); +double CommandXboxController::GetRightY() const { + return m_hid.GetRightY(); } -double CommandXboxController::GetRightX() { - return m_hid.GetRightX(); +double CommandXboxController::GetLeftTriggerAxis() const { + return m_hid.GetLeftTriggerAxis(); } -double CommandXboxController::GetLeftX() { - return m_hid.GetLeftX(); +double CommandXboxController::GetRightTriggerAxis() const { + return m_hid.GetRightTriggerAxis(); } diff --git a/wpilibNewCommands/src/generated/main/native/include/frc2/command/button/CommandPS4Controller.h b/wpilibNewCommands/src/generated/main/native/include/frc2/command/button/CommandPS4Controller.h new file mode 100644 index 00000000000..ac0920f1a50 --- /dev/null +++ b/wpilibNewCommands/src/generated/main/native/include/frc2/command/button/CommandPS4Controller.h @@ -0,0 +1,253 @@ +// Copyright (c) FIRST and other WPILib contributors. +// Open Source Software; you can modify and/or share it under the terms of +// the WPILib BSD license file in the root directory of this project. + +// THIS FILE WAS AUTO-GENERATED BY ./wpilibNewCommands/generate_hids.py. DO NOT MODIFY + +#pragma once +#include + +#include "frc2/command/button/Trigger.h" +#include "frc2/command/CommandScheduler.h" +#include "frc2/command/button/CommandGenericHID.h" + +namespace frc2 { +/** + * A version of {@link frc::PS4Controller} with {@link Trigger} factories for + * command-based. + * + * @see frc::PS4Controller + */ +class CommandPS4Controller : public CommandGenericHID { + public: + /** + * Construct an instance of a controller. + * + * @param port The port index on the Driver Station that the controller is + * plugged into. + */ + explicit CommandPS4Controller(int port); + + /** + * Get the underlying GenericHID object. + * + * @return the wrapped GenericHID object + */ + frc::PS4Controller& GetHID(); + + /** + * Constructs a Trigger instance around the square button's + * digital signal. + * + * @param loop the event loop instance to attach the event to. Defaults to the + * CommandScheduler's default loop. + * @return a Trigger instance representing the square button's + * digital signal attached to the given loop. + */ + Trigger Square(frc::EventLoop* loop = CommandScheduler::GetInstance() + .GetDefaultButtonLoop()) const; + + /** + * Constructs a Trigger instance around the cross button's + * digital signal. + * + * @param loop the event loop instance to attach the event to. Defaults to the + * CommandScheduler's default loop. + * @return a Trigger instance representing the cross button's + * digital signal attached to the given loop. + */ + Trigger Cross(frc::EventLoop* loop = CommandScheduler::GetInstance() + .GetDefaultButtonLoop()) const; + + /** + * Constructs a Trigger instance around the circle button's + * digital signal. + * + * @param loop the event loop instance to attach the event to. Defaults to the + * CommandScheduler's default loop. + * @return a Trigger instance representing the circle button's + * digital signal attached to the given loop. + */ + Trigger Circle(frc::EventLoop* loop = CommandScheduler::GetInstance() + .GetDefaultButtonLoop()) const; + + /** + * Constructs a Trigger instance around the triangle button's + * digital signal. + * + * @param loop the event loop instance to attach the event to. Defaults to the + * CommandScheduler's default loop. + * @return a Trigger instance representing the triangle button's + * digital signal attached to the given loop. + */ + Trigger Triangle(frc::EventLoop* loop = CommandScheduler::GetInstance() + .GetDefaultButtonLoop()) const; + + /** + * Constructs a Trigger instance around the left trigger 1 button's + * digital signal. + * + * @param loop the event loop instance to attach the event to. Defaults to the + * CommandScheduler's default loop. + * @return a Trigger instance representing the left trigger 1 button's + * digital signal attached to the given loop. + */ + Trigger L1(frc::EventLoop* loop = CommandScheduler::GetInstance() + .GetDefaultButtonLoop()) const; + + /** + * Constructs a Trigger instance around the right trigger 1 button's + * digital signal. + * + * @param loop the event loop instance to attach the event to. Defaults to the + * CommandScheduler's default loop. + * @return a Trigger instance representing the right trigger 1 button's + * digital signal attached to the given loop. + */ + Trigger R1(frc::EventLoop* loop = CommandScheduler::GetInstance() + .GetDefaultButtonLoop()) const; + + /** + * Constructs a Trigger instance around the left trigger 2 button's + * digital signal. + * + * @param loop the event loop instance to attach the event to. Defaults to the + * CommandScheduler's default loop. + * @return a Trigger instance representing the left trigger 2 button's + * digital signal attached to the given loop. + */ + Trigger L2(frc::EventLoop* loop = CommandScheduler::GetInstance() + .GetDefaultButtonLoop()) const; + + /** + * Constructs a Trigger instance around the right trigger 2 button's + * digital signal. + * + * @param loop the event loop instance to attach the event to. Defaults to the + * CommandScheduler's default loop. + * @return a Trigger instance representing the right trigger 2 button's + * digital signal attached to the given loop. + */ + Trigger R2(frc::EventLoop* loop = CommandScheduler::GetInstance() + .GetDefaultButtonLoop()) const; + + /** + * Constructs a Trigger instance around the share button's + * digital signal. + * + * @param loop the event loop instance to attach the event to. Defaults to the + * CommandScheduler's default loop. + * @return a Trigger instance representing the share button's + * digital signal attached to the given loop. + */ + Trigger Share(frc::EventLoop* loop = CommandScheduler::GetInstance() + .GetDefaultButtonLoop()) const; + + /** + * Constructs a Trigger instance around the options button's + * digital signal. + * + * @param loop the event loop instance to attach the event to. Defaults to the + * CommandScheduler's default loop. + * @return a Trigger instance representing the options button's + * digital signal attached to the given loop. + */ + Trigger Options(frc::EventLoop* loop = CommandScheduler::GetInstance() + .GetDefaultButtonLoop()) const; + + /** + * Constructs a Trigger instance around the L3 (left stick) button's + * digital signal. + * + * @param loop the event loop instance to attach the event to. Defaults to the + * CommandScheduler's default loop. + * @return a Trigger instance representing the L3 (left stick) button's + * digital signal attached to the given loop. + */ + Trigger L3(frc::EventLoop* loop = CommandScheduler::GetInstance() + .GetDefaultButtonLoop()) const; + + /** + * Constructs a Trigger instance around the R3 (right stick) button's + * digital signal. + * + * @param loop the event loop instance to attach the event to. Defaults to the + * CommandScheduler's default loop. + * @return a Trigger instance representing the R3 (right stick) button's + * digital signal attached to the given loop. + */ + Trigger R3(frc::EventLoop* loop = CommandScheduler::GetInstance() + .GetDefaultButtonLoop()) const; + + /** + * Constructs a Trigger instance around the PlayStation button's + * digital signal. + * + * @param loop the event loop instance to attach the event to. Defaults to the + * CommandScheduler's default loop. + * @return a Trigger instance representing the PlayStation button's + * digital signal attached to the given loop. + */ + Trigger PS(frc::EventLoop* loop = CommandScheduler::GetInstance() + .GetDefaultButtonLoop()) const; + + /** + * Constructs a Trigger instance around the touchpad button's + * digital signal. + * + * @param loop the event loop instance to attach the event to. Defaults to the + * CommandScheduler's default loop. + * @return a Trigger instance representing the touchpad button's + * digital signal attached to the given loop. + */ + Trigger Touchpad(frc::EventLoop* loop = CommandScheduler::GetInstance() + .GetDefaultButtonLoop()) const; + + /** + * Get the X axis value of left side of the controller. + * + * @return The axis value. + */ + double GetLeftX() const; + + /** + * Get the Y axis value of left side of the controller. + * + * @return The axis value. + */ + double GetLeftY() const; + + /** + * Get the X axis value of right side of the controller. + * + * @return The axis value. + */ + double GetRightX() const; + + /** + * Get the Y axis value of right side of the controller. + * + * @return The axis value. + */ + double GetRightY() const; + + /** + * Get the left trigger 2 axis value of the controller. Note that this axis is bound + * to the range of [0, 1] as opposed to the usual [-1, 1]. + * + * @return The axis value. + */ + double GetL2Axis() const; + + /** + * Get the right trigger 2 axis value of the controller. Note that this axis is bound + * to the range of [0, 1] as opposed to the usual [-1, 1]. + * + * @return The axis value. + */ + double GetR2Axis() const; + + private: + frc::PS4Controller m_hid; +}; +} // namespace frc2 diff --git a/wpilibNewCommands/src/generated/main/native/include/frc2/command/button/CommandPS5Controller.h b/wpilibNewCommands/src/generated/main/native/include/frc2/command/button/CommandPS5Controller.h new file mode 100644 index 00000000000..a92693ea83f --- /dev/null +++ b/wpilibNewCommands/src/generated/main/native/include/frc2/command/button/CommandPS5Controller.h @@ -0,0 +1,253 @@ +// Copyright (c) FIRST and other WPILib contributors. +// Open Source Software; you can modify and/or share it under the terms of +// the WPILib BSD license file in the root directory of this project. + +// THIS FILE WAS AUTO-GENERATED BY ./wpilibNewCommands/generate_hids.py. DO NOT MODIFY + +#pragma once +#include + +#include "frc2/command/button/Trigger.h" +#include "frc2/command/CommandScheduler.h" +#include "frc2/command/button/CommandGenericHID.h" + +namespace frc2 { +/** + * A version of {@link frc::PS5Controller} with {@link Trigger} factories for + * command-based. + * + * @see frc::PS5Controller + */ +class CommandPS5Controller : public CommandGenericHID { + public: + /** + * Construct an instance of a controller. + * + * @param port The port index on the Driver Station that the controller is + * plugged into. + */ + explicit CommandPS5Controller(int port); + + /** + * Get the underlying GenericHID object. + * + * @return the wrapped GenericHID object + */ + frc::PS5Controller& GetHID(); + + /** + * Constructs a Trigger instance around the square button's + * digital signal. + * + * @param loop the event loop instance to attach the event to. Defaults to the + * CommandScheduler's default loop. + * @return a Trigger instance representing the square button's + * digital signal attached to the given loop. + */ + Trigger Square(frc::EventLoop* loop = CommandScheduler::GetInstance() + .GetDefaultButtonLoop()) const; + + /** + * Constructs a Trigger instance around the cross button's + * digital signal. + * + * @param loop the event loop instance to attach the event to. Defaults to the + * CommandScheduler's default loop. + * @return a Trigger instance representing the cross button's + * digital signal attached to the given loop. + */ + Trigger Cross(frc::EventLoop* loop = CommandScheduler::GetInstance() + .GetDefaultButtonLoop()) const; + + /** + * Constructs a Trigger instance around the circle button's + * digital signal. + * + * @param loop the event loop instance to attach the event to. Defaults to the + * CommandScheduler's default loop. + * @return a Trigger instance representing the circle button's + * digital signal attached to the given loop. + */ + Trigger Circle(frc::EventLoop* loop = CommandScheduler::GetInstance() + .GetDefaultButtonLoop()) const; + + /** + * Constructs a Trigger instance around the triangle button's + * digital signal. + * + * @param loop the event loop instance to attach the event to. Defaults to the + * CommandScheduler's default loop. + * @return a Trigger instance representing the triangle button's + * digital signal attached to the given loop. + */ + Trigger Triangle(frc::EventLoop* loop = CommandScheduler::GetInstance() + .GetDefaultButtonLoop()) const; + + /** + * Constructs a Trigger instance around the left trigger 1 button's + * digital signal. + * + * @param loop the event loop instance to attach the event to. Defaults to the + * CommandScheduler's default loop. + * @return a Trigger instance representing the left trigger 1 button's + * digital signal attached to the given loop. + */ + Trigger L1(frc::EventLoop* loop = CommandScheduler::GetInstance() + .GetDefaultButtonLoop()) const; + + /** + * Constructs a Trigger instance around the right trigger 1 button's + * digital signal. + * + * @param loop the event loop instance to attach the event to. Defaults to the + * CommandScheduler's default loop. + * @return a Trigger instance representing the right trigger 1 button's + * digital signal attached to the given loop. + */ + Trigger R1(frc::EventLoop* loop = CommandScheduler::GetInstance() + .GetDefaultButtonLoop()) const; + + /** + * Constructs a Trigger instance around the left trigger 2 button's + * digital signal. + * + * @param loop the event loop instance to attach the event to. Defaults to the + * CommandScheduler's default loop. + * @return a Trigger instance representing the left trigger 2 button's + * digital signal attached to the given loop. + */ + Trigger L2(frc::EventLoop* loop = CommandScheduler::GetInstance() + .GetDefaultButtonLoop()) const; + + /** + * Constructs a Trigger instance around the right trigger 2 button's + * digital signal. + * + * @param loop the event loop instance to attach the event to. Defaults to the + * CommandScheduler's default loop. + * @return a Trigger instance representing the right trigger 2 button's + * digital signal attached to the given loop. + */ + Trigger R2(frc::EventLoop* loop = CommandScheduler::GetInstance() + .GetDefaultButtonLoop()) const; + + /** + * Constructs a Trigger instance around the create button's + * digital signal. + * + * @param loop the event loop instance to attach the event to. Defaults to the + * CommandScheduler's default loop. + * @return a Trigger instance representing the create button's + * digital signal attached to the given loop. + */ + Trigger Create(frc::EventLoop* loop = CommandScheduler::GetInstance() + .GetDefaultButtonLoop()) const; + + /** + * Constructs a Trigger instance around the options button's + * digital signal. + * + * @param loop the event loop instance to attach the event to. Defaults to the + * CommandScheduler's default loop. + * @return a Trigger instance representing the options button's + * digital signal attached to the given loop. + */ + Trigger Options(frc::EventLoop* loop = CommandScheduler::GetInstance() + .GetDefaultButtonLoop()) const; + + /** + * Constructs a Trigger instance around the L3 (left stick) button's + * digital signal. + * + * @param loop the event loop instance to attach the event to. Defaults to the + * CommandScheduler's default loop. + * @return a Trigger instance representing the L3 (left stick) button's + * digital signal attached to the given loop. + */ + Trigger L3(frc::EventLoop* loop = CommandScheduler::GetInstance() + .GetDefaultButtonLoop()) const; + + /** + * Constructs a Trigger instance around the R3 (right stick) button's + * digital signal. + * + * @param loop the event loop instance to attach the event to. Defaults to the + * CommandScheduler's default loop. + * @return a Trigger instance representing the R3 (right stick) button's + * digital signal attached to the given loop. + */ + Trigger R3(frc::EventLoop* loop = CommandScheduler::GetInstance() + .GetDefaultButtonLoop()) const; + + /** + * Constructs a Trigger instance around the PlayStation button's + * digital signal. + * + * @param loop the event loop instance to attach the event to. Defaults to the + * CommandScheduler's default loop. + * @return a Trigger instance representing the PlayStation button's + * digital signal attached to the given loop. + */ + Trigger PS(frc::EventLoop* loop = CommandScheduler::GetInstance() + .GetDefaultButtonLoop()) const; + + /** + * Constructs a Trigger instance around the touchpad button's + * digital signal. + * + * @param loop the event loop instance to attach the event to. Defaults to the + * CommandScheduler's default loop. + * @return a Trigger instance representing the touchpad button's + * digital signal attached to the given loop. + */ + Trigger Touchpad(frc::EventLoop* loop = CommandScheduler::GetInstance() + .GetDefaultButtonLoop()) const; + + /** + * Get the X axis value of left side of the controller. + * + * @return The axis value. + */ + double GetLeftX() const; + + /** + * Get the Y axis value of left side of the controller. + * + * @return The axis value. + */ + double GetLeftY() const; + + /** + * Get the X axis value of right side of the controller. + * + * @return The axis value. + */ + double GetRightX() const; + + /** + * Get the Y axis value of right side of the controller. + * + * @return The axis value. + */ + double GetRightY() const; + + /** + * Get the left trigger 2 axis value of the controller. Note that this axis is bound + * to the range of [0, 1] as opposed to the usual [-1, 1]. + * + * @return The axis value. + */ + double GetL2Axis() const; + + /** + * Get the right trigger 2 axis value of the controller. Note that this axis is bound + * to the range of [0, 1] as opposed to the usual [-1, 1]. + * + * @return The axis value. + */ + double GetR2Axis() const; + + private: + frc::PS5Controller m_hid; +}; +} // namespace frc2 diff --git a/wpilibNewCommands/src/generated/main/native/include/frc2/command/button/CommandStadiaController.h b/wpilibNewCommands/src/generated/main/native/include/frc2/command/button/CommandStadiaController.h new file mode 100644 index 00000000000..cbd89c2adad --- /dev/null +++ b/wpilibNewCommands/src/generated/main/native/include/frc2/command/button/CommandStadiaController.h @@ -0,0 +1,249 @@ +// Copyright (c) FIRST and other WPILib contributors. +// Open Source Software; you can modify and/or share it under the terms of +// the WPILib BSD license file in the root directory of this project. + +// THIS FILE WAS AUTO-GENERATED BY ./wpilibNewCommands/generate_hids.py. DO NOT MODIFY + +#pragma once +#include + +#include "frc2/command/button/Trigger.h" +#include "frc2/command/CommandScheduler.h" +#include "frc2/command/button/CommandGenericHID.h" + +namespace frc2 { +/** + * A version of {@link frc::StadiaController} with {@link Trigger} factories for + * command-based. + * + * @see frc::StadiaController + */ +class CommandStadiaController : public CommandGenericHID { + public: + /** + * Construct an instance of a controller. + * + * @param port The port index on the Driver Station that the controller is + * plugged into. + */ + explicit CommandStadiaController(int port); + + /** + * Get the underlying GenericHID object. + * + * @return the wrapped GenericHID object + */ + frc::StadiaController& GetHID(); + + /** + * Constructs a Trigger instance around the A button's + * digital signal. + * + * @param loop the event loop instance to attach the event to. Defaults to the + * CommandScheduler's default loop. + * @return a Trigger instance representing the A button's + * digital signal attached to the given loop. + */ + Trigger A(frc::EventLoop* loop = CommandScheduler::GetInstance() + .GetDefaultButtonLoop()) const; + + /** + * Constructs a Trigger instance around the B button's + * digital signal. + * + * @param loop the event loop instance to attach the event to. Defaults to the + * CommandScheduler's default loop. + * @return a Trigger instance representing the B button's + * digital signal attached to the given loop. + */ + Trigger B(frc::EventLoop* loop = CommandScheduler::GetInstance() + .GetDefaultButtonLoop()) const; + + /** + * Constructs a Trigger instance around the X button's + * digital signal. + * + * @param loop the event loop instance to attach the event to. Defaults to the + * CommandScheduler's default loop. + * @return a Trigger instance representing the X button's + * digital signal attached to the given loop. + */ + Trigger X(frc::EventLoop* loop = CommandScheduler::GetInstance() + .GetDefaultButtonLoop()) const; + + /** + * Constructs a Trigger instance around the Y button's + * digital signal. + * + * @param loop the event loop instance to attach the event to. Defaults to the + * CommandScheduler's default loop. + * @return a Trigger instance representing the Y button's + * digital signal attached to the given loop. + */ + Trigger Y(frc::EventLoop* loop = CommandScheduler::GetInstance() + .GetDefaultButtonLoop()) const; + + /** + * Constructs a Trigger instance around the left bumper button's + * digital signal. + * + * @param loop the event loop instance to attach the event to. Defaults to the + * CommandScheduler's default loop. + * @return a Trigger instance representing the left bumper button's + * digital signal attached to the given loop. + */ + Trigger LeftBumper(frc::EventLoop* loop = CommandScheduler::GetInstance() + .GetDefaultButtonLoop()) const; + + /** + * Constructs a Trigger instance around the right bumper button's + * digital signal. + * + * @param loop the event loop instance to attach the event to. Defaults to the + * CommandScheduler's default loop. + * @return a Trigger instance representing the right bumper button's + * digital signal attached to the given loop. + */ + Trigger RightBumper(frc::EventLoop* loop = CommandScheduler::GetInstance() + .GetDefaultButtonLoop()) const; + + /** + * Constructs a Trigger instance around the left stick button's + * digital signal. + * + * @param loop the event loop instance to attach the event to. Defaults to the + * CommandScheduler's default loop. + * @return a Trigger instance representing the left stick button's + * digital signal attached to the given loop. + */ + Trigger LeftStick(frc::EventLoop* loop = CommandScheduler::GetInstance() + .GetDefaultButtonLoop()) const; + + /** + * Constructs a Trigger instance around the right stick button's + * digital signal. + * + * @param loop the event loop instance to attach the event to. Defaults to the + * CommandScheduler's default loop. + * @return a Trigger instance representing the right stick button's + * digital signal attached to the given loop. + */ + Trigger RightStick(frc::EventLoop* loop = CommandScheduler::GetInstance() + .GetDefaultButtonLoop()) const; + + /** + * Constructs a Trigger instance around the ellipses button's + * digital signal. + * + * @param loop the event loop instance to attach the event to. Defaults to the + * CommandScheduler's default loop. + * @return a Trigger instance representing the ellipses button's + * digital signal attached to the given loop. + */ + Trigger Ellipses(frc::EventLoop* loop = CommandScheduler::GetInstance() + .GetDefaultButtonLoop()) const; + + /** + * Constructs a Trigger instance around the hamburger button's + * digital signal. + * + * @param loop the event loop instance to attach the event to. Defaults to the + * CommandScheduler's default loop. + * @return a Trigger instance representing the hamburger button's + * digital signal attached to the given loop. + */ + Trigger Hamburger(frc::EventLoop* loop = CommandScheduler::GetInstance() + .GetDefaultButtonLoop()) const; + + /** + * Constructs a Trigger instance around the stadia button's + * digital signal. + * + * @param loop the event loop instance to attach the event to. Defaults to the + * CommandScheduler's default loop. + * @return a Trigger instance representing the stadia button's + * digital signal attached to the given loop. + */ + Trigger Stadia(frc::EventLoop* loop = CommandScheduler::GetInstance() + .GetDefaultButtonLoop()) const; + + /** + * Constructs a Trigger instance around the right trigger button's + * digital signal. + * + * @param loop the event loop instance to attach the event to. Defaults to the + * CommandScheduler's default loop. + * @return a Trigger instance representing the right trigger button's + * digital signal attached to the given loop. + */ + Trigger RightTrigger(frc::EventLoop* loop = CommandScheduler::GetInstance() + .GetDefaultButtonLoop()) const; + + /** + * Constructs a Trigger instance around the left trigger button's + * digital signal. + * + * @param loop the event loop instance to attach the event to. Defaults to the + * CommandScheduler's default loop. + * @return a Trigger instance representing the left trigger button's + * digital signal attached to the given loop. + */ + Trigger LeftTrigger(frc::EventLoop* loop = CommandScheduler::GetInstance() + .GetDefaultButtonLoop()) const; + + /** + * Constructs a Trigger instance around the google button's + * digital signal. + * + * @param loop the event loop instance to attach the event to. Defaults to the + * CommandScheduler's default loop. + * @return a Trigger instance representing the google button's + * digital signal attached to the given loop. + */ + Trigger Google(frc::EventLoop* loop = CommandScheduler::GetInstance() + .GetDefaultButtonLoop()) const; + + /** + * Constructs a Trigger instance around the frame button's + * digital signal. + * + * @param loop the event loop instance to attach the event to. Defaults to the + * CommandScheduler's default loop. + * @return a Trigger instance representing the frame button's + * digital signal attached to the given loop. + */ + Trigger Frame(frc::EventLoop* loop = CommandScheduler::GetInstance() + .GetDefaultButtonLoop()) const; + + /** + * Get the X axis value of left side of the controller. + * + * @return The axis value. + */ + double GetLeftX() const; + + /** + * Get the X axis value of right side of the controller. + * + * @return The axis value. + */ + double GetRightX() const; + + /** + * Get the Y axis value of left side of the controller. + * + * @return The axis value. + */ + double GetLeftY() const; + + /** + * Get the Y axis value of right side of the controller. + * + * @return The axis value. + */ + double GetRightY() const; + + private: + frc::StadiaController m_hid; +}; +} // namespace frc2 diff --git a/wpilibNewCommands/src/main/native/include/frc2/command/button/CommandXboxController.h b/wpilibNewCommands/src/generated/main/native/include/frc2/command/button/CommandXboxController.h similarity index 58% rename from wpilibNewCommands/src/main/native/include/frc2/command/button/CommandXboxController.h rename to wpilibNewCommands/src/generated/main/native/include/frc2/command/button/CommandXboxController.h index 3b43d97dd66..9fb94f48254 100644 --- a/wpilibNewCommands/src/main/native/include/frc2/command/button/CommandXboxController.h +++ b/wpilibNewCommands/src/generated/main/native/include/frc2/command/button/CommandXboxController.h @@ -2,10 +2,12 @@ // Open Source Software; you can modify and/or share it under the terms of // the WPILib BSD license file in the root directory of this project. +// THIS FILE WAS AUTO-GENERATED BY ./wpilibNewCommands/generate_hids.py. DO NOT MODIFY + #pragma once #include -#include "Trigger.h" +#include "frc2/command/button/Trigger.h" #include "frc2/command/CommandScheduler.h" #include "frc2/command/button/CommandGenericHID.h" @@ -34,114 +36,124 @@ class CommandXboxController : public CommandGenericHID { frc::XboxController& GetHID(); /** - * Constructs an event instance around the left bumper's digital signal. + * Constructs a Trigger instance around the A button's + * digital signal. * * @param loop the event loop instance to attach the event to. Defaults to the * CommandScheduler's default loop. - * @return an event instance representing the left bumper's digital signal - * attached to the given loop. + * @return a Trigger instance representing the A button's + * digital signal attached to the given loop. */ - Trigger LeftBumper(frc::EventLoop* loop = CommandScheduler::GetInstance() + Trigger A(frc::EventLoop* loop = CommandScheduler::GetInstance() .GetDefaultButtonLoop()) const; /** - * Constructs an event instance around the right bumper's digital signal. + * Constructs a Trigger instance around the B button's + * digital signal. * * @param loop the event loop instance to attach the event to. Defaults to the * CommandScheduler's default loop. - * @return an event instance representing the right bumper's digital signal - * attached to the given loop. + * @return a Trigger instance representing the B button's + * digital signal attached to the given loop. */ - Trigger RightBumper(frc::EventLoop* loop = CommandScheduler::GetInstance() - .GetDefaultButtonLoop()) const; + Trigger B(frc::EventLoop* loop = CommandScheduler::GetInstance() + .GetDefaultButtonLoop()) const; /** - * Constructs an event instance around the left stick's digital signal. + * Constructs a Trigger instance around the X button's + * digital signal. * * @param loop the event loop instance to attach the event to. Defaults to the * CommandScheduler's default loop. - * @return an event instance representing the left stick's digital signal - * attached to the given loop. + * @return a Trigger instance representing the X button's + * digital signal attached to the given loop. */ - Trigger LeftStick(frc::EventLoop* loop = CommandScheduler::GetInstance() - .GetDefaultButtonLoop()) const; + Trigger X(frc::EventLoop* loop = CommandScheduler::GetInstance() + .GetDefaultButtonLoop()) const; /** - * Constructs an event instance around the right stick's digital signal. + * Constructs a Trigger instance around the Y button's + * digital signal. * * @param loop the event loop instance to attach the event to. Defaults to the * CommandScheduler's default loop. - * @return an event instance representing the right stick's digital signal - * attached to the given loop. + * @return a Trigger instance representing the Y button's + * digital signal attached to the given loop. */ - Trigger RightStick(frc::EventLoop* loop = CommandScheduler::GetInstance() + Trigger Y(frc::EventLoop* loop = CommandScheduler::GetInstance() .GetDefaultButtonLoop()) const; /** - * Constructs an event instance around the A button's digital signal. + * Constructs a Trigger instance around the left bumper button's + * digital signal. * * @param loop the event loop instance to attach the event to. Defaults to the * CommandScheduler's default loop. - * @return an event instance representing the A button's digital signal - * attached to the given loop. + * @return a Trigger instance representing the left bumper button's + * digital signal attached to the given loop. */ - Trigger A(frc::EventLoop* loop = - CommandScheduler::GetInstance().GetDefaultButtonLoop()) const; + Trigger LeftBumper(frc::EventLoop* loop = CommandScheduler::GetInstance() + .GetDefaultButtonLoop()) const; /** - * Constructs an event instance around the B button's digital signal. + * Constructs a Trigger instance around the right bumper button's + * digital signal. * * @param loop the event loop instance to attach the event to. Defaults to the * CommandScheduler's default loop. - * @return an event instance representing the B button's digital signal - * attached to the given loop. + * @return a Trigger instance representing the right bumper button's + * digital signal attached to the given loop. */ - Trigger B(frc::EventLoop* loop = - CommandScheduler::GetInstance().GetDefaultButtonLoop()) const; + Trigger RightBumper(frc::EventLoop* loop = CommandScheduler::GetInstance() + .GetDefaultButtonLoop()) const; /** - * Constructs an event instance around the X button's digital signal. + * Constructs a Trigger instance around the back button's + * digital signal. * * @param loop the event loop instance to attach the event to. Defaults to the * CommandScheduler's default loop. - * @return an event instance representing the X button's digital signal - * attached to the given loop. + * @return a Trigger instance representing the back button's + * digital signal attached to the given loop. */ - Trigger X(frc::EventLoop* loop = - CommandScheduler::GetInstance().GetDefaultButtonLoop()) const; + Trigger Back(frc::EventLoop* loop = CommandScheduler::GetInstance() + .GetDefaultButtonLoop()) const; /** - * Constructs an event instance around the Y button's digital signal. + * Constructs a Trigger instance around the start button's + * digital signal. * * @param loop the event loop instance to attach the event to. Defaults to the * CommandScheduler's default loop. - * @return an event instance representing the Y button's digital signal - * attached to the given loop. + * @return a Trigger instance representing the start button's + * digital signal attached to the given loop. */ - Trigger Y(frc::EventLoop* loop = - CommandScheduler::GetInstance().GetDefaultButtonLoop()) const; + Trigger Start(frc::EventLoop* loop = CommandScheduler::GetInstance() + .GetDefaultButtonLoop()) const; /** - * Constructs an event instance around the back button's digital signal. + * Constructs a Trigger instance around the left stick button's + * digital signal. * * @param loop the event loop instance to attach the event to. Defaults to the * CommandScheduler's default loop. - * @return an event instance representing the back button's digital signal - * attached to the given loop. + * @return a Trigger instance representing the left stick button's + * digital signal attached to the given loop. */ - Trigger Back(frc::EventLoop* loop = CommandScheduler::GetInstance() - .GetDefaultButtonLoop()) const; + Trigger LeftStick(frc::EventLoop* loop = CommandScheduler::GetInstance() + .GetDefaultButtonLoop()) const; /** - * Constructs an event instance around the start button's digital signal. + * Constructs a Trigger instance around the right stick button's + * digital signal. * * @param loop the event loop instance to attach the event to. Defaults to the * CommandScheduler's default loop. - * @return an event instance representing the start button's digital signal - * attached to the given loop. + * @return a Trigger instance representing the right stick button's + * digital signal attached to the given loop. */ - Trigger Start(frc::EventLoop* loop = CommandScheduler::GetInstance() - .GetDefaultButtonLoop()) const; + Trigger RightStick(frc::EventLoop* loop = CommandScheduler::GetInstance() + .GetDefaultButtonLoop()) const; /** * Constructs a Trigger instance around the axis value of the left trigger. @@ -173,54 +185,53 @@ class CommandXboxController : public CommandGenericHID { * @return a Trigger instance that is true when the right trigger's axis * exceeds the provided threshold, attached to the given loop */ - Trigger RightTrigger( - double threshold = 0.5, - frc::EventLoop* loop = - CommandScheduler::GetInstance().GetDefaultButtonLoop()) const; + Trigger RightTrigger(double threshold = 0.5, + frc::EventLoop* loop = CommandScheduler::GetInstance() + .GetDefaultButtonLoop()) const; /** - * Get the right trigger (RT) axis value of the controller. Note that this - * axis is bound to the range of [0, 1] as opposed to the usual [-1, 1]. + * Get the X axis value of left side of the controller. * * @return The axis value. */ - double GetRightTriggerAxis(); + double GetLeftX() const; /** - * Get the left trigger (LT) axis value of the controller. Note that this axis - * is bound to the range of [0, 1] as opposed to the usual [-1, 1]. + * Get the X axis value of right side of the controller. * * @return The axis value. */ - double GetLeftTriggerAxis(); + double GetRightX() const; /** - * Get the Y axis value of right side of the controller. + * Get the Y axis value of left side of the controller. * * @return The axis value. */ - double GetRightY(); + double GetLeftY() const; /** - * Get the Y axis value of left side of the controller. + * Get the Y axis value of right side of the controller. * * @return The axis value. */ - double GetLeftY(); + double GetRightY() const; /** - * Get the X axis value of right side of the controller. + * Get the left trigger axis value of the controller. Note that this axis is bound + * to the range of [0, 1] as opposed to the usual [-1, 1]. * * @return The axis value. */ - double GetRightX(); + double GetLeftTriggerAxis() const; /** - * Get the X axis value of left side of the controller. + * Get the right trigger axis value of the controller. Note that this axis is bound + * to the range of [0, 1] as opposed to the usual [-1, 1]. * * @return The axis value. */ - double GetLeftX(); + double GetRightTriggerAxis() const; private: frc::XboxController m_hid; diff --git a/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/ParallelRaceGroup.java b/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/ParallelRaceGroup.java index f2ff29920d7..39fe6114b41 100644 --- a/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/ParallelRaceGroup.java +++ b/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/ParallelRaceGroup.java @@ -41,6 +41,7 @@ public ParallelRaceGroup(Command... commands) { * * @param commands Commands to add to the group. */ + @SuppressWarnings("PMD.UseArraysAsList") public final void addCommands(Command... commands) { if (!m_finished) { throw new IllegalStateException( diff --git a/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/SequentialCommandGroup.java b/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/SequentialCommandGroup.java index c3598cb04c3..87805972c38 100644 --- a/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/SequentialCommandGroup.java +++ b/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/SequentialCommandGroup.java @@ -38,6 +38,7 @@ public SequentialCommandGroup(Command... commands) { * * @param commands Commands to add, in order of execution. */ + @SuppressWarnings("PMD.UseArraysAsList") public final void addCommands(Command... commands) { if (m_currentCommandIndex != -1) { throw new IllegalStateException( diff --git a/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/button/CommandPS4Controller.java b/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/button/CommandPS4Controller.java deleted file mode 100644 index a7c0ac7c211..00000000000 --- a/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/button/CommandPS4Controller.java +++ /dev/null @@ -1,389 +0,0 @@ -// Copyright (c) FIRST and other WPILib contributors. -// Open Source Software; you can modify and/or share it under the terms of -// the WPILib BSD license file in the root directory of this project. - -package edu.wpi.first.wpilibj2.command.button; - -import edu.wpi.first.wpilibj.PS4Controller; -import edu.wpi.first.wpilibj.event.EventLoop; -import edu.wpi.first.wpilibj2.command.CommandScheduler; - -/** - * A version of {@link PS4Controller} with {@link Trigger} factories for command-based. - * - * @see PS4Controller - */ -@SuppressWarnings("MethodName") -public class CommandPS4Controller extends CommandGenericHID { - private final PS4Controller m_hid; - - /** - * Construct an instance of a device. - * - * @param port The port index on the Driver Station that the device is plugged into. - */ - public CommandPS4Controller(int port) { - super(port); - m_hid = new PS4Controller(port); - } - - /** - * Get the underlying GenericHID object. - * - * @return the wrapped GenericHID object - */ - @Override - public PS4Controller getHID() { - return m_hid; - } - - /** - * Constructs an event instance around the L2 button's digital signal. - * - * @return an event instance representing the L2 button's digital signal attached to the {@link - * CommandScheduler#getDefaultButtonLoop() default scheduler button loop}. - */ - public Trigger L2() { - return L2(CommandScheduler.getInstance().getDefaultButtonLoop()); - } - - /** - * Constructs an event instance around the L2 button's digital signal. - * - * @param loop the event loop instance to attach the event to. - * @return an event instance representing the L2 button's digital signal attached to the given - * loop. - */ - public Trigger L2(EventLoop loop) { - return m_hid.L2(loop).castTo(Trigger::new); - } - - /** - * Constructs an event instance around the R2 button's digital signal. - * - * @return an event instance representing the R2 button's digital signal attached to the {@link - * CommandScheduler#getDefaultButtonLoop() default scheduler button loop}. - */ - public Trigger R2() { - return R2(CommandScheduler.getInstance().getDefaultButtonLoop()); - } - - /** - * Constructs an event instance around the R2 button's digital signal. - * - * @param loop the event loop instance to attach the event to. - * @return an event instance representing the R2 button's digital signal attached to the given - * loop. - */ - public Trigger R2(EventLoop loop) { - return m_hid.R2(loop).castTo(Trigger::new); - } - - /** - * Constructs an event instance around the L1 button's digital signal. - * - * @return an event instance representing the L1 button's digital signal attached to the {@link - * CommandScheduler#getDefaultButtonLoop() default scheduler button loop}. - */ - public Trigger L1() { - return L1(CommandScheduler.getInstance().getDefaultButtonLoop()); - } - - /** - * Constructs an event instance around the L1 button's digital signal. - * - * @param loop the event loop instance to attach the event to. - * @return an event instance representing the L1 button's digital signal attached to the given - * loop. - */ - public Trigger L1(EventLoop loop) { - return m_hid.L1(loop).castTo(Trigger::new); - } - - /** - * Constructs an event instance around the R1 button's digital signal. - * - * @return an event instance representing the R1 button's digital signal attached to the {@link - * CommandScheduler#getDefaultButtonLoop() default scheduler button loop}. - */ - public Trigger R1() { - return R1(CommandScheduler.getInstance().getDefaultButtonLoop()); - } - - /** - * Constructs an event instance around the R1 button's digital signal. - * - * @param loop the event loop instance to attach the event to. - * @return an event instance representing the R1 button's digital signal attached to the given - * loop. - */ - public Trigger R1(EventLoop loop) { - return m_hid.R1(loop).castTo(Trigger::new); - } - - /** - * Constructs an event instance around the L3 button's digital signal. - * - * @return an event instance representing the L3 button's digital signal attached to the {@link - * CommandScheduler#getDefaultButtonLoop() default scheduler button loop}. - */ - public Trigger L3() { - return L3(CommandScheduler.getInstance().getDefaultButtonLoop()); - } - - /** - * Constructs an event instance around the L3 button's digital signal. - * - * @param loop the event loop instance to attach the event to. - * @return an event instance representing the L3 button's digital signal attached to the given - * loop. - */ - public Trigger L3(EventLoop loop) { - return m_hid.L3(loop).castTo(Trigger::new); - } - - /** - * Constructs an event instance around the R3 button's digital signal. - * - * @return an event instance representing the R3 button's digital signal attached to the {@link - * CommandScheduler#getDefaultButtonLoop() default scheduler button loop}. - */ - public Trigger R3() { - return R3(CommandScheduler.getInstance().getDefaultButtonLoop()); - } - - /** - * Constructs an event instance around the R3 button's digital signal. - * - * @param loop the event loop instance to attach the event to. - * @return an event instance representing the R3 button's digital signal attached to the given - * loop. - */ - public Trigger R3(EventLoop loop) { - return m_hid.R3(loop).castTo(Trigger::new); - } - - /** - * Constructs an event instance around the square button's digital signal. - * - * @return an event instance representing the square button's digital signal attached to the - * {@link CommandScheduler#getDefaultButtonLoop() default scheduler button loop}. - */ - public Trigger square() { - return square(CommandScheduler.getInstance().getDefaultButtonLoop()); - } - - /** - * Constructs an event instance around the square button's digital signal. - * - * @param loop the event loop instance to attach the event to. - * @return an event instance representing the square button's digital signal attached to the given - * loop. - */ - public Trigger square(EventLoop loop) { - return m_hid.square(loop).castTo(Trigger::new); - } - - /** - * Constructs an event instance around the cross button's digital signal. - * - * @return an event instance representing the cross button's digital signal attached to the {@link - * CommandScheduler#getDefaultButtonLoop() default scheduler button loop}. - */ - public Trigger cross() { - return cross(CommandScheduler.getInstance().getDefaultButtonLoop()); - } - - /** - * Constructs an event instance around the cross button's digital signal. - * - * @param loop the event loop instance to attach the event to. - * @return an event instance representing the cross button's digital signal attached to the given - * loop. - */ - public Trigger cross(EventLoop loop) { - return m_hid.cross(loop).castTo(Trigger::new); - } - - /** - * Constructs an event instance around the triangle button's digital signal. - * - * @return an event instance representing the triangle button's digital signal attached to the - * {@link CommandScheduler#getDefaultButtonLoop() default scheduler button loop}. - */ - public Trigger triangle() { - return triangle(CommandScheduler.getInstance().getDefaultButtonLoop()); - } - - /** - * Constructs an event instance around the triangle button's digital signal. - * - * @param loop the event loop instance to attach the event to. - * @return an event instance representing the triangle button's digital signal attached to the - * given loop. - */ - public Trigger triangle(EventLoop loop) { - return m_hid.triangle(loop).castTo(Trigger::new); - } - - /** - * Constructs an event instance around the circle button's digital signal. - * - * @return an event instance representing the circle button's digital signal attached to the - * {@link CommandScheduler#getDefaultButtonLoop() default scheduler button loop}. - */ - public Trigger circle() { - return circle(CommandScheduler.getInstance().getDefaultButtonLoop()); - } - - /** - * Constructs an event instance around the circle button's digital signal. - * - * @param loop the event loop instance to attach the event to. - * @return an event instance representing the circle button's digital signal attached to the given - * loop. - */ - public Trigger circle(EventLoop loop) { - return m_hid.circle(loop).castTo(Trigger::new); - } - - /** - * Constructs an event instance around the share button's digital signal. - * - * @return an event instance representing the share button's digital signal attached to the {@link - * CommandScheduler#getDefaultButtonLoop() default scheduler button loop}. - */ - public Trigger share() { - return share(CommandScheduler.getInstance().getDefaultButtonLoop()); - } - - /** - * Constructs an event instance around the share button's digital signal. - * - * @param loop the event loop instance to attach the event to. - * @return an event instance representing the share button's digital signal attached to the given - * loop. - */ - public Trigger share(EventLoop loop) { - return m_hid.share(loop).castTo(Trigger::new); - } - - /** - * Constructs an event instance around the PS button's digital signal. - * - * @return an event instance representing the PS button's digital signal attached to the {@link - * CommandScheduler#getDefaultButtonLoop() default scheduler button loop}. - */ - public Trigger PS() { - return PS(CommandScheduler.getInstance().getDefaultButtonLoop()); - } - - /** - * Constructs an event instance around the PS button's digital signal. - * - * @param loop the event loop instance to attach the event to. - * @return an event instance representing the PS button's digital signal attached to the given - * loop. - */ - public Trigger PS(EventLoop loop) { - return m_hid.PS(loop).castTo(Trigger::new); - } - - /** - * Constructs an event instance around the options button's digital signal. - * - * @return an event instance representing the options button's digital signal attached to the - * {@link CommandScheduler#getDefaultButtonLoop() default scheduler button loop}. - */ - public Trigger options() { - return options(CommandScheduler.getInstance().getDefaultButtonLoop()); - } - - /** - * Constructs an event instance around the options button's digital signal. - * - * @param loop the event loop instance to attach the event to. - * @return an event instance representing the options button's digital signal attached to the - * given loop. - */ - public Trigger options(EventLoop loop) { - return m_hid.options(loop).castTo(Trigger::new); - } - - /** - * Constructs an event instance around the touchpad's digital signal. - * - * @return an event instance representing the touchpad's digital signal attached to the {@link - * CommandScheduler#getDefaultButtonLoop() default scheduler button loop}. - */ - public Trigger touchpad() { - return touchpad(CommandScheduler.getInstance().getDefaultButtonLoop()); - } - - /** - * Constructs an event instance around the touchpad's digital signal. - * - * @param loop the event loop instance to attach the event to. - * @return an event instance representing the touchpad's digital signal attached to the given - * loop. - */ - public Trigger touchpad(EventLoop loop) { - return m_hid.touchpad(loop).castTo(Trigger::new); - } - - /** - * Get the X axis value of left side of the controller. - * - * @return the axis value. - */ - public double getLeftX() { - return m_hid.getLeftX(); - } - - /** - * Get the X axis value of right side of the controller. - * - * @return the axis value. - */ - public double getRightX() { - return m_hid.getRightX(); - } - - /** - * Get the Y axis value of left side of the controller. - * - * @return the axis value. - */ - public double getLeftY() { - return m_hid.getLeftY(); - } - - /** - * Get the Y axis value of right side of the controller. - * - * @return the axis value. - */ - public double getRightY() { - return m_hid.getRightY(); - } - - /** - * Get the L2 axis value of the controller. Note that this axis is bound to the range of [0, 1] as - * opposed to the usual [-1, 1]. - * - * @return the axis value. - */ - public double getL2Axis() { - return m_hid.getL2Axis(); - } - - /** - * Get the R2 axis value of the controller. Note that this axis is bound to the range of [0, 1] as - * opposed to the usual [-1, 1]. - * - * @return the axis value. - */ - public double getR2Axis() { - return m_hid.getR2Axis(); - } -} diff --git a/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/button/CommandPS5Controller.java b/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/button/CommandPS5Controller.java deleted file mode 100644 index 6b149d62b4b..00000000000 --- a/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/button/CommandPS5Controller.java +++ /dev/null @@ -1,389 +0,0 @@ -// Copyright (c) FIRST and other WPILib contributors. -// Open Source Software; you can modify and/or share it under the terms of -// the WPILib BSD license file in the root directory of this project. - -package edu.wpi.first.wpilibj2.command.button; - -import edu.wpi.first.wpilibj.PS5Controller; -import edu.wpi.first.wpilibj.event.EventLoop; -import edu.wpi.first.wpilibj2.command.CommandScheduler; - -/** - * A version of {@link PS5Controller} with {@link Trigger} factories for command-based. - * - * @see PS5Controller - */ -@SuppressWarnings("MethodName") -public class CommandPS5Controller extends CommandGenericHID { - private final PS5Controller m_hid; - - /** - * Construct an instance of a device. - * - * @param port The port index on the Driver Station that the device is plugged into. - */ - public CommandPS5Controller(int port) { - super(port); - m_hid = new PS5Controller(port); - } - - /** - * Get the underlying GenericHID object. - * - * @return the wrapped GenericHID object - */ - @Override - public PS5Controller getHID() { - return m_hid; - } - - /** - * Constructs an event instance around the L2 button's digital signal. - * - * @return an event instance representing the L2 button's digital signal attached to the {@link - * CommandScheduler#getDefaultButtonLoop() default scheduler button loop}. - */ - public Trigger L2() { - return L2(CommandScheduler.getInstance().getDefaultButtonLoop()); - } - - /** - * Constructs an event instance around the L2 button's digital signal. - * - * @param loop the event loop instance to attach the event to. - * @return an event instance representing the L2 button's digital signal attached to the given - * loop. - */ - public Trigger L2(EventLoop loop) { - return m_hid.L2(loop).castTo(Trigger::new); - } - - /** - * Constructs an event instance around the R2 button's digital signal. - * - * @return an event instance representing the R2 button's digital signal attached to the {@link - * CommandScheduler#getDefaultButtonLoop() default scheduler button loop}. - */ - public Trigger R2() { - return R2(CommandScheduler.getInstance().getDefaultButtonLoop()); - } - - /** - * Constructs an event instance around the R2 button's digital signal. - * - * @param loop the event loop instance to attach the event to. - * @return an event instance representing the R2 button's digital signal attached to the given - * loop. - */ - public Trigger R2(EventLoop loop) { - return m_hid.R2(loop).castTo(Trigger::new); - } - - /** - * Constructs an event instance around the L1 button's digital signal. - * - * @return an event instance representing the L1 button's digital signal attached to the {@link - * CommandScheduler#getDefaultButtonLoop() default scheduler button loop}. - */ - public Trigger L1() { - return L1(CommandScheduler.getInstance().getDefaultButtonLoop()); - } - - /** - * Constructs an event instance around the L1 button's digital signal. - * - * @param loop the event loop instance to attach the event to. - * @return an event instance representing the L1 button's digital signal attached to the given - * loop. - */ - public Trigger L1(EventLoop loop) { - return m_hid.L1(loop).castTo(Trigger::new); - } - - /** - * Constructs an event instance around the R1 button's digital signal. - * - * @return an event instance representing the R1 button's digital signal attached to the {@link - * CommandScheduler#getDefaultButtonLoop() default scheduler button loop}. - */ - public Trigger R1() { - return R1(CommandScheduler.getInstance().getDefaultButtonLoop()); - } - - /** - * Constructs an event instance around the R1 button's digital signal. - * - * @param loop the event loop instance to attach the event to. - * @return an event instance representing the R1 button's digital signal attached to the given - * loop. - */ - public Trigger R1(EventLoop loop) { - return m_hid.R1(loop).castTo(Trigger::new); - } - - /** - * Constructs an event instance around the L3 button's digital signal. - * - * @return an event instance representing the L3 button's digital signal attached to the {@link - * CommandScheduler#getDefaultButtonLoop() default scheduler button loop}. - */ - public Trigger L3() { - return L3(CommandScheduler.getInstance().getDefaultButtonLoop()); - } - - /** - * Constructs an event instance around the L3 button's digital signal. - * - * @param loop the event loop instance to attach the event to. - * @return an event instance representing the L3 button's digital signal attached to the given - * loop. - */ - public Trigger L3(EventLoop loop) { - return m_hid.L3(loop).castTo(Trigger::new); - } - - /** - * Constructs an event instance around the R3 button's digital signal. - * - * @return an event instance representing the R3 button's digital signal attached to the {@link - * CommandScheduler#getDefaultButtonLoop() default scheduler button loop}. - */ - public Trigger R3() { - return R3(CommandScheduler.getInstance().getDefaultButtonLoop()); - } - - /** - * Constructs an event instance around the R3 button's digital signal. - * - * @param loop the event loop instance to attach the event to. - * @return an event instance representing the R3 button's digital signal attached to the given - * loop. - */ - public Trigger R3(EventLoop loop) { - return m_hid.R3(loop).castTo(Trigger::new); - } - - /** - * Constructs an event instance around the square button's digital signal. - * - * @return an event instance representing the square button's digital signal attached to the - * {@link CommandScheduler#getDefaultButtonLoop() default scheduler button loop}. - */ - public Trigger square() { - return square(CommandScheduler.getInstance().getDefaultButtonLoop()); - } - - /** - * Constructs an event instance around the square button's digital signal. - * - * @param loop the event loop instance to attach the event to. - * @return an event instance representing the square button's digital signal attached to the given - * loop. - */ - public Trigger square(EventLoop loop) { - return m_hid.square(loop).castTo(Trigger::new); - } - - /** - * Constructs an event instance around the cross button's digital signal. - * - * @return an event instance representing the cross button's digital signal attached to the {@link - * CommandScheduler#getDefaultButtonLoop() default scheduler button loop}. - */ - public Trigger cross() { - return cross(CommandScheduler.getInstance().getDefaultButtonLoop()); - } - - /** - * Constructs an event instance around the cross button's digital signal. - * - * @param loop the event loop instance to attach the event to. - * @return an event instance representing the cross button's digital signal attached to the given - * loop. - */ - public Trigger cross(EventLoop loop) { - return m_hid.cross(loop).castTo(Trigger::new); - } - - /** - * Constructs an event instance around the triangle button's digital signal. - * - * @return an event instance representing the triangle button's digital signal attached to the - * {@link CommandScheduler#getDefaultButtonLoop() default scheduler button loop}. - */ - public Trigger triangle() { - return triangle(CommandScheduler.getInstance().getDefaultButtonLoop()); - } - - /** - * Constructs an event instance around the triangle button's digital signal. - * - * @param loop the event loop instance to attach the event to. - * @return an event instance representing the triangle button's digital signal attached to the - * given loop. - */ - public Trigger triangle(EventLoop loop) { - return m_hid.triangle(loop).castTo(Trigger::new); - } - - /** - * Constructs an event instance around the circle button's digital signal. - * - * @return an event instance representing the circle button's digital signal attached to the - * {@link CommandScheduler#getDefaultButtonLoop() default scheduler button loop}. - */ - public Trigger circle() { - return circle(CommandScheduler.getInstance().getDefaultButtonLoop()); - } - - /** - * Constructs an event instance around the circle button's digital signal. - * - * @param loop the event loop instance to attach the event to. - * @return an event instance representing the circle button's digital signal attached to the given - * loop. - */ - public Trigger circle(EventLoop loop) { - return m_hid.circle(loop).castTo(Trigger::new); - } - - /** - * Constructs an event instance around the create button's digital signal. - * - * @return an event instance representing the create button's digital signal attached to the - * {@link CommandScheduler#getDefaultButtonLoop() default scheduler button loop}. - */ - public Trigger create() { - return create(CommandScheduler.getInstance().getDefaultButtonLoop()); - } - - /** - * Constructs an event instance around the create button's digital signal. - * - * @param loop the event loop instance to attach the event to. - * @return an event instance representing the create button's digital signal attached to the given - * loop. - */ - public Trigger create(EventLoop loop) { - return m_hid.create(loop).castTo(Trigger::new); - } - - /** - * Constructs an event instance around the PS button's digital signal. - * - * @return an event instance representing the PS button's digital signal attached to the {@link - * CommandScheduler#getDefaultButtonLoop() default scheduler button loop}. - */ - public Trigger PS() { - return PS(CommandScheduler.getInstance().getDefaultButtonLoop()); - } - - /** - * Constructs an event instance around the PS button's digital signal. - * - * @param loop the event loop instance to attach the event to. - * @return an event instance representing the PS button's digital signal attached to the given - * loop. - */ - public Trigger PS(EventLoop loop) { - return m_hid.PS(loop).castTo(Trigger::new); - } - - /** - * Constructs an event instance around the options button's digital signal. - * - * @return an event instance representing the options button's digital signal attached to the - * {@link CommandScheduler#getDefaultButtonLoop() default scheduler button loop}. - */ - public Trigger options() { - return options(CommandScheduler.getInstance().getDefaultButtonLoop()); - } - - /** - * Constructs an event instance around the options button's digital signal. - * - * @param loop the event loop instance to attach the event to. - * @return an event instance representing the options button's digital signal attached to the - * given loop. - */ - public Trigger options(EventLoop loop) { - return m_hid.options(loop).castTo(Trigger::new); - } - - /** - * Constructs an event instance around the touchpad's digital signal. - * - * @return an event instance representing the touchpad's digital signal attached to the {@link - * CommandScheduler#getDefaultButtonLoop() default scheduler button loop}. - */ - public Trigger touchpad() { - return touchpad(CommandScheduler.getInstance().getDefaultButtonLoop()); - } - - /** - * Constructs an event instance around the touchpad's digital signal. - * - * @param loop the event loop instance to attach the event to. - * @return an event instance representing the touchpad's digital signal attached to the given - * loop. - */ - public Trigger touchpad(EventLoop loop) { - return m_hid.touchpad(loop).castTo(Trigger::new); - } - - /** - * Get the X axis value of left side of the controller. - * - * @return the axis value. - */ - public double getLeftX() { - return m_hid.getLeftX(); - } - - /** - * Get the X axis value of right side of the controller. - * - * @return the axis value. - */ - public double getRightX() { - return m_hid.getRightX(); - } - - /** - * Get the Y axis value of left side of the controller. - * - * @return the axis value. - */ - public double getLeftY() { - return m_hid.getLeftY(); - } - - /** - * Get the Y axis value of right side of the controller. - * - * @return the axis value. - */ - public double getRightY() { - return m_hid.getRightY(); - } - - /** - * Get the L2 axis value of the controller. Note that this axis is bound to the range of [0, 1] as - * opposed to the usual [-1, 1]. - * - * @return the axis value. - */ - public double getL2Axis() { - return m_hid.getL2Axis(); - } - - /** - * Get the R2 axis value of the controller. Note that this axis is bound to the range of [0, 1] as - * opposed to the usual [-1, 1]. - * - * @return the axis value. - */ - public double getR2Axis() { - return m_hid.getR2Axis(); - } -} diff --git a/wpilibNewCommands/src/main/native/include/frc2/command/button/CommandPS4Controller.h b/wpilibNewCommands/src/main/native/include/frc2/command/button/CommandPS4Controller.h deleted file mode 100644 index 476828d26fc..00000000000 --- a/wpilibNewCommands/src/main/native/include/frc2/command/button/CommandPS4Controller.h +++ /dev/null @@ -1,239 +0,0 @@ -// Copyright (c) FIRST and other WPILib contributors. -// Open Source Software; you can modify and/or share it under the terms of -// the WPILib BSD license file in the root directory of this project. - -#pragma once -#include - -#include "Trigger.h" -#include "frc2/command/CommandScheduler.h" -#include "frc2/command/button/CommandGenericHID.h" - -namespace frc2 { -/** - * A version of {@link frc::PS4Controller} with {@link Trigger} factories for - * command-based. - * - * @see frc::PS4Controller - */ -class CommandPS4Controller : public frc2::CommandGenericHID { - public: - /** - * Construct an instance of a device. - * - * @param port The port index on the Driver Station that the device is plugged - * into. - */ - explicit CommandPS4Controller(int port); - - /** - * Get the underlying GenericHID object. - * - * @return the wrapped GenericHID object - */ - frc::PS4Controller& GetHID(); - - /** - * Constructs an event instance around this button's digital signal. - * - * @param button the button index - * @param loop the event loop instance to attach the event to. Defaults to the - * CommandScheduler's default loop. - * @return an event instance representing the button's digital signal attached - * to the given loop. - */ - Trigger Button(int button, - frc::EventLoop* loop = CommandScheduler::GetInstance() - .GetDefaultButtonLoop()) const; - - /** - * Constructs an event instance around the square button's digital signal. - * - * @param loop the event loop instance to attach the event to. Defaults to the - * CommandScheduler's default loop. - * @return an event instance representing the square button's digital signal - * attached to the given loop. - */ - Trigger Square(frc::EventLoop* loop = CommandScheduler::GetInstance() - .GetDefaultButtonLoop()) const; - - /** - * Constructs an event instance around the cross button's digital signal. - * - * @param loop the event loop instance to attach the event to. Defaults to the - * CommandScheduler's default loop. - * @return an event instance representing the cross button's digital signal - * attached to the given loop. - */ - Trigger Cross(frc::EventLoop* loop = CommandScheduler::GetInstance() - .GetDefaultButtonLoop()) const; - - /** - * Constructs an event instance around the circle button's digital signal. - * - * @param loop the event loop instance to attach the event to. Defaults to the - * CommandScheduler's default loop. - * @return an event instance representing the circle button's digital signal - * attached to the given loop. - */ - Trigger Circle(frc::EventLoop* loop = CommandScheduler::GetInstance() - .GetDefaultButtonLoop()) const; - - /** - * Constructs an event instance around the triangle button's digital signal. - * - * @param loop the event loop instance to attach the event to. Defaults to the - * CommandScheduler's default loop. - * @return an event instance representing the triangle button's digital signal - * attached to the given loop. - */ - Trigger Triangle(frc::EventLoop* loop = CommandScheduler::GetInstance() - .GetDefaultButtonLoop()) const; - - /** - * Constructs an event instance around the L1 button's digital signal. - * - * @param loop the event loop instance to attach the event to. Defaults to the - * CommandScheduler's default loop. - * @return an event instance representing the L1 button's digital signal - * attached to the given loop. - */ - Trigger L1(frc::EventLoop* loop = - CommandScheduler::GetInstance().GetDefaultButtonLoop()) const; - - /** - * Constructs an event instance around the R1 button's digital signal. - * - * @param loop the event loop instance to attach the event to. Defaults to the - * CommandScheduler's default loop. - * @return an event instance representing the R1 button's digital signal - * attached to the given loop. - */ - Trigger R1(frc::EventLoop* loop = - CommandScheduler::GetInstance().GetDefaultButtonLoop()) const; - - /** - * Constructs an event instance around the L2 button's digital signal. - * - * @param loop the event loop instance to attach the event to. Defaults to the - * CommandScheduler's default loop. - * @return an event instance representing the L2 button's digital signal - * attached to the given loop. - */ - Trigger L2(frc::EventLoop* loop = - CommandScheduler::GetInstance().GetDefaultButtonLoop()) const; - - /** - * Constructs an event instance around the R2 button's digital signal. - * - * @param loop the event loop instance to attach the event to. Defaults to the - * CommandScheduler's default loop. - * @return an event instance representing the R2 button's digital signal - * attached to the given loop. - */ - Trigger R2(frc::EventLoop* loop = - CommandScheduler::GetInstance().GetDefaultButtonLoop()) const; - - /** - * Constructs an event instance around the options button's digital signal. - * - * @param loop the event loop instance to attach the event to. Defaults to the - * CommandScheduler's default loop. - * @return an event instance representing the options button's digital signal - * attached to the given loop. - */ - Trigger Options(frc::EventLoop* loop = CommandScheduler::GetInstance() - .GetDefaultButtonLoop()) const; - - /** - * Constructs an event instance around the L3 button's digital signal. - * - * @param loop the event loop instance to attach the event to. Defaults to the - * CommandScheduler's default loop. - * @return an event instance representing the L3 button's digital signal - * attached to the given loop. - */ - Trigger L3(frc::EventLoop* loop = - CommandScheduler::GetInstance().GetDefaultButtonLoop()) const; - - /** - * Constructs an event instance around the R3 button's digital signal. - * - * @param loop the event loop instance to attach the event to. Defaults to the - * CommandScheduler's default loop. - * @return an event instance representing the R3 button's digital signal - * attached to the given loop. - */ - Trigger R3(frc::EventLoop* loop = - CommandScheduler::GetInstance().GetDefaultButtonLoop()) const; - - /** - * Constructs an event instance around the PS button's digital signal. - * - * @param loop the event loop instance to attach the event to. Defaults to the - * CommandScheduler's default loop. - * @return an event instance representing the PS button's digital signal - * attached to the given loop. - */ - Trigger PS(frc::EventLoop* loop = - CommandScheduler::GetInstance().GetDefaultButtonLoop()) const; - - /** - * Constructs an event instance around the touchpad's digital signal. - * - * @param loop the event loop instance to attach the event to. Defaults to the - * CommandScheduler's default loop. - * @return an event instance representing the touchpad's digital signal - * attached to the given loop. - */ - Trigger Touchpad(frc::EventLoop* loop = CommandScheduler::GetInstance() - .GetDefaultButtonLoop()) const; - - /** - * Get the R2 axis value of the controller. Note that this axis is bound to - * the range of [0, 1] as opposed to the usual [-1, 1]. - * - * @return the axis value. - */ - double GetR2Axis(); - - /** - * Get the L2 axis value of the controller. Note that this axis is bound to - * the range of [0, 1] as opposed to the usual [-1, 1]. - * - * @return the axis value. - */ - double GetL2Axis(); - - /** - * Get the Y axis value of right side of the controller. - * - * @return the axis value. - */ - double GetRightY(); - - /** - * Get the Y axis value of left side of the controller. - * - * @return the axis value. - */ - double GetLeftY(); - - /** - * Get the X axis value of right side of the controller. - * - * @return the axis value. - */ - double GetRightX(); - - /** - * Get the X axis value of left side of the controller. - * - * @return the axis value. - */ - double GetLeftX(); - - private: - frc::PS4Controller m_hid; -}; -} // namespace frc2 diff --git a/wpilibNewCommands/src/main/native/include/frc2/command/button/CommandPS5Controller.h b/wpilibNewCommands/src/main/native/include/frc2/command/button/CommandPS5Controller.h deleted file mode 100644 index badf55cd50a..00000000000 --- a/wpilibNewCommands/src/main/native/include/frc2/command/button/CommandPS5Controller.h +++ /dev/null @@ -1,226 +0,0 @@ -// Copyright (c) FIRST and other WPILib contributors. -// Open Source Software; you can modify and/or share it under the terms of -// the WPILib BSD license file in the root directory of this project. - -#pragma once -#include - -#include "Trigger.h" -#include "frc2/command/CommandScheduler.h" -#include "frc2/command/button/CommandGenericHID.h" - -namespace frc2 { -/** - * A version of {@link frc::PS5Controller} with {@link Trigger} factories for - * command-based. - * - * @see frc::PS5Controller - */ -class CommandPS5Controller : public CommandGenericHID { - public: - /** - * Construct an instance of a device. - * - * @param port The port index on the Driver Station that the device is plugged - * into. - */ - explicit CommandPS5Controller(int port); - - /** - * Get the underlying GenericHID object. - * - * @return the wrapped GenericHID object - */ - frc::PS5Controller& GetHID(); - - /** - * Constructs an event instance around the square button's digital signal. - * - * @param loop the event loop instance to attach the event to. Defaults to the - * CommandScheduler's default loop. - * @return an event instance representing the square button's digital signal - * attached to the given loop. - */ - Trigger Square(frc::EventLoop* loop = CommandScheduler::GetInstance() - .GetDefaultButtonLoop()) const; - - /** - * Constructs an event instance around the cross button's digital signal. - * - * @param loop the event loop instance to attach the event to. Defaults to the - * CommandScheduler's default loop. - * @return an event instance representing the cross button's digital signal - * attached to the given loop. - */ - Trigger Cross(frc::EventLoop* loop = CommandScheduler::GetInstance() - .GetDefaultButtonLoop()) const; - - /** - * Constructs an event instance around the circle button's digital signal. - * - * @param loop the event loop instance to attach the event to. Defaults to the - * CommandScheduler's default loop. - * @return an event instance representing the circle button's digital signal - * attached to the given loop. - */ - Trigger Circle(frc::EventLoop* loop = CommandScheduler::GetInstance() - .GetDefaultButtonLoop()) const; - - /** - * Constructs an event instance around the triangle button's digital signal. - * - * @param loop the event loop instance to attach the event to. Defaults to the - * CommandScheduler's default loop. - * @return an event instance representing the triangle button's digital signal - * attached to the given loop. - */ - Trigger Triangle(frc::EventLoop* loop = CommandScheduler::GetInstance() - .GetDefaultButtonLoop()) const; - - /** - * Constructs an event instance around the L1 button's digital signal. - * - * @param loop the event loop instance to attach the event to. Defaults to the - * CommandScheduler's default loop. - * @return an event instance representing the L1 button's digital signal - * attached to the given loop. - */ - Trigger L1(frc::EventLoop* loop = - CommandScheduler::GetInstance().GetDefaultButtonLoop()) const; - - /** - * Constructs an event instance around the R1 button's digital signal. - * - * @param loop the event loop instance to attach the event to. Defaults to the - * CommandScheduler's default loop. - * @return an event instance representing the R1 button's digital signal - * attached to the given loop. - */ - Trigger R1(frc::EventLoop* loop = - CommandScheduler::GetInstance().GetDefaultButtonLoop()) const; - - /** - * Constructs an event instance around the L2 button's digital signal. - * - * @param loop the event loop instance to attach the event to. Defaults to the - * CommandScheduler's default loop. - * @return an event instance representing the L2 button's digital signal - * attached to the given loop. - */ - Trigger L2(frc::EventLoop* loop = - CommandScheduler::GetInstance().GetDefaultButtonLoop()) const; - - /** - * Constructs an event instance around the R2 button's digital signal. - * - * @param loop the event loop instance to attach the event to. Defaults to the - * CommandScheduler's default loop. - * @return an event instance representing the R2 button's digital signal - * attached to the given loop. - */ - Trigger R2(frc::EventLoop* loop = - CommandScheduler::GetInstance().GetDefaultButtonLoop()) const; - - /** - * Constructs an event instance around the options button's digital signal. - * - * @param loop the event loop instance to attach the event to. Defaults to the - * CommandScheduler's default loop. - * @return an event instance representing the options button's digital signal - * attached to the given loop. - */ - Trigger Options(frc::EventLoop* loop = CommandScheduler::GetInstance() - .GetDefaultButtonLoop()) const; - - /** - * Constructs an event instance around the L3 button's digital signal. - * - * @param loop the event loop instance to attach the event to. Defaults to the - * CommandScheduler's default loop. - * @return an event instance representing the L3 button's digital signal - * attached to the given loop. - */ - Trigger L3(frc::EventLoop* loop = - CommandScheduler::GetInstance().GetDefaultButtonLoop()) const; - - /** - * Constructs an event instance around the R3 button's digital signal. - * - * @param loop the event loop instance to attach the event to. Defaults to the - * CommandScheduler's default loop. - * @return an event instance representing the R3 button's digital signal - * attached to the given loop. - */ - Trigger R3(frc::EventLoop* loop = - CommandScheduler::GetInstance().GetDefaultButtonLoop()) const; - - /** - * Constructs an event instance around the PS button's digital signal. - * - * @param loop the event loop instance to attach the event to. Defaults to the - * CommandScheduler's default loop. - * @return an event instance representing the PS button's digital signal - * attached to the given loop. - */ - Trigger PS(frc::EventLoop* loop = - CommandScheduler::GetInstance().GetDefaultButtonLoop()) const; - - /** - * Constructs an event instance around the touchpad's digital signal. - * - * @param loop the event loop instance to attach the event to. Defaults to the - * CommandScheduler's default loop. - * @return an event instance representing the touchpad's digital signal - * attached to the given loop. - */ - Trigger Touchpad(frc::EventLoop* loop = CommandScheduler::GetInstance() - .GetDefaultButtonLoop()) const; - - /** - * Get the R2 axis value of the controller. Note that this axis is bound to - * the range of [0, 1] as opposed to the usual [-1, 1]. - * - * @return the axis value. - */ - double GetR2Axis(); - - /** - * Get the L2 axis value of the controller. Note that this axis is bound to - * the range of [0, 1] as opposed to the usual [-1, 1]. - * - * @return the axis value. - */ - double GetL2Axis(); - - /** - * Get the Y axis value of right side of the controller. - * - * @return the axis value. - */ - double GetRightY(); - - /** - * Get the Y axis value of left side of the controller. - * - * @return the axis value. - */ - double GetLeftY(); - - /** - * Get the X axis value of right side of the controller. - * - * @return the axis value. - */ - double GetRightX(); - - /** - * Get the X axis value of left side of the controller. - * - * @return the axis value. - */ - double GetLeftX(); - - private: - frc::PS5Controller m_hid; -}; -} // namespace frc2 diff --git a/wpilibNewCommands/src/main/native/include/frc2/command/button/CommandStadiaController.h b/wpilibNewCommands/src/main/native/include/frc2/command/button/CommandStadiaController.h deleted file mode 100644 index 17e57a2dc2d..00000000000 --- a/wpilibNewCommands/src/main/native/include/frc2/command/button/CommandStadiaController.h +++ /dev/null @@ -1,233 +0,0 @@ -// Copyright (c) FIRST and other WPILib contributors. -// Open Source Software; you can modify and/or share it under the terms of -// the WPILib BSD license file in the root directory of this project. - -#pragma once -#include - -#include "Trigger.h" -#include "frc2/command/CommandScheduler.h" -#include "frc2/command/button/CommandGenericHID.h" - -namespace frc2 { -/** - * A version of {@link frc::StadiaController} with {@link Trigger} factories for - * command-based. - * - * @see frc::StadiaController - */ -class CommandStadiaController : public CommandGenericHID { - public: - /** - * Construct an instance of a controller. - * - * @param port The port index on the Driver Station that the controller is - * plugged into. - */ - explicit CommandStadiaController(int port); - - /** - * Get the underlying GenericHID object. - * - * @return the wrapped GenericHID object - */ - frc::StadiaController& GetHID(); - - /** - * Constructs an event instance around the left bumper's digital signal. - * - * @param loop the event loop instance to attach the event to. Defaults to the - * CommandScheduler's default loop. - * @return an event instance representing the left bumper's digital signal - * attached to the given loop. - */ - Trigger LeftBumper(frc::EventLoop* loop = CommandScheduler::GetInstance() - .GetDefaultButtonLoop()) const; - - /** - * Constructs an event instance around the right bumper's digital signal. - * - * @param loop the event loop instance to attach the event to. Defaults to the - * CommandScheduler's default loop. - * @return an event instance representing the right bumper's digital signal - * attached to the given loop. - */ - Trigger RightBumper(frc::EventLoop* loop = CommandScheduler::GetInstance() - .GetDefaultButtonLoop()) const; - - /** - * Constructs an event instance around the left stick's digital signal. - * - * @param loop the event loop instance to attach the event to. Defaults to the - * CommandScheduler's default loop. - * @return an event instance representing the left stick's digital signal - * attached to the given loop. - */ - Trigger LeftStick(frc::EventLoop* loop = CommandScheduler::GetInstance() - .GetDefaultButtonLoop()) const; - - /** - * Constructs an event instance around the right stick's digital signal. - * - * @param loop the event loop instance to attach the event to. Defaults to the - * CommandScheduler's default loop. - * @return an event instance representing the right stick's digital signal - * attached to the given loop. - */ - Trigger RightStick(frc::EventLoop* loop = CommandScheduler::GetInstance() - .GetDefaultButtonLoop()) const; - - /** - * Constructs an event instance around the A button's digital signal. - * - * @param loop the event loop instance to attach the event to. Defaults to the - * CommandScheduler's default loop. - * @return an event instance representing the A button's digital signal - * attached to the given loop. - */ - Trigger A(frc::EventLoop* loop = - CommandScheduler::GetInstance().GetDefaultButtonLoop()) const; - - /** - * Constructs an event instance around the B button's digital signal. - * - * @param loop the event loop instance to attach the event to. Defaults to the - * CommandScheduler's default loop. - * @return an event instance representing the B button's digital signal - * attached to the given loop. - */ - Trigger B(frc::EventLoop* loop = - CommandScheduler::GetInstance().GetDefaultButtonLoop()) const; - - /** - * Constructs an event instance around the X button's digital signal. - * - * @param loop the event loop instance to attach the event to. Defaults to the - * CommandScheduler's default loop. - * @return an event instance representing the X button's digital signal - * attached to the given loop. - */ - Trigger X(frc::EventLoop* loop = - CommandScheduler::GetInstance().GetDefaultButtonLoop()) const; - - /** - * Constructs an event instance around the Y button's digital signal. - * - * @param loop the event loop instance to attach the event to. Defaults to the - * CommandScheduler's default loop. - * @return an event instance representing the Y button's digital signal - * attached to the given loop. - */ - Trigger Y(frc::EventLoop* loop = - CommandScheduler::GetInstance().GetDefaultButtonLoop()) const; - - /** - * Constructs an event instance around the ellipses button's digital signal. - * - * @param loop the event loop instance to attach the event to. Defaults to the - * CommandScheduler's default loop. - * @return an event instance representing the ellipses button's digital signal - * attached to the given loop. - */ - Trigger Ellipses(frc::EventLoop* loop = CommandScheduler::GetInstance() - .GetDefaultButtonLoop()) const; - - /** - * Constructs an event instance around the hamburger button's digital signal. - * - * @param loop the event loop instance to attach the event to. Defaults to the - * CommandScheduler's default loop. - * @return an event instance representing the hamburger button's digital - * signal attached to the given loop. - */ - Trigger Hamburger(frc::EventLoop* loop = CommandScheduler::GetInstance() - .GetDefaultButtonLoop()) const; - - /** - * Constructs an event instance around the stadia button's digital signal. - * - * @param loop the event loop instance to attach the event to. Defaults to the - * CommandScheduler's default loop. - * @return an event instance representing the stadia button's digital signal - * attached to the given loop. - */ - Trigger Stadia(frc::EventLoop* loop = CommandScheduler::GetInstance() - .GetDefaultButtonLoop()) const; - - /** - * Constructs an event instance around the google button's digital signal. - * - * @param loop the event loop instance to attach the event to. Defaults to the - * CommandScheduler's default loop. - * @return an event instance representing the google button's digital signal - * attached to the given loop. - */ - Trigger Google(frc::EventLoop* loop = CommandScheduler::GetInstance() - .GetDefaultButtonLoop()) const; - - /** - * Constructs an event instance around the frame button's digital signal. - * - * @param loop the event loop instance to attach the event to. Defaults to the - * CommandScheduler's default loop. - * @return an event instance representing the frame button's digital signal - * attached to the given loop. - */ - Trigger Frame(frc::EventLoop* loop = CommandScheduler::GetInstance() - .GetDefaultButtonLoop()) const; - - /** - * Constructs an event instance around the left trigger's digital signal. - * - * @param loop the event loop instance to attach the event to. Defaults to the - * CommandScheduler's default loop. - * @return an event instance representing the left trigger's digital signal - * attached to the given loop. - */ - Trigger LeftTrigger(frc::EventLoop* loop = CommandScheduler::GetInstance() - .GetDefaultButtonLoop()) const; - - /** - * Constructs an event instance around the right trigger's digital signal. - * - * @param loop the event loop instance to attach the event to. Defaults to the - * CommandScheduler's default loop. - * @return an event instance representing the right trigger's digital signal - * attached to the given loop. - */ - Trigger RightTrigger( - frc::EventLoop* loop = - CommandScheduler::GetInstance().GetDefaultButtonLoop()) const; - - /** - * Get the X axis value of left side of the controller. - * - * @return the axis value - */ - double GetLeftX() const; - - /** - * Get the X axis value of right side of the controller. - * - * @return the axis value - */ - double GetRightX() const; - - /** - * Get the Y axis value of left side of the controller. - * - * @return the axis value - */ - double GetLeftY() const; - - /** - * Get the Y axis value of right side of the controller. - * - * @return the axis value - */ - double GetRightY() const; - - private: - frc::StadiaController m_hid; -}; -} // namespace frc2 diff --git a/wpilibNewCommands/src/test/java/edu/wpi/first/wpilibj2/command/SwerveControllerCommandTest.java b/wpilibNewCommands/src/test/java/edu/wpi/first/wpilibj2/command/SwerveControllerCommandTest.java index 2f6c6965656..0abe4990486 100644 --- a/wpilibNewCommands/src/test/java/edu/wpi/first/wpilibj2/command/SwerveControllerCommandTest.java +++ b/wpilibNewCommands/src/test/java/edu/wpi/first/wpilibj2/command/SwerveControllerCommandTest.java @@ -51,7 +51,7 @@ void cleanup() { new SwerveModuleState(0, Rotation2d.kZero) }; - private SwerveModulePosition[] m_modulePositions = + private final SwerveModulePosition[] m_modulePositions = new SwerveModulePosition[] { new SwerveModulePosition(0, Rotation2d.kZero), new SwerveModulePosition(0, Rotation2d.kZero), diff --git a/wpilibc/CMakeLists.txt b/wpilibc/CMakeLists.txt index 17e7c991ad2..186c9794b14 100644 --- a/wpilibc/CMakeLists.txt +++ b/wpilibc/CMakeLists.txt @@ -5,7 +5,12 @@ include(AddTest) configure_file(src/generate/WPILibVersion.cpp.in WPILibVersion.cpp) -file(GLOB_RECURSE wpilibc_native_src src/main/native/cpp/*.cpp src/main/native/cppcs/*.cpp) +file( + GLOB_RECURSE wpilibc_native_src + src/main/native/cpp/*.cpp + src/main/native/cppcs/*.cpp + src/generated/main/native/cpp/*.cpp +) add_library(wpilibc ${wpilibc_native_src} ${CMAKE_CURRENT_BINARY_DIR}/WPILibVersion.cpp) set_target_properties(wpilibc PROPERTIES DEBUG_POSTFIX "d") @@ -14,6 +19,7 @@ target_include_directories( wpilibc PUBLIC $ + $ $ ) wpilib_target_warnings(wpilibc) diff --git a/wpilibc/build.gradle b/wpilibc/build.gradle index 507ec445adf..3c9e8af704e 100644 --- a/wpilibc/build.gradle +++ b/wpilibc/build.gradle @@ -85,12 +85,16 @@ model { cpp { source { srcDirs = [ - 'src/main/native/cpp' + 'src/main/native/cpp', + 'src/generated/main/native/cpp' ] include '**/*.cpp' } exportedHeaders { - srcDirs 'src/main/native/include' + srcDirs = [ + 'src/main/native/include', + 'src/generated/main/native/include' + ] } } } @@ -131,7 +135,7 @@ model { include '**/*.cpp' } exportedHeaders { - srcDirs 'src/main/native/include', '../cameraserver/src/main/native/include' + srcDirs 'src/main/native/include', 'src/generated/main/native/include', '../cameraserver/src/main/native/include' } } } diff --git a/wpilibc/generate_hids.py b/wpilibc/generate_hids.py new file mode 100755 index 00000000000..cfe54f7dee6 --- /dev/null +++ b/wpilibc/generate_hids.py @@ -0,0 +1,90 @@ +#!/usr/bin/env python3 + +# Copyright (c) FIRST and other WPILib contributors. +# Open Source Software; you can modify and/or share it under the terms of +# the WPILib BSD license file in the root directory of this project. +import json +import os + +from jinja2 import Environment, FileSystemLoader + + +def write_controller_file(outPath, controllerName, contents): + if not os.path.exists(outPath): + os.makedirs(outPath) + + outpathname = f"{outPath}/{controllerName}" + + if os.path.exists(outpathname): + with open(outpathname, "r") as f: + if f.read() == contents: + return + + # File either doesn't exist or has different contents + with open(outpathname, "w", newline="\n") as f: + f.write(contents) + + +def main(): + dirname, _ = os.path.split(os.path.abspath(__file__)) + + with open("wpilibj/src/generate/hids.json") as f: + controllers = json.load(f) + + # C++ headers + env = Environment( + loader=FileSystemLoader(f"{dirname}/src/generate/main/native/include/frc"), + autoescape=False, + keep_trailing_newline=True, + ) + rootPath = f"{dirname}/src/generated/main/native/include/frc" + template = env.get_template("hid.h.jinja") + for controller in controllers: + controllerName = os.path.basename(f"{controller['ConsoleName']}Controller.h") + output = template.render(controller) + write_controller_file(rootPath, controllerName, output) + + # C++ files + env = Environment( + loader=FileSystemLoader(f"{dirname}/src/generate/main/native/cpp"), + autoescape=False, + ) + rootPath = f"{dirname}/src/generated/main/native/cpp" + template = env.get_template("hid.cpp.jinja") + for controller in controllers: + controllerName = os.path.basename(f"{controller['ConsoleName']}Controller.cpp") + output = template.render(controller) + write_controller_file(rootPath, controllerName, output) + + # C++ simulation headers + env = Environment( + loader=FileSystemLoader( + f"{dirname}/src/generate/main/native/include/frc/simulation" + ), + autoescape=False, + keep_trailing_newline=True, + ) + rootPath = f"{dirname}/src/generated/main/native/include/frc/simulation" + template = env.get_template("hidsim.h.jinja") + for controller in controllers: + controllerName = os.path.basename(f"{controller['ConsoleName']}ControllerSim.h") + output = template.render(controller) + write_controller_file(rootPath, controllerName, output) + + # C++ simulation files + env = Environment( + loader=FileSystemLoader(f"{dirname}/src/generate/main/native/cpp/simulation"), + autoescape=False, + ) + rootPath = f"{dirname}/src/generated/main/native/cpp/simulation" + template = env.get_template("hidsim.cpp.jinja") + for controller in controllers: + controllerName = os.path.basename( + f"{controller['ConsoleName']}ControllerSim.cpp" + ) + output = template.render(controller) + write_controller_file(rootPath, controllerName, output) + + +if __name__ == "__main__": + main() diff --git a/wpilibc/publish.gradle b/wpilibc/publish.gradle index a565ba5f3b6..aff50caa690 100644 --- a/wpilibc/publish.gradle +++ b/wpilibc/publish.gradle @@ -35,7 +35,8 @@ task cppHeadersZip(type: Zip) { } ext.includeDirs = [ - project.file('src/main/native/include') + project.file('src/main/native/include'), + project.file('src/generated/main/native/include') ] ext.includeDirs.each { diff --git a/wpilibc/src/generate/main/native/cpp/hid.cpp.jinja b/wpilibc/src/generate/main/native/cpp/hid.cpp.jinja new file mode 100644 index 00000000000..05b5572453e --- /dev/null +++ b/wpilibc/src/generate/main/native/cpp/hid.cpp.jinja @@ -0,0 +1,92 @@ +// Copyright (c) FIRST and other WPILib contributors. +// Open Source Software; you can modify and/or share it under the terms of +// the WPILib BSD license file in the root directory of this project. + +// THIS FILE WAS AUTO-GENERATED BY ./wpilibc/generate_hids.py. DO NOT MODIFY +{% macro capitalize_first(string) -%} +{{ string[0]|capitalize + string[1:] }} +{%- endmacro %} +#include "frc/{{ ConsoleName }}Controller.h" + +#include + +#include "frc/event/BooleanEvent.h" + +using namespace frc; + +{{ ConsoleName }}Controller::{{ ConsoleName }}Controller(int port) : GenericHID(port) { + {{ "// " if SkipReporting }}HAL_Report(HALUsageReporting::kResourceType_{{ ConsoleName }}Controller, port + 1); +} +{% for stick in sticks %} +double {{ ConsoleName }}Controller::Get{{ stick.NameParts|map("capitalize")|join }}() const { + return GetRawAxis(Axis::k{{ stick.NameParts|map("capitalize")|join }}); +} +{% endfor -%} +{% for trigger in triggers %} +double {{ ConsoleName }}Controller::Get{{ capitalize_first(trigger.name) }}Axis() const { + return GetRawAxis(Axis::k{{ capitalize_first(trigger.name) }}); +} +{% if trigger.UseThresholdMethods %} +BooleanEvent {{ ConsoleName }}Controller::{{ capitalize_first(trigger.name) }}(double threshold, EventLoop* loop) const { + return BooleanEvent(loop, [this, threshold] { return this->Get{{ capitalize_first(trigger.name) }}Axis() > threshold; }); +} + +BooleanEvent {{ ConsoleName }}Controller::{{ capitalize_first(trigger.name) }}(EventLoop* loop) const { + return this->{{ capitalize_first(trigger.name) }}(0.5, loop); +} +{% endif -%} +{% endfor -%} +{% for button in buttons %} +bool {{ ConsoleName }}Controller::Get{{ capitalize_first(button.name) }}Button() const { + return GetRawButton(Button::k{{ capitalize_first(button.name) }}); +} + +bool {{ ConsoleName }}Controller::Get{{ capitalize_first(button.name) }}ButtonPressed() { + return GetRawButtonPressed(Button::k{{ capitalize_first(button.name) }}); +} + +bool {{ ConsoleName }}Controller::Get{{ capitalize_first(button.name) }}ButtonReleased() { + return GetRawButtonReleased(Button::k{{ capitalize_first(button.name) }}); +} + +BooleanEvent {{ ConsoleName }}Controller::{{ capitalize_first(button.name) }}(EventLoop* loop) const { + return BooleanEvent(loop, [this]() { return this->Get{{ capitalize_first(button.name) }}Button(); }); +} +{% endfor -%} +{% if ConsoleName == "Xbox" or ConsoleName == "Stadia"%} +bool {{ ConsoleName }}Controller::GetLeftBumper() const { + return GetRawButton(Button::kLeftBumper); +} + +bool {{ ConsoleName }}Controller::GetRightBumper() const { + return GetRawButton(Button::kRightBumper); +} + +bool {{ ConsoleName }}Controller::GetLeftBumperPressed() { + return GetRawButtonPressed(Button::kLeftBumper); +} + +bool {{ ConsoleName }}Controller::GetRightBumperPressed() { + return GetRawButtonPressed(Button::kRightBumper); +} + +bool {{ ConsoleName }}Controller::GetLeftBumperReleased() { + return GetRawButtonReleased(Button::kLeftBumper); +} + +bool {{ ConsoleName }}Controller::GetRightBumperReleased() { + return GetRawButtonReleased(Button::kRightBumper); +} +{% elif ConsoleName == "PS4" or ConsoleName == "PS5" %} +bool {{ ConsoleName }}Controller::GetTouchpad() const { + return GetRawButton(Button::kTouchpad); +} + +bool {{ ConsoleName }}Controller::GetTouchpadPressed() { + return GetRawButtonPressed(Button::kTouchpad); +} + +bool {{ ConsoleName }}Controller::GetTouchpadReleased() { + return GetRawButtonReleased(Button::kTouchpad); +} +{% endif %} diff --git a/wpilibc/src/generate/main/native/cpp/simulation/hidsim.cpp.jinja b/wpilibc/src/generate/main/native/cpp/simulation/hidsim.cpp.jinja new file mode 100644 index 00000000000..89ffd0cd3ee --- /dev/null +++ b/wpilibc/src/generate/main/native/cpp/simulation/hidsim.cpp.jinja @@ -0,0 +1,42 @@ +// Copyright (c) FIRST and other WPILib contributors. +// Open Source Software; you can modify and/or share it under the terms of +// the WPILib BSD license file in the root directory of this project. + +// THIS FILE WAS AUTO-GENERATED BY ./wpilibc/generate_hids.py. DO NOT MODIFY +{% macro capitalize_first(string) -%} +{{ string[0]|capitalize + string[1:] }} +{%- endmacro %} +#include "frc/simulation/{{ ConsoleName }}ControllerSim.h" + +#include "frc/{{ ConsoleName }}Controller.h" + +using namespace frc; +using namespace frc::sim; + +{{ ConsoleName }}ControllerSim::{{ ConsoleName }}ControllerSim(const {{ ConsoleName }}Controller& joystick) + : GenericHIDSim{joystick} { + SetAxisCount({{ sticks|length + triggers|length }}); + SetButtonCount({{ buttons|length }}); + SetPOVCount(1); +} + +{{ ConsoleName }}ControllerSim::{{ ConsoleName }}ControllerSim(int port) : GenericHIDSim{port} { + SetAxisCount({{ sticks|length + triggers|length }}); + SetButtonCount({{ buttons|length }}); + SetPOVCount(1); +} +{% for stick in sticks %} +void {{ ConsoleName }}ControllerSim::Set{{ stick.NameParts|map("capitalize")|join }}(double value) { + SetRawAxis({{ ConsoleName }}Controller::Axis::k{{ stick.NameParts|map("capitalize")|join }}, value); +} +{% endfor -%} +{% for trigger in triggers %} +void {{ ConsoleName }}ControllerSim::Set{{ capitalize_first(trigger.name) }}Axis(double value) { + SetRawAxis({{ ConsoleName }}Controller::Axis::k{{ capitalize_first(trigger.name) }}, value); +} +{% endfor -%} +{% for button in buttons %} +void {{ ConsoleName }}ControllerSim::Set{{ capitalize_first(button.name) }}Button(bool value) { + SetRawButton({{ ConsoleName }}Controller::Button::k{{ capitalize_first(button.name) }}, value); +} +{% endfor %} diff --git a/wpilibc/src/generate/main/native/include/frc/hid.h.jinja b/wpilibc/src/generate/main/native/include/frc/hid.h.jinja new file mode 100644 index 00000000000..1d2ef67335f --- /dev/null +++ b/wpilibc/src/generate/main/native/include/frc/hid.h.jinja @@ -0,0 +1,208 @@ +// Copyright (c) FIRST and other WPILib contributors. +// Open Source Software; you can modify and/or share it under the terms of +// the WPILib BSD license file in the root directory of this project. + +// THIS FILE WAS AUTO-GENERATED BY ./wpilibc/generate_hids.py. DO NOT MODIFY +{% macro capitalize_first(string) -%} +{{ string[0]|capitalize + string[1:] }} +{%- endmacro %} +#pragma once + +#include "frc/GenericHID.h" + +namespace frc { + +/** + * Handle input from {{ ConsoleName }} controllers connected to the Driver Station. + * + * This class handles {{ ConsoleName }} input that comes from the Driver Station. Each + * time a value is requested the most recent value is returned. There is a + * single class instance for each controller and the mapping of ports to + * hardware buttons depends on the code in the Driver Station. + * + * Only first party controllers from {{ Manufacturer }} are guaranteed to have the + * correct mapping, and only through the official NI DS. Sim is not guaranteed + * to have the same mapping, as well as any 3rd party controllers. + */ +class {{ ConsoleName }}Controller : public GenericHID { + public: + /** + * Construct an instance of a controller. + * + * The controller index is the USB port on the Driver Station. + * + * @param port The port on the Driver Station that the controller is plugged + * into (0-5). + */ + explicit {{ ConsoleName }}Controller(int port); + + ~{{ ConsoleName }}Controller() override = default; + + {{ ConsoleName }}Controller({{ ConsoleName }}Controller&&) = default; + {{ ConsoleName }}Controller& operator=({{ ConsoleName }}Controller&&) = default; +{% for stick in sticks %} + /** + * Get the {{ stick.NameParts[1] }} axis value of {{ stick.NameParts[0] }} side of the controller. + * + * @return the axis value. + */ + double Get{{ stick.NameParts|map("capitalize")|join }}() const; +{% endfor -%} +{% for trigger in triggers %} + /** + * Get the {{ trigger.DocName }} axis value of the controller. Note that this axis + * is bound to the range of [0, 1] as opposed to the usual [-1, 1]. + * + * @return the axis value. + */ + double Get{{ capitalize_first(trigger.name) }}Axis() const; +{% if trigger.UseThresholdMethods %} + /** + * Constructs an event instance around the axis value of the {{ trigger.DocName }}. + * The returned trigger will be true when the axis value is greater than + * {@code threshold}. + * @param threshold the minimum axis value for the returned event to be true. + * This value should be in the range [0, 1] where 0 is the unpressed state of + * the axis. + * @param loop the event loop instance to attach the event to. + * @return an event instance that is true when the {{ trigger.DocName }}'s axis + * exceeds the provided threshold, attached to the given event loop + */ + BooleanEvent {{ capitalize_first(trigger.name) }}(double threshold, EventLoop* loop) const; + + /** + * Constructs an event instance around the axis value of the {{ trigger.DocName }}. + * The returned trigger will be true when the axis value is greater than 0.5. + * @param loop the event loop instance to attach the event to. + * @return an event instance that is true when the {{ trigger.DocName }}'s axis + * exceeds 0.5, attached to the given event loop + */ + BooleanEvent {{ capitalize_first(trigger.name) }}(EventLoop* loop) const; +{% endif -%} +{% endfor -%} +{% for button in buttons %} + /** + * Read the value of the {{ button.DocName|default(button.name) }} button on the controller. + * + * @return The state of the button. + */ + bool Get{{ capitalize_first(button.name) }}Button() const; + + /** + * Whether the {{ button.DocName|default(button.name) }} button was pressed since the last check. + * + * @return Whether the button was pressed since the last check. + */ + bool Get{{ capitalize_first(button.name) }}ButtonPressed(); + + /** + * Whether the {{ button.DocName|default(button.name) }} button was released since the last check. + * + * @return Whether the button was released since the last check. + */ + bool Get{{ capitalize_first(button.name) }}ButtonReleased(); + + /** + * Constructs an event instance around the {{ button.DocName|default(button.name) }} button's + * digital signal. + * + * @param loop the event loop instance to attach the event to. + * @return an event instance representing the {{ button.DocName|default(button.name) }} button's + * digital signal attached to the given loop. + */ + BooleanEvent {{ capitalize_first(button.name) }}(EventLoop* loop) const; +{% endfor -%} +{% if ConsoleName == "Xbox" or ConsoleName == "Stadia" %} + /** + * Read the value of the left bumper (LB) button on the controller. + * + * @return the state of the button + */ + [[deprecated("Use GetLeftBumperButton instead")]] + bool GetLeftBumper() const; + + /** + * Read the value of the right bumper (RB) button on the controller. + * + * @return the state of the button + */ + [[deprecated("Use GetRightBumperButton instead")]] + bool GetRightBumper() const; + + /** + * Whether the left bumper (LB) was pressed since the last check. + * + * @return Whether the button was pressed since the last check + */ + [[deprecated("Use GetLeftBumperButtonPressed instead")]] + bool GetLeftBumperPressed(); + + /** + * Whether the right bumper (RB) was pressed since the last check. + * + * @return Whether the button was pressed since the last check + */ + [[deprecated("Use GetRightBumperButtonPressed instead")]] + bool GetRightBumperPressed(); + + /** + * Whether the left bumper (LB) was released since the last check. + * + * @return Whether the button was released since the last check. + */ + [[deprecated("Use GetLeftBumperButtonReleased instead")]] + bool GetLeftBumperReleased(); + + /** + * Whether the right bumper (RB) was released since the last check. + * + * @return Whether the button was released since the last check. + */ + [[deprecated("Use GetRightBumperButtonReleased instead")]] + bool GetRightBumperReleased(); +{% elif ConsoleName == "PS4" or ConsoleName == "PS5" %} + /** + * Read the value of the touchpad button on the controller. + * + * @return The state of the button. + */ + [[deprecated("Use GetTouchpadButton instead")]] + bool GetTouchpad() const; + /** + * Whether the touchpad was pressed since the last check. + * + * @return Whether the touchpad was pressed since the last check. + */ + [[deprecated("Use GetTouchpadButtonPressed instead")]] + bool GetTouchpadPressed(); + + /** + * Whether the touchpad was released since the last check. + * + * @return Whether the touchpad was released since the last check. + */ + [[deprecated("Use GetTouchpadButtonReleased instead")]] + bool GetTouchpadReleased(); +{% endif %} + /** Represents a digital button on an {{ ConsoleName }}Controller. */ + struct Button { +{%- for button in buttons %} + /// {{ capitalize_first(button.DocName|default(button.name)) }} button. + static constexpr int k{{ capitalize_first(button.name) }} = {{ button.value }}; +{%- endfor %} + }; + + /** Represents an axis on an {{ ConsoleName }}Controller. */ + struct Axis { +{%- for stick in sticks %} + /// {{ stick.NameParts|map("capitalize")|join(" ") }} axis. + static constexpr int k{{ stick.NameParts|map("capitalize")|join }} = {{ stick.value }}; +{%- endfor %} +{%- for trigger in triggers %} + /// {{ trigger.DocName|capitalize }}. + static constexpr int k{{ capitalize_first(trigger.name) }} = {{ trigger.value }}; +{%- endfor %} + }; +}; + +} // namespace frc diff --git a/wpilibc/src/generate/main/native/include/frc/simulation/hidsim.h.jinja b/wpilibc/src/generate/main/native/include/frc/simulation/hidsim.h.jinja new file mode 100644 index 00000000000..6d1ad27f31f --- /dev/null +++ b/wpilibc/src/generate/main/native/include/frc/simulation/hidsim.h.jinja @@ -0,0 +1,89 @@ +// Copyright (c) FIRST and other WPILib contributors. +// Open Source Software; you can modify and/or share it under the terms of +// the WPILib BSD license file in the root directory of this project. + +// THIS FILE WAS AUTO-GENERATED BY ./wpilibc/generate_hids.py. DO NOT MODIFY +{% macro capitalize_first(string) -%} +{{ string[0]|capitalize + string[1:] }} +{%- endmacro %} +#pragma once + +#include "frc/simulation/GenericHIDSim.h" + +namespace frc { + +class {{ ConsoleName }}Controller; + +namespace sim { + +/** + * Class to control a simulated {{ ConsoleName }} controller. + */ +class {{ ConsoleName }}ControllerSim : public GenericHIDSim { + public: + /** + * Constructs from a {{ ConsoleName }}Controller object. + * + * @param joystick controller to simulate + */ + explicit {{ ConsoleName }}ControllerSim(const {{ ConsoleName }}Controller& joystick); + + /** + * Constructs from a joystick port number. + * + * @param port port number + */ + explicit {{ ConsoleName }}ControllerSim(int port); +{% for stick in sticks %} + /** + * Change the {{ stick.NameParts|join(" ") }} value of the controller's joystick. + * + * @param value the new value + */ + void Set{{ stick.NameParts|map("capitalize")|join }}(double value); +{% endfor -%} +{% for trigger in triggers %} + /** + * Change the value of the {{ trigger.DocName }} axis on the controller. + * + * @param value the new value + */ + void Set{{ capitalize_first(trigger.name) }}Axis(double value); +{% endfor -%} +{% for button in buttons %} + /** + * Change the value of the {{ button.DocName|default(button.name) }} button on the controller. + * + * @param value the new value + */ + void Set{{ capitalize_first(button.name) }}Button(bool value); +{% endfor -%} +{% if ConsoleName == "Xbox" %} + /** + * Change the left bumper value of the joystick. + * + * @param value the new value + */ + [[deprecated("Use SetLeftBumperButton instead")]] + void SetLeftBumper(bool value); + + /** + * Change the right bumper value of the joystick. + * + * @param value the new value + */ + [[deprecated("Use SetRightBumperButton instead")]] + void SetRightBumper(bool value); +{% elif ConsoleName == "PS4" or ConsoleName == "PS5" %} + /** + * Change the value of the touchpad button on the controller. + * + * @param value the new value + */ + [[deprecated("Use SetTouchpadButton instead")]] + void SetTouchpad(bool value); +{% endif %} +}; + +} // namespace sim +} // namespace frc diff --git a/wpilibc/src/main/native/cpp/PS4Controller.cpp b/wpilibc/src/generated/main/native/cpp/PS4Controller.cpp similarity index 93% rename from wpilibc/src/main/native/cpp/PS4Controller.cpp rename to wpilibc/src/generated/main/native/cpp/PS4Controller.cpp index e59e18cd3b3..3e4b991d8c7 100644 --- a/wpilibc/src/main/native/cpp/PS4Controller.cpp +++ b/wpilibc/src/generated/main/native/cpp/PS4Controller.cpp @@ -2,6 +2,8 @@ // Open Source Software; you can modify and/or share it under the terms of // the WPILib BSD license file in the root directory of this project. +// THIS FILE WAS AUTO-GENERATED BY ./wpilibc/generate_hids.py. DO NOT MODIFY + #include "frc/PS4Controller.h" #include @@ -18,14 +20,14 @@ double PS4Controller::GetLeftX() const { return GetRawAxis(Axis::kLeftX); } -double PS4Controller::GetRightX() const { - return GetRawAxis(Axis::kRightX); -} - double PS4Controller::GetLeftY() const { return GetRawAxis(Axis::kLeftY); } +double PS4Controller::GetRightX() const { + return GetRawAxis(Axis::kRightX); +} + double PS4Controller::GetRightY() const { return GetRawAxis(Axis::kRightY); } @@ -246,18 +248,30 @@ BooleanEvent PS4Controller::PS(EventLoop* loop) const { return BooleanEvent(loop, [this]() { return this->GetPSButton(); }); } -bool PS4Controller::GetTouchpad() const { +bool PS4Controller::GetTouchpadButton() const { return GetRawButton(Button::kTouchpad); } -bool PS4Controller::GetTouchpadPressed() { +bool PS4Controller::GetTouchpadButtonPressed() { return GetRawButtonPressed(Button::kTouchpad); } -bool PS4Controller::GetTouchpadReleased() { +bool PS4Controller::GetTouchpadButtonReleased() { return GetRawButtonReleased(Button::kTouchpad); } BooleanEvent PS4Controller::Touchpad(EventLoop* loop) const { - return BooleanEvent(loop, [this]() { return this->GetTouchpad(); }); + return BooleanEvent(loop, [this]() { return this->GetTouchpadButton(); }); +} + +bool PS4Controller::GetTouchpad() const { + return GetRawButton(Button::kTouchpad); +} + +bool PS4Controller::GetTouchpadPressed() { + return GetRawButtonPressed(Button::kTouchpad); +} + +bool PS4Controller::GetTouchpadReleased() { + return GetRawButtonReleased(Button::kTouchpad); } diff --git a/wpilibc/src/main/native/cpp/PS5Controller.cpp b/wpilibc/src/generated/main/native/cpp/PS5Controller.cpp similarity index 93% rename from wpilibc/src/main/native/cpp/PS5Controller.cpp rename to wpilibc/src/generated/main/native/cpp/PS5Controller.cpp index 95685d677b8..34df999abd1 100644 --- a/wpilibc/src/main/native/cpp/PS5Controller.cpp +++ b/wpilibc/src/generated/main/native/cpp/PS5Controller.cpp @@ -2,6 +2,8 @@ // Open Source Software; you can modify and/or share it under the terms of // the WPILib BSD license file in the root directory of this project. +// THIS FILE WAS AUTO-GENERATED BY ./wpilibc/generate_hids.py. DO NOT MODIFY + #include "frc/PS5Controller.h" #include @@ -18,14 +20,14 @@ double PS5Controller::GetLeftX() const { return GetRawAxis(Axis::kLeftX); } -double PS5Controller::GetRightX() const { - return GetRawAxis(Axis::kRightX); -} - double PS5Controller::GetLeftY() const { return GetRawAxis(Axis::kLeftY); } +double PS5Controller::GetRightX() const { + return GetRawAxis(Axis::kRightX); +} + double PS5Controller::GetRightY() const { return GetRawAxis(Axis::kRightY); } @@ -246,18 +248,30 @@ BooleanEvent PS5Controller::PS(EventLoop* loop) const { return BooleanEvent(loop, [this]() { return this->GetPSButton(); }); } -bool PS5Controller::GetTouchpad() const { +bool PS5Controller::GetTouchpadButton() const { return GetRawButton(Button::kTouchpad); } -bool PS5Controller::GetTouchpadPressed() { +bool PS5Controller::GetTouchpadButtonPressed() { return GetRawButtonPressed(Button::kTouchpad); } -bool PS5Controller::GetTouchpadReleased() { +bool PS5Controller::GetTouchpadButtonReleased() { return GetRawButtonReleased(Button::kTouchpad); } BooleanEvent PS5Controller::Touchpad(EventLoop* loop) const { - return BooleanEvent(loop, [this]() { return this->GetTouchpad(); }); + return BooleanEvent(loop, [this]() { return this->GetTouchpadButton(); }); +} + +bool PS5Controller::GetTouchpad() const { + return GetRawButton(Button::kTouchpad); +} + +bool PS5Controller::GetTouchpadPressed() { + return GetRawButtonPressed(Button::kTouchpad); +} + +bool PS5Controller::GetTouchpadReleased() { + return GetRawButtonReleased(Button::kTouchpad); } diff --git a/wpilibc/src/main/native/cpp/StadiaController.cpp b/wpilibc/src/generated/main/native/cpp/StadiaController.cpp similarity index 90% rename from wpilibc/src/main/native/cpp/StadiaController.cpp rename to wpilibc/src/generated/main/native/cpp/StadiaController.cpp index 4f8d666c54c..54192f2071b 100644 --- a/wpilibc/src/main/native/cpp/StadiaController.cpp +++ b/wpilibc/src/generated/main/native/cpp/StadiaController.cpp @@ -2,6 +2,8 @@ // Open Source Software; you can modify and/or share it under the terms of // the WPILib BSD license file in the root directory of this project. +// THIS FILE WAS AUTO-GENERATED BY ./wpilibc/generate_hids.py. DO NOT MODIFY + #include "frc/StadiaController.h" #include @@ -11,7 +13,6 @@ using namespace frc; StadiaController::StadiaController(int port) : GenericHID(port) { - // re-enable when StadiaController is added to Usage Reporting // HAL_Report(HALUsageReporting::kResourceType_StadiaController, port + 1); } @@ -31,70 +32,6 @@ double StadiaController::GetRightY() const { return GetRawAxis(Axis::kRightY); } -bool StadiaController::GetLeftBumper() const { - return GetRawButton(Button::kLeftBumper); -} - -bool StadiaController::GetRightBumper() const { - return GetRawButton(Button::kRightBumper); -} - -bool StadiaController::GetLeftBumperPressed() { - return GetRawButtonPressed(Button::kLeftBumper); -} - -bool StadiaController::GetRightBumperPressed() { - return GetRawButtonPressed(Button::kRightBumper); -} - -bool StadiaController::GetLeftBumperReleased() { - return GetRawButtonReleased(Button::kLeftBumper); -} - -bool StadiaController::GetRightBumperReleased() { - return GetRawButtonReleased(Button::kRightBumper); -} - -BooleanEvent StadiaController::LeftBumper(EventLoop* loop) const { - return BooleanEvent(loop, [this]() { return this->GetLeftBumper(); }); -} - -BooleanEvent StadiaController::RightBumper(EventLoop* loop) const { - return BooleanEvent(loop, [this]() { return this->GetRightBumper(); }); -} - -bool StadiaController::GetLeftStickButton() const { - return GetRawButton(Button::kLeftStick); -} - -bool StadiaController::GetRightStickButton() const { - return GetRawButton(Button::kRightStick); -} - -bool StadiaController::GetLeftStickButtonPressed() { - return GetRawButtonPressed(Button::kLeftStick); -} - -bool StadiaController::GetRightStickButtonPressed() { - return GetRawButtonPressed(Button::kRightStick); -} - -bool StadiaController::GetLeftStickButtonReleased() { - return GetRawButtonReleased(Button::kLeftStick); -} - -bool StadiaController::GetRightStickButtonReleased() { - return GetRawButtonReleased(Button::kRightStick); -} - -BooleanEvent StadiaController::LeftStick(EventLoop* loop) const { - return BooleanEvent(loop, [this]() { return this->GetLeftStickButton(); }); -} - -BooleanEvent StadiaController::RightStick(EventLoop* loop) const { - return BooleanEvent(loop, [this]() { return this->GetRightStickButton(); }); -} - bool StadiaController::GetAButton() const { return GetRawButton(Button::kA); } @@ -159,6 +96,70 @@ BooleanEvent StadiaController::Y(EventLoop* loop) const { return BooleanEvent(loop, [this]() { return this->GetYButton(); }); } +bool StadiaController::GetLeftBumperButton() const { + return GetRawButton(Button::kLeftBumper); +} + +bool StadiaController::GetLeftBumperButtonPressed() { + return GetRawButtonPressed(Button::kLeftBumper); +} + +bool StadiaController::GetLeftBumperButtonReleased() { + return GetRawButtonReleased(Button::kLeftBumper); +} + +BooleanEvent StadiaController::LeftBumper(EventLoop* loop) const { + return BooleanEvent(loop, [this]() { return this->GetLeftBumperButton(); }); +} + +bool StadiaController::GetRightBumperButton() const { + return GetRawButton(Button::kRightBumper); +} + +bool StadiaController::GetRightBumperButtonPressed() { + return GetRawButtonPressed(Button::kRightBumper); +} + +bool StadiaController::GetRightBumperButtonReleased() { + return GetRawButtonReleased(Button::kRightBumper); +} + +BooleanEvent StadiaController::RightBumper(EventLoop* loop) const { + return BooleanEvent(loop, [this]() { return this->GetRightBumperButton(); }); +} + +bool StadiaController::GetLeftStickButton() const { + return GetRawButton(Button::kLeftStick); +} + +bool StadiaController::GetLeftStickButtonPressed() { + return GetRawButtonPressed(Button::kLeftStick); +} + +bool StadiaController::GetLeftStickButtonReleased() { + return GetRawButtonReleased(Button::kLeftStick); +} + +BooleanEvent StadiaController::LeftStick(EventLoop* loop) const { + return BooleanEvent(loop, [this]() { return this->GetLeftStickButton(); }); +} + +bool StadiaController::GetRightStickButton() const { + return GetRawButton(Button::kRightStick); +} + +bool StadiaController::GetRightStickButtonPressed() { + return GetRawButtonPressed(Button::kRightStick); +} + +bool StadiaController::GetRightStickButtonReleased() { + return GetRawButtonReleased(Button::kRightStick); +} + +BooleanEvent StadiaController::RightStick(EventLoop* loop) const { + return BooleanEvent(loop, [this]() { return this->GetRightStickButton(); }); +} + bool StadiaController::GetEllipsesButton() const { return GetRawButton(Button::kEllipses); } @@ -207,6 +208,38 @@ BooleanEvent StadiaController::Stadia(EventLoop* loop) const { return BooleanEvent(loop, [this]() { return this->GetStadiaButton(); }); } +bool StadiaController::GetRightTriggerButton() const { + return GetRawButton(Button::kRightTrigger); +} + +bool StadiaController::GetRightTriggerButtonPressed() { + return GetRawButtonPressed(Button::kRightTrigger); +} + +bool StadiaController::GetRightTriggerButtonReleased() { + return GetRawButtonReleased(Button::kRightTrigger); +} + +BooleanEvent StadiaController::RightTrigger(EventLoop* loop) const { + return BooleanEvent(loop, [this]() { return this->GetRightTriggerButton(); }); +} + +bool StadiaController::GetLeftTriggerButton() const { + return GetRawButton(Button::kLeftTrigger); +} + +bool StadiaController::GetLeftTriggerButtonPressed() { + return GetRawButtonPressed(Button::kLeftTrigger); +} + +bool StadiaController::GetLeftTriggerButtonReleased() { + return GetRawButtonReleased(Button::kLeftTrigger); +} + +BooleanEvent StadiaController::LeftTrigger(EventLoop* loop) const { + return BooleanEvent(loop, [this]() { return this->GetLeftTriggerButton(); }); +} + bool StadiaController::GetGoogleButton() const { return GetRawButton(Button::kGoogle); } @@ -239,34 +272,26 @@ BooleanEvent StadiaController::Frame(EventLoop* loop) const { return BooleanEvent(loop, [this]() { return this->GetFrameButton(); }); } -bool StadiaController::GetLeftTriggerButton() const { - return GetRawButton(Button::kLeftTrigger); -} - -bool StadiaController::GetLeftTriggerButtonPressed() { - return GetRawButtonPressed(Button::kLeftTrigger); -} - -bool StadiaController::GetLeftTriggerButtonReleased() { - return GetRawButtonReleased(Button::kLeftTrigger); +bool StadiaController::GetLeftBumper() const { + return GetRawButton(Button::kLeftBumper); } -BooleanEvent StadiaController::LeftTrigger(EventLoop* loop) const { - return BooleanEvent(loop, [this]() { return this->GetLeftTriggerButton(); }); +bool StadiaController::GetRightBumper() const { + return GetRawButton(Button::kRightBumper); } -bool StadiaController::GetRightTriggerButton() const { - return GetRawButton(Button::kRightTrigger); +bool StadiaController::GetLeftBumperPressed() { + return GetRawButtonPressed(Button::kLeftBumper); } -bool StadiaController::GetRightTriggerButtonPressed() { - return GetRawButtonPressed(Button::kRightTrigger); +bool StadiaController::GetRightBumperPressed() { + return GetRawButtonPressed(Button::kRightBumper); } -bool StadiaController::GetRightTriggerButtonReleased() { - return GetRawButtonReleased(Button::kRightTrigger); +bool StadiaController::GetLeftBumperReleased() { + return GetRawButtonReleased(Button::kLeftBumper); } -BooleanEvent StadiaController::RightTrigger(EventLoop* loop) const { - return BooleanEvent(loop, [this]() { return this->GetRightTriggerButton(); }); +bool StadiaController::GetRightBumperReleased() { + return GetRawButtonReleased(Button::kRightBumper); } diff --git a/wpilibc/src/main/native/cpp/XboxController.cpp b/wpilibc/src/generated/main/native/cpp/XboxController.cpp similarity index 82% rename from wpilibc/src/main/native/cpp/XboxController.cpp rename to wpilibc/src/generated/main/native/cpp/XboxController.cpp index f10419f4006..a924ba21eff 100644 --- a/wpilibc/src/main/native/cpp/XboxController.cpp +++ b/wpilibc/src/generated/main/native/cpp/XboxController.cpp @@ -2,6 +2,8 @@ // Open Source Software; you can modify and/or share it under the terms of // the WPILib BSD license file in the root directory of this project. +// THIS FILE WAS AUTO-GENERATED BY ./wpilibc/generate_hids.py. DO NOT MODIFY + #include "frc/XboxController.h" #include @@ -34,72 +36,24 @@ double XboxController::GetLeftTriggerAxis() const { return GetRawAxis(Axis::kLeftTrigger); } -double XboxController::GetRightTriggerAxis() const { - return GetRawAxis(Axis::kRightTrigger); -} - -bool XboxController::GetLeftBumper() const { - return GetRawButton(Button::kLeftBumper); -} - -bool XboxController::GetRightBumper() const { - return GetRawButton(Button::kRightBumper); -} - -bool XboxController::GetLeftBumperPressed() { - return GetRawButtonPressed(Button::kLeftBumper); -} - -bool XboxController::GetRightBumperPressed() { - return GetRawButtonPressed(Button::kRightBumper); -} - -bool XboxController::GetLeftBumperReleased() { - return GetRawButtonReleased(Button::kLeftBumper); -} - -bool XboxController::GetRightBumperReleased() { - return GetRawButtonReleased(Button::kRightBumper); -} - -BooleanEvent XboxController::LeftBumper(EventLoop* loop) const { - return BooleanEvent(loop, [this]() { return this->GetLeftBumper(); }); -} - -BooleanEvent XboxController::RightBumper(EventLoop* loop) const { - return BooleanEvent(loop, [this]() { return this->GetRightBumper(); }); -} - -bool XboxController::GetLeftStickButton() const { - return GetRawButton(Button::kLeftStick); -} - -bool XboxController::GetRightStickButton() const { - return GetRawButton(Button::kRightStick); -} - -bool XboxController::GetLeftStickButtonPressed() { - return GetRawButtonPressed(Button::kLeftStick); -} - -bool XboxController::GetRightStickButtonPressed() { - return GetRawButtonPressed(Button::kRightStick); +BooleanEvent XboxController::LeftTrigger(double threshold, EventLoop* loop) const { + return BooleanEvent(loop, [this, threshold] { return this->GetLeftTriggerAxis() > threshold; }); } -bool XboxController::GetLeftStickButtonReleased() { - return GetRawButtonReleased(Button::kLeftStick); +BooleanEvent XboxController::LeftTrigger(EventLoop* loop) const { + return this->LeftTrigger(0.5, loop); } -bool XboxController::GetRightStickButtonReleased() { - return GetRawButtonReleased(Button::kRightStick); +double XboxController::GetRightTriggerAxis() const { + return GetRawAxis(Axis::kRightTrigger); } -BooleanEvent XboxController::LeftStick(EventLoop* loop) const { - return BooleanEvent(loop, [this]() { return this->GetLeftStickButton(); }); +BooleanEvent XboxController::RightTrigger(double threshold, EventLoop* loop) const { + return BooleanEvent(loop, [this, threshold] { return this->GetRightTriggerAxis() > threshold; }); } -BooleanEvent XboxController::RightStick(EventLoop* loop) const { - return BooleanEvent(loop, [this]() { return this->GetRightStickButton(); }); +BooleanEvent XboxController::RightTrigger(EventLoop* loop) const { + return this->RightTrigger(0.5, loop); } bool XboxController::GetAButton() const { @@ -166,6 +120,38 @@ BooleanEvent XboxController::Y(EventLoop* loop) const { return BooleanEvent(loop, [this]() { return this->GetYButton(); }); } +bool XboxController::GetLeftBumperButton() const { + return GetRawButton(Button::kLeftBumper); +} + +bool XboxController::GetLeftBumperButtonPressed() { + return GetRawButtonPressed(Button::kLeftBumper); +} + +bool XboxController::GetLeftBumperButtonReleased() { + return GetRawButtonReleased(Button::kLeftBumper); +} + +BooleanEvent XboxController::LeftBumper(EventLoop* loop) const { + return BooleanEvent(loop, [this]() { return this->GetLeftBumperButton(); }); +} + +bool XboxController::GetRightBumperButton() const { + return GetRawButton(Button::kRightBumper); +} + +bool XboxController::GetRightBumperButtonPressed() { + return GetRawButtonPressed(Button::kRightBumper); +} + +bool XboxController::GetRightBumperButtonReleased() { + return GetRawButtonReleased(Button::kRightBumper); +} + +BooleanEvent XboxController::RightBumper(EventLoop* loop) const { + return BooleanEvent(loop, [this]() { return this->GetRightBumperButton(); }); +} + bool XboxController::GetBackButton() const { return GetRawButton(Button::kBack); } @@ -198,24 +184,58 @@ BooleanEvent XboxController::Start(EventLoop* loop) const { return BooleanEvent(loop, [this]() { return this->GetStartButton(); }); } -BooleanEvent XboxController::LeftTrigger(double threshold, - EventLoop* loop) const { - return BooleanEvent(loop, [this, threshold]() { - return this->GetLeftTriggerAxis() > threshold; - }); +bool XboxController::GetLeftStickButton() const { + return GetRawButton(Button::kLeftStick); } -BooleanEvent XboxController::LeftTrigger(EventLoop* loop) const { - return this->LeftTrigger(0.5, loop); +bool XboxController::GetLeftStickButtonPressed() { + return GetRawButtonPressed(Button::kLeftStick); } -BooleanEvent XboxController::RightTrigger(double threshold, - EventLoop* loop) const { - return BooleanEvent(loop, [this, threshold]() { - return this->GetRightTriggerAxis() > threshold; - }); +bool XboxController::GetLeftStickButtonReleased() { + return GetRawButtonReleased(Button::kLeftStick); } -BooleanEvent XboxController::RightTrigger(EventLoop* loop) const { - return this->RightTrigger(0.5, loop); +BooleanEvent XboxController::LeftStick(EventLoop* loop) const { + return BooleanEvent(loop, [this]() { return this->GetLeftStickButton(); }); +} + +bool XboxController::GetRightStickButton() const { + return GetRawButton(Button::kRightStick); +} + +bool XboxController::GetRightStickButtonPressed() { + return GetRawButtonPressed(Button::kRightStick); +} + +bool XboxController::GetRightStickButtonReleased() { + return GetRawButtonReleased(Button::kRightStick); +} + +BooleanEvent XboxController::RightStick(EventLoop* loop) const { + return BooleanEvent(loop, [this]() { return this->GetRightStickButton(); }); +} + +bool XboxController::GetLeftBumper() const { + return GetRawButton(Button::kLeftBumper); +} + +bool XboxController::GetRightBumper() const { + return GetRawButton(Button::kRightBumper); +} + +bool XboxController::GetLeftBumperPressed() { + return GetRawButtonPressed(Button::kLeftBumper); +} + +bool XboxController::GetRightBumperPressed() { + return GetRawButtonPressed(Button::kRightBumper); +} + +bool XboxController::GetLeftBumperReleased() { + return GetRawButtonReleased(Button::kLeftBumper); +} + +bool XboxController::GetRightBumperReleased() { + return GetRawButtonReleased(Button::kRightBumper); } diff --git a/wpilibc/src/main/native/cpp/simulation/PS4ControllerSim.cpp b/wpilibc/src/generated/main/native/cpp/simulation/PS4ControllerSim.cpp similarity index 95% rename from wpilibc/src/main/native/cpp/simulation/PS4ControllerSim.cpp rename to wpilibc/src/generated/main/native/cpp/simulation/PS4ControllerSim.cpp index fecac9dc369..9fb4f3fc994 100644 --- a/wpilibc/src/main/native/cpp/simulation/PS4ControllerSim.cpp +++ b/wpilibc/src/generated/main/native/cpp/simulation/PS4ControllerSim.cpp @@ -2,6 +2,8 @@ // Open Source Software; you can modify and/or share it under the terms of // the WPILib BSD license file in the root directory of this project. +// THIS FILE WAS AUTO-GENERATED BY ./wpilibc/generate_hids.py. DO NOT MODIFY + #include "frc/simulation/PS4ControllerSim.h" #include "frc/PS4Controller.h" @@ -26,14 +28,14 @@ void PS4ControllerSim::SetLeftX(double value) { SetRawAxis(PS4Controller::Axis::kLeftX, value); } -void PS4ControllerSim::SetRightX(double value) { - SetRawAxis(PS4Controller::Axis::kRightX, value); -} - void PS4ControllerSim::SetLeftY(double value) { SetRawAxis(PS4Controller::Axis::kLeftY, value); } +void PS4ControllerSim::SetRightX(double value) { + SetRawAxis(PS4Controller::Axis::kRightX, value); +} + void PS4ControllerSim::SetRightY(double value) { SetRawAxis(PS4Controller::Axis::kRightY, value); } @@ -98,6 +100,6 @@ void PS4ControllerSim::SetPSButton(bool value) { SetRawButton(PS4Controller::Button::kPS, value); } -void PS4ControllerSim::SetTouchpad(bool value) { +void PS4ControllerSim::SetTouchpadButton(bool value) { SetRawButton(PS4Controller::Button::kTouchpad, value); } diff --git a/wpilibc/src/main/native/cpp/simulation/PS5ControllerSim.cpp b/wpilibc/src/generated/main/native/cpp/simulation/PS5ControllerSim.cpp similarity index 95% rename from wpilibc/src/main/native/cpp/simulation/PS5ControllerSim.cpp rename to wpilibc/src/generated/main/native/cpp/simulation/PS5ControllerSim.cpp index e20105c4b3d..4e3a095d8e5 100644 --- a/wpilibc/src/main/native/cpp/simulation/PS5ControllerSim.cpp +++ b/wpilibc/src/generated/main/native/cpp/simulation/PS5ControllerSim.cpp @@ -2,6 +2,8 @@ // Open Source Software; you can modify and/or share it under the terms of // the WPILib BSD license file in the root directory of this project. +// THIS FILE WAS AUTO-GENERATED BY ./wpilibc/generate_hids.py. DO NOT MODIFY + #include "frc/simulation/PS5ControllerSim.h" #include "frc/PS5Controller.h" @@ -26,14 +28,14 @@ void PS5ControllerSim::SetLeftX(double value) { SetRawAxis(PS5Controller::Axis::kLeftX, value); } -void PS5ControllerSim::SetRightX(double value) { - SetRawAxis(PS5Controller::Axis::kRightX, value); -} - void PS5ControllerSim::SetLeftY(double value) { SetRawAxis(PS5Controller::Axis::kLeftY, value); } +void PS5ControllerSim::SetRightX(double value) { + SetRawAxis(PS5Controller::Axis::kRightX, value); +} + void PS5ControllerSim::SetRightY(double value) { SetRawAxis(PS5Controller::Axis::kRightY, value); } @@ -98,6 +100,6 @@ void PS5ControllerSim::SetPSButton(bool value) { SetRawButton(PS5Controller::Button::kPS, value); } -void PS5ControllerSim::SetTouchpad(bool value) { +void PS5ControllerSim::SetTouchpadButton(bool value) { SetRawButton(PS5Controller::Button::kTouchpad, value); } diff --git a/wpilibc/src/generated/main/native/cpp/simulation/StadiaControllerSim.cpp b/wpilibc/src/generated/main/native/cpp/simulation/StadiaControllerSim.cpp new file mode 100644 index 00000000000..73f4a504e02 --- /dev/null +++ b/wpilibc/src/generated/main/native/cpp/simulation/StadiaControllerSim.cpp @@ -0,0 +1,101 @@ +// Copyright (c) FIRST and other WPILib contributors. +// Open Source Software; you can modify and/or share it under the terms of +// the WPILib BSD license file in the root directory of this project. + +// THIS FILE WAS AUTO-GENERATED BY ./wpilibc/generate_hids.py. DO NOT MODIFY + +#include "frc/simulation/StadiaControllerSim.h" + +#include "frc/StadiaController.h" + +using namespace frc; +using namespace frc::sim; + +StadiaControllerSim::StadiaControllerSim(const StadiaController& joystick) + : GenericHIDSim{joystick} { + SetAxisCount(4); + SetButtonCount(15); + SetPOVCount(1); +} + +StadiaControllerSim::StadiaControllerSim(int port) : GenericHIDSim{port} { + SetAxisCount(4); + SetButtonCount(15); + SetPOVCount(1); +} + +void StadiaControllerSim::SetLeftX(double value) { + SetRawAxis(StadiaController::Axis::kLeftX, value); +} + +void StadiaControllerSim::SetRightX(double value) { + SetRawAxis(StadiaController::Axis::kRightX, value); +} + +void StadiaControllerSim::SetLeftY(double value) { + SetRawAxis(StadiaController::Axis::kLeftY, value); +} + +void StadiaControllerSim::SetRightY(double value) { + SetRawAxis(StadiaController::Axis::kRightY, value); +} + +void StadiaControllerSim::SetAButton(bool value) { + SetRawButton(StadiaController::Button::kA, value); +} + +void StadiaControllerSim::SetBButton(bool value) { + SetRawButton(StadiaController::Button::kB, value); +} + +void StadiaControllerSim::SetXButton(bool value) { + SetRawButton(StadiaController::Button::kX, value); +} + +void StadiaControllerSim::SetYButton(bool value) { + SetRawButton(StadiaController::Button::kY, value); +} + +void StadiaControllerSim::SetLeftBumperButton(bool value) { + SetRawButton(StadiaController::Button::kLeftBumper, value); +} + +void StadiaControllerSim::SetRightBumperButton(bool value) { + SetRawButton(StadiaController::Button::kRightBumper, value); +} + +void StadiaControllerSim::SetLeftStickButton(bool value) { + SetRawButton(StadiaController::Button::kLeftStick, value); +} + +void StadiaControllerSim::SetRightStickButton(bool value) { + SetRawButton(StadiaController::Button::kRightStick, value); +} + +void StadiaControllerSim::SetEllipsesButton(bool value) { + SetRawButton(StadiaController::Button::kEllipses, value); +} + +void StadiaControllerSim::SetHamburgerButton(bool value) { + SetRawButton(StadiaController::Button::kHamburger, value); +} + +void StadiaControllerSim::SetStadiaButton(bool value) { + SetRawButton(StadiaController::Button::kStadia, value); +} + +void StadiaControllerSim::SetRightTriggerButton(bool value) { + SetRawButton(StadiaController::Button::kRightTrigger, value); +} + +void StadiaControllerSim::SetLeftTriggerButton(bool value) { + SetRawButton(StadiaController::Button::kLeftTrigger, value); +} + +void StadiaControllerSim::SetGoogleButton(bool value) { + SetRawButton(StadiaController::Button::kGoogle, value); +} + +void StadiaControllerSim::SetFrameButton(bool value) { + SetRawButton(StadiaController::Button::kFrame, value); +} diff --git a/wpilibc/src/main/native/cpp/simulation/XboxControllerSim.cpp b/wpilibc/src/generated/main/native/cpp/simulation/XboxControllerSim.cpp similarity index 52% rename from wpilibc/src/main/native/cpp/simulation/XboxControllerSim.cpp rename to wpilibc/src/generated/main/native/cpp/simulation/XboxControllerSim.cpp index daf48b78efe..441058982ed 100644 --- a/wpilibc/src/main/native/cpp/simulation/XboxControllerSim.cpp +++ b/wpilibc/src/generated/main/native/cpp/simulation/XboxControllerSim.cpp @@ -2,6 +2,8 @@ // Open Source Software; you can modify and/or share it under the terms of // the WPILib BSD license file in the root directory of this project. +// THIS FILE WAS AUTO-GENERATED BY ./wpilibc/generate_hids.py. DO NOT MODIFY + #include "frc/simulation/XboxControllerSim.h" #include "frc/XboxController.h" @@ -46,42 +48,42 @@ void XboxControllerSim::SetRightTriggerAxis(double value) { SetRawAxis(XboxController::Axis::kRightTrigger, value); } -void XboxControllerSim::SetLeftBumper(bool state) { - SetRawButton(XboxController::Button::kLeftBumper, state); +void XboxControllerSim::SetAButton(bool value) { + SetRawButton(XboxController::Button::kA, value); } -void XboxControllerSim::SetRightBumper(bool state) { - SetRawButton(XboxController::Button::kRightBumper, state); +void XboxControllerSim::SetBButton(bool value) { + SetRawButton(XboxController::Button::kB, value); } -void XboxControllerSim::SetLeftStickButton(bool state) { - SetRawButton(XboxController::Button::kLeftStick, state); +void XboxControllerSim::SetXButton(bool value) { + SetRawButton(XboxController::Button::kX, value); } -void XboxControllerSim::SetRightStickButton(bool state) { - SetRawButton(XboxController::Button::kRightStick, state); +void XboxControllerSim::SetYButton(bool value) { + SetRawButton(XboxController::Button::kY, value); } -void XboxControllerSim::SetAButton(bool state) { - SetRawButton(XboxController::Button::kA, state); +void XboxControllerSim::SetLeftBumperButton(bool value) { + SetRawButton(XboxController::Button::kLeftBumper, value); } -void XboxControllerSim::SetBButton(bool state) { - SetRawButton(XboxController::Button::kB, state); +void XboxControllerSim::SetRightBumperButton(bool value) { + SetRawButton(XboxController::Button::kRightBumper, value); } -void XboxControllerSim::SetXButton(bool state) { - SetRawButton(XboxController::Button::kX, state); +void XboxControllerSim::SetBackButton(bool value) { + SetRawButton(XboxController::Button::kBack, value); } -void XboxControllerSim::SetYButton(bool state) { - SetRawButton(XboxController::Button::kY, state); +void XboxControllerSim::SetStartButton(bool value) { + SetRawButton(XboxController::Button::kStart, value); } -void XboxControllerSim::SetBackButton(bool state) { - SetRawButton(XboxController::Button::kBack, state); +void XboxControllerSim::SetLeftStickButton(bool value) { + SetRawButton(XboxController::Button::kLeftStick, value); } -void XboxControllerSim::SetStartButton(bool state) { - SetRawButton(XboxController::Button::kStart, state); +void XboxControllerSim::SetRightStickButton(bool value) { + SetRawButton(XboxController::Button::kRightStick, value); } diff --git a/wpilibc/src/main/native/include/frc/PS4Controller.h b/wpilibc/src/generated/main/native/include/frc/PS4Controller.h similarity index 57% rename from wpilibc/src/main/native/include/frc/PS4Controller.h rename to wpilibc/src/generated/main/native/include/frc/PS4Controller.h index 881f8564f25..3614cc3fdf9 100644 --- a/wpilibc/src/main/native/include/frc/PS4Controller.h +++ b/wpilibc/src/generated/main/native/include/frc/PS4Controller.h @@ -2,6 +2,8 @@ // Open Source Software; you can modify and/or share it under the terms of // the WPILib BSD license file in the root directory of this project. +// THIS FILE WAS AUTO-GENERATED BY ./wpilibc/generate_hids.py. DO NOT MODIFY + #pragma once #include "frc/GenericHID.h" @@ -11,19 +13,19 @@ namespace frc { /** * Handle input from PS4 controllers connected to the Driver Station. * - * This class handles PS4 input that comes from the Driver Station. Each time - * a value is requested the most recent value is returned. There is a single - * class instance for each controller and the mapping of ports to hardware - * buttons depends on the code in the Driver Station. + * This class handles PS4 input that comes from the Driver Station. Each + * time a value is requested the most recent value is returned. There is a + * single class instance for each controller and the mapping of ports to + * hardware buttons depends on the code in the Driver Station. * - * Only first party controllers from Sony are guaranteed to have the correct - * mapping, and only through the official NI DS. Sim is not guaranteed to have - * the same mapping, as well as any 3rd party controllers. + * Only first party controllers from Sony are guaranteed to have the + * correct mapping, and only through the official NI DS. Sim is not guaranteed + * to have the same mapping, as well as any 3rd party controllers. */ class PS4Controller : public GenericHID { public: /** - * Construct an instance of an PS4 controller. + * Construct an instance of a controller. * * The controller index is the USB port on the Driver Station. * @@ -45,18 +47,18 @@ class PS4Controller : public GenericHID { double GetLeftX() const; /** - * Get the X axis value of right side of the controller. + * Get the Y axis value of left side of the controller. * * @return the axis value. */ - double GetRightX() const; + double GetLeftY() const; /** - * Get the Y axis value of left side of the controller. + * Get the X axis value of right side of the controller. * * @return the axis value. */ - double GetLeftY() const; + double GetRightX() const; /** * Get the Y axis value of right side of the controller. @@ -66,324 +68,333 @@ class PS4Controller : public GenericHID { double GetRightY() const; /** - * Get the L2 axis value of the controller. Note that this axis is bound to - * the range of [0, 1] as opposed to the usual [-1, 1]. + * Get the left trigger 2 axis value of the controller. Note that this axis + * is bound to the range of [0, 1] as opposed to the usual [-1, 1]. * * @return the axis value. */ double GetL2Axis() const; /** - * Get the R2 axis value of the controller. Note that this axis is bound to - * the range of [0, 1] as opposed to the usual [-1, 1]. + * Get the right trigger 2 axis value of the controller. Note that this axis + * is bound to the range of [0, 1] as opposed to the usual [-1, 1]. * * @return the axis value. */ double GetR2Axis() const; /** - * Read the value of the Square button on the controller. + * Read the value of the square button on the controller. * * @return The state of the button. */ bool GetSquareButton() const; /** - * Whether the Square button was pressed since the last check. + * Whether the square button was pressed since the last check. * * @return Whether the button was pressed since the last check. */ bool GetSquareButtonPressed(); /** - * Whether the Square button was released since the last check. + * Whether the square button was released since the last check. * * @return Whether the button was released since the last check. */ bool GetSquareButtonReleased(); /** - * Constructs an event instance around the square button's digital signal. + * Constructs an event instance around the square button's + * digital signal. * * @param loop the event loop instance to attach the event to. - * @return an event instance representing the square button's digital signal - * attached to the given loop. + * @return an event instance representing the square button's + * digital signal attached to the given loop. */ BooleanEvent Square(EventLoop* loop) const; /** - * Read the value of the Cross button on the controller. + * Read the value of the cross button on the controller. * * @return The state of the button. */ bool GetCrossButton() const; /** - * Whether the Cross button was pressed since the last check. + * Whether the cross button was pressed since the last check. * * @return Whether the button was pressed since the last check. */ bool GetCrossButtonPressed(); /** - * Whether the Cross button was released since the last check. + * Whether the cross button was released since the last check. * * @return Whether the button was released since the last check. */ bool GetCrossButtonReleased(); /** - * Constructs an event instance around the cross button's digital signal. + * Constructs an event instance around the cross button's + * digital signal. * * @param loop the event loop instance to attach the event to. - * @return an event instance representing the cross button's digital signal - * attached to the given loop. + * @return an event instance representing the cross button's + * digital signal attached to the given loop. */ BooleanEvent Cross(EventLoop* loop) const; /** - * Read the value of the Circle button on the controller. + * Read the value of the circle button on the controller. * * @return The state of the button. */ bool GetCircleButton() const; /** - * Whether the Circle button was pressed since the last check. + * Whether the circle button was pressed since the last check. * * @return Whether the button was pressed since the last check. */ bool GetCircleButtonPressed(); /** - * Whether the Circle button was released since the last check. + * Whether the circle button was released since the last check. * * @return Whether the button was released since the last check. */ bool GetCircleButtonReleased(); /** - * Constructs an event instance around the circle button's digital signal. + * Constructs an event instance around the circle button's + * digital signal. * * @param loop the event loop instance to attach the event to. - * @return an event instance representing the circle button's digital signal - * attached to the given loop. + * @return an event instance representing the circle button's + * digital signal attached to the given loop. */ BooleanEvent Circle(EventLoop* loop) const; /** - * Read the value of the Triangle button on the controller. + * Read the value of the triangle button on the controller. * * @return The state of the button. */ bool GetTriangleButton() const; /** - * Whether the Triangle button was pressed since the last check. + * Whether the triangle button was pressed since the last check. * * @return Whether the button was pressed since the last check. */ bool GetTriangleButtonPressed(); /** - * Whether the Triangle button was released since the last check. + * Whether the triangle button was released since the last check. * * @return Whether the button was released since the last check. */ bool GetTriangleButtonReleased(); /** - * Constructs an event instance around the triangle button's digital signal. + * Constructs an event instance around the triangle button's + * digital signal. * * @param loop the event loop instance to attach the event to. - * @return an event instance representing the triangle button's digital signal - * attached to the given loop. + * @return an event instance representing the triangle button's + * digital signal attached to the given loop. */ BooleanEvent Triangle(EventLoop* loop) const; /** - * Read the value of the L1 button on the controller. + * Read the value of the left trigger 1 button on the controller. * * @return The state of the button. */ bool GetL1Button() const; /** - * Whether the L1 button was pressed since the last check. + * Whether the left trigger 1 button was pressed since the last check. * * @return Whether the button was pressed since the last check. */ bool GetL1ButtonPressed(); /** - * Whether the L1 button was released since the last check. + * Whether the left trigger 1 button was released since the last check. * * @return Whether the button was released since the last check. */ bool GetL1ButtonReleased(); /** - * Constructs an event instance around the L1 button's digital signal. + * Constructs an event instance around the left trigger 1 button's + * digital signal. * * @param loop the event loop instance to attach the event to. - * @return an event instance representing the L1 button's digital signal - * attached to the given loop. + * @return an event instance representing the left trigger 1 button's + * digital signal attached to the given loop. */ BooleanEvent L1(EventLoop* loop) const; /** - * Read the value of the R1 button on the controller. + * Read the value of the right trigger 1 button on the controller. * * @return The state of the button. */ bool GetR1Button() const; /** - * Whether the R1 button was pressed since the last check. + * Whether the right trigger 1 button was pressed since the last check. * * @return Whether the button was pressed since the last check. */ bool GetR1ButtonPressed(); /** - * Whether the R1 button was released since the last check. + * Whether the right trigger 1 button was released since the last check. * * @return Whether the button was released since the last check. */ bool GetR1ButtonReleased(); /** - * Constructs an event instance around the R1 button's digital signal. + * Constructs an event instance around the right trigger 1 button's + * digital signal. * * @param loop the event loop instance to attach the event to. - * @return an event instance representing the R1 button's digital signal - * attached to the given loop. + * @return an event instance representing the right trigger 1 button's + * digital signal attached to the given loop. */ BooleanEvent R1(EventLoop* loop) const; /** - * Read the value of the L2 button on the controller. + * Read the value of the left trigger 2 button on the controller. * * @return The state of the button. */ bool GetL2Button() const; /** - * Whether the L2 button was pressed since the last check. + * Whether the left trigger 2 button was pressed since the last check. * * @return Whether the button was pressed since the last check. */ bool GetL2ButtonPressed(); /** - * Whether the L2 button was released since the last check. + * Whether the left trigger 2 button was released since the last check. * * @return Whether the button was released since the last check. */ bool GetL2ButtonReleased(); /** - * Constructs an event instance around the L2 button's digital signal. + * Constructs an event instance around the left trigger 2 button's + * digital signal. * * @param loop the event loop instance to attach the event to. - * @return an event instance representing the L2 button's digital signal - * attached to the given loop. + * @return an event instance representing the left trigger 2 button's + * digital signal attached to the given loop. */ BooleanEvent L2(EventLoop* loop) const; /** - * Read the value of the R2 button on the controller. + * Read the value of the right trigger 2 button on the controller. * * @return The state of the button. */ bool GetR2Button() const; /** - * Whether the R2 button was pressed since the last check. + * Whether the right trigger 2 button was pressed since the last check. * * @return Whether the button was pressed since the last check. */ bool GetR2ButtonPressed(); /** - * Whether the R2 button was released since the last check. + * Whether the right trigger 2 button was released since the last check. * * @return Whether the button was released since the last check. */ bool GetR2ButtonReleased(); /** - * Constructs an event instance around the R2 button's digital signal. + * Constructs an event instance around the right trigger 2 button's + * digital signal. * * @param loop the event loop instance to attach the event to. - * @return an event instance representing the R2 button's digital signal - * attached to the given loop. + * @return an event instance representing the right trigger 2 button's + * digital signal attached to the given loop. */ BooleanEvent R2(EventLoop* loop) const; /** - * Read the value of the Share button on the controller. + * Read the value of the share button on the controller. * * @return The state of the button. */ bool GetShareButton() const; /** - * Whether the Share button was pressed since the last check. + * Whether the share button was pressed since the last check. * * @return Whether the button was pressed since the last check. */ bool GetShareButtonPressed(); /** - * Whether the Share button was released since the last check. + * Whether the share button was released since the last check. * * @return Whether the button was released since the last check. */ bool GetShareButtonReleased(); /** - * Constructs an event instance around the share button's digital signal. + * Constructs an event instance around the share button's + * digital signal. * * @param loop the event loop instance to attach the event to. - * @return an event instance representing the share button's digital signal - * attached to the given loop. + * @return an event instance representing the share button's + * digital signal attached to the given loop. */ BooleanEvent Share(EventLoop* loop) const; /** - * Read the value of the Options button on the controller. + * Read the value of the options button on the controller. * * @return The state of the button. */ bool GetOptionsButton() const; /** - * Whether the Options button was pressed since the last check. + * Whether the options button was pressed since the last check. * * @return Whether the button was pressed since the last check. */ bool GetOptionsButtonPressed(); /** - * Whether the Options button was released since the last check. + * Whether the options button was released since the last check. * * @return Whether the button was released since the last check. */ bool GetOptionsButtonReleased(); /** - * Constructs an event instance around the options button's digital signal. + * Constructs an event instance around the options button's + * digital signal. * * @param loop the event loop instance to attach the event to. - * @return an event instance representing the options button's digital signal - * attached to the given loop. + * @return an event instance representing the options button's + * digital signal attached to the given loop. */ BooleanEvent Options(EventLoop* loop) const; /** - * Read the value of the L3 button (pressing the left analog stick) on the - * controller. + * Read the value of the L3 (left stick) button on the controller. * * @return The state of the button. */ @@ -404,17 +415,17 @@ class PS4Controller : public GenericHID { bool GetL3ButtonReleased(); /** - * Constructs an event instance around the L3 button's digital signal. + * Constructs an event instance around the L3 (left stick) button's + * digital signal. * * @param loop the event loop instance to attach the event to. - * @return an event instance representing the L3 button's digital signal - * attached to the given loop. + * @return an event instance representing the L3 (left stick) button's + * digital signal attached to the given loop. */ BooleanEvent L3(EventLoop* loop) const; /** - * Read the value of the R3 button (pressing the right analog stick) on the - * controller. + * Read the value of the R3 (right stick) button on the controller. * * @return The state of the button. */ @@ -435,41 +446,43 @@ class PS4Controller : public GenericHID { bool GetR3ButtonReleased(); /** - * Constructs an event instance around the R3 button's digital signal. + * Constructs an event instance around the R3 (right stick) button's + * digital signal. * * @param loop the event loop instance to attach the event to. - * @return an event instance representing the R3 button's digital signal - * attached to the given loop. + * @return an event instance representing the R3 (right stick) button's + * digital signal attached to the given loop. */ BooleanEvent R3(EventLoop* loop) const; /** - * Read the value of the PS button on the controller. + * Read the value of the PlayStation button on the controller. * * @return The state of the button. */ bool GetPSButton() const; /** - * Whether the PS button was pressed since the last check. + * Whether the PlayStation button was pressed since the last check. * * @return Whether the button was pressed since the last check. */ bool GetPSButtonPressed(); /** - * Whether the PS button was released since the last check. + * Whether the PlayStation button was released since the last check. * * @return Whether the button was released since the last check. */ bool GetPSButtonReleased(); /** - * Constructs an event instance around the PS button's digital signal. + * Constructs an event instance around the PlayStation button's + * digital signal. * * @param loop the event loop instance to attach the event to. - * @return an event instance representing the PS button's digital signal - * attached to the given loop. + * @return an event instance representing the PlayStation button's + * digital signal attached to the given loop. */ BooleanEvent PS(EventLoop* loop) const; @@ -478,68 +491,88 @@ class PS4Controller : public GenericHID { * * @return The state of the button. */ - bool GetTouchpad() const; + bool GetTouchpadButton() const; /** - * Whether the touchpad was pressed since the last check. + * Whether the touchpad button was pressed since the last check. * - * @return Whether the touchpad was pressed since the last check. + * @return Whether the button was pressed since the last check. */ - bool GetTouchpadPressed(); + bool GetTouchpadButtonPressed(); /** - * Whether the touchpad was released since the last check. + * Whether the touchpad button was released since the last check. * - * @return Whether the touchpad was released since the last check. + * @return Whether the button was released since the last check. */ - bool GetTouchpadReleased(); + bool GetTouchpadButtonReleased(); /** - * Constructs an event instance around the touchpad's digital signal. + * Constructs an event instance around the touchpad button's + * digital signal. * * @param loop the event loop instance to attach the event to. - * @return an event instance representing the touchpad's digital signal - * attached to the given loop. + * @return an event instance representing the touchpad button's + * digital signal attached to the given loop. */ BooleanEvent Touchpad(EventLoop* loop) const; /** - * Represents a digital button on a PS4Controller. + * Read the value of the touchpad button on the controller. + * + * @return The state of the button. + */ + [[deprecated("Use GetTouchpadButton instead")]] + bool GetTouchpad() const; + /** + * Whether the touchpad was pressed since the last check. + * + * @return Whether the touchpad was pressed since the last check. + */ + [[deprecated("Use GetTouchpadButtonPressed instead")]] + bool GetTouchpadPressed(); + + /** + * Whether the touchpad was released since the last check. + * + * @return Whether the touchpad was released since the last check. */ + [[deprecated("Use GetTouchpadButtonReleased instead")]] + bool GetTouchpadReleased(); + + /** Represents a digital button on an PS4Controller. */ struct Button { /// Square button. static constexpr int kSquare = 1; - /// X button. + /// Cross button. static constexpr int kCross = 2; /// Circle button. static constexpr int kCircle = 3; /// Triangle button. static constexpr int kTriangle = 4; - /// Left Trigger 1 button. + /// Left trigger 1 button. static constexpr int kL1 = 5; - /// Right Trigger 1 button. + /// Right trigger 1 button. static constexpr int kR1 = 6; - /// Left Trigger 2 button. + /// Left trigger 2 button. static constexpr int kL2 = 7; - /// Right Trigger 2 button. + /// Right trigger 2 button. static constexpr int kR2 = 8; /// Share button. static constexpr int kShare = 9; - /// Option button. + /// Options button. static constexpr int kOptions = 10; - /// Left stick button. + /// L3 (left stick) button. static constexpr int kL3 = 11; - /// Right stick button. + /// R3 (right stick) button. static constexpr int kR3 = 12; /// PlayStation button. static constexpr int kPS = 13; - /// Touchpad click button. + /// Touchpad button. static constexpr int kTouchpad = 14; }; - /** - * Represents an axis on a PS4Controller. - */ + /** Represents an axis on an PS4Controller. */ struct Axis { /// Left X axis. static constexpr int kLeftX = 0; @@ -549,9 +582,9 @@ class PS4Controller : public GenericHID { static constexpr int kRightX = 2; /// Right Y axis. static constexpr int kRightY = 5; - /// Left Trigger 2. + /// Left trigger 2. static constexpr int kL2 = 3; - /// Right Trigger 2. + /// Right trigger 2. static constexpr int kR2 = 4; }; }; diff --git a/wpilibc/src/main/native/include/frc/PS5Controller.h b/wpilibc/src/generated/main/native/include/frc/PS5Controller.h similarity index 58% rename from wpilibc/src/main/native/include/frc/PS5Controller.h rename to wpilibc/src/generated/main/native/include/frc/PS5Controller.h index e9d52352304..461a853a98c 100644 --- a/wpilibc/src/main/native/include/frc/PS5Controller.h +++ b/wpilibc/src/generated/main/native/include/frc/PS5Controller.h @@ -2,6 +2,8 @@ // Open Source Software; you can modify and/or share it under the terms of // the WPILib BSD license file in the root directory of this project. +// THIS FILE WAS AUTO-GENERATED BY ./wpilibc/generate_hids.py. DO NOT MODIFY + #pragma once #include "frc/GenericHID.h" @@ -11,19 +13,19 @@ namespace frc { /** * Handle input from PS5 controllers connected to the Driver Station. * - * This class handles PS5 input that comes from the Driver Station. Each time - * a value is requested the most recent value is returned. There is a single - * class instance for each controller and the mapping of ports to hardware - * buttons depends on the code in the Driver Station. + * This class handles PS5 input that comes from the Driver Station. Each + * time a value is requested the most recent value is returned. There is a + * single class instance for each controller and the mapping of ports to + * hardware buttons depends on the code in the Driver Station. * - * Only first party controllers from Sony are guaranteed to have the correct - * mapping, and only through the official NI DS. Sim is not guaranteed to have - * the same mapping, as well as any 3rd party controllers. + * Only first party controllers from Sony are guaranteed to have the + * correct mapping, and only through the official NI DS. Sim is not guaranteed + * to have the same mapping, as well as any 3rd party controllers. */ class PS5Controller : public GenericHID { public: /** - * Construct an instance of an PS5 controller. + * Construct an instance of a controller. * * The controller index is the USB port on the Driver Station. * @@ -45,18 +47,18 @@ class PS5Controller : public GenericHID { double GetLeftX() const; /** - * Get the X axis value of right side of the controller. + * Get the Y axis value of left side of the controller. * * @return the axis value. */ - double GetRightX() const; + double GetLeftY() const; /** - * Get the Y axis value of left side of the controller. + * Get the X axis value of right side of the controller. * * @return the axis value. */ - double GetLeftY() const; + double GetRightX() const; /** * Get the Y axis value of right side of the controller. @@ -66,324 +68,333 @@ class PS5Controller : public GenericHID { double GetRightY() const; /** - * Get the L2 axis value of the controller. Note that this axis is bound to - * the range of [0, 1] as opposed to the usual [-1, 1]. + * Get the left trigger 2 axis value of the controller. Note that this axis + * is bound to the range of [0, 1] as opposed to the usual [-1, 1]. * * @return the axis value. */ double GetL2Axis() const; /** - * Get the R2 axis value of the controller. Note that this axis is bound to - * the range of [0, 1] as opposed to the usual [-1, 1]. + * Get the right trigger 2 axis value of the controller. Note that this axis + * is bound to the range of [0, 1] as opposed to the usual [-1, 1]. * * @return the axis value. */ double GetR2Axis() const; /** - * Read the value of the Square button on the controller. + * Read the value of the square button on the controller. * * @return The state of the button. */ bool GetSquareButton() const; /** - * Whether the Square button was pressed since the last check. + * Whether the square button was pressed since the last check. * * @return Whether the button was pressed since the last check. */ bool GetSquareButtonPressed(); /** - * Whether the Square button was released since the last check. + * Whether the square button was released since the last check. * * @return Whether the button was released since the last check. */ bool GetSquareButtonReleased(); /** - * Constructs an event instance around the square button's digital signal. + * Constructs an event instance around the square button's + * digital signal. * * @param loop the event loop instance to attach the event to. - * @return an event instance representing the square button's digital signal - * attached to the given loop. + * @return an event instance representing the square button's + * digital signal attached to the given loop. */ BooleanEvent Square(EventLoop* loop) const; /** - * Read the value of the Cross button on the controller. + * Read the value of the cross button on the controller. * * @return The state of the button. */ bool GetCrossButton() const; /** - * Whether the Cross button was pressed since the last check. + * Whether the cross button was pressed since the last check. * * @return Whether the button was pressed since the last check. */ bool GetCrossButtonPressed(); /** - * Whether the Cross button was released since the last check. + * Whether the cross button was released since the last check. * * @return Whether the button was released since the last check. */ bool GetCrossButtonReleased(); /** - * Constructs an event instance around the cross button's digital signal. + * Constructs an event instance around the cross button's + * digital signal. * * @param loop the event loop instance to attach the event to. - * @return an event instance representing the cross button's digital signal - * attached to the given loop. + * @return an event instance representing the cross button's + * digital signal attached to the given loop. */ BooleanEvent Cross(EventLoop* loop) const; /** - * Read the value of the Circle button on the controller. + * Read the value of the circle button on the controller. * * @return The state of the button. */ bool GetCircleButton() const; /** - * Whether the Circle button was pressed since the last check. + * Whether the circle button was pressed since the last check. * * @return Whether the button was pressed since the last check. */ bool GetCircleButtonPressed(); /** - * Whether the Circle button was released since the last check. + * Whether the circle button was released since the last check. * * @return Whether the button was released since the last check. */ bool GetCircleButtonReleased(); /** - * Constructs an event instance around the circle button's digital signal. + * Constructs an event instance around the circle button's + * digital signal. * * @param loop the event loop instance to attach the event to. - * @return an event instance representing the circle button's digital signal - * attached to the given loop. + * @return an event instance representing the circle button's + * digital signal attached to the given loop. */ BooleanEvent Circle(EventLoop* loop) const; /** - * Read the value of the Triangle button on the controller. + * Read the value of the triangle button on the controller. * * @return The state of the button. */ bool GetTriangleButton() const; /** - * Whether the Triangle button was pressed since the last check. + * Whether the triangle button was pressed since the last check. * * @return Whether the button was pressed since the last check. */ bool GetTriangleButtonPressed(); /** - * Whether the Triangle button was released since the last check. + * Whether the triangle button was released since the last check. * * @return Whether the button was released since the last check. */ bool GetTriangleButtonReleased(); /** - * Constructs an event instance around the triangle button's digital signal. + * Constructs an event instance around the triangle button's + * digital signal. * * @param loop the event loop instance to attach the event to. - * @return an event instance representing the triangle button's digital signal - * attached to the given loop. + * @return an event instance representing the triangle button's + * digital signal attached to the given loop. */ BooleanEvent Triangle(EventLoop* loop) const; /** - * Read the value of the L1 button on the controller. + * Read the value of the left trigger 1 button on the controller. * * @return The state of the button. */ bool GetL1Button() const; /** - * Whether the L1 button was pressed since the last check. + * Whether the left trigger 1 button was pressed since the last check. * * @return Whether the button was pressed since the last check. */ bool GetL1ButtonPressed(); /** - * Whether the L1 button was released since the last check. + * Whether the left trigger 1 button was released since the last check. * * @return Whether the button was released since the last check. */ bool GetL1ButtonReleased(); /** - * Constructs an event instance around the L1 button's digital signal. + * Constructs an event instance around the left trigger 1 button's + * digital signal. * * @param loop the event loop instance to attach the event to. - * @return an event instance representing the L1 button's digital signal - * attached to the given loop. + * @return an event instance representing the left trigger 1 button's + * digital signal attached to the given loop. */ BooleanEvent L1(EventLoop* loop) const; /** - * Read the value of the R1 button on the controller. + * Read the value of the right trigger 1 button on the controller. * * @return The state of the button. */ bool GetR1Button() const; /** - * Whether the R1 button was pressed since the last check. + * Whether the right trigger 1 button was pressed since the last check. * * @return Whether the button was pressed since the last check. */ bool GetR1ButtonPressed(); /** - * Whether the R1 button was released since the last check. + * Whether the right trigger 1 button was released since the last check. * * @return Whether the button was released since the last check. */ bool GetR1ButtonReleased(); /** - * Constructs an event instance around the R1 button's digital signal. + * Constructs an event instance around the right trigger 1 button's + * digital signal. * * @param loop the event loop instance to attach the event to. - * @return an event instance representing the R1 button's digital signal - * attached to the given loop. + * @return an event instance representing the right trigger 1 button's + * digital signal attached to the given loop. */ BooleanEvent R1(EventLoop* loop) const; /** - * Read the value of the L2 button on the controller. + * Read the value of the left trigger 2 button on the controller. * * @return The state of the button. */ bool GetL2Button() const; /** - * Whether the L2 button was pressed since the last check. + * Whether the left trigger 2 button was pressed since the last check. * * @return Whether the button was pressed since the last check. */ bool GetL2ButtonPressed(); /** - * Whether the L2 button was released since the last check. + * Whether the left trigger 2 button was released since the last check. * * @return Whether the button was released since the last check. */ bool GetL2ButtonReleased(); /** - * Constructs an event instance around the L2 button's digital signal. + * Constructs an event instance around the left trigger 2 button's + * digital signal. * * @param loop the event loop instance to attach the event to. - * @return an event instance representing the L2 button's digital signal - * attached to the given loop. + * @return an event instance representing the left trigger 2 button's + * digital signal attached to the given loop. */ BooleanEvent L2(EventLoop* loop) const; /** - * Read the value of the R2 button on the controller. + * Read the value of the right trigger 2 button on the controller. * * @return The state of the button. */ bool GetR2Button() const; /** - * Whether the R2 button was pressed since the last check. + * Whether the right trigger 2 button was pressed since the last check. * * @return Whether the button was pressed since the last check. */ bool GetR2ButtonPressed(); /** - * Whether the R2 button was released since the last check. + * Whether the right trigger 2 button was released since the last check. * * @return Whether the button was released since the last check. */ bool GetR2ButtonReleased(); /** - * Constructs an event instance around the R2 button's digital signal. + * Constructs an event instance around the right trigger 2 button's + * digital signal. * * @param loop the event loop instance to attach the event to. - * @return an event instance representing the R2 button's digital signal - * attached to the given loop. + * @return an event instance representing the right trigger 2 button's + * digital signal attached to the given loop. */ BooleanEvent R2(EventLoop* loop) const; /** - * Read the value of the Create button on the controller. + * Read the value of the create button on the controller. * * @return The state of the button. */ bool GetCreateButton() const; /** - * Whether the Create button was pressed since the last check. + * Whether the create button was pressed since the last check. * * @return Whether the button was pressed since the last check. */ bool GetCreateButtonPressed(); /** - * Whether the Create button was released since the last check. + * Whether the create button was released since the last check. * * @return Whether the button was released since the last check. */ bool GetCreateButtonReleased(); /** - * Constructs an event instance around the Create button's digital signal. + * Constructs an event instance around the create button's + * digital signal. * * @param loop the event loop instance to attach the event to. - * @return an event instance representing the Create button's digital signal - * attached to the given loop. + * @return an event instance representing the create button's + * digital signal attached to the given loop. */ BooleanEvent Create(EventLoop* loop) const; /** - * Read the value of the Options button on the controller. + * Read the value of the options button on the controller. * * @return The state of the button. */ bool GetOptionsButton() const; /** - * Whether the Options button was pressed since the last check. + * Whether the options button was pressed since the last check. * * @return Whether the button was pressed since the last check. */ bool GetOptionsButtonPressed(); /** - * Whether the Options button was released since the last check. + * Whether the options button was released since the last check. * * @return Whether the button was released since the last check. */ bool GetOptionsButtonReleased(); /** - * Constructs an event instance around the options button's digital signal. + * Constructs an event instance around the options button's + * digital signal. * * @param loop the event loop instance to attach the event to. - * @return an event instance representing the options button's digital signal - * attached to the given loop. + * @return an event instance representing the options button's + * digital signal attached to the given loop. */ BooleanEvent Options(EventLoop* loop) const; /** - * Read the value of the L3 button (pressing the left analog stick) on the - * controller. + * Read the value of the L3 (left stick) button on the controller. * * @return The state of the button. */ @@ -404,17 +415,17 @@ class PS5Controller : public GenericHID { bool GetL3ButtonReleased(); /** - * Constructs an event instance around the L3 button's digital signal. + * Constructs an event instance around the L3 (left stick) button's + * digital signal. * * @param loop the event loop instance to attach the event to. - * @return an event instance representing the L3 button's digital signal - * attached to the given loop. + * @return an event instance representing the L3 (left stick) button's + * digital signal attached to the given loop. */ BooleanEvent L3(EventLoop* loop) const; /** - * Read the value of the R3 button (pressing the right analog stick) on the - * controller. + * Read the value of the R3 (right stick) button on the controller. * * @return The state of the button. */ @@ -435,41 +446,43 @@ class PS5Controller : public GenericHID { bool GetR3ButtonReleased(); /** - * Constructs an event instance around the R3 button's digital signal. + * Constructs an event instance around the R3 (right stick) button's + * digital signal. * * @param loop the event loop instance to attach the event to. - * @return an event instance representing the R3 button's digital signal - * attached to the given loop. + * @return an event instance representing the R3 (right stick) button's + * digital signal attached to the given loop. */ BooleanEvent R3(EventLoop* loop) const; /** - * Read the value of the PS button on the controller. + * Read the value of the PlayStation button on the controller. * * @return The state of the button. */ bool GetPSButton() const; /** - * Whether the PS button was pressed since the last check. + * Whether the PlayStation button was pressed since the last check. * * @return Whether the button was pressed since the last check. */ bool GetPSButtonPressed(); /** - * Whether the PS button was released since the last check. + * Whether the PlayStation button was released since the last check. * * @return Whether the button was released since the last check. */ bool GetPSButtonReleased(); /** - * Constructs an event instance around the PS button's digital signal. + * Constructs an event instance around the PlayStation button's + * digital signal. * * @param loop the event loop instance to attach the event to. - * @return an event instance representing the PS button's digital signal - * attached to the given loop. + * @return an event instance representing the PlayStation button's + * digital signal attached to the given loop. */ BooleanEvent PS(EventLoop* loop) const; @@ -478,38 +491,60 @@ class PS5Controller : public GenericHID { * * @return The state of the button. */ - bool GetTouchpad() const; + bool GetTouchpadButton() const; /** - * Whether the touchpad was pressed since the last check. + * Whether the touchpad button was pressed since the last check. * - * @return Whether the touchpad was pressed since the last check. + * @return Whether the button was pressed since the last check. */ - bool GetTouchpadPressed(); + bool GetTouchpadButtonPressed(); /** - * Whether the touchpad was released since the last check. + * Whether the touchpad button was released since the last check. * - * @return Whether the touchpad was released since the last check. + * @return Whether the button was released since the last check. */ - bool GetTouchpadReleased(); + bool GetTouchpadButtonReleased(); /** - * Constructs an event instance around the touchpad's digital signal. + * Constructs an event instance around the touchpad button's + * digital signal. * * @param loop the event loop instance to attach the event to. - * @return an event instance representing the touchpad's digital signal - * attached to the given loop. + * @return an event instance representing the touchpad button's + * digital signal attached to the given loop. */ BooleanEvent Touchpad(EventLoop* loop) const; /** - * Represents a digital button on a PS5Controller. + * Read the value of the touchpad button on the controller. + * + * @return The state of the button. + */ + [[deprecated("Use GetTouchpadButton instead")]] + bool GetTouchpad() const; + /** + * Whether the touchpad was pressed since the last check. + * + * @return Whether the touchpad was pressed since the last check. + */ + [[deprecated("Use GetTouchpadButtonPressed instead")]] + bool GetTouchpadPressed(); + + /** + * Whether the touchpad was released since the last check. + * + * @return Whether the touchpad was released since the last check. */ + [[deprecated("Use GetTouchpadButtonReleased instead")]] + bool GetTouchpadReleased(); + + /** Represents a digital button on an PS5Controller. */ struct Button { /// Square button. static constexpr int kSquare = 1; - /// X button. + /// Cross button. static constexpr int kCross = 2; /// Circle button. static constexpr int kCircle = 3; @@ -527,19 +562,17 @@ class PS5Controller : public GenericHID { static constexpr int kCreate = 9; /// Options button. static constexpr int kOptions = 10; - /// Left stick button. + /// L3 (left stick) button. static constexpr int kL3 = 11; - /// Right stick button. + /// R3 (right stick) button. static constexpr int kR3 = 12; /// PlayStation button. static constexpr int kPS = 13; - /// Touchpad click button. + /// Touchpad button. static constexpr int kTouchpad = 14; }; - /** - * Represents an axis on a PS5Controller. - */ + /** Represents an axis on an PS5Controller. */ struct Axis { /// Left X axis. static constexpr int kLeftX = 0; @@ -549,9 +582,9 @@ class PS5Controller : public GenericHID { static constexpr int kRightX = 2; /// Right Y axis. static constexpr int kRightY = 5; - /// Left Trigger 2. + /// Left trigger 2. static constexpr int kL2 = 3; - /// Right Trigger 2. + /// Right trigger 2. static constexpr int kR2 = 4; }; }; diff --git a/wpilibc/src/main/native/include/frc/StadiaController.h b/wpilibc/src/generated/main/native/include/frc/StadiaController.h similarity index 68% rename from wpilibc/src/main/native/include/frc/StadiaController.h rename to wpilibc/src/generated/main/native/include/frc/StadiaController.h index cc9dbae981c..6a10aa213b0 100644 --- a/wpilibc/src/main/native/include/frc/StadiaController.h +++ b/wpilibc/src/generated/main/native/include/frc/StadiaController.h @@ -2,6 +2,8 @@ // Open Source Software; you can modify and/or share it under the terms of // the WPILib BSD license file in the root directory of this project. +// THIS FILE WAS AUTO-GENERATED BY ./wpilibc/generate_hids.py. DO NOT MODIFY + #pragma once #include "frc/GenericHID.h" @@ -9,18 +11,21 @@ namespace frc { /** - * Handle input from Stadia controllers connected to the Driver - * Station. + * Handle input from Stadia controllers connected to the Driver Station. + * + * This class handles Stadia input that comes from the Driver Station. Each + * time a value is requested the most recent value is returned. There is a + * single class instance for each controller and the mapping of ports to + * hardware buttons depends on the code in the Driver Station. * - * This class handles Stadia input that comes from the Driver Station. Each time - * a value is requested the most recent value is returned. There is a single - * class instance for each controller and the mapping of ports to hardware - * buttons depends on the code in the Driver Station. + * Only first party controllers from Google are guaranteed to have the + * correct mapping, and only through the official NI DS. Sim is not guaranteed + * to have the same mapping, as well as any 3rd party controllers. */ class StadiaController : public GenericHID { public: /** - * Construct an instance of a Stadia controller. + * Construct an instance of a controller. * * The controller index is the USB port on the Driver Station. * @@ -37,270 +42,278 @@ class StadiaController : public GenericHID { /** * Get the X axis value of left side of the controller. * - * @return the axis value + * @return the axis value. */ double GetLeftX() const; /** * Get the X axis value of right side of the controller. * - * @return the axis value + * @return the axis value. */ double GetRightX() const; /** * Get the Y axis value of left side of the controller. * - * @return the axis value + * @return the axis value. */ double GetLeftY() const; /** * Get the Y axis value of right side of the controller. * - * @return the axis value + * @return the axis value. */ double GetRightY() const; /** - * Read the value of the left bumper (LB) button on the controller. + * Read the value of the A button on the controller. * - * @return the state of the button + * @return The state of the button. */ - bool GetLeftBumper() const; + bool GetAButton() const; /** - * Read the value of the right bumper (RB) button on the controller. + * Whether the A button was pressed since the last check. * - * @return the state of the button + * @return Whether the button was pressed since the last check. */ - bool GetRightBumper() const; + bool GetAButtonPressed(); /** - * Whether the left bumper (LB) was pressed since the last check. + * Whether the A button was released since the last check. * - * @return Whether the button was pressed since the last check + * @return Whether the button was released since the last check. */ - bool GetLeftBumperPressed(); + bool GetAButtonReleased(); /** - * Whether the right bumper (RB) was pressed since the last check. + * Constructs an event instance around the A button's + * digital signal. * - * @return Whether the button was pressed since the last check + * @param loop the event loop instance to attach the event to. + * @return an event instance representing the A button's + * digital signal attached to the given loop. */ - bool GetRightBumperPressed(); + BooleanEvent A(EventLoop* loop) const; /** - * Whether the left bumper (LB) was released since the last check. + * Read the value of the B button on the controller. * - * @return Whether the button was released since the last check. + * @return The state of the button. */ - bool GetLeftBumperReleased(); + bool GetBButton() const; /** - * Whether the right bumper (RB) was released since the last check. + * Whether the B button was pressed since the last check. * - * @return Whether the button was released since the last check. + * @return Whether the button was pressed since the last check. */ - bool GetRightBumperReleased(); + bool GetBButtonPressed(); /** - * Constructs an event instance around the left bumper's digital signal. + * Whether the B button was released since the last check. * - * @param loop the event loop instance to attach the event to. - * @return an event instance representing the left bumper's digital signal - * attached to the given loop. + * @return Whether the button was released since the last check. */ - BooleanEvent LeftBumper(EventLoop* loop) const; + bool GetBButtonReleased(); /** - * Constructs an event instance around the right bumper's digital signal. + * Constructs an event instance around the B button's + * digital signal. * * @param loop the event loop instance to attach the event to. - * @return an event instance representing the right bumper's digital signal - * attached to the given loop. + * @return an event instance representing the B button's + * digital signal attached to the given loop. */ - BooleanEvent RightBumper(EventLoop* loop) const; + BooleanEvent B(EventLoop* loop) const; /** - * Read the value of the left stick button (LSB) on the controller. + * Read the value of the X button on the controller. * - * @return the state of the button + * @return The state of the button. */ - bool GetLeftStickButton() const; + bool GetXButton() const; /** - * Read the value of the right stick button (RSB) on the controller. + * Whether the X button was pressed since the last check. * - * @return the state of the button + * @return Whether the button was pressed since the last check. */ - bool GetRightStickButton() const; + bool GetXButtonPressed(); /** - * Whether the left stick button (LSB) was pressed since the last check. + * Whether the X button was released since the last check. * - * @return Whether the button was pressed since the last check. + * @return Whether the button was released since the last check. */ - bool GetLeftStickButtonPressed(); + bool GetXButtonReleased(); /** - * Whether the right stick button (RSB) was pressed since the last check. + * Constructs an event instance around the X button's + * digital signal. * - * @return Whether the button was pressed since the last check + * @param loop the event loop instance to attach the event to. + * @return an event instance representing the X button's + * digital signal attached to the given loop. */ - bool GetRightStickButtonPressed(); + BooleanEvent X(EventLoop* loop) const; /** - * Whether the left stick button (LSB) was released since the last check. + * Read the value of the Y button on the controller. * - * @return Whether the button was released since the last check. + * @return The state of the button. */ - bool GetLeftStickButtonReleased(); + bool GetYButton() const; /** - * Whether the right stick button (RSB) was released since the last check. + * Whether the Y button was pressed since the last check. * - * @return Whether the button was released since the last check. + * @return Whether the button was pressed since the last check. */ - bool GetRightStickButtonReleased(); + bool GetYButtonPressed(); /** - * Constructs an event instance around the left stick's digital signal. + * Whether the Y button was released since the last check. * - * @param loop the event loop instance to attach the event to. - * @return an event instance representing the left stick's digital signal - * attached to the given loop. + * @return Whether the button was released since the last check. */ - BooleanEvent LeftStick(EventLoop* loop) const; + bool GetYButtonReleased(); /** - * Constructs an event instance around the right stick's digital signal. + * Constructs an event instance around the Y button's + * digital signal. * * @param loop the event loop instance to attach the event to. - * @return an event instance representing the right stick's digital signal - * attached to the given loop. + * @return an event instance representing the Y button's + * digital signal attached to the given loop. */ - BooleanEvent RightStick(EventLoop* loop) const; + BooleanEvent Y(EventLoop* loop) const; /** - * Read the value of the A button on the controller. + * Read the value of the left bumper button on the controller. * * @return The state of the button. */ - bool GetAButton() const; + bool GetLeftBumperButton() const; /** - * Whether the A button was pressed since the last check. + * Whether the left bumper button was pressed since the last check. * * @return Whether the button was pressed since the last check. */ - bool GetAButtonPressed(); + bool GetLeftBumperButtonPressed(); /** - * Whether the A button was released since the last check. + * Whether the left bumper button was released since the last check. * * @return Whether the button was released since the last check. */ - bool GetAButtonReleased(); + bool GetLeftBumperButtonReleased(); /** - * Constructs an event instance around the A button's digital signal. + * Constructs an event instance around the left bumper button's + * digital signal. * * @param loop the event loop instance to attach the event to. - * @return an event instance representing the A button's digital signal - * attached to the given loop. + * @return an event instance representing the left bumper button's + * digital signal attached to the given loop. */ - BooleanEvent A(EventLoop* loop) const; + BooleanEvent LeftBumper(EventLoop* loop) const; /** - * Read the value of the B button on the controller. + * Read the value of the right bumper button on the controller. * * @return The state of the button. */ - bool GetBButton() const; + bool GetRightBumperButton() const; /** - * Whether the B button was pressed since the last check. + * Whether the right bumper button was pressed since the last check. * * @return Whether the button was pressed since the last check. */ - bool GetBButtonPressed(); + bool GetRightBumperButtonPressed(); /** - * Whether the B button was released since the last check. + * Whether the right bumper button was released since the last check. * * @return Whether the button was released since the last check. */ - bool GetBButtonReleased(); + bool GetRightBumperButtonReleased(); /** - * Constructs an event instance around the B button's digital signal. + * Constructs an event instance around the right bumper button's + * digital signal. * * @param loop the event loop instance to attach the event to. - * @return an event instance representing the B button's digital signal - * attached to the given loop. + * @return an event instance representing the right bumper button's + * digital signal attached to the given loop. */ - BooleanEvent B(EventLoop* loop) const; + BooleanEvent RightBumper(EventLoop* loop) const; /** - * Read the value of the X button on the controller. + * Read the value of the left stick button on the controller. * * @return The state of the button. */ - bool GetXButton() const; + bool GetLeftStickButton() const; /** - * Whether the X button was pressed since the last check. + * Whether the left stick button was pressed since the last check. * * @return Whether the button was pressed since the last check. */ - bool GetXButtonPressed(); + bool GetLeftStickButtonPressed(); /** - * Whether the X button was released since the last check. + * Whether the left stick button was released since the last check. * * @return Whether the button was released since the last check. */ - bool GetXButtonReleased(); + bool GetLeftStickButtonReleased(); /** - * Constructs an event instance around the X button's digital signal. + * Constructs an event instance around the left stick button's + * digital signal. * * @param loop the event loop instance to attach the event to. - * @return an event instance representing the X button's digital signal - * attached to the given loop. + * @return an event instance representing the left stick button's + * digital signal attached to the given loop. */ - BooleanEvent X(EventLoop* loop) const; + BooleanEvent LeftStick(EventLoop* loop) const; /** - * Read the value of the Y button on the controller. + * Read the value of the right stick button on the controller. * * @return The state of the button. */ - bool GetYButton() const; + bool GetRightStickButton() const; /** - * Whether the Y button was pressed since the last check. + * Whether the right stick button was pressed since the last check. * * @return Whether the button was pressed since the last check. */ - bool GetYButtonPressed(); + bool GetRightStickButtonPressed(); /** - * Whether the Y button was released since the last check. + * Whether the right stick button was released since the last check. * * @return Whether the button was released since the last check. */ - bool GetYButtonReleased(); + bool GetRightStickButtonReleased(); /** - * Constructs an event instance around the Y button's digital signal. + * Constructs an event instance around the right stick button's + * digital signal. * * @param loop the event loop instance to attach the event to. - * @return an event instance representing the Y button's digital signal - * attached to the given loop. + * @return an event instance representing the right stick button's + * digital signal attached to the given loop. */ - BooleanEvent Y(EventLoop* loop) const; + BooleanEvent RightStick(EventLoop* loop) const; /** * Read the value of the ellipses button on the controller. @@ -324,11 +337,12 @@ class StadiaController : public GenericHID { bool GetEllipsesButtonReleased(); /** - * Constructs an event instance around the ellipses button's digital signal. + * Constructs an event instance around the ellipses button's + * digital signal. * * @param loop the event loop instance to attach the event to. - * @return an event instance representing the ellipses button's digital signal - * attached to the given loop. + * @return an event instance representing the ellipses button's + * digital signal attached to the given loop. */ BooleanEvent Ellipses(EventLoop* loop) const; @@ -354,11 +368,12 @@ class StadiaController : public GenericHID { bool GetHamburgerButtonReleased(); /** - * Constructs an event instance around the hamburger button's digital signal. + * Constructs an event instance around the hamburger button's + * digital signal. * * @param loop the event loop instance to attach the event to. - * @return an event instance representing the hamburger button's digital - * signal attached to the given loop. + * @return an event instance representing the hamburger button's + * digital signal attached to the given loop. */ BooleanEvent Hamburger(EventLoop* loop) const; @@ -384,139 +399,188 @@ class StadiaController : public GenericHID { bool GetStadiaButtonReleased(); /** - * Constructs an event instance around the stadia button's digital signal. + * Constructs an event instance around the stadia button's + * digital signal. * * @param loop the event loop instance to attach the event to. - * @return an event instance representing the stadia button's digital signal - * attached to the given loop. + * @return an event instance representing the stadia button's + * digital signal attached to the given loop. */ BooleanEvent Stadia(EventLoop* loop) const; /** - * Read the value of the google button on the controller. + * Read the value of the right trigger button on the controller. * * @return The state of the button. */ - bool GetGoogleButton() const; + bool GetRightTriggerButton() const; /** - * Whether the google button was pressed since the last check. + * Whether the right trigger button was pressed since the last check. * * @return Whether the button was pressed since the last check. */ - bool GetGoogleButtonPressed(); + bool GetRightTriggerButtonPressed(); /** - * Whether the google button was released since the last check. + * Whether the right trigger button was released since the last check. * * @return Whether the button was released since the last check. */ - bool GetGoogleButtonReleased(); + bool GetRightTriggerButtonReleased(); /** - * Constructs an event instance around the google button's digital signal. + * Constructs an event instance around the right trigger button's + * digital signal. * * @param loop the event loop instance to attach the event to. - * @return an event instance representing the google button's digital signal - * attached to the given loop. + * @return an event instance representing the right trigger button's + * digital signal attached to the given loop. */ - BooleanEvent Google(EventLoop* loop) const; + BooleanEvent RightTrigger(EventLoop* loop) const; /** - * Read the value of the frame button on the controller. + * Read the value of the left trigger button on the controller. * * @return The state of the button. */ - bool GetFrameButton() const; + bool GetLeftTriggerButton() const; /** - * Whether the frame button was pressed since the last check. + * Whether the left trigger button was pressed since the last check. * * @return Whether the button was pressed since the last check. */ - bool GetFrameButtonPressed(); + bool GetLeftTriggerButtonPressed(); /** - * Whether the frame button was released since the last check. + * Whether the left trigger button was released since the last check. * * @return Whether the button was released since the last check. */ - bool GetFrameButtonReleased(); + bool GetLeftTriggerButtonReleased(); /** - * Constructs an event instance around the frame button's digital signal. + * Constructs an event instance around the left trigger button's + * digital signal. * * @param loop the event loop instance to attach the event to. - * @return an event instance representing the frame button's digital signal - * attached to the given loop. + * @return an event instance representing the left trigger button's + * digital signal attached to the given loop. */ - BooleanEvent Frame(EventLoop* loop) const; + BooleanEvent LeftTrigger(EventLoop* loop) const; /** - * Read the value of the left trigger button on the controller. + * Read the value of the google button on the controller. * * @return The state of the button. */ - bool GetLeftTriggerButton() const; + bool GetGoogleButton() const; /** - * Whether the left trigger button was pressed since the last check. + * Whether the google button was pressed since the last check. * * @return Whether the button was pressed since the last check. */ - bool GetLeftTriggerButtonPressed(); + bool GetGoogleButtonPressed(); /** - * Whether the left trigger button was released since the last check. + * Whether the google button was released since the last check. * * @return Whether the button was released since the last check. */ - bool GetLeftTriggerButtonReleased(); + bool GetGoogleButtonReleased(); /** - * Constructs an event instance around the left trigger button's digital - * signal. + * Constructs an event instance around the google button's + * digital signal. * * @param loop the event loop instance to attach the event to. - * @return an event instance representing the left trigger button's digital - * signal attached to the given loop. + * @return an event instance representing the google button's + * digital signal attached to the given loop. */ - BooleanEvent LeftTrigger(EventLoop* loop) const; + BooleanEvent Google(EventLoop* loop) const; /** - * Read the value of the right trigger button on the controller. + * Read the value of the frame button on the controller. * * @return The state of the button. */ - bool GetRightTriggerButton() const; + bool GetFrameButton() const; /** - * Whether the right trigger button was pressed since the last check. + * Whether the frame button was pressed since the last check. * * @return Whether the button was pressed since the last check. */ - bool GetRightTriggerButtonPressed(); + bool GetFrameButtonPressed(); /** - * Whether the right trigger button was released since the last check. + * Whether the frame button was released since the last check. * * @return Whether the button was released since the last check. */ - bool GetRightTriggerButtonReleased(); + bool GetFrameButtonReleased(); /** - * Constructs an event instance around the right trigger button's digital - * signal. + * Constructs an event instance around the frame button's + * digital signal. * * @param loop the event loop instance to attach the event to. - * @return an event instance representing the right trigger button's digital - * signal attached to the given loop. + * @return an event instance representing the frame button's + * digital signal attached to the given loop. */ - BooleanEvent RightTrigger(EventLoop* loop) const; + BooleanEvent Frame(EventLoop* loop) const; + + /** + * Read the value of the left bumper (LB) button on the controller. + * + * @return the state of the button + */ + [[deprecated("Use GetLeftBumperButton instead")]] + bool GetLeftBumper() const; + + /** + * Read the value of the right bumper (RB) button on the controller. + * + * @return the state of the button + */ + [[deprecated("Use GetRightBumperButton instead")]] + bool GetRightBumper() const; + + /** + * Whether the left bumper (LB) was pressed since the last check. + * + * @return Whether the button was pressed since the last check + */ + [[deprecated("Use GetLeftBumperButtonPressed instead")]] + bool GetLeftBumperPressed(); /** - * Represents a digital button on a StadiaController. + * Whether the right bumper (RB) was pressed since the last check. + * + * @return Whether the button was pressed since the last check */ + [[deprecated("Use GetRightBumperButtonPressed instead")]] + bool GetRightBumperPressed(); + + /** + * Whether the left bumper (LB) was released since the last check. + * + * @return Whether the button was released since the last check. + */ + [[deprecated("Use GetLeftBumperButtonReleased instead")]] + bool GetLeftBumperReleased(); + + /** + * Whether the right bumper (RB) was released since the last check. + * + * @return Whether the button was released since the last check. + */ + [[deprecated("Use GetRightBumperButtonReleased instead")]] + bool GetRightBumperReleased(); + + /** Represents a digital button on an StadiaController. */ struct Button { /// A button. static constexpr int kA = 1; @@ -550,18 +614,16 @@ class StadiaController : public GenericHID { static constexpr int kFrame = 15; }; - /** - * Represents an axis on a StadiaController. - */ + /** Represents an axis on an StadiaController. */ struct Axis { /// Left X axis. static constexpr int kLeftX = 0; /// Right X axis. - static constexpr int kRightX = 4; + static constexpr int kRightX = 3; /// Left Y axis. static constexpr int kLeftY = 1; /// Right Y axis. - static constexpr int kRightY = 5; + static constexpr int kRightY = 4; }; }; diff --git a/wpilibc/src/main/native/include/frc/XboxController.h b/wpilibc/src/generated/main/native/include/frc/XboxController.h similarity index 66% rename from wpilibc/src/main/native/include/frc/XboxController.h rename to wpilibc/src/generated/main/native/include/frc/XboxController.h index 4b720c1fc72..0a8357df16b 100644 --- a/wpilibc/src/main/native/include/frc/XboxController.h +++ b/wpilibc/src/generated/main/native/include/frc/XboxController.h @@ -2,6 +2,8 @@ // Open Source Software; you can modify and/or share it under the terms of // the WPILib BSD license file in the root directory of this project. +// THIS FILE WAS AUTO-GENERATED BY ./wpilibc/generate_hids.py. DO NOT MODIFY + #pragma once #include "frc/GenericHID.h" @@ -9,13 +11,12 @@ namespace frc { /** - * Handle input from Xbox 360 or Xbox One controllers connected to the Driver - * Station. + * Handle input from Xbox controllers connected to the Driver Station. * - * This class handles Xbox input that comes from the Driver Station. Each time a - * value is requested the most recent value is returned. There is a single class - * instance for each controller and the mapping of ports to hardware buttons - * depends on the code in the Driver Station. + * This class handles Xbox input that comes from the Driver Station. Each + * time a value is requested the most recent value is returned. There is a + * single class instance for each controller and the mapping of ports to + * hardware buttons depends on the code in the Driver Station. * * Only first party controllers from Microsoft are guaranteed to have the * correct mapping, and only through the official NI DS. Sim is not guaranteed @@ -24,7 +25,7 @@ namespace frc { class XboxController : public GenericHID { public: /** - * Construct an instance of an Xbox controller. + * Construct an instance of a controller. * * The controller index is the USB port on the Driver Station. * @@ -41,424 +42,482 @@ class XboxController : public GenericHID { /** * Get the X axis value of left side of the controller. * - * @return the axis value + * @return the axis value. */ double GetLeftX() const; /** * Get the X axis value of right side of the controller. * - * @return the axis value + * @return the axis value. */ double GetRightX() const; /** * Get the Y axis value of left side of the controller. * - * @return the axis value + * @return the axis value. */ double GetLeftY() const; /** * Get the Y axis value of right side of the controller. * - * @return the axis value + * @return the axis value. */ double GetRightY() const; /** - * Get the left trigger (LT) axis value of the controller. Note that this axis + * Get the left trigger axis value of the controller. Note that this axis * is bound to the range of [0, 1] as opposed to the usual [-1, 1]. * - * @return the axis value + * @return the axis value. */ double GetLeftTriggerAxis() const; /** - * Get the right trigger (RT) axis value of the controller. Note that this - * axis is bound to the range of [0, 1] as opposed to the usual [-1, 1]. + * Constructs an event instance around the axis value of the left trigger. + * The returned trigger will be true when the axis value is greater than + * {@code threshold}. + * @param threshold the minimum axis value for the returned event to be true. + * This value should be in the range [0, 1] where 0 is the unpressed state of + * the axis. + * @param loop the event loop instance to attach the event to. + * @return an event instance that is true when the left trigger's axis + * exceeds the provided threshold, attached to the given event loop + */ + BooleanEvent LeftTrigger(double threshold, EventLoop* loop) const; + + /** + * Constructs an event instance around the axis value of the left trigger. + * The returned trigger will be true when the axis value is greater than 0.5. + * @param loop the event loop instance to attach the event to. + * @return an event instance that is true when the left trigger's axis + * exceeds 0.5, attached to the given event loop + */ + BooleanEvent LeftTrigger(EventLoop* loop) const; + + /** + * Get the right trigger axis value of the controller. Note that this axis + * is bound to the range of [0, 1] as opposed to the usual [-1, 1]. * - * @return the axis value + * @return the axis value. */ double GetRightTriggerAxis() const; /** - * Read the value of the left bumper (LB) button on the controller. + * Constructs an event instance around the axis value of the right trigger. + * The returned trigger will be true when the axis value is greater than + * {@code threshold}. + * @param threshold the minimum axis value for the returned event to be true. + * This value should be in the range [0, 1] where 0 is the unpressed state of + * the axis. + * @param loop the event loop instance to attach the event to. + * @return an event instance that is true when the right trigger's axis + * exceeds the provided threshold, attached to the given event loop + */ + BooleanEvent RightTrigger(double threshold, EventLoop* loop) const; + + /** + * Constructs an event instance around the axis value of the right trigger. + * The returned trigger will be true when the axis value is greater than 0.5. + * @param loop the event loop instance to attach the event to. + * @return an event instance that is true when the right trigger's axis + * exceeds 0.5, attached to the given event loop + */ + BooleanEvent RightTrigger(EventLoop* loop) const; + + /** + * Read the value of the A button on the controller. * - * @return the state of the button + * @return The state of the button. */ - bool GetLeftBumper() const; + bool GetAButton() const; /** - * Read the value of the right bumper (RB) button on the controller. + * Whether the A button was pressed since the last check. * - * @return the state of the button + * @return Whether the button was pressed since the last check. */ - bool GetRightBumper() const; + bool GetAButtonPressed(); /** - * Whether the left bumper (LB) was pressed since the last check. + * Whether the A button was released since the last check. * - * @return Whether the button was pressed since the last check + * @return Whether the button was released since the last check. */ - bool GetLeftBumperPressed(); + bool GetAButtonReleased(); /** - * Whether the right bumper (RB) was pressed since the last check. + * Constructs an event instance around the A button's + * digital signal. * - * @return Whether the button was pressed since the last check + * @param loop the event loop instance to attach the event to. + * @return an event instance representing the A button's + * digital signal attached to the given loop. */ - bool GetRightBumperPressed(); + BooleanEvent A(EventLoop* loop) const; /** - * Whether the left bumper (LB) was released since the last check. + * Read the value of the B button on the controller. * - * @return Whether the button was released since the last check. + * @return The state of the button. */ - bool GetLeftBumperReleased(); + bool GetBButton() const; /** - * Whether the right bumper (RB) was released since the last check. + * Whether the B button was pressed since the last check. * - * @return Whether the button was released since the last check. + * @return Whether the button was pressed since the last check. */ - bool GetRightBumperReleased(); + bool GetBButtonPressed(); /** - * Constructs an event instance around the left bumper's digital signal. + * Whether the B button was released since the last check. * - * @param loop the event loop instance to attach the event to. - * @return an event instance representing the left bumper's digital signal - * attached to the given loop. + * @return Whether the button was released since the last check. */ - BooleanEvent LeftBumper(EventLoop* loop) const; + bool GetBButtonReleased(); /** - * Constructs an event instance around the right bumper's digital signal. + * Constructs an event instance around the B button's + * digital signal. * * @param loop the event loop instance to attach the event to. - * @return an event instance representing the right bumper's digital signal - * attached to the given loop. + * @return an event instance representing the B button's + * digital signal attached to the given loop. */ - BooleanEvent RightBumper(EventLoop* loop) const; + BooleanEvent B(EventLoop* loop) const; /** - * Read the value of the left stick button (LSB) on the controller. + * Read the value of the X button on the controller. * - * @return the state of the button + * @return The state of the button. */ - bool GetLeftStickButton() const; + bool GetXButton() const; /** - * Read the value of the right stick button (RSB) on the controller. + * Whether the X button was pressed since the last check. * - * @return the state of the button + * @return Whether the button was pressed since the last check. */ - bool GetRightStickButton() const; + bool GetXButtonPressed(); /** - * Whether the left stick button (LSB) was pressed since the last check. + * Whether the X button was released since the last check. * - * @return Whether the button was pressed since the last check. + * @return Whether the button was released since the last check. */ - bool GetLeftStickButtonPressed(); + bool GetXButtonReleased(); /** - * Whether the right stick button (RSB) was pressed since the last check. + * Constructs an event instance around the X button's + * digital signal. * - * @return Whether the button was pressed since the last check + * @param loop the event loop instance to attach the event to. + * @return an event instance representing the X button's + * digital signal attached to the given loop. */ - bool GetRightStickButtonPressed(); + BooleanEvent X(EventLoop* loop) const; /** - * Whether the left stick button (LSB) was released since the last check. + * Read the value of the Y button on the controller. * - * @return Whether the button was released since the last check. + * @return The state of the button. */ - bool GetLeftStickButtonReleased(); + bool GetYButton() const; /** - * Whether the right stick button (RSB) was released since the last check. + * Whether the Y button was pressed since the last check. * - * @return Whether the button was released since the last check. + * @return Whether the button was pressed since the last check. */ - bool GetRightStickButtonReleased(); + bool GetYButtonPressed(); /** - * Constructs an event instance around the left stick's digital signal. + * Whether the Y button was released since the last check. * - * @param loop the event loop instance to attach the event to. - * @return an event instance representing the left stick's digital signal - * attached to the given loop. + * @return Whether the button was released since the last check. */ - BooleanEvent LeftStick(EventLoop* loop) const; + bool GetYButtonReleased(); /** - * Constructs an event instance around the right stick's digital signal. + * Constructs an event instance around the Y button's + * digital signal. * * @param loop the event loop instance to attach the event to. - * @return an event instance representing the right stick's digital signal - * attached to the given loop. + * @return an event instance representing the Y button's + * digital signal attached to the given loop. */ - BooleanEvent RightStick(EventLoop* loop) const; + BooleanEvent Y(EventLoop* loop) const; /** - * Read the value of the A button on the controller. + * Read the value of the left bumper button on the controller. * * @return The state of the button. */ - bool GetAButton() const; + bool GetLeftBumperButton() const; /** - * Whether the A button was pressed since the last check. + * Whether the left bumper button was pressed since the last check. * * @return Whether the button was pressed since the last check. */ - bool GetAButtonPressed(); + bool GetLeftBumperButtonPressed(); /** - * Whether the A button was released since the last check. + * Whether the left bumper button was released since the last check. * * @return Whether the button was released since the last check. */ - bool GetAButtonReleased(); + bool GetLeftBumperButtonReleased(); /** - * Constructs an event instance around the A button's digital signal. + * Constructs an event instance around the left bumper button's + * digital signal. * * @param loop the event loop instance to attach the event to. - * @return an event instance representing the A button's digital signal - * attached to the given loop. + * @return an event instance representing the left bumper button's + * digital signal attached to the given loop. */ - BooleanEvent A(EventLoop* loop) const; + BooleanEvent LeftBumper(EventLoop* loop) const; /** - * Read the value of the B button on the controller. + * Read the value of the right bumper button on the controller. * * @return The state of the button. */ - bool GetBButton() const; + bool GetRightBumperButton() const; /** - * Whether the B button was pressed since the last check. + * Whether the right bumper button was pressed since the last check. * * @return Whether the button was pressed since the last check. */ - bool GetBButtonPressed(); + bool GetRightBumperButtonPressed(); /** - * Whether the B button was released since the last check. + * Whether the right bumper button was released since the last check. * * @return Whether the button was released since the last check. */ - bool GetBButtonReleased(); + bool GetRightBumperButtonReleased(); /** - * Constructs an event instance around the B button's digital signal. + * Constructs an event instance around the right bumper button's + * digital signal. * * @param loop the event loop instance to attach the event to. - * @return an event instance representing the B button's digital signal - * attached to the given loop. + * @return an event instance representing the right bumper button's + * digital signal attached to the given loop. */ - BooleanEvent B(EventLoop* loop) const; + BooleanEvent RightBumper(EventLoop* loop) const; /** - * Read the value of the X button on the controller. + * Read the value of the back button on the controller. * * @return The state of the button. */ - bool GetXButton() const; + bool GetBackButton() const; /** - * Whether the X button was pressed since the last check. + * Whether the back button was pressed since the last check. * * @return Whether the button was pressed since the last check. */ - bool GetXButtonPressed(); + bool GetBackButtonPressed(); /** - * Whether the X button was released since the last check. + * Whether the back button was released since the last check. * * @return Whether the button was released since the last check. */ - bool GetXButtonReleased(); + bool GetBackButtonReleased(); /** - * Constructs an event instance around the X button's digital signal. + * Constructs an event instance around the back button's + * digital signal. * * @param loop the event loop instance to attach the event to. - * @return an event instance representing the X button's digital signal - * attached to the given loop. + * @return an event instance representing the back button's + * digital signal attached to the given loop. */ - BooleanEvent X(EventLoop* loop) const; + BooleanEvent Back(EventLoop* loop) const; /** - * Read the value of the Y button on the controller. + * Read the value of the start button on the controller. * * @return The state of the button. */ - bool GetYButton() const; + bool GetStartButton() const; /** - * Whether the Y button was pressed since the last check. + * Whether the start button was pressed since the last check. * * @return Whether the button was pressed since the last check. */ - bool GetYButtonPressed(); + bool GetStartButtonPressed(); /** - * Whether the Y button was released since the last check. + * Whether the start button was released since the last check. * * @return Whether the button was released since the last check. */ - bool GetYButtonReleased(); + bool GetStartButtonReleased(); /** - * Constructs an event instance around the Y button's digital signal. + * Constructs an event instance around the start button's + * digital signal. * * @param loop the event loop instance to attach the event to. - * @return an event instance representing the Y button's digital signal - * attached to the given loop. + * @return an event instance representing the start button's + * digital signal attached to the given loop. */ - BooleanEvent Y(EventLoop* loop) const; + BooleanEvent Start(EventLoop* loop) const; /** - * Read the value of the back button on the controller. + * Read the value of the left stick button on the controller. * * @return The state of the button. */ - bool GetBackButton() const; + bool GetLeftStickButton() const; /** - * Whether the back button was pressed since the last check. + * Whether the left stick button was pressed since the last check. * * @return Whether the button was pressed since the last check. */ - bool GetBackButtonPressed(); + bool GetLeftStickButtonPressed(); /** - * Whether the back button was released since the last check. + * Whether the left stick button was released since the last check. * * @return Whether the button was released since the last check. */ - bool GetBackButtonReleased(); + bool GetLeftStickButtonReleased(); /** - * Constructs an event instance around the back button's digital signal. + * Constructs an event instance around the left stick button's + * digital signal. * * @param loop the event loop instance to attach the event to. - * @return an event instance representing the back button's digital signal - * attached to the given loop. + * @return an event instance representing the left stick button's + * digital signal attached to the given loop. */ - BooleanEvent Back(EventLoop* loop) const; + BooleanEvent LeftStick(EventLoop* loop) const; /** - * Read the value of the start button on the controller. + * Read the value of the right stick button on the controller. * * @return The state of the button. */ - bool GetStartButton() const; + bool GetRightStickButton() const; /** - * Whether the start button was pressed since the last check. + * Whether the right stick button was pressed since the last check. * * @return Whether the button was pressed since the last check. */ - bool GetStartButtonPressed(); + bool GetRightStickButtonPressed(); /** - * Whether the start button was released since the last check. + * Whether the right stick button was released since the last check. * * @return Whether the button was released since the last check. */ - bool GetStartButtonReleased(); + bool GetRightStickButtonReleased(); /** - * Constructs an event instance around the start button's digital signal. + * Constructs an event instance around the right stick button's + * digital signal. * * @param loop the event loop instance to attach the event to. - * @return an event instance representing the start button's digital signal - * attached to the given loop. + * @return an event instance representing the right stick button's + * digital signal attached to the given loop. */ - BooleanEvent Start(EventLoop* loop) const; + BooleanEvent RightStick(EventLoop* loop) const; /** - * Constructs an event instance around the axis value of the left trigger. The - * returned trigger will be true when the axis value is greater than {@code - * threshold}. - * @param threshold the minimum axis value for the returned event to be true. - * This value should be in the range [0, 1] where 0 is the unpressed state of - * the axis. - * @param loop the event loop instance to attach the event to. - * @return an event instance that is true when the left trigger's axis exceeds - * the provided threshold, attached to the given event loop + * Read the value of the left bumper (LB) button on the controller. + * + * @return the state of the button */ - BooleanEvent LeftTrigger(double threshold, EventLoop* loop) const; + [[deprecated("Use GetLeftBumperButton instead")]] + bool GetLeftBumper() const; /** - * Constructs an event instance around the axis value of the left trigger. - * The returned trigger will be true when the axis value is greater than 0.5. - * @param loop the event loop instance to attach the event to. - * @return an event instance that is true when the left trigger's axis - * exceeds 0.5, attached to the given event loop + * Read the value of the right bumper (RB) button on the controller. + * + * @return the state of the button */ - BooleanEvent LeftTrigger(EventLoop* loop) const; + [[deprecated("Use GetRightBumperButton instead")]] + bool GetRightBumper() const; /** - * Constructs an event instance around the axis value of the right trigger. - * The returned trigger will be true when the axis value is greater than - * {@code threshold}. - * @param threshold the minimum axis value for the returned event to be true. - * This value should be in the range [0, 1] where 0 is the unpressed state of - * the axis. - * @param loop the event loop instance to attach the event to. - * @return an event instance that is true when the right trigger's axis - * exceeds the provided threshold, attached to the given event loop + * Whether the left bumper (LB) was pressed since the last check. + * + * @return Whether the button was pressed since the last check */ - BooleanEvent RightTrigger(double threshold, EventLoop* loop) const; + [[deprecated("Use GetLeftBumperButtonPressed instead")]] + bool GetLeftBumperPressed(); /** - * Constructs an event instance around the axis value of the right trigger. - * The returned trigger will be true when the axis value is greater than 0.5. - * @param loop the event loop instance to attach the event to. - * @return an event instance that is true when the right trigger's axis - * exceeds 0.5, attached to the given event loop + * Whether the right bumper (RB) was pressed since the last check. + * + * @return Whether the button was pressed since the last check */ - BooleanEvent RightTrigger(EventLoop* loop) const; + [[deprecated("Use GetRightBumperButtonPressed instead")]] + bool GetRightBumperPressed(); + + /** + * Whether the left bumper (LB) was released since the last check. + * + * @return Whether the button was released since the last check. + */ + [[deprecated("Use GetLeftBumperButtonReleased instead")]] + bool GetLeftBumperReleased(); + + /** + * Whether the right bumper (RB) was released since the last check. + * + * @return Whether the button was released since the last check. + */ + [[deprecated("Use GetRightBumperButtonReleased instead")]] + bool GetRightBumperReleased(); /** Represents a digital button on an XboxController. */ struct Button { - /// Left bumper. - static constexpr int kLeftBumper = 5; - /// Right bumper. - static constexpr int kRightBumper = 6; - /// Left stick. - static constexpr int kLeftStick = 9; - /// Right stick. - static constexpr int kRightStick = 10; - /// A. + /// A button. static constexpr int kA = 1; - /// B. + /// B button. static constexpr int kB = 2; - /// X. + /// X button. static constexpr int kX = 3; - /// Y. + /// Y button. static constexpr int kY = 4; - /// Back. + /// Left bumper button. + static constexpr int kLeftBumper = 5; + /// Right bumper button. + static constexpr int kRightBumper = 6; + /// Back button. static constexpr int kBack = 7; - /// Start. + /// Start button. static constexpr int kStart = 8; + /// Left stick button. + static constexpr int kLeftStick = 9; + /// Right stick button. + static constexpr int kRightStick = 10; }; /** Represents an axis on an XboxController. */ struct Axis { - /// Left X. + /// Left X axis. static constexpr int kLeftX = 0; - /// Right X. + /// Right X axis. static constexpr int kRightX = 4; - /// Left Y. + /// Left Y axis. static constexpr int kLeftY = 1; - /// Right Y. + /// Right Y axis. static constexpr int kRightY = 5; /// Left trigger. static constexpr int kLeftTrigger = 2; diff --git a/wpilibc/src/main/native/include/frc/simulation/PS4ControllerSim.h b/wpilibc/src/generated/main/native/include/frc/simulation/PS4ControllerSim.h similarity index 65% rename from wpilibc/src/main/native/include/frc/simulation/PS4ControllerSim.h rename to wpilibc/src/generated/main/native/include/frc/simulation/PS4ControllerSim.h index a599ad98d63..79dd5ecec73 100644 --- a/wpilibc/src/main/native/include/frc/simulation/PS4ControllerSim.h +++ b/wpilibc/src/generated/main/native/include/frc/simulation/PS4ControllerSim.h @@ -2,6 +2,8 @@ // Open Source Software; you can modify and/or share it under the terms of // the WPILib BSD license file in the root directory of this project. +// THIS FILE WAS AUTO-GENERATED BY ./wpilibc/generate_hids.py. DO NOT MODIFY + #pragma once #include "frc/simulation/GenericHIDSim.h" @@ -32,112 +34,112 @@ class PS4ControllerSim : public GenericHIDSim { explicit PS4ControllerSim(int port); /** - * Change the X axis value of the controller's left stick. + * Change the left X value of the controller's joystick. * * @param value the new value */ void SetLeftX(double value); /** - * Change the X axis value of the controller's right stick. + * Change the left Y value of the controller's joystick. * * @param value the new value */ - void SetRightX(double value); + void SetLeftY(double value); /** - * Change the Y axis value of the controller's left stick. + * Change the right X value of the controller's joystick. * * @param value the new value */ - void SetLeftY(double value); + void SetRightX(double value); /** - * Change the Y axis value of the controller's right stick. + * Change the right Y value of the controller's joystick. * * @param value the new value */ void SetRightY(double value); /** - * Change the L2 axis axis value of the controller. + * Change the value of the left trigger 2 axis on the controller. * * @param value the new value */ void SetL2Axis(double value); /** - * Change the R2 axis value of the controller. + * Change the value of the right trigger 2 axis on the controller. * * @param value the new value */ void SetR2Axis(double value); /** - * Change the value of the Square button on the controller. + * Change the value of the square button on the controller. * * @param value the new value */ void SetSquareButton(bool value); /** - * Change the value of the Cross button on the controller. + * Change the value of the cross button on the controller. * * @param value the new value */ void SetCrossButton(bool value); /** - * Change the value of the Circle button on the controller. + * Change the value of the circle button on the controller. * * @param value the new value */ void SetCircleButton(bool value); /** - * Change the value of the Triangle button on the controller. + * Change the value of the triangle button on the controller. * * @param value the new value */ void SetTriangleButton(bool value); /** - * Change the value of the L1 button on the controller. + * Change the value of the left trigger 1 button on the controller. * * @param value the new value */ void SetL1Button(bool value); /** - * Change the value of the R1 button on the controller. + * Change the value of the right trigger 1 button on the controller. * * @param value the new value */ void SetR1Button(bool value); /** - * Change the value of the L2 button on the controller. + * Change the value of the left trigger 2 button on the controller. * * @param value the new value */ void SetL2Button(bool value); /** - * Change the value of the R2 button on the controller. + * Change the value of the right trigger 2 button on the controller. * * @param value the new value */ void SetR2Button(bool value); /** - * Change the value of the Share button on the controller. + * Change the value of the share button on the controller. * * @param value the new value */ void SetShareButton(bool value); /** - * Change the value of the Options button on the controller. + * Change the value of the options button on the controller. * * @param value the new value */ @@ -158,7 +160,7 @@ class PS4ControllerSim : public GenericHIDSim { void SetR3Button(bool value); /** - * Change the value of the PS button on the controller. + * Change the value of the PlayStation button on the controller. * * @param value the new value */ @@ -169,7 +171,16 @@ class PS4ControllerSim : public GenericHIDSim { * * @param value the new value */ + void SetTouchpadButton(bool value); + + /** + * Change the value of the touchpad button on the controller. + * + * @param value the new value + */ + [[deprecated("Use SetTouchpadButton instead")]] void SetTouchpad(bool value); + }; } // namespace sim diff --git a/wpilibc/src/main/native/include/frc/simulation/PS5ControllerSim.h b/wpilibc/src/generated/main/native/include/frc/simulation/PS5ControllerSim.h similarity index 65% rename from wpilibc/src/main/native/include/frc/simulation/PS5ControllerSim.h rename to wpilibc/src/generated/main/native/include/frc/simulation/PS5ControllerSim.h index 6b9e2c7b2b3..e3762bbf204 100644 --- a/wpilibc/src/main/native/include/frc/simulation/PS5ControllerSim.h +++ b/wpilibc/src/generated/main/native/include/frc/simulation/PS5ControllerSim.h @@ -2,6 +2,8 @@ // Open Source Software; you can modify and/or share it under the terms of // the WPILib BSD license file in the root directory of this project. +// THIS FILE WAS AUTO-GENERATED BY ./wpilibc/generate_hids.py. DO NOT MODIFY + #pragma once #include "frc/simulation/GenericHIDSim.h" @@ -32,112 +34,112 @@ class PS5ControllerSim : public GenericHIDSim { explicit PS5ControllerSim(int port); /** - * Change the X axis value of the controller's left stick. + * Change the left X value of the controller's joystick. * * @param value the new value */ void SetLeftX(double value); /** - * Change the X axis value of the controller's right stick. + * Change the left Y value of the controller's joystick. * * @param value the new value */ - void SetRightX(double value); + void SetLeftY(double value); /** - * Change the Y axis value of the controller's left stick. + * Change the right X value of the controller's joystick. * * @param value the new value */ - void SetLeftY(double value); + void SetRightX(double value); /** - * Change the Y axis value of the controller's right stick. + * Change the right Y value of the controller's joystick. * * @param value the new value */ void SetRightY(double value); /** - * Change the L2 axis axis value of the controller. + * Change the value of the left trigger 2 axis on the controller. * * @param value the new value */ void SetL2Axis(double value); /** - * Change the R2 axis value of the controller. + * Change the value of the right trigger 2 axis on the controller. * * @param value the new value */ void SetR2Axis(double value); /** - * Change the value of the Square button on the controller. + * Change the value of the square button on the controller. * * @param value the new value */ void SetSquareButton(bool value); /** - * Change the value of the Cross button on the controller. + * Change the value of the cross button on the controller. * * @param value the new value */ void SetCrossButton(bool value); /** - * Change the value of the Circle button on the controller. + * Change the value of the circle button on the controller. * * @param value the new value */ void SetCircleButton(bool value); /** - * Change the value of the Triangle button on the controller. + * Change the value of the triangle button on the controller. * * @param value the new value */ void SetTriangleButton(bool value); /** - * Change the value of the L1 button on the controller. + * Change the value of the left trigger 1 button on the controller. * * @param value the new value */ void SetL1Button(bool value); /** - * Change the value of the R1 button on the controller. + * Change the value of the right trigger 1 button on the controller. * * @param value the new value */ void SetR1Button(bool value); /** - * Change the value of the L2 button on the controller. + * Change the value of the left trigger 2 button on the controller. * * @param value the new value */ void SetL2Button(bool value); /** - * Change the value of the R2 button on the controller. + * Change the value of the right trigger 2 button on the controller. * * @param value the new value */ void SetR2Button(bool value); /** - * Change the value of the Create button on the controller. + * Change the value of the create button on the controller. * * @param value the new value */ void SetCreateButton(bool value); /** - * Change the value of the Options button on the controller. + * Change the value of the options button on the controller. * * @param value the new value */ @@ -158,7 +160,7 @@ class PS5ControllerSim : public GenericHIDSim { void SetR3Button(bool value); /** - * Change the value of the PS button on the controller. + * Change the value of the PlayStation button on the controller. * * @param value the new value */ @@ -169,7 +171,16 @@ class PS5ControllerSim : public GenericHIDSim { * * @param value the new value */ + void SetTouchpadButton(bool value); + + /** + * Change the value of the touchpad button on the controller. + * + * @param value the new value + */ + [[deprecated("Use SetTouchpadButton instead")]] void SetTouchpad(bool value); + }; } // namespace sim diff --git a/wpilibc/src/generated/main/native/include/frc/simulation/StadiaControllerSim.h b/wpilibc/src/generated/main/native/include/frc/simulation/StadiaControllerSim.h new file mode 100644 index 00000000000..532328ab629 --- /dev/null +++ b/wpilibc/src/generated/main/native/include/frc/simulation/StadiaControllerSim.h @@ -0,0 +1,172 @@ +// Copyright (c) FIRST and other WPILib contributors. +// Open Source Software; you can modify and/or share it under the terms of +// the WPILib BSD license file in the root directory of this project. + +// THIS FILE WAS AUTO-GENERATED BY ./wpilibc/generate_hids.py. DO NOT MODIFY + +#pragma once + +#include "frc/simulation/GenericHIDSim.h" + +namespace frc { + +class StadiaController; + +namespace sim { + +/** + * Class to control a simulated Stadia controller. + */ +class StadiaControllerSim : public GenericHIDSim { + public: + /** + * Constructs from a StadiaController object. + * + * @param joystick controller to simulate + */ + explicit StadiaControllerSim(const StadiaController& joystick); + + /** + * Constructs from a joystick port number. + * + * @param port port number + */ + explicit StadiaControllerSim(int port); + + /** + * Change the left X value of the controller's joystick. + * + * @param value the new value + */ + void SetLeftX(double value); + + /** + * Change the right X value of the controller's joystick. + * + * @param value the new value + */ + void SetRightX(double value); + + /** + * Change the left Y value of the controller's joystick. + * + * @param value the new value + */ + void SetLeftY(double value); + + /** + * Change the right Y value of the controller's joystick. + * + * @param value the new value + */ + void SetRightY(double value); + + /** + * Change the value of the A button on the controller. + * + * @param value the new value + */ + void SetAButton(bool value); + + /** + * Change the value of the B button on the controller. + * + * @param value the new value + */ + void SetBButton(bool value); + + /** + * Change the value of the X button on the controller. + * + * @param value the new value + */ + void SetXButton(bool value); + + /** + * Change the value of the Y button on the controller. + * + * @param value the new value + */ + void SetYButton(bool value); + + /** + * Change the value of the left bumper button on the controller. + * + * @param value the new value + */ + void SetLeftBumperButton(bool value); + + /** + * Change the value of the right bumper button on the controller. + * + * @param value the new value + */ + void SetRightBumperButton(bool value); + + /** + * Change the value of the left stick button on the controller. + * + * @param value the new value + */ + void SetLeftStickButton(bool value); + + /** + * Change the value of the right stick button on the controller. + * + * @param value the new value + */ + void SetRightStickButton(bool value); + + /** + * Change the value of the ellipses button on the controller. + * + * @param value the new value + */ + void SetEllipsesButton(bool value); + + /** + * Change the value of the hamburger button on the controller. + * + * @param value the new value + */ + void SetHamburgerButton(bool value); + + /** + * Change the value of the stadia button on the controller. + * + * @param value the new value + */ + void SetStadiaButton(bool value); + + /** + * Change the value of the right trigger button on the controller. + * + * @param value the new value + */ + void SetRightTriggerButton(bool value); + + /** + * Change the value of the left trigger button on the controller. + * + * @param value the new value + */ + void SetLeftTriggerButton(bool value); + + /** + * Change the value of the google button on the controller. + * + * @param value the new value + */ + void SetGoogleButton(bool value); + + /** + * Change the value of the frame button on the controller. + * + * @param value the new value + */ + void SetFrameButton(bool value); + +}; + +} // namespace sim +} // namespace frc diff --git a/wpilibc/src/main/native/include/frc/simulation/XboxControllerSim.h b/wpilibc/src/generated/main/native/include/frc/simulation/XboxControllerSim.h similarity index 60% rename from wpilibc/src/main/native/include/frc/simulation/XboxControllerSim.h rename to wpilibc/src/generated/main/native/include/frc/simulation/XboxControllerSim.h index e609ff04ab3..06d6ad6d6e3 100644 --- a/wpilibc/src/main/native/include/frc/simulation/XboxControllerSim.h +++ b/wpilibc/src/generated/main/native/include/frc/simulation/XboxControllerSim.h @@ -2,6 +2,8 @@ // Open Source Software; you can modify and/or share it under the terms of // the WPILib BSD license file in the root directory of this project. +// THIS FILE WAS AUTO-GENERATED BY ./wpilibc/generate_hids.py. DO NOT MODIFY + #pragma once #include "frc/simulation/GenericHIDSim.h" @@ -13,7 +15,7 @@ class XboxController; namespace sim { /** - * Class to control a simulated Xbox 360 or Xbox One controller. + * Class to control a simulated Xbox controller. */ class XboxControllerSim : public GenericHIDSim { public: @@ -32,116 +34,133 @@ class XboxControllerSim : public GenericHIDSim { explicit XboxControllerSim(int port); /** - * Change the X axis value of the controller's left stick. + * Change the left X value of the controller's joystick. * * @param value the new value */ void SetLeftX(double value); /** - * Change the X axis value of the controller's right stick. + * Change the right X value of the controller's joystick. * * @param value the new value */ void SetRightX(double value); /** - * Change the Y axis value of the controller's left stick. + * Change the left Y value of the controller's joystick. * * @param value the new value */ void SetLeftY(double value); /** - * Change the Y axis value of the controller's right stick. + * Change the right Y value of the controller's joystick. * * @param value the new value */ void SetRightY(double value); /** - * Change the left trigger axis value of the joystick. + * Change the value of the left trigger axis on the controller. * * @param value the new value */ void SetLeftTriggerAxis(double value); /** - * Change the right trigger axis value of the joystick. + * Change the value of the right trigger axis on the controller. * * @param value the new value */ void SetRightTriggerAxis(double value); /** - * Change the left bumper value of the joystick. + * Change the value of the A button on the controller. * * @param value the new value */ - void SetLeftBumper(bool value); + void SetAButton(bool value); /** - * Change the right bumper value of the joystick. + * Change the value of the B button on the controller. * * @param value the new value */ - void SetRightBumper(bool value); + void SetBButton(bool value); /** - * Change the left button value of the joystick. + * Change the value of the X button on the controller. * * @param value the new value */ - void SetLeftStickButton(bool value); + void SetXButton(bool value); /** - * Change the right button value of the joystick. + * Change the value of the Y button on the controller. * * @param value the new value */ - void SetRightStickButton(bool value); + void SetYButton(bool value); /** - * Change the value of the A button. + * Change the value of the left bumper button on the controller. * * @param value the new value */ - void SetAButton(bool value); + void SetLeftBumperButton(bool value); /** - * Change the value of the B button. + * Change the value of the right bumper button on the controller. * * @param value the new value */ - void SetBButton(bool value); + void SetRightBumperButton(bool value); /** - * Change the value of the X button. + * Change the value of the back button on the controller. * * @param value the new value */ - void SetXButton(bool value); + void SetBackButton(bool value); /** - * Change the value of the Y button. + * Change the value of the start button on the controller. * * @param value the new value */ - void SetYButton(bool value); + void SetStartButton(bool value); /** - * Change the value of the Back button. + * Change the value of the left stick button on the controller. * * @param value the new value */ - void SetBackButton(bool value); + void SetLeftStickButton(bool value); /** - * Change the value of the Start button. + * Change the value of the right stick button on the controller. * * @param value the new value */ - void SetStartButton(bool value); + void SetRightStickButton(bool value); + + /** + * Change the left bumper value of the joystick. + * + * @param value the new value + */ + [[deprecated("Use SetLeftBumperButton instead")]] + void SetLeftBumper(bool value); + + /** + * Change the right bumper value of the joystick. + * + * @param value the new value + */ + [[deprecated("Use SetRightBumperButton instead")]] + void SetRightBumper(bool value); + }; } // namespace sim diff --git a/wpilibc/src/main/native/cpp/LEDPattern.cpp b/wpilibc/src/main/native/cpp/LEDPattern.cpp new file mode 100644 index 00000000000..2b745e9645d --- /dev/null +++ b/wpilibc/src/main/native/cpp/LEDPattern.cpp @@ -0,0 +1,305 @@ +// Copyright (c) FIRST and other WPILib contributors. +// Open Source Software; you can modify and/or share it under the terms of +// the WPILib BSD license file in the root directory of this project. + +#include "frc/LEDPattern.h" + +#include +#include +#include + +#include +#include + +#include "frc/MathUtil.h" + +using namespace frc; + +LEDPattern::LEDPattern(LEDPatternFn impl) : m_impl(std::move(impl)) {} + +void LEDPattern::ApplyTo(std::span data, + LEDWriterFn writer) const { + m_impl(data, writer); +} + +void LEDPattern::ApplyTo(std::span data) const { + ApplyTo(data, [&](int index, Color color) { data[index].SetLED(color); }); +} + +LEDPattern LEDPattern::Reversed() { + return LEDPattern{[self = *this](auto data, auto writer) { + self.ApplyTo(data, [&](int i, Color color) { + writer((data.size() - 1) - i, color); + }); + }}; +} + +LEDPattern LEDPattern::OffsetBy(int offset) { + return LEDPattern{[=, self = *this](auto data, auto writer) { + self.ApplyTo(data, [&data, &writer, offset](int i, Color color) { + int shiftedIndex = + frc::FloorMod(i + offset, static_cast(data.size())); + writer(shiftedIndex, color); + }); + }}; +} + +LEDPattern LEDPattern::ScrollAtRelativeSpeed(units::hertz_t velocity) { + // velocity is in terms of LED lengths per second (1_hz = full cycle per + // second, 0.5_hz = half cycle per second, 2_hz = two cycles per second) + // Invert and multiply by 1,000,000 to get microseconds + double periodMicros = 1e6 / velocity.value(); + + return LEDPattern{[=, self = *this](auto data, auto writer) { + auto bufLen = data.size(); + auto now = wpi::Now(); + + // index should move by (bufLen) / (period) + double t = + (now % static_cast(std::floor(periodMicros))) / periodMicros; + int offset = static_cast(std::floor(t * bufLen)); + + self.ApplyTo(data, [=](int i, Color color) { + // floorMod so if the offset is negative, we still get positive outputs + int shiftedIndex = frc::FloorMod(i + offset, static_cast(bufLen)); + writer(shiftedIndex, color); + }); + }}; +} + +LEDPattern LEDPattern::ScrollAtAbsoluteSpeed( + units::meters_per_second_t velocity, units::meter_t ledSpacing) { + // Velocity is in terms of meters per second + // Multiply by 1,000,000 to use microseconds instead of seconds + auto microsPerLed = + static_cast(std::floor((ledSpacing / velocity).value() * 1e6)); + + return LEDPattern{[=, self = *this](auto data, auto writer) { + auto bufLen = data.size(); + auto now = wpi::Now(); + + // every step in time that's a multiple of microsPerLED will increment + // the offset by 1 + // cast unsigned int64 `now` to a signed int64 so we can get negative + // offset values for negative velocities + auto offset = static_cast(now) / microsPerLed; + + self.ApplyTo(data, [=, &writer](int i, Color color) { + // FloorMod so if the offset is negative, we still get positive outputs + int shiftedIndex = frc::FloorMod(i + offset, static_cast(bufLen)); + + writer(shiftedIndex, color); + }); + }}; +} + +LEDPattern LEDPattern::Blink(units::second_t onTime, units::second_t offTime) { + auto totalMicros = units::microsecond_t{onTime + offTime}.to(); + auto onMicros = units::microsecond_t{onTime}.to(); + + return LEDPattern{[=, self = *this](auto data, auto writer) { + if (wpi::Now() % totalMicros < onMicros) { + self.ApplyTo(data, writer); + } else { + LEDPattern::kOff.ApplyTo(data, writer); + } + }}; +} + +LEDPattern LEDPattern::Blink(units::second_t onTime) { + return LEDPattern::Blink(onTime, onTime); +} + +LEDPattern LEDPattern::SynchronizedBlink(std::function signal) { + return LEDPattern{[=, self = *this](auto data, auto writer) { + if (signal()) { + self.ApplyTo(data, writer); + } else { + LEDPattern::kOff.ApplyTo(data, writer); + } + }}; +} + +LEDPattern LEDPattern::Breathe(units::second_t period) { + auto periodMicros = units::microsecond_t{period}; + + return LEDPattern{[periodMicros, self = *this](auto data, auto writer) { + self.ApplyTo(data, [&writer, periodMicros](int i, Color color) { + double t = (wpi::Now() % periodMicros.to()) / + periodMicros.to(); + double phase = t * 2 * std::numbers::pi; + + // Apply the cosine function and shift its output from [-1, 1] to [0, 1] + // Use cosine so the period starts at 100% brightness + double dim = (std::cos(phase) + 1) / 2.0; + + writer(i, Color{color.red * dim, color.green * dim, color.blue * dim}); + }); + }}; +} + +LEDPattern LEDPattern::OverlayOn(const LEDPattern& base) { + return LEDPattern{[self = *this, base](auto data, auto writer) { + // write the base pattern down first... + base.ApplyTo(data, writer); + + // ... then, overwrite with illuminated LEDs from the overlay + self.ApplyTo(data, [&](int i, Color color) { + if (color.red > 0 || color.green > 0 || color.blue > 0) { + writer(i, color); + } + }); + }}; +} + +LEDPattern LEDPattern::Blend(const LEDPattern& other) { + return LEDPattern{[self = *this, other](auto data, auto writer) { + // Apply the current pattern down as normal... + self.ApplyTo(data, writer); + + other.ApplyTo(data, [&](int i, Color color) { + // ... then read the result and average it with the output from the other + // pattern + writer(i, Color{(data[i].r / 255.0 + color.red) / 2, + (data[i].g / 255.0 + color.green) / 2, + (data[i].b / 255.0 + color.blue) / 2}); + }); + }}; +} + +LEDPattern LEDPattern::Mask(const LEDPattern& mask) { + return LEDPattern{[self = *this, mask](auto data, auto writer) { + // Apply the current pattern down as normal... + self.ApplyTo(data, writer); + + mask.ApplyTo(data, [&](int i, Color color) { + auto currentColor = data[i]; + // ... then perform a bitwise AND operation on each channel to apply the + // mask + writer(i, Color{currentColor.r & static_cast(255 * color.red), + currentColor.g & static_cast(255 * color.green), + currentColor.b & static_cast(255 * color.blue)}); + }); + }}; +} + +LEDPattern LEDPattern::AtBrightness(double relativeBrightness) { + return LEDPattern{[relativeBrightness, self = *this](auto data, auto writer) { + self.ApplyTo(data, [&](int i, Color color) { + writer(i, Color{color.red * relativeBrightness, + color.green * relativeBrightness, + color.blue * relativeBrightness}); + }); + }}; +} + +// Static constants and functions + +LEDPattern LEDPattern::kOff = LEDPattern::Solid(Color::kBlack); + +LEDPattern LEDPattern::Solid(const Color color) { + return LEDPattern{[=](auto data, auto writer) { + auto bufLen = data.size(); + for (size_t i = 0; i < bufLen; i++) { + writer(i, color); + } + }}; +} + +LEDPattern LEDPattern::ProgressMaskLayer( + std::function progressFunction) { + return LEDPattern{[=](auto data, auto writer) { + double progress = std::clamp(progressFunction(), 0.0, 1.0); + auto bufLen = data.size(); + size_t max = bufLen * progress; + + for (size_t led = 0; led < max; led++) { + writer(led, Color::kWhite); + } + for (size_t led = max; led < bufLen; led++) { + writer(led, Color::kBlack); + } + }}; +} + +LEDPattern LEDPattern::Steps(std::span> steps) { + if (steps.size() == 0) { + // no colors specified + return LEDPattern::kOff; + } + if (steps.size() == 1 && steps[0].first == 0) { + // only one color specified, just show a static color + return LEDPattern::Solid(steps[0].second); + } + + return LEDPattern{[steps = std::vector(steps.begin(), steps.end())]( + auto data, auto writer) { + auto bufLen = data.size(); + + // precompute relevant positions for this buffer so we don't need to do a + // check on every single LED index + std::unordered_map stopPositions; + + for (auto step : steps) { + stopPositions[std::floor(step.first * bufLen)] = step.second; + } + auto currentColor = Color::kBlack; + for (size_t led = 0; led < bufLen; led++) { + if (stopPositions.contains(led)) { + currentColor = stopPositions[led]; + } + writer(led, currentColor); + } + }}; +} + +LEDPattern LEDPattern::Steps( + std::initializer_list> steps) { + return Steps(std::span{steps.begin(), steps.end()}); +} + +LEDPattern LEDPattern::Gradient(std::span colors) { + if (colors.size() == 0) { + // no colors specified + return LEDPattern::kOff; + } + if (colors.size() == 1) { + // only one color specified, just show a static color + return LEDPattern::Solid(colors[0]); + } + + return LEDPattern{[colors = std::vector(colors.begin(), colors.end())]( + auto data, auto writer) { + size_t numSegments = colors.size(); + auto bufLen = data.size(); + int ledsPerSegment = bufLen / numSegments; + + for (size_t led = 0; led < bufLen; led++) { + int colorIndex = (led / ledsPerSegment) % numSegments; + int nextColorIndex = (colorIndex + 1) % numSegments; + double t = std::fmod(led / static_cast(ledsPerSegment), 1.0); + + auto color = colors[colorIndex]; + auto nextColor = colors[nextColorIndex]; + + Color gradientColor{wpi::Lerp(color.red, nextColor.red, t), + wpi::Lerp(color.green, nextColor.green, t), + wpi::Lerp(color.blue, nextColor.blue, t)}; + writer(led, gradientColor); + } + }}; +} + +LEDPattern LEDPattern::Gradient(std::initializer_list colors) { + return Gradient(std::span{colors.begin(), colors.end()}); +} + +LEDPattern LEDPattern::Rainbow(int saturation, int value) { + return LEDPattern{[=](auto data, auto writer) { + auto bufLen = data.size(); + for (size_t led = 0; led < bufLen; led++) { + int hue = ((led * 180) / bufLen) % 180; + writer(led, Color::FromHSV(hue, saturation, value)); + } + }}; +} diff --git a/wpilibc/src/main/native/include/frc/LEDPattern.h b/wpilibc/src/main/native/include/frc/LEDPattern.h new file mode 100644 index 00000000000..37e743d5ba9 --- /dev/null +++ b/wpilibc/src/main/native/include/frc/LEDPattern.h @@ -0,0 +1,355 @@ +// Copyright (c) FIRST and other WPILib contributors. +// Open Source Software; you can modify and/or share it under the terms of +// the WPILib BSD license file in the root directory of this project. + +#pragma once + +#include +#include +#include + +#include +#include +#include +#include + +#include "frc/AddressableLED.h" +#include "util/Color.h" + +namespace frc { + +/** + * Sets the LED at the given index to the given color. + */ +using LEDWriterFn = std::function; + +/** + * Accepts a data buffer (1st argument) and a callback (2nd argument) for + * writing data. + */ +using LEDPatternFn = + std::function, LEDWriterFn)>; + +class LEDPattern { + public: + explicit LEDPattern(LEDPatternFn impl); + + /** + * Writes the pattern to an LED buffer. Dynamic animations should be called + * periodically (such as with a command or with a periodic method) to refresh + * the buffer over time. + * + * This method is intentionally designed to use separate objects for reading + * and writing data. By splitting them up, we can easily modify the behavior + * of some base pattern to make it scroll, blink, or breathe by intercepting + * the data writes to transform their behavior to whatever we like. + * + * @param data the current data of the LED strip + * @param writer data writer for setting new LED colors on the LED strip + */ + void ApplyTo(std::span data, + LEDWriterFn writer) const; + + /** + * Writes the pattern to an LED buffer. Dynamic animations should be called + * periodically (such as with a command or with a periodic method) to refresh + * the buffer over time. + * + * This method is intentionally designed to use separate objects for reading + * and writing data. By splitting them up, we can easily modify the behavior + * of some base pattern to make it scroll, blink, or breathe by intercepting + * the data writes to transform their behavior to whatever we like. + * + * @param data the current data of the LED strip + */ + void ApplyTo(std::span data) const; + + /** + * Creates a pattern that displays this one in reverse. Scrolling patterns + * will scroll in the opposite direction (but at the same speed). It will + * treat the end of an LED strip as the start, and the start of the strip as + * the end. This can be useful for making ping-pong patterns that travel from + * one end of an LED strip to the other, then reverse direction and move back + * to the start. This can also be useful when working with LED strips + * connected in a serpentine pattern (where the start of one strip is + * connected to the end of the previous one). + * + * @return the reverse pattern + */ + [[nodiscard]] + LEDPattern Reversed(); + + /** + * Creates a pattern that displays this one, but offset by a certain number of + * LEDs. The offset pattern will wrap around, if necessary. + * + * @param offset how many LEDs to offset by + * @return the offset pattern + */ + [[nodiscard]] + LEDPattern OffsetBy(int offset); + + /** + * Creates a pattern that plays this one scrolling up the buffer. The velocity + * controls how fast the pattern returns back to its original position, and is + * in terms of the length of the LED strip; scrolling across a segment that is + * 10 LEDs long will travel twice as fast as on a segment that's only 5 LEDs + * long (assuming equal LED density on both segments). + */ + [[nodiscard]] + LEDPattern ScrollAtRelativeSpeed(units::hertz_t velocity); + + /** + * Creates a pattern that plays this one scrolling up an LED strip. A negative + * velocity makes the pattern play in reverse. + * + *

For example, scrolling a pattern at 4 inches per second along an LED + * strip with 60 LEDs per meter: + * + *

+   *   // LEDs per meter, a known value taken from the spec sheet of our
+   * particular LED strip units::meter_t LED_SPACING = units::meter_t{1 /60.0};
+   *
+   *   frc::LEDPattern rainbow = frc::LEDPattern::Rainbow();
+   *   frc::LEDPattern scrollingRainbow =
+   *     rainbow.ScrollAtAbsoluteSpeed(units::inches_per_second_t{4},
+   * LED_SPACING);
+   * 
+ * + *

Note that this pattern will scroll faster if applied to a less + * dense LED strip (such as 30 LEDs per meter), or slower if applied to + * a denser LED strip (such as 120 or 144 LEDs per meter). + * + * @param velocity how fast the pattern should move along a physical LED strip + * @param ledSpacing the distance between adjacent LEDs on the physical LED + * strip + * @return the scrolling pattern + */ + [[nodiscard]] + LEDPattern ScrollAtAbsoluteSpeed(units::meters_per_second_t velocity, + units::meter_t ledSpacing); + + /** + * Creates a pattern that switches between playing this pattern and turning + * the entire LED strip off. + * + * @param onTime how long the pattern should play for, per cycle + * @param offTime how long the pattern should be turned off for, per cycle + * @return the blinking pattern + */ + [[nodiscard]] + LEDPattern Blink(units::second_t onTime, units::second_t offTime); + + /** + * Like {@link LEDPattern::Blink(units::second_t)}, but where the + * "off" time is exactly equal to the "on" time. + * + * @param onTime how long the pattern should play for (and be turned off for), + * per cycle + * @return the blinking pattern + */ + [[nodiscard]] + LEDPattern Blink(units::second_t onTime); + + /** + * Creates a pattern that blinks this one on and off in sync with a true/false + * signal. The pattern will play while the signal outputs {@code true}, and + * will turn off while the signal outputs + * {@code false}. + * + * @param signal the signal to synchronize with + * @return the blinking pattern + */ + [[nodiscard]] + LEDPattern SynchronizedBlink(std::function signal); + + /** + * Creates a pattern that brightens and dims this one over time. Brightness + * follows a sinusoidal pattern. + * + * @param period how fast the breathing pattern should complete a single cycle + * @return the breathing pattern + */ + [[nodiscard]] + LEDPattern Breathe(units::second_t period); + + /** + * Creates a pattern that plays this pattern overlaid on another. Anywhere + * this pattern sets an LED to off (or {@link frc::Color::kBlack}), the base + * pattern will be displayed instead. + * + * @param base the base pattern to overlay on top of + * @return the combined overlay pattern + */ + [[nodiscard]] + LEDPattern OverlayOn(const LEDPattern& base); + + /** + * Creates a pattern that displays outputs as a combination of this pattern + * and another. Color values are calculated as the average color of both + * patterns; if both patterns set the same LED to the same color, then it is + * set to that color, but if one pattern sets to one color and the other + * pattern sets it to off, then it will show the color of the first pattern + * but at approximately half brightness. This is different from {@link + * LEDPattern::OverlayOn(const LEDPattern&)}, which will show the base pattern + * at full brightness if the overlay is set to off at that position. + * + * @param other the pattern to blend with + * @return the blended pattern + */ + [[nodiscard]] + LEDPattern Blend(const LEDPattern& other); + + /** + * Similar to {@link LEDPattern::Blend(const LEDPattern&)}, but performs a + * bitwise mask on each color channel rather than averaging the colors for + * each LED. This can be helpful for displaying only a portion of the base + * pattern by applying a mask that sets the desired area to white, and all + * other areas to black. However, it can also be used to display only certain + * color channels or hues; for example, masking with {@code + * LEDPattern.color(Color.kRed)} will turn off the green and blue channels on + * the output pattern, leaving only the red LEDs to be illuminated. + * + * @param mask the mask to apply + * @return the masked pattern + */ + [[nodiscard]] + LEDPattern Mask(const LEDPattern& mask); + + /** + * Creates a pattern that plays this one, but at a different brightness. + * Brightness multipliers are applied per-channel in the RGB space; no HSL or + * HSV conversions are applied. Multipliers are also uncapped, which may + * result in the original colors washing out and appearing less saturated or + * even just a bright white. + * + *

This method is predominantly intended for dimming LEDs to avoid + * painfully bright or distracting patterns from playing (apologies to the + * 2024 NE Greater Boston field staff). + * + *

For example, dimming can be done simply by adding a call to + * `atBrightness` at the end of a pattern: + * + *

+   *   // Solid red, but at 50% brightness
+   *   frc::LEDPattern::Solid(frc::Color::kRed).AtBrightness(0.5);
+   *
+   *   // Solid white, but at only 10% (i.e. ~0.5V)
+   *   frc::LEDPattern::Solid(frc:Color::kWhite).AtBrightness(0.1);
+   * 
+ * + * @param relativeBrightness the multiplier to apply to all channels to modify + * brightness + * @return the input pattern, displayed at + */ + [[nodiscard]] + LEDPattern AtBrightness(double relativeBrightness); + + /** A pattern that turns off all LEDs. */ + static LEDPattern kOff; + + /** + * Creates a pattern that displays a single static color along the entire + * length of the LED strip. + * + * @param color the color to display + * @return the pattern + */ + static LEDPattern Solid(const Color color); + + /** + * Creates a pattern that works as a mask layer for {@link + * LEDPattern::Mask(const LEDPattern&)} that illuminates only the portion of + * the LED strip corresponding with some progress. The mask pattern will start + * from the base and set LEDs to white at a proportion equal to the progress + * returned by the function. Some usages for this could be for displaying + * progress of a flywheel to its target velocity, progress of a complex + * autonomous sequence, or the height of an elevator. + * + *

For example, creating a mask for displaying a red-to-blue gradient, + * starting from the red end, based on where an elevator is in its range of + * travel. + * + *

+   * frc::LEDPattern basePattern =
+   *   frc::LEDPattern::Gradient(frc::Color::kRed, frc::Color::kBlue);
+   * frc::LEDPattern progressPattern =
+   *   basePattern.Mask(frc::LEDPattern::ProgressMaskLayer([&]() {
+   *     return elevator.GetHeight() / elevator.MaxHeight();
+   *   });
+   * 
+ * + * @param progressFunction the function to call to determine the progress. + * This should return values in the range [0, 1]; any values outside that + * range will be clamped. + * @return the mask pattern + */ + static LEDPattern ProgressMaskLayer(std::function progressFunction); + + /** + * Display a set of colors in steps across the length of the LED strip. No + * interpolation is done between colors. Colors are specified by the first LED + * on the strip to show that color. The last color in the map will be + * displayed all the way to the end of the strip. LEDs positioned before the + * first specified step will be turned off (you can think of this as if + * there's a 0 -> black step by default). + * + * @param steps a map of progress to the color to start displaying at that + * position along the LED strip + * @return a motionless step pattern + */ + static LEDPattern Steps(std::span> steps); + + /** + * Display a set of colors in steps across the length of the LED strip. No + * interpolation is done between colors. Colors are specified by the first LED + * on the strip to show that color. The last color in the map will be + * displayed all the way to the end of the strip. LEDs positioned before the + * first specified step will be turned off (you can think of this as if + * there's a 0 -> black step by default). + * + * @param steps a map of progress to the color to start displaying at that + * position along the LED strip + * @return a motionless step pattern + */ + static LEDPattern Steps( + std::initializer_list> steps); + + /** + * Creates a pattern that displays a non-animated gradient of colors across + * the entire length of the LED strip. The gradient wraps around so the start + * and end of the strip are the same color, which allows the gradient to be + * modified with a scrolling effect with no discontinuities. Colors are evenly + * distributed along the full length of the LED strip. + * + * @param colors the colors to display in the gradient + * @return a motionless gradient pattern + */ + static LEDPattern Gradient(std::span colors); + + /** + * Creates a pattern that displays a non-animated gradient of colors across + * the entire length of the LED strip. The gradient wraps around so the start + * and end of the strip are the same color, which allows the gradient to be + * modified with a scrolling effect with no discontinuities. Colors are evenly + * distributed along the full length of the LED strip. + * + * @param colors the colors to display in the gradient + * @return a motionless gradient pattern + */ + static LEDPattern Gradient(std::initializer_list colors); + + /** + * Creates an LED pattern that displays a rainbow across the color wheel. The + * rainbow pattern will stretch across the entire length of the LED strip. + * + * @param saturation the saturation of the HSV colors, in [0, 255] + * @param value the value of the HSV colors, in [0, 255] + * @return the rainbow pattern + */ + static LEDPattern Rainbow(int saturation, int value); + + private: + LEDPatternFn m_impl; +}; +} // namespace frc diff --git a/wpilibc/src/test/native/cpp/LEDPatternTest.cpp b/wpilibc/src/test/native/cpp/LEDPatternTest.cpp new file mode 100644 index 00000000000..5ea506c3c07 --- /dev/null +++ b/wpilibc/src/test/native/cpp/LEDPatternTest.cpp @@ -0,0 +1,801 @@ +// Copyright (c) FIRST and other WPILib contributors. +// Open Source Software; you can modify and/or share it under the terms of +// the WPILib BSD license file in the root directory of this project. + +#include +#include +#include + +#include "frc/LEDPattern.h" +#include "frc/MathUtil.h" + +namespace frc { + +static LEDPattern whiteYellowPurple{[](auto data, auto writer) { + for (size_t led = 0; led < data.size(); led++) { + switch (led % 3) { + case 0: + writer(led, Color::kWhite); + break; + case 1: + writer(led, Color::kYellow); + break; + case 2: + writer(led, Color::kPurple); + break; + } + } +}}; + +void AssertIndexColor(std::span data, int index, + Color color); +Color LerpColors(Color a, Color b, double t); + +TEST(LEDPatternTest, SolidColor) { + LEDPattern pattern = LEDPattern::Solid(Color::kYellow); + std::array buffer; + + // prefill + for (int i = 0; i < 5; i++) { + buffer[i].SetLED(Color::kPurple); + } + + pattern.ApplyTo(buffer); + for (int i = 0; i < 5; i++) { + AssertIndexColor(buffer, i, Color::kYellow); + } +} + +TEST(LEDPatternTest, EmptyGradientSetsToBlack) { + std::array colors; + LEDPattern pattern = LEDPattern::Gradient(colors); + std::array buffer; + pattern.ApplyTo(buffer); + for (int i = 0; i < 5; i++) { + AssertIndexColor(buffer, i, Color::kBlack); + } +} + +TEST(LEDPatternTest, SingleColorGradientSetsSolid) { + std::array colors{Color::kYellow}; + LEDPattern pattern = LEDPattern::Gradient(colors); + std::array buffer; + pattern.ApplyTo(buffer); + for (int i = 0; i < 5; i++) { + AssertIndexColor(buffer, i, Color::kYellow); + } +} + +TEST(LEDPatternTest, Gradient2Colors) { + std::array colors{Color::kYellow, Color::kPurple}; + LEDPattern pattern = LEDPattern::Gradient(colors); + std::array buffer; + pattern.ApplyTo(buffer); + AssertIndexColor(buffer, 0, Color::kYellow); + AssertIndexColor(buffer, 25, + LerpColors(Color::kYellow, Color::kPurple, 25 / 49.0)); + AssertIndexColor(buffer, 49, Color::kPurple); + AssertIndexColor(buffer, 74, + LerpColors(Color::kPurple, Color::kYellow, 25 / 49.0)); + AssertIndexColor(buffer, 98, Color::kYellow); +} + +TEST(LEDPatternTest, Gradient3Colors) { + std::array colors{Color::kYellow, Color::kPurple, Color::kWhite}; + LEDPattern pattern = LEDPattern::Gradient(colors); + std::array buffer; + pattern.ApplyTo(buffer); + + AssertIndexColor(buffer, 0, Color::kYellow); + AssertIndexColor(buffer, 25, + LerpColors(Color::kYellow, Color::kPurple, 25 / 33.0)); + AssertIndexColor(buffer, 33, Color::kPurple); + AssertIndexColor(buffer, 58, + LerpColors(Color::kPurple, Color::kWhite, 25 / 33.0)); + AssertIndexColor(buffer, 66, Color::kWhite); + AssertIndexColor(buffer, 91, + LerpColors(Color::kWhite, Color::kYellow, 25 / 33.0)); + AssertIndexColor(buffer, 98, + LerpColors(Color::kWhite, Color::kYellow, 32 / 33.0)); +} + +TEST(LEDPatternTest, EmptyStepsSetsToBlack) { + std::array, 0> steps; + LEDPattern pattern = LEDPattern::Steps(steps); + std::array buffer; + + // prefill + for (int i = 0; i < 5; i++) { + buffer[i].SetLED(Color::kPurple); + } + + pattern.ApplyTo(buffer); + + for (int i = 0; i < 5; i++) { + AssertIndexColor(buffer, i, Color::kBlack); + } +} + +TEST(LEDPatternTest, SingleStepSetsSolid) { + std::array, 1> steps{std::pair{0.0, Color::kYellow}}; + LEDPattern pattern = LEDPattern::Steps(steps); + std::array buffer; + + pattern.ApplyTo(buffer); + + for (int i = 0; i < 5; i++) { + AssertIndexColor(buffer, i, Color::kYellow); + } +} + +TEST(LEDPatternTest, SingleHalfStepSetsHalfOffHalfColor) { + std::array, 1> steps{std::pair{0.5, Color::kYellow}}; + LEDPattern pattern = LEDPattern::Steps(steps); + std::array buffer; + + pattern.ApplyTo(buffer); + + // [0, 48] should be black... + for (int i = 0; i < 49; i++) { + AssertIndexColor(buffer, i, Color::kBlack); + } + + // ... and [49, ] should be the color that was set + for (int i = 49; i < 99; i++) { + AssertIndexColor(buffer, i, Color::kYellow); + } +} + +TEST(LEDPatternTest, ScrollRelativeForward) { + // A black to white gradient + LEDPattern pattern = LEDPattern{[=](auto data, auto writer) { + for (size_t led = 0; led < data.size(); led++) { + int ch = static_cast(led % 256); + writer(led, Color{ch, ch, ch}); + } + }}; + std::array buffer; + + // Scrolling at 1/256th of the buffer per second, + // or 1 individual diode per second + auto scroll = pattern.ScrollAtRelativeSpeed(units::hertz_t{1 / 256.0}); + + static uint64_t now = 0ull; + WPI_SetNowImpl([] { return now; }); + + for (int time = 0; time < 500; time++) { + // convert time (seconds) to microseconds + now = time * 1000000ull; + + scroll.ApplyTo(buffer); + + for (size_t led = 0; led < buffer.size(); led++) { + SCOPED_TRACE( + fmt::format("LED {} of 256, run {} of 500", led + 1, time + 1)); + // Base: [(0, 0, 0) (1, 1, 1) (2, 2, 2) (3, 3, 3) (4, 4, 4) ... (255, 255, + // 255)] Value for every channel should DECREASE by 1 in each timestep, + // wrapping around 0 and 255 + + // t=0, channel value = (0, 1, 2, ..., 254, 255) + // t=1, channel value = (255, 0, 1, ..., 253, 254) + // t=2, channel value = (254, 255, 0, ..., 252, 253) + // t=255, channel value = (1, 2, 3, ..., 255, 0) + // t=256, channel value = (0, 1, 2, ..., 254, 255) + int ch = frc::FloorMod(static_cast(led - time), 256); + AssertIndexColor(buffer, led, Color{ch, ch, ch}); + } + } + + WPI_SetNowImpl(nullptr); // cleanup +} + +TEST(LEDPatternTest, ScrollRelativeBackward) { + // A black to white gradient + LEDPattern pattern = LEDPattern{[=](auto data, auto writer) { + for (size_t led = 0; led < data.size(); led++) { + int ch = static_cast(led % 256); + writer(led, Color{ch, ch, ch}); + } + }}; + std::array buffer; + + // Scrolling at 1/256th of the buffer per second, + // or 1 individual diode per second + auto scroll = pattern.ScrollAtRelativeSpeed(units::hertz_t{-1 / 256.0}); + + static uint64_t now = 0ull; + WPI_SetNowImpl([] { return now; }); + + for (int time = 0; time < 500; time++) { + // convert time (seconds) to microseconds + now = time * 1000000ull; + + scroll.ApplyTo(buffer); + + for (size_t led = 0; led < buffer.size(); led++) { + SCOPED_TRACE( + fmt::format("LED {} of 256, run {} of 500", led + 1, time + 1)); + // Base: [(0, 0, 0) (1, 1, 1) (2, 2, 2) (3, 3, 3) (4, 4, 4) ... (255, 255, + // 255)] Value for every channel should DECREASE by 1 in each timestep, + // wrapping around 0 and 255 + + // t=0, channel value = (0, 1, 2, ..., 254, 255) + // t=1, channel value = (255, 0, 1, ..., 253, 254) + // t=2, channel value = (254, 255, 0, ..., 252, 253) + // t=255, channel value = (1, 2, 3, ..., 255, 0) + // t=256, channel value = (0, 1, 2, ..., 254, 255) + int ch = frc::FloorMod(static_cast(led + time), 256); + AssertIndexColor(buffer, led, Color{ch, ch, ch}); + } + } + + WPI_SetNowImpl(nullptr); // cleanup +} + +TEST(LEDPatternTest, ScrollAbsoluteForward) { + // A black to white gradient + LEDPattern pattern = LEDPattern{[](auto data, auto writer) { + for (size_t led = 0; led < data.size(); led++) { + int ch = static_cast(led % 256); + writer(led, Color{ch, ch, ch}); + } + }}; + std::array buffer; + // scroll at 16 m/s, LED spacing = 2cm + // buffer is 256 LEDs, so total length = 512cm = 5.12m + // scrolling at 16 m/s yields a period of 0.32 seconds, + // or 0.00125 seconds per LED (800 LEDs/s) + auto scroll = pattern.ScrollAtAbsoluteSpeed(16_mps, 2_cm); + + static uint64_t now = 0ull; + WPI_SetNowImpl([] { return now; }); + + for (int time = 0; time < 500; time++) { + // convert time (seconds) to microseconds + now = time * 1250ull; // 1.25ms per LED + + scroll.ApplyTo(buffer); + + for (size_t led = 0; led < buffer.size(); led++) { + SCOPED_TRACE( + fmt::format("LED {} of 256, run {} of 500", led + 1, time + 1)); + // Base: [(0, 0, 0) (1, 1, 1) (2, 2, 2) (3, 3, 3) (4, 4, 4) ... (255, 255, + // 255)] Value for every channel should DECREASE by 1 in each timestep, + // wrapping around 0 and 255 + + // t=0, channel value = (0, 1, 2, ..., 254, 255) + // t=1, channel value = (255, 0, 1, ..., 253, 254) + // t=2, channel value = (254, 255, 0, ..., 252, 253) + // t=255, channel value = (1, 2, 3, ..., 255, 0) + // t=256, channel value = (0, 1, 2, ..., 254, 255) + int ch = frc::FloorMod(static_cast(led - time), 256); + AssertIndexColor(buffer, led, Color{ch, ch, ch}); + } + } + + WPI_SetNowImpl(nullptr); // cleanup +} + +TEST(LEDPatternTest, ScrollAbsoluteBackward) { + // A black to white gradient + LEDPattern pattern = LEDPattern{[](auto data, auto writer) { + for (size_t led = 0; led < data.size(); led++) { + int ch = static_cast(led % 256); + writer(led, Color{ch, ch, ch}); + } + }}; + std::array buffer; + // scroll at 16 m/s, LED spacing = 2cm + // buffer is 256 LEDs, so total length = 512cm = 5.12m + // scrolling at 16 m/s yields a period of 0.32 seconds, + // or 0.00125 seconds per LED (800 LEDs/s) + auto scroll = pattern.ScrollAtAbsoluteSpeed(-16_mps, 2_cm); + + static uint64_t now = 0ull; + WPI_SetNowImpl([] { return now; }); + + for (int time = 0; time < 500; time++) { + // convert time (seconds) to microseconds + now = time * 1250ull; // 1.25ms per LED + + scroll.ApplyTo(buffer); + + for (size_t led = 0; led < buffer.size(); led++) { + SCOPED_TRACE( + fmt::format("LED {} of 256, run {} of 500", led + 1, time + 1)); + // Base: [(0, 0, 0) (1, 1, 1) (2, 2, 2) (3, 3, 3) (4, 4, 4) ... (255, 255, + // 255)] Value for every channel should DECREASE by 1 in each timestep, + // wrapping around 0 and 255 + + // t=0, channel value = (0, 1, 2, ..., 254, 255) + // t=1, channel value = (255, 0, 1, ..., 253, 254) + // t=2, channel value = (254, 255, 0, ..., 252, 253) + // t=255, channel value = (1, 2, 3, ..., 255, 0) + // t=256, channel value = (0, 1, 2, ..., 254, 255) + int ch = frc::FloorMod(static_cast(led + time), 256); + AssertIndexColor(buffer, led, Color{ch, ch, ch}); + } + } + + WPI_SetNowImpl(nullptr); // cleanup +} + +TEST(LEDPatternTest, RainbowFullSize) { + std::array buffer; + int saturation = 255; + int value = 255; + LEDPattern pattern = LEDPattern::Rainbow(saturation, value); + pattern.ApplyTo(buffer); + + for (int led = 0; led < 180; led++) { + AssertIndexColor(buffer, led, Color::FromHSV(led, saturation, value)); + } +} + +TEST(LEDPatternTest, RainbowHalfSize) { + std::array buffer; + int saturation = 42; + int value = 87; + LEDPattern pattern = LEDPattern::Rainbow(saturation, value); + pattern.ApplyTo(buffer); + + for (int led = 0; led < 90; led++) { + AssertIndexColor(buffer, led, Color::FromHSV(led * 2, saturation, value)); + } +} + +TEST(LEDPatternTest, RainbowThirdSize) { + std::array buffer; + int saturation = 191; + int value = 255; + LEDPattern pattern = LEDPattern::Rainbow(saturation, value); + pattern.ApplyTo(buffer); + + for (int led = 0; led < 60; led++) { + SCOPED_TRACE(fmt::format("LED {} of 60", led + 1)); + AssertIndexColor(buffer, led, Color::FromHSV(led * 3, saturation, value)); + } +} + +TEST(LEDPatternTest, RainbowDoubleSize) { + std::array buffer; + int saturation = 212; + int value = 93; + LEDPattern pattern = LEDPattern::Rainbow(saturation, value); + pattern.ApplyTo(buffer); + + for (int led = 0; led < 360; led++) { + SCOPED_TRACE(fmt::format("LED {} of 360", led + 1)); + AssertIndexColor(buffer, led, Color::FromHSV(led / 2, saturation, value)); + } +} + +TEST(LEDPatternTest, RainbowOddSize) { + std::array buffer; + double scale = 180.0 / 127; + int saturation = 73; + int value = 128; + LEDPattern pattern = LEDPattern::Rainbow(saturation, value); + pattern.ApplyTo(buffer); + + for (int led = 0; led < 127; led++) { + SCOPED_TRACE(fmt::format("LED {} of 127", led + 1)); + AssertIndexColor( + buffer, led, + Color::FromHSV(static_cast(led * scale), saturation, value)); + } +} + +TEST(LEDPatternTest, ReverseSolid) { + std::array buffer; + const auto color = Color::kRosyBrown; + + auto solid = LEDPattern::Solid(color); + auto pattern = solid.Reversed(); + + pattern.ApplyTo(buffer); + + for (int led = 0; led < 90; led++) { + SCOPED_TRACE(fmt::format("LED {} of 90", led + 1)); + AssertIndexColor(buffer, led, Color::kRosyBrown); + } +} + +TEST(LEDPatternTest, ReverseSteps) { + std::array buffer; + std::array, 2> steps{std::pair{0.0, Color::kPlum}, + std::pair{0.5, Color::kYellow}}; + auto stepPattern = LEDPattern::Steps(steps); + auto pattern = stepPattern.Reversed(); + + pattern.ApplyTo(buffer); + + // colors should be swapped; yellow first, then plum + for (int led = 0; led < 50; led++) { + SCOPED_TRACE(fmt::format("LED {} of 100", led + 1)); + AssertIndexColor(buffer, led, Color::kYellow); + } + for (int led = 50; led < 100; led++) { + SCOPED_TRACE(fmt::format("LED {} of 100", led + 1)); + AssertIndexColor(buffer, led, Color::kPlum); + } +} + +TEST(LEDPatternTest, OffsetPositive) { + std::array buffer; + auto offset = whiteYellowPurple.OffsetBy(1); + offset.ApplyTo(buffer); + + for (int led = 0; led < 21; led++) { + SCOPED_TRACE(fmt::format("LED {} of 21", led + 1)); + switch (led % 3) { + case 0: + AssertIndexColor(buffer, led, Color::kPurple); + break; + case 1: + AssertIndexColor(buffer, led, Color::kWhite); + break; + case 2: + AssertIndexColor(buffer, led, Color::kYellow); + break; + } + } +} + +TEST(LEDPatternTest, OffsetNegative) { + std::array buffer; + auto offset = whiteYellowPurple.OffsetBy(-1); + offset.ApplyTo(buffer); + + for (int led = 0; led < 21; led++) { + SCOPED_TRACE(fmt::format("LED {} of 21", led + 1)); + switch (led % 3) { + case 0: + AssertIndexColor(buffer, led, Color::kYellow); + break; + case 1: + AssertIndexColor(buffer, led, Color::kPurple); + break; + case 2: + AssertIndexColor(buffer, led, Color::kWhite); + break; + } + } +} + +TEST(LEDPatternTest, OffsetZero) { + std::array buffer; + auto offset = whiteYellowPurple.OffsetBy(0); + offset.ApplyTo(buffer); + + for (int led = 0; led < 21; led++) { + SCOPED_TRACE(fmt::format("LED {} of 21", led + 1)); + switch (led % 3) { + case 0: + AssertIndexColor(buffer, led, Color::kWhite); + break; + case 1: + AssertIndexColor(buffer, led, Color::kYellow); + break; + case 2: + AssertIndexColor(buffer, led, Color::kPurple); + break; + } + } +} + +TEST(LEDPatternTest, BlinkSymmetric) { + std::array buffer; + auto white = LEDPattern::Solid(Color::kWhite); + + // on for 2 seconds, off for 2 seconds + auto pattern = white.Blink(2_s); + + static uint64_t now = 0ull; + WPI_SetNowImpl([] { return now; }); + for (int t = 0; t < 8; t++) { + now = t * 1000000ull; // time travel 1 second + SCOPED_TRACE(fmt::format("Time {} seconds", t)); + pattern.ApplyTo(buffer); + + switch (t) { + case 0: + case 1: + case 4: + case 5: + AssertIndexColor(buffer, 0, Color::kWhite); + break; + case 2: + case 3: + case 6: + case 7: + AssertIndexColor(buffer, 0, Color::kBlack); + break; + } + } + + WPI_SetNowImpl(nullptr); // cleanup +} + +TEST(LEDPatternTest, BlinkAsymmetric) { + std::array buffer; + auto white = LEDPattern::Solid(Color::kWhite); + + // on for 3 seconds, off for 1 second + auto pattern = white.Blink(3_s, 1_s); + + static uint64_t now = 0ull; + WPI_SetNowImpl([] { return now; }); + for (int t = 0; t < 8; t++) { + now = t * 1000000ull; // time travel 1 second + SCOPED_TRACE(fmt::format("Time {} seconds", t)); + pattern.ApplyTo(buffer); + + switch (t) { + case 0: + case 1: + case 2: // first period + case 4: + case 5: + case 6: // second period + AssertIndexColor(buffer, 0, Color::kWhite); + break; + case 3: + case 7: + AssertIndexColor(buffer, 0, Color::kBlack); + break; + } + } + + WPI_SetNowImpl(nullptr); // cleanup +} + +TEST(LEDPatternTest, BlinkInSync) { + std::array buffer; + auto white = LEDPattern::Solid(Color::kWhite); + + bool flag = false; + auto condition = [&flag]() { return flag; }; + + auto pattern = white.SynchronizedBlink(condition); + + SCOPED_TRACE("Flag off"); + pattern.ApplyTo(buffer); + AssertIndexColor(buffer, 0, Color::kBlack); + + SCOPED_TRACE("Flag on"); + flag = true; + pattern.ApplyTo(buffer); + AssertIndexColor(buffer, 0, Color::kWhite); + + SCOPED_TRACE("Flag off"); + flag = false; + pattern.ApplyTo(buffer); + AssertIndexColor(buffer, 0, Color::kBlack); +} + +TEST(LEDPatternTest, Breathe) { + Color midGray{0.5, 0.5, 0.5}; + std::array buffer; + auto white = LEDPattern::Solid(Color::kWhite); + auto pattern = white.Breathe(4_us); + + static uint64_t now = 0ull; + WPI_SetNowImpl([] { return now; }); + + { + now = 0ull; // start + SCOPED_TRACE(fmt::format("Time {}", now)); + + pattern.ApplyTo(buffer); + AssertIndexColor(buffer, 0, Color::kWhite); + } + { + now = 1ull; // midway (down) + SCOPED_TRACE(fmt::format("Time {}", now)); + + pattern.ApplyTo(buffer); + AssertIndexColor(buffer, 0, midGray); + } + { + now = 2ull; // bottom + SCOPED_TRACE(fmt::format("Time {}", now)); + + pattern.ApplyTo(buffer); + AssertIndexColor(buffer, 0, Color::kBlack); + } + { + now = 3ull; // midway (up) + SCOPED_TRACE(fmt::format("Time {}", now)); + + pattern.ApplyTo(buffer); + AssertIndexColor(buffer, 0, midGray); + } + { + now = 4ull; // back to start + SCOPED_TRACE(fmt::format("Time {}", now)); + + pattern.ApplyTo(buffer); + AssertIndexColor(buffer, 0, Color::kWhite); + } + WPI_SetNowImpl(nullptr); // cleanup +} + +TEST(LEDPatternTest, OverlaySolidOnSolid) { + std::array buffer; + + auto base = LEDPattern::Solid(Color::kWhite); + auto overlay = LEDPattern::Solid(Color::kYellow); + auto pattern = overlay.OverlayOn(base); + pattern.ApplyTo(buffer); + + AssertIndexColor(buffer, 0, Color::kYellow); +} + +TEST(LEDPatternTest, OverlayNearlyBlack) { + std::array buffer; + + auto base = LEDPattern::Solid(Color::kWhite); + auto overlay = LEDPattern::Solid(Color{1, 0, 0}); + auto pattern = overlay.OverlayOn(base); + pattern.ApplyTo(buffer); + + AssertIndexColor(buffer, 0, Color{1, 0, 0}); +} + +TEST(LEDPatternTest, OverlayMixed) { + std::array buffer; + + auto base = LEDPattern::Solid(Color::kWhite); + std::array, 2> steps{std::pair{0.0, Color::kYellow}, + std::pair{0.5, Color::kBlack}}; + auto overlay = LEDPattern::Steps(steps); + auto pattern = overlay.OverlayOn(base); + pattern.ApplyTo(buffer); + + AssertIndexColor(buffer, 0, Color::kYellow); + AssertIndexColor(buffer, 1, Color::kWhite); +} + +TEST(LEDPatternTest, Blend) { + std::array buffer; + + auto pattern1 = LEDPattern::Solid(Color::kBlue); + auto pattern2 = LEDPattern::Solid(Color::kRed); + auto blend = pattern1.Blend(pattern2); + blend.ApplyTo(buffer); + + // Individual RGB channels are averaged + // #0000FF blended with #FF0000 yields #7F007F + AssertIndexColor(buffer, 0, Color{127, 0, 127}); +} + +TEST(LEDPatternTest, BinaryMask) { + std::array buffer; + + Color color{123, 123, 123}; + auto base = LEDPattern::Solid(color); + + // first 50% mask on, last 50% mask off + std::array, 2> steps{std::pair{0.0, Color::kWhite}, + std::pair{0.5, Color::kBlack}}; + auto mask = LEDPattern::Steps(steps); + auto masked = base.Mask(mask); + masked.ApplyTo(buffer); + + for (int i = 0; i < 5; i++) { + AssertIndexColor(buffer, i, color); + } + + for (int i = 5; i < 10; i++) { + AssertIndexColor(buffer, i, Color::kBlack); + } +} + +TEST(LEDPatternTest, ChannelwiseMask) { + std::array buffer; + + Color baseColor{123, 123, 123}; + Color halfGray{0.5, 0.5, 0.5}; + auto base = LEDPattern::Solid(baseColor); + std::array, 5> steps{ + std::pair{0.0, Color::kRed}, std::pair{0.2, Color::kLime}, + std::pair{0.4, Color::kBlue}, std::pair{0.6, halfGray}, + std::pair{0.8, Color::kWhite}}; + auto mask = LEDPattern::Steps(steps); + auto masked = base.Mask(mask); + masked.ApplyTo(buffer); + + AssertIndexColor(buffer, 0, Color{123, 0, 0}); + AssertIndexColor(buffer, 1, Color{0, 123, 0}); + AssertIndexColor(buffer, 2, Color{0, 0, 123}); + + // mask channels are all 0b00111111, base is 0b00111011, + // so the AND should give us the unmodified base color + AssertIndexColor(buffer, 3, baseColor); + AssertIndexColor(buffer, 4, baseColor); +} + +TEST(LEDPatternTest, ProcessMaskLayer) { + std::array buffer; + + double progress = 0.0; + auto maskLayer = + LEDPattern::ProgressMaskLayer([&progress]() { return progress; }); + + for (double t = 0; t <= 1.0; t += 0.01) { + SCOPED_TRACE(fmt::format("Time {}", t)); + progress = t; + maskLayer.ApplyTo(buffer); + + int lastMaskedLED = static_cast(t * 100); + for (int i = 0; i < lastMaskedLED; i++) { + SCOPED_TRACE(fmt::format("LED {}", i)); + AssertIndexColor(buffer, i, Color::kWhite); + } + for (int i = lastMaskedLED; i < 100; i++) { + SCOPED_TRACE(fmt::format("LED {}", i)); + AssertIndexColor(buffer, i, Color::kBlack); + } + } +} + +TEST(LEDPatternTest, ZeroBrightness) { + std::array buffer; + + auto base = LEDPattern::Solid(Color::kRed); + auto pattern = base.AtBrightness(0); + pattern.ApplyTo(buffer); + AssertIndexColor(buffer, 0, Color::kBlack); +} + +TEST(LEDPatternTest, SameBrightness) { + std::array buffer; + + auto base = LEDPattern::Solid(Color::kMagenta); + auto pattern = base.AtBrightness(1.0); + pattern.ApplyTo(buffer); + AssertIndexColor(buffer, 0, Color::kMagenta); +} + +TEST(LEDPatternTest, HigherBrightness) { + std::array buffer; + + auto base = LEDPattern::Solid(Color::kMagenta); + auto pattern = base.AtBrightness(4 / 3.0); + pattern.ApplyTo(buffer); + AssertIndexColor(buffer, 0, Color::kMagenta); +} + +TEST(LEDPatternTest, NegativeBrightness) { + std::array buffer; + + auto base = LEDPattern::Solid(Color::kWhite); + auto pattern = base.AtBrightness(-1.0); + pattern.ApplyTo(buffer); + AssertIndexColor(buffer, 0, Color::kBlack); +} + +TEST(LEDPatternTest, ClippingBrightness) { + std::array buffer; + auto base = LEDPattern::Solid(Color::kMidnightBlue); + auto pattern = base.AtBrightness(100); + pattern.ApplyTo(buffer); + AssertIndexColor(buffer, 0, Color::kWhite); +} + +void AssertIndexColor(std::span data, int index, + Color color) { + frc::Color8Bit color8bit{color}; + + EXPECT_EQ(0, data[index].padding); + EXPECT_EQ(color8bit.red, data[index].r & 0xFF); + EXPECT_EQ(color8bit.green, data[index].g & 0xFF); + EXPECT_EQ(color8bit.blue, data[index].b & 0xFF); +} + +Color LerpColors(Color a, Color b, double t) { + return Color{wpi::Lerp(a.red, b.red, t), wpi::Lerp(a.green, b.green, t), + wpi::Lerp(a.blue, b.blue, t)}; +} +} // namespace frc diff --git a/wpilibc/src/test/native/cpp/PS4ControllerTest.cpp b/wpilibc/src/test/native/cpp/PS4ControllerTest.cpp index 4284aed36cd..42d2b9dd526 100644 --- a/wpilibc/src/test/native/cpp/PS4ControllerTest.cpp +++ b/wpilibc/src/test/native/cpp/PS4ControllerTest.cpp @@ -28,7 +28,7 @@ BUTTON_TEST(PS4Controller, L3Button) BUTTON_TEST(PS4Controller, R3Button) BUTTON_TEST(PS4Controller, PSButton) -BUTTON_TEST(PS4Controller, Touchpad) +BUTTON_TEST(PS4Controller, TouchpadButton) AXIS_TEST(PS4Controller, LeftX) AXIS_TEST(PS4Controller, RightX) diff --git a/wpilibc/src/test/native/cpp/PS5ControllerTest.cpp b/wpilibc/src/test/native/cpp/PS5ControllerTest.cpp index 67dd0caa98e..13ae7709efe 100644 --- a/wpilibc/src/test/native/cpp/PS5ControllerTest.cpp +++ b/wpilibc/src/test/native/cpp/PS5ControllerTest.cpp @@ -28,7 +28,7 @@ BUTTON_TEST(PS5Controller, L3Button) BUTTON_TEST(PS5Controller, R3Button) BUTTON_TEST(PS5Controller, PSButton) -BUTTON_TEST(PS5Controller, Touchpad) +BUTTON_TEST(PS5Controller, TouchpadButton) AXIS_TEST(PS5Controller, LeftX) AXIS_TEST(PS5Controller, RightX) diff --git a/wpilibc/src/test/native/cpp/XboxControllerTest.cpp b/wpilibc/src/test/native/cpp/XboxControllerTest.cpp index 3798fde51c3..fdc9866d72b 100644 --- a/wpilibc/src/test/native/cpp/XboxControllerTest.cpp +++ b/wpilibc/src/test/native/cpp/XboxControllerTest.cpp @@ -11,8 +11,8 @@ using namespace frc; -BUTTON_TEST(XboxController, LeftBumper) -BUTTON_TEST(XboxController, RightBumper) +BUTTON_TEST(XboxController, LeftBumperButton) +BUTTON_TEST(XboxController, RightBumperButton) BUTTON_TEST(XboxController, LeftStickButton) BUTTON_TEST(XboxController, RightStickButton) diff --git a/wpilibcExamples/src/main/cpp/examples/AddressableLED/cpp/Robot.cpp b/wpilibcExamples/src/main/cpp/examples/AddressableLED/cpp/Robot.cpp index d3356c65b89..97c0925e4ff 100644 --- a/wpilibcExamples/src/main/cpp/examples/AddressableLED/cpp/Robot.cpp +++ b/wpilibcExamples/src/main/cpp/examples/AddressableLED/cpp/Robot.cpp @@ -13,27 +13,12 @@ void Robot::RobotInit() { } void Robot::RobotPeriodic() { - // Fill the buffer with a rainbow - Rainbow(); + // Run the rainbow pattern and apply it to the buffer + m_scrollingRainbow.ApplyTo(m_ledBuffer); // Set the LEDs m_led.SetData(m_ledBuffer); } -void Robot::Rainbow() { - // For every pixel - for (int i = 0; i < kLength; i++) { - // Calculate the hue - hue is easier for rainbows because the color - // shape is a circle so only one value needs to precess - const auto pixelHue = (firstPixelHue + (i * 180 / kLength)) % 180; - // Set the value - m_ledBuffer[i].SetHSV(pixelHue, 255, 128); - } - // Increase by to make the rainbow "move" - firstPixelHue += 3; - // Check bounds - firstPixelHue %= 180; -} - #ifndef RUNNING_FRC_TESTS int main() { return frc::StartRobot(); diff --git a/wpilibcExamples/src/main/cpp/examples/AddressableLED/include/Robot.h b/wpilibcExamples/src/main/cpp/examples/AddressableLED/include/Robot.h index 77090b6a57d..488f5e5991c 100644 --- a/wpilibcExamples/src/main/cpp/examples/AddressableLED/include/Robot.h +++ b/wpilibcExamples/src/main/cpp/examples/AddressableLED/include/Robot.h @@ -7,11 +7,11 @@ #include #include +#include #include class Robot : public frc::TimedRobot { public: - void Rainbow(); void RobotInit() override; void RobotPeriodic() override; @@ -23,6 +23,16 @@ class Robot : public frc::TimedRobot { frc::AddressableLED m_led{9}; std::array m_ledBuffer; // Reuse the buffer - // Store what the last hue of the first pixel is - int firstPixelHue = 0; + + // Our LED strip has a density of 120 LEDs per meter + units::meter_t kLedSpacing{1 / 120.0}; + + // Create an LED pattern that will display a rainbow across + // all hues at maximum saturation and half brightness + frc::LEDPattern m_rainbow = frc::LEDPattern::Rainbow(255, 128); + + // Create a new pattern that scrolls the rainbow pattern across the LED + // strip, moving at a speed of 1 meter per second. + frc::LEDPattern m_scrollingRainbow = + m_rainbow.ScrollAtAbsoluteSpeed(1_mps, kLedSpacing); }; diff --git a/wpilibcExamples/src/main/cpp/examples/StateSpaceArm/cpp/Robot.cpp b/wpilibcExamples/src/main/cpp/examples/StateSpaceArm/cpp/Robot.cpp index 9b91e205c66..01d3db6abe3 100644 --- a/wpilibcExamples/src/main/cpp/examples/StateSpaceArm/cpp/Robot.cpp +++ b/wpilibcExamples/src/main/cpp/examples/StateSpaceArm/cpp/Robot.cpp @@ -110,7 +110,7 @@ class Robot : public frc::TimedRobot { // Sets the target position of our arm. This is similar to setting the // setpoint of a PID controller. frc::TrapezoidProfile::State goal; - if (m_joystick.GetRightBumper()) { + if (m_joystick.GetRightBumperButton()) { // We pressed the bumper, so let's set our next reference goal = {kRaisedPosition, 0_rad_per_s}; } else { diff --git a/wpilibcExamples/src/main/cpp/examples/StateSpaceElevator/cpp/Robot.cpp b/wpilibcExamples/src/main/cpp/examples/StateSpaceElevator/cpp/Robot.cpp index 7b982b581bb..08074f8cf1b 100644 --- a/wpilibcExamples/src/main/cpp/examples/StateSpaceElevator/cpp/Robot.cpp +++ b/wpilibcExamples/src/main/cpp/examples/StateSpaceElevator/cpp/Robot.cpp @@ -110,7 +110,7 @@ class Robot : public frc::TimedRobot { // Sets the target height of our elevator. This is similar to setting the // setpoint of a PID controller. frc::TrapezoidProfile::State goal; - if (m_joystick.GetRightBumper()) { + if (m_joystick.GetRightBumperButton()) { // We pressed the bumper, so let's set our next reference goal = {kRaisedPosition, 0_fps}; } else { diff --git a/wpilibcExamples/src/main/cpp/examples/StateSpaceFlywheel/cpp/Robot.cpp b/wpilibcExamples/src/main/cpp/examples/StateSpaceFlywheel/cpp/Robot.cpp index 5d413ab26b0..b0a9ed3a92f 100644 --- a/wpilibcExamples/src/main/cpp/examples/StateSpaceFlywheel/cpp/Robot.cpp +++ b/wpilibcExamples/src/main/cpp/examples/StateSpaceFlywheel/cpp/Robot.cpp @@ -92,7 +92,7 @@ class Robot : public frc::TimedRobot { void TeleopPeriodic() override { // Sets the target speed of our flywheel. This is similar to setting the // setpoint of a PID controller. - if (m_joystick.GetRightBumper()) { + if (m_joystick.GetRightBumperButton()) { // We pressed the bumper, so let's set our next reference m_loop.SetNextR(frc::Vectord<1>{kSpinup.value()}); } else { diff --git a/wpilibcExamples/src/main/cpp/examples/StateSpaceFlywheelSysId/cpp/Robot.cpp b/wpilibcExamples/src/main/cpp/examples/StateSpaceFlywheelSysId/cpp/Robot.cpp index d3bab6e7954..2be14fd49f0 100644 --- a/wpilibcExamples/src/main/cpp/examples/StateSpaceFlywheelSysId/cpp/Robot.cpp +++ b/wpilibcExamples/src/main/cpp/examples/StateSpaceFlywheelSysId/cpp/Robot.cpp @@ -92,7 +92,7 @@ class Robot : public frc::TimedRobot { void TeleopPeriodic() override { // Sets the target speed of our flywheel. This is similar to setting the // setpoint of a PID controller. - if (m_joystick.GetRightBumper()) { + if (m_joystick.GetRightBumperButton()) { // We pressed the bumper, so let's set our next reference m_loop.SetNextR(frc::Vectord<1>{kSpinup.value()}); } else { diff --git a/wpilibcExamples/src/test/cpp/examples/AddressableLED/cpp/RainbowTest.cpp b/wpilibcExamples/src/test/cpp/examples/AddressableLED/cpp/RainbowTest.cpp deleted file mode 100644 index ca06df9cddb..00000000000 --- a/wpilibcExamples/src/test/cpp/examples/AddressableLED/cpp/RainbowTest.cpp +++ /dev/null @@ -1,52 +0,0 @@ -// Copyright (c) FIRST and other WPILib contributors. -// Open Source Software; you can modify and/or share it under the terms of -// the WPILib BSD license file in the root directory of this project. - -#include - -#include -#include -#include -#include -#include -#include -#include - -#include "Robot.h" - -void AssertIndexColor(std::array data, - int index, int hue, int saturation, int value); - -TEST(RainbowTest, RainbowPattern) { - Robot robot; - robot.RobotInit(); - frc::sim::AddressableLEDSim ledSim = - frc::sim::AddressableLEDSim::CreateForChannel(9); - EXPECT_TRUE(ledSim.GetRunning()); - EXPECT_EQ(60, ledSim.GetLength()); - - auto rainbowFirstPixelHue = 0; - std::array data; - for (int iteration = 0; iteration < 100; iteration++) { - SCOPED_TRACE(fmt::format("Iteration {} of 100", iteration)); - robot.RobotPeriodic(); - ledSim.GetData(data.data()); - for (int i = 0; i < 60; i++) { - SCOPED_TRACE(fmt::format("LED {} of 60", i)); - auto hue = (rainbowFirstPixelHue + (i * 180 / 60)) % 180; - AssertIndexColor(data, i, hue, 255, 128); - } - rainbowFirstPixelHue += 3; - rainbowFirstPixelHue %= 180; - } -} - -void AssertIndexColor(std::array data, - int index, int hue, int saturation, int value) { - frc::Color8Bit color{frc::Color::FromHSV(hue, saturation, value)}; - - EXPECT_EQ(0, data[index].padding); - EXPECT_EQ(color.red, data[index].r & 0xFF); - EXPECT_EQ(color.green, data[index].g & 0xFF); - EXPECT_EQ(color.blue, data[index].b & 0xFF); -} diff --git a/wpilibcExamples/src/test/cpp/examples/AddressableLED/cpp/main.cpp b/wpilibcExamples/src/test/cpp/examples/AddressableLED/cpp/main.cpp deleted file mode 100644 index 38d5cfa2fed..00000000000 --- a/wpilibcExamples/src/test/cpp/examples/AddressableLED/cpp/main.cpp +++ /dev/null @@ -1,16 +0,0 @@ -// Copyright (c) FIRST and other WPILib contributors. -// Open Source Software; you can modify and/or share it under the terms of -// the WPILib BSD license file in the root directory of this project. - -#include -#include - -/** - * Runs all unit tests. - */ -int main(int argc, char** argv) { - HAL_Initialize(500, 0); - ::testing::InitGoogleTest(&argc, argv); - int ret = RUN_ALL_TESTS(); - return ret; -} diff --git a/wpilibj/CMakeLists.txt b/wpilibj/CMakeLists.txt index 684c26062bf..2418b6d3edf 100644 --- a/wpilibj/CMakeLists.txt +++ b/wpilibj/CMakeLists.txt @@ -17,7 +17,7 @@ if(WITH_JAVA) configure_file(src/generate/WPILibVersion.java.in WPILibVersion.java) - file(GLOB_RECURSE JAVA_SOURCES src/main/java/*.java) + file(GLOB_RECURSE JAVA_SOURCES src/main/java/*.java src/generated/main/java/*.java) file(GLOB EJML_JARS "${WPILIB_BINARY_DIR}/wpimath/thirdparty/ejml/*.jar") file(GLOB JACKSON_JARS "${WPILIB_BINARY_DIR}/wpiutil/thirdparty/jackson/*.jar") @@ -49,14 +49,22 @@ endif() if(WITH_JAVA_SOURCE) find_package(Java REQUIRED) include(UseJava) - file(GLOB WPILIBJ_SOURCES src/main/java/edu/wpi/first/wpilibj/*.java) + file( + GLOB WPILIBJ_SOURCES + src/main/java/edu/wpi/first/wpilibj/*.java + src/generated/main/java/edu/wpi/first/wpilibj/*.java + ) file(GLOB WPILIBJ_COUNTER_SOURCES src/main/java/edu/wpi/first/wpilibj/counter/*.java) file(GLOB WPILIBJ_DRIVE_SOURCES src/main/java/edu/wpi/first/wpilibj/drive/*.java) file(GLOB WPILIBJ_EVENT_SOURCES src/main/java/edu/wpi/first/wpilibj/event/*.java) file(GLOB WPILIBJ_INTERFACES_SOURCES src/main/java/edu/wpi/first/wpilibj/interfaces/*.java) file(GLOB WPILIBJ_MOTORCONTROL_SOURCES src/main/java/edu/wpi/first/wpilibj/motorcontrol*.java) file(GLOB WPILIBJ_SHUFFLEBOARD_SOURCES src/main/java/edu/wpi/first/wpilibj/shuffleboard*.java) - file(GLOB WPILIBJ_SIMULATION_SOURCES src/main/java/edu/wpi/first/wpilibj/simulation*.java) + file( + GLOB WPILIBJ_SIMULATION_SOURCES + src/main/java/edu/wpi/first/wpilibj/simulation/*.java + src/generated/main/java/edu/wpi/first/wpilibj/simulation/*.java + ) file(GLOB WPILIBJ_SMARTDASHBOARD_SOURCES src/main/java/edu/wpi/first/wpilibj/*.java) file( GLOB WPILIBJ_UTIL_SOURCES diff --git a/wpilibj/build.gradle b/wpilibj/build.gradle index b31630e70ea..d397f934801 100644 --- a/wpilibj/build.gradle +++ b/wpilibj/build.gradle @@ -50,6 +50,7 @@ gradle.taskGraph.addTaskExecutionGraphListener { graph -> } sourceSets.main.java.srcDir "${buildDir}/generated/java/" +sourceSets.main.java.srcDir "${projectDir}/src/generated/main/java" compileJava { dependsOn generateJavaVersion @@ -143,14 +144,8 @@ model { def filePath = it.tasks.install.installDirectory.get().toString() + File.separatorChar + 'lib' test.dependsOn it.tasks.install test.systemProperty 'java.library.path', filePath - test.environment 'LD_LIBRARY_PATH', filePath - test.environment 'DYLD_LIBRARY_PATH', filePath - test.workingDir filePath run.dependsOn it.tasks.install run.systemProperty 'java.library.path', filePath - run.environment 'LD_LIBRARY_PATH', filePath - run.environment 'DYLD_LIBRARY_PATH', filePath - run.workingDir filePath found = true } diff --git a/wpilibj/generate_hids.py b/wpilibj/generate_hids.py new file mode 100755 index 00000000000..98f97dd6c0e --- /dev/null +++ b/wpilibj/generate_hids.py @@ -0,0 +1,59 @@ +#!/usr/bin/env python3 + +# Copyright (c) FIRST and other WPILib contributors. +# Open Source Software; you can modify and/or share it under the terms of +# the WPILib BSD license file in the root directory of this project. +import json +import os + +from jinja2 import Environment, FileSystemLoader + + +def write_controller_file(outPath, controllerName, contents): + if not os.path.exists(outPath): + os.makedirs(outPath) + + outpathname = f"{outPath}/{controllerName}" + + if os.path.exists(outpathname): + with open(outpathname, "r") as f: + if f.read() == contents: + return + + # File either doesn't exist or has different contents + with open(outpathname, "w", newline="\n") as f: + f.write(contents) + + +def main(): + dirname, _ = os.path.split(os.path.abspath(__file__)) + + with open(f"{dirname}/src/generate/hids.json") as f: + controllers = json.load(f) + + # Java files + env = Environment( + loader=FileSystemLoader(f"{dirname}/src/generate/"), + autoescape=False, + keep_trailing_newline=True, + ) + rootPath = f"{dirname}/src/generated/main/java/edu/wpi/first/wpilibj" + template = env.get_template("hid.java.jinja") + for controller in controllers: + controllerName = os.path.basename(f"{controller['ConsoleName']}Controller.java") + output = template.render(controller) + write_controller_file(rootPath, controllerName, output) + + # Java simulation files + rootPath = f"{dirname}/src/generated/main/java/edu/wpi/first/wpilibj/simulation" + template = env.get_template("hidsim.java.jinja") + for controller in controllers: + controllerName = os.path.basename( + f"{controller['ConsoleName']}ControllerSim.java" + ) + output = template.render(controller) + write_controller_file(rootPath, controllerName, output) + + +if __name__ == "__main__": + main() diff --git a/wpilibj/src/generate/hid.java.jinja b/wpilibj/src/generate/hid.java.jinja new file mode 100644 index 00000000000..84dbd8c3e83 --- /dev/null +++ b/wpilibj/src/generate/hid.java.jinja @@ -0,0 +1,289 @@ +// Copyright (c) FIRST and other WPILib contributors. +// Open Source Software; you can modify and/or share it under the terms of +// the WPILib BSD license file in the root directory of this project. + +// THIS FILE WAS AUTO-GENERATED BY ./wpilibj/generate_hids.py. DO NOT MODIFY +{% macro capitalize_first(string) -%} +{{ string[0]|capitalize + string[1:] }} +{%- endmacro %} +package edu.wpi.first.wpilibj; + +{{ "// " if SkipReporting }}import edu.wpi.first.hal.FRCNetComm.tResourceType; +{{ "// " if SkipReporting }}import edu.wpi.first.hal.HAL; +import edu.wpi.first.wpilibj.event.BooleanEvent; +import edu.wpi.first.wpilibj.event.EventLoop; + +/** + * Handle input from {{ ConsoleName }} controllers connected to the Driver Station. + * + *

This class handles {{ ConsoleName }} input that comes from the Driver Station. Each time a value is + * requested the most recent value is returned. There is a single class instance for each controller + * and the mapping of ports to hardware buttons depends on the code in the Driver Station. + * + *

Only first party controllers from {{ Manufacturer }} are guaranteed to have the correct mapping, and + * only through the official NI DS. Sim is not guaranteed to have the same mapping, as well as any + * 3rd party controllers. + */ +public class {{ ConsoleName }}Controller extends GenericHID { + /** Represents a digital button on a {{ ConsoleName }}Controller. */ + public enum Button { +{%- for button in buttons %} + /** {{ capitalize_first(button.DocName|default(button.name)) }} button. */ + k{{ capitalize_first(button.name) }}({{ button.value }}){{ ";" if loop.last else ","}} +{%- endfor %} + + /** Button value. */ + public final int value; + + Button(int value) { + this.value = value; + } + + /** + * Get the human-friendly name of the button, matching the relevant methods. This is done by + * stripping the leading `k`, and appending `Button`. + * + *

Primarily used for automated unit tests. + * + * @return the human-friendly name of the button. + */ + @Override + public String toString() { + // Remove leading `k` + return this.name().substring(1) + "Button"; + } + } + + /** Represents an axis on an {{ ConsoleName }}Controller. */ + public enum Axis { +{%- for stick in sticks %} + /** {{ stick.NameParts|map("capitalize")|join(" ") }} axis. */ + k{{ stick.NameParts|map("capitalize")|join }}({{ stick.value }}){{ "," if triggers|length > 0 or not loop.last else ";"}} +{%- endfor %} +{%- for trigger in triggers %} + /** {{ trigger.DocName|capitalize }}. */ + k{{ capitalize_first(trigger.name) }}({{ trigger.value }}){{ ";" if loop.last else ","}} +{%- endfor %} + + /** Axis value. */ + public final int value; + + Axis(int value) { + this.value = value; + } + + /** + * Get the human-friendly name of the axis, matching the relevant methods. This is done by + * stripping the leading `k`, and appending `Axis` if the name ends with `{{ AxisNameSuffix }}`. + * + *

Primarily used for automated unit tests. + * + * @return the human-friendly name of the axis. + */ + @Override + public String toString() { + var name = this.name().substring(1); // Remove leading `k` + if (name.endsWith("{{ AxisNameSuffix }}")) { + return name + "Axis"; + } + return name; + } + } + + /** + * Construct an instance of a controller. + * + * @param port The port index on the Driver Station that the controller is plugged into (0-5). + */ + public {{ ConsoleName }}Controller(final int port) { + super(port); + {{ "// " if SkipReporting }}HAL.report(tResourceType.kResourceType_{{ ConsoleName }}Controller, port + 1); + } +{% for stick in sticks %} + /** + * Get the {{ stick.NameParts[1] }} axis value of {{ stick.NameParts[0] }} side of the controller. + * + * @return The axis value. + */ + public double get{{ stick.NameParts|map("capitalize")|join }}() { + return getRawAxis(Axis.k{{ stick.NameParts|map("capitalize")|join }}.value); + } +{% endfor -%} +{% for trigger in triggers %} + /** + * Get the {{ trigger.DocName }} axis value of the controller. Note that this axis is bound to the + * range of [0, 1] as opposed to the usual [-1, 1]. + * + * @return The axis value. + */ + public double get{{ capitalize_first(trigger.name) }}Axis() { + return getRawAxis(Axis.k{{ capitalize_first(trigger.name) }}.value); + } +{% if trigger.UseThresholdMethods %} + /** + * Constructs an event instance around the axis value of the {{ trigger.DocName }}. The returned trigger + * will be true when the axis value is greater than {@code threshold}. + * + * @param threshold the minimum axis value for the returned {@link BooleanEvent} to be true. This + * value should be in the range [0, 1] where 0 is the unpressed state of the axis. + * @param loop the event loop instance to attach the event to. + * @return an event instance that is true when the {{ trigger.DocName }}'s axis exceeds the provided + * threshold, attached to the given event loop + */ + public BooleanEvent {{ trigger.name }}(double threshold, EventLoop loop) { + return new BooleanEvent(loop, () -> get{{ capitalize_first(trigger.name) }}Axis() > threshold); + } + + /** + * Constructs an event instance around the axis value of the {{ trigger.DocName }}. The returned trigger + * will be true when the axis value is greater than 0.5. + * + * @param loop the event loop instance to attach the event to. + * @return an event instance that is true when the {{ trigger.DocName }}'s axis exceeds the provided + * threshold, attached to the given event loop + */ + public BooleanEvent {{ trigger.name }}(EventLoop loop) { + return {{ trigger.name }}(0.5, loop); + } +{% endif -%} +{% endfor -%} +{% for button in buttons %} + /** + * Read the value of the {{ button.DocName|default(button.name) }} button on the controller. + * + * @return The state of the button. + */ + public boolean get{{ capitalize_first(button.name) }}Button() { + return getRawButton(Button.k{{ capitalize_first(button.name) }}.value); + } + + /** + * Whether the {{ button.DocName|default(button.name) }} button was pressed since the last check. + * + * @return Whether the button was pressed since the last check. + */ + public boolean get{{ capitalize_first(button.name) }}ButtonPressed() { + return getRawButtonPressed(Button.k{{ capitalize_first(button.name) }}.value); + } + + /** + * Whether the {{ button.DocName|default(button.name) }} button was released since the last check. + * + * @return Whether the button was released since the last check. + */ + public boolean get{{ capitalize_first(button.name) }}ButtonReleased() { + return getRawButtonReleased(Button.k{{ capitalize_first(button.name) }}.value); + } + + /** + * Constructs an event instance around the {{ button.DocName|default(button.name) }} button's digital signal. + * + * @param loop the event loop instance to attach the event to. + * @return an event instance representing the {{ button.DocName|default(button.name) }} button's digital signal + * attached to the given loop. + */ + public BooleanEvent {{ button.name }}(EventLoop loop) { + return new BooleanEvent(loop, this::get{{ capitalize_first(button.name) }}Button); + } +{% endfor -%} +{% if ConsoleName == "Xbox" or ConsoleName == "Stadia" %} + /** + * Read the value of the left bumper (LB) button on the controller. + * + * @return The state of the button. + * @deprecated Use {@link getLeftBumperButton} instead + */ + @Deprecated(since = "2025", forRemoval = true) + public boolean getLeftBumper() { + return getRawButton(Button.kLeftBumper.value); + } + + /** + * Read the value of the right bumper (RB) button on the controller. + * + * @return The state of the button. + * @deprecated Use {@link getRightBumperButton} instead + */ + @Deprecated(since = "2025", forRemoval = true) + public boolean getRightBumper() { + return getRawButton(Button.kRightBumper.value); + } + + /** + * Whether the left bumper (LB) was pressed since the last check. + * + * @return Whether the button was pressed since the last check. + * @deprecated Use {@link getLeftBumperButtonPressed} instead + */ + @Deprecated(since = "2025", forRemoval = true) + public boolean getLeftBumperPressed() { + return getRawButtonPressed(Button.kLeftBumper.value); + } + + /** + * Whether the right bumper (RB) was pressed since the last check. + * + * @return Whether the button was pressed since the last check. + * @deprecated Use {@link getRightBumperButtonPressed} instead + */ + @Deprecated(since = "2025", forRemoval = true) + public boolean getRightBumperPressed() { + return getRawButtonPressed(Button.kRightBumper.value); + } + + /** + * Whether the left bumper (LB) was released since the last check. + * + * @return Whether the button was released since the last check. + * @deprecated Use {@link getLeftBumperButtonReleased} instead + */ + @Deprecated(since = "2025", forRemoval = true) + public boolean getLeftBumperReleased() { + return getRawButtonReleased(Button.kLeftBumper.value); + } + + /** + * Whether the right bumper (RB) was released since the last check. + * + * @return Whether the button was released since the last check. + * @deprecated Use {@link getRightBumperButtonReleased} instead + */ + @Deprecated(since = "2025", forRemoval = true) + public boolean getRightBumperReleased() { + return getRawButtonReleased(Button.kRightBumper.value); + } +{% elif ConsoleName == "PS4" or ConsoleName == "PS5" %} + /** + * Read the value of the touchpad on the controller. + * + * @return The state of the touchpad. + * @deprecated Use {@link getTouchpadButton} instead + */ + @Deprecated(since = "2025", forRemoval = true) + public boolean getTouchpad() { + return getRawButton(Button.kTouchpad.value); + } + + /** + * Whether the touchpad was pressed since the last check. + * + * @return Whether the touchpad was pressed since the last check. + * @deprecated Use {@link getTouchpadButtonPressed} instead + */ + @Deprecated(since = "2025", forRemoval = true) + public boolean getTouchpadPressed() { + return getRawButtonPressed(Button.kTouchpad.value); + } + + /** + * Whether the touchpad was released since the last check. + * + * @return Whether the touchpad was released since the last check. + * @deprecated Use {@link getTouchpadButtonReleased} instead + */ + @Deprecated(since = "2025", forRemoval = true) + public boolean getTouchpadReleased() { + return getRawButtonReleased(Button.kTouchpad.value); + } +{% endif -%} +} diff --git a/wpilibj/src/generate/hids.json b/wpilibj/src/generate/hids.json new file mode 100644 index 00000000000..f27806458a1 --- /dev/null +++ b/wpilibj/src/generate/hids.json @@ -0,0 +1,440 @@ +[ + { + "ConsoleName": "Xbox", + "Manufacturer": "Microsoft", + "SkipReporting": false, + "AxisNameSuffix": "Trigger", + "buttons": [ + { + "name": "a", + "value": 1, + "DocName": "A" + }, + { + "name": "b", + "value": 2, + "DocName": "B" + }, + { + "name": "x", + "value": 3, + "DocName": "X" + }, + { + "name": "y", + "value": 4, + "DocName": "Y" + }, + { + "name": "leftBumper", + "value": 5, + "DocName": "left bumper" + }, + { + "name": "rightBumper", + "value": 6, + "DocName": "right bumper" + }, + { + "name": "back", + "value": 7 + }, + { + "name": "start", + "value": 8 + }, + { + "name": "leftStick", + "value": 9, + "DocName": "left stick" + }, + { + "name": "rightStick", + "value": 10, + "DocName": "right stick" + } + ], + "sticks": [ + { + "NameParts": [ + "left", + "X" + ], + "value": 0 + }, + { + "NameParts": [ + "right", + "X" + ], + "value": 4 + }, + { + "NameParts": [ + "left", + "Y" + ], + "value": 1 + }, + { + "NameParts": [ + "right", + "Y" + ], + "value": 5 + } + ], + "triggers": [ + { + "name": "leftTrigger", + "value": 2, + "DocName": "left trigger", + "UseThresholdMethods": true + }, + { + "name": "rightTrigger", + "value": 3, + "DocName": "right trigger", + "UseThresholdMethods": true + } + ] + }, + { + "ConsoleName": "PS4", + "Manufacturer": "Sony", + "SkipReporting": false, + "AxisNameSuffix": "2", + "buttons": [ + { + "name": "square", + "value": 1 + }, + { + "name": "cross", + "value": 2 + }, + { + "name": "circle", + "value": 3 + }, + { + "name": "triangle", + "value": 4 + }, + { + "name": "L1", + "value": 5, + "DocName": "left trigger 1" + }, + { + "name": "R1", + "value": 6, + "DocName": "right trigger 1" + }, + { + "name": "L2", + "value": 7, + "DocName": "left trigger 2" + }, + { + "name": "R2", + "value": 8, + "DocName": "right trigger 2" + }, + { + "name": "share", + "value": 9 + }, + { + "name": "options", + "value": 10 + }, + { + "name": "L3", + "value": 11, + "DocName": "L3 (left stick)" + }, + { + "name": "R3", + "value": 12, + "DocName": "R3 (right stick)" + }, + { + "name": "PS", + "value": 13, + "DocName": "PlayStation" + }, + { + "name": "touchpad", + "value": 14 + } + ], + "sticks": [ + { + "NameParts": [ + "left", + "X" + ], + "value": 0 + }, + { + "NameParts": [ + "left", + "Y" + ], + "value": 1 + }, + { + "NameParts": [ + "right", + "X" + ], + "value": 2 + }, + { + "NameParts": [ + "right", + "Y" + ], + "value": 5 + } + ], + "triggers": [ + { + "name": "L2", + "value": 3, + "DocName": "left trigger 2", + "UseThresholdMethods": false + }, + { + "name": "R2", + "value": 4, + "DocName": "right trigger 2", + "UseThresholdMethods": false + } + ] + }, + { + "ConsoleName": "PS5", + "Manufacturer": "Sony", + "SkipReporting": true, + "AxisNameSuffix": "2", + "buttons": [ + { + "name": "square", + "value": 1 + }, + { + "name": "cross", + "value": 2 + }, + { + "name": "circle", + "value": 3 + }, + { + "name": "triangle", + "value": 4 + }, + { + "name": "L1", + "value": 5, + "DocName": "left trigger 1" + }, + { + "name": "R1", + "value": 6, + "DocName": "right trigger 1" + }, + { + "name": "L2", + "value": 7, + "DocName": "left trigger 2" + }, + { + "name": "R2", + "value": 8, + "DocName": "right trigger 2" + }, + { + "name": "create", + "value": 9 + }, + { + "name": "options", + "value": 10 + }, + { + "name": "L3", + "value": 11, + "DocName": "L3 (left stick)" + }, + { + "name": "R3", + "value": 12, + "DocName": "R3 (right stick)" + }, + { + "name": "PS", + "value": 13, + "DocName": "PlayStation" + }, + { + "name": "touchpad", + "value": 14 + } + ], + "sticks": [ + { + "NameParts": [ + "left", + "X" + ], + "value": 0 + }, + { + "NameParts": [ + "left", + "Y" + ], + "value": 1 + }, + { + "NameParts": [ + "right", + "X" + ], + "value": 2 + }, + { + "NameParts": [ + "right", + "Y" + ], + "value": 5 + } + ], + "triggers": [ + { + "name": "L2", + "value": 3, + "DocName": "left trigger 2", + "UseThresholdMethods": false + }, + { + "name": "R2", + "value": 4, + "DocName": "right trigger 2", + "UseThresholdMethods": false + } + ] + }, + { + "ConsoleName": "Stadia", + "Manufacturer": "Google", + "SkipReporting": true, + "AxisNameSuffix": "Trigger", + "buttons": [ + { + "name": "a", + "value": 1, + "DocName": "A" + }, + { + "name": "b", + "value": 2, + "DocName": "B" + }, + { + "name": "x", + "value": 3, + "DocName": "X" + }, + { + "name": "y", + "value": 4, + "DocName": "Y" + }, + { + "name": "leftBumper", + "value": 5, + "DocName": "left bumper" + }, + { + "name": "rightBumper", + "value": 6, + "DocName": "right bumper" + }, + { + "name": "leftStick", + "value": 7, + "DocName": "left stick" + }, + { + "name": "rightStick", + "value": 8, + "DocName": "right stick" + }, + { + "name": "ellipses", + "value": 9 + }, + { + "name": "hamburger", + "value": 10 + }, + { + "name": "stadia", + "value": 11 + }, + { + "name": "rightTrigger", + "value": 12, + "DocName": "right trigger" + }, + { + "name": "leftTrigger", + "value": 13, + "DocName": "left trigger" + }, + { + "name": "google", + "value": 14 + }, + { + "name": "frame", + "value": 15 + } + ], + "sticks": [ + { + "NameParts": [ + "left", + "X" + ], + "value": 0 + }, + { + "NameParts": [ + "right", + "X" + ], + "value": 3 + }, + { + "NameParts": [ + "left", + "Y" + ], + "value": 1 + }, + { + "NameParts": [ + "right", + "Y" + ], + "value": 4 + } + ] + } +] diff --git a/wpilibj/src/generate/hids.schema.json b/wpilibj/src/generate/hids.schema.json new file mode 100644 index 00000000000..3b9dca30150 --- /dev/null +++ b/wpilibj/src/generate/hids.schema.json @@ -0,0 +1,120 @@ +{ + "$schema": "https://json-schema.org/draft/2019-09/schema", + "$id": "https://raw.githubusercontent.com/wpilibsuite/allwpilib/main/wpilibj/src/generate/hids.schema.json", + "title": "A schema for defining HIDs with JSON", + "type": "array", + "default": [], + "items": { + "title": "A Schema", + "type": "object", + "required": [ + "ConsoleName", + "Manufacturer", + "SkipReporting", + "AxisNameSuffix", + "buttons", + "sticks" + ], + "properties": { + "ConsoleName": { + "description": "The name of the console this controller is associated with", + "type": "string" + }, + "Manufacturer": { + "description": "The manufacturer of the console", + "type": "string" + }, + "SkipReporting": { + "description": "Whether or not to skip the usage reporting call", + "type": "boolean" + }, + "AxisNameSuffix": { + "description": "The suffix of an axis that shouldn't have Axis appended to its name", + "type": "string" + }, + "buttons": { + "description": "A list of buttons on the controller", + "type": "array", + "items": { + "description": "A description of a button on the controller", + "type": "object", + "required": [ + "name", + "value" + ], + "properties": { + "name": { + "description": "The name in lowerCamelCase", + "type": "string" + }, + "value": { + "description": "The button value", + "type": "integer" + }, + "DocName": { + "description": "The name of the button to use in docs", + "type": "string" + } + } + } + }, + "sticks": { + "description": "A list of joysticks on the controller", + "type": "array", + "items": { + "description": "A description of a joystick", + "type": "object", + "required": [ + "NameParts", + "value" + ], + "properties": { + "NameParts": { + "description": "The parts of the joystick name in lowerCamelCase", + "type": "array", + "items": { + "description": "The different components of a joystick name, direction and axis", + "type": "string" + } + }, + "value": { + "description": "The axis value", + "type": "integer" + } + } + } + }, + "triggers": { + "description": "A list of triggers on the controller", + "type": "array", + "items": { + "description": "A description of a trigger on the controller", + "type": "object", + "required": [ + "name", + "value", + "UseThresholdMethods" + ], + "properties": { + "name": { + "description": "The name of the trigger to use in code", + "type": "string" + }, + "value": { + "description": "The axis value", + "type": "integer" + }, + "DocName": { + "description": "The name of the trigger for use in docs", + "type": "string" + }, + "UseThresholdMethods": { + "description": "Whether or not an method is created where an event fires based on the axis value", + "type": "boolean" + } + } + } + } + } + } +} diff --git a/wpilibj/src/generate/hidsim.java.jinja b/wpilibj/src/generate/hidsim.java.jinja new file mode 100644 index 00000000000..c2f2704befb --- /dev/null +++ b/wpilibj/src/generate/hidsim.java.jinja @@ -0,0 +1,115 @@ +// Copyright (c) FIRST and other WPILib contributors. +// Open Source Software; you can modify and/or share it under the terms of +// the WPILib BSD license file in the root directory of this project. + +// THIS FILE WAS AUTO-GENERATED BY ./wpilibj/generate_hids.py. DO NOT MODIFY +{% macro capitalize_first(string) -%} +{{ string[0]|capitalize + string[1:] }} +{%- endmacro %} +package edu.wpi.first.wpilibj.simulation; + +import edu.wpi.first.wpilibj.{{ ConsoleName }}Controller; + +/** Class to control a simulated {{ ConsoleName }} controller. */ +public class {{ ConsoleName }}ControllerSim extends GenericHIDSim { + /** + * Constructs from a {{ ConsoleName }}Controller object. + * + * @param joystick controller to simulate + */ + @SuppressWarnings("this-escape") + public {{ ConsoleName }}ControllerSim({{ ConsoleName }}Controller joystick) { + super(joystick); + setAxisCount({{ sticks|length + triggers|length }}); + setButtonCount({{ buttons|length }}); + setPOVCount(1); + } + + /** + * Constructs from a joystick port number. + * + * @param port port number + */ + @SuppressWarnings("this-escape") + public {{ ConsoleName }}ControllerSim(int port) { + super(port); + setAxisCount({{ sticks|length + triggers|length }}); + setButtonCount({{ buttons|length }}); + setPOVCount(1); + } +{% for stick in sticks %} + /** + * Change the {{ stick.NameParts|join(" ") }} value of the controller's joystick. + * + * @param value the new value + */ + public void set{{ stick.NameParts|map("capitalize")|join }}(double value) { + setRawAxis({{ ConsoleName }}Controller.Axis.k{{ stick.NameParts|map("capitalize")|join }}.value, value); + } +{% endfor -%} +{% for trigger in triggers %} + /** + * Change the value of the {{ trigger.DocName }} axis on the controller. + * + * @param value the new value + */ + public void set{{ capitalize_first(trigger.name) }}Axis(double value) { + setRawAxis({{ ConsoleName }}Controller.Axis.k{{ capitalize_first(trigger.name) }}.value, value); + } +{% endfor -%} +{% for button in buttons %} + /** + * Change the value of the {{ button.DocName|default(button.name) }} button on the controller. + * + * @param value the new value + */ + public void set{{ capitalize_first(button.name) }}Button(boolean value) { + setRawButton({{ ConsoleName }}Controller.Button.k{{ capitalize_first(button.name) }}.value, value); + } +{% endfor -%} +{% if ConsoleName == "Xbox" %} + /** + * Change the value of the left bumper on the joystick. + * + * @param state the new value + * @deprecated Use {@link setLeftBumperButton} instead + */ + @Deprecated(since = "2025", forRemoval = true) + public void setLeftBumper(boolean state) { + setRawButton(XboxController.Button.kLeftBumper.value, state); + } + + /** + * Change the value of the right bumper on the joystick. + * + * @param state the new value + * @deprecated Use {@link setRightBumperButton} instead + */ + @Deprecated(since = "2025", forRemoval = true) + public void setRightBumper(boolean state) { + setRawButton(XboxController.Button.kRightBumper.value, state); + } +{% elif ConsoleName == "PS4" %} + /** + * Change the value of the touchpad button on the controller. + * + * @param value the new value + * @deprecated Use {@link setTouchpadButton} instead + */ + @Deprecated(since = "2025", forRemoval = true) + public void setTouchpad(boolean value) { + setRawButton(PS4Controller.Button.kTouchpad.value, value); + } +{% elif ConsoleName == "PS5" %} + /** + * Change the value of the touchpad button on the controller. + * + * @param value the new value + * @deprecated Use {@link setTouchpadButton} instead + */ + @Deprecated(since = "2025", forRemoval = true) + public void setTouchpad(boolean value) { + setRawButton(PS5Controller.Button.kTouchpad.value, value); + } +{% endif -%} +} diff --git a/wpilibj/src/main/java/edu/wpi/first/wpilibj/PS4Controller.java b/wpilibj/src/generated/main/java/edu/wpi/first/wpilibj/PS4Controller.java similarity index 68% rename from wpilibj/src/main/java/edu/wpi/first/wpilibj/PS4Controller.java rename to wpilibj/src/generated/main/java/edu/wpi/first/wpilibj/PS4Controller.java index e000c6f51d3..3195c5122b0 100644 --- a/wpilibj/src/main/java/edu/wpi/first/wpilibj/PS4Controller.java +++ b/wpilibj/src/generated/main/java/edu/wpi/first/wpilibj/PS4Controller.java @@ -2,6 +2,8 @@ // Open Source Software; you can modify and/or share it under the terms of // the WPILib BSD license file in the root directory of this project. +// THIS FILE WAS AUTO-GENERATED BY ./wpilibj/generate_hids.py. DO NOT MODIFY + package edu.wpi.first.wpilibj; import edu.wpi.first.hal.FRCNetComm.tResourceType; @@ -16,63 +18,52 @@ * requested the most recent value is returned. There is a single class instance for each controller * and the mapping of ports to hardware buttons depends on the code in the Driver Station. * - *

Only first party controllers from Sony are guaranteed to have the correct mapping, and only - * through the official NI DS. Sim is not guaranteed to have the same mapping, as well as any 3rd - * party controllers. + *

Only first party controllers from Sony are guaranteed to have the correct mapping, and + * only through the official NI DS. Sim is not guaranteed to have the same mapping, as well as any + * 3rd party controllers. */ public class PS4Controller extends GenericHID { - /** - * Construct an instance of a device. - * - * @param port The port index on the Driver Station that the device is plugged into. - */ - public PS4Controller(int port) { - super(port); - - HAL.report(tResourceType.kResourceType_PS4Controller, port + 1); - } - /** Represents a digital button on a PS4Controller. */ public enum Button { /** Square button. */ kSquare(1), - /** X button. */ + /** Cross button. */ kCross(2), /** Circle button. */ kCircle(3), /** Triangle button. */ kTriangle(4), - /** Left Trigger 1 button. */ + /** Left trigger 1 button. */ kL1(5), - /** Right Trigger 1 button. */ + /** Right trigger 1 button. */ kR1(6), - /** Left Trigger 2 button. */ + /** Left trigger 2 button. */ kL2(7), - /** Right Trigger 2 button. */ + /** Right trigger 2 button. */ kR2(8), /** Share button. */ kShare(9), - /** Option button. */ + /** Options button. */ kOptions(10), - /** Left stick button. */ + /** L3 (left stick) button. */ kL3(11), - /** Right stick button. */ + /** R3 (right stick) button. */ kR3(12), /** PlayStation button. */ kPS(13), - /** Touchpad click button. */ + /** Touchpad button. */ kTouchpad(14); /** Button value. */ public final int value; - Button(int index) { - this.value = index; + Button(int value) { + this.value = value; } /** * Get the human-friendly name of the button, matching the relevant methods. This is done by - * stripping the leading `k`, and if not the touchpad append `Button`. + * stripping the leading `k`, and appending `Button`. * *

Primarily used for automated unit tests. * @@ -80,15 +71,12 @@ public enum Button { */ @Override public String toString() { - var name = this.name().substring(1); // Remove leading `k` - if (this == kTouchpad) { - return name; - } - return name + "Button"; + // Remove leading `k` + return this.name().substring(1) + "Button"; } } - /** Represents an axis on a PS4Controller. */ + /** Represents an axis on an PS4Controller. */ public enum Axis { /** Left X axis. */ kLeftX(0), @@ -98,21 +86,21 @@ public enum Axis { kRightX(2), /** Right Y axis. */ kRightY(5), - /** Left Trigger 2. */ + /** Left trigger 2. */ kL2(3), - /** Right Trigger 2. */ + /** Right trigger 2. */ kR2(4); /** Axis value. */ public final int value; - Axis(int index) { - value = index; + Axis(int value) { + this.value = value; } /** * Get the human-friendly name of the axis, matching the relevant methods. This is done by - * stripping the leading `k`, and if one of L2/R2 append `Axis`. + * stripping the leading `k`, and appending `Axis` if the name ends with `2`. * *

Primarily used for automated unit tests. * @@ -129,488 +117,529 @@ public String toString() { } /** - * Get the X axis value of left side of the controller. + * Construct an instance of a controller. * - * @return the axis value. + * @param port The port index on the Driver Station that the controller is plugged into (0-5). */ - public double getLeftX() { - return getRawAxis(Axis.kLeftX.value); + public PS4Controller(final int port) { + super(port); + HAL.report(tResourceType.kResourceType_PS4Controller, port + 1); } /** - * Get the X axis value of right side of the controller. + * Get the X axis value of left side of the controller. * - * @return the axis value. + * @return The axis value. */ - public double getRightX() { - return getRawAxis(Axis.kRightX.value); + public double getLeftX() { + return getRawAxis(Axis.kLeftX.value); } /** * Get the Y axis value of left side of the controller. * - * @return the axis value. + * @return The axis value. */ public double getLeftY() { return getRawAxis(Axis.kLeftY.value); } + /** + * Get the X axis value of right side of the controller. + * + * @return The axis value. + */ + public double getRightX() { + return getRawAxis(Axis.kRightX.value); + } + /** * Get the Y axis value of right side of the controller. * - * @return the axis value. + * @return The axis value. */ public double getRightY() { return getRawAxis(Axis.kRightY.value); } /** - * Get the L2 axis value of the controller. Note that this axis is bound to the range of [0, 1] as - * opposed to the usual [-1, 1]. + * Get the left trigger 2 axis value of the controller. Note that this axis is bound to the + * range of [0, 1] as opposed to the usual [-1, 1]. * - * @return the axis value. + * @return The axis value. */ public double getL2Axis() { return getRawAxis(Axis.kL2.value); } /** - * Get the R2 axis value of the controller. Note that this axis is bound to the range of [0, 1] as - * opposed to the usual [-1, 1]. + * Get the right trigger 2 axis value of the controller. Note that this axis is bound to the + * range of [0, 1] as opposed to the usual [-1, 1]. * - * @return the axis value. + * @return The axis value. */ public double getR2Axis() { return getRawAxis(Axis.kR2.value); } /** - * Read the value of the left trigger button on the controller. + * Read the value of the square button on the controller. * * @return The state of the button. */ - public boolean getL2Button() { - return getRawButton(Button.kL2.value); + public boolean getSquareButton() { + return getRawButton(Button.kSquare.value); } /** - * Read the value of the right trigger button on the controller. + * Whether the square button was pressed since the last check. * - * @return The state of the button. + * @return Whether the button was pressed since the last check. */ - public boolean getR2Button() { - return getRawButton(Button.kR2.value); + public boolean getSquareButtonPressed() { + return getRawButtonPressed(Button.kSquare.value); } /** - * Whether the L2 button was pressed since the last check. + * Whether the square button was released since the last check. * - * @return Whether the button was pressed since the last check. + * @return Whether the button was released since the last check. */ - public boolean getL2ButtonPressed() { - return getRawButtonPressed(Button.kL2.value); + public boolean getSquareButtonReleased() { + return getRawButtonReleased(Button.kSquare.value); } /** - * Whether the R2 button was pressed since the last check. + * Constructs an event instance around the square button's digital signal. * - * @return Whether the button was pressed since the last check. + * @param loop the event loop instance to attach the event to. + * @return an event instance representing the square button's digital signal + * attached to the given loop. */ - public boolean getR2ButtonPressed() { - return getRawButtonPressed(Button.kR2.value); + public BooleanEvent square(EventLoop loop) { + return new BooleanEvent(loop, this::getSquareButton); } /** - * Whether the L2 button was released since the last check. + * Read the value of the cross button on the controller. * - * @return Whether the button was released since the last check. + * @return The state of the button. */ - public boolean getL2ButtonReleased() { - return getRawButtonReleased(Button.kL2.value); + public boolean getCrossButton() { + return getRawButton(Button.kCross.value); } /** - * Whether the R2 button was released since the last check. + * Whether the cross button was pressed since the last check. * - * @return Whether the button was released since the last check. + * @return Whether the button was pressed since the last check. */ - public boolean getR2ButtonReleased() { - return getRawButtonReleased(Button.kR2.value); + public boolean getCrossButtonPressed() { + return getRawButtonPressed(Button.kCross.value); } /** - * Constructs an event instance around the L2 button's digital signal. + * Whether the cross button was released since the last check. * - * @param loop the event loop instance to attach the event to. - * @return an event instance representing the L2 button's digital signal attached to the given - * loop. + * @return Whether the button was released since the last check. */ - @SuppressWarnings("MethodName") - public BooleanEvent L2(EventLoop loop) { - return new BooleanEvent(loop, this::getL2Button); + public boolean getCrossButtonReleased() { + return getRawButtonReleased(Button.kCross.value); } /** - * Constructs an event instance around the R2 button's digital signal. + * Constructs an event instance around the cross button's digital signal. * * @param loop the event loop instance to attach the event to. - * @return an event instance representing the R2 button's digital signal attached to the given - * loop. + * @return an event instance representing the cross button's digital signal + * attached to the given loop. */ - @SuppressWarnings("MethodName") - public BooleanEvent R2(EventLoop loop) { - return new BooleanEvent(loop, this::getR2Button); + public BooleanEvent cross(EventLoop loop) { + return new BooleanEvent(loop, this::getCrossButton); } /** - * Read the value of the L1 button on the controller. + * Read the value of the circle button on the controller. * * @return The state of the button. */ - public boolean getL1Button() { - return getRawButton(Button.kL1.value); + public boolean getCircleButton() { + return getRawButton(Button.kCircle.value); } /** - * Read the value of the R1 button on the controller. + * Whether the circle button was pressed since the last check. * - * @return The state of the button. + * @return Whether the button was pressed since the last check. */ - public boolean getR1Button() { - return getRawButton(Button.kR1.value); + public boolean getCircleButtonPressed() { + return getRawButtonPressed(Button.kCircle.value); } /** - * Whether the L1 button was pressed since the last check. + * Whether the circle button was released since the last check. * - * @return Whether the button was pressed since the last check. + * @return Whether the button was released since the last check. */ - public boolean getL1ButtonPressed() { - return getRawButtonPressed(Button.kL1.value); + public boolean getCircleButtonReleased() { + return getRawButtonReleased(Button.kCircle.value); } /** - * Whether the R1 button was pressed since the last check. + * Constructs an event instance around the circle button's digital signal. * - * @return Whether the button was pressed since the last check. + * @param loop the event loop instance to attach the event to. + * @return an event instance representing the circle button's digital signal + * attached to the given loop. */ - public boolean getR1ButtonPressed() { - return getRawButtonPressed(Button.kR1.value); + public BooleanEvent circle(EventLoop loop) { + return new BooleanEvent(loop, this::getCircleButton); } /** - * Whether the L1 button was released since the last check. + * Read the value of the triangle button on the controller. * - * @return Whether the button was released since the last check. + * @return The state of the button. */ - public boolean getL1ButtonReleased() { - return getRawButtonReleased(Button.kL1.value); + public boolean getTriangleButton() { + return getRawButton(Button.kTriangle.value); } /** - * Whether the R1 button was released since the last check. + * Whether the triangle button was pressed since the last check. * - * @return Whether the button was released since the last check. + * @return Whether the button was pressed since the last check. */ - public boolean getR1ButtonReleased() { - return getRawButtonReleased(Button.kR1.value); + public boolean getTriangleButtonPressed() { + return getRawButtonPressed(Button.kTriangle.value); } /** - * Constructs an event instance around the L1 button's digital signal. + * Whether the triangle button was released since the last check. * - * @param loop the event loop instance to attach the event to. - * @return an event instance representing the L1 button's digital signal attached to the given - * loop. + * @return Whether the button was released since the last check. */ - @SuppressWarnings("MethodName") - public BooleanEvent L1(EventLoop loop) { - return new BooleanEvent(loop, this::getL1Button); + public boolean getTriangleButtonReleased() { + return getRawButtonReleased(Button.kTriangle.value); } /** - * Constructs an event instance around the R1 button's digital signal. + * Constructs an event instance around the triangle button's digital signal. * * @param loop the event loop instance to attach the event to. - * @return an event instance representing the R1 button's digital signal attached to the given - * loop. + * @return an event instance representing the triangle button's digital signal + * attached to the given loop. */ - @SuppressWarnings("MethodName") - public BooleanEvent R1(EventLoop loop) { - return new BooleanEvent(loop, this::getR1Button); + public BooleanEvent triangle(EventLoop loop) { + return new BooleanEvent(loop, this::getTriangleButton); } /** - * Read the value of the L3 button (pressing the left analog stick) on the controller. + * Read the value of the left trigger 1 button on the controller. * * @return The state of the button. */ - public boolean getL3Button() { - return getRawButton(Button.kL3.value); + public boolean getL1Button() { + return getRawButton(Button.kL1.value); } /** - * Read the value of the R3 button (pressing the right analog stick) on the controller. + * Whether the left trigger 1 button was pressed since the last check. * - * @return The state of the button. + * @return Whether the button was pressed since the last check. */ - public boolean getR3Button() { - return getRawButton(Button.kR3.value); + public boolean getL1ButtonPressed() { + return getRawButtonPressed(Button.kL1.value); } /** - * Whether the L3 (left stick) button was pressed since the last check. + * Whether the left trigger 1 button was released since the last check. * - * @return Whether the button was pressed since the last check. + * @return Whether the button was released since the last check. */ - public boolean getL3ButtonPressed() { - return getRawButtonPressed(Button.kL3.value); + public boolean getL1ButtonReleased() { + return getRawButtonReleased(Button.kL1.value); } /** - * Whether the R3 (right stick) button was pressed since the last check. + * Constructs an event instance around the left trigger 1 button's digital signal. * - * @return Whether the button was pressed since the last check. + * @param loop the event loop instance to attach the event to. + * @return an event instance representing the left trigger 1 button's digital signal + * attached to the given loop. */ - public boolean getR3ButtonPressed() { - return getRawButtonPressed(Button.kR3.value); + public BooleanEvent L1(EventLoop loop) { + return new BooleanEvent(loop, this::getL1Button); } /** - * Whether the L3 (left stick) button was released since the last check. + * Read the value of the right trigger 1 button on the controller. * - * @return Whether the button was released since the last check. + * @return The state of the button. */ - public boolean getL3ButtonReleased() { - return getRawButtonReleased(Button.kL3.value); + public boolean getR1Button() { + return getRawButton(Button.kR1.value); } /** - * Whether the R3 (right stick) button was released since the last check. + * Whether the right trigger 1 button was pressed since the last check. + * + * @return Whether the button was pressed since the last check. + */ + public boolean getR1ButtonPressed() { + return getRawButtonPressed(Button.kR1.value); + } + + /** + * Whether the right trigger 1 button was released since the last check. * * @return Whether the button was released since the last check. */ - public boolean getR3ButtonReleased() { - return getRawButtonReleased(Button.kR3.value); + public boolean getR1ButtonReleased() { + return getRawButtonReleased(Button.kR1.value); } /** - * Constructs an event instance around the L3 button's digital signal. + * Constructs an event instance around the right trigger 1 button's digital signal. * * @param loop the event loop instance to attach the event to. - * @return an event instance representing the L3 button's digital signal attached to the given - * loop. + * @return an event instance representing the right trigger 1 button's digital signal + * attached to the given loop. */ - @SuppressWarnings("MethodName") - public BooleanEvent L3(EventLoop loop) { - return new BooleanEvent(loop, this::getL3Button); + public BooleanEvent R1(EventLoop loop) { + return new BooleanEvent(loop, this::getR1Button); + } + + /** + * Read the value of the left trigger 2 button on the controller. + * + * @return The state of the button. + */ + public boolean getL2Button() { + return getRawButton(Button.kL2.value); + } + + /** + * Whether the left trigger 2 button was pressed since the last check. + * + * @return Whether the button was pressed since the last check. + */ + public boolean getL2ButtonPressed() { + return getRawButtonPressed(Button.kL2.value); + } + + /** + * Whether the left trigger 2 button was released since the last check. + * + * @return Whether the button was released since the last check. + */ + public boolean getL2ButtonReleased() { + return getRawButtonReleased(Button.kL2.value); } /** - * Constructs an event instance around the R3 button's digital signal. + * Constructs an event instance around the left trigger 2 button's digital signal. * * @param loop the event loop instance to attach the event to. - * @return an event instance representing the R3 button's digital signal attached to the given - * loop. + * @return an event instance representing the left trigger 2 button's digital signal + * attached to the given loop. */ - @SuppressWarnings("MethodName") - public BooleanEvent R3(EventLoop loop) { - return new BooleanEvent(loop, this::getR3Button); + public BooleanEvent L2(EventLoop loop) { + return new BooleanEvent(loop, this::getL2Button); } /** - * Read the value of the Square button on the controller. + * Read the value of the right trigger 2 button on the controller. * * @return The state of the button. */ - public boolean getSquareButton() { - return getRawButton(Button.kSquare.value); + public boolean getR2Button() { + return getRawButton(Button.kR2.value); } /** - * Whether the Square button was pressed since the last check. + * Whether the right trigger 2 button was pressed since the last check. * * @return Whether the button was pressed since the last check. */ - public boolean getSquareButtonPressed() { - return getRawButtonPressed(Button.kSquare.value); + public boolean getR2ButtonPressed() { + return getRawButtonPressed(Button.kR2.value); } /** - * Whether the Square button was released since the last check. + * Whether the right trigger 2 button was released since the last check. * * @return Whether the button was released since the last check. */ - public boolean getSquareButtonReleased() { - return getRawButtonReleased(Button.kSquare.value); + public boolean getR2ButtonReleased() { + return getRawButtonReleased(Button.kR2.value); } /** - * Constructs an event instance around the square button's digital signal. + * Constructs an event instance around the right trigger 2 button's digital signal. * * @param loop the event loop instance to attach the event to. - * @return an event instance representing the square button's digital signal attached to the given - * loop. + * @return an event instance representing the right trigger 2 button's digital signal + * attached to the given loop. */ - public BooleanEvent square(EventLoop loop) { - return new BooleanEvent(loop, this::getSquareButton); + public BooleanEvent R2(EventLoop loop) { + return new BooleanEvent(loop, this::getR2Button); } /** - * Read the value of the Cross button on the controller. + * Read the value of the share button on the controller. * * @return The state of the button. */ - public boolean getCrossButton() { - return getRawButton(Button.kCross.value); + public boolean getShareButton() { + return getRawButton(Button.kShare.value); } /** - * Whether the Cross button was pressed since the last check. + * Whether the share button was pressed since the last check. * * @return Whether the button was pressed since the last check. */ - public boolean getCrossButtonPressed() { - return getRawButtonPressed(Button.kCross.value); + public boolean getShareButtonPressed() { + return getRawButtonPressed(Button.kShare.value); } /** - * Whether the Cross button was released since the last check. + * Whether the share button was released since the last check. * * @return Whether the button was released since the last check. */ - public boolean getCrossButtonReleased() { - return getRawButtonReleased(Button.kCross.value); + public boolean getShareButtonReleased() { + return getRawButtonReleased(Button.kShare.value); } /** - * Constructs an event instance around the cross button's digital signal. + * Constructs an event instance around the share button's digital signal. * * @param loop the event loop instance to attach the event to. - * @return an event instance representing the cross button's digital signal attached to the given - * loop. + * @return an event instance representing the share button's digital signal + * attached to the given loop. */ - public BooleanEvent cross(EventLoop loop) { - return new BooleanEvent(loop, this::getCrossButton); + public BooleanEvent share(EventLoop loop) { + return new BooleanEvent(loop, this::getShareButton); } /** - * Read the value of the Triangle button on the controller. + * Read the value of the options button on the controller. * * @return The state of the button. */ - public boolean getTriangleButton() { - return getRawButton(Button.kTriangle.value); + public boolean getOptionsButton() { + return getRawButton(Button.kOptions.value); } /** - * Whether the Triangle button was pressed since the last check. + * Whether the options button was pressed since the last check. * * @return Whether the button was pressed since the last check. */ - public boolean getTriangleButtonPressed() { - return getRawButtonPressed(Button.kTriangle.value); + public boolean getOptionsButtonPressed() { + return getRawButtonPressed(Button.kOptions.value); } /** - * Whether the Triangle button was released since the last check. + * Whether the options button was released since the last check. * * @return Whether the button was released since the last check. */ - public boolean getTriangleButtonReleased() { - return getRawButtonReleased(Button.kTriangle.value); + public boolean getOptionsButtonReleased() { + return getRawButtonReleased(Button.kOptions.value); } /** - * Constructs an event instance around the triangle button's digital signal. + * Constructs an event instance around the options button's digital signal. * * @param loop the event loop instance to attach the event to. - * @return an event instance representing the triangle button's digital signal attached to the - * given loop. + * @return an event instance representing the options button's digital signal + * attached to the given loop. */ - public BooleanEvent triangle(EventLoop loop) { - return new BooleanEvent(loop, this::getTriangleButton); + public BooleanEvent options(EventLoop loop) { + return new BooleanEvent(loop, this::getOptionsButton); } /** - * Read the value of the Circle button on the controller. + * Read the value of the L3 (left stick) button on the controller. * * @return The state of the button. */ - public boolean getCircleButton() { - return getRawButton(Button.kCircle.value); + public boolean getL3Button() { + return getRawButton(Button.kL3.value); } /** - * Whether the Circle button was pressed since the last check. + * Whether the L3 (left stick) button was pressed since the last check. * * @return Whether the button was pressed since the last check. */ - public boolean getCircleButtonPressed() { - return getRawButtonPressed(Button.kCircle.value); + public boolean getL3ButtonPressed() { + return getRawButtonPressed(Button.kL3.value); } /** - * Whether the Circle button was released since the last check. + * Whether the L3 (left stick) button was released since the last check. * * @return Whether the button was released since the last check. */ - public boolean getCircleButtonReleased() { - return getRawButtonReleased(Button.kCircle.value); + public boolean getL3ButtonReleased() { + return getRawButtonReleased(Button.kL3.value); } /** - * Constructs an event instance around the circle button's digital signal. + * Constructs an event instance around the L3 (left stick) button's digital signal. * * @param loop the event loop instance to attach the event to. - * @return an event instance representing the circle button's digital signal attached to the given - * loop. + * @return an event instance representing the L3 (left stick) button's digital signal + * attached to the given loop. */ - public BooleanEvent circle(EventLoop loop) { - return new BooleanEvent(loop, this::getCircleButton); + public BooleanEvent L3(EventLoop loop) { + return new BooleanEvent(loop, this::getL3Button); } /** - * Read the value of the share button on the controller. + * Read the value of the R3 (right stick) button on the controller. * * @return The state of the button. */ - public boolean getShareButton() { - return getRawButton(Button.kShare.value); + public boolean getR3Button() { + return getRawButton(Button.kR3.value); } /** - * Whether the share button was pressed since the last check. + * Whether the R3 (right stick) button was pressed since the last check. * * @return Whether the button was pressed since the last check. */ - public boolean getShareButtonPressed() { - return getRawButtonPressed(Button.kShare.value); + public boolean getR3ButtonPressed() { + return getRawButtonPressed(Button.kR3.value); } /** - * Whether the share button was released since the last check. + * Whether the R3 (right stick) button was released since the last check. * * @return Whether the button was released since the last check. */ - public boolean getShareButtonReleased() { - return getRawButtonReleased(Button.kShare.value); + public boolean getR3ButtonReleased() { + return getRawButtonReleased(Button.kR3.value); } /** - * Constructs an event instance around the share button's digital signal. + * Constructs an event instance around the R3 (right stick) button's digital signal. * * @param loop the event loop instance to attach the event to. - * @return an event instance representing the share button's digital signal attached to the given - * loop. + * @return an event instance representing the R3 (right stick) button's digital signal + * attached to the given loop. */ - @SuppressWarnings("MethodName") - public BooleanEvent share(EventLoop loop) { - return new BooleanEvent(loop, this::getShareButton); + public BooleanEvent R3(EventLoop loop) { + return new BooleanEvent(loop, this::getR3Button); } /** - * Read the value of the PS button on the controller. + * Read the value of the PlayStation button on the controller. * * @return The state of the button. */ @@ -619,7 +648,7 @@ public boolean getPSButton() { } /** - * Whether the PS button was pressed since the last check. + * Whether the PlayStation button was pressed since the last check. * * @return Whether the button was pressed since the last check. */ @@ -628,7 +657,7 @@ public boolean getPSButtonPressed() { } /** - * Whether the PS button was released since the last check. + * Whether the PlayStation button was released since the last check. * * @return Whether the button was released since the last check. */ @@ -637,60 +666,61 @@ public boolean getPSButtonReleased() { } /** - * Constructs an event instance around the PS button's digital signal. + * Constructs an event instance around the PlayStation button's digital signal. * * @param loop the event loop instance to attach the event to. - * @return an event instance representing the PS button's digital signal attached to the given - * loop. + * @return an event instance representing the PlayStation button's digital signal + * attached to the given loop. */ - @SuppressWarnings("MethodName") public BooleanEvent PS(EventLoop loop) { return new BooleanEvent(loop, this::getPSButton); } /** - * Read the value of the options button on the controller. + * Read the value of the touchpad button on the controller. * * @return The state of the button. */ - public boolean getOptionsButton() { - return getRawButton(Button.kOptions.value); + public boolean getTouchpadButton() { + return getRawButton(Button.kTouchpad.value); } /** - * Whether the options button was pressed since the last check. + * Whether the touchpad button was pressed since the last check. * * @return Whether the button was pressed since the last check. */ - public boolean getOptionsButtonPressed() { - return getRawButtonPressed(Button.kOptions.value); + public boolean getTouchpadButtonPressed() { + return getRawButtonPressed(Button.kTouchpad.value); } /** - * Whether the options button was released since the last check. + * Whether the touchpad button was released since the last check. * * @return Whether the button was released since the last check. */ - public boolean getOptionsButtonReleased() { - return getRawButtonReleased(Button.kOptions.value); + public boolean getTouchpadButtonReleased() { + return getRawButtonReleased(Button.kTouchpad.value); } /** - * Constructs an event instance around the options button's digital signal. + * Constructs an event instance around the touchpad button's digital signal. * * @param loop the event loop instance to attach the event to. - * @return an event instance representing the options button's digital signal attached to the - * given loop. + * @return an event instance representing the touchpad button's digital signal + * attached to the given loop. */ - public BooleanEvent options(EventLoop loop) { - return new BooleanEvent(loop, this::getOptionsButton); + public BooleanEvent touchpad(EventLoop loop) { + return new BooleanEvent(loop, this::getTouchpadButton); } /** * Read the value of the touchpad on the controller. * * @return The state of the touchpad. + * @deprecated Use {@link getTouchpadButton} instead */ + @Deprecated(since = "2025", forRemoval = true) public boolean getTouchpad() { return getRawButton(Button.kTouchpad.value); } @@ -699,7 +729,9 @@ public boolean getTouchpad() { * Whether the touchpad was pressed since the last check. * * @return Whether the touchpad was pressed since the last check. + * @deprecated Use {@link getTouchpadButtonPressed} instead */ + @Deprecated(since = "2025", forRemoval = true) public boolean getTouchpadPressed() { return getRawButtonPressed(Button.kTouchpad.value); } @@ -708,19 +740,10 @@ public boolean getTouchpadPressed() { * Whether the touchpad was released since the last check. * * @return Whether the touchpad was released since the last check. + * @deprecated Use {@link getTouchpadButtonReleased} instead */ + @Deprecated(since = "2025", forRemoval = true) public boolean getTouchpadReleased() { return getRawButtonReleased(Button.kTouchpad.value); } - - /** - * Constructs an event instance around the touchpad's digital signal. - * - * @param loop the event loop instance to attach the event to. - * @return an event instance representing the touchpad's digital signal attached to the given - * loop. - */ - public BooleanEvent touchpad(EventLoop loop) { - return new BooleanEvent(loop, this::getTouchpad); - } } diff --git a/wpilibj/src/main/java/edu/wpi/first/wpilibj/PS5Controller.java b/wpilibj/src/generated/main/java/edu/wpi/first/wpilibj/PS5Controller.java similarity index 67% rename from wpilibj/src/main/java/edu/wpi/first/wpilibj/PS5Controller.java rename to wpilibj/src/generated/main/java/edu/wpi/first/wpilibj/PS5Controller.java index 18cb738e883..7b0e3083aba 100644 --- a/wpilibj/src/main/java/edu/wpi/first/wpilibj/PS5Controller.java +++ b/wpilibj/src/generated/main/java/edu/wpi/first/wpilibj/PS5Controller.java @@ -2,8 +2,12 @@ // Open Source Software; you can modify and/or share it under the terms of // the WPILib BSD license file in the root directory of this project. +// THIS FILE WAS AUTO-GENERATED BY ./wpilibj/generate_hids.py. DO NOT MODIFY + package edu.wpi.first.wpilibj; +// import edu.wpi.first.hal.FRCNetComm.tResourceType; +// import edu.wpi.first.hal.HAL; import edu.wpi.first.wpilibj.event.BooleanEvent; import edu.wpi.first.wpilibj.event.EventLoop; @@ -14,26 +18,16 @@ * requested the most recent value is returned. There is a single class instance for each controller * and the mapping of ports to hardware buttons depends on the code in the Driver Station. * - *

Only first party controllers from Sony are guaranteed to have the correct mapping, and only - * through the official NI DS. Sim is not guaranteed to have the same mapping, as well as any 3rd - * party controllers. + *

Only first party controllers from Sony are guaranteed to have the correct mapping, and + * only through the official NI DS. Sim is not guaranteed to have the same mapping, as well as any + * 3rd party controllers. */ public class PS5Controller extends GenericHID { - /** - * Construct an instance of a device. - * - * @param port The port index on the Driver Station that the device is plugged into. - */ - public PS5Controller(int port) { - super(port); - // HAL.report(tResourceType.kResourceType_PS5Controller, port + 1); - } - /** Represents a digital button on a PS5Controller. */ public enum Button { /** Square button. */ kSquare(1), - /** X button. */ + /** Cross button. */ kCross(2), /** Circle button. */ kCircle(3), @@ -51,25 +45,25 @@ public enum Button { kCreate(9), /** Options button. */ kOptions(10), - /** Left stick button. */ + /** L3 (left stick) button. */ kL3(11), - /** Right stick button. */ + /** R3 (right stick) button. */ kR3(12), /** PlayStation button. */ kPS(13), - /** Touchpad click button. */ + /** Touchpad button. */ kTouchpad(14); /** Button value. */ public final int value; - Button(int index) { - this.value = index; + Button(int value) { + this.value = value; } /** * Get the human-friendly name of the button, matching the relevant methods. This is done by - * stripping the leading `k`, and if not the touchpad append `Button`. + * stripping the leading `k`, and appending `Button`. * *

Primarily used for automated unit tests. * @@ -77,15 +71,12 @@ public enum Button { */ @Override public String toString() { - var name = this.name().substring(1); // Remove leading `k` - if (this == kTouchpad) { - return name; - } - return name + "Button"; + // Remove leading `k` + return this.name().substring(1) + "Button"; } } - /** Represents an axis on a PS5Controller. */ + /** Represents an axis on an PS5Controller. */ public enum Axis { /** Left X axis. */ kLeftX(0), @@ -95,21 +86,21 @@ public enum Axis { kRightX(2), /** Right Y axis. */ kRightY(5), - /** Left Trigger 2. */ + /** Left trigger 2. */ kL2(3), - /** Right Trigger 2. */ + /** Right trigger 2. */ kR2(4); /** Axis value. */ public final int value; - Axis(int index) { - value = index; + Axis(int value) { + this.value = value; } /** * Get the human-friendly name of the axis, matching the relevant methods. This is done by - * stripping the leading `k`, and if one of L2/R2 append `Axis`. + * stripping the leading `k`, and appending `Axis` if the name ends with `2`. * *

Primarily used for automated unit tests. * @@ -126,488 +117,529 @@ public String toString() { } /** - * Get the X axis value of left side of the controller. + * Construct an instance of a controller. * - * @return the axis value. + * @param port The port index on the Driver Station that the controller is plugged into (0-5). */ - public double getLeftX() { - return getRawAxis(Axis.kLeftX.value); + public PS5Controller(final int port) { + super(port); + // HAL.report(tResourceType.kResourceType_PS5Controller, port + 1); } /** - * Get the X axis value of right side of the controller. + * Get the X axis value of left side of the controller. * - * @return the axis value. + * @return The axis value. */ - public double getRightX() { - return getRawAxis(Axis.kRightX.value); + public double getLeftX() { + return getRawAxis(Axis.kLeftX.value); } /** * Get the Y axis value of left side of the controller. * - * @return the axis value. + * @return The axis value. */ public double getLeftY() { return getRawAxis(Axis.kLeftY.value); } + /** + * Get the X axis value of right side of the controller. + * + * @return The axis value. + */ + public double getRightX() { + return getRawAxis(Axis.kRightX.value); + } + /** * Get the Y axis value of right side of the controller. * - * @return the axis value. + * @return The axis value. */ public double getRightY() { return getRawAxis(Axis.kRightY.value); } /** - * Get the L2 axis value of the controller. Note that this axis is bound to the range of [0, 1] as - * opposed to the usual [-1, 1]. + * Get the left trigger 2 axis value of the controller. Note that this axis is bound to the + * range of [0, 1] as opposed to the usual [-1, 1]. * - * @return the axis value. + * @return The axis value. */ public double getL2Axis() { return getRawAxis(Axis.kL2.value); } /** - * Get the R2 axis value of the controller. Note that this axis is bound to the range of [0, 1] as - * opposed to the usual [-1, 1]. + * Get the right trigger 2 axis value of the controller. Note that this axis is bound to the + * range of [0, 1] as opposed to the usual [-1, 1]. * - * @return the axis value. + * @return The axis value. */ public double getR2Axis() { return getRawAxis(Axis.kR2.value); } /** - * Read the value of the left trigger button on the controller. + * Read the value of the square button on the controller. * * @return The state of the button. */ - public boolean getL2Button() { - return getRawButton(Button.kL2.value); + public boolean getSquareButton() { + return getRawButton(Button.kSquare.value); } /** - * Read the value of the right trigger button on the controller. + * Whether the square button was pressed since the last check. * - * @return The state of the button. + * @return Whether the button was pressed since the last check. */ - public boolean getR2Button() { - return getRawButton(Button.kR2.value); + public boolean getSquareButtonPressed() { + return getRawButtonPressed(Button.kSquare.value); } /** - * Whether the L2 button was pressed since the last check. + * Whether the square button was released since the last check. * - * @return Whether the button was pressed since the last check. + * @return Whether the button was released since the last check. */ - public boolean getL2ButtonPressed() { - return getRawButtonPressed(Button.kL2.value); + public boolean getSquareButtonReleased() { + return getRawButtonReleased(Button.kSquare.value); } /** - * Whether the R2 button was pressed since the last check. + * Constructs an event instance around the square button's digital signal. * - * @return Whether the button was pressed since the last check. + * @param loop the event loop instance to attach the event to. + * @return an event instance representing the square button's digital signal + * attached to the given loop. */ - public boolean getR2ButtonPressed() { - return getRawButtonPressed(Button.kR2.value); + public BooleanEvent square(EventLoop loop) { + return new BooleanEvent(loop, this::getSquareButton); } /** - * Whether the L2 button was released since the last check. + * Read the value of the cross button on the controller. * - * @return Whether the button was released since the last check. + * @return The state of the button. */ - public boolean getL2ButtonReleased() { - return getRawButtonReleased(Button.kL2.value); + public boolean getCrossButton() { + return getRawButton(Button.kCross.value); } /** - * Whether the R2 button was released since the last check. + * Whether the cross button was pressed since the last check. * - * @return Whether the button was released since the last check. + * @return Whether the button was pressed since the last check. */ - public boolean getR2ButtonReleased() { - return getRawButtonReleased(Button.kR2.value); + public boolean getCrossButtonPressed() { + return getRawButtonPressed(Button.kCross.value); } /** - * Constructs an event instance around the L2 button's digital signal. + * Whether the cross button was released since the last check. * - * @param loop the event loop instance to attach the event to. - * @return an event instance representing the L2 button's digital signal attached to the given - * loop. + * @return Whether the button was released since the last check. */ - @SuppressWarnings("MethodName") - public BooleanEvent L2(EventLoop loop) { - return new BooleanEvent(loop, this::getL2Button); + public boolean getCrossButtonReleased() { + return getRawButtonReleased(Button.kCross.value); } /** - * Constructs an event instance around the R2 button's digital signal. + * Constructs an event instance around the cross button's digital signal. * * @param loop the event loop instance to attach the event to. - * @return an event instance representing the R2 button's digital signal attached to the given - * loop. + * @return an event instance representing the cross button's digital signal + * attached to the given loop. */ - @SuppressWarnings("MethodName") - public BooleanEvent R2(EventLoop loop) { - return new BooleanEvent(loop, this::getR2Button); + public BooleanEvent cross(EventLoop loop) { + return new BooleanEvent(loop, this::getCrossButton); } /** - * Read the value of the L1 button on the controller. + * Read the value of the circle button on the controller. * * @return The state of the button. */ - public boolean getL1Button() { - return getRawButton(Button.kL1.value); + public boolean getCircleButton() { + return getRawButton(Button.kCircle.value); } /** - * Read the value of the R1 button on the controller. + * Whether the circle button was pressed since the last check. * - * @return The state of the button. + * @return Whether the button was pressed since the last check. */ - public boolean getR1Button() { - return getRawButton(Button.kR1.value); + public boolean getCircleButtonPressed() { + return getRawButtonPressed(Button.kCircle.value); } /** - * Whether the L1 button was pressed since the last check. + * Whether the circle button was released since the last check. * - * @return Whether the button was pressed since the last check. + * @return Whether the button was released since the last check. */ - public boolean getL1ButtonPressed() { - return getRawButtonPressed(Button.kL1.value); + public boolean getCircleButtonReleased() { + return getRawButtonReleased(Button.kCircle.value); } /** - * Whether the R1 button was pressed since the last check. + * Constructs an event instance around the circle button's digital signal. * - * @return Whether the button was pressed since the last check. + * @param loop the event loop instance to attach the event to. + * @return an event instance representing the circle button's digital signal + * attached to the given loop. */ - public boolean getR1ButtonPressed() { - return getRawButtonPressed(Button.kR1.value); + public BooleanEvent circle(EventLoop loop) { + return new BooleanEvent(loop, this::getCircleButton); } /** - * Whether the L1 button was released since the last check. + * Read the value of the triangle button on the controller. * - * @return Whether the button was released since the last check. + * @return The state of the button. */ - public boolean getL1ButtonReleased() { - return getRawButtonReleased(Button.kL1.value); + public boolean getTriangleButton() { + return getRawButton(Button.kTriangle.value); } /** - * Whether the R1 button was released since the last check. + * Whether the triangle button was pressed since the last check. * - * @return Whether the button was released since the last check. + * @return Whether the button was pressed since the last check. */ - public boolean getR1ButtonReleased() { - return getRawButtonReleased(Button.kR1.value); + public boolean getTriangleButtonPressed() { + return getRawButtonPressed(Button.kTriangle.value); } /** - * Constructs an event instance around the L1 button's digital signal. + * Whether the triangle button was released since the last check. * - * @param loop the event loop instance to attach the event to. - * @return an event instance representing the L1 button's digital signal attached to the given - * loop. + * @return Whether the button was released since the last check. */ - @SuppressWarnings("MethodName") - public BooleanEvent L1(EventLoop loop) { - return new BooleanEvent(loop, this::getL1Button); + public boolean getTriangleButtonReleased() { + return getRawButtonReleased(Button.kTriangle.value); } /** - * Constructs an event instance around the R1 button's digital signal. + * Constructs an event instance around the triangle button's digital signal. * * @param loop the event loop instance to attach the event to. - * @return an event instance representing the R1 button's digital signal attached to the given - * loop. + * @return an event instance representing the triangle button's digital signal + * attached to the given loop. */ - @SuppressWarnings("MethodName") - public BooleanEvent R1(EventLoop loop) { - return new BooleanEvent(loop, this::getR1Button); + public BooleanEvent triangle(EventLoop loop) { + return new BooleanEvent(loop, this::getTriangleButton); } /** - * Read the value of the L3 button (pressing the left analog stick) on the controller. + * Read the value of the left trigger 1 button on the controller. * * @return The state of the button. */ - public boolean getL3Button() { - return getRawButton(Button.kL3.value); + public boolean getL1Button() { + return getRawButton(Button.kL1.value); } /** - * Read the value of the R3 button (pressing the right analog stick) on the controller. + * Whether the left trigger 1 button was pressed since the last check. * - * @return The state of the button. + * @return Whether the button was pressed since the last check. */ - public boolean getR3Button() { - return getRawButton(Button.kR3.value); + public boolean getL1ButtonPressed() { + return getRawButtonPressed(Button.kL1.value); } /** - * Whether the L3 (left stick) button was pressed since the last check. + * Whether the left trigger 1 button was released since the last check. * - * @return Whether the button was pressed since the last check. + * @return Whether the button was released since the last check. */ - public boolean getL3ButtonPressed() { - return getRawButtonPressed(Button.kL3.value); + public boolean getL1ButtonReleased() { + return getRawButtonReleased(Button.kL1.value); } /** - * Whether the R3 (right stick) button was pressed since the last check. + * Constructs an event instance around the left trigger 1 button's digital signal. * - * @return Whether the button was pressed since the last check. + * @param loop the event loop instance to attach the event to. + * @return an event instance representing the left trigger 1 button's digital signal + * attached to the given loop. */ - public boolean getR3ButtonPressed() { - return getRawButtonPressed(Button.kR3.value); + public BooleanEvent L1(EventLoop loop) { + return new BooleanEvent(loop, this::getL1Button); } /** - * Whether the L3 (left stick) button was released since the last check. + * Read the value of the right trigger 1 button on the controller. * - * @return Whether the button was released since the last check. + * @return The state of the button. */ - public boolean getL3ButtonReleased() { - return getRawButtonReleased(Button.kL3.value); + public boolean getR1Button() { + return getRawButton(Button.kR1.value); } /** - * Whether the R3 (right stick) button was released since the last check. + * Whether the right trigger 1 button was pressed since the last check. + * + * @return Whether the button was pressed since the last check. + */ + public boolean getR1ButtonPressed() { + return getRawButtonPressed(Button.kR1.value); + } + + /** + * Whether the right trigger 1 button was released since the last check. * * @return Whether the button was released since the last check. */ - public boolean getR3ButtonReleased() { - return getRawButtonReleased(Button.kR3.value); + public boolean getR1ButtonReleased() { + return getRawButtonReleased(Button.kR1.value); } /** - * Constructs an event instance around the L3 button's digital signal. + * Constructs an event instance around the right trigger 1 button's digital signal. * * @param loop the event loop instance to attach the event to. - * @return an event instance representing the L3 button's digital signal attached to the given - * loop. + * @return an event instance representing the right trigger 1 button's digital signal + * attached to the given loop. */ - @SuppressWarnings("MethodName") - public BooleanEvent L3(EventLoop loop) { - return new BooleanEvent(loop, this::getL3Button); + public BooleanEvent R1(EventLoop loop) { + return new BooleanEvent(loop, this::getR1Button); } /** - * Constructs an event instance around the R3 button's digital signal. + * Read the value of the left trigger 2 button on the controller. + * + * @return The state of the button. + */ + public boolean getL2Button() { + return getRawButton(Button.kL2.value); + } + + /** + * Whether the left trigger 2 button was pressed since the last check. + * + * @return Whether the button was pressed since the last check. + */ + public boolean getL2ButtonPressed() { + return getRawButtonPressed(Button.kL2.value); + } + + /** + * Whether the left trigger 2 button was released since the last check. + * + * @return Whether the button was released since the last check. + */ + public boolean getL2ButtonReleased() { + return getRawButtonReleased(Button.kL2.value); + } + + /** + * Constructs an event instance around the left trigger 2 button's digital signal. * * @param loop the event loop instance to attach the event to. - * @return an event instance representing the R3 button's digital signal attached to the given - * loop. + * @return an event instance representing the left trigger 2 button's digital signal + * attached to the given loop. */ - @SuppressWarnings("MethodName") - public BooleanEvent R3(EventLoop loop) { - return new BooleanEvent(loop, this::getR3Button); + public BooleanEvent L2(EventLoop loop) { + return new BooleanEvent(loop, this::getL2Button); } /** - * Read the value of the Square button on the controller. + * Read the value of the right trigger 2 button on the controller. * * @return The state of the button. */ - public boolean getSquareButton() { - return getRawButton(Button.kSquare.value); + public boolean getR2Button() { + return getRawButton(Button.kR2.value); } /** - * Whether the Square button was pressed since the last check. + * Whether the right trigger 2 button was pressed since the last check. * * @return Whether the button was pressed since the last check. */ - public boolean getSquareButtonPressed() { - return getRawButtonPressed(Button.kSquare.value); + public boolean getR2ButtonPressed() { + return getRawButtonPressed(Button.kR2.value); } /** - * Whether the Square button was released since the last check. + * Whether the right trigger 2 button was released since the last check. * * @return Whether the button was released since the last check. */ - public boolean getSquareButtonReleased() { - return getRawButtonReleased(Button.kSquare.value); + public boolean getR2ButtonReleased() { + return getRawButtonReleased(Button.kR2.value); } /** - * Constructs an event instance around the square button's digital signal. + * Constructs an event instance around the right trigger 2 button's digital signal. * * @param loop the event loop instance to attach the event to. - * @return an event instance representing the square button's digital signal attached to the given - * loop. + * @return an event instance representing the right trigger 2 button's digital signal + * attached to the given loop. */ - public BooleanEvent square(EventLoop loop) { - return new BooleanEvent(loop, this::getSquareButton); + public BooleanEvent R2(EventLoop loop) { + return new BooleanEvent(loop, this::getR2Button); } /** - * Read the value of the Cross button on the controller. + * Read the value of the create button on the controller. * * @return The state of the button. */ - public boolean getCrossButton() { - return getRawButton(Button.kCross.value); + public boolean getCreateButton() { + return getRawButton(Button.kCreate.value); } /** - * Whether the Cross button was pressed since the last check. + * Whether the create button was pressed since the last check. * * @return Whether the button was pressed since the last check. */ - public boolean getCrossButtonPressed() { - return getRawButtonPressed(Button.kCross.value); + public boolean getCreateButtonPressed() { + return getRawButtonPressed(Button.kCreate.value); } /** - * Whether the Cross button was released since the last check. + * Whether the create button was released since the last check. * * @return Whether the button was released since the last check. */ - public boolean getCrossButtonReleased() { - return getRawButtonReleased(Button.kCross.value); + public boolean getCreateButtonReleased() { + return getRawButtonReleased(Button.kCreate.value); } /** - * Constructs an event instance around the cross button's digital signal. + * Constructs an event instance around the create button's digital signal. * * @param loop the event loop instance to attach the event to. - * @return an event instance representing the cross button's digital signal attached to the given - * loop. + * @return an event instance representing the create button's digital signal + * attached to the given loop. */ - public BooleanEvent cross(EventLoop loop) { - return new BooleanEvent(loop, this::getCrossButton); + public BooleanEvent create(EventLoop loop) { + return new BooleanEvent(loop, this::getCreateButton); } /** - * Read the value of the Triangle button on the controller. + * Read the value of the options button on the controller. * * @return The state of the button. */ - public boolean getTriangleButton() { - return getRawButton(Button.kTriangle.value); + public boolean getOptionsButton() { + return getRawButton(Button.kOptions.value); } /** - * Whether the Triangle button was pressed since the last check. + * Whether the options button was pressed since the last check. * * @return Whether the button was pressed since the last check. */ - public boolean getTriangleButtonPressed() { - return getRawButtonPressed(Button.kTriangle.value); + public boolean getOptionsButtonPressed() { + return getRawButtonPressed(Button.kOptions.value); } /** - * Whether the Triangle button was released since the last check. + * Whether the options button was released since the last check. * * @return Whether the button was released since the last check. */ - public boolean getTriangleButtonReleased() { - return getRawButtonReleased(Button.kTriangle.value); + public boolean getOptionsButtonReleased() { + return getRawButtonReleased(Button.kOptions.value); } /** - * Constructs an event instance around the triangle button's digital signal. + * Constructs an event instance around the options button's digital signal. * * @param loop the event loop instance to attach the event to. - * @return an event instance representing the triangle button's digital signal attached to the - * given loop. + * @return an event instance representing the options button's digital signal + * attached to the given loop. */ - public BooleanEvent triangle(EventLoop loop) { - return new BooleanEvent(loop, this::getTriangleButton); + public BooleanEvent options(EventLoop loop) { + return new BooleanEvent(loop, this::getOptionsButton); } /** - * Read the value of the Circle button on the controller. + * Read the value of the L3 (left stick) button on the controller. * * @return The state of the button. */ - public boolean getCircleButton() { - return getRawButton(Button.kCircle.value); + public boolean getL3Button() { + return getRawButton(Button.kL3.value); } /** - * Whether the Circle button was pressed since the last check. + * Whether the L3 (left stick) button was pressed since the last check. * * @return Whether the button was pressed since the last check. */ - public boolean getCircleButtonPressed() { - return getRawButtonPressed(Button.kCircle.value); + public boolean getL3ButtonPressed() { + return getRawButtonPressed(Button.kL3.value); } /** - * Whether the Circle button was released since the last check. + * Whether the L3 (left stick) button was released since the last check. * * @return Whether the button was released since the last check. */ - public boolean getCircleButtonReleased() { - return getRawButtonReleased(Button.kCircle.value); + public boolean getL3ButtonReleased() { + return getRawButtonReleased(Button.kL3.value); } /** - * Constructs an event instance around the circle button's digital signal. + * Constructs an event instance around the L3 (left stick) button's digital signal. * * @param loop the event loop instance to attach the event to. - * @return an event instance representing the circle button's digital signal attached to the given - * loop. + * @return an event instance representing the L3 (left stick) button's digital signal + * attached to the given loop. */ - public BooleanEvent circle(EventLoop loop) { - return new BooleanEvent(loop, this::getCircleButton); + public BooleanEvent L3(EventLoop loop) { + return new BooleanEvent(loop, this::getL3Button); } /** - * Read the value of the share button on the controller. + * Read the value of the R3 (right stick) button on the controller. * * @return The state of the button. */ - public boolean getCreateButton() { - return getRawButton(Button.kCreate.value); + public boolean getR3Button() { + return getRawButton(Button.kR3.value); } /** - * Whether the share button was pressed since the last check. + * Whether the R3 (right stick) button was pressed since the last check. * * @return Whether the button was pressed since the last check. */ - public boolean getCreateButtonPressed() { - return getRawButtonPressed(Button.kCreate.value); + public boolean getR3ButtonPressed() { + return getRawButtonPressed(Button.kR3.value); } /** - * Whether the share button was released since the last check. + * Whether the R3 (right stick) button was released since the last check. * * @return Whether the button was released since the last check. */ - public boolean getCreateButtonReleased() { - return getRawButtonReleased(Button.kCreate.value); + public boolean getR3ButtonReleased() { + return getRawButtonReleased(Button.kR3.value); } /** - * Constructs an event instance around the share button's digital signal. + * Constructs an event instance around the R3 (right stick) button's digital signal. * * @param loop the event loop instance to attach the event to. - * @return an event instance representing the share button's digital signal attached to the given - * loop. + * @return an event instance representing the R3 (right stick) button's digital signal + * attached to the given loop. */ - @SuppressWarnings("MethodName") - public BooleanEvent create(EventLoop loop) { - return new BooleanEvent(loop, this::getCreateButton); + public BooleanEvent R3(EventLoop loop) { + return new BooleanEvent(loop, this::getR3Button); } /** - * Read the value of the PS button on the controller. + * Read the value of the PlayStation button on the controller. * * @return The state of the button. */ @@ -616,7 +648,7 @@ public boolean getPSButton() { } /** - * Whether the PS button was pressed since the last check. + * Whether the PlayStation button was pressed since the last check. * * @return Whether the button was pressed since the last check. */ @@ -625,7 +657,7 @@ public boolean getPSButtonPressed() { } /** - * Whether the PS button was released since the last check. + * Whether the PlayStation button was released since the last check. * * @return Whether the button was released since the last check. */ @@ -634,60 +666,61 @@ public boolean getPSButtonReleased() { } /** - * Constructs an event instance around the PS button's digital signal. + * Constructs an event instance around the PlayStation button's digital signal. * * @param loop the event loop instance to attach the event to. - * @return an event instance representing the PS button's digital signal attached to the given - * loop. + * @return an event instance representing the PlayStation button's digital signal + * attached to the given loop. */ - @SuppressWarnings("MethodName") public BooleanEvent PS(EventLoop loop) { return new BooleanEvent(loop, this::getPSButton); } /** - * Read the value of the options button on the controller. + * Read the value of the touchpad button on the controller. * * @return The state of the button. */ - public boolean getOptionsButton() { - return getRawButton(Button.kOptions.value); + public boolean getTouchpadButton() { + return getRawButton(Button.kTouchpad.value); } /** - * Whether the options button was pressed since the last check. + * Whether the touchpad button was pressed since the last check. * * @return Whether the button was pressed since the last check. */ - public boolean getOptionsButtonPressed() { - return getRawButtonPressed(Button.kOptions.value); + public boolean getTouchpadButtonPressed() { + return getRawButtonPressed(Button.kTouchpad.value); } /** - * Whether the options button was released since the last check. + * Whether the touchpad button was released since the last check. * * @return Whether the button was released since the last check. */ - public boolean getOptionsButtonReleased() { - return getRawButtonReleased(Button.kOptions.value); + public boolean getTouchpadButtonReleased() { + return getRawButtonReleased(Button.kTouchpad.value); } /** - * Constructs an event instance around the options button's digital signal. + * Constructs an event instance around the touchpad button's digital signal. * * @param loop the event loop instance to attach the event to. - * @return an event instance representing the options button's digital signal attached to the - * given loop. + * @return an event instance representing the touchpad button's digital signal + * attached to the given loop. */ - public BooleanEvent options(EventLoop loop) { - return new BooleanEvent(loop, this::getOptionsButton); + public BooleanEvent touchpad(EventLoop loop) { + return new BooleanEvent(loop, this::getTouchpadButton); } /** * Read the value of the touchpad on the controller. * * @return The state of the touchpad. + * @deprecated Use {@link getTouchpadButton} instead */ + @Deprecated(since = "2025", forRemoval = true) public boolean getTouchpad() { return getRawButton(Button.kTouchpad.value); } @@ -696,7 +729,9 @@ public boolean getTouchpad() { * Whether the touchpad was pressed since the last check. * * @return Whether the touchpad was pressed since the last check. + * @deprecated Use {@link getTouchpadButtonPressed} instead */ + @Deprecated(since = "2025", forRemoval = true) public boolean getTouchpadPressed() { return getRawButtonPressed(Button.kTouchpad.value); } @@ -705,19 +740,10 @@ public boolean getTouchpadPressed() { * Whether the touchpad was released since the last check. * * @return Whether the touchpad was released since the last check. + * @deprecated Use {@link getTouchpadButtonReleased} instead */ + @Deprecated(since = "2025", forRemoval = true) public boolean getTouchpadReleased() { return getRawButtonReleased(Button.kTouchpad.value); } - - /** - * Constructs an event instance around the touchpad's digital signal. - * - * @param loop the event loop instance to attach the event to. - * @return an event instance representing the touchpad's digital signal attached to the given - * loop. - */ - public BooleanEvent touchpad(EventLoop loop) { - return new BooleanEvent(loop, this::getTouchpad); - } } diff --git a/wpilibj/src/main/java/edu/wpi/first/wpilibj/StadiaController.java b/wpilibj/src/generated/main/java/edu/wpi/first/wpilibj/StadiaController.java similarity index 78% rename from wpilibj/src/main/java/edu/wpi/first/wpilibj/StadiaController.java rename to wpilibj/src/generated/main/java/edu/wpi/first/wpilibj/StadiaController.java index d092d8b9375..916ab3979dc 100644 --- a/wpilibj/src/main/java/edu/wpi/first/wpilibj/StadiaController.java +++ b/wpilibj/src/generated/main/java/edu/wpi/first/wpilibj/StadiaController.java @@ -2,6 +2,8 @@ // Open Source Software; you can modify and/or share it under the terms of // the WPILib BSD license file in the root directory of this project. +// THIS FILE WAS AUTO-GENERATED BY ./wpilibj/generate_hids.py. DO NOT MODIFY + package edu.wpi.first.wpilibj; // import edu.wpi.first.hal.FRCNetComm.tResourceType; @@ -15,6 +17,10 @@ *

This class handles Stadia input that comes from the Driver Station. Each time a value is * requested the most recent value is returned. There is a single class instance for each controller * and the mapping of ports to hardware buttons depends on the code in the Driver Station. + * + *

Only first party controllers from Google are guaranteed to have the correct mapping, and + * only through the official NI DS. Sim is not guaranteed to have the same mapping, as well as any + * 3rd party controllers. */ public class StadiaController extends GenericHID { /** Represents a digital button on a StadiaController. */ @@ -23,9 +29,9 @@ public enum Button { kA(1), /** B button. */ kB(2), - /** X Button. */ + /** X button. */ kX(3), - /** Y Button. */ + /** Y button. */ kY(4), /** Left bumper button. */ kLeftBumper(5), @@ -59,7 +65,7 @@ public enum Button { /** * Get the human-friendly name of the button, matching the relevant methods. This is done by - * stripping the leading `k`, and if not a Bumper button append `Button`. + * stripping the leading `k`, and appending `Button`. * *

Primarily used for automated unit tests. * @@ -67,15 +73,12 @@ public enum Button { */ @Override public String toString() { - var name = this.name().substring(1); // Remove leading `k` - if (name.endsWith("Bumper")) { - return name; - } - return name + "Button"; + // Remove leading `k` + return this.name().substring(1) + "Button"; } } - /** Represents an axis on a StadiaController. */ + /** Represents an axis on an StadiaController. */ public enum Axis { /** Left X axis. */ kLeftX(0), @@ -95,7 +98,7 @@ public enum Axis { /** * Get the human-friendly name of the axis, matching the relevant methods. This is done by - * stripping the leading `k`, and if a trigger axis append `Axis`. + * stripping the leading `k`, and appending `Axis` if the name ends with `Trigger`. * *

Primarily used for automated unit tests. * @@ -114,12 +117,11 @@ public String toString() { /** * Construct an instance of a controller. * - * @param port The port index on the Driver Station that the controller is plugged into. + * @param port The port index on the Driver Station that the controller is plugged into (0-5). */ public StadiaController(final int port) { super(port); - // re-enable when StadiaController is added to Usage Reporting - // HAL.report(tResourceType.kResourceType_Joystick, port + 1); + // HAL.report(tResourceType.kResourceType_StadiaController, port + 1); } /** @@ -159,387 +161,307 @@ public double getRightY() { } /** - * Read the value of the left bumper (LB) button on the controller. - * - * @return The state of the button. - */ - public boolean getLeftBumper() { - return getRawButton(Button.kLeftBumper.value); - } - - /** - * Read the value of the right bumper (RB) button on the controller. + * Read the value of the A button on the controller. * * @return The state of the button. */ - public boolean getRightBumper() { - return getRawButton(Button.kRightBumper.value); - } - - /** - * Whether the left bumper (LB) was pressed since the last check. - * - * @return Whether the button was pressed since the last check. - */ - public boolean getLeftBumperPressed() { - return getRawButtonPressed(Button.kLeftBumper.value); + public boolean getAButton() { + return getRawButton(Button.kA.value); } /** - * Whether the right bumper (RB) was pressed since the last check. + * Whether the A button was pressed since the last check. * * @return Whether the button was pressed since the last check. */ - public boolean getRightBumperPressed() { - return getRawButtonPressed(Button.kRightBumper.value); - } - - /** - * Whether the left bumper (LB) was released since the last check. - * - * @return Whether the button was released since the last check. - */ - public boolean getLeftBumperReleased() { - return getRawButtonReleased(Button.kLeftBumper.value); + public boolean getAButtonPressed() { + return getRawButtonPressed(Button.kA.value); } /** - * Whether the right bumper (RB) was released since the last check. + * Whether the A button was released since the last check. * * @return Whether the button was released since the last check. */ - public boolean getRightBumperReleased() { - return getRawButtonReleased(Button.kRightBumper.value); - } - - /** - * Constructs an event instance around the right bumper's digital signal. - * - * @param loop the event loop instance to attach the event to. - * @return an event instance representing the right bumper's digital signal attached to the given - * loop. - */ - public BooleanEvent leftBumper(EventLoop loop) { - return new BooleanEvent(loop, this::getLeftBumper); + public boolean getAButtonReleased() { + return getRawButtonReleased(Button.kA.value); } /** - * Constructs an event instance around the left bumper's digital signal. + * Constructs an event instance around the A button's digital signal. * * @param loop the event loop instance to attach the event to. - * @return an event instance representing the left bumper's digital signal attached to the given - * loop. + * @return an event instance representing the A button's digital signal + * attached to the given loop. */ - public BooleanEvent rightBumper(EventLoop loop) { - return new BooleanEvent(loop, this::getRightBumper); - } - - /** - * Read the value of the left stick button (LSB) on the controller. - * - * @return The state of the button. - */ - public boolean getLeftStickButton() { - return getRawButton(Button.kLeftStick.value); + public BooleanEvent a(EventLoop loop) { + return new BooleanEvent(loop, this::getAButton); } /** - * Read the value of the right stick button (RSB) on the controller. + * Read the value of the B button on the controller. * * @return The state of the button. */ - public boolean getRightStickButton() { - return getRawButton(Button.kRightStick.value); - } - - /** - * Whether the left stick button (LSB) was pressed since the last check. - * - * @return Whether the button was pressed since the last check. - */ - public boolean getLeftStickButtonPressed() { - return getRawButtonPressed(Button.kLeftStick.value); + public boolean getBButton() { + return getRawButton(Button.kB.value); } /** - * Whether the right stick button (RSB) was pressed since the last check. + * Whether the B button was pressed since the last check. * * @return Whether the button was pressed since the last check. */ - public boolean getRightStickButtonPressed() { - return getRawButtonPressed(Button.kRightStick.value); - } - - /** - * Whether the left stick button (LSB) was released since the last check. - * - * @return Whether the button was released since the last check. - */ - public boolean getLeftStickButtonReleased() { - return getRawButtonReleased(Button.kLeftStick.value); + public boolean getBButtonPressed() { + return getRawButtonPressed(Button.kB.value); } /** - * Whether the right stick (RSB) button was released since the last check. + * Whether the B button was released since the last check. * * @return Whether the button was released since the last check. */ - public boolean getRightStickButtonReleased() { - return getRawButtonReleased(Button.kRightStick.value); - } - - /** - * Constructs an event instance around the left stick button's digital signal. - * - * @param loop the event loop instance to attach the event to. - * @return an event instance representing the left stick button's digital signal attached to the - * given loop. - */ - public BooleanEvent leftStick(EventLoop loop) { - return new BooleanEvent(loop, this::getLeftStickButton); + public boolean getBButtonReleased() { + return getRawButtonReleased(Button.kB.value); } /** - * Constructs an event instance around the right stick button's digital signal. + * Constructs an event instance around the B button's digital signal. * * @param loop the event loop instance to attach the event to. - * @return an event instance representing the right stick button's digital signal attached to the - * given loop. + * @return an event instance representing the B button's digital signal + * attached to the given loop. */ - public BooleanEvent rightStick(EventLoop loop) { - return new BooleanEvent(loop, this::getRightStickButton); + public BooleanEvent b(EventLoop loop) { + return new BooleanEvent(loop, this::getBButton); } /** - * Read the value of the left trigger button (LTB) on the controller. + * Read the value of the X button on the controller. * * @return The state of the button. */ - public boolean getLeftTriggerButton() { - return getRawButton(Button.kLeftTrigger.value); + public boolean getXButton() { + return getRawButton(Button.kX.value); } /** - * Read the value of the right trigger button (RTB) on the controller. + * Whether the X button was pressed since the last check. * - * @return The state of the button. + * @return Whether the button was pressed since the last check. */ - public boolean getRightTriggerButton() { - return getRawButton(Button.kRightTrigger.value); + public boolean getXButtonPressed() { + return getRawButtonPressed(Button.kX.value); } /** - * Whether the left trigger button (LTB) was pressed since the last check. + * Whether the X button was released since the last check. * - * @return Whether the button was pressed since the last check. + * @return Whether the button was released since the last check. */ - public boolean getLeftTriggerButtonPressed() { - return getRawButtonPressed(Button.kLeftTrigger.value); + public boolean getXButtonReleased() { + return getRawButtonReleased(Button.kX.value); } /** - * Whether the right trigger button (RTB) was pressed since the last check. + * Constructs an event instance around the X button's digital signal. * - * @return Whether the button was pressed since the last check. + * @param loop the event loop instance to attach the event to. + * @return an event instance representing the X button's digital signal + * attached to the given loop. */ - public boolean getRightTriggerButtonPressed() { - return getRawButtonPressed(Button.kRightTrigger.value); + public BooleanEvent x(EventLoop loop) { + return new BooleanEvent(loop, this::getXButton); } /** - * Whether the left trigger button (LTB) was released since the last check. + * Read the value of the Y button on the controller. * - * @return Whether the button was released since the last check. + * @return The state of the button. */ - public boolean getLeftTriggerButtonReleased() { - return getRawButtonReleased(Button.kLeftTrigger.value); + public boolean getYButton() { + return getRawButton(Button.kY.value); } /** - * Whether the right trigger (RTB) button was released since the last check. + * Whether the Y button was pressed since the last check. * - * @return Whether the button was released since the last check. + * @return Whether the button was pressed since the last check. */ - public boolean getRightTriggerButtonReleased() { - return getRawButtonReleased(Button.kRightTrigger.value); + public boolean getYButtonPressed() { + return getRawButtonPressed(Button.kY.value); } /** - * Constructs an event instance around the left trigger button's digital signal. + * Whether the Y button was released since the last check. * - * @param loop the event loop instance to attach the event to. - * @return an event instance representing the left trigger button's digital signal attached to the - * given loop. + * @return Whether the button was released since the last check. */ - public BooleanEvent leftTrigger(EventLoop loop) { - return new BooleanEvent(loop, this::getLeftTriggerButton); + public boolean getYButtonReleased() { + return getRawButtonReleased(Button.kY.value); } /** - * Constructs an event instance around the right trigger button's digital signal. + * Constructs an event instance around the Y button's digital signal. * * @param loop the event loop instance to attach the event to. - * @return an event instance representing the right trigger button's digital signal attached to - * the given loop. + * @return an event instance representing the Y button's digital signal + * attached to the given loop. */ - public BooleanEvent rightTrigger(EventLoop loop) { - return new BooleanEvent(loop, this::getRightTriggerButton); + public BooleanEvent y(EventLoop loop) { + return new BooleanEvent(loop, this::getYButton); } /** - * Read the value of the A button on the controller. + * Read the value of the left bumper button on the controller. * * @return The state of the button. */ - public boolean getAButton() { - return getRawButton(Button.kA.value); + public boolean getLeftBumperButton() { + return getRawButton(Button.kLeftBumper.value); } /** - * Whether the A button was pressed since the last check. + * Whether the left bumper button was pressed since the last check. * * @return Whether the button was pressed since the last check. */ - public boolean getAButtonPressed() { - return getRawButtonPressed(Button.kA.value); + public boolean getLeftBumperButtonPressed() { + return getRawButtonPressed(Button.kLeftBumper.value); } /** - * Whether the A button was released since the last check. + * Whether the left bumper button was released since the last check. * * @return Whether the button was released since the last check. */ - public boolean getAButtonReleased() { - return getRawButtonReleased(Button.kA.value); + public boolean getLeftBumperButtonReleased() { + return getRawButtonReleased(Button.kLeftBumper.value); } /** - * Constructs an event instance around the A button's digital signal. + * Constructs an event instance around the left bumper button's digital signal. * * @param loop the event loop instance to attach the event to. - * @return an event instance representing the A button's digital signal attached to the given - * loop. + * @return an event instance representing the left bumper button's digital signal + * attached to the given loop. */ - @SuppressWarnings("MethodName") - public BooleanEvent a(EventLoop loop) { - return new BooleanEvent(loop, this::getAButton); + public BooleanEvent leftBumper(EventLoop loop) { + return new BooleanEvent(loop, this::getLeftBumperButton); } /** - * Read the value of the B button on the controller. + * Read the value of the right bumper button on the controller. * * @return The state of the button. */ - public boolean getBButton() { - return getRawButton(Button.kB.value); + public boolean getRightBumperButton() { + return getRawButton(Button.kRightBumper.value); } /** - * Whether the B button was pressed since the last check. + * Whether the right bumper button was pressed since the last check. * * @return Whether the button was pressed since the last check. */ - public boolean getBButtonPressed() { - return getRawButtonPressed(Button.kB.value); + public boolean getRightBumperButtonPressed() { + return getRawButtonPressed(Button.kRightBumper.value); } /** - * Whether the B button was released since the last check. + * Whether the right bumper button was released since the last check. * * @return Whether the button was released since the last check. */ - public boolean getBButtonReleased() { - return getRawButtonReleased(Button.kB.value); + public boolean getRightBumperButtonReleased() { + return getRawButtonReleased(Button.kRightBumper.value); } /** - * Constructs an event instance around the B button's digital signal. + * Constructs an event instance around the right bumper button's digital signal. * * @param loop the event loop instance to attach the event to. - * @return an event instance representing the B button's digital signal attached to the given - * loop. + * @return an event instance representing the right bumper button's digital signal + * attached to the given loop. */ - @SuppressWarnings("MethodName") - public BooleanEvent b(EventLoop loop) { - return new BooleanEvent(loop, this::getBButton); + public BooleanEvent rightBumper(EventLoop loop) { + return new BooleanEvent(loop, this::getRightBumperButton); } /** - * Read the value of the X button on the controller. + * Read the value of the left stick button on the controller. * * @return The state of the button. */ - public boolean getXButton() { - return getRawButton(Button.kX.value); + public boolean getLeftStickButton() { + return getRawButton(Button.kLeftStick.value); } /** - * Whether the X button was pressed since the last check. + * Whether the left stick button was pressed since the last check. * * @return Whether the button was pressed since the last check. */ - public boolean getXButtonPressed() { - return getRawButtonPressed(Button.kX.value); + public boolean getLeftStickButtonPressed() { + return getRawButtonPressed(Button.kLeftStick.value); } /** - * Whether the X button was released since the last check. + * Whether the left stick button was released since the last check. * * @return Whether the button was released since the last check. */ - public boolean getXButtonReleased() { - return getRawButtonReleased(Button.kX.value); + public boolean getLeftStickButtonReleased() { + return getRawButtonReleased(Button.kLeftStick.value); } /** - * Constructs an event instance around the X button's digital signal. + * Constructs an event instance around the left stick button's digital signal. * * @param loop the event loop instance to attach the event to. - * @return an event instance representing the X button's digital signal attached to the given - * loop. + * @return an event instance representing the left stick button's digital signal + * attached to the given loop. */ - @SuppressWarnings("MethodName") - public BooleanEvent x(EventLoop loop) { - return new BooleanEvent(loop, this::getXButton); + public BooleanEvent leftStick(EventLoop loop) { + return new BooleanEvent(loop, this::getLeftStickButton); } /** - * Read the value of the Y button on the controller. + * Read the value of the right stick button on the controller. * * @return The state of the button. */ - public boolean getYButton() { - return getRawButton(Button.kY.value); + public boolean getRightStickButton() { + return getRawButton(Button.kRightStick.value); } /** - * Whether the Y button was pressed since the last check. + * Whether the right stick button was pressed since the last check. * * @return Whether the button was pressed since the last check. */ - public boolean getYButtonPressed() { - return getRawButtonPressed(Button.kY.value); + public boolean getRightStickButtonPressed() { + return getRawButtonPressed(Button.kRightStick.value); } /** - * Whether the Y button was released since the last check. + * Whether the right stick button was released since the last check. * * @return Whether the button was released since the last check. */ - public boolean getYButtonReleased() { - return getRawButtonReleased(Button.kY.value); + public boolean getRightStickButtonReleased() { + return getRawButtonReleased(Button.kRightStick.value); } /** - * Constructs an event instance around the Y button's digital signal. + * Constructs an event instance around the right stick button's digital signal. * * @param loop the event loop instance to attach the event to. - * @return an event instance representing the Y button's digital signal attached to the given - * loop. + * @return an event instance representing the right stick button's digital signal + * attached to the given loop. */ - @SuppressWarnings("MethodName") - public BooleanEvent y(EventLoop loop) { - return new BooleanEvent(loop, this::getYButton); + public BooleanEvent rightStick(EventLoop loop) { + return new BooleanEvent(loop, this::getRightStickButton); } /** @@ -573,8 +495,8 @@ public boolean getEllipsesButtonReleased() { * Constructs an event instance around the ellipses button's digital signal. * * @param loop the event loop instance to attach the event to. - * @return an event instance representing the ellipses button's digital signal attached to the - * given loop. + * @return an event instance representing the ellipses button's digital signal + * attached to the given loop. */ public BooleanEvent ellipses(EventLoop loop) { return new BooleanEvent(loop, this::getEllipsesButton); @@ -611,8 +533,8 @@ public boolean getHamburgerButtonReleased() { * Constructs an event instance around the hamburger button's digital signal. * * @param loop the event loop instance to attach the event to. - * @return an event instance representing the hamburger button's digital signal attached to the - * given loop. + * @return an event instance representing the hamburger button's digital signal + * attached to the given loop. */ public BooleanEvent hamburger(EventLoop loop) { return new BooleanEvent(loop, this::getHamburgerButton); @@ -649,14 +571,89 @@ public boolean getStadiaButtonReleased() { * Constructs an event instance around the stadia button's digital signal. * * @param loop the event loop instance to attach the event to. - * @return an event instance representing the stadia button's digital signal attached to the given - * loop. + * @return an event instance representing the stadia button's digital signal + * attached to the given loop. */ - @SuppressWarnings("MethodName") public BooleanEvent stadia(EventLoop loop) { return new BooleanEvent(loop, this::getStadiaButton); } + /** + * Read the value of the right trigger button on the controller. + * + * @return The state of the button. + */ + public boolean getRightTriggerButton() { + return getRawButton(Button.kRightTrigger.value); + } + + /** + * Whether the right trigger button was pressed since the last check. + * + * @return Whether the button was pressed since the last check. + */ + public boolean getRightTriggerButtonPressed() { + return getRawButtonPressed(Button.kRightTrigger.value); + } + + /** + * Whether the right trigger button was released since the last check. + * + * @return Whether the button was released since the last check. + */ + public boolean getRightTriggerButtonReleased() { + return getRawButtonReleased(Button.kRightTrigger.value); + } + + /** + * Constructs an event instance around the right trigger button's digital signal. + * + * @param loop the event loop instance to attach the event to. + * @return an event instance representing the right trigger button's digital signal + * attached to the given loop. + */ + public BooleanEvent rightTrigger(EventLoop loop) { + return new BooleanEvent(loop, this::getRightTriggerButton); + } + + /** + * Read the value of the left trigger button on the controller. + * + * @return The state of the button. + */ + public boolean getLeftTriggerButton() { + return getRawButton(Button.kLeftTrigger.value); + } + + /** + * Whether the left trigger button was pressed since the last check. + * + * @return Whether the button was pressed since the last check. + */ + public boolean getLeftTriggerButtonPressed() { + return getRawButtonPressed(Button.kLeftTrigger.value); + } + + /** + * Whether the left trigger button was released since the last check. + * + * @return Whether the button was released since the last check. + */ + public boolean getLeftTriggerButtonReleased() { + return getRawButtonReleased(Button.kLeftTrigger.value); + } + + /** + * Constructs an event instance around the left trigger button's digital signal. + * + * @param loop the event loop instance to attach the event to. + * @return an event instance representing the left trigger button's digital signal + * attached to the given loop. + */ + public BooleanEvent leftTrigger(EventLoop loop) { + return new BooleanEvent(loop, this::getLeftTriggerButton); + } + /** * Read the value of the google button on the controller. * @@ -688,10 +685,9 @@ public boolean getGoogleButtonReleased() { * Constructs an event instance around the google button's digital signal. * * @param loop the event loop instance to attach the event to. - * @return an event instance representing the google button's digital signal attached to the given - * loop. + * @return an event instance representing the google button's digital signal + * attached to the given loop. */ - @SuppressWarnings("MethodName") public BooleanEvent google(EventLoop loop) { return new BooleanEvent(loop, this::getGoogleButton); } @@ -727,11 +723,76 @@ public boolean getFrameButtonReleased() { * Constructs an event instance around the frame button's digital signal. * * @param loop the event loop instance to attach the event to. - * @return an event instance representing the frame button's digital signal attached to the given - * loop. + * @return an event instance representing the frame button's digital signal + * attached to the given loop. */ - @SuppressWarnings("MethodName") public BooleanEvent frame(EventLoop loop) { return new BooleanEvent(loop, this::getFrameButton); } + + /** + * Read the value of the left bumper (LB) button on the controller. + * + * @return The state of the button. + * @deprecated Use {@link getLeftBumperButton} instead + */ + @Deprecated(since = "2025", forRemoval = true) + public boolean getLeftBumper() { + return getRawButton(Button.kLeftBumper.value); + } + + /** + * Read the value of the right bumper (RB) button on the controller. + * + * @return The state of the button. + * @deprecated Use {@link getRightBumperButton} instead + */ + @Deprecated(since = "2025", forRemoval = true) + public boolean getRightBumper() { + return getRawButton(Button.kRightBumper.value); + } + + /** + * Whether the left bumper (LB) was pressed since the last check. + * + * @return Whether the button was pressed since the last check. + * @deprecated Use {@link getLeftBumperButtonPressed} instead + */ + @Deprecated(since = "2025", forRemoval = true) + public boolean getLeftBumperPressed() { + return getRawButtonPressed(Button.kLeftBumper.value); + } + + /** + * Whether the right bumper (RB) was pressed since the last check. + * + * @return Whether the button was pressed since the last check. + * @deprecated Use {@link getRightBumperButtonPressed} instead + */ + @Deprecated(since = "2025", forRemoval = true) + public boolean getRightBumperPressed() { + return getRawButtonPressed(Button.kRightBumper.value); + } + + /** + * Whether the left bumper (LB) was released since the last check. + * + * @return Whether the button was released since the last check. + * @deprecated Use {@link getLeftBumperButtonReleased} instead + */ + @Deprecated(since = "2025", forRemoval = true) + public boolean getLeftBumperReleased() { + return getRawButtonReleased(Button.kLeftBumper.value); + } + + /** + * Whether the right bumper (RB) was released since the last check. + * + * @return Whether the button was released since the last check. + * @deprecated Use {@link getRightBumperButtonReleased} instead + */ + @Deprecated(since = "2025", forRemoval = true) + public boolean getRightBumperReleased() { + return getRawButtonReleased(Button.kRightBumper.value); + } } diff --git a/wpilibj/src/main/java/edu/wpi/first/wpilibj/XboxController.java b/wpilibj/src/generated/main/java/edu/wpi/first/wpilibj/XboxController.java similarity index 77% rename from wpilibj/src/main/java/edu/wpi/first/wpilibj/XboxController.java rename to wpilibj/src/generated/main/java/edu/wpi/first/wpilibj/XboxController.java index 5bd7a019274..3bf77e11f61 100644 --- a/wpilibj/src/main/java/edu/wpi/first/wpilibj/XboxController.java +++ b/wpilibj/src/generated/main/java/edu/wpi/first/wpilibj/XboxController.java @@ -2,6 +2,8 @@ // Open Source Software; you can modify and/or share it under the terms of // the WPILib BSD license file in the root directory of this project. +// THIS FILE WAS AUTO-GENERATED BY ./wpilibj/generate_hids.py. DO NOT MODIFY + package edu.wpi.first.wpilibj; import edu.wpi.first.hal.FRCNetComm.tResourceType; @@ -10,7 +12,7 @@ import edu.wpi.first.wpilibj.event.EventLoop; /** - * Handle input from Xbox 360 or Xbox One controllers connected to the Driver Station. + * Handle input from Xbox controllers connected to the Driver Station. * *

This class handles Xbox input that comes from the Driver Station. Each time a value is * requested the most recent value is returned. There is a single class instance for each controller @@ -21,28 +23,28 @@ * 3rd party controllers. */ public class XboxController extends GenericHID { - /** Represents a digital button on an XboxController. */ + /** Represents a digital button on a XboxController. */ public enum Button { - /** Left bumper. */ - kLeftBumper(5), - /** Right bumper. */ - kRightBumper(6), - /** Left stick. */ - kLeftStick(9), - /** Right stick. */ - kRightStick(10), - /** A. */ + /** A button. */ kA(1), - /** B. */ + /** B button. */ kB(2), - /** X. */ + /** X button. */ kX(3), - /** Y. */ + /** Y button. */ kY(4), - /** Back. */ + /** Left bumper button. */ + kLeftBumper(5), + /** Right bumper button. */ + kRightBumper(6), + /** Back button. */ kBack(7), - /** Start. */ - kStart(8); + /** Start button. */ + kStart(8), + /** Left stick button. */ + kLeftStick(9), + /** Right stick button. */ + kRightStick(10); /** Button value. */ public final int value; @@ -53,7 +55,7 @@ public enum Button { /** * Get the human-friendly name of the button, matching the relevant methods. This is done by - * stripping the leading `k`, and if not a Bumper button append `Button`. + * stripping the leading `k`, and appending `Button`. * *

Primarily used for automated unit tests. * @@ -61,23 +63,20 @@ public enum Button { */ @Override public String toString() { - var name = this.name().substring(1); // Remove leading `k` - if (name.endsWith("Bumper")) { - return name; - } - return name + "Button"; + // Remove leading `k` + return this.name().substring(1) + "Button"; } } /** Represents an axis on an XboxController. */ public enum Axis { - /** Left X. */ + /** Left X axis. */ kLeftX(0), - /** Right X. */ + /** Right X axis. */ kRightX(4), - /** Left Y. */ + /** Left Y axis. */ kLeftY(1), - /** Right Y. */ + /** Right Y axis. */ kRightY(5), /** Left trigger. */ kLeftTrigger(2), @@ -93,7 +92,7 @@ public enum Axis { /** * Get the human-friendly name of the axis, matching the relevant methods. This is done by - * stripping the leading `k`, and if a trigger axis append `Axis`. + * stripping the leading `k`, and appending `Axis` if the name ends with `Trigger`. * *

Primarily used for automated unit tests. * @@ -112,11 +111,10 @@ public String toString() { /** * Construct an instance of a controller. * - * @param port The port index on the Driver Station that the controller is plugged into. + * @param port The port index on the Driver Station that the controller is plugged into (0-5). */ public XboxController(final int port) { super(port); - HAL.report(tResourceType.kResourceType_XboxController, port + 1); } @@ -157,7 +155,7 @@ public double getRightY() { } /** - * Get the left trigger (LT) axis value of the controller. Note that this axis is bound to the + * Get the left trigger axis value of the controller. Note that this axis is bound to the * range of [0, 1] as opposed to the usual [-1, 1]. * * @return The axis value. @@ -167,165 +165,65 @@ public double getLeftTriggerAxis() { } /** - * Get the right trigger (RT) axis value of the controller. Note that this axis is bound to the - * range of [0, 1] as opposed to the usual [-1, 1]. - * - * @return The axis value. - */ - public double getRightTriggerAxis() { - return getRawAxis(Axis.kRightTrigger.value); - } - - /** - * Read the value of the left bumper (LB) button on the controller. - * - * @return The state of the button. - */ - public boolean getLeftBumper() { - return getRawButton(Button.kLeftBumper.value); - } - - /** - * Read the value of the right bumper (RB) button on the controller. - * - * @return The state of the button. - */ - public boolean getRightBumper() { - return getRawButton(Button.kRightBumper.value); - } - - /** - * Whether the left bumper (LB) was pressed since the last check. - * - * @return Whether the button was pressed since the last check. - */ - public boolean getLeftBumperPressed() { - return getRawButtonPressed(Button.kLeftBumper.value); - } - - /** - * Whether the right bumper (RB) was pressed since the last check. - * - * @return Whether the button was pressed since the last check. - */ - public boolean getRightBumperPressed() { - return getRawButtonPressed(Button.kRightBumper.value); - } - - /** - * Whether the left bumper (LB) was released since the last check. - * - * @return Whether the button was released since the last check. - */ - public boolean getLeftBumperReleased() { - return getRawButtonReleased(Button.kLeftBumper.value); - } - - /** - * Whether the right bumper (RB) was released since the last check. - * - * @return Whether the button was released since the last check. - */ - public boolean getRightBumperReleased() { - return getRawButtonReleased(Button.kRightBumper.value); - } - - /** - * Constructs an event instance around the right bumper's digital signal. + * Constructs an event instance around the axis value of the left trigger. The returned trigger + * will be true when the axis value is greater than {@code threshold}. * + * @param threshold the minimum axis value for the returned {@link BooleanEvent} to be true. This + * value should be in the range [0, 1] where 0 is the unpressed state of the axis. * @param loop the event loop instance to attach the event to. - * @return an event instance representing the right bumper's digital signal attached to the given - * loop. + * @return an event instance that is true when the left trigger's axis exceeds the provided + * threshold, attached to the given event loop */ - public BooleanEvent leftBumper(EventLoop loop) { - return new BooleanEvent(loop, this::getLeftBumper); + public BooleanEvent leftTrigger(double threshold, EventLoop loop) { + return new BooleanEvent(loop, () -> getLeftTriggerAxis() > threshold); } /** - * Constructs an event instance around the left bumper's digital signal. + * Constructs an event instance around the axis value of the left trigger. The returned trigger + * will be true when the axis value is greater than 0.5. * * @param loop the event loop instance to attach the event to. - * @return an event instance representing the left bumper's digital signal attached to the given - * loop. - */ - public BooleanEvent rightBumper(EventLoop loop) { - return new BooleanEvent(loop, this::getRightBumper); - } - - /** - * Read the value of the left stick button (LSB) on the controller. - * - * @return The state of the button. - */ - public boolean getLeftStickButton() { - return getRawButton(Button.kLeftStick.value); - } - - /** - * Read the value of the right stick button (RSB) on the controller. - * - * @return The state of the button. - */ - public boolean getRightStickButton() { - return getRawButton(Button.kRightStick.value); - } - - /** - * Whether the left stick button (LSB) was pressed since the last check. - * - * @return Whether the button was pressed since the last check. - */ - public boolean getLeftStickButtonPressed() { - return getRawButtonPressed(Button.kLeftStick.value); - } - - /** - * Whether the right stick button (RSB) was pressed since the last check. - * - * @return Whether the button was pressed since the last check. - */ - public boolean getRightStickButtonPressed() { - return getRawButtonPressed(Button.kRightStick.value); - } - - /** - * Whether the left stick button (LSB) was released since the last check. - * - * @return Whether the button was released since the last check. + * @return an event instance that is true when the left trigger's axis exceeds the provided + * threshold, attached to the given event loop */ - public boolean getLeftStickButtonReleased() { - return getRawButtonReleased(Button.kLeftStick.value); + public BooleanEvent leftTrigger(EventLoop loop) { + return leftTrigger(0.5, loop); } /** - * Whether the right stick (RSB) button was released since the last check. + * Get the right trigger axis value of the controller. Note that this axis is bound to the + * range of [0, 1] as opposed to the usual [-1, 1]. * - * @return Whether the button was released since the last check. + * @return The axis value. */ - public boolean getRightStickButtonReleased() { - return getRawButtonReleased(Button.kRightStick.value); + public double getRightTriggerAxis() { + return getRawAxis(Axis.kRightTrigger.value); } /** - * Constructs an event instance around the left stick button's digital signal. + * Constructs an event instance around the axis value of the right trigger. The returned trigger + * will be true when the axis value is greater than {@code threshold}. * + * @param threshold the minimum axis value for the returned {@link BooleanEvent} to be true. This + * value should be in the range [0, 1] where 0 is the unpressed state of the axis. * @param loop the event loop instance to attach the event to. - * @return an event instance representing the left stick button's digital signal attached to the - * given loop. + * @return an event instance that is true when the right trigger's axis exceeds the provided + * threshold, attached to the given event loop */ - public BooleanEvent leftStick(EventLoop loop) { - return new BooleanEvent(loop, this::getLeftStickButton); + public BooleanEvent rightTrigger(double threshold, EventLoop loop) { + return new BooleanEvent(loop, () -> getRightTriggerAxis() > threshold); } /** - * Constructs an event instance around the right stick button's digital signal. + * Constructs an event instance around the axis value of the right trigger. The returned trigger + * will be true when the axis value is greater than 0.5. * * @param loop the event loop instance to attach the event to. - * @return an event instance representing the right stick button's digital signal attached to the - * given loop. + * @return an event instance that is true when the right trigger's axis exceeds the provided + * threshold, attached to the given event loop */ - public BooleanEvent rightStick(EventLoop loop) { - return new BooleanEvent(loop, this::getRightStickButton); + public BooleanEvent rightTrigger(EventLoop loop) { + return rightTrigger(0.5, loop); } /** @@ -359,10 +257,9 @@ public boolean getAButtonReleased() { * Constructs an event instance around the A button's digital signal. * * @param loop the event loop instance to attach the event to. - * @return an event instance representing the A button's digital signal attached to the given - * loop. + * @return an event instance representing the A button's digital signal + * attached to the given loop. */ - @SuppressWarnings("MethodName") public BooleanEvent a(EventLoop loop) { return new BooleanEvent(loop, this::getAButton); } @@ -398,10 +295,9 @@ public boolean getBButtonReleased() { * Constructs an event instance around the B button's digital signal. * * @param loop the event loop instance to attach the event to. - * @return an event instance representing the B button's digital signal attached to the given - * loop. + * @return an event instance representing the B button's digital signal + * attached to the given loop. */ - @SuppressWarnings("MethodName") public BooleanEvent b(EventLoop loop) { return new BooleanEvent(loop, this::getBButton); } @@ -437,10 +333,9 @@ public boolean getXButtonReleased() { * Constructs an event instance around the X button's digital signal. * * @param loop the event loop instance to attach the event to. - * @return an event instance representing the X button's digital signal attached to the given - * loop. + * @return an event instance representing the X button's digital signal + * attached to the given loop. */ - @SuppressWarnings("MethodName") public BooleanEvent x(EventLoop loop) { return new BooleanEvent(loop, this::getXButton); } @@ -476,14 +371,89 @@ public boolean getYButtonReleased() { * Constructs an event instance around the Y button's digital signal. * * @param loop the event loop instance to attach the event to. - * @return an event instance representing the Y button's digital signal attached to the given - * loop. + * @return an event instance representing the Y button's digital signal + * attached to the given loop. */ - @SuppressWarnings("MethodName") public BooleanEvent y(EventLoop loop) { return new BooleanEvent(loop, this::getYButton); } + /** + * Read the value of the left bumper button on the controller. + * + * @return The state of the button. + */ + public boolean getLeftBumperButton() { + return getRawButton(Button.kLeftBumper.value); + } + + /** + * Whether the left bumper button was pressed since the last check. + * + * @return Whether the button was pressed since the last check. + */ + public boolean getLeftBumperButtonPressed() { + return getRawButtonPressed(Button.kLeftBumper.value); + } + + /** + * Whether the left bumper button was released since the last check. + * + * @return Whether the button was released since the last check. + */ + public boolean getLeftBumperButtonReleased() { + return getRawButtonReleased(Button.kLeftBumper.value); + } + + /** + * Constructs an event instance around the left bumper button's digital signal. + * + * @param loop the event loop instance to attach the event to. + * @return an event instance representing the left bumper button's digital signal + * attached to the given loop. + */ + public BooleanEvent leftBumper(EventLoop loop) { + return new BooleanEvent(loop, this::getLeftBumperButton); + } + + /** + * Read the value of the right bumper button on the controller. + * + * @return The state of the button. + */ + public boolean getRightBumperButton() { + return getRawButton(Button.kRightBumper.value); + } + + /** + * Whether the right bumper button was pressed since the last check. + * + * @return Whether the button was pressed since the last check. + */ + public boolean getRightBumperButtonPressed() { + return getRawButtonPressed(Button.kRightBumper.value); + } + + /** + * Whether the right bumper button was released since the last check. + * + * @return Whether the button was released since the last check. + */ + public boolean getRightBumperButtonReleased() { + return getRawButtonReleased(Button.kRightBumper.value); + } + + /** + * Constructs an event instance around the right bumper button's digital signal. + * + * @param loop the event loop instance to attach the event to. + * @return an event instance representing the right bumper button's digital signal + * attached to the given loop. + */ + public BooleanEvent rightBumper(EventLoop loop) { + return new BooleanEvent(loop, this::getRightBumperButton); + } + /** * Read the value of the back button on the controller. * @@ -515,8 +485,8 @@ public boolean getBackButtonReleased() { * Constructs an event instance around the back button's digital signal. * * @param loop the event loop instance to attach the event to. - * @return an event instance representing the back button's digital signal attached to the given - * loop. + * @return an event instance representing the back button's digital signal + * attached to the given loop. */ public BooleanEvent back(EventLoop loop) { return new BooleanEvent(loop, this::getBackButton); @@ -553,62 +523,152 @@ public boolean getStartButtonReleased() { * Constructs an event instance around the start button's digital signal. * * @param loop the event loop instance to attach the event to. - * @return an event instance representing the start button's digital signal attached to the given - * loop. + * @return an event instance representing the start button's digital signal + * attached to the given loop. */ public BooleanEvent start(EventLoop loop) { return new BooleanEvent(loop, this::getStartButton); } /** - * Constructs an event instance around the axis value of the left trigger. The returned trigger - * will be true when the axis value is greater than {@code threshold}. + * Read the value of the left stick button on the controller. * - * @param threshold the minimum axis value for the returned {@link BooleanEvent} to be true. This - * value should be in the range [0, 1] where 0 is the unpressed state of the axis. - * @param loop the event loop instance to attach the event to. - * @return an event instance that is true when the left trigger's axis exceeds the provided - * threshold, attached to the given event loop + * @return The state of the button. */ - public BooleanEvent leftTrigger(double threshold, EventLoop loop) { - return new BooleanEvent(loop, () -> getLeftTriggerAxis() > threshold); + public boolean getLeftStickButton() { + return getRawButton(Button.kLeftStick.value); } /** - * Constructs an event instance around the axis value of the left trigger. The returned trigger - * will be true when the axis value is greater than 0.5. + * Whether the left stick button was pressed since the last check. * - * @param loop the event loop instance to attach the event to. - * @return an event instance that is true when the left trigger's axis exceeds the provided - * threshold, attached to the given event loop + * @return Whether the button was pressed since the last check. */ - public BooleanEvent leftTrigger(EventLoop loop) { - return leftTrigger(0.5, loop); + public boolean getLeftStickButtonPressed() { + return getRawButtonPressed(Button.kLeftStick.value); } /** - * Constructs an event instance around the axis value of the right trigger. The returned trigger - * will be true when the axis value is greater than {@code threshold}. + * Whether the left stick button was released since the last check. + * + * @return Whether the button was released since the last check. + */ + public boolean getLeftStickButtonReleased() { + return getRawButtonReleased(Button.kLeftStick.value); + } + + /** + * Constructs an event instance around the left stick button's digital signal. * - * @param threshold the minimum axis value for the returned {@link BooleanEvent} to be true. This - * value should be in the range [0, 1] where 0 is the unpressed state of the axis. * @param loop the event loop instance to attach the event to. - * @return an event instance that is true when the right trigger's axis exceeds the provided - * threshold, attached to the given event loop + * @return an event instance representing the left stick button's digital signal + * attached to the given loop. */ - public BooleanEvent rightTrigger(double threshold, EventLoop loop) { - return new BooleanEvent(loop, () -> getRightTriggerAxis() > threshold); + public BooleanEvent leftStick(EventLoop loop) { + return new BooleanEvent(loop, this::getLeftStickButton); } /** - * Constructs an event instance around the axis value of the right trigger. The returned trigger - * will be true when the axis value is greater than 0.5. + * Read the value of the right stick button on the controller. + * + * @return The state of the button. + */ + public boolean getRightStickButton() { + return getRawButton(Button.kRightStick.value); + } + + /** + * Whether the right stick button was pressed since the last check. + * + * @return Whether the button was pressed since the last check. + */ + public boolean getRightStickButtonPressed() { + return getRawButtonPressed(Button.kRightStick.value); + } + + /** + * Whether the right stick button was released since the last check. + * + * @return Whether the button was released since the last check. + */ + public boolean getRightStickButtonReleased() { + return getRawButtonReleased(Button.kRightStick.value); + } + + /** + * Constructs an event instance around the right stick button's digital signal. * * @param loop the event loop instance to attach the event to. - * @return an event instance that is true when the right trigger's axis exceeds the provided - * threshold, attached to the given event loop + * @return an event instance representing the right stick button's digital signal + * attached to the given loop. */ - public BooleanEvent rightTrigger(EventLoop loop) { - return rightTrigger(0.5, loop); + public BooleanEvent rightStick(EventLoop loop) { + return new BooleanEvent(loop, this::getRightStickButton); + } + + /** + * Read the value of the left bumper (LB) button on the controller. + * + * @return The state of the button. + * @deprecated Use {@link getLeftBumperButton} instead + */ + @Deprecated(since = "2025", forRemoval = true) + public boolean getLeftBumper() { + return getRawButton(Button.kLeftBumper.value); + } + + /** + * Read the value of the right bumper (RB) button on the controller. + * + * @return The state of the button. + * @deprecated Use {@link getRightBumperButton} instead + */ + @Deprecated(since = "2025", forRemoval = true) + public boolean getRightBumper() { + return getRawButton(Button.kRightBumper.value); + } + + /** + * Whether the left bumper (LB) was pressed since the last check. + * + * @return Whether the button was pressed since the last check. + * @deprecated Use {@link getLeftBumperButtonPressed} instead + */ + @Deprecated(since = "2025", forRemoval = true) + public boolean getLeftBumperPressed() { + return getRawButtonPressed(Button.kLeftBumper.value); + } + + /** + * Whether the right bumper (RB) was pressed since the last check. + * + * @return Whether the button was pressed since the last check. + * @deprecated Use {@link getRightBumperButtonPressed} instead + */ + @Deprecated(since = "2025", forRemoval = true) + public boolean getRightBumperPressed() { + return getRawButtonPressed(Button.kRightBumper.value); + } + + /** + * Whether the left bumper (LB) was released since the last check. + * + * @return Whether the button was released since the last check. + * @deprecated Use {@link getLeftBumperButtonReleased} instead + */ + @Deprecated(since = "2025", forRemoval = true) + public boolean getLeftBumperReleased() { + return getRawButtonReleased(Button.kLeftBumper.value); + } + + /** + * Whether the right bumper (RB) was released since the last check. + * + * @return Whether the button was released since the last check. + * @deprecated Use {@link getRightBumperButtonReleased} instead + */ + @Deprecated(since = "2025", forRemoval = true) + public boolean getRightBumperReleased() { + return getRawButtonReleased(Button.kRightBumper.value); } } diff --git a/wpilibj/src/main/java/edu/wpi/first/wpilibj/simulation/PS4ControllerSim.java b/wpilibj/src/generated/main/java/edu/wpi/first/wpilibj/simulation/PS4ControllerSim.java similarity index 73% rename from wpilibj/src/main/java/edu/wpi/first/wpilibj/simulation/PS4ControllerSim.java rename to wpilibj/src/generated/main/java/edu/wpi/first/wpilibj/simulation/PS4ControllerSim.java index 822b1db58f1..a2f1141abc8 100644 --- a/wpilibj/src/main/java/edu/wpi/first/wpilibj/simulation/PS4ControllerSim.java +++ b/wpilibj/src/generated/main/java/edu/wpi/first/wpilibj/simulation/PS4ControllerSim.java @@ -2,6 +2,8 @@ // Open Source Software; you can modify and/or share it under the terms of // the WPILib BSD license file in the root directory of this project. +// THIS FILE WAS AUTO-GENERATED BY ./wpilibj/generate_hids.py. DO NOT MODIFY + package edu.wpi.first.wpilibj.simulation; import edu.wpi.first.wpilibj.PS4Controller; @@ -35,7 +37,7 @@ public PS4ControllerSim(int port) { } /** - * Change the X axis value of the controller's left stick. + * Change the left X value of the controller's joystick. * * @param value the new value */ @@ -44,25 +46,25 @@ public void setLeftX(double value) { } /** - * Change the X axis value of the controller's right stick. + * Change the left Y value of the controller's joystick. * * @param value the new value */ - public void setRightX(double value) { - setRawAxis(PS4Controller.Axis.kRightX.value, value); + public void setLeftY(double value) { + setRawAxis(PS4Controller.Axis.kLeftY.value, value); } /** - * Change the Y axis value of the controller's left stick. + * Change the right X value of the controller's joystick. * * @param value the new value */ - public void setLeftY(double value) { - setRawAxis(PS4Controller.Axis.kLeftY.value, value); + public void setRightX(double value) { + setRawAxis(PS4Controller.Axis.kRightX.value, value); } /** - * Change the Y axis value of the controller's right stick. + * Change the right Y value of the controller's joystick. * * @param value the new value */ @@ -71,7 +73,7 @@ public void setRightY(double value) { } /** - * Change the L2 axis value of the controller. + * Change the value of the left trigger 2 axis on the controller. * * @param value the new value */ @@ -80,7 +82,7 @@ public void setL2Axis(double value) { } /** - * Change the R2 axis value of the controller. + * Change the value of the right trigger 2 axis on the controller. * * @param value the new value */ @@ -89,7 +91,7 @@ public void setR2Axis(double value) { } /** - * Change the value of the Square button on the controller. + * Change the value of the square button on the controller. * * @param value the new value */ @@ -98,7 +100,7 @@ public void setSquareButton(boolean value) { } /** - * Change the value of the Cross button on the controller. + * Change the value of the cross button on the controller. * * @param value the new value */ @@ -107,7 +109,7 @@ public void setCrossButton(boolean value) { } /** - * Change the value of the Circle button on the controller. + * Change the value of the circle button on the controller. * * @param value the new value */ @@ -116,7 +118,7 @@ public void setCircleButton(boolean value) { } /** - * Change the value of the Triangle button on the controller. + * Change the value of the triangle button on the controller. * * @param value the new value */ @@ -125,7 +127,7 @@ public void setTriangleButton(boolean value) { } /** - * Change the value of the L1 button on the controller. + * Change the value of the left trigger 1 button on the controller. * * @param value the new value */ @@ -134,7 +136,7 @@ public void setL1Button(boolean value) { } /** - * Change the value of the R1 button on the controller. + * Change the value of the right trigger 1 button on the controller. * * @param value the new value */ @@ -143,7 +145,7 @@ public void setR1Button(boolean value) { } /** - * Change the value of the L2 button on the controller. + * Change the value of the left trigger 2 button on the controller. * * @param value the new value */ @@ -152,7 +154,7 @@ public void setL2Button(boolean value) { } /** - * Change the value of the R2 button on the controller. + * Change the value of the right trigger 2 button on the controller. * * @param value the new value */ @@ -161,7 +163,7 @@ public void setR2Button(boolean value) { } /** - * Change the value of the Share button on the controller. + * Change the value of the share button on the controller. * * @param value the new value */ @@ -170,7 +172,7 @@ public void setShareButton(boolean value) { } /** - * Change the value of the Options button on the controller. + * Change the value of the options button on the controller. * * @param value the new value */ @@ -197,7 +199,7 @@ public void setR3Button(boolean value) { } /** - * Change the value of the PS button on the controller. + * Change the value of the PlayStation button on the controller. * * @param value the new value */ @@ -210,6 +212,17 @@ public void setPSButton(boolean value) { * * @param value the new value */ + public void setTouchpadButton(boolean value) { + setRawButton(PS4Controller.Button.kTouchpad.value, value); + } + + /** + * Change the value of the touchpad button on the controller. + * + * @param value the new value + * @deprecated Use {@link setTouchpadButton} instead + */ + @Deprecated(since = "2025", forRemoval = true) public void setTouchpad(boolean value) { setRawButton(PS4Controller.Button.kTouchpad.value, value); } diff --git a/wpilibj/src/main/java/edu/wpi/first/wpilibj/simulation/PS5ControllerSim.java b/wpilibj/src/generated/main/java/edu/wpi/first/wpilibj/simulation/PS5ControllerSim.java similarity index 73% rename from wpilibj/src/main/java/edu/wpi/first/wpilibj/simulation/PS5ControllerSim.java rename to wpilibj/src/generated/main/java/edu/wpi/first/wpilibj/simulation/PS5ControllerSim.java index e11cdd084ce..090e74435ea 100644 --- a/wpilibj/src/main/java/edu/wpi/first/wpilibj/simulation/PS5ControllerSim.java +++ b/wpilibj/src/generated/main/java/edu/wpi/first/wpilibj/simulation/PS5ControllerSim.java @@ -2,6 +2,8 @@ // Open Source Software; you can modify and/or share it under the terms of // the WPILib BSD license file in the root directory of this project. +// THIS FILE WAS AUTO-GENERATED BY ./wpilibj/generate_hids.py. DO NOT MODIFY + package edu.wpi.first.wpilibj.simulation; import edu.wpi.first.wpilibj.PS5Controller; @@ -35,7 +37,7 @@ public PS5ControllerSim(int port) { } /** - * Change the X axis value of the controller's left stick. + * Change the left X value of the controller's joystick. * * @param value the new value */ @@ -44,25 +46,25 @@ public void setLeftX(double value) { } /** - * Change the X axis value of the controller's right stick. + * Change the left Y value of the controller's joystick. * * @param value the new value */ - public void setRightX(double value) { - setRawAxis(PS5Controller.Axis.kRightX.value, value); + public void setLeftY(double value) { + setRawAxis(PS5Controller.Axis.kLeftY.value, value); } /** - * Change the Y axis value of the controller's left stick. + * Change the right X value of the controller's joystick. * * @param value the new value */ - public void setLeftY(double value) { - setRawAxis(PS5Controller.Axis.kLeftY.value, value); + public void setRightX(double value) { + setRawAxis(PS5Controller.Axis.kRightX.value, value); } /** - * Change the Y axis value of the controller's right stick. + * Change the right Y value of the controller's joystick. * * @param value the new value */ @@ -71,7 +73,7 @@ public void setRightY(double value) { } /** - * Change the L2 axis value of the controller. + * Change the value of the left trigger 2 axis on the controller. * * @param value the new value */ @@ -80,7 +82,7 @@ public void setL2Axis(double value) { } /** - * Change the R2 axis value of the controller. + * Change the value of the right trigger 2 axis on the controller. * * @param value the new value */ @@ -89,7 +91,7 @@ public void setR2Axis(double value) { } /** - * Change the value of the Square button on the controller. + * Change the value of the square button on the controller. * * @param value the new value */ @@ -98,7 +100,7 @@ public void setSquareButton(boolean value) { } /** - * Change the value of the Cross button on the controller. + * Change the value of the cross button on the controller. * * @param value the new value */ @@ -107,7 +109,7 @@ public void setCrossButton(boolean value) { } /** - * Change the value of the Circle button on the controller. + * Change the value of the circle button on the controller. * * @param value the new value */ @@ -116,7 +118,7 @@ public void setCircleButton(boolean value) { } /** - * Change the value of the Triangle button on the controller. + * Change the value of the triangle button on the controller. * * @param value the new value */ @@ -125,7 +127,7 @@ public void setTriangleButton(boolean value) { } /** - * Change the value of the L1 button on the controller. + * Change the value of the left trigger 1 button on the controller. * * @param value the new value */ @@ -134,7 +136,7 @@ public void setL1Button(boolean value) { } /** - * Change the value of the R1 button on the controller. + * Change the value of the right trigger 1 button on the controller. * * @param value the new value */ @@ -143,7 +145,7 @@ public void setR1Button(boolean value) { } /** - * Change the value of the L2 button on the controller. + * Change the value of the left trigger 2 button on the controller. * * @param value the new value */ @@ -152,7 +154,7 @@ public void setL2Button(boolean value) { } /** - * Change the value of the R2 button on the controller. + * Change the value of the right trigger 2 button on the controller. * * @param value the new value */ @@ -161,7 +163,7 @@ public void setR2Button(boolean value) { } /** - * Change the value of the Create button on the controller. + * Change the value of the create button on the controller. * * @param value the new value */ @@ -170,7 +172,7 @@ public void setCreateButton(boolean value) { } /** - * Change the value of the Options button on the controller. + * Change the value of the options button on the controller. * * @param value the new value */ @@ -197,7 +199,7 @@ public void setR3Button(boolean value) { } /** - * Change the value of the PS button on the controller. + * Change the value of the PlayStation button on the controller. * * @param value the new value */ @@ -210,6 +212,17 @@ public void setPSButton(boolean value) { * * @param value the new value */ + public void setTouchpadButton(boolean value) { + setRawButton(PS5Controller.Button.kTouchpad.value, value); + } + + /** + * Change the value of the touchpad button on the controller. + * + * @param value the new value + * @deprecated Use {@link setTouchpadButton} instead + */ + @Deprecated(since = "2025", forRemoval = true) public void setTouchpad(boolean value) { setRawButton(PS5Controller.Button.kTouchpad.value, value); } diff --git a/wpilibj/src/generated/main/java/edu/wpi/first/wpilibj/simulation/StadiaControllerSim.java b/wpilibj/src/generated/main/java/edu/wpi/first/wpilibj/simulation/StadiaControllerSim.java new file mode 100644 index 00000000000..4bde45da276 --- /dev/null +++ b/wpilibj/src/generated/main/java/edu/wpi/first/wpilibj/simulation/StadiaControllerSim.java @@ -0,0 +1,209 @@ +// Copyright (c) FIRST and other WPILib contributors. +// Open Source Software; you can modify and/or share it under the terms of +// the WPILib BSD license file in the root directory of this project. + +// THIS FILE WAS AUTO-GENERATED BY ./wpilibj/generate_hids.py. DO NOT MODIFY + +package edu.wpi.first.wpilibj.simulation; + +import edu.wpi.first.wpilibj.StadiaController; + +/** Class to control a simulated Stadia controller. */ +public class StadiaControllerSim extends GenericHIDSim { + /** + * Constructs from a StadiaController object. + * + * @param joystick controller to simulate + */ + @SuppressWarnings("this-escape") + public StadiaControllerSim(StadiaController joystick) { + super(joystick); + setAxisCount(4); + setButtonCount(15); + setPOVCount(1); + } + + /** + * Constructs from a joystick port number. + * + * @param port port number + */ + @SuppressWarnings("this-escape") + public StadiaControllerSim(int port) { + super(port); + setAxisCount(4); + setButtonCount(15); + setPOVCount(1); + } + + /** + * Change the left X value of the controller's joystick. + * + * @param value the new value + */ + public void setLeftX(double value) { + setRawAxis(StadiaController.Axis.kLeftX.value, value); + } + + /** + * Change the right X value of the controller's joystick. + * + * @param value the new value + */ + public void setRightX(double value) { + setRawAxis(StadiaController.Axis.kRightX.value, value); + } + + /** + * Change the left Y value of the controller's joystick. + * + * @param value the new value + */ + public void setLeftY(double value) { + setRawAxis(StadiaController.Axis.kLeftY.value, value); + } + + /** + * Change the right Y value of the controller's joystick. + * + * @param value the new value + */ + public void setRightY(double value) { + setRawAxis(StadiaController.Axis.kRightY.value, value); + } + + /** + * Change the value of the A button on the controller. + * + * @param value the new value + */ + public void setAButton(boolean value) { + setRawButton(StadiaController.Button.kA.value, value); + } + + /** + * Change the value of the B button on the controller. + * + * @param value the new value + */ + public void setBButton(boolean value) { + setRawButton(StadiaController.Button.kB.value, value); + } + + /** + * Change the value of the X button on the controller. + * + * @param value the new value + */ + public void setXButton(boolean value) { + setRawButton(StadiaController.Button.kX.value, value); + } + + /** + * Change the value of the Y button on the controller. + * + * @param value the new value + */ + public void setYButton(boolean value) { + setRawButton(StadiaController.Button.kY.value, value); + } + + /** + * Change the value of the left bumper button on the controller. + * + * @param value the new value + */ + public void setLeftBumperButton(boolean value) { + setRawButton(StadiaController.Button.kLeftBumper.value, value); + } + + /** + * Change the value of the right bumper button on the controller. + * + * @param value the new value + */ + public void setRightBumperButton(boolean value) { + setRawButton(StadiaController.Button.kRightBumper.value, value); + } + + /** + * Change the value of the left stick button on the controller. + * + * @param value the new value + */ + public void setLeftStickButton(boolean value) { + setRawButton(StadiaController.Button.kLeftStick.value, value); + } + + /** + * Change the value of the right stick button on the controller. + * + * @param value the new value + */ + public void setRightStickButton(boolean value) { + setRawButton(StadiaController.Button.kRightStick.value, value); + } + + /** + * Change the value of the ellipses button on the controller. + * + * @param value the new value + */ + public void setEllipsesButton(boolean value) { + setRawButton(StadiaController.Button.kEllipses.value, value); + } + + /** + * Change the value of the hamburger button on the controller. + * + * @param value the new value + */ + public void setHamburgerButton(boolean value) { + setRawButton(StadiaController.Button.kHamburger.value, value); + } + + /** + * Change the value of the stadia button on the controller. + * + * @param value the new value + */ + public void setStadiaButton(boolean value) { + setRawButton(StadiaController.Button.kStadia.value, value); + } + + /** + * Change the value of the right trigger button on the controller. + * + * @param value the new value + */ + public void setRightTriggerButton(boolean value) { + setRawButton(StadiaController.Button.kRightTrigger.value, value); + } + + /** + * Change the value of the left trigger button on the controller. + * + * @param value the new value + */ + public void setLeftTriggerButton(boolean value) { + setRawButton(StadiaController.Button.kLeftTrigger.value, value); + } + + /** + * Change the value of the google button on the controller. + * + * @param value the new value + */ + public void setGoogleButton(boolean value) { + setRawButton(StadiaController.Button.kGoogle.value, value); + } + + /** + * Change the value of the frame button on the controller. + * + * @param value the new value + */ + public void setFrameButton(boolean value) { + setRawButton(StadiaController.Button.kFrame.value, value); + } +} diff --git a/wpilibj/src/generated/main/java/edu/wpi/first/wpilibj/simulation/XboxControllerSim.java b/wpilibj/src/generated/main/java/edu/wpi/first/wpilibj/simulation/XboxControllerSim.java new file mode 100644 index 00000000000..8417b777f71 --- /dev/null +++ b/wpilibj/src/generated/main/java/edu/wpi/first/wpilibj/simulation/XboxControllerSim.java @@ -0,0 +1,204 @@ +// Copyright (c) FIRST and other WPILib contributors. +// Open Source Software; you can modify and/or share it under the terms of +// the WPILib BSD license file in the root directory of this project. + +// THIS FILE WAS AUTO-GENERATED BY ./wpilibj/generate_hids.py. DO NOT MODIFY + +package edu.wpi.first.wpilibj.simulation; + +import edu.wpi.first.wpilibj.XboxController; + +/** Class to control a simulated Xbox controller. */ +public class XboxControllerSim extends GenericHIDSim { + /** + * Constructs from a XboxController object. + * + * @param joystick controller to simulate + */ + @SuppressWarnings("this-escape") + public XboxControllerSim(XboxController joystick) { + super(joystick); + setAxisCount(6); + setButtonCount(10); + setPOVCount(1); + } + + /** + * Constructs from a joystick port number. + * + * @param port port number + */ + @SuppressWarnings("this-escape") + public XboxControllerSim(int port) { + super(port); + setAxisCount(6); + setButtonCount(10); + setPOVCount(1); + } + + /** + * Change the left X value of the controller's joystick. + * + * @param value the new value + */ + public void setLeftX(double value) { + setRawAxis(XboxController.Axis.kLeftX.value, value); + } + + /** + * Change the right X value of the controller's joystick. + * + * @param value the new value + */ + public void setRightX(double value) { + setRawAxis(XboxController.Axis.kRightX.value, value); + } + + /** + * Change the left Y value of the controller's joystick. + * + * @param value the new value + */ + public void setLeftY(double value) { + setRawAxis(XboxController.Axis.kLeftY.value, value); + } + + /** + * Change the right Y value of the controller's joystick. + * + * @param value the new value + */ + public void setRightY(double value) { + setRawAxis(XboxController.Axis.kRightY.value, value); + } + + /** + * Change the value of the left trigger axis on the controller. + * + * @param value the new value + */ + public void setLeftTriggerAxis(double value) { + setRawAxis(XboxController.Axis.kLeftTrigger.value, value); + } + + /** + * Change the value of the right trigger axis on the controller. + * + * @param value the new value + */ + public void setRightTriggerAxis(double value) { + setRawAxis(XboxController.Axis.kRightTrigger.value, value); + } + + /** + * Change the value of the A button on the controller. + * + * @param value the new value + */ + public void setAButton(boolean value) { + setRawButton(XboxController.Button.kA.value, value); + } + + /** + * Change the value of the B button on the controller. + * + * @param value the new value + */ + public void setBButton(boolean value) { + setRawButton(XboxController.Button.kB.value, value); + } + + /** + * Change the value of the X button on the controller. + * + * @param value the new value + */ + public void setXButton(boolean value) { + setRawButton(XboxController.Button.kX.value, value); + } + + /** + * Change the value of the Y button on the controller. + * + * @param value the new value + */ + public void setYButton(boolean value) { + setRawButton(XboxController.Button.kY.value, value); + } + + /** + * Change the value of the left bumper button on the controller. + * + * @param value the new value + */ + public void setLeftBumperButton(boolean value) { + setRawButton(XboxController.Button.kLeftBumper.value, value); + } + + /** + * Change the value of the right bumper button on the controller. + * + * @param value the new value + */ + public void setRightBumperButton(boolean value) { + setRawButton(XboxController.Button.kRightBumper.value, value); + } + + /** + * Change the value of the back button on the controller. + * + * @param value the new value + */ + public void setBackButton(boolean value) { + setRawButton(XboxController.Button.kBack.value, value); + } + + /** + * Change the value of the start button on the controller. + * + * @param value the new value + */ + public void setStartButton(boolean value) { + setRawButton(XboxController.Button.kStart.value, value); + } + + /** + * Change the value of the left stick button on the controller. + * + * @param value the new value + */ + public void setLeftStickButton(boolean value) { + setRawButton(XboxController.Button.kLeftStick.value, value); + } + + /** + * Change the value of the right stick button on the controller. + * + * @param value the new value + */ + public void setRightStickButton(boolean value) { + setRawButton(XboxController.Button.kRightStick.value, value); + } + + /** + * Change the value of the left bumper on the joystick. + * + * @param state the new value + * @deprecated Use {@link setLeftBumperButton} instead + */ + @Deprecated(since = "2025", forRemoval = true) + public void setLeftBumper(boolean state) { + setRawButton(XboxController.Button.kLeftBumper.value, state); + } + + /** + * Change the value of the right bumper on the joystick. + * + * @param state the new value + * @deprecated Use {@link setRightBumperButton} instead + */ + @Deprecated(since = "2025", forRemoval = true) + public void setRightBumper(boolean state) { + setRawButton(XboxController.Button.kRightBumper.value, state); + } +} diff --git a/wpilibj/src/main/java/edu/wpi/first/wpilibj/ADIS16448_IMU.java b/wpilibj/src/main/java/edu/wpi/first/wpilibj/ADIS16448_IMU.java index fdb553714d4..1d79d0d6694 100644 --- a/wpilibj/src/main/java/edu/wpi/first/wpilibj/ADIS16448_IMU.java +++ b/wpilibj/src/main/java/edu/wpi/first/wpilibj/ADIS16448_IMU.java @@ -840,7 +840,7 @@ private void acquire() { if (calc_crc == imu_crc) { // Timestamp is at buffer[i] - m_dt = ((double) buffer[i] - previous_timestamp) / 1000000.0; + m_dt = (buffer[i] - previous_timestamp) / 1000000.0; // Scale sensor data gyro_rate_x = (toShort(buffer[i + 5], buffer[i + 6]) * 0.04); diff --git a/wpilibj/src/main/java/edu/wpi/first/wpilibj/ADIS16470_IMU.java b/wpilibj/src/main/java/edu/wpi/first/wpilibj/ADIS16470_IMU.java index b3cc31c51cf..d320167c4fe 100644 --- a/wpilibj/src/main/java/edu/wpi/first/wpilibj/ADIS16470_IMU.java +++ b/wpilibj/src/main/java/edu/wpi/first/wpilibj/ADIS16470_IMU.java @@ -825,7 +825,7 @@ private void acquire() { // Could be multiple data sets in the buffer. Handle each one. for (int i = 0; i < data_to_read; i += dataset_len) { // Timestamp is at buffer[i] - m_dt = ((double) buffer[i] - previous_timestamp) / 1000000.0; + m_dt = (buffer[i] - previous_timestamp) / 1000000.0; /* * System.out.println(((toInt(buffer[i + 3], buffer[i + 4], buffer[i + 5], diff --git a/wpilibj/src/main/java/edu/wpi/first/wpilibj/AddressableLEDBuffer.java b/wpilibj/src/main/java/edu/wpi/first/wpilibj/AddressableLEDBuffer.java index f751a31a5e0..28bbc4b4c5e 100644 --- a/wpilibj/src/main/java/edu/wpi/first/wpilibj/AddressableLEDBuffer.java +++ b/wpilibj/src/main/java/edu/wpi/first/wpilibj/AddressableLEDBuffer.java @@ -4,11 +4,8 @@ package edu.wpi.first.wpilibj; -import edu.wpi.first.wpilibj.util.Color; -import edu.wpi.first.wpilibj.util.Color8Bit; - /** Buffer storage for Addressable LEDs. */ -public class AddressableLEDBuffer { +public class AddressableLEDBuffer implements LEDReader, LEDWriter { byte[] m_buffer; /** @@ -28,6 +25,7 @@ public AddressableLEDBuffer(int length) { * @param g the g value [0-255] * @param b the b value [0-255] */ + @Override public void setRGB(int index, int r, int g, int b) { m_buffer[index * 4] = (byte) b; m_buffer[(index * 4) + 1] = (byte) g; @@ -35,109 +33,23 @@ public void setRGB(int index, int r, int g, int b) { m_buffer[(index * 4) + 3] = 0; } - /** - * Sets a specific led in the buffer. - * - * @param index the index to write - * @param h the h value [0-180) - * @param s the s value [0-255] - * @param v the v value [0-255] - */ - public void setHSV(final int index, final int h, final int s, final int v) { - if (s == 0) { - setRGB(index, v, v, v); - return; - } - - // The below algorithm is copied from Color.fromHSV and moved here for - // performance reasons. - - // Loosely based on - // https://en.wikipedia.org/wiki/HSL_and_HSV#HSV_to_RGB - // The hue range is split into 60 degree regions where in each region there - // is one rgb component at a low value (m), one at a high value (v) and one - // that changes (X) from low to high (X+m) or high to low (v-X) - - // Difference between highest and lowest value of any rgb component - final int chroma = (s * v) / 255; - - // Because hue is 0-180 rather than 0-360 use 30 not 60 - final int region = (h / 30) % 6; - - // Remainder converted from 0-30 to 0-255 - final int remainder = (int) Math.round((h % 30) * (255 / 30.0)); - - // Value of the lowest rgb component - final int m = v - chroma; - - // Goes from 0 to chroma as hue increases - final int X = (chroma * remainder) >> 8; - - switch (region) { - case 0 -> setRGB(index, v, X + m, m); - case 1 -> setRGB(index, v - X, v, m); - case 2 -> setRGB(index, m, v, X + m); - case 3 -> setRGB(index, m, v - X, v); - case 4 -> setRGB(index, X + m, m, v); - default -> setRGB(index, v, m, v - X); - } - } - - /** - * Sets a specific LED in the buffer. - * - * @param index The index to write - * @param color The color of the LED - */ - public void setLED(int index, Color color) { - setRGB(index, (int) (color.red * 255), (int) (color.green * 255), (int) (color.blue * 255)); - } - - /** - * Sets a specific LED in the buffer. - * - * @param index The index to write - * @param color The color of the LED - */ - public void setLED(int index, Color8Bit color) { - setRGB(index, color.red, color.green, color.blue); - } - /** * Gets the buffer length. * * @return the buffer length */ + @Override public int getLength() { return m_buffer.length / 4; } - /** - * Gets the color at the specified index. - * - * @param index the index to get - * @return the LED color at the specified index - */ - public Color8Bit getLED8Bit(int index) { - return new Color8Bit(getRed(index), getGreen(index), getBlue(index)); - } - - /** - * Gets the color at the specified index. - * - * @param index the index to get - * @return the LED color at the specified index - */ - public Color getLED(int index) { - return new Color(getRed(index) / 255.0, getGreen(index) / 255.0, getBlue(index) / 255.0); - } - /** * Gets the red channel of the color at the specified index. * * @param index the index of the LED to read * @return the value of the red channel, from [0, 255] */ + @Override public int getRed(int index) { return m_buffer[index * 4 + 2] & 0xFF; } @@ -148,6 +60,7 @@ public int getRed(int index) { * @param index the index of the LED to read * @return the value of the green channel, from [0, 255] */ + @Override public int getGreen(int index) { return m_buffer[index * 4 + 1] & 0xFF; } @@ -158,41 +71,22 @@ public int getGreen(int index) { * @param index the index of the LED to read * @return the value of the blue channel, from [0, 255] */ + @Override public int getBlue(int index) { return m_buffer[index * 4] & 0xFF; } /** - * A functional interface that allows for iteration over an LED buffer without manually writing an - * indexed for-loop. - */ - @FunctionalInterface - public interface IndexedColorIterator { - /** - * Accepts an index of an LED in the buffer and the red, green, and blue components of the - * currently stored color for that LED. - * - * @param index the index of the LED in the buffer that the red, green, and blue channels - * corresponds to - * @param r the value of the red channel of the color currently in the buffer at index {@code i} - * @param g the value of the green channel of the color currently in the buffer at index {@code - * i} - * @param b the value of the blue channel of the color currently in the buffer at index {@code - * i} - */ - void accept(int index, int r, int g, int b); - } - - /** - * Iterates over the LEDs in the buffer, starting from index 0. The iterator function is passed - * the current index of iteration, along with the values for the red, green, and blue components - * of the color written to the LED at that index. + * Creates a view of a subsection of this data buffer, starting from (and including) {@code + * startingIndex} and ending on (and including) {@code endingIndex}. Views cannot be written + * directly to an {@link AddressableLED}, but are useful tools for logically separating different + * sections of an LED strip for independent control. * - * @param iterator the iterator function to call for each LED in the buffer. + * @param startingIndex the first index in this buffer that the view should encompass (inclusive) + * @param endingIndex the last index in this buffer that the view should encompass (inclusive) + * @return the view object */ - public void forEach(IndexedColorIterator iterator) { - for (int i = 0; i < getLength(); i++) { - iterator.accept(i, getRed(i), getGreen(i), getBlue(i)); - } + public AddressableLEDBufferView createView(int startingIndex, int endingIndex) { + return new AddressableLEDBufferView(this, startingIndex, endingIndex); } } diff --git a/wpilibj/src/main/java/edu/wpi/first/wpilibj/AddressableLEDBufferView.java b/wpilibj/src/main/java/edu/wpi/first/wpilibj/AddressableLEDBufferView.java new file mode 100644 index 00000000000..1f7cfb0d6ef --- /dev/null +++ b/wpilibj/src/main/java/edu/wpi/first/wpilibj/AddressableLEDBufferView.java @@ -0,0 +1,163 @@ +// Copyright (c) FIRST and other WPILib contributors. +// Open Source Software; you can modify and/or share it under the terms of +// the WPILib BSD license file in the root directory of this project. + +package edu.wpi.first.wpilibj; + +import static edu.wpi.first.util.ErrorMessages.requireNonNullParam; + +import edu.wpi.first.wpilibj.util.Color; +import edu.wpi.first.wpilibj.util.Color8Bit; + +/** + * A view of another addressable LED buffer. Views CANNOT be written directly to an LED strip; the + * backing buffer must be written instead. However, views provide an easy way to split a large LED + * strip into smaller sections (which may be reversed from the orientation of the LED strip as a + * whole) that can be animated individually without modifying LEDs outside those sections. + */ +public class AddressableLEDBufferView implements LEDReader, LEDWriter { + private final LEDReader m_backingReader; + private final LEDWriter m_backingWriter; + private final int m_startingIndex; + private final int m_endingIndex; + private final int m_length; + + /** + * Creates a new view of a buffer. A view will be reversed if the starting index is after the + * ending index; writing front-to-back in the view will write in the back-to-front direction on + * the underlying buffer. + * + * @param backingBuffer the backing buffer to view + * @param startingIndex the index of the LED in the backing buffer that the view should start from + * @param endingIndex the index of the LED in the backing buffer that the view should end on + * @param the type of the buffer object to create a view for + */ + public AddressableLEDBufferView( + B backingBuffer, int startingIndex, int endingIndex) { + this( + requireNonNullParam(backingBuffer, "backingBuffer", "AddressableLEDBufferView"), + backingBuffer, + startingIndex, + endingIndex); + } + + /** + * Creates a new view of a buffer. A view will be reversed if the starting index is after the + * ending index; writing front-to-back in the view will write in the back-to-front direction on + * the underlying buffer. + * + * @param backingReader the backing LED data reader + * @param backingWriter the backing LED data writer + * @param startingIndex the index of the LED in the backing buffer that the view should start from + * @param endingIndex the index of the LED in the backing buffer that the view should end on + */ + public AddressableLEDBufferView( + LEDReader backingReader, LEDWriter backingWriter, int startingIndex, int endingIndex) { + requireNonNullParam(backingReader, "backingReader", "AddressableLEDBufferView"); + requireNonNullParam(backingWriter, "backingWriter", "AddressableLEDBufferView"); + + if (startingIndex < 0 || startingIndex >= backingReader.getLength()) { + throw new IndexOutOfBoundsException("Start index out of range: " + startingIndex); + } + if (endingIndex < 0 || endingIndex >= backingReader.getLength()) { + throw new IndexOutOfBoundsException("End index out of range: " + endingIndex); + } + + m_backingReader = backingReader; + m_backingWriter = backingWriter; + + m_startingIndex = startingIndex; + m_endingIndex = endingIndex; + m_length = Math.abs(endingIndex - startingIndex) + 1; + } + + /** + * Creates a view that operates on the same range as this one, but goes in reverse order. This is + * useful for serpentine runs of LED strips connected front-to-end; simply reverse the view for + * reversed sections and animations will move in the same physical direction along both strips. + * + * @return the reversed view + */ + public AddressableLEDBufferView reversed() { + return new AddressableLEDBufferView(this, m_length - 1, 0); + } + + @Override + public int getLength() { + return m_length; + } + + @Override + public void setRGB(int index, int r, int g, int b) { + m_backingWriter.setRGB(nativeIndex(index), r, g, b); + } + + @Override + public Color getLED(int index) { + // override to delegate to the backing buffer to avoid 3x native index lookups & bounds checks + return m_backingReader.getLED(nativeIndex(index)); + } + + @Override + public Color8Bit getLED8Bit(int index) { + // override to delegate to the backing buffer to avoid 3x native index lookups & bounds checks + return m_backingReader.getLED8Bit(nativeIndex(index)); + } + + @Override + public int getRed(int index) { + return m_backingReader.getRed(nativeIndex(index)); + } + + @Override + public int getGreen(int index) { + return m_backingReader.getGreen(nativeIndex(index)); + } + + @Override + public int getBlue(int index) { + return m_backingReader.getBlue(nativeIndex(index)); + } + + /** + * Checks if this view is reversed with respect to its backing buffer. + * + * @return true if the view is reversed, false otherwise + */ + public boolean isReversed() { + return m_endingIndex < m_startingIndex; + } + + /** + * Converts a view-local index in the range [start, end] to a global index in the range [0, + * length]. + * + * @param viewIndex the view-local index + * @return the corresponding global index + * @throws IndexOutOfBoundsException if the view index is not contained withing the bounds of this + * view + */ + private int nativeIndex(int viewIndex) { + if (isReversed()) { + // 0 1 2 3 4 5 6 7 8 9 10 + // ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ + // [_, _, _, _, (d, c, b, a), _, _, _] + // ↑ ↑ ↑ ↑ + // 3 2 1 0 + if (viewIndex < 0 || viewIndex > m_startingIndex) { + throw new IndexOutOfBoundsException(viewIndex); + } + return m_startingIndex - viewIndex; + } else { + // 0 1 2 3 4 5 6 7 8 9 10 + // ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ + // [_, _, _, _, (a, b, c, d), _, _, _] + // ↑ ↑ ↑ ↑ + // 0 1 2 3 + if (viewIndex < 0 || viewIndex > m_endingIndex) { + throw new IndexOutOfBoundsException(viewIndex); + } + return m_startingIndex + viewIndex; + } + } +} diff --git a/wpilibj/src/main/java/edu/wpi/first/wpilibj/DigitalGlitchFilter.java b/wpilibj/src/main/java/edu/wpi/first/wpilibj/DigitalGlitchFilter.java index 2fcc9dd7a9a..7bc705deb23 100644 --- a/wpilibj/src/main/java/edu/wpi/first/wpilibj/DigitalGlitchFilter.java +++ b/wpilibj/src/main/java/edu/wpi/first/wpilibj/DigitalGlitchFilter.java @@ -168,7 +168,7 @@ public int getPeriodCycles() { public long getPeriodNanoSeconds() { int fpgaCycles = getPeriodCycles(); - return (long) fpgaCycles * 1000L / (long) (SensorUtil.kSystemClockTicksPerMicrosecond / 4); + return fpgaCycles * 1000L / (SensorUtil.kSystemClockTicksPerMicrosecond / 4); } @Override diff --git a/wpilibj/src/main/java/edu/wpi/first/wpilibj/DriverStation.java b/wpilibj/src/main/java/edu/wpi/first/wpilibj/DriverStation.java index 2213f2604b8..c5d720589a5 100644 --- a/wpilibj/src/main/java/edu/wpi/first/wpilibj/DriverStation.java +++ b/wpilibj/src/main/java/edu/wpi/first/wpilibj/DriverStation.java @@ -11,7 +11,6 @@ import edu.wpi.first.hal.MatchInfoData; import edu.wpi.first.networktables.BooleanPublisher; import edu.wpi.first.networktables.IntegerPublisher; -import edu.wpi.first.networktables.NetworkTable; import edu.wpi.first.networktables.NetworkTableInstance; import edu.wpi.first.networktables.StringPublisher; import edu.wpi.first.util.EventVector; @@ -32,13 +31,13 @@ public final class DriverStation { /** Number of Joystick ports. */ public static final int kJoystickPorts = 6; - private static class HALJoystickButtons { + private static final class HALJoystickButtons { public int m_buttons; public byte m_count; } private static class HALJoystickAxes { - public float[] m_axes; + public final float[] m_axes; public int m_count; HALJoystickAxes(int count) { @@ -47,7 +46,7 @@ private static class HALJoystickAxes { } private static class HALJoystickAxesRaw { - public int[] m_axes; + public final int[] m_axes; @SuppressWarnings("unused") public int m_count; @@ -58,7 +57,7 @@ private static class HALJoystickAxesRaw { } private static class HALJoystickPOVs { - public short[] m_povs; + public final short[] m_povs; public int m_count; HALJoystickPOVs(int count) { @@ -94,16 +93,14 @@ public enum MatchType { @SuppressWarnings("MemberName") private static class MatchDataSender { - NetworkTable table; - StringPublisher typeMetadata; - StringPublisher gameSpecificMessage; - StringPublisher eventName; - IntegerPublisher matchNumber; - IntegerPublisher replayNumber; - IntegerPublisher matchType; - BooleanPublisher alliance; - IntegerPublisher station; - IntegerPublisher controlWord; + final StringPublisher gameSpecificMessage; + final StringPublisher eventName; + final IntegerPublisher matchNumber; + final IntegerPublisher replayNumber; + final IntegerPublisher matchType; + final BooleanPublisher alliance; + final IntegerPublisher station; + final IntegerPublisher controlWord; boolean oldIsRedAlliance = true; int oldStationNumber = 1; String oldEventName = ""; @@ -114,9 +111,8 @@ private static class MatchDataSender { int oldControlWord; MatchDataSender() { - table = NetworkTableInstance.getDefault().getTable("FMSInfo"); - typeMetadata = table.getStringTopic(".type").publish(); - typeMetadata.set("FMSInfo"); + var table = NetworkTableInstance.getDefault().getTable("FMSInfo"); + table.getStringTopic(".type").publish().set("FMSInfo"); gameSpecificMessage = table.getStringTopic("GameSpecificMessage").publish(); gameSpecificMessage.set(""); eventName = table.getStringTopic("EventName").publish(); diff --git a/wpilibj/src/main/java/edu/wpi/first/wpilibj/LEDPattern.java b/wpilibj/src/main/java/edu/wpi/first/wpilibj/LEDPattern.java new file mode 100644 index 00000000000..3d39b502c01 --- /dev/null +++ b/wpilibj/src/main/java/edu/wpi/first/wpilibj/LEDPattern.java @@ -0,0 +1,644 @@ +// Copyright (c) FIRST and other WPILib contributors. +// Open Source Software; you can modify and/or share it under the terms of +// the WPILib BSD license file in the root directory of this project. + +package edu.wpi.first.wpilibj; + +import static edu.wpi.first.units.Units.Meters; +import static edu.wpi.first.units.Units.Microsecond; +import static edu.wpi.first.units.Units.Microseconds; +import static edu.wpi.first.units.Units.Value; + +import edu.wpi.first.math.MathUtil; +import edu.wpi.first.units.Dimensionless; +import edu.wpi.first.units.Distance; +import edu.wpi.first.units.Measure; +import edu.wpi.first.units.Time; +import edu.wpi.first.units.Velocity; +import edu.wpi.first.units.collections.LongToObjectHashMap; +import edu.wpi.first.util.WPIUtilJNI; +import edu.wpi.first.wpilibj.util.Color; +import java.util.Map; +import java.util.Objects; +import java.util.function.BooleanSupplier; +import java.util.function.DoubleSupplier; + +/** + * An LED pattern controls lights on an LED strip to command patterns of color that may change over + * time. Dynamic patterns should synchronize on an external clock for timed-based animations ({@link + * WPIUtilJNI#now()} is recommended, since it can be mocked in simulation and unit tests), or on + * some other dynamic input (see {@link #synchronizedBlink(BooleanSupplier)}, for example). + * + *

Patterns should be updated periodically in order for animations to play smoothly. For example, + * a hypothetical LED subsystem could create a {@code Command} that will continuously apply the + * pattern to its LED data buffer as part of the main periodic loop. + * + *


+ *   public class LEDs extends SubsystemBase {
+ *     private final AddressableLED m_led = new AddressableLED(0);
+ *     private final AddressableLEDBuffer m_ledData = new AddressableLEDBuffer(120);
+ *
+ *     public LEDs() {
+ *       m_led.setLength(120);
+ *       m_led.start();
+ *     }
+ *
+ *    {@literal @}Override
+ *     public void periodic() {
+ *       m_led.writeData(m_ledData);
+ *     }
+ *
+ *     public Command runPattern(LEDPattern pattern) {
+ *       return run(() -> pattern.applyTo(m_ledData));
+ *     }
+ *   }
+ * 
+ * + *

LED patterns are stateless, and as such can be applied to multiple LED strips (or different + * sections of the same LED strip, since the roboRIO can only drive a single LED strip). In this + * example, we split the single buffer into two views - one for the section of the LED strip on the + * left side of a robot, and another view for the section of LEDs on the right side. The same + * pattern is able to be applied to both sides. + * + *


+ *   public class LEDs extends SubsystemBase {
+ *     private final AddressableLED m_led = new AddressableLED(0);
+ *     private final AddressableLEDBuffer m_ledData = new AddressableLEDBuffer(60);
+ *     private final AddressableLEDBufferView m_leftData = m_ledData.createView(0, 29);
+ *     private final AddressableLEDBufferView m_rightData = m_ledData.createView(30, 59).reversed();
+ *
+ *     public LEDs() {
+ *       m_led.setLength(60);
+ *       m_led.start();
+ *     }
+ *
+ *    {@literal @}Override
+ *     public void periodic() {
+ *       m_led.writeData(m_ledData);
+ *     }
+ *
+ *     public Command runPattern(LEDPattern pattern) {
+ *       // Use the single input pattern to drive both sides
+ *       return runSplitPatterns(pattern, pattern);
+ *     }
+ *
+ *     public Command runSplitPatterns(LEDPattern left, LEDPattern right) {
+ *       return run(() -> {
+ *         left.applyTo(m_leftData);
+ *         right.applyTo(m_rightData);
+ *       });
+ *     }
+ *   }
+ * 
+ */ +@FunctionalInterface +public interface LEDPattern { + /** + * Writes the pattern to an LED buffer. Dynamic animations should be called periodically (such as + * with a command or with a periodic method) to refresh the buffer over time. + * + *

This method is intentionally designed to use separate objects for reading and writing data. + * By splitting them up, we can easily modify the behavior of some base pattern to make it {@link + * #scrollAtRelativeSpeed(Measure) scroll}, {@link #blink(Measure, Measure) blink}, or {@link + * #breathe(Measure) breathe} by intercepting the data writes to transform their behavior to + * whatever we like. + * + * @param reader data reader for accessing buffer length and current colors + * @param writer data writer for setting new LED colors on the buffer + */ + void applyTo(LEDReader reader, LEDWriter writer); + + /** + * Convenience for {@link #applyTo(LEDReader, LEDWriter)} when one object provides both a read and + * a write interface. This is most helpful for playing an animated pattern directly on an {@link + * AddressableLEDBuffer} for the sake of code clarity. + * + *


+   *   AddressableLEDBuffer data = new AddressableLEDBuffer(120);
+   *   LEDPattern pattern = ...
+   *
+   *   void periodic() {
+   *     pattern.applyTo(data);
+   *   }
+   * 
+ * + * @param readWriter the object to use for both reading and writing to a set of LEDs + * @param the type of the object that can both read and write LED data + */ + default void applyTo(T readWriter) { + applyTo(readWriter, readWriter); + } + + /** + * Creates a pattern that displays this one in reverse. Scrolling patterns will scroll in the + * opposite direction (but at the same speed). It will treat the end of an LED strip as the start, + * and the start of the strip as the end. This can be useful for making ping-pong patterns that + * travel from one end of an LED strip to the other, then reverse direction and move back to the + * start. This can also be useful when working with LED strips connected in a serpentine pattern + * (where the start of one strip is connected to the end of the previous one); however, consider + * using a {@link AddressableLEDBufferView#reversed() reversed view} of the overall buffer for + * that segment rather than reversing patterns. + * + * @return the reverse pattern + * @see AddressableLEDBufferView#reversed() + */ + default LEDPattern reversed() { + return (reader, writer) -> { + int bufLen = reader.getLength(); + applyTo(reader, (i, r, g, b) -> writer.setRGB((bufLen - 1) - i, r, g, b)); + }; + } + + /** + * Creates a pattern that plays this one, but offset by a certain number of LEDs. The offset + * pattern will wrap around, if necessary. + * + * @param offset how many LEDs to offset by + * @return the offset pattern + */ + default LEDPattern offsetBy(int offset) { + return (reader, writer) -> { + int bufLen = reader.getLength(); + applyTo( + reader, + (i, r, g, b) -> { + int shiftedIndex = Math.floorMod(i + offset, bufLen); + writer.setRGB(shiftedIndex, r, g, b); + }); + }; + } + + /** + * Creates a pattern that plays this one scrolling up the buffer. The velocity controls how fast + * the pattern returns back to its original position, and is in terms of the length of the LED + * strip; scrolling across a segment that is 10 LEDs long will travel twice as fast as on a + * segment that's only 5 LEDs long (assuming equal LED density on both segments). + * + *

For example, scrolling a pattern by one quarter of any LED strip's length per second, + * regardless of the total number of LEDs on that strip: + * + *

+   *   LEDPattern rainbow = LEDPattern.rainbow(255, 255);
+   *   LEDPattern scrollingRainbow = rainbow.scrollAtRelativeSpeed(Percent.per(Second).of(25));
+   * 
+ * + * @param velocity how fast the pattern should move, in terms of how long it takes to do a full + * scroll along the length of LEDs and return back to the starting position + * @return the scrolling pattern + */ + default LEDPattern scrollAtRelativeSpeed(Measure> velocity) { + final double periodMicros = 1 / velocity.in(Value.per(Microsecond)); + + return (reader, writer) -> { + int bufLen = reader.getLength(); + long now = WPIUtilJNI.now(); + + // index should move by (buf.length) / (period) + double t = (now % (long) periodMicros) / periodMicros; + int offset = (int) (t * bufLen); + + applyTo( + reader, + (i, r, g, b) -> { + // floorMod so if the offset is negative, we still get positive outputs + int shiftedIndex = Math.floorMod(i + offset, bufLen); + + writer.setRGB(shiftedIndex, r, g, b); + }); + }; + } + + /** + * Creates a pattern that plays this one scrolling up an LED strip. A negative velocity makes the + * pattern play in reverse. + * + *

For example, scrolling a pattern at 4 inches per second along an LED strip with 60 LEDs per + * meter: + * + *

+   *   // LEDs per meter, a known value taken from the spec sheet of our particular LED strip
+   *   Measure<Distance> LED_SPACING = Meters.of(1.0 / 60);
+   *
+   *   LEDPattern rainbow = LEDPattern.rainbow();
+   *   LEDPattern scrollingRainbow =
+   *     rainbow.scrollAtAbsoluteSpeed(InchesPerSecond.of(4), LED_SPACING);
+   * 
+ * + *

Note that this pattern will scroll faster if applied to a less dense LED strip (such + * as 30 LEDs per meter), or slower if applied to a denser LED strip (such as 120 or 144 + * LEDs per meter). + * + * @param velocity how fast the pattern should move along a physical LED strip + * @param ledSpacing the distance between adjacent LEDs on the physical LED strip + * @return the scrolling pattern + */ + default LEDPattern scrollAtAbsoluteSpeed( + Measure> velocity, Measure ledSpacing) { + // eg velocity = 10 m/s, spacing = 0.01m + // meters per micro = 1e-5 m/us + // micros per LED = 1e-2 m / (1e-5 m/us) = 1e-3 us + + var metersPerMicro = velocity.in(Meters.per(Microsecond)); + var microsPerLED = (int) (ledSpacing.in(Meters) / metersPerMicro); + + return (reader, writer) -> { + int bufLen = reader.getLength(); + long now = WPIUtilJNI.now(); + + // every step in time that's a multiple of microsPerLED will increment the offset by 1 + var offset = now / microsPerLED; + + applyTo( + reader, + (i, r, g, b) -> { + // floorMod so if the offset is negative, we still get positive outputs + int shiftedIndex = Math.floorMod(i + offset, bufLen); + + writer.setRGB(shiftedIndex, r, g, b); + }); + }; + } + + /** + * Creates a pattern that switches between playing this pattern and turning the entire LED strip + * off. + * + * @param onTime how long the pattern should play for, per cycle + * @param offTime how long the pattern should be turned off for, per cycle + * @return the blinking pattern + */ + default LEDPattern blink(Measure

This method is predominantly intended for dimming LEDs to avoid painfully bright or + * distracting patterns from playing (apologies to the 2024 NE Greater Boston field staff). + * + *

For example, dimming can be done simply by adding a call to `atBrightness` at the end of a + * pattern: + * + *

+   *   // Solid red, but at 50% brightness
+   *   LEDPattern.solid(Color.kRed).atBrightness(Percent.of(50));
+   *
+   *   // Solid white, but at only 10% (i.e. ~0.5V)
+   *   LEDPattern.solid(Color.kWhite).atBrightness(Percent.of(10));
+   * 
+ * + * @param relativeBrightness the multiplier to apply to all channels to modify brightness + * @return the input pattern, displayed at + */ + default LEDPattern atBrightness(Measure relativeBrightness) { + double multiplier = relativeBrightness.in(Value); + + return (reader, writer) -> { + applyTo( + reader, + (i, r, g, b) -> { + // Clamp RGB values to keep them in the range [0, 255]. + // Otherwise, the casts to byte would result in values like 256 wrapping to 0 + + writer.setRGB( + i, + (int) MathUtil.clamp(r * multiplier, 0, 255), + (int) MathUtil.clamp(g * multiplier, 0, 255), + (int) MathUtil.clamp(b * multiplier, 0, 255)); + }); + }; + } + + /** A pattern that turns off all LEDs. */ + LEDPattern kOff = solid(Color.kBlack); + + /** + * Creates a pattern that displays a single static color along the entire length of the LED strip. + * + * @param color the color to display + * @return the pattern + */ + static LEDPattern solid(Color color) { + return (reader, writer) -> { + int bufLen = reader.getLength(); + for (int led = 0; led < bufLen; led++) { + writer.setLED(led, color); + } + }; + } + + /** + * Creates a pattern that works as a mask layer for {@link #mask(LEDPattern)} that illuminates + * only the portion of the LED strip corresponding with some progress. The mask pattern will start + * from the base and set LEDs to white at a proportion equal to the progress returned by the + * function. Some usages for this could be for displaying progress of a flywheel to its target + * velocity, progress of a complex autonomous sequence, or the height of an elevator. + * + *

For example, creating a mask for displaying a red-to-blue gradient, starting from the red + * end, based on where an elevator is in its range of travel. + * + *

+   *   LEDPattern basePattern = gradient(Color.kRed, Color.kBlue);
+   *   LEDPattern progressPattern =
+   *     basePattern.mask(progressMaskLayer(() -> elevator.getHeight() / elevator.maxHeight());
+   * 
+ * + * @param progressSupplier the function to call to determine the progress. This should return + * values in the range [0, 1]; any values outside that range will be clamped. + * @return the mask pattern + */ + static LEDPattern progressMaskLayer(DoubleSupplier progressSupplier) { + return (reader, writer) -> { + double progress = MathUtil.clamp(progressSupplier.getAsDouble(), 0, 1); + + int bufLen = reader.getLength(); + int max = (int) (bufLen * progress); + + for (int led = 0; led < max; led++) { + writer.setLED(led, Color.kWhite); + } + + for (int led = max; led < bufLen; led++) { + writer.setLED(led, Color.kBlack); + } + }; + } + + /** + * Display a set of colors in steps across the length of the LED strip. No interpolation is done + * between colors. Colors are specified by the first LED on the strip to show that color. The last + * color in the map will be displayed all the way to the end of the strip. LEDs positioned before + * the first specified step will be turned off (you can think of this as if there's a 0 -> black + * step by default) + * + *
+   *   // Display red from 0-33%, white from 33% - 67%, and blue from 67% to 100%
+   *   steps(Map.of(0.00, Color.kRed, 0.33, Color.kWhite, 0.67, Color.kBlue))
+   *
+   *   // Half off, half on
+   *   steps(Map.of(0.5, Color.kWhite))
+   * 
+ * + * @param steps a map of progress to the color to start displaying at that position along the LED + * strip + * @return a motionless step pattern + */ + static LEDPattern steps(Map steps) { + if (steps.isEmpty()) { + // no colors specified + DriverStation.reportWarning("Creating LED steps with no colors!", false); + return kOff; + } + + if (steps.size() == 1 && steps.keySet().iterator().next().doubleValue() == 0) { + // only one color specified, just show a static color + DriverStation.reportWarning("Creating LED steps with only one color!", false); + return solid(steps.values().iterator().next()); + } + + return (reader, writer) -> { + int bufLen = reader.getLength(); + + // precompute relevant positions for this buffer so we don't need to do a check + // on every single LED index + var stopPositions = new LongToObjectHashMap(); + steps.forEach( + (progress, color) -> { + stopPositions.put((int) Math.floor(progress.doubleValue() * bufLen), color); + }); + + Color currentColor = Color.kBlack; + for (int led = 0; led < bufLen; led++) { + currentColor = Objects.requireNonNullElse(stopPositions.get(led), currentColor); + + writer.setLED(led, currentColor); + } + }; + } + + /** + * Creates a pattern that displays a non-animated gradient of colors across the entire length of + * the LED strip. The gradient wraps around so the start and end of the strip are the same color, + * which allows the gradient to be modified with a scrolling effect with no discontinuities. + * Colors are evenly distributed along the full length of the LED strip. + * + * @param colors the colors to display in the gradient + * @return a motionless gradient pattern + */ + static LEDPattern gradient(Color... colors) { + if (colors.length == 0) { + // Nothing to display + DriverStation.reportWarning("Creating a gradient with no colors!", false); + return kOff; + } + + if (colors.length == 1) { + // No gradients with one color + DriverStation.reportWarning("Creating a gradient with only one color!", false); + return solid(colors[0]); + } + + final int numSegments = colors.length; + + return (reader, writer) -> { + int bufLen = reader.getLength(); + int ledsPerSegment = bufLen / numSegments; + + for (int led = 0; led < bufLen; led++) { + int colorIndex = (led / ledsPerSegment) % numSegments; + int nextColorIndex = (colorIndex + 1) % numSegments; + double t = (led / (double) ledsPerSegment) % 1; + + Color color = colors[colorIndex]; + Color nextColor = colors[nextColorIndex]; + int gradientColor = + Color.lerpRGB( + color.red, + color.green, + color.blue, + nextColor.red, + nextColor.green, + nextColor.blue, + t); + + writer.setRGB( + led, + Color.unpackRGB(gradientColor, Color.RGBChannel.kRed), + Color.unpackRGB(gradientColor, Color.RGBChannel.kGreen), + Color.unpackRGB(gradientColor, Color.RGBChannel.kBlue)); + } + }; + } + + /** + * Creates an LED pattern that displays a rainbow across the color wheel. The rainbow pattern will + * stretch across the entire length of the LED strip. + * + * @param saturation the saturation of the HSV colors, in [0, 255] + * @param value the value of the HSV colors, in [0, 255] + * @return the rainbow pattern + */ + static LEDPattern rainbow(int saturation, int value) { + return (reader, writer) -> { + int bufLen = reader.getLength(); + for (int i = 0; i < bufLen; i++) { + int hue = ((i * 180) / bufLen) % 180; + writer.setHSV(i, hue, saturation, value); + } + }; + } +} diff --git a/wpilibj/src/main/java/edu/wpi/first/wpilibj/LEDReader.java b/wpilibj/src/main/java/edu/wpi/first/wpilibj/LEDReader.java new file mode 100644 index 00000000000..176884a9221 --- /dev/null +++ b/wpilibj/src/main/java/edu/wpi/first/wpilibj/LEDReader.java @@ -0,0 +1,99 @@ +// Copyright (c) FIRST and other WPILib contributors. +// Open Source Software; you can modify and/or share it under the terms of +// the WPILib BSD license file in the root directory of this project. + +package edu.wpi.first.wpilibj; + +import edu.wpi.first.wpilibj.util.Color; +import edu.wpi.first.wpilibj.util.Color8Bit; + +/** Generic interface for reading data from an LED buffer. */ +public interface LEDReader { + /** + * Gets the length of the buffer. + * + * @return the buffer length + */ + int getLength(); + + /** + * Gets the most recently written color for a particular LED in the buffer. + * + * @param index the index of the LED + * @return the LED color + * @throws IndexOutOfBoundsException if the index is negative or greater than {@link #getLength()} + */ + default Color getLED(int index) { + return new Color(getRed(index) / 255.0, getGreen(index) / 255.0, getBlue(index) / 255.0); + } + + /** + * Gets the most recently written color for a particular LED in the buffer. + * + * @param index the index of the LED + * @return the LED color + * @throws IndexOutOfBoundsException if the index is negative or greater than {@link #getLength()} + */ + default Color8Bit getLED8Bit(int index) { + return new Color8Bit(getRed(index), getGreen(index), getBlue(index)); + } + + /** + * Gets the red channel of the color at the specified index. + * + * @param index the index of the LED to read + * @return the value of the red channel, from [0, 255] + */ + int getRed(int index); + + /** + * Gets the green channel of the color at the specified index. + * + * @param index the index of the LED to read + * @return the value of the green channel, from [0, 255] + */ + int getGreen(int index); + + /** + * Gets the blue channel of the color at the specified index. + * + * @param index the index of the LED to read + * @return the value of the blue channel, from [0, 255] + */ + int getBlue(int index); + + /** + * A functional interface that allows for iteration over an LED buffer without manually writing an + * indexed for-loop. + */ + @FunctionalInterface + interface IndexedColorIterator { + /** + * Accepts an index of an LED in the buffer and the red, green, and blue components of the + * currently stored color for that LED. + * + * @param index the index of the LED in the buffer that the red, green, and blue channels + * corresponds to + * @param r the value of the red channel of the color currently in the buffer at index {@code i} + * @param g the value of the green channel of the color currently in the buffer at index {@code + * i} + * @param b the value of the blue channel of the color currently in the buffer at index {@code + * i} + */ + void accept(int index, int r, int g, int b); + } + + /** + * Iterates over the LEDs in the buffer, starting from index 0. The iterator function is passed + * the current index of iteration, along with the values for the red, green, and blue components + * of the color written to the LED at that index. + * + * @param iterator the iterator function to call for each LED in the buffer. + */ + default void forEach(IndexedColorIterator iterator) { + int bufLen = getLength(); + for (int i = 0; i < bufLen; i++) { + iterator.accept(i, getRed(i), getGreen(i), getBlue(i)); + } + } +} diff --git a/wpilibj/src/main/java/edu/wpi/first/wpilibj/LEDWriter.java b/wpilibj/src/main/java/edu/wpi/first/wpilibj/LEDWriter.java new file mode 100644 index 00000000000..076291d7703 --- /dev/null +++ b/wpilibj/src/main/java/edu/wpi/first/wpilibj/LEDWriter.java @@ -0,0 +1,65 @@ +// Copyright (c) FIRST and other WPILib contributors. +// Open Source Software; you can modify and/or share it under the terms of +// the WPILib BSD license file in the root directory of this project. + +package edu.wpi.first.wpilibj; + +import edu.wpi.first.wpilibj.util.Color; +import edu.wpi.first.wpilibj.util.Color8Bit; + +/** Generic interface for writing data to an LED buffer. */ +@FunctionalInterface +public interface LEDWriter { + /** + * Sets the RGB value for an LED at a specific index on a LED buffer. + * + * @param index the index of the LED to write to + * @param r the value of the red channel, in [0, 255] + * @param g the value of the green channel, in [0, 255] + * @param b the value of the blue channel, in [0, 255] + */ + void setRGB(int index, int r, int g, int b); + + /** + * Sets a specific led in the buffer. + * + * @param index the index to write + * @param h the h value [0-180) + * @param s the s value [0-255] + * @param v the v value [0-255] + */ + default void setHSV(int index, int h, int s, int v) { + if (s == 0) { + setRGB(index, v, v, v); + return; + } + + int packedRGB = Color.hsvToRgb(h, s, v); + + setRGB( + index, + Color.unpackRGB(packedRGB, Color.RGBChannel.kRed), + Color.unpackRGB(packedRGB, Color.RGBChannel.kGreen), + Color.unpackRGB(packedRGB, Color.RGBChannel.kBlue)); + } + + /** + * Sets the RGB value for an LED at a specific index on a LED buffer. + * + * @param index the index of the LED to write to + * @param color the color to set + */ + default void setLED(int index, Color color) { + setRGB(index, (int) (color.red * 255), (int) (color.green * 255), (int) (color.blue * 255)); + } + + /** + * Sets the RGB value for an LED at a specific index on a LED buffer. + * + * @param index the index of the LED to write to + * @param color the color to set + */ + default void setLED(int index, Color8Bit color) { + setRGB(index, color.red, color.green, color.blue); + } +} diff --git a/wpilibj/src/main/java/edu/wpi/first/wpilibj/PneumaticHub.java b/wpilibj/src/main/java/edu/wpi/first/wpilibj/PneumaticHub.java index 32d2ec5aee2..cdfb0cbc2d4 100644 --- a/wpilibj/src/main/java/edu/wpi/first/wpilibj/PneumaticHub.java +++ b/wpilibj/src/main/java/edu/wpi/first/wpilibj/PneumaticHub.java @@ -25,7 +25,7 @@ private static class DataStore implements AutoCloseable { private int m_refCount; private int m_reservedMask; private boolean m_compressorReserved; - public int[] m_oneShotDurMs = new int[PortsJNI.getNumREVPHChannels()]; + public final int[] m_oneShotDurMs = new int[PortsJNI.getNumREVPHChannels()]; private final Object m_reserveLock = new Object(); DataStore(int module) { diff --git a/wpilibj/src/main/java/edu/wpi/first/wpilibj/SPI.java b/wpilibj/src/main/java/edu/wpi/first/wpilibj/SPI.java index 1a3bb345a0f..9278fd81703 100644 --- a/wpilibj/src/main/java/edu/wpi/first/wpilibj/SPI.java +++ b/wpilibj/src/main/java/edu/wpi/first/wpilibj/SPI.java @@ -54,8 +54,7 @@ public enum Mode { } } - private int m_port; - private int m_mode; + private final int m_port; /** * Constructor. @@ -67,8 +66,7 @@ public SPI(Port port) { SPIJNI.spiInitialize(m_port); - m_mode = 0; - SPIJNI.spiSetMode(m_port, m_mode); + SPIJNI.spiSetMode(m_port, 0); HAL.report(tResourceType.kResourceType_SPI, port.value + 1); } @@ -115,8 +113,7 @@ public final void setClockRate(int hz) { * @param mode The mode to set. */ public final void setMode(Mode mode) { - m_mode = mode.value & 0x3; - SPIJNI.spiSetMode(m_port, m_mode); + SPIJNI.spiSetMode(m_port, mode.value & 0x3); } /** Configure the chip select line to be active high. */ diff --git a/wpilibj/src/main/java/edu/wpi/first/wpilibj/Ultrasonic.java b/wpilibj/src/main/java/edu/wpi/first/wpilibj/Ultrasonic.java index a7b5e71b56e..14103544ce3 100644 --- a/wpilibj/src/main/java/edu/wpi/first/wpilibj/Ultrasonic.java +++ b/wpilibj/src/main/java/edu/wpi/first/wpilibj/Ultrasonic.java @@ -44,7 +44,9 @@ public class Ultrasonic implements Sendable, AutoCloseable { private static Thread m_task; private static int m_instances; + @SuppressWarnings("PMD.SingularField") private SimDevice m_simDevice; + private SimBoolean m_simRangeValid; private SimDouble m_simRange; @@ -57,7 +59,7 @@ public class Ultrasonic implements Sendable, AutoCloseable { * certainly break. Make sure to disable automatic mode before changing anything with the * sensors!! */ - private static class UltrasonicChecker extends Thread { + private static final class UltrasonicChecker extends Thread { @Override public synchronized void run() { while (m_automaticEnabled) { diff --git a/wpilibj/src/main/java/edu/wpi/first/wpilibj/event/EventLoop.java b/wpilibj/src/main/java/edu/wpi/first/wpilibj/event/EventLoop.java index 38d21cd990a..2cbb3afd68f 100644 --- a/wpilibj/src/main/java/edu/wpi/first/wpilibj/event/EventLoop.java +++ b/wpilibj/src/main/java/edu/wpi/first/wpilibj/event/EventLoop.java @@ -31,6 +31,7 @@ public void bind(Runnable action) { } /** Poll all bindings. */ + @SuppressWarnings("PMD.UnusedAssignment") public void poll() { try { m_running = true; diff --git a/wpilibj/src/main/java/edu/wpi/first/wpilibj/livewindow/LiveWindow.java b/wpilibj/src/main/java/edu/wpi/first/wpilibj/livewindow/LiveWindow.java index 1b9d1ea24a6..ecb0e89f22a 100644 --- a/wpilibj/src/main/java/edu/wpi/first/wpilibj/livewindow/LiveWindow.java +++ b/wpilibj/src/main/java/edu/wpi/first/wpilibj/livewindow/LiveWindow.java @@ -17,7 +17,7 @@ * The LiveWindow class is the public interface for putting sensors and actuators on the LiveWindow. */ public final class LiveWindow { - private static class Component implements AutoCloseable { + private static final class Component implements AutoCloseable { @Override public void close() { if (m_namePub != null) { diff --git a/wpilibj/src/main/java/edu/wpi/first/wpilibj/simulation/XboxControllerSim.java b/wpilibj/src/main/java/edu/wpi/first/wpilibj/simulation/XboxControllerSim.java deleted file mode 100644 index 37e0bda32d8..00000000000 --- a/wpilibj/src/main/java/edu/wpi/first/wpilibj/simulation/XboxControllerSim.java +++ /dev/null @@ -1,180 +0,0 @@ -// Copyright (c) FIRST and other WPILib contributors. -// Open Source Software; you can modify and/or share it under the terms of -// the WPILib BSD license file in the root directory of this project. - -package edu.wpi.first.wpilibj.simulation; - -import edu.wpi.first.wpilibj.XboxController; - -/** Class to control a simulated Xbox 360 or Xbox One controller. */ -public class XboxControllerSim extends GenericHIDSim { - /** - * Constructs from a XboxController object. - * - * @param joystick controller to simulate - */ - @SuppressWarnings("this-escape") - public XboxControllerSim(XboxController joystick) { - super(joystick); - setAxisCount(6); - setButtonCount(10); - setPOVCount(1); - } - - /** - * Constructs from a joystick port number. - * - * @param port port number - */ - @SuppressWarnings("this-escape") - public XboxControllerSim(int port) { - super(port); - setAxisCount(6); - setButtonCount(10); - setPOVCount(1); - } - - /** - * Change the left X value of the joystick. - * - * @param value the new value - */ - public void setLeftX(double value) { - setRawAxis(XboxController.Axis.kLeftX.value, value); - } - - /** - * Change the right X value of the joystick. - * - * @param value the new value - */ - public void setRightX(double value) { - setRawAxis(XboxController.Axis.kRightX.value, value); - } - - /** - * Change the left Y value of the joystick. - * - * @param value the new value - */ - public void setLeftY(double value) { - setRawAxis(XboxController.Axis.kLeftY.value, value); - } - - /** - * Change the right Y value of the joystick. - * - * @param value the new value - */ - public void setRightY(double value) { - setRawAxis(XboxController.Axis.kRightY.value, value); - } - - /** - * Change the value of the left trigger axis on the joystick. - * - * @param value the new value - */ - public void setLeftTriggerAxis(double value) { - setRawAxis(XboxController.Axis.kLeftTrigger.value, value); - } - - /** - * Change the value of the right trigger axis on the joystick. - * - * @param value the new value - */ - public void setRightTriggerAxis(double value) { - setRawAxis(XboxController.Axis.kRightTrigger.value, value); - } - - /** - * Change the value of the left bumper on the joystick. - * - * @param state the new value - */ - public void setLeftBumper(boolean state) { - setRawButton(XboxController.Button.kLeftBumper.value, state); - } - - /** - * Change the value of the right bumper on the joystick. - * - * @param state the new value - */ - public void setRightBumper(boolean state) { - setRawButton(XboxController.Button.kRightBumper.value, state); - } - - /** - * Change the value of the left stick button on the joystick. - * - * @param state the new value - */ - public void setLeftStickButton(boolean state) { - setRawButton(XboxController.Button.kLeftStick.value, state); - } - - /** - * Change the value of the right stick button on the joystick. - * - * @param state the new value - */ - public void setRightStickButton(boolean state) { - setRawButton(XboxController.Button.kRightStick.value, state); - } - - /** - * Change the value of the A button. - * - * @param state the new value - */ - public void setAButton(boolean state) { - setRawButton(XboxController.Button.kA.value, state); - } - - /** - * Change the value of the B button. - * - * @param state the new value - */ - public void setBButton(boolean state) { - setRawButton(XboxController.Button.kB.value, state); - } - - /** - * Change the value of the X button. - * - * @param state the new value - */ - public void setXButton(boolean state) { - setRawButton(XboxController.Button.kX.value, state); - } - - /** - * Change the value of the Y button. - * - * @param state the new value - */ - public void setYButton(boolean state) { - setRawButton(XboxController.Button.kY.value, state); - } - - /** - * Change the value of the Back button. - * - * @param state the new value - */ - public void setBackButton(boolean state) { - setRawButton(XboxController.Button.kBack.value, state); - } - - /** - * Change the value of the Start button. - * - * @param state the new value - */ - public void setStartButton(boolean state) { - setRawButton(XboxController.Button.kStart.value, state); - } -} diff --git a/wpilibj/src/main/java/edu/wpi/first/wpilibj/smartdashboard/SendableBuilderImpl.java b/wpilibj/src/main/java/edu/wpi/first/wpilibj/smartdashboard/SendableBuilderImpl.java index f15198fd102..2f288910744 100644 --- a/wpilibj/src/main/java/edu/wpi/first/wpilibj/smartdashboard/SendableBuilderImpl.java +++ b/wpilibj/src/main/java/edu/wpi/first/wpilibj/smartdashboard/SendableBuilderImpl.java @@ -65,7 +65,7 @@ private interface TimedConsumer { void accept(T value, long time); } - private static class Property

+ private static final class Property

implements AutoCloseable { @Override @SuppressWarnings("PMD.AvoidCatchingGenericException") diff --git a/wpilibj/src/main/java/edu/wpi/first/wpilibj/sysid/SysIdRoutineLog.java b/wpilibj/src/main/java/edu/wpi/first/wpilibj/sysid/SysIdRoutineLog.java index a8d7d940e8d..cbc6991fd35 100644 --- a/wpilibj/src/main/java/edu/wpi/first/wpilibj/sysid/SysIdRoutineLog.java +++ b/wpilibj/src/main/java/edu/wpi/first/wpilibj/sysid/SysIdRoutineLog.java @@ -72,7 +72,7 @@ public String toString() { } /** Logs data from a single motor during a SysIdRoutine. */ - public class MotorLog { + public final class MotorLog { private final String m_motorName; /** diff --git a/wpilibj/src/main/java/edu/wpi/first/wpilibj/util/Color.java b/wpilibj/src/main/java/edu/wpi/first/wpilibj/util/Color.java index c7c441daf74..0653367ca9f 100644 --- a/wpilibj/src/main/java/edu/wpi/first/wpilibj/util/Color.java +++ b/wpilibj/src/main/java/edu/wpi/first/wpilibj/util/Color.java @@ -105,35 +105,11 @@ public Color(String hexString) { * @return The color */ public static Color fromHSV(int h, int s, int v) { - // Loosely based on - // https://en.wikipedia.org/wiki/HSL_and_HSV#HSV_to_RGB - // The hue range is split into 60 degree regions where in each region there - // is one rgb component at a low value (m), one at a high value (v) and one - // that changes (X) from low to high (X+m) or high to low (v-X) - - // Difference between highest and lowest value of any rgb component - final int chroma = (s * v) / 255; - - // Because hue is 0-180 rather than 0-360 use 30 not 60 - final int region = (h / 30) % 6; - - // Remainder converted from 0-30 to 0-255 - final int remainder = (int) Math.round((h % 30) * (255 / 30.0)); - - // Value of the lowest rgb component - final int m = v - chroma; - - // Goes from 0 to chroma as hue increases - final int X = (chroma * remainder) >> 8; - - return switch (region) { - case 0 -> new Color(v, X + m, m); - case 1 -> new Color(v - X, v, m); - case 2 -> new Color(m, v, X + m); - case 3 -> new Color(m, v - X, v); - case 4 -> new Color(X + m, m, v); - default -> new Color(v, m, v - X); - }; + int rgb = hsvToRgb(h, s, v); + return new Color( + unpackRGB(rgb, RGBChannel.kRed), + unpackRGB(rgb, RGBChannel.kGreen), + unpackRGB(rgb, RGBChannel.kBlue)); } @Override @@ -179,6 +155,184 @@ private static double roundAndClamp(double value) { return MathUtil.clamp(Math.ceil(value * (1 << 12)) / (1 << 12), 0.0, 1.0); } + // Helper methods + + /** + * Converts HSV values to RGB values. The returned RGB color is packed into a 32-bit integer for + * memory performance reasons. + * + * @param h The h value [0-180) + * @param s The s value [0-255] + * @param v The v value [0-255] + * @return the packed RGB color + */ + public static int hsvToRgb(int h, int s, int v) { + // Loosely based on + // https://en.wikipedia.org/wiki/HSL_and_HSV#HSV_to_RGB + // The hue range is split into 60 degree regions where in each region there + // is one rgb component at a low value (m), one at a high value (v) and one + // that changes (X) from low to high (X+m) or high to low (v-X) + + // Difference between highest and lowest value of any rgb component + final int chroma = (s * v) / 255; + + // Because hue is 0-180 rather than 0-360 use 30 not 60 + final int region = (h / 30) % 6; + + // Remainder converted from 0-30 to 0-255 + final int remainder = (int) Math.round((h % 30) * (255 / 30.0)); + + // Value of the lowest rgb component + final int m = v - chroma; + + // Goes from 0 to chroma as hue increases + final int X = (chroma * remainder) >> 8; + + int red; + int green; + int blue; + switch (region) { + case 0: + red = v; + green = X + m; + blue = m; + break; + case 1: + red = v - X; + green = v; + blue = m; + break; + case 2: + red = m; + green = v; + blue = X + m; + break; + case 3: + red = m; + green = v - X; + blue = v; + break; + case 4: + red = X + m; + green = m; + blue = v; + break; + default: + red = v; + green = m; + blue = v - X; + break; + } + return packRGB(red, green, blue); + } + + /** Represents a color channel in an RGB color. */ + public enum RGBChannel { + /** The red channel of an RGB color. */ + kRed, + /** The green channel of an RGB color. */ + kGreen, + /** The blue channel of an RGB color. */ + kBlue + } + + /** + * Packs 3 RGB values into a single 32-bit integer. These values can be unpacked with {@link + * #unpackRGB(int, RGBChannel)} to retrieve the values. This is helpful for avoiding memory + * allocations of new {@code Color} objects and its resulting garbage collector pressure. + * + * @param r the value of the first channel to pack + * @param g the value of the second channel to pack + * @param b the value of the third channel to pack + * @return the packed integer + */ + public static int packRGB(int r, int g, int b) { + return (r & 0xFF) << 16 | (g & 0xFF) << 8 | (b & 0xFF); + } + + /** + * Unpacks a single color channel from a packed 32-bit RGB integer. + * + *

Note: Packed RGB colors are expected to be in byte order [empty][red][green][blue]. + * + * @param packedColor the packed color to extract from + * @param channel the color channel to unpack + * @return the value of the stored color channel + */ + public static int unpackRGB(int packedColor, RGBChannel channel) { + return switch (channel) { + case kRed -> (packedColor >> 16) & 0xFF; + case kGreen -> (packedColor >> 8) & 0xFF; + case kBlue -> packedColor & 0xFF; + }; + } + + /** + * Performs a linear interpolation between two colors in the RGB colorspace. + * + * @param a the first color to interpolate from + * @param b the second color to interpolate from + * @param t the interpolation scale in [0, 1] + * @return the interpolated color + */ + public static Color lerpRGB(Color a, Color b, double t) { + int packedRGB = lerpRGB(a.red, a.green, a.blue, b.red, b.green, b.blue, t); + + return new Color( + unpackRGB(packedRGB, RGBChannel.kRed), + unpackRGB(packedRGB, RGBChannel.kGreen), + unpackRGB(packedRGB, RGBChannel.kBlue)); + } + + /** + * Linearly interpolates between two RGB colors represented by the (r1, g1, b1) and (r2, g2, b2) + * triplets. For memory performance reasons, the output color is returned packed into a single + * 32-bit integer; use {@link #unpackRGB(int, RGBChannel)} to extract the values for the + * individual red, green, and blue channels. + * + * @param r1 the red value of the first color, in [0, 1] + * @param g1 the green value of the first color, in [0, 1] + * @param b1 the blue value of the first color, in [0, 1] + * @param r2 the red value of the second color, in [0, 1] + * @param g2 the green value of the second color, in [0, 1] + * @param b2 the blue value of the second color, in [0, 1] + * @param t the interpolation value, in [0, 1] + * @return the interpolated color, packed in a 32-bit integer + */ + public static int lerpRGB( + double r1, double g1, double b1, double r2, double g2, double b2, double t) { + return lerpRGB( + (int) (r1 * 255), + (int) (g1 * 255), + (int) (b1 * 255), + (int) (r2 * 255), + (int) (g2 * 255), + (int) (b2 * 255), + t); + } + + /** + * Linearly interpolates between two RGB colors represented by the (r1, g1, b1) and (r2, g2, b2) + * triplets. For memory performance reasons, the output color is returned packed into a single + * 32-bit integer; use {@link #unpackRGB(int, RGBChannel)} to extract the values for the + * individual red, green, and blue channels. + * + * @param r1 the red value of the first color, in [0, 255] + * @param g1 the green value of the first color, in [0, 255] + * @param b1 the blue value of the first color, in [0, 255] + * @param r2 the red value of the second color, in [0, 255] + * @param g2 the green value of the second color, in [0, 255] + * @param b2 the blue value of the second color, in [0, 255] + * @param t the interpolation value, in [0, 1] + * @return the interpolated color, packed in a 32-bit integer + */ + public static int lerpRGB(int r1, int g1, int b1, int r2, int g2, int b2, double t) { + return packRGB( + (int) MathUtil.interpolate(r1, r2, t), + (int) MathUtil.interpolate(g1, g2, t), + (int) MathUtil.interpolate(b1, b2, t)); + } + /* * FIRST Colors */ diff --git a/wpilibj/src/test/java/edu/wpi/first/wpilibj/AddressableLEDBufferViewTest.java b/wpilibj/src/test/java/edu/wpi/first/wpilibj/AddressableLEDBufferViewTest.java new file mode 100644 index 00000000000..9ec78fdc6ff --- /dev/null +++ b/wpilibj/src/test/java/edu/wpi/first/wpilibj/AddressableLEDBufferViewTest.java @@ -0,0 +1,69 @@ +// Copyright (c) FIRST and other WPILib contributors. +// Open Source Software; you can modify and/or share it under the terms of +// the WPILib BSD license file in the root directory of this project. + +package edu.wpi.first.wpilibj; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +import edu.wpi.first.wpilibj.util.Color; +import org.junit.jupiter.api.Test; + +class AddressableLEDBufferViewTest { + @Test + void singleLED() { + var buffer = new AddressableLEDBuffer(10); + var view = new AddressableLEDBufferView(buffer, 5, 5); + var color = Color.kAqua; + view.setLED(0, color); + assertEquals(color, buffer.getLED(5)); + assertEquals(color, view.getLED(0)); + } + + @Test + void segment() { + var buffer = new AddressableLEDBuffer(10); + var view = new AddressableLEDBufferView(buffer, 2, 8); + view.setLED(0, Color.kAqua); + assertEquals(Color.kAqua, buffer.getLED(2)); + + view.setLED(6, Color.kAzure); + assertEquals(Color.kAzure, buffer.getLED(8)); + } + + @Test + void manualReversed() { + var buffer = new AddressableLEDBuffer(10); + var view = new AddressableLEDBufferView(buffer, 8, 2); + + // LED 0 in the view should write to LED 8 on the real buffer + view.setLED(0, Color.kAqua); + assertEquals(Color.kAqua, buffer.getLED(8)); + + // .. and LED 6 in the view should write to LED 2 on the real buffer + view.setLED(6, Color.kAzure); + assertEquals(Color.kAzure, buffer.getLED(2)); + } + + @Test + void fullManualReversed() { + var buffer = new AddressableLEDBuffer(10); + var view = new AddressableLEDBufferView(buffer, 9, 0); + view.setLED(0, Color.kWhite); + assertEquals(Color.kWhite, buffer.getLED(9)); + + buffer.setLED(8, Color.kRed); + assertEquals(Color.kRed, view.getLED(1)); + } + + @Test + void reversed() { + var buffer = new AddressableLEDBuffer(10); + var view = new AddressableLEDBufferView(buffer, 0, 9).reversed(); + view.setLED(0, Color.kWhite); + assertEquals(Color.kWhite, buffer.getLED(9)); + + view.setLED(9, Color.kRed); + assertEquals(Color.kRed, buffer.getLED(0)); + } +} diff --git a/wpilibj/src/test/java/edu/wpi/first/wpilibj/LEDPatternTest.java b/wpilibj/src/test/java/edu/wpi/first/wpilibj/LEDPatternTest.java new file mode 100644 index 00000000000..f6d38ed7484 --- /dev/null +++ b/wpilibj/src/test/java/edu/wpi/first/wpilibj/LEDPatternTest.java @@ -0,0 +1,798 @@ +// Copyright (c) FIRST and other WPILib contributors. +// Open Source Software; you can modify and/or share it under the terms of +// the WPILib BSD license file in the root directory of this project. + +package edu.wpi.first.wpilibj; + +import static edu.wpi.first.units.Units.Centimeters; +import static edu.wpi.first.units.Units.MetersPerSecond; +import static edu.wpi.first.units.Units.Microsecond; +import static edu.wpi.first.units.Units.Microseconds; +import static edu.wpi.first.units.Units.Percent; +import static edu.wpi.first.units.Units.Seconds; +import static edu.wpi.first.units.Units.Value; +import static edu.wpi.first.wpilibj.util.Color.kBlack; +import static edu.wpi.first.wpilibj.util.Color.kBlue; +import static edu.wpi.first.wpilibj.util.Color.kLime; +import static edu.wpi.first.wpilibj.util.Color.kMagenta; +import static edu.wpi.first.wpilibj.util.Color.kMidnightBlue; +import static edu.wpi.first.wpilibj.util.Color.kPurple; +import static edu.wpi.first.wpilibj.util.Color.kRed; +import static edu.wpi.first.wpilibj.util.Color.kWhite; +import static edu.wpi.first.wpilibj.util.Color.kYellow; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.fail; + +import edu.wpi.first.util.WPIUtilJNI; +import edu.wpi.first.wpilibj.util.Color; +import edu.wpi.first.wpilibj.util.Color8Bit; +import java.util.Map; +import java.util.concurrent.atomic.AtomicBoolean; +import java.util.concurrent.atomic.AtomicReference; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +class LEDPatternTest { + // Applies a pattern of White, Yellow, Purple to LED triplets + LEDPattern m_whiteYellowPurple = + (reader, writer) -> { + for (int led = 0; led < reader.getLength(); led++) { + switch (led % 3) { + case 0: + writer.setLED(led, kWhite); + break; + case 1: + writer.setLED(led, kYellow); + break; + case 2: + writer.setLED(led, kPurple); + break; + default: + fail("Bad test setup"); + break; + } + } + }; + + @BeforeEach + void setUp() { + WPIUtilJNI.enableMockTime(); + WPIUtilJNI.setMockTime(0L); + } + + @AfterEach + void tearDown() { + WPIUtilJNI.setMockTime(0L); + WPIUtilJNI.disableMockTime(); + } + + @Test + void solidColor() { + LEDPattern pattern = LEDPattern.solid(kYellow); + AddressableLEDBuffer buffer = new AddressableLEDBuffer(99); + pattern.applyTo(buffer); + + for (int i = 0; i < buffer.getLength(); i++) { + assertEquals(kYellow, buffer.getLED(i)); + } + } + + @Test + void gradient0SetsToBlack() { + LEDPattern pattern = LEDPattern.gradient(); + AddressableLEDBuffer buffer = new AddressableLEDBuffer(99); + for (int i = 0; i < buffer.getLength(); i++) { + buffer.setRGB(i, 127, 128, 129); + } + + pattern.applyTo(buffer); + + for (int i = 0; i < buffer.getLength(); i++) { + assertEquals(kBlack, buffer.getLED(i)); + } + } + + @Test + void gradient1SetsToSolid() { + LEDPattern pattern = LEDPattern.gradient(kYellow); + + AddressableLEDBuffer buffer = new AddressableLEDBuffer(99); + pattern.applyTo(buffer); + + for (int i = 0; i < buffer.getLength(); i++) { + assertEquals(kYellow, buffer.getLED(i)); + } + } + + @Test + void gradient2Colors() { + LEDPattern pattern = LEDPattern.gradient(kYellow, kPurple); + + AddressableLEDBuffer buffer = new AddressableLEDBuffer(99); + pattern.applyTo(buffer); + + assertColorEquals(kYellow, buffer.getLED(0)); + assertColorEquals(Color.lerpRGB(kYellow, kPurple, 25 / 49.0), buffer.getLED(25)); + assertColorEquals(kPurple, buffer.getLED(49)); + assertColorEquals(Color.lerpRGB(kYellow, kPurple, 25 / 49.0), buffer.getLED(73)); + assertColorEquals(kYellow, buffer.getLED(98)); + } + + @Test + void gradient3Colors() { + LEDPattern pattern = LEDPattern.gradient(kYellow, kPurple, kWhite); + AddressableLEDBuffer buffer = new AddressableLEDBuffer(99); + pattern.applyTo(buffer); + + assertColorEquals(kYellow, buffer.getLED(0)); + assertColorEquals(Color.lerpRGB(kYellow, kPurple, 25.0 / 33.0), buffer.getLED(25)); + assertColorEquals(kPurple, buffer.getLED(33)); + assertColorEquals(Color.lerpRGB(kPurple, kWhite, 25.0 / 33.0), buffer.getLED(58)); + assertColorEquals(kWhite, buffer.getLED(66)); + assertColorEquals(Color.lerpRGB(kWhite, kYellow, 25.0 / 33.0), buffer.getLED(91)); + assertColorEquals(Color.lerpRGB(kWhite, kYellow, 32.0 / 33.0), buffer.getLED(98)); + } + + @Test + void step0SetsToBlack() { + LEDPattern pattern = LEDPattern.steps(Map.of()); + + AddressableLEDBuffer buffer = new AddressableLEDBuffer(99); + for (int i = 0; i < buffer.getLength(); i++) { + buffer.setRGB(i, 127, 128, 129); + } + + pattern.applyTo(buffer); + for (int i = 0; i < 99; i++) { + assertColorEquals(kBlack, buffer.getLED(i)); + } + } + + @Test + void step1SetsToSolid() { + LEDPattern pattern = LEDPattern.steps(Map.of(0.0, kYellow)); + + AddressableLEDBuffer buffer = new AddressableLEDBuffer(99); + + pattern.applyTo(buffer); + for (int i = 0; i < 99; i++) { + assertColorEquals(kYellow, buffer.getLED(i)); + } + } + + @Test + void step1HalfSetsToHalfOffHalfColor() { + LEDPattern pattern = LEDPattern.steps(Map.of(0.50, kYellow)); + + AddressableLEDBuffer buffer = new AddressableLEDBuffer(99); + pattern.applyTo(buffer); + + // [0, 48] should be black... + for (int i = 0; i < 49; i++) { + assertColorEquals(kBlack, buffer.getLED(i)); + } + // ... and [49, ] should be the color that was set + for (int i = 49; i < buffer.getLength(); i++) { + assertColorEquals(kYellow, buffer.getLED(i)); + } + } + + @Test + void scrollForward() { + var buffer = new AddressableLEDBuffer(256); + + LEDPattern base = + (reader, writer) -> { + for (int led = 0; led < reader.getLength(); led++) { + writer.setRGB(led, led % 256, led % 256, led % 256); + } + }; + + // scroll forwards 1/256th (1 LED) per microsecond - this makes mock time easier + var scroll = base.scrollAtRelativeSpeed(Value.per(Microsecond).of(1 / 256.0)); + + for (int time = 0; time < 500; time++) { + WPIUtilJNI.setMockTime(time); + scroll.applyTo(buffer); + + for (int led = 0; led < buffer.getLength(); led++) { + // Base: [(0, 0, 0) (1, 1, 1) (2, 2, 2) (3, 3, 3) (4, 4, 4) ... (255, 255, 255)] + // Value for every channel should DECREASE by 1 in each timestep, wrapping around 0 and 255 + + // t=0, channel value = (0, 1, 2, ..., 254, 255) + // t=1, channel value = (255, 0, 1, ..., 253, 254) + // t=2, channel value = (254, 255, 0, ..., 252, 253) + // t=255, channel value = (1, 2, 3, ..., 255, 0) + // t=256, channel value = (0, 1, 2, ..., 254, 255) + int ch = Math.floorMod(led - time, 256); + + assertEquals(new Color8Bit(ch, ch, ch), buffer.getLED8Bit(led)); + } + } + } + + @Test + void scrollBackward() { + var buffer = new AddressableLEDBuffer(256); + + LEDPattern base = + (reader, writer) -> { + for (int led = 0; led < reader.getLength(); led++) { + writer.setRGB(led, led % 256, led % 256, led % 256); + } + }; + + // scroll backwards 1/256th (1 LED) per microsecond - this makes mock time easier + var scroll = base.scrollAtRelativeSpeed(Value.per(Microsecond).of(-1 / 256.0)); + + for (int time = 0; time < 500; time++) { + WPIUtilJNI.setMockTime(time); + scroll.applyTo(buffer); + + for (int led = 0; led < buffer.getLength(); led++) { + // Base: [(0, 0, 0) (1, 1, 1) (2, 2, 2) (3, 3, 3) (4, 4, 4) ... (255, 255, 255)] + // Value for every channel should INCREASE by 1 in each timestep, wrapping around 0 and 255 + + // t=0, channel value = (0, 1, 2, ..., 254, 255) + // t=1, channel value = (1, 2, 3, ..., 255, 0) + // t=2, channel value = (2, 3, 4, ..., 0, 1) + // t=255, channel value = (255, 0, 1, ..., 253, 254) + // t=256, channel value = (0, 1, 2, ..., 254, 255) + int ch = Math.floorMod(led + time, 256); + + assertEquals(new Color8Bit(ch, ch, ch), buffer.getLED8Bit(led)); + } + } + } + + @Test + void scrollAbsoluteSpeedForward() { + var buffer = new AddressableLEDBuffer(256); + + LEDPattern base = + (reader, writer) -> { + for (int led = 0; led < reader.getLength(); led++) { + writer.setRGB(led, led % 256, led % 256, led % 256); + } + }; + + // scroll at 16 m/s, LED spacing = 2cm + // buffer is 256 LEDs, so total length = 512cm = 5.12m + // scrolling at 16 m/s yields a period of 0.32 seconds, or 0.00125 seconds per LED (800 LEDs/s) + var scroll = base.scrollAtAbsoluteSpeed(MetersPerSecond.of(16), Centimeters.of(2)); + + for (int time = 0; time < 500; time++) { + WPIUtilJNI.setMockTime(time * 1_250); // 1.25ms per LED + scroll.applyTo(buffer); + + for (int led = 0; led < buffer.getLength(); led++) { + // Base: [(0, 0, 0) (1, 1, 1) (2, 2, 2) (3, 3, 3) (4, 4, 4) ... (255, 255, 255)] + // Value for every channel should DECREASE by 1 in each timestep, wrapping around 0 and 255 + + // t=0, channel value = (0, 1, 2, ..., 254, 255) + // t=1, channel value = (255, 0, 1, ..., 253, 254) + // t=2, channel value = (254, 255, 0, ..., 252, 253) + // t=255, channel value = (1, 2, 3, ..., 255, 0) + // t=256, channel value = (0, 1, 2, ..., 254, 255) + int ch = Math.floorMod(led - time, 256); + + assertEquals(new Color8Bit(ch, ch, ch), buffer.getLED8Bit(led)); + } + } + } + + @Test + void scrollAbsoluteSpeedBackward() { + var buffer = new AddressableLEDBuffer(256); + + LEDPattern base = + (reader, writer) -> { + for (int led = 0; led < reader.getLength(); led++) { + writer.setRGB(led, led % 256, led % 256, led % 256); + } + }; + + // scroll at 16 m/s, LED spacing = 2cm + // buffer is 256 LEDs, so total length = 512cm = 5.12m + // scrolling at 16 m/s yields a period of 0.32 seconds, or 0.00125 seconds per LED (800 LEDs/s) + var scroll = base.scrollAtAbsoluteSpeed(MetersPerSecond.of(-16), Centimeters.of(2)); + + for (int time = 0; time < 500; time++) { + WPIUtilJNI.setMockTime(time * 1_250); // 1.25ms per LED + scroll.applyTo(buffer); + + for (int led = 0; led < buffer.getLength(); led++) { + // Base: [(0, 0, 0) (1, 1, 1) (2, 2, 2) (3, 3, 3) (4, 4, 4) ... (255, 255, 255)] + // Value for every channel should DECREASE by 1 in each timestep, wrapping around 0 and 255 + + // t=0, channel value = (0, 1, 2, ..., 254, 255) + // t=1, channel value = (255, 0, 1, ..., 253, 254) + // t=2, channel value = (254, 255, 0, ..., 252, 253) + // t=255, channel value = (1, 2, 3, ..., 255, 0) + // t=256, channel value = (0, 1, 2, ..., 254, 255) + int ch = Math.floorMod(led + time, 256); + + assertEquals(new Color8Bit(ch, ch, ch), buffer.getLED8Bit(led)); + } + } + } + + @Test + void rainbowAtFullSize() { + var buffer = new AddressableLEDBuffer(180); + + int saturation = 255; + int value = 255; + var pattern = LEDPattern.rainbow(saturation, value); + + pattern.applyTo(buffer); + + for (int led = 0; led < buffer.getLength(); led++) { + assertColorEquals(Color.fromHSV(led, saturation, value), buffer.getLED(led)); + } + } + + @Test + void rainbowAtHalfSize() { + var buffer = new AddressableLEDBuffer(90); + + int saturation = 42; + int value = 87; + var pattern = LEDPattern.rainbow(saturation, value); + + pattern.applyTo(buffer); + + for (int led = 0; led < buffer.getLength(); led++) { + assertColorEquals(Color.fromHSV(led * 2, saturation, value), buffer.getLED(led)); + } + } + + @Test + void rainbowAtOneThirdSize() { + var buffer = new AddressableLEDBuffer(60); + + int saturation = 191; + int value = 255; + var pattern = LEDPattern.rainbow(saturation, value); + + pattern.applyTo(buffer); + + for (int led = 0; led < buffer.getLength(); led++) { + assertColorEquals(Color.fromHSV(led * 3, saturation, value), buffer.getLED(led)); + } + } + + @Test + void rainbowAtDoubleSize() { + var buffer = new AddressableLEDBuffer(360); + + int saturation = 212; + int value = 93; + var pattern = LEDPattern.rainbow(saturation, value); + + pattern.applyTo(buffer); + + for (int led = 0; led < buffer.getLength(); led++) { + assertColorEquals(Color.fromHSV(led / 2, saturation, value), buffer.getLED(led)); + } + } + + @Test + void rainbowOddSize() { + var buffer = new AddressableLEDBuffer(127); + double scale = 180.0 / buffer.getLength(); + + int saturation = 73; + int value = 128; + var pattern = LEDPattern.rainbow(saturation, value); + + pattern.applyTo(buffer); + + for (int led = 0; led < buffer.getLength(); led++) { + assertColorEquals(Color.fromHSV((int) (led * scale), saturation, value), buffer.getLED(led)); + } + } + + @Test + void reverseSolid() { + var buffer = new AddressableLEDBuffer(90); + + var pattern = LEDPattern.solid(Color.kRosyBrown).reversed(); + pattern.applyTo(buffer); + + for (int led = 0; led < buffer.getLength(); led++) { + assertColorEquals(Color.kRosyBrown, buffer.getLED(led)); + } + } + + @Test + void reverseSteps() { + var buffer = new AddressableLEDBuffer(100); + + var pattern = LEDPattern.steps(Map.of(0, kWhite, 0.5, kYellow)).reversed(); + pattern.applyTo(buffer); + + // colors should be swapped; yellow first, then white + for (int led = 0; led < buffer.getLength(); led++) { + if (led < 50) { + assertColorEquals(kYellow, buffer.getLED(led)); + } else { + assertColorEquals(kWhite, buffer.getLED(led)); + } + } + } + + @Test + void offsetPositive() { + var buffer = new AddressableLEDBuffer(21); + + // offset repeats PWY + var offset = m_whiteYellowPurple.offsetBy(1); + offset.applyTo(buffer); + + for (int led = 0; led < buffer.getLength(); led++) { + Color color = buffer.getLED(led); + switch (led % 3) { + case 0: + assertColorEquals(kPurple, color); + break; + case 1: + assertColorEquals(kWhite, color); + break; + case 2: + assertColorEquals(kYellow, color); + break; + default: + fail("Bad test setup"); + break; + } + } + } + + @Test + void offsetNegative() { + var buffer = new AddressableLEDBuffer(21); + + // offset repeats YPW + var offset = m_whiteYellowPurple.offsetBy(-1); + offset.applyTo(buffer); + + for (int led = 0; led < buffer.getLength(); led++) { + Color color = buffer.getLED(led); + switch (led % 3) { + case 0: + assertColorEquals(kYellow, color); + break; + case 1: + assertColorEquals(kPurple, color); + break; + case 2: + assertColorEquals(kWhite, color); + break; + default: + fail("Bad test setup"); + break; + } + } + } + + @Test + void offsetZero() { + var buffer = new AddressableLEDBuffer(21); + + // offset copies the base pattern, WYP + var offset = m_whiteYellowPurple.offsetBy(0); + offset.applyTo(buffer); + + for (int led = 0; led < buffer.getLength(); led++) { + Color color = buffer.getLED(led); + switch (led % 3) { + case 0: + assertColorEquals(kWhite, color); + break; + case 1: + assertColorEquals(kYellow, color); + break; + case 2: + assertColorEquals(kPurple, color); + break; + default: + fail("Bad test setup"); + break; + } + } + } + + @Test + void blinkSymmetric() { + // on for 2 seconds, off for 2 seconds + var pattern = LEDPattern.solid(kWhite).blink(Seconds.of(2)); + + var buffer = new AddressableLEDBuffer(1); + + for (int t = 0; t < 8; t++) { + WPIUtilJNI.setMockTime(t * 1_000_000L); // time travel 1 second + pattern.applyTo(buffer); + + Color color = buffer.getLED(0); + switch (t) { + case 0: + case 1: + case 4: + case 5: + assertColorEquals(kWhite, color); + break; + case 2: + case 3: + case 6: + case 7: + assertColorEquals(kBlack, color); + break; + default: + fail("Bad test setup"); + break; + } + } + } + + @Test + void blinkAsymmetric() { + // on for 3 seconds, off for 1 second + var pattern = LEDPattern.solid(kWhite).blink(Seconds.of(3), Seconds.of(1)); + + var buffer = new AddressableLEDBuffer(1); + + for (int t = 0; t < 8; t++) { + WPIUtilJNI.setMockTime(t * 1_000_000L); // time travel 1 second + pattern.applyTo(buffer); + + Color color = buffer.getLED(0); + switch (t) { + case 0: + case 1: + case 2: // first period + case 4: + case 5: + case 6: // second period + assertColorEquals(kWhite, color); + break; + case 3: + case 7: + assertColorEquals(kBlack, color); + break; + default: + fail("Bad test setup"); + break; + } + } + } + + @Test + void blinkInSync() { + AtomicBoolean condition = new AtomicBoolean(false); + var pattern = LEDPattern.solid(kWhite).synchronizedBlink(condition::get); + + var buffer = new AddressableLEDBuffer(1); + + pattern.applyTo(buffer); + assertColorEquals(kBlack, buffer.getLED(0)); + + condition.set(true); + pattern.applyTo(buffer); + assertColorEquals(kWhite, buffer.getLED(0)); + + condition.set(false); + pattern.applyTo(buffer); + assertColorEquals(kBlack, buffer.getLED(0)); + } + + @Test + void breathe() { + final Color midGray = new Color(0.5, 0.5, 0.5); + + var pattern = LEDPattern.solid(kWhite).breathe(Microseconds.of(4)); + + var buffer = new AddressableLEDBuffer(1); + + { + WPIUtilJNI.setMockTime(0); // start + pattern.applyTo(buffer); + assertColorEquals(kWhite, buffer.getLED(0)); + } + + { + WPIUtilJNI.setMockTime(1); // midway (down) + pattern.applyTo(buffer); + assertColorEquals(midGray, buffer.getLED(0)); + } + + { + WPIUtilJNI.setMockTime(2); // bottom + pattern.applyTo(buffer); + assertColorEquals(kBlack, buffer.getLED(0)); + } + + { + WPIUtilJNI.setMockTime(3); // midway (up) + pattern.applyTo(buffer); + assertColorEquals(midGray, buffer.getLED(0)); + } + + { + WPIUtilJNI.setMockTime(4); // back to start + pattern.applyTo(buffer); + assertColorEquals(kWhite, buffer.getLED(0)); + } + } + + @Test + void overlaySolidOnSolid() { + var overlay = LEDPattern.solid(kYellow).overlayOn(LEDPattern.solid(kWhite)); + + var buffer = new AddressableLEDBuffer(1); + overlay.applyTo(buffer); + + assertColorEquals(kYellow, buffer.getLED(0)); + } + + @Test + void overlayNearlyBlack() { + Color overlayColor = new Color(new Color8Bit(1, 0, 0)); + var overlay = LEDPattern.solid(overlayColor).overlayOn(LEDPattern.solid(kWhite)); + + var buffer = new AddressableLEDBuffer(1); + overlay.applyTo(buffer); + + assertColorEquals(overlayColor, buffer.getLED(0)); + } + + @Test + void overlayMixed() { + var overlay = + LEDPattern.steps(Map.of(0, kYellow, 0.5, kBlack)).overlayOn(LEDPattern.solid(kWhite)); + + var buffer = new AddressableLEDBuffer(2); + overlay.applyTo(buffer); + + assertColorEquals(kYellow, buffer.getLED(0)); + assertColorEquals(kWhite, buffer.getLED(1)); + } + + @Test + void blend() { + var pattern1 = LEDPattern.solid(kBlue); + var pattern2 = LEDPattern.solid(kRed); + var blend = pattern1.blend(pattern2); + + var buffer = new AddressableLEDBuffer(1); + blend.applyTo(buffer); + + // Individual RGB channels are averaged; #0000FF blended with #FF0000 yields #7F007F + assertColorEquals(new Color(127, 0, 127), buffer.getLED(0)); + } + + @Test + void binaryMask() { + Color color = new Color(123, 123, 123); + var base = LEDPattern.solid(color); + // first 50% mask on, last 50% mask off + var mask = LEDPattern.steps(Map.of(0, kWhite, 0.5, kBlack)); + var masked = base.mask(mask); + + var buffer = new AddressableLEDBuffer(10); + masked.applyTo(buffer); + + for (int i = 0; i < 5; i++) { + assertColorEquals(color, buffer.getLED(i)); + } + + for (int i = 5; i < 10; i++) { + assertColorEquals(kBlack, buffer.getLED(i)); + } + } + + @Test + void channelwiseMask() { + Color baseColor = new Color(123, 123, 123); + Color halfGray = new Color(0.5, 0.5, 0.5); + var base = LEDPattern.solid(baseColor); + + var mask = + LEDPattern.steps(Map.of(0, kRed, 0.2, kLime, 0.4, kBlue, 0.6, halfGray, 0.8, kWhite)); + + var masked = base.mask(mask); + + var buffer = new AddressableLEDBuffer(5); + masked.applyTo(buffer); + + assertColorEquals(new Color(123, 0, 0), buffer.getLED(0)); // red channel only + assertColorEquals(new Color(0, 123, 0), buffer.getLED(1)); // green channel only + assertColorEquals(new Color(0, 0, 123), buffer.getLED(2)); // blue channel only + + // mask channels are all 0b00111111, base is 0b00111011, + // so the AND should give us the unmodified base color + assertColorEquals(baseColor, buffer.getLED(3)); + assertColorEquals(baseColor, buffer.getLED(4)); // full color allowed + } + + @Test + void progressMaskLayer() { + var progress = new AtomicReference<>(0.0); + var maskLayer = LEDPattern.progressMaskLayer(progress::get); + var buffer = new AddressableLEDBuffer(100); + + for (double t = 0; t <= 1.0; t += 0.01) { + progress.set(t); + maskLayer.applyTo(buffer); + + int lastMaskedLED = (int) (t * 100); + for (int i = 0; i < lastMaskedLED; i++) { + assertColorEquals( + kWhite, + buffer.getLED(i), + "Progress " + lastMaskedLED + "%, LED " + i + " should be WHITE"); + } + + for (int i = lastMaskedLED; i < 100; i++) { + assertColorEquals( + kBlack, + buffer.getLED(i), + "Progress " + lastMaskedLED + "% , LED " + i + " should be BLACK"); + } + } + } + + @Test + void zeroBrightness() { + var pattern = LEDPattern.solid(kRed).atBrightness(Percent.zero()); + var buffer = new AddressableLEDBuffer(1); + pattern.applyTo(buffer); + + assertColorEquals(kBlack, buffer.getLED(0)); + } + + @Test + void sameBrightness() { + var pattern = LEDPattern.solid(kMagenta).atBrightness(Percent.of(100)); + var buffer = new AddressableLEDBuffer(1); + pattern.applyTo(buffer); + + assertColorEquals(kMagenta, buffer.getLED(0)); + } + + @Test + void higherBrightness() { + var pattern = LEDPattern.solid(kMagenta).atBrightness(Value.of(4 / 3.0)); + var buffer = new AddressableLEDBuffer(1); + pattern.applyTo(buffer); + + assertColorEquals(kMagenta, buffer.getLED(0)); + } + + @Test + void negativeBrightness() { + var pattern = LEDPattern.solid(kWhite).atBrightness(Percent.of(-1000)); + var buffer = new AddressableLEDBuffer(1); + pattern.applyTo(buffer); + + assertColorEquals(kBlack, buffer.getLED(0)); + } + + @Test + void clippingBrightness() { + var pattern = LEDPattern.solid(kMidnightBlue).atBrightness(Percent.of(10000)); + var buffer = new AddressableLEDBuffer(1); + pattern.applyTo(buffer); + + assertColorEquals(kWhite, buffer.getLED(0)); + } + + void assertColorEquals(Color expected, Color actual) { + assertEquals(new Color8Bit(expected), new Color8Bit(actual)); + } + + void assertColorEquals(Color expected, Color actual, String message) { + assertEquals(new Color8Bit(expected), new Color8Bit(actual), message); + } +} diff --git a/wpilibj/src/test/java/edu/wpi/first/wpilibj/util/ColorTest.java b/wpilibj/src/test/java/edu/wpi/first/wpilibj/util/ColorTest.java index 1b32afdaa9d..76901c2f403 100644 --- a/wpilibj/src/test/java/edu/wpi/first/wpilibj/util/ColorTest.java +++ b/wpilibj/src/test/java/edu/wpi/first/wpilibj/util/ColorTest.java @@ -4,10 +4,16 @@ package edu.wpi.first.wpilibj.util; +import static org.junit.jupiter.api.Assertions.assertAll; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.params.provider.Arguments.arguments; +import java.util.stream.Stream; import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.Arguments; +import org.junit.jupiter.params.provider.MethodSource; class ColorTest { @Test @@ -82,4 +88,39 @@ void testToHexString() { assertEquals("#FF8040", color.toHexString()); assertEquals("#FF8040", color.toString()); } + + @ParameterizedTest + @MethodSource("hsvToRgbProvider") + void hsvToRgb(int h, int s, int v, int r, int g, int b) { + int rgb = Color.hsvToRgb(h, s, v); + int R = Color.unpackRGB(rgb, Color.RGBChannel.kRed); + int G = Color.unpackRGB(rgb, Color.RGBChannel.kGreen); + int B = Color.unpackRGB(rgb, Color.RGBChannel.kBlue); + + assertAll( + () -> assertEquals(r, R, "R value didn't match"), + () -> assertEquals(g, G, "G value didn't match"), + () -> assertEquals(b, B, "B value didn't match")); + } + + private static Stream hsvToRgbProvider() { + return Stream.of( + arguments(0, 0, 0, 0, 0, 0), // Black + arguments(0, 0, 255, 255, 255, 255), // White + arguments(0, 255, 255, 255, 0, 0), // Red + arguments(60, 255, 255, 0, 255, 0), // Lime + arguments(120, 255, 255, 0, 0, 255), // Blue + arguments(30, 255, 255, 255, 255, 0), // Yellow + arguments(90, 255, 255, 0, 255, 255), // Cyan + arguments(150, 255, 255, 255, 0, 255), // Magenta + arguments(0, 0, 191, 191, 191, 191), // Silver + arguments(0, 0, 128, 128, 128, 128), // Gray + arguments(0, 255, 128, 128, 0, 0), // Maroon + arguments(30, 255, 128, 128, 128, 0), // Olive + arguments(60, 255, 128, 0, 128, 0), // Green + arguments(150, 255, 128, 128, 0, 128), // Purple + arguments(90, 255, 128, 0, 128, 128), // Teal + arguments(120, 255, 128, 0, 0, 128) // Navy + ); + } } diff --git a/wpilibjExamples/build.gradle b/wpilibjExamples/build.gradle index 4caafc2571e..37b6d95cc95 100644 --- a/wpilibjExamples/build.gradle +++ b/wpilibjExamples/build.gradle @@ -154,9 +154,6 @@ model { commandLine it.tasks.install.runScriptFile.get().asFile.toString() test.dependsOn it.tasks.install test.systemProperty 'java.library.path', filePath - test.environment 'LD_LIBRARY_PATH', filePath - test.environment 'DYLD_LIBRARY_PATH', filePath - test.workingDir filePath } new groovy.json.JsonSlurper().parseText(exampleFile.text).each { entry -> @@ -166,9 +163,6 @@ model { run.classpath = sourceSets.main.runtimeClasspath run.dependsOn it.tasks.install run.systemProperty 'java.library.path', filePath - run.environment 'LD_LIBRARY_PATH', filePath - run.environment 'DYLD_LIBRARY_PATH', filePath - run.workingDir filePath doFirst { doFirstTask(run) } if (org.gradle.internal.os.OperatingSystem.current().isMacOsX()) { @@ -199,9 +193,6 @@ model { exceptionFormat "full" } testTask.systemProperty 'java.library.path', filePath - testTask.environment 'LD_LIBRARY_PATH', filePath - testTask.environment 'DYLD_LIBRARY_PATH', filePath - testTask.workingDir filePath if (project.hasProperty('onlylinuxathena') || project.hasProperty('onlylinuxarm32') || project.hasProperty('onlylinuxarm64') || project.hasProperty('onlywindowsarm64')) { testTask.enabled = false diff --git a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/addressableled/Robot.java b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/addressableled/Robot.java index 5995cd044fb..3c5b2f7eb07 100644 --- a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/addressableled/Robot.java +++ b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/addressableled/Robot.java @@ -4,15 +4,31 @@ package edu.wpi.first.wpilibj.examples.addressableled; +import static edu.wpi.first.units.Units.Meters; +import static edu.wpi.first.units.Units.MetersPerSecond; + +import edu.wpi.first.units.Distance; +import edu.wpi.first.units.Measure; import edu.wpi.first.wpilibj.AddressableLED; import edu.wpi.first.wpilibj.AddressableLEDBuffer; +import edu.wpi.first.wpilibj.LEDPattern; import edu.wpi.first.wpilibj.TimedRobot; public class Robot extends TimedRobot { private AddressableLED m_led; private AddressableLEDBuffer m_ledBuffer; - // Store what the last hue of the first pixel is - private int m_rainbowFirstPixelHue; + + // Create an LED pattern that will display a rainbow across + // all hues at maximum saturation and half brightness + private final LEDPattern m_rainbow = LEDPattern.rainbow(255, 128); + + // Our LED strip has a density of 120 LEDs per meter + private static final Measure kLedSpacing = Meters.of(1 / 120.0); + + // Create a new pattern that scrolls the rainbow pattern across the LED strip, moving at a speed + // of 1 meter per second. + private final LEDPattern m_scrollingRainbow = + m_rainbow.scrollAtAbsoluteSpeed(MetersPerSecond.of(1), kLedSpacing); @Override public void robotInit() { @@ -33,24 +49,9 @@ public void robotInit() { @Override public void robotPeriodic() { - // Fill the buffer with a rainbow - rainbow(); + // Update the buffer with the rainbow animation + m_scrollingRainbow.applyTo(m_ledBuffer); // Set the LEDs m_led.setData(m_ledBuffer); } - - private void rainbow() { - // For every pixel - for (var i = 0; i < m_ledBuffer.getLength(); i++) { - // Calculate the hue - hue is easier for rainbows because the color - // shape is a circle so only one value needs to precess - final var hue = (m_rainbowFirstPixelHue + (i * 180 / m_ledBuffer.getLength())) % 180; - // Set the value - m_ledBuffer.setHSV(i, hue, 255, 128); - } - // Increase by to make the rainbow "move" - m_rainbowFirstPixelHue += 3; - // Check bounds - m_rainbowFirstPixelHue %= 180; - } } diff --git a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/armbot/Constants.java b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/armbot/Constants.java index fe72d3db698..0fe85f3243c 100644 --- a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/armbot/Constants.java +++ b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/armbot/Constants.java @@ -28,7 +28,7 @@ public static final class DriveConstants { public static final double kWheelDiameterInches = 6; public static final double kEncoderDistancePerPulse = // Assumes the encoders are directly mounted on the wheel shafts - (kWheelDiameterInches * Math.PI) / (double) kEncoderCPR; + (kWheelDiameterInches * Math.PI) / kEncoderCPR; } public static final class ArmConstants { diff --git a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/armbotoffboard/Constants.java b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/armbotoffboard/Constants.java index fb003aaeb5b..f27aebafe4e 100644 --- a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/armbotoffboard/Constants.java +++ b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/armbotoffboard/Constants.java @@ -28,7 +28,7 @@ public static final class DriveConstants { public static final double kWheelDiameterInches = 6; public static final double kEncoderDistancePerPulse = // Assumes the encoders are directly mounted on the wheel shafts - (kWheelDiameterInches * Math.PI) / (double) kEncoderCPR; + (kWheelDiameterInches * Math.PI) / kEncoderCPR; } public static final class ArmConstants { diff --git a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/frisbeebot/Constants.java b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/frisbeebot/Constants.java index 3fe16cfc747..e3126cdd23d 100644 --- a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/frisbeebot/Constants.java +++ b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/frisbeebot/Constants.java @@ -28,7 +28,7 @@ public static final class DriveConstants { public static final double kWheelDiameterInches = 6; public static final double kEncoderDistancePerPulse = // Assumes the encoders are directly mounted on the wheel shafts - (kWheelDiameterInches * Math.PI) / (double) kEncoderCPR; + (kWheelDiameterInches * Math.PI) / kEncoderCPR; } public static final class ShooterConstants { @@ -37,7 +37,7 @@ public static final class ShooterConstants { public static final int kEncoderCPR = 1024; public static final double kEncoderDistancePerPulse = // Distance units will be rotations - 1.0 / (double) kEncoderCPR; + 1.0 / kEncoderCPR; public static final int kShooterMotorPort = 4; public static final int kFeederMotorPort = 5; diff --git a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/gearsbot/Constants.java b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/gearsbot/Constants.java index 6f800677696..8ffa56c6811 100644 --- a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/gearsbot/Constants.java +++ b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/gearsbot/Constants.java @@ -24,7 +24,7 @@ public static final class DriveConstants { public static final double kWheelDiameterInches = 6; public static final double kEncoderDistancePerPulse = // Assumes the encoders are directly mounted on the wheel shafts - (kWheelDiameterInches * Math.PI) / (double) kEncoderCPR; + (kWheelDiameterInches * Math.PI) / kEncoderCPR; } public static final class ClawConstants { diff --git a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/gyrodrivecommands/Constants.java b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/gyrodrivecommands/Constants.java index b59c23dceb7..5c5f0b23b17 100644 --- a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/gyrodrivecommands/Constants.java +++ b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/gyrodrivecommands/Constants.java @@ -28,7 +28,7 @@ public static final class DriveConstants { public static final double kWheelDiameterInches = 6; public static final double kEncoderDistancePerPulse = // Assumes the encoders are directly mounted on the wheel shafts - (kWheelDiameterInches * Math.PI) / (double) kEncoderCPR; + (kWheelDiameterInches * Math.PI) / kEncoderCPR; public static final boolean kGyroReversed = false; diff --git a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/hatchbotinlined/Constants.java b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/hatchbotinlined/Constants.java index 30e8aadaa46..68468f6d077 100644 --- a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/hatchbotinlined/Constants.java +++ b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/hatchbotinlined/Constants.java @@ -28,7 +28,7 @@ public static final class DriveConstants { public static final double kWheelDiameterInches = 6; public static final double kEncoderDistancePerPulse = // Assumes the encoders are directly mounted on the wheel shafts - (kWheelDiameterInches * Math.PI) / (double) kEncoderCPR; + (kWheelDiameterInches * Math.PI) / kEncoderCPR; } public static final class HatchConstants { diff --git a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/hatchbottraditional/Constants.java b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/hatchbottraditional/Constants.java index f02fa12a25c..87b06e19657 100644 --- a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/hatchbottraditional/Constants.java +++ b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/hatchbottraditional/Constants.java @@ -28,7 +28,7 @@ public static final class DriveConstants { public static final double kWheelDiameterInches = 6; public static final double kEncoderDistancePerPulse = // Assumes the encoders are directly mounted on the wheel shafts - (kWheelDiameterInches * Math.PI) / (double) kEncoderCPR; + (kWheelDiameterInches * Math.PI) / kEncoderCPR; } public static final class HatchConstants { diff --git a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/i2ccommunication/Robot.java b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/i2ccommunication/Robot.java index cc1af03b6b2..bfbfc39de91 100644 --- a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/i2ccommunication/Robot.java +++ b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/i2ccommunication/Robot.java @@ -37,6 +37,7 @@ private void writeString(String input) { } @Override + @SuppressWarnings("PMD.ConsecutiveLiteralAppends") public void robotPeriodic() { // Creates a string to hold current robot state information, including // alliance, enabled state, operation mode, and match time. The message diff --git a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/mecanumcontrollercommand/Constants.java b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/mecanumcontrollercommand/Constants.java index 99962ee4a53..19164dc29e8 100644 --- a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/mecanumcontrollercommand/Constants.java +++ b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/mecanumcontrollercommand/Constants.java @@ -50,7 +50,7 @@ public static final class DriveConstants { public static final double kWheelDiameterMeters = 0.15; public static final double kEncoderDistancePerPulse = // Assumes the encoders are directly mounted on the wheel shafts - (kWheelDiameterMeters * Math.PI) / (double) kEncoderCPR; + (kWheelDiameterMeters * Math.PI) / kEncoderCPR; // These are example values only - DO NOT USE THESE FOR YOUR OWN ROBOT! // These characterization values MUST be determined either experimentally or theoretically diff --git a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/rapidreactcommandbot/Constants.java b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/rapidreactcommandbot/Constants.java index 5809616cf7f..31ce798c65f 100644 --- a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/rapidreactcommandbot/Constants.java +++ b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/rapidreactcommandbot/Constants.java @@ -30,7 +30,7 @@ public static final class DriveConstants { public static final double kWheelDiameterMeters = Units.inchesToMeters(6); public static final double kEncoderDistancePerPulse = // Assumes the encoders are directly mounted on the wheel shafts - (kWheelDiameterMeters * Math.PI) / (double) kEncoderCPR; + (kWheelDiameterMeters * Math.PI) / kEncoderCPR; } public static final class ShooterConstants { @@ -39,7 +39,7 @@ public static final class ShooterConstants { public static final int kEncoderCPR = 1024; public static final double kEncoderDistancePerPulse = // Distance units will be rotations - 1.0 / (double) kEncoderCPR; + 1.0 / kEncoderCPR; public static final int kShooterMotorPort = 4; public static final int kFeederMotorPort = 5; diff --git a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/swervecontrollercommand/Constants.java b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/swervecontrollercommand/Constants.java index 0965db376df..acdaa388594 100644 --- a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/swervecontrollercommand/Constants.java +++ b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/swervecontrollercommand/Constants.java @@ -84,11 +84,11 @@ public static final class ModuleConstants { public static final double kWheelDiameterMeters = 0.15; public static final double kDriveEncoderDistancePerPulse = // Assumes the encoders are directly mounted on the wheel shafts - (kWheelDiameterMeters * Math.PI) / (double) kEncoderCPR; + (kWheelDiameterMeters * Math.PI) / kEncoderCPR; public static final double kTurningEncoderDistancePerPulse = // Assumes the encoders are on a 1:1 reduction with the module shaft. - (2 * Math.PI) / (double) kEncoderCPR; + (2 * Math.PI) / kEncoderCPR; public static final double kPModuleTurningController = 1; diff --git a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/sysid/Constants.java b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/sysid/Constants.java index f7731317dec..a6f09eb2d92 100644 --- a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/sysid/Constants.java +++ b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/sysid/Constants.java @@ -30,7 +30,7 @@ public static final class DriveConstants { public static final double kWheelDiameterMeters = Units.inchesToMeters(6); public static final double kEncoderDistancePerPulse = // Assumes the encoders are directly mounted on the wheel shafts - (kWheelDiameterMeters * Math.PI) / (double) kEncoderCPR; + (kWheelDiameterMeters * Math.PI) / kEncoderCPR; } public static final class ShooterConstants { @@ -39,7 +39,7 @@ public static final class ShooterConstants { public static final int kEncoderCPR = 1024; public static final double kEncoderDistancePerPulse = // Distance units will be rotations - 1.0 / (double) kEncoderCPR; + 1.0 / kEncoderCPR; public static final int kShooterMotorPort = 4; public static final int kFeederMotorPort = 5; diff --git a/wpilibjExamples/src/test/java/edu/wpi/first/wpilibj/examples/addressableled/RainbowTest.java b/wpilibjExamples/src/test/java/edu/wpi/first/wpilibj/examples/addressableled/RainbowTest.java deleted file mode 100644 index 90acfb08bd9..00000000000 --- a/wpilibjExamples/src/test/java/edu/wpi/first/wpilibj/examples/addressableled/RainbowTest.java +++ /dev/null @@ -1,54 +0,0 @@ -// Copyright (c) FIRST and other WPILib contributors. -// Open Source Software; you can modify and/or share it under the terms of -// the WPILib BSD license file in the root directory of this project. - -package edu.wpi.first.wpilibj.examples.addressableled; - -import static org.junit.jupiter.api.Assertions.assertAll; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertTrue; - -import edu.wpi.first.hal.HAL; -import edu.wpi.first.wpilibj.simulation.AddressableLEDSim; -import edu.wpi.first.wpilibj.util.Color; -import edu.wpi.first.wpilibj.util.Color8Bit; -import org.junit.jupiter.api.Test; - -class RainbowTest { - @Test - void rainbowPatternTest() { - HAL.initialize(500, 0); - try (var robot = new Robot()) { - robot.robotInit(); - AddressableLEDSim ledSim = AddressableLEDSim.createForChannel(9); - assertTrue(ledSim.getRunning()); - assertEquals(60, ledSim.getLength()); - - var rainbowFirstPixelHue = 0; - for (int iteration = 0; iteration < 100; iteration++) { - robot.robotPeriodic(); - var data = ledSim.getData(); - for (int i = 0; i < 60; i++) { - final var hue = (rainbowFirstPixelHue + (i * 180 / 60)) % 180; - assertIndexColor(data, i, hue, 255, 128); - } - rainbowFirstPixelHue += 3; - rainbowFirstPixelHue %= 180; - } - } - } - - private void assertIndexColor(byte[] data, int index, int hue, int saturation, int value) { - var color = new Color8Bit(Color.fromHSV(hue, saturation, value)); - int b = data[index * 4]; - int g = data[(index * 4) + 1]; - int r = data[(index * 4) + 2]; - int z = data[(index * 4) + 3]; - - assertAll( - () -> assertEquals(0, z), - () -> assertEquals(color.red, r & 0xFF), - () -> assertEquals(color.green, g & 0xFF), - () -> assertEquals(color.blue, b & 0xFF)); - } -} diff --git a/wpimath/CMakeLists.txt b/wpimath/CMakeLists.txt index d0984731b58..f56558410af 100644 --- a/wpimath/CMakeLists.txt +++ b/wpimath/CMakeLists.txt @@ -19,14 +19,14 @@ protobuf_generate_cpp( file( GLOB wpimath_jni_src - src/main/native/cpp/jni/WPIMathJNI_ArmFeedforward.cpp - src/main/native/cpp/jni/WPIMathJNI_DARE.cpp - src/main/native/cpp/jni/WPIMathJNI_Eigen.cpp - src/main/native/cpp/jni/WPIMathJNI_Ellipse2d.cpp - src/main/native/cpp/jni/WPIMathJNI_Exceptions.cpp - src/main/native/cpp/jni/WPIMathJNI_Pose3d.cpp - src/main/native/cpp/jni/WPIMathJNI_StateSpaceUtil.cpp - src/main/native/cpp/jni/WPIMathJNI_Trajectory.cpp + src/main/native/cpp/jni/ArmFeedforwardJNI.cpp + src/main/native/cpp/jni/DAREJNI.cpp + src/main/native/cpp/jni/EigenJNI.cpp + src/main/native/cpp/jni/Ellipse2dJNI.cpp + src/main/native/cpp/jni/Exceptions.cpp + src/main/native/cpp/jni/Pose3dJNI.cpp + src/main/native/cpp/jni/StateSpaceUtilJNI.cpp + src/main/native/cpp/jni/TrajectoryUtilJNI.cpp ) # Java bindings diff --git a/wpimath/src/main/java/edu/wpi/first/math/DARE.java b/wpimath/src/main/java/edu/wpi/first/math/DARE.java index 44c488dc526..504a863279b 100644 --- a/wpimath/src/main/java/edu/wpi/first/math/DARE.java +++ b/wpimath/src/main/java/edu/wpi/first/math/DARE.java @@ -4,6 +4,7 @@ package edu.wpi.first.math; +import edu.wpi.first.math.jni.DAREJNI; import org.ejml.simple.SimpleMatrix; /** DARE solver utility functions. */ @@ -43,7 +44,7 @@ public static Matrix da Matrix Q, Matrix R) { var S = new Matrix(new SimpleMatrix(A.getNumRows(), A.getNumCols())); - WPIMathJNI.dareDetailABQR( + DAREJNI.dareDetailABQR( A.getStorage().getDDRM().getData(), B.getStorage().getDDRM().getData(), Q.getStorage().getDDRM().getData(), @@ -121,7 +122,7 @@ public static Matrix da Matrix R, Matrix N) { var S = new Matrix(new SimpleMatrix(A.getNumRows(), A.getNumCols())); - WPIMathJNI.dareDetailABQRN( + DAREJNI.dareDetailABQRN( A.getStorage().getDDRM().getData(), B.getStorage().getDDRM().getData(), Q.getStorage().getDDRM().getData(), @@ -156,7 +157,7 @@ public static Matrix da Matrix Q, Matrix R) { var S = new Matrix(new SimpleMatrix(A.getNumRows(), A.getNumCols())); - WPIMathJNI.dareABQR( + DAREJNI.dareABQR( A.getStorage().getDDRM().getData(), B.getStorage().getDDRM().getData(), Q.getStorage().getDDRM().getData(), @@ -226,7 +227,7 @@ public static Matrix da Matrix R, Matrix N) { var S = new Matrix(new SimpleMatrix(A.getNumRows(), A.getNumCols())); - WPIMathJNI.dareABQRN( + DAREJNI.dareABQRN( A.getStorage().getDDRM().getData(), B.getStorage().getDDRM().getData(), Q.getStorage().getDDRM().getData(), diff --git a/wpimath/src/main/java/edu/wpi/first/math/Matrix.java b/wpimath/src/main/java/edu/wpi/first/math/Matrix.java index 40f279913f9..ae5741ea132 100644 --- a/wpimath/src/main/java/edu/wpi/first/math/Matrix.java +++ b/wpimath/src/main/java/edu/wpi/first/math/Matrix.java @@ -4,6 +4,7 @@ package edu.wpi.first.math; +import edu.wpi.first.math.jni.EigenJNI; import edu.wpi.first.math.numbers.N1; import java.util.Objects; import org.ejml.MatrixDimensionException; @@ -201,7 +202,7 @@ public final double minInternal() { * @return The mean value of this matrix. */ public final double mean() { - return this.elementSum() / (double) this.m_storage.getNumElements(); + return this.elementSum() / this.m_storage.getNumElements(); } /** @@ -360,7 +361,7 @@ public final Matrix solve(Matrix b) { public final Matrix solveFullPivHouseholderQr( Matrix other) { Matrix solution = new Matrix<>(new SimpleMatrix(this.getNumCols(), other.getNumCols())); - WPIMathJNI.solveFullPivHouseholderQr( + EigenJNI.solveFullPivHouseholderQr( this.getData(), this.getNumRows(), this.getNumCols(), @@ -387,7 +388,7 @@ public final Matrix exp() { + this.getNumCols()); } Matrix toReturn = new Matrix<>(new SimpleMatrix(this.getNumRows(), this.getNumCols())); - WPIMathJNI.exp( + EigenJNI.exp( this.m_storage.getDDRM().getData(), this.getNumRows(), toReturn.m_storage.getDDRM().getData()); @@ -411,7 +412,7 @@ public final Matrix pow(double exponent) { + this.getNumCols()); } Matrix toReturn = new Matrix<>(new SimpleMatrix(this.getNumRows(), this.getNumCols())); - WPIMathJNI.pow( + EigenJNI.pow( this.m_storage.getDDRM().getData(), this.getNumRows(), exponent, @@ -709,7 +710,7 @@ public boolean isEqual(Matrix other, double tolerance) { * @param lowerTriangular Whether this matrix is lower triangular. */ public void rankUpdate(Matrix v, double sigma, boolean lowerTriangular) { - WPIMathJNI.rankUpdate(this.getData(), this.getNumRows(), v.getData(), sigma, lowerTriangular); + EigenJNI.rankUpdate(this.getData(), this.getNumRows(), v.getData(), sigma, lowerTriangular); } @Override @@ -727,12 +728,10 @@ public String toString() { */ @Override public boolean equals(Object other) { - if (this == other) { - return true; - } - return other instanceof Matrix matrix - && !MatrixFeatures_DDRM.hasUncountable(matrix.m_storage.getDDRM()) - && MatrixFeatures_DDRM.isEquals(this.m_storage.getDDRM(), matrix.m_storage.getDDRM()); + return this == other + || other instanceof Matrix matrix + && !MatrixFeatures_DDRM.hasUncountable(matrix.m_storage.getDDRM()) + && MatrixFeatures_DDRM.isEquals(this.m_storage.getDDRM(), matrix.m_storage.getDDRM()); } @Override diff --git a/wpimath/src/main/java/edu/wpi/first/math/Pair.java b/wpimath/src/main/java/edu/wpi/first/math/Pair.java index eacbac4179d..9ec237c0aaa 100644 --- a/wpimath/src/main/java/edu/wpi/first/math/Pair.java +++ b/wpimath/src/main/java/edu/wpi/first/math/Pair.java @@ -71,12 +71,10 @@ public String toString() { */ @Override public boolean equals(Object obj) { - if (obj == this) { - return true; - } - return obj instanceof Pair other - && Objects.equals(m_first, other.getFirst()) - && Objects.equals(m_second, other.getSecond()); + return obj == this + || obj instanceof Pair other + && Objects.equals(m_first, other.getFirst()) + && Objects.equals(m_second, other.getSecond()); } @Override diff --git a/wpimath/src/main/java/edu/wpi/first/math/StateSpaceUtil.java b/wpimath/src/main/java/edu/wpi/first/math/StateSpaceUtil.java index 4e003747693..461d9a6f080 100644 --- a/wpimath/src/main/java/edu/wpi/first/math/StateSpaceUtil.java +++ b/wpimath/src/main/java/edu/wpi/first/math/StateSpaceUtil.java @@ -5,6 +5,7 @@ package edu.wpi.first.math; import edu.wpi.first.math.geometry.Pose2d; +import edu.wpi.first.math.jni.StateSpaceUtilJNI; import edu.wpi.first.math.numbers.N1; import edu.wpi.first.math.numbers.N3; import edu.wpi.first.math.numbers.N4; @@ -102,7 +103,8 @@ public static Matrix makeCostMatrix( */ public static boolean isStabilizable( Matrix A, Matrix B) { - return WPIMathJNI.isStabilizable(A.getNumRows(), B.getNumCols(), A.getData(), B.getData()); + return StateSpaceUtilJNI.isStabilizable( + A.getNumRows(), B.getNumCols(), A.getData(), B.getData()); } /** @@ -120,7 +122,7 @@ public static boolean isStabilizable( */ public static boolean isDetectable( Matrix A, Matrix C) { - return WPIMathJNI.isStabilizable( + return StateSpaceUtilJNI.isStabilizable( A.getNumRows(), C.getNumRows(), A.transpose().getData(), C.transpose().getData()); } diff --git a/wpimath/src/main/java/edu/wpi/first/math/WPIMathJNI.java b/wpimath/src/main/java/edu/wpi/first/math/WPIMathJNI.java deleted file mode 100644 index 10a9147c7d2..00000000000 --- a/wpimath/src/main/java/edu/wpi/first/math/WPIMathJNI.java +++ /dev/null @@ -1,463 +0,0 @@ -// Copyright (c) FIRST and other WPILib contributors. -// Open Source Software; you can modify and/or share it under the terms of -// the WPILib BSD license file in the root directory of this project. - -package edu.wpi.first.math; - -import edu.wpi.first.util.RuntimeLoader; -import java.io.IOException; -import java.util.concurrent.atomic.AtomicBoolean; - -/** WPIMath JNI. */ -public final class WPIMathJNI { - static boolean libraryLoaded = false; - - static { - if (Helper.getExtractOnStaticLoad()) { - try { - RuntimeLoader.loadLibrary("wpimathjni"); - } catch (Exception ex) { - ex.printStackTrace(); - System.exit(1); - } - libraryLoaded = true; - } - } - - /** - * Force load the library. - * - * @throws IOException If the library could not be loaded or found. - */ - public static synchronized void forceLoad() throws IOException { - if (libraryLoaded) { - return; - } - RuntimeLoader.loadLibrary("wpimathjni"); - libraryLoaded = true; - } - - // ArmFeedforward wrappers - - /** - * Obtain a feedforward voltage from a single jointed arm feedforward object. - * - *

Constructs an ArmFeedforward object and runs its currentVelocity and nextVelocity overload - * - * @param ks The ArmFeedforward's static gain in volts. - * @param kv The ArmFeedforward's velocity gain in volt seconds per radian. - * @param ka The ArmFeedforward's acceleration gain in volt seconds² per radian. - * @param kg The ArmFeedforward's gravity gain in volts. - * @param currentAngle The current angle in the calculation in radians. - * @param currentVelocity The current velocity in the calculation in radians per second. - * @param nextVelocity The next velocity in the calculation in radians per second. - * @param dt The time between velocity setpoints in seconds. - * @return The calculated feedforward in volts. - */ - public static native double calculate( - double ks, - double kv, - double ka, - double kg, - double currentAngle, - double currentVelocity, - double nextVelocity, - double dt); - - // DARE wrappers - - /** - * Computes the unique stabilizing solution X to the discrete-time algebraic Riccati equation. - * - *

AᵀXA − X − AᵀXB(BᵀXB + R)⁻¹BᵀXA + Q = 0 - * - *

This internal function skips expensive precondition checks for increased performance. The - * solver may hang if any of the following occur: - * - *

    - *
  • Q isn't symmetric positive semidefinite - *
  • R isn't symmetric positive definite - *
  • The (A, B) pair isn't stabilizable - *
  • The (A, C) pair where Q = CᵀC isn't detectable - *
- * - *

Only use this function if you're sure the preconditions are met. Solves the discrete - * alegebraic Riccati equation. - * - * @param A Array containing elements of A in row-major order. - * @param B Array containing elements of B in row-major order. - * @param Q Array containing elements of Q in row-major order. - * @param R Array containing elements of R in row-major order. - * @param states Number of states in A matrix. - * @param inputs Number of inputs in B matrix. - * @param S Array storage for DARE solution. - */ - public static native void dareDetailABQR( - double[] A, double[] B, double[] Q, double[] R, int states, int inputs, double[] S); - - /** - * Computes the unique stabilizing solution X to the discrete-time algebraic Riccati equation. - * - *

AᵀXA − X − (AᵀXB + N)(BᵀXB + R)⁻¹(BᵀXA + Nᵀ) + Q = 0 - * - *

This overload of the DARE is useful for finding the control law uₖ that minimizes the - * following cost function subject to xₖ₊₁ = Axₖ + Buₖ. - * - *

-   *     ∞ [xₖ]ᵀ[Q  N][xₖ]
-   * J = Σ [uₖ] [Nᵀ R][uₖ] ΔT
-   *    k=0
-   * 
- * - *

This is a more general form of the following. The linear-quadratic regulator is the feedback - * control law uₖ that minimizes the following cost function subject to xₖ₊₁ = Axₖ + Buₖ: - * - *

-   *     ∞
-   * J = Σ (xₖᵀQxₖ + uₖᵀRuₖ) ΔT
-   *    k=0
-   * 
- * - *

This can be refactored as: - * - *

-   *     ∞ [xₖ]ᵀ[Q 0][xₖ]
-   * J = Σ [uₖ] [0 R][uₖ] ΔT
-   *    k=0
-   * 
- * - *

This internal function skips expensive precondition checks for increased performance. The - * solver may hang if any of the following occur: - * - *

    - *
  • Q − NR⁻¹Nᵀ isn't symmetric positive semidefinite - *
  • R isn't symmetric positive definite - *
  • The (A − BR⁻¹Nᵀ, B) pair isn't stabilizable - *
  • The (A, C) pair where Q = CᵀC isn't detectable - *
- * - *

Only use this function if you're sure the preconditions are met. - * - * @param A Array containing elements of A in row-major order. - * @param B Array containing elements of B in row-major order. - * @param Q Array containing elements of Q in row-major order. - * @param R Array containing elements of R in row-major order. - * @param N Array containing elements of N in row-major order. - * @param states Number of states in A matrix. - * @param inputs Number of inputs in B matrix. - * @param S Array storage for DARE solution. - */ - public static native void dareDetailABQRN( - double[] A, - double[] B, - double[] Q, - double[] R, - double[] N, - int states, - int inputs, - double[] S); - - /** - * Computes the unique stabilizing solution X to the discrete-time algebraic Riccati equation. - * - *

AᵀXA − X − AᵀXB(BᵀXB + R)⁻¹BᵀXA + Q = 0 - * - * @param A Array containing elements of A in row-major order. - * @param B Array containing elements of B in row-major order. - * @param Q Array containing elements of Q in row-major order. - * @param R Array containing elements of R in row-major order. - * @param states Number of states in A matrix. - * @param inputs Number of inputs in B matrix. - * @param S Array storage for DARE solution. - * @throws IllegalArgumentException if Q isn't symmetric positive semidefinite. - * @throws IllegalArgumentException if R isn't symmetric positive definite. - * @throws IllegalArgumentException if the (A, B) pair isn't stabilizable. - * @throws IllegalArgumentException if the (A, C) pair where Q = CᵀC isn't detectable. - */ - public static native void dareABQR( - double[] A, double[] B, double[] Q, double[] R, int states, int inputs, double[] S); - - /** - * Computes the unique stabilizing solution X to the discrete-time algebraic Riccati equation. - * - *

AᵀXA − X − (AᵀXB + N)(BᵀXB + R)⁻¹(BᵀXA + Nᵀ) + Q = 0 - * - *

This overload of the DARE is useful for finding the control law uₖ that minimizes the - * following cost function subject to xₖ₊₁ = Axₖ + Buₖ. - * - *

-   *     ∞ [xₖ]ᵀ[Q  N][xₖ]
-   * J = Σ [uₖ] [Nᵀ R][uₖ] ΔT
-   *    k=0
-   * 
- * - *

This is a more general form of the following. The linear-quadratic regulator is the feedback - * control law uₖ that minimizes the following cost function subject to xₖ₊₁ = Axₖ + Buₖ: - * - *

-   *     ∞
-   * J = Σ (xₖᵀQxₖ + uₖᵀRuₖ) ΔT
-   *    k=0
-   * 
- * - *

This can be refactored as: - * - *

-   *     ∞ [xₖ]ᵀ[Q 0][xₖ]
-   * J = Σ [uₖ] [0 R][uₖ] ΔT
-   *    k=0
-   * 
- * - * @param A Array containing elements of A in row-major order. - * @param B Array containing elements of B in row-major order. - * @param Q Array containing elements of Q in row-major order. - * @param R Array containing elements of R in row-major order. - * @param N Array containing elements of N in row-major order. - * @param states Number of states in A matrix. - * @param inputs Number of inputs in B matrix. - * @param S Array storage for DARE solution. - * @throws IllegalArgumentException if Q − NR⁻¹Nᵀ isn't symmetric positive semidefinite. - * @throws IllegalArgumentException if R isn't symmetric positive definite. - * @throws IllegalArgumentException if the (A − BR⁻¹Nᵀ, B) pair isn't stabilizable. - * @throws IllegalArgumentException if the (A, C) pair where Q = CᵀC isn't detectable. - */ - public static native void dareABQRN( - double[] A, - double[] B, - double[] Q, - double[] R, - double[] N, - int states, - int inputs, - double[] S); - - // Eigen wrappers - - /** - * Computes the matrix exp. - * - * @param src Array of elements of the matrix to be exponentiated. - * @param rows How many rows there are. - * @param dst Array where the result will be stored. - */ - public static native void exp(double[] src, int rows, double[] dst); - - /** - * Computes the matrix pow. - * - * @param src Array of elements of the matrix to be raised to a power. - * @param rows How many rows there are. - * @param exponent The exponent. - * @param dst Array where the result will be stored. - */ - public static native void pow(double[] src, int rows, double exponent, double[] dst); - - /** - * Performs an inplace rank one update (or downdate) of an upper triangular Cholesky decomposition - * matrix. - * - * @param mat Array of elements of the matrix to be updated. - * @param lowerTriangular Whether mat is lower triangular. - * @param rows How many rows there are. - * @param vec Vector to use for the rank update. - * @param sigma Sigma value to use for the rank update. - */ - public static native void rankUpdate( - double[] mat, int rows, double[] vec, double sigma, boolean lowerTriangular); - - /** - * Solves the least-squares problem Ax=B using a QR decomposition with full pivoting. - * - * @param A Array of elements of the A matrix. - * @param Arows Number of rows of the A matrix. - * @param Acols Number of rows of the A matrix. - * @param B Array of elements of the B matrix. - * @param Brows Number of rows of the B matrix. - * @param Bcols Number of rows of the B matrix. - * @param dst Array to store solution in. If A is m-n and B is m-p, dst is n-p. - */ - public static native void solveFullPivHouseholderQr( - double[] A, int Arows, int Acols, double[] B, int Brows, int Bcols, double[] dst); - - // Ellipse2d wrappers - - /** - * Returns the nearest point that is contained within the ellipse. - * - *

Constructs an Ellipse2d object and runs its FindNearestPoint() method. - * - * @param centerX The x coordinate of the center of the ellipse in meters. - * @param centerY The y coordinate of the center of the ellipse in meters. - * @param centerHeading The ellipse's rotation in radians. - * @param xSemiAxis The x semi-axis in meters. - * @param ySemiAxis The y semi-axis in meters. - * @param pointX The x coordinate of the point that this will find the nearest point to. - * @param pointY The y coordinate of the point that this will find the nearest point to. - * @param nearestPoint Array to store nearest point into. - */ - public static native void ellipse2dFindNearestPoint( - double centerX, - double centerY, - double centerHeading, - double xSemiAxis, - double ySemiAxis, - double pointX, - double pointY, - double[] nearestPoint); - - // Pose3d wrappers - - /** - * Obtain a Pose3d from a (constant curvature) velocity. - * - *

The double array returned is of the form [dx, dy, dz, qx, qy, qz]. - * - * @param poseX The pose's translational X component. - * @param poseY The pose's translational Y component. - * @param poseZ The pose's translational Z component. - * @param poseQw The pose quaternion's W component. - * @param poseQx The pose quaternion's X component. - * @param poseQy The pose quaternion's Y component. - * @param poseQz The pose quaternion's Z component. - * @param twistDx The twist's dx value. - * @param twistDy The twist's dy value. - * @param twistDz The twist's dz value. - * @param twistRx The twist's rx value. - * @param twistRy The twist's ry value. - * @param twistRz The twist's rz value. - * @return The new pose as a double array. - */ - public static native double[] expPose3d( - double poseX, - double poseY, - double poseZ, - double poseQw, - double poseQx, - double poseQy, - double poseQz, - double twistDx, - double twistDy, - double twistDz, - double twistRx, - double twistRy, - double twistRz); - - /** - * Returns a Twist3d that maps the starting pose to the end pose. - * - *

The double array returned is of the form [dx, dy, dz, rx, ry, rz]. - * - * @param startX The starting pose's translational X component. - * @param startY The starting pose's translational Y component. - * @param startZ The starting pose's translational Z component. - * @param startQw The starting pose quaternion's W component. - * @param startQx The starting pose quaternion's X component. - * @param startQy The starting pose quaternion's Y component. - * @param startQz The starting pose quaternion's Z component. - * @param endX The ending pose's translational X component. - * @param endY The ending pose's translational Y component. - * @param endZ The ending pose's translational Z component. - * @param endQw The ending pose quaternion's W component. - * @param endQx The ending pose quaternion's X component. - * @param endQy The ending pose quaternion's Y component. - * @param endQz The ending pose quaternion's Z component. - * @return The twist that maps start to end as a double array. - */ - public static native double[] logPose3d( - double startX, - double startY, - double startZ, - double startQw, - double startQx, - double startQy, - double startQz, - double endX, - double endY, - double endZ, - double endQw, - double endQx, - double endQy, - double endQz); - - // StateSpaceUtil wrappers - - /** - * Returns true if (A, B) is a stabilizable pair. - * - *

(A, B) is stabilizable if and only if the uncontrollable eigenvalues of A, if any, have - * absolute values less than one, where an eigenvalue is uncontrollable if rank(lambda * I - A, B) - * < n where n is the number of states. - * - * @param states the number of states of the system. - * @param inputs the number of inputs to the system. - * @param A System matrix. - * @param B Input matrix. - * @return If the system is stabilizable. - */ - public static native boolean isStabilizable(int states, int inputs, double[] A, double[] B); - - // Trajectory wrappers - - /** - * Loads a Pathweaver JSON. - * - * @param path The path to the JSON. - * @return A double array with the trajectory states from the JSON. - * @throws IOException if the JSON could not be read. - */ - public static native double[] fromPathweaverJson(String path) throws IOException; - - /** - * Converts a trajectory into a Pathweaver JSON and saves it. - * - * @param elements The elements of the trajectory. - * @param path The location to save the JSON to. - * @throws IOException if the JSON could not be written. - */ - public static native void toPathweaverJson(double[] elements, String path) throws IOException; - - /** - * Deserializes a trajectory JSON into a double[] of trajectory elements. - * - * @param json The JSON containing the serialized trajectory. - * @return A double array with the trajectory states. - */ - public static native double[] deserializeTrajectory(String json); - - /** - * Serializes the trajectory into a JSON string. - * - * @param elements The elements of the trajectory. - * @return A JSON containing the serialized trajectory. - */ - public static native String serializeTrajectory(double[] elements); - - /** Sets whether JNI should be loaded in the static block. */ - public static class Helper { - private static AtomicBoolean extractOnStaticLoad = new AtomicBoolean(true); - - /** - * Returns true if the JNI should be loaded in the static block. - * - * @return True if the JNI should be loaded in the static block. - */ - public static boolean getExtractOnStaticLoad() { - return extractOnStaticLoad.get(); - } - - /** - * Sets whether the JNI should be loaded in the static block. - * - * @param load Whether the JNI should be loaded in the static block. - */ - public static void setExtractOnStaticLoad(boolean load) { - extractOnStaticLoad.set(load); - } - - /** Utility class. */ - private Helper() {} - } - - /** Utility class. */ - private WPIMathJNI() {} -} diff --git a/wpimath/src/main/java/edu/wpi/first/math/controller/ArmFeedforward.java b/wpimath/src/main/java/edu/wpi/first/math/controller/ArmFeedforward.java index 0d479418063..32464ece107 100644 --- a/wpimath/src/main/java/edu/wpi/first/math/controller/ArmFeedforward.java +++ b/wpimath/src/main/java/edu/wpi/first/math/controller/ArmFeedforward.java @@ -4,9 +4,9 @@ package edu.wpi.first.math.controller; -import edu.wpi.first.math.WPIMathJNI; import edu.wpi.first.math.controller.proto.ArmFeedforwardProto; import edu.wpi.first.math.controller.struct.ArmFeedforwardStruct; +import edu.wpi.first.math.jni.ArmFeedforwardJNI; import edu.wpi.first.util.protobuf.ProtobufSerializable; import edu.wpi.first.util.struct.StructSerializable; @@ -114,7 +114,8 @@ public double calculate(double positionRadians, double velocity) { */ public double calculate( double currentAngle, double currentVelocity, double nextVelocity, double dt) { - return WPIMathJNI.calculate(ks, kv, ka, kg, currentAngle, currentVelocity, nextVelocity, dt); + return ArmFeedforwardJNI.calculate( + ks, kv, ka, kg, currentAngle, currentVelocity, nextVelocity, dt); } // Rearranging the main equation from the calculate() method yields the diff --git a/wpimath/src/main/java/edu/wpi/first/math/estimator/KalmanFilterLatencyCompensator.java b/wpimath/src/main/java/edu/wpi/first/math/estimator/KalmanFilterLatencyCompensator.java index ad4db523377..da8b0132e56 100644 --- a/wpimath/src/main/java/edu/wpi/first/math/estimator/KalmanFilterLatencyCompensator.java +++ b/wpimath/src/main/java/edu/wpi/first/math/estimator/KalmanFilterLatencyCompensator.java @@ -171,7 +171,7 @@ public void applyPastGlobalMeasurement( } /** This class contains all the information about our observer at a given time. */ - public class ObserverSnapshot { + public final class ObserverSnapshot { /** The state estimate. */ public final Matrix xHat; diff --git a/wpimath/src/main/java/edu/wpi/first/math/estimator/PoseEstimator.java b/wpimath/src/main/java/edu/wpi/first/math/estimator/PoseEstimator.java index 46b8871daa6..2b956dac106 100644 --- a/wpimath/src/main/java/edu/wpi/first/math/estimator/PoseEstimator.java +++ b/wpimath/src/main/java/edu/wpi/first/math/estimator/PoseEstimator.java @@ -308,7 +308,7 @@ public Pose2d updateWithTime(double currentTimeSeconds, Rotation2d gyroAngle, T * Represents a vision update record. The record contains the vision-compensated pose estimate as * well as the corresponding odometry pose estimate. */ - private static class VisionUpdate { + private static final class VisionUpdate { // The vision-compensated pose estimate. private final Pose2d visionPose; diff --git a/wpimath/src/main/java/edu/wpi/first/math/filter/LinearFilter.java b/wpimath/src/main/java/edu/wpi/first/math/filter/LinearFilter.java index 850b7f2f75c..4af3da002c8 100644 --- a/wpimath/src/main/java/edu/wpi/first/math/filter/LinearFilter.java +++ b/wpimath/src/main/java/edu/wpi/first/math/filter/LinearFilter.java @@ -56,6 +56,7 @@ public class LinearFilter { private final DoubleCircularBuffer m_outputs; private final double[] m_inputGains; private final double[] m_outputGains; + private double m_lastOutput; private static int instances; @@ -310,6 +311,7 @@ public double calculate(double input) { m_outputs.addFirst(retVal); } + m_lastOutput = retVal; return retVal; } @@ -319,7 +321,7 @@ public double calculate(double input) { * @return The last value. */ public double lastValue() { - return m_outputs.getFirst(); + return m_lastOutput; } /** diff --git a/wpimath/src/main/java/edu/wpi/first/math/geometry/Ellipse2d.java b/wpimath/src/main/java/edu/wpi/first/math/geometry/Ellipse2d.java index e52464a30e6..499dae86545 100644 --- a/wpimath/src/main/java/edu/wpi/first/math/geometry/Ellipse2d.java +++ b/wpimath/src/main/java/edu/wpi/first/math/geometry/Ellipse2d.java @@ -5,9 +5,9 @@ package edu.wpi.first.math.geometry; import edu.wpi.first.math.Pair; -import edu.wpi.first.math.WPIMathJNI; import edu.wpi.first.math.geometry.proto.Ellipse2dProto; import edu.wpi.first.math.geometry.struct.Ellipse2dStruct; +import edu.wpi.first.math.jni.Ellipse2dJNI; import edu.wpi.first.util.protobuf.ProtobufSerializable; import edu.wpi.first.util.struct.StructSerializable; import java.util.Objects; @@ -172,7 +172,7 @@ public Translation2d findNearestPoint(Translation2d point) { // Find nearest point var nearestPoint = new double[2]; - WPIMathJNI.ellipse2dFindNearestPoint( + Ellipse2dJNI.findNearestPoint( m_center.getX(), m_center.getY(), m_center.getRotation().getRadians(), diff --git a/wpimath/src/main/java/edu/wpi/first/math/geometry/Pose3d.java b/wpimath/src/main/java/edu/wpi/first/math/geometry/Pose3d.java index 4bb404ed7fa..6b116a6cff2 100644 --- a/wpimath/src/main/java/edu/wpi/first/math/geometry/Pose3d.java +++ b/wpimath/src/main/java/edu/wpi/first/math/geometry/Pose3d.java @@ -8,10 +8,10 @@ import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonProperty; -import edu.wpi.first.math.WPIMathJNI; import edu.wpi.first.math.geometry.proto.Pose3dProto; import edu.wpi.first.math.geometry.struct.Pose3dStruct; import edu.wpi.first.math.interpolation.Interpolatable; +import edu.wpi.first.math.jni.Pose3dJNI; import edu.wpi.first.util.protobuf.ProtobufSerializable; import edu.wpi.first.util.struct.StructSerializable; import java.util.Objects; @@ -224,7 +224,7 @@ public Pose3d relativeTo(Pose3d other) { public Pose3d exp(Twist3d twist) { var quaternion = this.getRotation().getQuaternion(); double[] resultArray = - WPIMathJNI.expPose3d( + Pose3dJNI.exp( this.getX(), this.getY(), this.getZ(), @@ -257,7 +257,7 @@ public Twist3d log(Pose3d end) { var thisQuaternion = this.getRotation().getQuaternion(); var endQuaternion = end.getRotation().getQuaternion(); double[] resultArray = - WPIMathJNI.logPose3d( + Pose3dJNI.log( this.getX(), this.getY(), this.getZ(), diff --git a/wpimath/src/main/java/edu/wpi/first/math/jni/ArmFeedforwardJNI.java b/wpimath/src/main/java/edu/wpi/first/math/jni/ArmFeedforwardJNI.java new file mode 100644 index 00000000000..22796cf2464 --- /dev/null +++ b/wpimath/src/main/java/edu/wpi/first/math/jni/ArmFeedforwardJNI.java @@ -0,0 +1,93 @@ +// Copyright (c) FIRST and other WPILib contributors. +// Open Source Software; you can modify and/or share it under the terms of +// the WPILib BSD license file in the root directory of this project. + +package edu.wpi.first.math.jni; + +import edu.wpi.first.util.RuntimeLoader; +import java.io.IOException; +import java.util.concurrent.atomic.AtomicBoolean; + +/** ArmFeedforward JNI. */ +public final class ArmFeedforwardJNI { + static boolean libraryLoaded = false; + + static { + if (Helper.getExtractOnStaticLoad()) { + try { + RuntimeLoader.loadLibrary("wpimathjni"); + } catch (Exception ex) { + ex.printStackTrace(); + System.exit(1); + } + libraryLoaded = true; + } + } + + /** + * Force load the library. + * + * @throws IOException If the library could not be loaded or found. + */ + public static synchronized void forceLoad() throws IOException { + if (libraryLoaded) { + return; + } + RuntimeLoader.loadLibrary("wpimathjni"); + libraryLoaded = true; + } + + /** + * Obtain a feedforward voltage from a single jointed arm feedforward object. + * + *

Constructs an ArmFeedforward object and runs its currentVelocity and nextVelocity overload + * + * @param ks The ArmFeedforward's static gain in volts. + * @param kv The ArmFeedforward's velocity gain in volt seconds per radian. + * @param ka The ArmFeedforward's acceleration gain in volt seconds² per radian. + * @param kg The ArmFeedforward's gravity gain in volts. + * @param currentAngle The current angle in the calculation in radians. + * @param currentVelocity The current velocity in the calculation in radians per second. + * @param nextVelocity The next velocity in the calculation in radians per second. + * @param dt The time between velocity setpoints in seconds. + * @return The calculated feedforward in volts. + */ + public static native double calculate( + double ks, + double kv, + double ka, + double kg, + double currentAngle, + double currentVelocity, + double nextVelocity, + double dt); + + /** Sets whether JNI should be loaded in the static block. */ + public static class Helper { + private static AtomicBoolean extractOnStaticLoad = new AtomicBoolean(true); + + /** + * Returns true if the JNI should be loaded in the static block. + * + * @return True if the JNI should be loaded in the static block. + */ + public static boolean getExtractOnStaticLoad() { + return extractOnStaticLoad.get(); + } + + /** + * Sets whether the JNI should be loaded in the static block. + * + * @param load Whether the JNI should be loaded in the static block. + */ + public static void setExtractOnStaticLoad(boolean load) { + extractOnStaticLoad.set(load); + } + + /** Utility class. */ + private Helper() {} + } + + /** Utility class. */ + private ArmFeedforwardJNI() {} +} diff --git a/wpimath/src/main/java/edu/wpi/first/math/jni/DAREJNI.java b/wpimath/src/main/java/edu/wpi/first/math/jni/DAREJNI.java new file mode 100644 index 00000000000..8dcdf0e72a7 --- /dev/null +++ b/wpimath/src/main/java/edu/wpi/first/math/jni/DAREJNI.java @@ -0,0 +1,233 @@ +// Copyright (c) FIRST and other WPILib contributors. +// Open Source Software; you can modify and/or share it under the terms of +// the WPILib BSD license file in the root directory of this project. + +package edu.wpi.first.math.jni; + +import edu.wpi.first.util.RuntimeLoader; +import java.io.IOException; +import java.util.concurrent.atomic.AtomicBoolean; + +/** DARE JNI. */ +public final class DAREJNI { + static boolean libraryLoaded = false; + + static { + if (Helper.getExtractOnStaticLoad()) { + try { + RuntimeLoader.loadLibrary("wpimathjni"); + } catch (Exception ex) { + ex.printStackTrace(); + System.exit(1); + } + libraryLoaded = true; + } + } + + /** + * Force load the library. + * + * @throws IOException If the library could not be loaded or found. + */ + public static synchronized void forceLoad() throws IOException { + if (libraryLoaded) { + return; + } + RuntimeLoader.loadLibrary("wpimathjni"); + libraryLoaded = true; + } + + /** + * Computes the unique stabilizing solution X to the discrete-time algebraic Riccati equation. + * + *

AᵀXA − X − AᵀXB(BᵀXB + R)⁻¹BᵀXA + Q = 0 + * + *

This internal function skips expensive precondition checks for increased performance. The + * solver may hang if any of the following occur: + * + *

    + *
  • Q isn't symmetric positive semidefinite + *
  • R isn't symmetric positive definite + *
  • The (A, B) pair isn't stabilizable + *
  • The (A, C) pair where Q = CᵀC isn't detectable + *
+ * + *

Only use this function if you're sure the preconditions are met. Solves the discrete + * alegebraic Riccati equation. + * + * @param A Array containing elements of A in row-major order. + * @param B Array containing elements of B in row-major order. + * @param Q Array containing elements of Q in row-major order. + * @param R Array containing elements of R in row-major order. + * @param states Number of states in A matrix. + * @param inputs Number of inputs in B matrix. + * @param S Array storage for DARE solution. + */ + public static native void dareDetailABQR( + double[] A, double[] B, double[] Q, double[] R, int states, int inputs, double[] S); + + /** + * Computes the unique stabilizing solution X to the discrete-time algebraic Riccati equation. + * + *

AᵀXA − X − (AᵀXB + N)(BᵀXB + R)⁻¹(BᵀXA + Nᵀ) + Q = 0 + * + *

This overload of the DARE is useful for finding the control law uₖ that minimizes the + * following cost function subject to xₖ₊₁ = Axₖ + Buₖ. + * + *

+   *     ∞ [xₖ]ᵀ[Q  N][xₖ]
+   * J = Σ [uₖ] [Nᵀ R][uₖ] ΔT
+   *    k=0
+   * 
+ * + *

This is a more general form of the following. The linear-quadratic regulator is the feedback + * control law uₖ that minimizes the following cost function subject to xₖ₊₁ = Axₖ + Buₖ: + * + *

+   *     ∞
+   * J = Σ (xₖᵀQxₖ + uₖᵀRuₖ) ΔT
+   *    k=0
+   * 
+ * + *

This can be refactored as: + * + *

+   *     ∞ [xₖ]ᵀ[Q 0][xₖ]
+   * J = Σ [uₖ] [0 R][uₖ] ΔT
+   *    k=0
+   * 
+ * + *

This internal function skips expensive precondition checks for increased performance. The + * solver may hang if any of the following occur: + * + *

    + *
  • Q − NR⁻¹Nᵀ isn't symmetric positive semidefinite + *
  • R isn't symmetric positive definite + *
  • The (A − BR⁻¹Nᵀ, B) pair isn't stabilizable + *
  • The (A, C) pair where Q = CᵀC isn't detectable + *
+ * + *

Only use this function if you're sure the preconditions are met. + * + * @param A Array containing elements of A in row-major order. + * @param B Array containing elements of B in row-major order. + * @param Q Array containing elements of Q in row-major order. + * @param R Array containing elements of R in row-major order. + * @param N Array containing elements of N in row-major order. + * @param states Number of states in A matrix. + * @param inputs Number of inputs in B matrix. + * @param S Array storage for DARE solution. + */ + public static native void dareDetailABQRN( + double[] A, + double[] B, + double[] Q, + double[] R, + double[] N, + int states, + int inputs, + double[] S); + + /** + * Computes the unique stabilizing solution X to the discrete-time algebraic Riccati equation. + * + *

AᵀXA − X − AᵀXB(BᵀXB + R)⁻¹BᵀXA + Q = 0 + * + * @param A Array containing elements of A in row-major order. + * @param B Array containing elements of B in row-major order. + * @param Q Array containing elements of Q in row-major order. + * @param R Array containing elements of R in row-major order. + * @param states Number of states in A matrix. + * @param inputs Number of inputs in B matrix. + * @param S Array storage for DARE solution. + * @throws IllegalArgumentException if Q isn't symmetric positive semidefinite. + * @throws IllegalArgumentException if R isn't symmetric positive definite. + * @throws IllegalArgumentException if the (A, B) pair isn't stabilizable. + * @throws IllegalArgumentException if the (A, C) pair where Q = CᵀC isn't detectable. + */ + public static native void dareABQR( + double[] A, double[] B, double[] Q, double[] R, int states, int inputs, double[] S); + + /** + * Computes the unique stabilizing solution X to the discrete-time algebraic Riccati equation. + * + *

AᵀXA − X − (AᵀXB + N)(BᵀXB + R)⁻¹(BᵀXA + Nᵀ) + Q = 0 + * + *

This overload of the DARE is useful for finding the control law uₖ that minimizes the + * following cost function subject to xₖ₊₁ = Axₖ + Buₖ. + * + *

+   *     ∞ [xₖ]ᵀ[Q  N][xₖ]
+   * J = Σ [uₖ] [Nᵀ R][uₖ] ΔT
+   *    k=0
+   * 
+ * + *

This is a more general form of the following. The linear-quadratic regulator is the feedback + * control law uₖ that minimizes the following cost function subject to xₖ₊₁ = Axₖ + Buₖ: + * + *

+   *     ∞
+   * J = Σ (xₖᵀQxₖ + uₖᵀRuₖ) ΔT
+   *    k=0
+   * 
+ * + *

This can be refactored as: + * + *

+   *     ∞ [xₖ]ᵀ[Q 0][xₖ]
+   * J = Σ [uₖ] [0 R][uₖ] ΔT
+   *    k=0
+   * 
+ * + * @param A Array containing elements of A in row-major order. + * @param B Array containing elements of B in row-major order. + * @param Q Array containing elements of Q in row-major order. + * @param R Array containing elements of R in row-major order. + * @param N Array containing elements of N in row-major order. + * @param states Number of states in A matrix. + * @param inputs Number of inputs in B matrix. + * @param S Array storage for DARE solution. + * @throws IllegalArgumentException if Q − NR⁻¹Nᵀ isn't symmetric positive semidefinite. + * @throws IllegalArgumentException if R isn't symmetric positive definite. + * @throws IllegalArgumentException if the (A − BR⁻¹Nᵀ, B) pair isn't stabilizable. + * @throws IllegalArgumentException if the (A, C) pair where Q = CᵀC isn't detectable. + */ + public static native void dareABQRN( + double[] A, + double[] B, + double[] Q, + double[] R, + double[] N, + int states, + int inputs, + double[] S); + + /** Sets whether JNI should be loaded in the static block. */ + public static class Helper { + private static AtomicBoolean extractOnStaticLoad = new AtomicBoolean(true); + + /** + * Returns true if the JNI should be loaded in the static block. + * + * @return True if the JNI should be loaded in the static block. + */ + public static boolean getExtractOnStaticLoad() { + return extractOnStaticLoad.get(); + } + + /** + * Sets whether the JNI should be loaded in the static block. + * + * @param load Whether the JNI should be loaded in the static block. + */ + public static void setExtractOnStaticLoad(boolean load) { + extractOnStaticLoad.set(load); + } + + /** Utility class. */ + private Helper() {} + } + + /** Utility class. */ + private DAREJNI() {} +} diff --git a/wpimath/src/main/java/edu/wpi/first/math/jni/EigenJNI.java b/wpimath/src/main/java/edu/wpi/first/math/jni/EigenJNI.java new file mode 100644 index 00000000000..ba7f2478d1e --- /dev/null +++ b/wpimath/src/main/java/edu/wpi/first/math/jni/EigenJNI.java @@ -0,0 +1,114 @@ +// Copyright (c) FIRST and other WPILib contributors. +// Open Source Software; you can modify and/or share it under the terms of +// the WPILib BSD license file in the root directory of this project. + +package edu.wpi.first.math.jni; + +import edu.wpi.first.util.RuntimeLoader; +import java.io.IOException; +import java.util.concurrent.atomic.AtomicBoolean; + +/** Eigen JNI. */ +public final class EigenJNI { + static boolean libraryLoaded = false; + + static { + if (Helper.getExtractOnStaticLoad()) { + try { + RuntimeLoader.loadLibrary("wpimathjni"); + } catch (Exception ex) { + ex.printStackTrace(); + System.exit(1); + } + libraryLoaded = true; + } + } + + /** + * Force load the library. + * + * @throws IOException If the library could not be loaded or found. + */ + public static synchronized void forceLoad() throws IOException { + if (libraryLoaded) { + return; + } + RuntimeLoader.loadLibrary("wpimathjni"); + libraryLoaded = true; + } + + /** + * Computes the matrix exp. + * + * @param src Array of elements of the matrix to be exponentiated. + * @param rows How many rows there are. + * @param dst Array where the result will be stored. + */ + public static native void exp(double[] src, int rows, double[] dst); + + /** + * Computes the matrix pow. + * + * @param src Array of elements of the matrix to be raised to a power. + * @param rows How many rows there are. + * @param exponent The exponent. + * @param dst Array where the result will be stored. + */ + public static native void pow(double[] src, int rows, double exponent, double[] dst); + + /** + * Performs an inplace rank one update (or downdate) of an upper triangular Cholesky decomposition + * matrix. + * + * @param mat Array of elements of the matrix to be updated. + * @param lowerTriangular Whether mat is lower triangular. + * @param rows How many rows there are. + * @param vec Vector to use for the rank update. + * @param sigma Sigma value to use for the rank update. + */ + public static native void rankUpdate( + double[] mat, int rows, double[] vec, double sigma, boolean lowerTriangular); + + /** + * Solves the least-squares problem Ax=B using a QR decomposition with full pivoting. + * + * @param A Array of elements of the A matrix. + * @param Arows Number of rows of the A matrix. + * @param Acols Number of rows of the A matrix. + * @param B Array of elements of the B matrix. + * @param Brows Number of rows of the B matrix. + * @param Bcols Number of rows of the B matrix. + * @param dst Array to store solution in. If A is m-n and B is m-p, dst is n-p. + */ + public static native void solveFullPivHouseholderQr( + double[] A, int Arows, int Acols, double[] B, int Brows, int Bcols, double[] dst); + + /** Sets whether JNI should be loaded in the static block. */ + public static class Helper { + private static AtomicBoolean extractOnStaticLoad = new AtomicBoolean(true); + + /** + * Returns true if the JNI should be loaded in the static block. + * + * @return True if the JNI should be loaded in the static block. + */ + public static boolean getExtractOnStaticLoad() { + return extractOnStaticLoad.get(); + } + + /** + * Sets whether the JNI should be loaded in the static block. + * + * @param load Whether the JNI should be loaded in the static block. + */ + public static void setExtractOnStaticLoad(boolean load) { + extractOnStaticLoad.set(load); + } + + /** Utility class. */ + private Helper() {} + } + + /** Utility class. */ + private EigenJNI() {} +} diff --git a/wpimath/src/main/java/edu/wpi/first/math/jni/Ellipse2dJNI.java b/wpimath/src/main/java/edu/wpi/first/math/jni/Ellipse2dJNI.java new file mode 100644 index 00000000000..e9a5c870677 --- /dev/null +++ b/wpimath/src/main/java/edu/wpi/first/math/jni/Ellipse2dJNI.java @@ -0,0 +1,92 @@ +// Copyright (c) FIRST and other WPILib contributors. +// Open Source Software; you can modify and/or share it under the terms of +// the WPILib BSD license file in the root directory of this project. + +package edu.wpi.first.math.jni; + +import edu.wpi.first.util.RuntimeLoader; +import java.io.IOException; +import java.util.concurrent.atomic.AtomicBoolean; + +/** Ellipse2d JNI. */ +public final class Ellipse2dJNI { + static boolean libraryLoaded = false; + + static { + if (Helper.getExtractOnStaticLoad()) { + try { + RuntimeLoader.loadLibrary("wpimathjni"); + } catch (Exception ex) { + ex.printStackTrace(); + System.exit(1); + } + libraryLoaded = true; + } + } + + /** + * Force load the library. + * + * @throws IOException If the library could not be loaded or found. + */ + public static synchronized void forceLoad() throws IOException { + if (libraryLoaded) { + return; + } + RuntimeLoader.loadLibrary("wpimathjni"); + libraryLoaded = true; + } + + /** + * Returns the nearest point that is contained within the ellipse. + * + *

Constructs an Ellipse2d object and runs its FindNearestPoint() method. + * + * @param centerX The x coordinate of the center of the ellipse in meters. + * @param centerY The y coordinate of the center of the ellipse in meters. + * @param centerHeading The ellipse's rotation in radians. + * @param xSemiAxis The x semi-axis in meters. + * @param ySemiAxis The y semi-axis in meters. + * @param pointX The x coordinate of the point that this will find the nearest point to. + * @param pointY The y coordinate of the point that this will find the nearest point to. + * @param nearestPoint Array to store nearest point into. + */ + public static native void findNearestPoint( + double centerX, + double centerY, + double centerHeading, + double xSemiAxis, + double ySemiAxis, + double pointX, + double pointY, + double[] nearestPoint); + + /** Sets whether JNI should be loaded in the static block. */ + public static class Helper { + private static AtomicBoolean extractOnStaticLoad = new AtomicBoolean(true); + + /** + * Returns true if the JNI should be loaded in the static block. + * + * @return True if the JNI should be loaded in the static block. + */ + public static boolean getExtractOnStaticLoad() { + return extractOnStaticLoad.get(); + } + + /** + * Sets whether the JNI should be loaded in the static block. + * + * @param load Whether the JNI should be loaded in the static block. + */ + public static void setExtractOnStaticLoad(boolean load) { + extractOnStaticLoad.set(load); + } + + /** Utility class. */ + private Helper() {} + } + + /** Utility class. */ + private Ellipse2dJNI() {} +} diff --git a/wpimath/src/main/java/edu/wpi/first/math/jni/Pose3dJNI.java b/wpimath/src/main/java/edu/wpi/first/math/jni/Pose3dJNI.java new file mode 100644 index 00000000000..a642eaa3a98 --- /dev/null +++ b/wpimath/src/main/java/edu/wpi/first/math/jni/Pose3dJNI.java @@ -0,0 +1,140 @@ +// Copyright (c) FIRST and other WPILib contributors. +// Open Source Software; you can modify and/or share it under the terms of +// the WPILib BSD license file in the root directory of this project. + +package edu.wpi.first.math.jni; + +import edu.wpi.first.util.RuntimeLoader; +import java.io.IOException; +import java.util.concurrent.atomic.AtomicBoolean; + +/** Pose3d JNI. */ +public final class Pose3dJNI { + static boolean libraryLoaded = false; + + static { + if (Helper.getExtractOnStaticLoad()) { + try { + RuntimeLoader.loadLibrary("wpimathjni"); + } catch (Exception ex) { + ex.printStackTrace(); + System.exit(1); + } + libraryLoaded = true; + } + } + + /** + * Force load the library. + * + * @throws IOException If the library could not be loaded or found. + */ + public static synchronized void forceLoad() throws IOException { + if (libraryLoaded) { + return; + } + RuntimeLoader.loadLibrary("wpimathjni"); + libraryLoaded = true; + } + + /** + * Obtain a Pose3d from a (constant curvature) velocity. + * + *

The double array returned is of the form [dx, dy, dz, qx, qy, qz]. + * + * @param poseX The pose's translational X component. + * @param poseY The pose's translational Y component. + * @param poseZ The pose's translational Z component. + * @param poseQw The pose quaternion's W component. + * @param poseQx The pose quaternion's X component. + * @param poseQy The pose quaternion's Y component. + * @param poseQz The pose quaternion's Z component. + * @param twistDx The twist's dx value. + * @param twistDy The twist's dy value. + * @param twistDz The twist's dz value. + * @param twistRx The twist's rx value. + * @param twistRy The twist's ry value. + * @param twistRz The twist's rz value. + * @return The new pose as a double array. + */ + public static native double[] exp( + double poseX, + double poseY, + double poseZ, + double poseQw, + double poseQx, + double poseQy, + double poseQz, + double twistDx, + double twistDy, + double twistDz, + double twistRx, + double twistRy, + double twistRz); + + /** + * Returns a Twist3d that maps the starting pose to the end pose. + * + *

The double array returned is of the form [dx, dy, dz, rx, ry, rz]. + * + * @param startX The starting pose's translational X component. + * @param startY The starting pose's translational Y component. + * @param startZ The starting pose's translational Z component. + * @param startQw The starting pose quaternion's W component. + * @param startQx The starting pose quaternion's X component. + * @param startQy The starting pose quaternion's Y component. + * @param startQz The starting pose quaternion's Z component. + * @param endX The ending pose's translational X component. + * @param endY The ending pose's translational Y component. + * @param endZ The ending pose's translational Z component. + * @param endQw The ending pose quaternion's W component. + * @param endQx The ending pose quaternion's X component. + * @param endQy The ending pose quaternion's Y component. + * @param endQz The ending pose quaternion's Z component. + * @return The twist that maps start to end as a double array. + */ + public static native double[] log( + double startX, + double startY, + double startZ, + double startQw, + double startQx, + double startQy, + double startQz, + double endX, + double endY, + double endZ, + double endQw, + double endQx, + double endQy, + double endQz); + + /** Sets whether JNI should be loaded in the static block. */ + public static class Helper { + private static AtomicBoolean extractOnStaticLoad = new AtomicBoolean(true); + + /** + * Returns true if the JNI should be loaded in the static block. + * + * @return True if the JNI should be loaded in the static block. + */ + public static boolean getExtractOnStaticLoad() { + return extractOnStaticLoad.get(); + } + + /** + * Sets whether the JNI should be loaded in the static block. + * + * @param load Whether the JNI should be loaded in the static block. + */ + public static void setExtractOnStaticLoad(boolean load) { + extractOnStaticLoad.set(load); + } + + /** Utility class. */ + private Helper() {} + } + + /** Utility class. */ + private Pose3dJNI() {} +} diff --git a/wpimath/src/main/java/edu/wpi/first/math/jni/StateSpaceUtilJNI.java b/wpimath/src/main/java/edu/wpi/first/math/jni/StateSpaceUtilJNI.java new file mode 100644 index 00000000000..9ee02b6c4c6 --- /dev/null +++ b/wpimath/src/main/java/edu/wpi/first/math/jni/StateSpaceUtilJNI.java @@ -0,0 +1,83 @@ +// Copyright (c) FIRST and other WPILib contributors. +// Open Source Software; you can modify and/or share it under the terms of +// the WPILib BSD license file in the root directory of this project. + +package edu.wpi.first.math.jni; + +import edu.wpi.first.util.RuntimeLoader; +import java.io.IOException; +import java.util.concurrent.atomic.AtomicBoolean; + +/** StateSpaceUtil JNI. */ +public final class StateSpaceUtilJNI { + static boolean libraryLoaded = false; + + static { + if (Helper.getExtractOnStaticLoad()) { + try { + RuntimeLoader.loadLibrary("wpimathjni"); + } catch (Exception ex) { + ex.printStackTrace(); + System.exit(1); + } + libraryLoaded = true; + } + } + + /** + * Force load the library. + * + * @throws IOException If the library could not be loaded or found. + */ + public static synchronized void forceLoad() throws IOException { + if (libraryLoaded) { + return; + } + RuntimeLoader.loadLibrary("wpimathjni"); + libraryLoaded = true; + } + + /** + * Returns true if (A, B) is a stabilizable pair. + * + *

(A, B) is stabilizable if and only if the uncontrollable eigenvalues of A, if any, have + * absolute values less than one, where an eigenvalue is uncontrollable if rank(lambda * I - A, B) + * < n where n is the number of states. + * + * @param states the number of states of the system. + * @param inputs the number of inputs to the system. + * @param A System matrix. + * @param B Input matrix. + * @return If the system is stabilizable. + */ + public static native boolean isStabilizable(int states, int inputs, double[] A, double[] B); + + /** Sets whether JNI should be loaded in the static block. */ + public static class Helper { + private static AtomicBoolean extractOnStaticLoad = new AtomicBoolean(true); + + /** + * Returns true if the JNI should be loaded in the static block. + * + * @return True if the JNI should be loaded in the static block. + */ + public static boolean getExtractOnStaticLoad() { + return extractOnStaticLoad.get(); + } + + /** + * Sets whether the JNI should be loaded in the static block. + * + * @param load Whether the JNI should be loaded in the static block. + */ + public static void setExtractOnStaticLoad(boolean load) { + extractOnStaticLoad.set(load); + } + + /** Utility class. */ + private Helper() {} + } + + /** Utility class. */ + private StateSpaceUtilJNI() {} +} diff --git a/wpimath/src/main/java/edu/wpi/first/math/jni/TrajectoryUtilJNI.java b/wpimath/src/main/java/edu/wpi/first/math/jni/TrajectoryUtilJNI.java new file mode 100644 index 00000000000..935b0c958b9 --- /dev/null +++ b/wpimath/src/main/java/edu/wpi/first/math/jni/TrajectoryUtilJNI.java @@ -0,0 +1,102 @@ +// Copyright (c) FIRST and other WPILib contributors. +// Open Source Software; you can modify and/or share it under the terms of +// the WPILib BSD license file in the root directory of this project. + +package edu.wpi.first.math.jni; + +import edu.wpi.first.util.RuntimeLoader; +import java.io.IOException; +import java.util.concurrent.atomic.AtomicBoolean; + +/** TrajectoryUtil JNI. */ +public final class TrajectoryUtilJNI { + static boolean libraryLoaded = false; + + static { + if (Helper.getExtractOnStaticLoad()) { + try { + RuntimeLoader.loadLibrary("wpimathjni"); + } catch (Exception ex) { + ex.printStackTrace(); + System.exit(1); + } + libraryLoaded = true; + } + } + + /** + * Force load the library. + * + * @throws IOException If the library could not be loaded or found. + */ + public static synchronized void forceLoad() throws IOException { + if (libraryLoaded) { + return; + } + RuntimeLoader.loadLibrary("wpimathjni"); + libraryLoaded = true; + } + + /** + * Loads a Pathweaver JSON. + * + * @param path The path to the JSON. + * @return A double array with the trajectory states from the JSON. + * @throws IOException if the JSON could not be read. + */ + public static native double[] fromPathweaverJson(String path) throws IOException; + + /** + * Converts a trajectory into a Pathweaver JSON and saves it. + * + * @param elements The elements of the trajectory. + * @param path The location to save the JSON to. + * @throws IOException if the JSON could not be written. + */ + public static native void toPathweaverJson(double[] elements, String path) throws IOException; + + /** + * Deserializes a trajectory JSON into a double[] of trajectory elements. + * + * @param json The JSON containing the serialized trajectory. + * @return A double array with the trajectory states. + */ + public static native double[] deserializeTrajectory(String json); + + /** + * Serializes the trajectory into a JSON string. + * + * @param elements The elements of the trajectory. + * @return A JSON containing the serialized trajectory. + */ + public static native String serializeTrajectory(double[] elements); + + /** Sets whether JNI should be loaded in the static block. */ + public static class Helper { + private static AtomicBoolean extractOnStaticLoad = new AtomicBoolean(true); + + /** + * Returns true if the JNI should be loaded in the static block. + * + * @return True if the JNI should be loaded in the static block. + */ + public static boolean getExtractOnStaticLoad() { + return extractOnStaticLoad.get(); + } + + /** + * Sets whether the JNI should be loaded in the static block. + * + * @param load Whether the JNI should be loaded in the static block. + */ + public static void setExtractOnStaticLoad(boolean load) { + extractOnStaticLoad.set(load); + } + + /** Utility class. */ + private Helper() {} + } + + /** Utility class. */ + private TrajectoryUtilJNI() {} +} diff --git a/wpimath/src/main/java/edu/wpi/first/math/kinematics/ChassisSpeeds.java b/wpimath/src/main/java/edu/wpi/first/math/kinematics/ChassisSpeeds.java index e223d7ebe3a..5ad8f36c5bb 100644 --- a/wpimath/src/main/java/edu/wpi/first/math/kinematics/ChassisSpeeds.java +++ b/wpimath/src/main/java/edu/wpi/first/math/kinematics/ChassisSpeeds.java @@ -391,13 +391,11 @@ public final int hashCode() { @Override public boolean equals(Object o) { - if (o == this) { - return true; - } - return o instanceof ChassisSpeeds c - && vxMetersPerSecond == c.vxMetersPerSecond - && vyMetersPerSecond == c.vyMetersPerSecond - && omegaRadiansPerSecond == c.omegaRadiansPerSecond; + return o == this + || o instanceof ChassisSpeeds c + && vxMetersPerSecond == c.vxMetersPerSecond + && vyMetersPerSecond == c.vyMetersPerSecond + && omegaRadiansPerSecond == c.omegaRadiansPerSecond; } @Override diff --git a/wpimath/src/main/java/edu/wpi/first/math/spline/CubicHermiteSpline.java b/wpimath/src/main/java/edu/wpi/first/math/spline/CubicHermiteSpline.java index 72108a5deb5..f9457bccdb9 100644 --- a/wpimath/src/main/java/edu/wpi/first/math/spline/CubicHermiteSpline.java +++ b/wpimath/src/main/java/edu/wpi/first/math/spline/CubicHermiteSpline.java @@ -105,6 +105,7 @@ public ControlVector getFinalControlVector() { * * @return The hermite basis matrix for cubic hermite spline interpolation. */ + @SuppressWarnings("PMD.UnnecessaryVarargsArrayCreation") private SimpleMatrix makeHermiteBasis() { if (hermiteBasis == null) { // Given P(i), P'(i), P(i+1), P'(i+1), the control vectors, we want to find @@ -148,6 +149,7 @@ private SimpleMatrix makeHermiteBasis() { * @param finalVector The control vector for the final point. * @return The control vector matrix for a dimension. */ + @SuppressWarnings("PMD.UnnecessaryVarargsArrayCreation") private SimpleMatrix getControlVectorFromArrays(double[] initialVector, double[] finalVector) { if (initialVector.length < 2 || finalVector.length < 2) { throw new IllegalArgumentException("Size of vectors must be 2 or greater."); diff --git a/wpimath/src/main/java/edu/wpi/first/math/spline/QuinticHermiteSpline.java b/wpimath/src/main/java/edu/wpi/first/math/spline/QuinticHermiteSpline.java index 5d38bef60a7..0dc712a3b8b 100644 --- a/wpimath/src/main/java/edu/wpi/first/math/spline/QuinticHermiteSpline.java +++ b/wpimath/src/main/java/edu/wpi/first/math/spline/QuinticHermiteSpline.java @@ -105,6 +105,7 @@ public ControlVector getFinalControlVector() { * * @return The hermite basis matrix for quintic hermite spline interpolation. */ + @SuppressWarnings("PMD.UnnecessaryVarargsArrayCreation") private SimpleMatrix makeHermiteBasis() { if (hermiteBasis == null) { // Given P(i), P'(i), P"(i), P(i+1), P'(i+1), P"(i+1), the control vectors, @@ -156,6 +157,7 @@ private SimpleMatrix makeHermiteBasis() { * @param finalVector The control vector for the final point. * @return The control vector matrix for a dimension. */ + @SuppressWarnings("PMD.UnnecessaryVarargsArrayCreation") private SimpleMatrix getControlVectorFromArrays(double[] initialVector, double[] finalVector) { if (initialVector.length != 3 || finalVector.length != 3) { throw new IllegalArgumentException("Size of vectors must be 3"); diff --git a/wpimath/src/main/java/edu/wpi/first/math/spline/SplineHelper.java b/wpimath/src/main/java/edu/wpi/first/math/spline/SplineHelper.java index 3ba27144039..2df70589c60 100644 --- a/wpimath/src/main/java/edu/wpi/first/math/spline/SplineHelper.java +++ b/wpimath/src/main/java/edu/wpi/first/math/spline/SplineHelper.java @@ -257,7 +257,7 @@ public static QuinticHermiteSpline[] optimizeCurvature(QuinticHermiteSpline[] sp CubicHermiteSpline cb = new CubicHermiteSpline(bInitial.x, bFinal.x, bInitial.y, bFinal.y); // Calculate the second derivatives at the knot points. - SimpleMatrix bases = new SimpleMatrix(4, 1, true, new double[] {1, 1, 1, 1}); + SimpleMatrix bases = new SimpleMatrix(4, 1, true, 1, 1, 1, 1); SimpleMatrix combinedA = ca.getCoefficients().mult(bases); double ddxA = combinedA.get(4, 0); diff --git a/wpimath/src/main/java/edu/wpi/first/math/spline/SplineParameterizer.java b/wpimath/src/main/java/edu/wpi/first/math/spline/SplineParameterizer.java index 5cf742b3da4..36bddb1feb1 100644 --- a/wpimath/src/main/java/edu/wpi/first/math/spline/SplineParameterizer.java +++ b/wpimath/src/main/java/edu/wpi/first/math/spline/SplineParameterizer.java @@ -57,7 +57,7 @@ private static class StackContents { } /** Exception for malformed splines. */ - public static class MalformedSplineException extends RuntimeException { + public static final class MalformedSplineException extends RuntimeException { /** * Create a new exception with the given message. * diff --git a/wpimath/src/main/java/edu/wpi/first/math/trajectory/ExponentialProfile.java b/wpimath/src/main/java/edu/wpi/first/math/trajectory/ExponentialProfile.java index fd2cef3d257..896ba6bdc51 100644 --- a/wpimath/src/main/java/edu/wpi/first/math/trajectory/ExponentialProfile.java +++ b/wpimath/src/main/java/edu/wpi/first/math/trajectory/ExponentialProfile.java @@ -70,7 +70,7 @@ public boolean isFinished(double t) { } /** Profile constraints. */ - public static class Constraints { + public static final class Constraints { /** Maximum unsigned input voltage. */ public final double maxInput; diff --git a/wpimath/src/main/java/edu/wpi/first/math/trajectory/TrajectoryUtil.java b/wpimath/src/main/java/edu/wpi/first/math/trajectory/TrajectoryUtil.java index f1b2d6a97b6..19832966df4 100644 --- a/wpimath/src/main/java/edu/wpi/first/math/trajectory/TrajectoryUtil.java +++ b/wpimath/src/main/java/edu/wpi/first/math/trajectory/TrajectoryUtil.java @@ -4,9 +4,9 @@ package edu.wpi.first.math.trajectory; -import edu.wpi.first.math.WPIMathJNI; import edu.wpi.first.math.geometry.Pose2d; import edu.wpi.first.math.geometry.Rotation2d; +import edu.wpi.first.math.jni.TrajectoryUtilJNI; import java.io.IOException; import java.nio.file.Path; import java.util.ArrayList; @@ -76,7 +76,7 @@ private static double[] getElementsFromTrajectory(Trajectory trajectory) { * @throws IOException if reading from the file fails. */ public static Trajectory fromPathweaverJson(Path path) throws IOException { - return createTrajectoryFromElements(WPIMathJNI.fromPathweaverJson(path.toString())); + return createTrajectoryFromElements(TrajectoryUtilJNI.fromPathweaverJson(path.toString())); } /** @@ -87,7 +87,7 @@ public static Trajectory fromPathweaverJson(Path path) throws IOException { * @throws IOException if writing to the file fails. */ public static void toPathweaverJson(Trajectory trajectory, Path path) throws IOException { - WPIMathJNI.toPathweaverJson(getElementsFromTrajectory(trajectory), path.toString()); + TrajectoryUtilJNI.toPathweaverJson(getElementsFromTrajectory(trajectory), path.toString()); } /** @@ -98,7 +98,7 @@ public static void toPathweaverJson(Trajectory trajectory, Path path) throws IOE * @throws TrajectorySerializationException if deserialization of the string fails. */ public static Trajectory deserializeTrajectory(String json) { - return createTrajectoryFromElements(WPIMathJNI.deserializeTrajectory(json)); + return createTrajectoryFromElements(TrajectoryUtilJNI.deserializeTrajectory(json)); } /** @@ -109,7 +109,7 @@ public static Trajectory deserializeTrajectory(String json) { * @throws TrajectorySerializationException if serialization of the trajectory fails. */ public static String serializeTrajectory(Trajectory trajectory) { - return WPIMathJNI.serializeTrajectory(getElementsFromTrajectory(trajectory)); + return TrajectoryUtilJNI.serializeTrajectory(getElementsFromTrajectory(trajectory)); } /** Exception for trajectory serialization failure. */ diff --git a/wpimath/src/main/native/cpp/jni/WPIMathJNI_ArmFeedforward.cpp b/wpimath/src/main/native/cpp/jni/ArmFeedforwardJNI.cpp similarity index 86% rename from wpimath/src/main/native/cpp/jni/WPIMathJNI_ArmFeedforward.cpp rename to wpimath/src/main/native/cpp/jni/ArmFeedforwardJNI.cpp index 3428c52688e..ca3a072d644 100644 --- a/wpimath/src/main/native/cpp/jni/WPIMathJNI_ArmFeedforward.cpp +++ b/wpimath/src/main/native/cpp/jni/ArmFeedforwardJNI.cpp @@ -6,7 +6,7 @@ #include -#include "edu_wpi_first_math_WPIMathJNI.h" +#include "edu_wpi_first_math_jni_ArmFeedforwardJNI.h" #include "frc/controller/ArmFeedforward.h" using namespace wpi::java; @@ -14,12 +14,12 @@ using namespace wpi::java; extern "C" { /* - * Class: edu_wpi_first_math_WPIMathJNI + * Class: edu_wpi_first_math_jni_ArmFeedforwardJNI * Method: calculate * Signature: (DDDDDDDD)D */ JNIEXPORT jdouble JNICALL -Java_edu_wpi_first_math_WPIMathJNI_calculate +Java_edu_wpi_first_math_jni_ArmFeedforwardJNI_calculate (JNIEnv* env, jclass, jdouble ks, jdouble kv, jdouble ka, jdouble kg, jdouble currentAngle, jdouble currentVelocity, jdouble nextVelocity, jdouble dt) diff --git a/wpimath/src/main/native/cpp/jni/WPIMathJNI_DARE.cpp b/wpimath/src/main/native/cpp/jni/DAREJNI.cpp similarity index 93% rename from wpimath/src/main/native/cpp/jni/WPIMathJNI_DARE.cpp rename to wpimath/src/main/native/cpp/jni/DAREJNI.cpp index e5c3ac59125..c4b530194bf 100644 --- a/wpimath/src/main/native/cpp/jni/WPIMathJNI_DARE.cpp +++ b/wpimath/src/main/native/cpp/jni/DAREJNI.cpp @@ -8,8 +8,8 @@ #include -#include "WPIMathJNI_Exceptions.h" -#include "edu_wpi_first_math_WPIMathJNI.h" +#include "Exceptions.h" +#include "edu_wpi_first_math_jni_DAREJNI.h" #include "frc/DARE.h" using namespace wpi::java; @@ -17,12 +17,12 @@ using namespace wpi::java; extern "C" { /* - * Class: edu_wpi_first_math_WPIMathJNI + * Class: edu_wpi_first_math_jni_DAREJNI * Method: dareDetailABQR * Signature: ([D[D[D[DII[D)V */ JNIEXPORT void JNICALL -Java_edu_wpi_first_math_WPIMathJNI_dareDetailABQR +Java_edu_wpi_first_math_jni_DAREJNI_dareDetailABQR (JNIEnv* env, jclass, jdoubleArray A, jdoubleArray B, jdoubleArray Q, jdoubleArray R, jint states, jint inputs, jdoubleArray S) { @@ -54,12 +54,12 @@ Java_edu_wpi_first_math_WPIMathJNI_dareDetailABQR } /* - * Class: edu_wpi_first_math_WPIMathJNI + * Class: edu_wpi_first_math_jni_DAREJNI * Method: dareDetailABQRN * Signature: ([D[D[D[D[DII[D)V */ JNIEXPORT void JNICALL -Java_edu_wpi_first_math_WPIMathJNI_dareDetailABQRN +Java_edu_wpi_first_math_jni_DAREJNI_dareDetailABQRN (JNIEnv* env, jclass, jdoubleArray A, jdoubleArray B, jdoubleArray Q, jdoubleArray R, jdoubleArray N, jint states, jint inputs, jdoubleArray S) { @@ -95,12 +95,12 @@ Java_edu_wpi_first_math_WPIMathJNI_dareDetailABQRN } /* - * Class: edu_wpi_first_math_WPIMathJNI + * Class: edu_wpi_first_math_jni_DAREJNI * Method: dareABQR * Signature: ([D[D[D[DII[D)V */ JNIEXPORT void JNICALL -Java_edu_wpi_first_math_WPIMathJNI_dareABQR +Java_edu_wpi_first_math_jni_DAREJNI_dareABQR (JNIEnv* env, jclass, jdoubleArray A, jdoubleArray B, jdoubleArray Q, jdoubleArray R, jint states, jint inputs, jdoubleArray S) { @@ -133,12 +133,12 @@ Java_edu_wpi_first_math_WPIMathJNI_dareABQR } /* - * Class: edu_wpi_first_math_WPIMathJNI + * Class: edu_wpi_first_math_jni_DAREJNI * Method: dareABQRN * Signature: ([D[D[D[D[DII[D)V */ JNIEXPORT void JNICALL -Java_edu_wpi_first_math_WPIMathJNI_dareABQRN +Java_edu_wpi_first_math_jni_DAREJNI_dareABQRN (JNIEnv* env, jclass, jdoubleArray A, jdoubleArray B, jdoubleArray Q, jdoubleArray R, jdoubleArray N, jint states, jint inputs, jdoubleArray S) { diff --git a/wpimath/src/main/native/cpp/jni/WPIMathJNI_Eigen.cpp b/wpimath/src/main/native/cpp/jni/EigenJNI.cpp similarity index 87% rename from wpimath/src/main/native/cpp/jni/WPIMathJNI_Eigen.cpp rename to wpimath/src/main/native/cpp/jni/EigenJNI.cpp index 642a2bad69d..e024f994e7a 100644 --- a/wpimath/src/main/native/cpp/jni/WPIMathJNI_Eigen.cpp +++ b/wpimath/src/main/native/cpp/jni/EigenJNI.cpp @@ -10,19 +10,19 @@ #include #include -#include "edu_wpi_first_math_WPIMathJNI.h" +#include "edu_wpi_first_math_jni_EigenJNI.h" using namespace wpi::java; extern "C" { /* - * Class: edu_wpi_first_math_WPIMathJNI + * Class: edu_wpi_first_math_jni_EigenJNI * Method: exp * Signature: ([DI[D)V */ JNIEXPORT void JNICALL -Java_edu_wpi_first_math_WPIMathJNI_exp +Java_edu_wpi_first_math_jni_EigenJNI_exp (JNIEnv* env, jclass, jdoubleArray src, jint rows, jdoubleArray dst) { JSpan arrayBody{env, src}; @@ -37,12 +37,12 @@ Java_edu_wpi_first_math_WPIMathJNI_exp } /* - * Class: edu_wpi_first_math_WPIMathJNI + * Class: edu_wpi_first_math_jni_EigenJNI * Method: pow * Signature: ([DID[D)V */ JNIEXPORT void JNICALL -Java_edu_wpi_first_math_WPIMathJNI_pow +Java_edu_wpi_first_math_jni_EigenJNI_pow (JNIEnv* env, jclass, jdoubleArray src, jint rows, jdouble exponent, jdoubleArray dst) { @@ -58,12 +58,12 @@ Java_edu_wpi_first_math_WPIMathJNI_pow } /* - * Class: edu_wpi_first_math_WPIMathJNI + * Class: edu_wpi_first_math_jni_EigenJNI * Method: rankUpdate * Signature: ([DI[DDZ)V */ JNIEXPORT void JNICALL -Java_edu_wpi_first_math_WPIMathJNI_rankUpdate +Java_edu_wpi_first_math_jni_EigenJNI_rankUpdate (JNIEnv* env, jclass, jdoubleArray mat, jint rows, jdoubleArray vec, jdouble sigma, jboolean lowerTriangular) { @@ -84,12 +84,12 @@ Java_edu_wpi_first_math_WPIMathJNI_rankUpdate } /* - * Class: edu_wpi_first_math_WPIMathJNI + * Class: edu_wpi_first_math_jni_EigenJNI * Method: solveFullPivHouseholderQr * Signature: ([DII[DII[D)V */ JNIEXPORT void JNICALL -Java_edu_wpi_first_math_WPIMathJNI_solveFullPivHouseholderQr +Java_edu_wpi_first_math_jni_EigenJNI_solveFullPivHouseholderQr (JNIEnv* env, jclass, jdoubleArray A, jint Arows, jint Acols, jdoubleArray B, jint Brows, jint Bcols, jdoubleArray dst) { diff --git a/wpimath/src/main/native/cpp/jni/WPIMathJNI_Ellipse2d.cpp b/wpimath/src/main/native/cpp/jni/Ellipse2dJNI.cpp similarity index 84% rename from wpimath/src/main/native/cpp/jni/WPIMathJNI_Ellipse2d.cpp rename to wpimath/src/main/native/cpp/jni/Ellipse2dJNI.cpp index ae6f88a21ee..cc53d693154 100644 --- a/wpimath/src/main/native/cpp/jni/WPIMathJNI_Ellipse2d.cpp +++ b/wpimath/src/main/native/cpp/jni/Ellipse2dJNI.cpp @@ -7,7 +7,7 @@ #include #include -#include "edu_wpi_first_math_WPIMathJNI.h" +#include "edu_wpi_first_math_jni_Ellipse2dJNI.h" #include "frc/geometry/Ellipse2d.h" using namespace wpi::java; @@ -15,12 +15,12 @@ using namespace wpi::java; extern "C" { /* - * Class: edu_wpi_first_math_WPIMathJNI - * Method: ellipse2dFindNearestPoint + * Class: edu_wpi_first_math_jni_Ellipse2dJNI + * Method: findNearestPoint * Signature: (DDDDDDD[D)V */ JNIEXPORT void JNICALL -Java_edu_wpi_first_math_WPIMathJNI_ellipse2dFindNearestPoint +Java_edu_wpi_first_math_jni_Ellipse2dJNI_findNearestPoint (JNIEnv* env, jclass, jdouble centerX, jdouble centerY, jdouble centerHeading, jdouble xSemiAxis, jdouble ySemiAxis, jdouble pointX, jdouble pointY, jdoubleArray nearestPoint) diff --git a/wpimath/src/main/native/cpp/jni/WPIMathJNI_Exceptions.cpp b/wpimath/src/main/native/cpp/jni/Exceptions.cpp similarity index 97% rename from wpimath/src/main/native/cpp/jni/WPIMathJNI_Exceptions.cpp rename to wpimath/src/main/native/cpp/jni/Exceptions.cpp index 7f5a03f6fa0..6e217bfafc0 100644 --- a/wpimath/src/main/native/cpp/jni/WPIMathJNI_Exceptions.cpp +++ b/wpimath/src/main/native/cpp/jni/Exceptions.cpp @@ -2,7 +2,7 @@ // Open Source Software; you can modify and/or share it under the terms of // the WPILib BSD license file in the root directory of this project. -#include "WPIMathJNI_Exceptions.h" +#include "Exceptions.h" #include diff --git a/wpimath/src/main/native/cpp/jni/WPIMathJNI_Exceptions.h b/wpimath/src/main/native/cpp/jni/Exceptions.h similarity index 100% rename from wpimath/src/main/native/cpp/jni/WPIMathJNI_Exceptions.h rename to wpimath/src/main/native/cpp/jni/Exceptions.h diff --git a/wpimath/src/main/native/cpp/jni/WPIMathJNI_Pose3d.cpp b/wpimath/src/main/native/cpp/jni/Pose3dJNI.cpp similarity index 89% rename from wpimath/src/main/native/cpp/jni/WPIMathJNI_Pose3d.cpp rename to wpimath/src/main/native/cpp/jni/Pose3dJNI.cpp index f985231e547..e41e0eb7030 100644 --- a/wpimath/src/main/native/cpp/jni/WPIMathJNI_Pose3d.cpp +++ b/wpimath/src/main/native/cpp/jni/Pose3dJNI.cpp @@ -6,7 +6,7 @@ #include -#include "edu_wpi_first_math_WPIMathJNI.h" +#include "edu_wpi_first_math_jni_Pose3dJNI.h" #include "frc/geometry/Pose3d.h" using namespace wpi::java; @@ -14,12 +14,12 @@ using namespace wpi::java; extern "C" { /* - * Class: edu_wpi_first_math_WPIMathJNI - * Method: expPose3d + * Class: edu_wpi_first_math_jni_Pose3dJNI + * Method: exp * Signature: (DDDDDDDDDDDDD)[D */ JNIEXPORT jdoubleArray JNICALL -Java_edu_wpi_first_math_WPIMathJNI_expPose3d +Java_edu_wpi_first_math_jni_Pose3dJNI_exp (JNIEnv* env, jclass, jdouble poseX, jdouble poseY, jdouble poseZ, jdouble poseQw, jdouble poseQx, jdouble poseQy, jdouble poseQz, jdouble twistDx, jdouble twistDy, jdouble twistDz, jdouble twistRx, @@ -42,12 +42,12 @@ Java_edu_wpi_first_math_WPIMathJNI_expPose3d } /* - * Class: edu_wpi_first_math_WPIMathJNI - * Method: logPose3d + * Class: edu_wpi_first_math_jni_Pose3dJNI + * Method: log * Signature: (DDDDDDDDDDDDDD)[D */ JNIEXPORT jdoubleArray JNICALL -Java_edu_wpi_first_math_WPIMathJNI_logPose3d +Java_edu_wpi_first_math_jni_Pose3dJNI_log (JNIEnv* env, jclass, jdouble startX, jdouble startY, jdouble startZ, jdouble startQw, jdouble startQx, jdouble startQy, jdouble startQz, jdouble endX, jdouble endY, jdouble endZ, jdouble endQw, jdouble endQx, diff --git a/wpimath/src/main/native/cpp/jni/WPIMathJNI_StateSpaceUtil.cpp b/wpimath/src/main/native/cpp/jni/StateSpaceUtilJNI.cpp similarity index 86% rename from wpimath/src/main/native/cpp/jni/WPIMathJNI_StateSpaceUtil.cpp rename to wpimath/src/main/native/cpp/jni/StateSpaceUtilJNI.cpp index dc3dfddf33d..e13d659bf2d 100644 --- a/wpimath/src/main/native/cpp/jni/WPIMathJNI_StateSpaceUtil.cpp +++ b/wpimath/src/main/native/cpp/jni/StateSpaceUtilJNI.cpp @@ -7,7 +7,7 @@ #include #include -#include "edu_wpi_first_math_WPIMathJNI.h" +#include "edu_wpi_first_math_jni_StateSpaceUtilJNI.h" #include "frc/StateSpaceUtil.h" using namespace wpi::java; @@ -15,12 +15,12 @@ using namespace wpi::java; extern "C" { /* - * Class: edu_wpi_first_math_WPIMathJNI + * Class: edu_wpi_first_math_jni_StateSpaceUtilJNI * Method: isStabilizable * Signature: (II[D[D)Z */ JNIEXPORT jboolean JNICALL -Java_edu_wpi_first_math_WPIMathJNI_isStabilizable +Java_edu_wpi_first_math_jni_StateSpaceUtilJNI_isStabilizable (JNIEnv* env, jclass, jint states, jint inputs, jdoubleArray aSrc, jdoubleArray bSrc) { diff --git a/wpimath/src/main/native/cpp/jni/WPIMathJNI_Trajectory.cpp b/wpimath/src/main/native/cpp/jni/TrajectoryUtilJNI.cpp similarity index 86% rename from wpimath/src/main/native/cpp/jni/WPIMathJNI_Trajectory.cpp rename to wpimath/src/main/native/cpp/jni/TrajectoryUtilJNI.cpp index 3359da984ca..1066e037c8c 100644 --- a/wpimath/src/main/native/cpp/jni/WPIMathJNI_Trajectory.cpp +++ b/wpimath/src/main/native/cpp/jni/TrajectoryUtilJNI.cpp @@ -8,8 +8,8 @@ #include -#include "WPIMathJNI_Exceptions.h" -#include "edu_wpi_first_math_WPIMathJNI.h" +#include "Exceptions.h" +#include "edu_wpi_first_math_jni_TrajectoryUtilJNI.h" #include "frc/trajectory/TrajectoryUtil.h" using namespace wpi::java; @@ -57,12 +57,12 @@ frc::Trajectory CreateTrajectoryFromElements(std::span elements) { extern "C" { /* - * Class: edu_wpi_first_math_WPIMathJNI + * Class: edu_wpi_first_math_jni_TrajectoryUtilJNI * Method: fromPathweaverJson * Signature: (Ljava/lang/String;)[D */ JNIEXPORT jdoubleArray JNICALL -Java_edu_wpi_first_math_WPIMathJNI_fromPathweaverJson +Java_edu_wpi_first_math_jni_TrajectoryUtilJNI_fromPathweaverJson (JNIEnv* env, jclass, jstring path) { try { @@ -77,12 +77,12 @@ Java_edu_wpi_first_math_WPIMathJNI_fromPathweaverJson } /* - * Class: edu_wpi_first_math_WPIMathJNI + * Class: edu_wpi_first_math_jni_TrajectoryUtilJNI * Method: toPathweaverJson * Signature: ([DLjava/lang/String;)V */ JNIEXPORT void JNICALL -Java_edu_wpi_first_math_WPIMathJNI_toPathweaverJson +Java_edu_wpi_first_math_jni_TrajectoryUtilJNI_toPathweaverJson (JNIEnv* env, jclass, jdoubleArray elements, jstring path) { try { @@ -96,12 +96,12 @@ Java_edu_wpi_first_math_WPIMathJNI_toPathweaverJson } /* - * Class: edu_wpi_first_math_WPIMathJNI + * Class: edu_wpi_first_math_jni_TrajectoryUtilJNI * Method: deserializeTrajectory * Signature: (Ljava/lang/String;)[D */ JNIEXPORT jdoubleArray JNICALL -Java_edu_wpi_first_math_WPIMathJNI_deserializeTrajectory +Java_edu_wpi_first_math_jni_TrajectoryUtilJNI_deserializeTrajectory (JNIEnv* env, jclass, jstring json) { try { @@ -116,12 +116,12 @@ Java_edu_wpi_first_math_WPIMathJNI_deserializeTrajectory } /* - * Class: edu_wpi_first_math_WPIMathJNI + * Class: edu_wpi_first_math_jni_TrajectoryUtilJNI * Method: serializeTrajectory * Signature: ([D)Ljava/lang/String; */ JNIEXPORT jstring JNICALL -Java_edu_wpi_first_math_WPIMathJNI_serializeTrajectory +Java_edu_wpi_first_math_jni_TrajectoryUtilJNI_serializeTrajectory (JNIEnv* env, jclass, jdoubleArray elements) { try { diff --git a/wpimath/src/main/native/include/frc/MathUtil.h b/wpimath/src/main/native/include/frc/MathUtil.h index 26f106ef6bf..76e11ce64b0 100644 --- a/wpimath/src/main/native/include/frc/MathUtil.h +++ b/wpimath/src/main/native/include/frc/MathUtil.h @@ -169,4 +169,41 @@ constexpr units::radian_t AngleModulus(units::radian_t angle) { units::radian_t{std::numbers::pi}); } +// floorDiv and floorMod algorithms taken from Java + +/** + * Returns the largest (closest to positive infinity) + * {@code int} value that is less than or equal to the algebraic quotient. + * + * @param x the dividend + * @param y the divisor + * @return the largest (closest to positive infinity) + * {@code int} value that is less than or equal to the algebraic quotient. + */ +constexpr std::signed_integral auto FloorDiv(std::signed_integral auto x, + std::signed_integral auto y) { + auto quot = x / y; + auto rem = x % y; + // if the signs are different and modulo not zero, round down + if ((x < 0) != (y < 0) && rem != 0) { + --quot; + } + return quot; +} + +/** + * Returns the floor modulus of the {@code int} arguments. + *

+ * The floor modulus is {@code r = x - (floorDiv(x, y) * y)}, + * has the same sign as the divisor {@code y} or is zero, and + * is in the range of {@code -std::abs(y) < r < +std::abs(y)}. + * + * @param x the dividend + * @param y the divisor + * @return the floor modulus {@code x - (floorDiv(x, y) * y)} + */ +constexpr std::signed_integral auto FloorMod(std::signed_integral auto x, + std::signed_integral auto y) { + return x - FloorDiv(x, y) * y; +} } // namespace frc diff --git a/wpimath/src/main/native/include/frc/filter/LinearFilter.h b/wpimath/src/main/native/include/frc/filter/LinearFilter.h index 3f5462d5947..52eec9de2b2 100644 --- a/wpimath/src/main/native/include/frc/filter/LinearFilter.h +++ b/wpimath/src/main/native/include/frc/filter/LinearFilter.h @@ -367,6 +367,7 @@ class LinearFilter { m_outputs.push_front(retVal); } + m_lastOutput = retVal; return retVal; } @@ -375,13 +376,14 @@ class LinearFilter { * * @return The last value. */ - T LastValue() const { return m_outputs.front(); } + T LastValue() const { return m_lastOutput; } private: wpi::circular_buffer m_inputs; wpi::circular_buffer m_outputs; std::vector m_inputGains; std::vector m_outputGains; + T m_lastOutput{0.0}; /** * Factorial of n. diff --git a/wpimath/src/main/native/include/frc/trajectory/TrapezoidProfile.h b/wpimath/src/main/native/include/frc/trajectory/TrapezoidProfile.h index 90c5cd973fe..0f4c65ec884 100644 --- a/wpimath/src/main/native/include/frc/trajectory/TrapezoidProfile.h +++ b/wpimath/src/main/native/include/frc/trajectory/TrapezoidProfile.h @@ -107,22 +107,6 @@ class TrapezoidProfile { TrapezoidProfile(TrapezoidProfile&&) = default; TrapezoidProfile& operator=(TrapezoidProfile&&) = default; - /** - * Calculates the position and velocity for the profile at a time t where the - * current state is at time t = 0. - * - * @param t How long to advance from the current state toward the desired - * state. - * @return The position and velocity of the profile at time t. - * @deprecated Pass the desired and current state into calculate instead of - * constructing a new TrapezoidProfile with the desired and current state - */ - [[deprecated( - "Pass the desired and current state into calculate instead of " - "constructing a new TrapezoidProfile with the desired and current " - "state")]] - State Calculate(units::second_t t) const; - /** * Calculates the position and velocity for the profile at a time t where the * current state is at time t = 0. diff --git a/wpimath/src/main/native/thirdparty/eigen/include/Eigen/src/Core/util/DisableStupidWarnings.h b/wpimath/src/main/native/thirdparty/eigen/include/Eigen/src/Core/util/DisableStupidWarnings.h index 60a1f063171..1182198231a 100644 --- a/wpimath/src/main/native/thirdparty/eigen/include/Eigen/src/Core/util/DisableStupidWarnings.h +++ b/wpimath/src/main/native/thirdparty/eigen/include/Eigen/src/Core/util/DisableStupidWarnings.h @@ -81,7 +81,7 @@ // See: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=89325 #pragma GCC diagnostic ignored "-Wattributes" #endif -#if __GNUC__ >= 11 && __GNUC__ <= 13 +#if __GNUC__ >= 11 #pragma GCC diagnostic ignored "-Wmaybe-uninitialized" #endif #if __GNUC__ >= 12 diff --git a/wpimath/src/main/native/thirdparty/sleipnir/.styleguide b/wpimath/src/main/native/thirdparty/sleipnir/.styleguide index 2476200a876..fc51b044a61 100644 --- a/wpimath/src/main/native/thirdparty/sleipnir/.styleguide +++ b/wpimath/src/main/native/thirdparty/sleipnir/.styleguide @@ -17,7 +17,6 @@ modifiableFileExclude { includeOtherLibs { ^Eigen/ ^catch2/ - ^fmt/ ^pybind11/ ^sleipnir/ } diff --git a/wpimath/src/main/native/thirdparty/sleipnir/include/sleipnir/autodiff/Expression.hpp b/wpimath/src/main/native/thirdparty/sleipnir/include/sleipnir/autodiff/Expression.hpp index fc503c10a20..7aa715a0aa5 100644 --- a/wpimath/src/main/native/thirdparty/sleipnir/include/sleipnir/autodiff/Expression.hpp +++ b/wpimath/src/main/native/thirdparty/sleipnir/include/sleipnir/autodiff/Expression.hpp @@ -21,8 +21,7 @@ namespace sleipnir::detail { struct SLEIPNIR_DLLEXPORT Expression; -inline constexpr void IntrusiveSharedPtrIncRefCount(Expression* expr); -// FIXME: Make constexpr after upgrading to GCC 12+ +inline void IntrusiveSharedPtrIncRefCount(Expression* expr); inline void IntrusiveSharedPtrDecRefCount(Expression* expr); /** @@ -410,7 +409,7 @@ SLEIPNIR_DLLEXPORT inline ExpressionPtr sqrt(const ExpressionPtr& x); * * @param expr The shared pointer's managed object. */ -inline constexpr void IntrusiveSharedPtrIncRefCount(Expression* expr) { +inline void IntrusiveSharedPtrIncRefCount(Expression* expr) { ++expr->refCount; } @@ -419,7 +418,6 @@ inline constexpr void IntrusiveSharedPtrIncRefCount(Expression* expr) { * * @param expr The shared pointer's managed object. */ -// FIXME: Make constexpr after upgrading to GCC 12+ inline void IntrusiveSharedPtrDecRefCount(Expression* expr) { // If a deeply nested tree is being deallocated all at once, calling the // Expression destructor when expr's refcount reaches zero can cause a stack diff --git a/wpimath/src/main/native/thirdparty/sleipnir/include/sleipnir/autodiff/VariableBlock.hpp b/wpimath/src/main/native/thirdparty/sleipnir/include/sleipnir/autodiff/VariableBlock.hpp index 44c48fb6ae2..3e06601aa47 100644 --- a/wpimath/src/main/native/thirdparty/sleipnir/include/sleipnir/autodiff/VariableBlock.hpp +++ b/wpimath/src/main/native/thirdparty/sleipnir/include/sleipnir/autodiff/VariableBlock.hpp @@ -26,6 +26,8 @@ class VariableBlock { /** * Assigns a VariableBlock to the block. + * + * @param values VariableBlock of values. */ VariableBlock& operator=(const VariableBlock& values) { if (this == &values) { @@ -56,6 +58,8 @@ class VariableBlock { /** * Assigns a VariableBlock to the block. + * + * @param values VariableBlock of values. */ VariableBlock& operator=(VariableBlock&& values) { if (this == &values) { @@ -124,6 +128,8 @@ class VariableBlock { * Assigns a double to the block. * * This only works for blocks with one row and one column. + * + * @param value Value to assign. */ VariableBlock& SetValue(double value) { Assert(Rows() == 1 && Cols() == 1); @@ -135,6 +141,8 @@ class VariableBlock { /** * Assigns an Eigen matrix to the block. + * + * @param values Eigen matrix of values to assign. */ template VariableBlock& operator=(const Eigen::MatrixBase& values) { @@ -152,6 +160,8 @@ class VariableBlock { /** * Sets block's internal values. + * + * @param values Eigen matrix of values. */ template requires std::same_as @@ -170,6 +180,8 @@ class VariableBlock { /** * Assigns a VariableMatrix to the block. + * + * @param values VariableMatrix of values. */ VariableBlock& operator=(const Mat& values) { Assert(Rows() == values.Rows()); @@ -185,6 +197,8 @@ class VariableBlock { /** * Assigns a VariableMatrix to the block. + * + * @param values VariableMatrix of values. */ VariableBlock& operator=(Mat&& values) { Assert(Rows() == values.Rows()); diff --git a/wpimath/src/main/native/thirdparty/sleipnir/include/sleipnir/autodiff/VariableMatrix.hpp b/wpimath/src/main/native/thirdparty/sleipnir/include/sleipnir/autodiff/VariableMatrix.hpp index 68c71a5a372..ecd7a82d077 100644 --- a/wpimath/src/main/native/thirdparty/sleipnir/include/sleipnir/autodiff/VariableMatrix.hpp +++ b/wpimath/src/main/native/thirdparty/sleipnir/include/sleipnir/autodiff/VariableMatrix.hpp @@ -137,6 +137,8 @@ class SLEIPNIR_DLLEXPORT VariableMatrix { /** * Constructs a VariableMatrix from an Eigen matrix. + * + * @param values Eigen matrix of values. */ template VariableMatrix(const Eigen::MatrixBase& values) // NOLINT @@ -152,6 +154,8 @@ class SLEIPNIR_DLLEXPORT VariableMatrix { /** * Constructs a VariableMatrix from an Eigen diagonal matrix. + * + * @param values Diagonal matrix of values. */ template VariableMatrix(const Eigen::DiagonalBase& values) // NOLINT @@ -171,6 +175,8 @@ class SLEIPNIR_DLLEXPORT VariableMatrix { /** * Assigns an Eigen matrix to a VariableMatrix. + * + * @param values Eigen matrix of values. */ template VariableMatrix& operator=(const Eigen::MatrixBase& values) { @@ -188,6 +194,8 @@ class SLEIPNIR_DLLEXPORT VariableMatrix { /** * Sets the VariableMatrix's internal values. + * + * @param values Eigen matrix of values. */ template requires std::same_as @@ -206,6 +214,8 @@ class SLEIPNIR_DLLEXPORT VariableMatrix { /** * Constructs a scalar VariableMatrix from a Variable. + * + * @param variable Variable. */ VariableMatrix(const Variable& variable) // NOLINT : m_rows{1}, m_cols{1} { @@ -214,6 +224,8 @@ class SLEIPNIR_DLLEXPORT VariableMatrix { /** * Constructs a scalar VariableMatrix from a Variable. + * + * @param variable Variable. */ VariableMatrix(Variable&& variable) : m_rows{1}, m_cols{1} { // NOLINT m_storage.emplace_back(std::move(variable)); @@ -221,6 +233,8 @@ class SLEIPNIR_DLLEXPORT VariableMatrix { /** * Constructs a VariableMatrix from a VariableBlock. + * + * @param values VariableBlock of values. */ VariableMatrix(const VariableBlock& values) // NOLINT : m_rows{values.Rows()}, m_cols{values.Cols()} { @@ -233,6 +247,8 @@ class SLEIPNIR_DLLEXPORT VariableMatrix { /** * Constructs a VariableMatrix from a VariableBlock. + * + * @param values VariableBlock of values. */ VariableMatrix(const VariableBlock& values) // NOLINT : m_rows{values.Rows()}, m_cols{values.Cols()} { diff --git a/wpimath/src/main/native/thirdparty/sleipnir/include/sleipnir/util/Concepts.hpp b/wpimath/src/main/native/thirdparty/sleipnir/include/sleipnir/util/Concepts.hpp index 3f4f7252394..653200e708c 100644 --- a/wpimath/src/main/native/thirdparty/sleipnir/include/sleipnir/util/Concepts.hpp +++ b/wpimath/src/main/native/thirdparty/sleipnir/include/sleipnir/util/Concepts.hpp @@ -15,6 +15,10 @@ template concept ScalarLike = std::same_as || std::same_as || std::same_as; +template +concept SleipnirMatrixLike = std::same_as || + std::same_as>; + template concept EigenMatrixLike = std::derived_from>; @@ -23,8 +27,6 @@ template concept EigenSolver = requires(T t) { t.solve(Eigen::VectorXd{}); }; template -concept MatrixLike = - std::same_as || - std::same_as> || EigenMatrixLike; +concept MatrixLike = SleipnirMatrixLike || EigenMatrixLike; } // namespace sleipnir diff --git a/wpimath/src/main/native/thirdparty/sleipnir/src/.styleguide b/wpimath/src/main/native/thirdparty/sleipnir/src/.styleguide index 8251a490677..f3b2f0cf9e6 100644 --- a/wpimath/src/main/native/thirdparty/sleipnir/src/.styleguide +++ b/wpimath/src/main/native/thirdparty/sleipnir/src/.styleguide @@ -8,5 +8,4 @@ cppSrcFileInclude { includeOtherLibs { ^Eigen/ - ^fmt/ } diff --git a/wpimath/src/test/java/edu/wpi/first/math/jni/ArmFeedforwardJNITest.java b/wpimath/src/test/java/edu/wpi/first/math/jni/ArmFeedforwardJNITest.java new file mode 100644 index 00000000000..7fadaa2c40f --- /dev/null +++ b/wpimath/src/test/java/edu/wpi/first/math/jni/ArmFeedforwardJNITest.java @@ -0,0 +1,16 @@ +// Copyright (c) FIRST and other WPILib contributors. +// Open Source Software; you can modify and/or share it under the terms of +// the WPILib BSD license file in the root directory of this project. + +package edu.wpi.first.math.jni; + +import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; + +import org.junit.jupiter.api.Test; + +public class ArmFeedforwardJNITest { + @Test + public void testLink() { + assertDoesNotThrow(ArmFeedforwardJNI::forceLoad); + } +} diff --git a/wpimath/src/test/java/edu/wpi/first/math/WPIMathJNITest.java b/wpimath/src/test/java/edu/wpi/first/math/jni/DAREJNITest.java similarity index 76% rename from wpimath/src/test/java/edu/wpi/first/math/WPIMathJNITest.java rename to wpimath/src/test/java/edu/wpi/first/math/jni/DAREJNITest.java index 6a1bf2edaff..88d0486554e 100644 --- a/wpimath/src/test/java/edu/wpi/first/math/WPIMathJNITest.java +++ b/wpimath/src/test/java/edu/wpi/first/math/jni/DAREJNITest.java @@ -2,15 +2,15 @@ // Open Source Software; you can modify and/or share it under the terms of // the WPILib BSD license file in the root directory of this project. -package edu.wpi.first.math; +package edu.wpi.first.math.jni; import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; import org.junit.jupiter.api.Test; -public class WPIMathJNITest { +public class DAREJNITest { @Test public void testLink() { - assertDoesNotThrow(WPIMathJNI::forceLoad); + assertDoesNotThrow(DAREJNI::forceLoad); } } diff --git a/wpimath/src/test/java/edu/wpi/first/math/jni/EigenJNITest.java b/wpimath/src/test/java/edu/wpi/first/math/jni/EigenJNITest.java new file mode 100644 index 00000000000..ad98fefbf55 --- /dev/null +++ b/wpimath/src/test/java/edu/wpi/first/math/jni/EigenJNITest.java @@ -0,0 +1,16 @@ +// Copyright (c) FIRST and other WPILib contributors. +// Open Source Software; you can modify and/or share it under the terms of +// the WPILib BSD license file in the root directory of this project. + +package edu.wpi.first.math.jni; + +import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; + +import org.junit.jupiter.api.Test; + +public class EigenJNITest { + @Test + public void testLink() { + assertDoesNotThrow(EigenJNI::forceLoad); + } +} diff --git a/wpimath/src/test/java/edu/wpi/first/math/jni/Ellipse2dJNITest.java b/wpimath/src/test/java/edu/wpi/first/math/jni/Ellipse2dJNITest.java new file mode 100644 index 00000000000..dbdb97f7b84 --- /dev/null +++ b/wpimath/src/test/java/edu/wpi/first/math/jni/Ellipse2dJNITest.java @@ -0,0 +1,16 @@ +// Copyright (c) FIRST and other WPILib contributors. +// Open Source Software; you can modify and/or share it under the terms of +// the WPILib BSD license file in the root directory of this project. + +package edu.wpi.first.math.jni; + +import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; + +import org.junit.jupiter.api.Test; + +public class Ellipse2dJNITest { + @Test + public void testLink() { + assertDoesNotThrow(Ellipse2dJNI::forceLoad); + } +} diff --git a/wpimath/src/test/java/edu/wpi/first/math/jni/Pose3dJNITest.java b/wpimath/src/test/java/edu/wpi/first/math/jni/Pose3dJNITest.java new file mode 100644 index 00000000000..d7f90a98e27 --- /dev/null +++ b/wpimath/src/test/java/edu/wpi/first/math/jni/Pose3dJNITest.java @@ -0,0 +1,16 @@ +// Copyright (c) FIRST and other WPILib contributors. +// Open Source Software; you can modify and/or share it under the terms of +// the WPILib BSD license file in the root directory of this project. + +package edu.wpi.first.math.jni; + +import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; + +import org.junit.jupiter.api.Test; + +public class Pose3dJNITest { + @Test + public void testLink() { + assertDoesNotThrow(Pose3dJNI::forceLoad); + } +} diff --git a/wpimath/src/test/java/edu/wpi/first/math/jni/StateSpaceUtilJNITest.java b/wpimath/src/test/java/edu/wpi/first/math/jni/StateSpaceUtilJNITest.java new file mode 100644 index 00000000000..a7d9cad06d6 --- /dev/null +++ b/wpimath/src/test/java/edu/wpi/first/math/jni/StateSpaceUtilJNITest.java @@ -0,0 +1,16 @@ +// Copyright (c) FIRST and other WPILib contributors. +// Open Source Software; you can modify and/or share it under the terms of +// the WPILib BSD license file in the root directory of this project. + +package edu.wpi.first.math.jni; + +import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; + +import org.junit.jupiter.api.Test; + +public class StateSpaceUtilJNITest { + @Test + public void testLink() { + assertDoesNotThrow(StateSpaceUtilJNI::forceLoad); + } +} diff --git a/wpimath/src/test/java/edu/wpi/first/math/jni/TrajectoryUtilJNITest.java b/wpimath/src/test/java/edu/wpi/first/math/jni/TrajectoryUtilJNITest.java new file mode 100644 index 00000000000..9513995f137 --- /dev/null +++ b/wpimath/src/test/java/edu/wpi/first/math/jni/TrajectoryUtilJNITest.java @@ -0,0 +1,16 @@ +// Copyright (c) FIRST and other WPILib contributors. +// Open Source Software; you can modify and/or share it under the terms of +// the WPILib BSD license file in the root directory of this project. + +package edu.wpi.first.math.jni; + +import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; + +import org.junit.jupiter.api.Test; + +public class TrajectoryUtilJNITest { + @Test + public void testLink() { + assertDoesNotThrow(TrajectoryUtilJNI::forceLoad); + } +} diff --git a/wpiunits/src/main/java/edu/wpi/first/units/Measure.java b/wpiunits/src/main/java/edu/wpi/first/units/Measure.java index b545e55bed9..f71b80238f8 100644 --- a/wpiunits/src/main/java/edu/wpi/first/units/Measure.java +++ b/wpiunits/src/main/java/edu/wpi/first/units/Measure.java @@ -299,11 +299,9 @@ default boolean isNear(Measure other, Measure tolerance) { * @return true if this measure is equivalent, false otherwise */ default boolean isEquivalent(Measure other) { - if (!this.unit().getBaseUnit().equals(other.unit().getBaseUnit())) { - return false; // Disjoint units, not compatible - } - - return Math.abs(baseUnitMagnitude() - other.baseUnitMagnitude()) <= EQUIVALENCE_THRESHOLD; + // Return false for disjoint units that aren't compatible + return this.unit().getBaseUnit().equals(other.unit().getBaseUnit()) + && Math.abs(baseUnitMagnitude() - other.baseUnitMagnitude()) <= EQUIVALENCE_THRESHOLD; } /** {@inheritDoc} */ diff --git a/wpiunits/src/main/java/edu/wpi/first/units/Mult.java b/wpiunits/src/main/java/edu/wpi/first/units/Mult.java index d5e54d0e520..fa3570e4cc8 100644 --- a/wpiunits/src/main/java/edu/wpi/first/units/Mult.java +++ b/wpiunits/src/main/java/edu/wpi/first/units/Mult.java @@ -66,9 +66,9 @@ protected Mult(A a, B b) { * @param b the second unit * @return the combined unit */ - @SuppressWarnings({"unchecked", "rawtypes"}) + @SuppressWarnings("unchecked") public static , B extends Unit> Mult combine(A a, B b) { - final long key = ((long) a.hashCode()) << 32L | (((long) b.hashCode()) & 0xFFFFFFFFL); + final long key = ((long) a.hashCode()) << 32L | (b.hashCode() & 0xFFFFFFFFL); if (cache.containsKey(key)) { return cache.get(key); } diff --git a/wpiunits/src/main/java/edu/wpi/first/units/Per.java b/wpiunits/src/main/java/edu/wpi/first/units/Per.java index 897c405f43a..fe9131487e8 100644 --- a/wpiunits/src/main/java/edu/wpi/first/units/Per.java +++ b/wpiunits/src/main/java/edu/wpi/first/units/Per.java @@ -78,8 +78,7 @@ protected Per(N numerator, D denominator) { @SuppressWarnings("unchecked") public static , D extends Unit> Per combine( N numerator, D denominator) { - final long key = - ((long) numerator.hashCode()) << 32L | (((long) denominator.hashCode()) & 0xFFFFFFFFL); + final long key = ((long) numerator.hashCode()) << 32L | (denominator.hashCode() & 0xFFFFFFFFL); var existing = cache.get(key); if (existing != null) { diff --git a/wpiunits/src/main/java/edu/wpi/first/units/Unit.java b/wpiunits/src/main/java/edu/wpi/first/units/Unit.java index 8c61543fb2d..65339f87ce1 100644 --- a/wpiunits/src/main/java/edu/wpi/first/units/Unit.java +++ b/wpiunits/src/main/java/edu/wpi/first/units/Unit.java @@ -286,13 +286,11 @@ public boolean equivalent(Unit other) { @Override public boolean equals(Object o) { - if (this == o) { - return true; - } - return o instanceof Unit that - && m_name.equals(that.m_name) - && m_symbol.equals(that.m_symbol) - && this.equivalent(that); + return this == o + || o instanceof Unit that + && m_name.equals(that.m_name) + && m_symbol.equals(that.m_symbol) + && this.equivalent(that); } @Override diff --git a/wpiunits/src/main/java/edu/wpi/first/units/UnitBuilder.java b/wpiunits/src/main/java/edu/wpi/first/units/UnitBuilder.java index 1ae185ad946..01e014f6d96 100644 --- a/wpiunits/src/main/java/edu/wpi/first/units/UnitBuilder.java +++ b/wpiunits/src/main/java/edu/wpi/first/units/UnitBuilder.java @@ -69,7 +69,7 @@ private static double mapValue( } /** Helper class used for safely chaining mapping builder calls. */ - public class MappingBuilder { + public final class MappingBuilder { private final double m_minInput; private final double m_maxInput; @@ -271,7 +271,7 @@ public U make() { }); } - @SuppressWarnings("unchecked") + @SuppressWarnings({"unchecked", "PMD.AvoidAccessibilityAlteration"}) private static > Constructor> getConstructor(U baseUnit) throws NoSuchMethodException { var baseClass = baseUnit.getClass(); diff --git a/wpiunits/src/main/java/edu/wpi/first/units/Units.java b/wpiunits/src/main/java/edu/wpi/first/units/Units.java index dcb27f78452..b71a977ba94 100644 --- a/wpiunits/src/main/java/edu/wpi/first/units/Units.java +++ b/wpiunits/src/main/java/edu/wpi/first/units/Units.java @@ -419,7 +419,7 @@ private Units() { * @param symbol the symbol of the new derived unit * @return the milli-unit */ - @SuppressWarnings({"PMD.MethodName", "checkstyle:methodname"}) + @SuppressWarnings("checkstyle:methodname") public static > U Milli(Unit baseUnit, String name, String symbol) { return derive(baseUnit).splitInto(1000).named(name).symbol(symbol).make(); } @@ -431,7 +431,7 @@ public static > U Milli(Unit baseUnit, String name, String * @param baseUnit the unit being derived from. This does not have to be the base unit of measure * @return the milli-unit */ - @SuppressWarnings({"PMD.MethodName", "checkstyle:methodname"}) + @SuppressWarnings("checkstyle:methodname") public static > U Milli(Unit baseUnit) { return Milli( baseUnit, "Milli" + baseUnit.name().toLowerCase(Locale.ROOT), "m" + baseUnit.symbol()); @@ -447,7 +447,7 @@ public static > U Milli(Unit baseUnit) { * @param symbol the symbol of the new derived unit * @return the micro-unit */ - @SuppressWarnings({"PMD.MethodName", "checkstyle:methodname"}) + @SuppressWarnings("checkstyle:methodname") public static > U Micro(Unit baseUnit, String name, String symbol) { return derive(baseUnit).splitInto(1_000_000).named(name).symbol(symbol).make(); } @@ -459,7 +459,7 @@ public static > U Micro(Unit baseUnit, String name, String * @param baseUnit the unit being derived from. This does not have to be the base unit of measure * @return the micro-unit */ - @SuppressWarnings({"PMD.MethodName", "checkstyle:methodname"}) + @SuppressWarnings("checkstyle:methodname") public static > U Micro(Unit baseUnit) { return Micro( baseUnit, "Micro" + baseUnit.name().toLowerCase(Locale.ROOT), "u" + baseUnit.symbol()); @@ -474,7 +474,7 @@ public static > U Micro(Unit baseUnit) { * @param symbol the symbol of the new derived unit * @return the kilo-unit */ - @SuppressWarnings({"PMD.MethodName", "checkstyle:methodname"}) + @SuppressWarnings("checkstyle:methodname") public static > U Kilo(Unit baseUnit, String name, String symbol) { return derive(baseUnit).aggregate(1000).named(name).symbol(symbol).make(); } @@ -486,7 +486,7 @@ public static > U Kilo(Unit baseUnit, String name, String s * @param baseUnit the unit being derived from. This does not have to be the base unit of measure * @return the kilo-unit */ - @SuppressWarnings({"PMD.MethodName", "checkstyle:methodname"}) + @SuppressWarnings("checkstyle:methodname") public static > U Kilo(Unit baseUnit) { return Kilo( baseUnit, "Kilo" + baseUnit.name().toLowerCase(Locale.ROOT), "K" + baseUnit.symbol()); diff --git a/wpiunits/src/main/java/edu/wpi/first/units/Velocity.java b/wpiunits/src/main/java/edu/wpi/first/units/Velocity.java index 6fdfba10d08..287c1601633 100644 --- a/wpiunits/src/main/java/edu/wpi/first/units/Velocity.java +++ b/wpiunits/src/main/java/edu/wpi/first/units/Velocity.java @@ -33,7 +33,7 @@ public class Velocity> extends Unit> { /** Generates a cache key used for cache lookups. */ private static long cacheKey(Unit numerator, Unit denominator) { - return ((long) numerator.hashCode()) << 32L | (((long) denominator.hashCode()) & 0xFFFFFFFFL); + return ((long) numerator.hashCode()) << 32L | (denominator.hashCode() & 0xFFFFFFFFL); } /** diff --git a/wpiutil/src/main/java/edu/wpi/first/util/struct/StructDescriptorDatabase.java b/wpiutil/src/main/java/edu/wpi/first/util/struct/StructDescriptorDatabase.java index 459fa9e10f8..14515a50a6a 100644 --- a/wpiutil/src/main/java/edu/wpi/first/util/struct/StructDescriptorDatabase.java +++ b/wpiutil/src/main/java/edu/wpi/first/util/struct/StructDescriptorDatabase.java @@ -119,8 +119,7 @@ public StructDescriptor add(String name, String schema) throws BadSchemaExceptio } else { // check for circular reference if (!theStruct.checkCircular(stack)) { - StringBuilder builder = new StringBuilder(); - builder.append("circular struct reference: "); + StringBuilder builder = new StringBuilder("circular struct reference: "); boolean first = true; for (StructDescriptor elem : stack) { if (!first) { diff --git a/wpiutil/src/main/native/cpp/DataLogBackgroundWriter.cpp b/wpiutil/src/main/native/cpp/DataLogBackgroundWriter.cpp index 2db52e3cf7e..ec01346ef03 100644 --- a/wpiutil/src/main/native/cpp/DataLogBackgroundWriter.cpp +++ b/wpiutil/src/main/native/cpp/DataLogBackgroundWriter.cpp @@ -237,6 +237,7 @@ void DataLogBackgroundWriter::StartLogFile(WriterThreadState& state) { WPI_ERROR(m_msglog, "Insufficient free space ({} available), no log being saved", FormatBytesSize(state.freeSpace)); + m_state = kStopped; } else { // try preferred filename, or randomize it a few times, before giving up for (int i = 0; i < 5; ++i) { diff --git a/xrpVendordep/src/main/java/edu/wpi/first/wpilibj/xrp/XRPMotor.java b/xrpVendordep/src/main/java/edu/wpi/first/wpilibj/xrp/XRPMotor.java index 6db4fc236ac..5924cb4adb7 100644 --- a/xrpVendordep/src/main/java/edu/wpi/first/wpilibj/xrp/XRPMotor.java +++ b/xrpVendordep/src/main/java/edu/wpi/first/wpilibj/xrp/XRPMotor.java @@ -92,10 +92,7 @@ public void setInverted(boolean isInverted) { @Override public boolean getInverted() { - if (m_simInverted != null) { - return m_simInverted.get(); - } - return false; + return m_simInverted != null && m_simInverted.get(); } @Override