-
Notifications
You must be signed in to change notification settings - Fork 283
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?
|
||
* - 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
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())); |
); | ||
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
### 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 |
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.