Skip to content
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

[DRAFT] Add async command framework using Java 21 language features #6518

Draft
wants to merge 41 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
67d8638
JDK 21 (graal)
SamCarlberg Dec 11, 2023
83f26e8
wip
SamCarlberg Dec 31, 2023
1c4ff6e
java 21
SamCarlberg Jan 1, 2024
8cfc99f
Proper async, add mirrors of existing command code, move to wpilibj3 …
SamCarlberg Apr 11, 2024
cb44c64
Spotless formatting and improved command group scheduling
SamCarlberg Apr 12, 2024
be6b901
Add Rapid React example bot using async commands
SamCarlberg Apr 12, 2024
c4a6126
Cleanup; rename Resource to HardwareResource
SamCarlberg Apr 13, 2024
d6f42d4
Allow async commands to suspend on interrupt
SamCarlberg Apr 19, 2024
fc0eac4
Make publishable, add AsyncRobot base class to let main loop run on s…
SamCarlberg Apr 29, 2024
298cefa
Various stability updates
SamCarlberg May 2, 2024
5200639
stability
SamCarlberg May 2, 2024
4bdc585
Stability
SamCarlberg May 3, 2024
a686e80
Remove usages of Logger; generic cleanup
SamCarlberg May 3, 2024
03e3b26
Delete logger
SamCarlberg May 3, 2024
c908796
Nuke sequences and parallel groups
SamCarlberg May 3, 2024
8d889ab
Print all nested exceptions, not just the first cause
SamCarlberg May 3, 2024
5a3ad53
Remove deadlocking in cancelAll, minor refactor
SamCarlberg May 3, 2024
8525a4f
Add some helpers to command API
SamCarlberg May 3, 2024
7994bed
Revert "Delete logger"
SamCarlberg May 3, 2024
d24144a
wip dump
SamCarlberg May 9, 2024
d570544
Replace virtual threads with raw Continuations
SamCarlberg May 11, 2024
ce01728
Drop `throws Exception` from AsyncCommand.run
SamCarlberg May 11, 2024
b7e565b
Update examples
SamCarlberg May 11, 2024
f39f7a3
Smarter schedule for nested commands
SamCarlberg May 12, 2024
de11138
Remove logging code
SamCarlberg May 12, 2024
4164ed2
Improve deeply nested commands; add Sequence; documentation pass
SamCarlberg May 13, 2024
861db2f
Remove vestigial code
SamCarlberg May 13, 2024
2083f0e
Move command waiting logic to the scheduler
SamCarlberg May 14, 2024
22be42a
Allow commands to be suspended on interrupt
SamCarlberg May 15, 2024
7a691bc
Add scheduleAndWait helper
SamCarlberg May 15, 2024
408d904
Track nested resources to allow partial ownership of compound mechanisms
SamCarlberg May 15, 2024
a6aa306
Move default command knowledge to HardwareResource
SamCarlberg May 16, 2024
3f21d4d
Extract CommandState record
SamCarlberg May 17, 2024
1c5c8a4
Refactor scheduler run() method
SamCarlberg May 17, 2024
11fdca1
Coroutine injection
SamCarlberg May 19, 2024
ebd4a71
Spotless formatting
SamCarlberg May 19, 2024
2366f87
Rename `noHardware` to `noRequirements`
SamCarlberg May 19, 2024
1ac94cc
Rename "HardwareResource" to "RequireableResource"
SamCarlberg May 19, 2024
055980c
Move to commandsv3 project
SamCarlberg May 19, 2024
3ab52bd
Remove "async" moniker
SamCarlberg May 19, 2024
1321fd4
Add simple wait to coroutines
SamCarlberg May 19, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .tool-versions
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
java openjdk-21.0.2
6 changes: 3 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ plugins {
id 'visual-studio'
id 'net.ltgt.errorprone' version '3.1.0' apply false
id 'com.github.johnrengelman.shadow' version '8.1.1' apply false
id 'com.diffplug.spotless' version '6.20.0' apply false
id 'com.diffplug.spotless' version '6.25.0' apply false
id 'com.github.spotbugs' version '6.0.2' apply false
id 'com.google.protobuf' version '0.9.3' apply false
}
Expand Down Expand Up @@ -114,8 +114,8 @@ subprojects {

plugins.withType(JavaPlugin) {
java {
sourceCompatibility = 11
targetCompatibility = 11
sourceCompatibility = 21
targetCompatibility = 21
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public VisionRunner(VideoSource videoSource, P pipeline, Listener<? super P> lis
public void runOnce() {
Long id = CameraServerSharedStore.getCameraServerShared().getRobotMainThreadId();

if (id != null && Thread.currentThread().getId() == id) {
if (id != null && Thread.currentThread().threadId() == id) {
throw new IllegalStateException(
"VisionRunner.runOnce() cannot be called from the main robot thread");
}
Expand Down Expand Up @@ -106,7 +106,7 @@ private void runOnceInternal() {
public void runForever() {
Long id = CameraServerSharedStore.getCameraServerShared().getRobotMainThreadId();

if (id != null && Thread.currentThread().getId() == id) {
if (id != null && Thread.currentThread().threadId() == id) {
throw new IllegalStateException(
"VisionRunner.runForever() cannot be called from the main robot thread");
}
Expand Down
70 changes: 70 additions & 0 deletions commandsv3/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
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
)

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()

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)

18 changes: 18 additions & 0 deletions commandsv3/CommandsV3.json
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",
"mavenUrls": [],
"jsonUrl": "",
"javaDependencies": [
{
"groupId": "edu.wpi.first.commandsv3",
"artifactId": "commandsv3-java",
"version": "wpilib"
}
],
"jniDependencies": [],
"cppDependencies": []
}
47 changes: 47 additions & 0 deletions commandsv3/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
ext {
useJava = true
useCpp = false
baseId = 'commandsv3'
groupId = 'edu.wpi.first.wpilibj'

nativeName = 'commandsv3'
devMain = ''
}

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')
testImplementation 'org.mockito:mockito-core:4.1.0'
}

tasks.withType(Javadoc) {
options.addBooleanOption("-enable-preview", true)
options.addStringOption("-release", "21")
}

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',
]
}
}
Loading