-
Notifications
You must be signed in to change notification settings - Fork 664
[cmd] Commands v3 framework #6518
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
PeterJohnson
merged 161 commits into
wpilibsuite:2027
from
SamCarlberg:better-async-commands
Oct 10, 2025
Merged
Changes from 55 commits
Commits
Show all changes
161 commits
Select commit
Hold shift + click to select a range
e1fd7c9
Add commandsv3 subproject
SamCarlberg 0dcaaaf
Add wrapper classes for JDK internals
SamCarlberg 89e7471
Add core classes
SamCarlberg 6682824
Add command joysticks and buttons
SamCarlberg 10869c8
Add example program for commandsv3
SamCarlberg 9173146
Add comment on exception handling
SamCarlberg ded1394
Add Coroutine.fork
SamCarlberg 17bb1a6
Add tests for sibling requirements and nested oneshots
SamCarlberg dd0420e
Make documentation comment a little clearer
SamCarlberg dce0903
Change Coroutine.fork to accept multiple commands
SamCarlberg b669696
Add copyright headers to generated protobuf classes
SamCarlberg 676e787
Add first draft of a commands v3 design doc
SamCarlberg 10ff94f
Rename package to org.wpilib.commands3
SamCarlberg 841319d
Allow child commands to interrupt their siblings
SamCarlberg 62d1b66
Remove CommandExecutionException
SamCarlberg 9373371
Move parallel and sequence builders to top-level classes
SamCarlberg 1d63344
Update design doc telemetry and child command sections
SamCarlberg b866393
Add timing to scheduler and command telemetry
SamCarlberg 9813dd3
Throw when calling methods on unmounted coroutines
SamCarlberg eea410b
Fix copy-paste error from v2 cmake setup
SamCarlberg f9dbda3
Track mounted continuation in wrapper
SamCarlberg 62925d6
Clean up after awaitAny
SamCarlberg dfde0c5
Command-local trigger bindings
SamCarlberg 063bb27
Report scheduling trace for exceptions thrown by commands
SamCarlberg 131d443
Remove RobotDisabledBehavior
SamCarlberg ddf147f
Add some documentation comments
SamCarlberg 73ee346
Rename `getScheduledCommands()` to `getQueuedCommands()`
SamCarlberg 6b084c7
Add explicit test for child commands not cancelling their parents
SamCarlberg 5d9d6bb
Remove automatic setting of default command in constructor
SamCarlberg b2cf1e2
Remove Sendable from RequireableResource
SamCarlberg a6e7043
Run wpiformat
SamCarlberg f48061e
Rename Scheduler.getInstance() to Scheduler.getDefault()
SamCarlberg 5240501
Remove requirement for default commands to have low priorities
SamCarlberg dd2b565
Add until and asLongAs to CommandBuilder
SamCarlberg 498f95f
Rename `waitingFor` to `waitUntil`
SamCarlberg 8b968ca
Add Coroutine.waitUntil
SamCarlberg 8f3d4cb
Add RequireableResource.runRepeatedly and add docs for run
SamCarlberg da191b7
Make RequireableResource set idle default commands in constructor
SamCarlberg 50438be
Add ParallelGroupBuilder.alongWith
SamCarlberg 799b25b
Make EventLoop-taking Trigger constructor public
SamCarlberg bc5d728
Simplify Command.waitUntil
SamCarlberg a5236bb
Emit events during scheduler actions
SamCarlberg 36eac8b
Linting
SamCarlberg f01d6d4
Move generated protobuf classes to separate directory
SamCarlberg c714689
Update joystick classes for parity and generate command controllers
SamCarlberg caba87b
Adjust indentation on top-level command example snippet
SamCarlberg 70a7874
Checkstyle test
SamCarlberg cca0acc
Suppress checkstyle for all generated protobuf files
SamCarlberg 162739d
PMD
SamCarlberg 3aaaa8c
Linting
SamCarlberg 40a5cb0
Remove old examples
SamCarlberg 081289c
Formatting
SamCarlberg c6145d6
Formatting
SamCarlberg f889a08
Add bazel build and DevMain
SamCarlberg 9d1e490
Bazel linting
SamCarlberg 6a78627
Fix comment in generated controllers
SamCarlberg 017135d
Update frcYear in vendor json
SamCarlberg 6a9c1ec
Remove unneeded javadoc compile options
SamCarlberg 67c4e0b
Unmuck snippet formatting
SamCarlberg c9c5a1f
CMake build updates
SamCarlberg 21806f7
DevMain linting
SamCarlberg dafbe32
Apply bazel patch from PJ to generate protobuf files
SamCarlberg d11d9ad
Cancel commands when binding scopes become inactive
SamCarlberg db62193
Lint
SamCarlberg 5130af2
Lint
SamCarlberg e6f63da
Bazel linting
SamCarlberg cb51791
Regenerate protobuf files
SamCarlberg 8127e61
Replace snippet tags with code blocks
SamCarlberg 33a28d9
Stop wpiformat from running against generated files
SamCarlberg d188948
Minor cleanup for readability
SamCarlberg 56a0798
Fix nested commands being allowed to interrupt higher-priority commands
SamCarlberg f292977
Improve top-level documentation for Scheduler and Continuation
SamCarlberg 8b0f050
Make inner continuation reference private
SamCarlberg 1f11dbd
Merge remote-tracking branch 'wpi/2027' into better-async-commands
SamCarlberg b9c4548
Linting
SamCarlberg e36fb91
Document reasons for using Throwable to get stack frames
SamCarlberg e266735
Clean up debounced triggers
SamCarlberg f50fe6e
Documentation pass on Coroutine; add minor test
SamCarlberg f797231
Improve docs for Command.java
SamCarlberg 244e67e
Note pinned error removal
SamCarlberg 2cc43f9
Remove redundant `this` specifier on members
SamCarlberg e2c9650
Fix commands bound to inner triggers outliving the outer command
SamCarlberg 5f592d2
Merge remote-tracking branch 'wpi/2027' into better-async-commands
SamCarlberg 7d49e49
Address new linting warnings from upstream config changes
SamCarlberg eff9a2b
Make cancelAll() also evict on-deck commands
SamCarlberg c84aaec
Add tests for deadlock scenarios
SamCarlberg 2cab487
Rename v2 test file to match the class under test
SamCarlberg 7115a46
Rename "RequireableResource" to "Mechanism"
SamCarlberg 4bc3970
Rename "generate_hids" to "generate_files"
SamCarlberg db2c85c
Update design doc with new name
SamCarlberg ae6d01b
Update script name in comment and github action
SamCarlberg 56393c4
Linting
SamCarlberg 2d66742
Cleanup resource -> mechanism rename that wasn't caught earlier
SamCarlberg 91c766b
Change artifact name to "commands3"
SamCarlberg 9607585
Change command builders to be staged, instead of a single builder object
SamCarlberg 3d49867
Update design doc with builder changes
SamCarlberg 87696c3
Allow `onCancel` callback to be null
SamCarlberg b1ac457
Streamline command builder stages
SamCarlberg 9aceb46
Simplify builder stages
SamCarlberg 9fd0323
Use a counter to issue IDs to CommandStates
SamCarlberg 05477bd
Remove old CommandBuilder class
SamCarlberg 310145e
Make scheduler field private
SamCarlberg f37a806
Include commandsv3 in docs build
SamCarlberg a5a14af
Documentation pass
SamCarlberg 0f7d40b
Lint
SamCarlberg 0c2d420
Run child commands BEFORE parents, not after
SamCarlberg 547853b
Document caveats around waiting for a fixed time
SamCarlberg 7185f25
Documentation and API cleanup pass
SamCarlberg ff4f02f
Add test for Scheduler.addPeriodic; move yield to end of loop
SamCarlberg 48140a2
Remove IdleCommand and WaitCommand in favor of factories
SamCarlberg ca4044e
Document coroutine fork/await as nonblocking and blocking operations
SamCarlberg bf1828e
Remove ParallelGroupBuilder methods that modified optionalailty
SamCarlberg 67b2376
Documentation and import cleanup in button code
SamCarlberg 980ad84
Explicitly handle one-time loop binding
SamCarlberg 9a08755
Rename Evicted event to Canceled
SamCarlberg 5982f57
Fix cancelAll() not calling cancellation hooks
SamCarlberg 3f92f54
Add tests for sideload function interactions with commands
SamCarlberg bf0c4cf
Make "canceled" and "canceling" spelling consistent
SamCarlberg 32d68c8
Make Continuation and ContinuationScope package-private
SamCarlberg fd1b50a
Parallel and sequential group cleanup
SamCarlberg 817e0f1
Rename `Sequence` to `SequentialGroup`
SamCarlberg 00d8c91
Move conflict detection to utility class
SamCarlberg 2609056
Reorder scheduler `run()` cycle
SamCarlberg f08a4a0
Sort conflicting mechanism names alphabetically in ConflictDetector
SamCarlberg 6aea6db
Update design doc with changes to `run()` method steps ordering
SamCarlberg da46844
Properly clean up after commands that encounter uncaught exceptions
SamCarlberg 786ce08
Cancel parent commands when child command encounters an error
SamCarlberg ad925bd
Split scheduler tests into separate files for organization
SamCarlberg 62fdc44
Rename `SequenceBuilder` to `SequentialGroupBuilder` for consistency
SamCarlberg eebbc59
Protobuf reorganization
SamCarlberg 66856bf
Rename test files
SamCarlberg 02aa15f
Test cleanup
SamCarlberg d4d3c64
Document cancellation event order
SamCarlberg b9593ba
Minor cleanup for PMD
SamCarlberg d8f7dad
Document scheduler and event loop on controller trigger factories
SamCarlberg 42bf6b2
Rename `forkAll` to `fork` for consistency
SamCarlberg e7cd399
Covariance
SamCarlberg 1893fc0
Delegate `fork(Collection)` to variadic overload
SamCarlberg 6af662c
Make scheduler constructor private; use a factory method instead
SamCarlberg 15d9b85
Merge remote-tracking branch 'wpi/2027' into better-async-commands
SamCarlberg 97e8941
Remove merge artifact
SamCarlberg f74fbf8
Linting
SamCarlberg 8baeb86
Regenerate protobuf classes with script
SamCarlberg 5a62bff
Update generate_files to work on macOS without modifications
SamCarlberg 3abcf09
Update default command documentation
SamCarlberg 15760f2
Regenerate protbuf classes
SamCarlberg 5ce3fa1
Remove unnecessary suppression
SamCarlberg 9bb94a7
Merge branch '2027' into better-async-commands
SamCarlberg 103397d
Merge branch '2027' into better-async-commands
SamCarlberg d6cae87
Test updates
SamCarlberg 966cfa0
Gradle updates
SamCarlberg 68441a3
Merge branch '2027' into better-async-commands
SamCarlberg ca98b4b
Add explicit check for command 1 completing normally
SamCarlberg 2489813
Merge branch '2027' into better-async-commands
SamCarlberg 7a3fe6e
Add NoDiscard to command types
SamCarlberg 3ccd430
Linting
SamCarlberg 9473a2d
Update cmake to include commandsv3 with wpilib build
SamCarlberg 4a89bf1
Add wpiannotations to bazel dependencies
SamCarlberg c00da49
Merge branch '2027' into better-async-commands
SamCarlberg efbf0c3
Add datalog to cmake deps
SamCarlberg fee4a8f
Add null check for binding frames
SamCarlberg File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
load("@allwpilib_pip_deps//:requirements.bzl", "requirement") | ||
load("@aspect_bazel_lib//lib:write_source_files.bzl", "write_source_files") | ||
load("@rules_java//java:defs.bzl", "java_binary") | ||
load("@rules_python//python:defs.bzl", "py_binary") | ||
load("//commandsv3:generate.bzl", "generate_commandsv3") | ||
load("//shared/bazel/rules:java_rules.bzl", "wpilib_java_junit5_test", "wpilib_java_library") | ||
|
||
py_binary( | ||
name = "generate_hids", | ||
srcs = ["generate_hids.py"], | ||
target_compatible_with = select({ | ||
"@rules_bzlmodrio_toolchains//constraints/is_systemcore:systemcore": ["@platforms//:incompatible"], | ||
"//conditions:default": [], | ||
}), | ||
deps = [requirement("jinja2")], | ||
) | ||
|
||
filegroup( | ||
name = "templates", | ||
srcs = glob(["src/generate/main/**"]) + [ | ||
"//wpilibj:hid_schema", | ||
], | ||
) | ||
|
||
generate_commandsv3( | ||
name = "generate_commandsv3", | ||
) | ||
|
||
write_source_files( | ||
name = "write_commandsv3", | ||
files = { | ||
"src/generated": ":generate_commandsv3", | ||
}, | ||
suggested_update_target = "//:write_all", | ||
tags = ["pregeneration"], | ||
visibility = ["//visibility:public"], | ||
) | ||
|
||
filegroup( | ||
name = "generated_java", | ||
srcs = glob(["src/generated/main/java/**/*.java"]), | ||
) | ||
|
||
wpilib_java_library( | ||
name = "commandsv3-java", | ||
srcs = glob(["src/main/java/**/*.java"]) + [":generated_java"], | ||
maven_artifact_name = "commandsv3-java", | ||
maven_group_id = "org.wpilib.commands3", | ||
visibility = ["//visibility:public"], | ||
deps = [ | ||
"//cscore:cscore-java", | ||
"//hal:hal-java", | ||
"//ntcore:ntcore-java", | ||
"//wpilibj:wpilibj-java", | ||
"//wpimath:wpimath-java", | ||
"//wpinet:wpinet-java", | ||
"//wpiunits:wpiunits-java", | ||
"//wpiutil:wpiutil-java", | ||
"@maven//:us_hebi_quickbuf_quickbuf_runtime", | ||
], | ||
) | ||
|
||
wpilib_java_junit5_test( | ||
name = "commandsv3-java-test", | ||
srcs = glob(["**/*.java"]), | ||
deps = [ | ||
":commandsv3-java", | ||
"//hal:hal-java", | ||
"//ntcore:ntcore-java", | ||
"//wpilibj:wpilibj-java", | ||
"//wpimath:wpimath-java", | ||
"//wpiunits:wpiunits-java", | ||
"//wpiutil:wpiutil-java", | ||
"@maven//:us_hebi_quickbuf_quickbuf_runtime", | ||
], | ||
) | ||
|
||
java_binary( | ||
name = "DevMain-Java", | ||
srcs = ["src/dev/java/org/wpilib/commands3/DevMain.java"], | ||
main_class = "org.wpilib.commands3.DevMain", | ||
deps = [ | ||
"//hal:hal-java", | ||
"//ntcore:ntcore-java", | ||
"//wpimath:wpimath-java", | ||
"//wpiutil:wpiutil-java", | ||
], | ||
) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
project(commandsv3) | ||
|
||
include(SubDirList) | ||
include(CompileWarnings) | ||
include(AddTest) | ||
|
||
if(WITH_JAVA) | ||
find_package(Java REQUIRED) | ||
include(UseJava) | ||
set(CMAKE_JAVA_COMPILE_FLAGS "-encoding" "UTF8" "-Xlint:unchecked") | ||
|
||
file(GLOB_RECURSE JAVA_SOURCES src/main/java/*.java) | ||
add_jar( | ||
commandsv3_jar | ||
${JAVA_SOURCES} | ||
INCLUDE_JARS | ||
hal_jar | ||
ntcore_jar | ||
cscore_jar | ||
cameraserver_jar | ||
wpimath_jar | ||
wpiunits_jar | ||
wpiutil_jar | ||
wpilibj_jar | ||
OUTPUT_NAME commandsv3 | ||
SamCarlberg marked this conversation as resolved.
Show resolved
Hide resolved
|
||
) | ||
|
||
install_jar(commandsv3_jar DESTINATION ${java_lib_dest}) | ||
install_jar_exports( | ||
TARGETS commandsv3_jar | ||
FILE commandsv3_jar.cmake | ||
DESTINATION share/commandsv3 | ||
) | ||
endif() | ||
|
||
if(WITH_JAVA_SOURCE) | ||
find_package(Java REQUIRED) | ||
include(UseJava) | ||
file(GLOB commandsv3_SOURCES src/main/java/edu/wpi/first/wpilibj/commandsv3/*.java) | ||
file(GLOB commandsv3_BUTTON_SOURCES src/main/java/edu/wpi/first/wpilibj2/command/button*.java) | ||
add_jar( | ||
commandsv3_src_jar | ||
RESOURCES | ||
NAMESPACE "edu/wpi/first/wpilibj/commandsv3" ${commandsv3_SOURCES} | ||
NAMESPACE "edu/wpi/first/wpilibj/commandsv3/button" ${commandsv3_BUTTON_SOURCES} | ||
OUTPUT_NAME commandsv3-sources | ||
) | ||
|
||
get_property(commandsv3_SRC_JAR_FILE TARGET commandsv3_src_jar PROPERTY JAR_FILE) | ||
install(FILES ${commandsv3_SRC_JAR_FILE} DESTINATION "${java_lib_dest}") | ||
|
||
set_property(TARGET commandsv3_src_jar PROPERTY FOLDER "java") | ||
endif() | ||
SamCarlberg marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
install(TARGETS commandsv3 EXPORT commandsv3) | ||
export(TARGETS commandsv3 FILE commandsv3.cmake NAMESPACE commandsv3::) | ||
|
||
configure_file(commandsv3-config.cmake.in ${WPILIB_BINARY_DIR}/commandsv3-config.cmake) | ||
install(FILES ${WPILIB_BINARY_DIR}/commandsv3-config.cmake DESTINATION share/commandsv3) | ||
install(EXPORT commandsv3 DESTINATION share/commandsv3) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
{ | ||
"fileName": "CommandsV3.json", | ||
"name": "Commands v3", | ||
"version": "1.0.0", | ||
"uuid": "4decdc05-a056-46cf-9561-39449bbb0130", | ||
"frcYear": "2024", | ||
SamCarlberg marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
"mavenUrls": [], | ||
"jsonUrl": "", | ||
"javaDependencies": [ | ||
{ | ||
"groupId": "org.wpilib.commands3", | ||
"artifactId": "commandsv3-java", | ||
SamCarlberg marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
"version": "wpilib" | ||
} | ||
], | ||
"jniDependencies": [], | ||
"cppDependencies": [] | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
ext { | ||
useJava = true | ||
useCpp = false | ||
baseId = 'commandsv3' | ||
groupId = 'org.wpilib' | ||
|
||
nativeName = 'commandsv3' | ||
SamCarlberg marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
devMain = '' | ||
SamCarlberg marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
} | ||
|
||
apply from: "${rootDir}/shared/java/javacommon.gradle" | ||
|
||
evaluationDependsOn(':wpiutil') | ||
evaluationDependsOn(':ntcore') | ||
evaluationDependsOn(':hal') | ||
evaluationDependsOn(':wpimath') | ||
evaluationDependsOn(':wpilibj') | ||
|
||
dependencies { | ||
implementation project(':wpiutil') | ||
implementation project(':wpinet') | ||
implementation project(':ntcore') | ||
implementation project(':hal') | ||
implementation project(':wpimath') | ||
implementation project(':wpilibj') | ||
api("us.hebi.quickbuf:quickbuf-runtime:1.3.3") | ||
SamCarlberg marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
testImplementation 'org.mockito:mockito-core:4.1.0' | ||
} | ||
|
||
sourceSets.main.java.srcDir "${projectDir}/src/generated/main/java" | ||
sourceSets.main.resources.srcDir "${projectDir}/src/main/proto" | ||
|
||
tasks.withType(Javadoc) { | ||
options.addBooleanOption("-enable-preview", true) | ||
options.addStringOption("-release", "21") | ||
} | ||
SamCarlberg marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
||
test { | ||
testLogging { | ||
outputs.upToDateWhen {false} | ||
showStandardStreams = true | ||
} | ||
doFirst { | ||
jvmArgs = [ | ||
'--add-opens', | ||
'java.base/jdk.internal.vm=ALL-UNNAMED', | ||
'--add-opens', | ||
'java.base/java.lang=ALL-UNNAMED', | ||
] | ||
} | ||
SamCarlberg marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
include(CMakeFindDependencyMacro) | ||
@WPIUTIL_DEP_REPLACE@ | ||
@NTCORE_DEP_REPLACE@ | ||
SamCarlberg marked this conversation as resolved.
Show resolved
Hide resolved
|
||
@CSCORE_DEP_REPLACE@ | ||
@CAMERASERVER_DEP_REPLACE@ | ||
@HAL_DEP_REPLACE@ | ||
@WPILIBC_DEP_REPLACE@ | ||
@WPIMATH_DEP_REPLACE@ | ||
|
||
@FILENAME_DEP_REPLACE@ | ||
include(${SELF_DIR}/commandsv3.cmake) | ||
if(@WITH_JAVA@) | ||
include(${SELF_DIR}/commandsv3_jar.cmake) | ||
endif() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
def __generate_commandsv3_impl(ctx): | ||
""" | ||
Custom rule used to create the commandsv3 pre-generated files. See `./README-Bazel.md` for the reasoning. | ||
""" | ||
output_dir = ctx.actions.declare_directory("_gendir") | ||
|
||
args = ctx.actions.args() | ||
args.add("--output_directory", output_dir.path) | ||
args.add("--template_root", "commandsv3/src/generate") | ||
|
||
ctx.actions.run( | ||
inputs = ctx.attr._templates.files, | ||
outputs = [output_dir], | ||
executable = ctx.executable._tool, | ||
arguments = [args], | ||
) | ||
|
||
return [DefaultInfo(files = depset([output_dir]))] | ||
|
||
generate_commandsv3 = rule( | ||
implementation = __generate_commandsv3_impl, | ||
attrs = { | ||
"_templates": attr.label( | ||
default = Label("//commandsv3:templates"), | ||
), | ||
"_tool": attr.label( | ||
default = Label("//commandsv3:generate_hids"), | ||
cfg = "exec", | ||
executable = True, | ||
), | ||
}, | ||
) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
#!/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 argparse | ||
import json | ||
from pathlib import Path | ||
|
||
from jinja2 import Environment, FileSystemLoader | ||
|
||
|
||
def write_controller_file(output_dir: Path, controller_name: str, contents: str): | ||
output_dir.mkdir(parents=True, exist_ok=True) | ||
output_file = output_dir / controller_name | ||
output_file.write_text(contents, encoding="utf-8", newline="\n") | ||
|
||
|
||
def generate_hids(output_directory: Path, template_directory: Path, schema_file: Path): | ||
with schema_file.open(encoding="utf-8") as f: | ||
controllers = json.load(f) | ||
|
||
# Java files | ||
java_subdirectory = "main/java/org/wpilib/commands3/button" | ||
env = Environment( | ||
loader=FileSystemLoader(template_directory / "main/java"), | ||
autoescape=False, | ||
keep_trailing_newline=True, | ||
) | ||
root_path = output_directory / java_subdirectory | ||
template = env.get_template("commandhid.java.jinja") | ||
for controller in controllers: | ||
controllerName = f"Command{controller['ConsoleName']}Controller.java" | ||
output = template.render(controller) | ||
write_controller_file(root_path, controllerName, output) | ||
|
||
|
||
def main(): | ||
script_path = Path(__file__).resolve() | ||
dirname = script_path.parent | ||
|
||
parser = argparse.ArgumentParser() | ||
parser.add_argument( | ||
"--output_directory", | ||
help="Optional. If set, will output the generated files to this directory, otherwise it will use a path relative to the script", | ||
default=dirname / "src/generated", | ||
type=Path, | ||
) | ||
parser.add_argument( | ||
"--template_root", | ||
help="Optional. If set, will use this directory as the root for the jinja templates", | ||
default=dirname / "src/generate", | ||
type=Path, | ||
) | ||
parser.add_argument( | ||
"--schema_file", | ||
help="Optional. If set, will use this file for the joystick schema", | ||
default="wpilibj/src/generate/hids.json", | ||
type=Path, | ||
) | ||
args = parser.parse_args() | ||
|
||
generate_hids(args.output_directory, args.template_root, args.schema_file) | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
// 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 org.wpilib.commands3; | ||
|
||
import edu.wpi.first.hal.HALUtil; | ||
import edu.wpi.first.networktables.NetworkTablesJNI; | ||
import edu.wpi.first.util.CombinedRuntimeLoader; | ||
|
||
public class DevMain { | ||
public static void main(String[] args) { | ||
System.out.println("Commands V3 DevMain"); | ||
|
||
System.out.println(CombinedRuntimeLoader.getPlatformPath()); | ||
System.out.println(NetworkTablesJNI.now()); | ||
System.out.println(HALUtil.getHALRuntimeType()); | ||
} | ||
|
||
private DevMain() {} | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.