-
Notifications
You must be signed in to change notification settings - Fork 288
Commands v3 Documentation #3095
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
base: 2027
Are you sure you want to change the base?
Conversation
source/docs/software/commandbased/commands-v3/command-compositions-v3.rst
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
First pass, still a lot to cover. Generally, I'd like sections to have more detail that just one or two sentences, particularly for things like parent/child commands and nested triggers. The LLM also seems to be conflating some v2 and v3 APIs (and outright hallucinating a few others)
We should also have a conversation about suggested project structure, since the Robot/RobotContainer split does a poor job of separating concerns
|
|
||
| Command driveWithTimeout = Commands.race( | ||
| drivetrain.driveToPose(pose), | ||
| Commands.waitSeconds(3.0) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a better example than racing with a wait command? That's more idiomatically written using withTimeout. Maybe play an LED pattern instead?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I replace it with an LED while doing action example. Is the thinking that this works in place of deadline or do we have that too and I missed it?
|
|
||
| * - Commands v2 | ||
| - Commands v3 | ||
| * - ``edu.wpi.first.wpilibj2.command.*`` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
btw, v2 is moving to the org.wpilib.commands2 package in 2027
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it now hast it right in anticipation for this but it will be easier once we get things moved but I know that is a huge PR
| controller.a().onTrue(Commands.runOnce(() -> intake.extend())); | ||
| controller.b().whileTrue(new RunCommand(() -> intake.run(), intake)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should use subsystem factories in our examples whenever possible
| controller.a().onTrue(Commands.runOnce(() -> intake.extend())); | |
| controller.b().whileTrue(new RunCommand(() -> intake.run(), intake)); | |
| controller.a().onTrue(intake.runOnce(() -> intake.extend())); | |
| controller.b().whileTrue(intake.run(() -> intake.run())); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
agreed done
| ); | ||
|
|
||
| new Trigger(() -> sensor.isTriggered()) | ||
| .onTrue(Command.print("Sensor triggered!")); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That reminds me, we don't currently have a print command in v3
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is that just an oversight and there will / should be something like this in the future?
| CommandXboxController controller = new CommandXboxController(0); | ||
|
|
||
| controller.a().onTrue( | ||
| intake.run(coro -> intake.extend()).named("Extend Intake") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This could be _ -> intake.extend() if we're on Java 22 or higher
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is that style we want to adopt?
|
|
||
| ### Wait and Delay Methods | ||
|
|
||
| #### ``wait(Measure<Time>)`` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| #### ``wait(Measure<Time>)`` | |
| #### ``wait(Time)`` |
|
|
||
| #### ``fork(Command)`` | ||
|
|
||
| Starts a command in the background without waiting for it to finish. Returns a ``CoroutineFuture`` you can ``await()`` later. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LLM hallucination? fork returns void
| intake.setSpeed(0); | ||
| }).named("Collect Until Full"); | ||
|
|
||
| ### Parallel Actions with Timeout |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we'd just use the withTimeout decorator instead of manually racing with timed wait commands
|
|
||
| ### 4. Child Commands and Lifetimes | ||
|
|
||
| Commands started with ``await()`` or ``fork()`` are "child commands" of the parent. If the parent is canceled, all children are automatically canceled. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
likewise, interrupting a child command will also interrupt its parent (and its parent and... all the way up the chain). One child interrupting another, though, will not interrupt their shared parent
| } | ||
| }); | ||
|
|
||
| ### 2. Don't Yield Inside Synchronized Blocks |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not relevant if we're on Java 25
|
I think I touched them all. I will go back through the comments later to make sure |
source/docs/software/commandbased/commands-v3/getting-started.rst
Outdated
Show resolved
Hide resolved
source/docs/software/commandbased/commands-v3/getting-started.rst
Outdated
Show resolved
Hide resolved
source/docs/software/commandbased/commands-v3/getting-started.rst
Outdated
Show resolved
Hide resolved
sciencewhiz
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm really concerned about the amount of code, LLM hallucinations, and the fact that the framework hasn't had team feedback yet, so I expect more changes are coming. I think the code needs to be from examples or snippets, so we don't end up with code that doesn't work and isn't noticed.
|
|
||
| Commands v3 is the next-generation command-based framework for Java that introduces imperative-style command writing using coroutines. Instead of building complex chains of lambda expressions and decorators, you can write command logic as straightforward sequential code with loops, conditionals, and explicit control flow. | ||
|
|
||
| **WPILib recommends Commands v3 for Java teams.** Commands v3 is actively being developed with new features including improved telemetry, enhanced trigger functionality, and self-canceling commands. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's too early to explicitly recommend Commands v3. I'd either be silent (and let teams make the decision based on the pros/cons below), or ask teams to try it and provide feedback.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was discussion on this already and this was the way I was told to do it. I agree with you that the lack of testing at this point it concerning and it worries me too. By the time all this goes live in 2027 I hope I will feel much more comfortable.
| **WPILib recommends Commands v3 for Java teams.** Commands v3 is actively being developed with new features including improved telemetry, enhanced trigger functionality, and self-canceling commands. | ||
|
|
||
| .. warning:: | ||
| Commands v3 is **Java-only** and does not support C++ or Python. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Somewhere it might be good to document why it's java only, but probably not here.
|
|
||
| See :ref:`docs/software/commandbased/commands-v2/index:Commands v2 Programming` for the v2 documentation. | ||
|
|
||
| ## What's New in v3? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd put this ahead of the v3 vs v2 comparison
|
|
||
| ## Mechanisms and Commands | ||
|
|
||
| .. image:: ../diagrams/subsystems-and-commands.drawio.svg |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be updated to replace subsystems with mechanism.
|
|
||
| See :ref:`docs/software/commandbased/commands-v3/command-compositions-v3:Command Compositions` for more details. | ||
|
|
||
| ## When to Use v3 vs v2 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This also shows up in the index. Should only be one place
|
|
||
| ## Example: Complete Small Project | ||
|
|
||
| See the full example structure: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is confusing. Is it missing a full project or link to full project? or is it duplicative of the first section?
|
|
||
| ## Should You Migrate? | ||
|
|
||
| **WPILib recommends migrating to Commands v3 for Java teams.** Commands v3 is the future direction of command-based programming with ongoing development and new features including improved telemetry, enhanced triggers, and self-canceling commands. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Similar to my previous comment, I think this needs to be reworked to not be so final on a framework that doesn't have much runtime
| **Migrate to v3 if:** | ||
|
|
||
| - You're a Java team | ||
| - You want to use the actively developed command framework |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Given the number of PRs for v2, I think both v2 and v3 are actively developed
|
|
||
| ### 1. Always Yield in Loops | ||
|
|
||
| In v3, **you must call** ``coroutine.yield()`` inside any loop. If you don't, the scheduler can't run other commands, and your robot will freeze. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It has happened
|
|
||
| ## Critical Rules and Gotchas | ||
|
|
||
| ### 1. Always Yield in Loops |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add something about compile error
Move all Commands v2 documentation files into a commands-v2/ subdirectory to prepare for Commands v3 documentation. This is Phase 1 of the Commands v3 documentation project. Changes: - Move 12 v2 documentation files to commands-v2/ subdirectory (preserving git history) - Create new commands-v2/index.rst as landing page for v2 docs - Update main commandbased/index.rst to serve as high-level framework chooser - Update 24 files with corrected cross-references to new v2 locations - Add 12 redirects to ensure old URLs continue working This reorganization addresses feedback on PR wpilibsuite#3095 to split the work into manageable phases. The next phase will add v3 documentation structure with TODO placeholders. Related to wpilibsuite#3095
Move all Commands v2 documentation files into a commands-v2/ subdirectory to prepare for Commands v3 documentation. This is Phase 1 of the Commands v3 documentation project. Changes: - Move 12 v2 documentation files to commands-v2/ subdirectory (preserving git history) - Create new commands-v2/index.rst as landing page for v2 docs - Update main commandbased/index.rst to serve as high-level framework chooser - Update 20 files with corrected cross-references to new v2 locations - Add 12 redirects to ensure old URLs continue working This reorganization addresses feedback on PR wpilibsuite#3095 to split the work into manageable phases. The next phase will add v3 documentation structure with TODO placeholders. Related to wpilibsuite#3095
Move all Commands v2 documentation files into a commands-v2/ subdirectory to prepare for Commands v3 documentation. This is Phase 1 of the Commands v3 documentation project. Changes: - Move 12 v2 documentation files to commands-v2/ subdirectory (preserving git history) - Create new commands-v2/index.rst as landing page for v2 docs - Update main commandbased/index.rst to serve as high-level framework chooser - Update 20 files with corrected cross-references to new v2 locations - Add 12 redirects to ensure old URLs continue working This reorganization addresses feedback on PR wpilibsuite#3095 to split the work into manageable phases. The next phase will add v3 documentation structure with TODO placeholders. Related to wpilibsuite#3095
Create skeleton structure for Commands v3 documentation with section headers and TODO notes describing what content should go in each section. This phase establishes the documentation organization for review before content is written. Files created: - index.rst: Landing page with overview and quick examples - what-is-commands-v3.rst: Conceptual foundation and core concepts - getting-started.rst: Hands-on tutorial for first v3 program - mechanisms.rst: Deep dive into Mechanisms (v3's Subsystems) - commands-and-coroutines.rst: Core command creation and coroutine API - async-await-patterns.rst: Async/await helpers for orchestration - command-compositions.rst: Traditional composition groups - binding-commands-to-triggers.rst: Button bindings and triggers - priorities-and-interrupts.rst: Priority system and interruption - structuring-v3-project.rst: Code organization best practices - testing-and-simulation.rst: Testing commands with simulation - telemetry-and-debugging.rst: Enhanced telemetry and debugging - migration-from-v2.rst: Migration guide from v2 to v3 - advanced-topics.rst: Advanced patterns and edge cases Each file contains: - Section headers outlining the article structure - TODO directives describing what content should be written - Guidance for future content writers on what to include No actual tutorial content or code examples are included - this is purely structural planning for review. Related to wpilibsuite#3095 Related to wpilibsuite#3165
Move all Commands v2 documentation files into a commands-v2/ subdirectory to prepare for Commands v3 documentation. This is Phase 1 of the Commands v3 documentation project. Changes: - Move 12 v2 documentation files to commands-v2/ subdirectory (preserving git history) - Create new commands-v2/index.rst as landing page for v2 docs - Update main commandbased/index.rst to serve as high-level framework chooser - Update 20 files with corrected cross-references to new v2 locations - Add 12 redirects to ensure old URLs continue working This reorganization addresses feedback on PR wpilibsuite#3095 to split the work into manageable phases. The next phase will add v3 documentation structure with TODO placeholders. Related to wpilibsuite#3095
Move all Commands v2 documentation files into a commands-v2/ subdirectory to prepare for Commands v3 documentation. This is Phase 1 of the Commands v3 documentation project. Changes: - Move 12 v2 documentation files to commands-v2/ subdirectory (preserving git history) - Create new commands-v2/index.rst as landing page for v2 docs - Update main commandbased/index.rst to serve as high-level framework chooser - Update 20 files with corrected cross-references to new v2 locations - Add 12 redirects to ensure old URLs continue working This reorganization addresses feedback on PR wpilibsuite#3095 to split the work into manageable phases. The next phase will add v3 documentation structure with TODO placeholders. Related to wpilibsuite#3095
Move all Commands v2 documentation files into a commands-v2/ subdirectory to prepare for Commands v3 documentation. This is Phase 1 of the Commands v3 documentation project. Changes: - Move 12 v2 documentation files to commands-v2/ subdirectory (preserving git history) - Create new commands-v2/index.rst as landing page for v2 docs - Update main commandbased/index.rst to serve as high-level framework chooser - Update 20 files with corrected cross-references to new v2 locations - Add 12 redirects to ensure old URLs continue working This reorganization addresses feedback on PR wpilibsuite#3095 to split the work into manageable phases. The next phase will add v3 documentation structure with TODO placeholders. Related to wpilibsuite#3095
Create skeleton structure for Commands v3 documentation with section headers and TODO notes describing what content should go in each section. This phase establishes the documentation organization for review before content is written. Files created: - index.rst: Landing page with overview and quick examples - what-is-commands-v3.rst: Conceptual foundation and core concepts - getting-started.rst: Hands-on tutorial for first v3 program - mechanisms.rst: Deep dive into Mechanisms (v3's Subsystems) - commands-and-coroutines.rst: Core command creation and coroutine API - async-await-patterns.rst: Async/await helpers for orchestration - command-compositions.rst: Traditional composition groups - binding-commands-to-triggers.rst: Button bindings and triggers - priorities-and-interrupts.rst: Priority system and interruption - structuring-v3-project.rst: Code organization best practices - testing-and-simulation.rst: Testing commands with simulation - telemetry-and-debugging.rst: Enhanced telemetry and debugging - migration-from-v2.rst: Migration guide from v2 to v3 - advanced-topics.rst: Advanced patterns and edge cases Each file contains: - Section headers outlining the article structure - TODO directives describing what content should be written - Guidance for future content writers on what to include No actual tutorial content or code examples are included - this is purely structural planning for review. Related to wpilibsuite#3095 Related to wpilibsuite#3165
Move all Commands v2 documentation files into a commands-v2/ subdirectory to prepare for Commands v3 documentation. This is Phase 1 of the Commands v3 documentation project. Changes: - Move 12 v2 documentation files to commands-v2/ subdirectory (preserving git history) - Create new commands-v2/index.rst as landing page for v2 docs - Update main commandbased/index.rst to serve as high-level framework chooser - Update 20 files with corrected cross-references to new v2 locations - Add 12 redirects to ensure old URLs continue working This reorganization addresses feedback on PR wpilibsuite#3095 to split the work into manageable phases. The next phase will add v3 documentation structure with TODO placeholders. Related to wpilibsuite#3095
Move all Commands v2 documentation files into a commands-v2/ subdirectory to prepare for Commands v3 documentation. This is Phase 1 of the Commands v3 documentation project. Changes: - Move 12 v2 documentation files to commands-v2/ subdirectory (preserving git history) - Create new commands-v2/index.rst as landing page for v2 docs - Update main commandbased/index.rst to serve as high-level framework chooser - Update 20 files with corrected cross-references to new v2 locations - Add 12 redirects to ensure old URLs continue working This reorganization addresses feedback on PR wpilibsuite#3095 to split the work into manageable phases. The next phase will add v3 documentation structure with TODO placeholders. Related to wpilibsuite#3095
Create skeleton structure for Commands v3 documentation with section headers and TODO notes describing what content should go in each section. This phase establishes the documentation organization for review before content is written. Files created: - index.rst: Landing page with overview and quick examples - what-is-commands-v3.rst: Conceptual foundation and core concepts - getting-started.rst: Hands-on tutorial for first v3 program - mechanisms.rst: Deep dive into Mechanisms (v3's Subsystems) - commands-and-coroutines.rst: Core command creation and coroutine API - async-await-patterns.rst: Async/await helpers for orchestration - command-compositions.rst: Traditional composition groups - binding-commands-to-triggers.rst: Button bindings and triggers - priorities-and-interrupts.rst: Priority system and interruption - structuring-v3-project.rst: Code organization best practices - testing-and-simulation.rst: Testing commands with simulation - telemetry-and-debugging.rst: Enhanced telemetry and debugging - migration-from-v2.rst: Migration guide from v2 to v3 - advanced-topics.rst: Advanced patterns and edge cases Each file contains: - Section headers outlining the article structure - TODO directives describing what content should be written - Guidance for future content writers on what to include No actual tutorial content or code examples are included - this is purely structural planning for review. Related to wpilibsuite#3095 Related to wpilibsuite#3165
Move all Commands v2 documentation files into a commands-v2/ subdirectory to prepare for Commands v3 documentation. This is Phase 1 of the Commands v3 documentation project. Changes: - Move 12 v2 documentation files to commands-v2/ subdirectory (preserving git history) - Create new commands-v2/index.rst as landing page for v2 docs - Update main commandbased/index.rst to serve as high-level framework chooser - Update 20 files with corrected cross-references to new v2 locations - Add 12 redirects to ensure old URLs continue working This reorganization addresses feedback on PR #3095 to split the work into manageable phases. The next phase will add v3 documentation structure with TODO placeholders. Related to #3095
I added a bunch of stuff in here. Maybe some of it is too verbose? The idea was basically that Commands v3 could almost completely stand on its own.