Skip to content

Add preliminary articles for commands V3#21

Open
Daniel1464 wants to merge 10 commits into
frcsoftware:mainfrom
Daniel1464:commandsDocs
Open

Add preliminary articles for commands V3#21
Daniel1464 wants to merge 10 commits into
frcsoftware:mainfrom
Daniel1464:commandsDocs

Conversation

@Daniel1464

Copy link
Copy Markdown

No description provided.

---
import Aside from '../../../components/Aside.astro';

# What is a Command?

@Adrianamm Adrianamm May 25, 2026

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it needs some explanation of what command based programming is to make the transition between intro to Java and FRC programming smoother. I also think that knowing what is Command Based programming as a concept, even if it's in simple terms, is important.
This introduction could also mention what WPILib is since it's sort of mentioned in #9 but it's never correctly explained.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would probably be better to direct them to the WPILib docs on commands / subsystems and say 'familiarize yourself with commands and subsystems before continuing with this section'.

In this section you can refer back to it, but you're likely going to need to reiterate everything that's already said in those docs in order to provide the necessary context for teaching this lesson.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't do that because when I first read wpilib's command docs as a freshman, they pretty much threw everything at you all at once instead of starting with the basics.

Maybe V3 docs would be different, im down to moving some of the stuff covered here to the wpilib docs instead and redirecting people.

as raising an arm joint or complex as an autonomous program. Think of them as powered-up
methods that can handle the requirements for controlling a robot over long periods of time.

# What's wrong with methods?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about "Why not use methods?" because I think that's the question most new programmers might think. also "what's wrong" could sound like methods aren't supposed to be used in FRC programming

```
Here, the problem is with the while loop. While it's running, we are only setting the voltage of the motor;
not listening to button presses, logging data, and running other background tasks. To function properly, WPILib
requires many of these background tasks to be run periodically(at a 0.02 second or smaller interval).

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about

many of these background tasks to be run periodically, which means they run at 0.02 seconds or at a smaller interval

Functionally, commands are superpowered methods that gives you a special statement that runs
these background tasks within a while loop: `coroutine.yield()`.
```java
System.out.println("Hello World!");

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

System.out.println isn't used for print outs in FRC but I think this is a good spot to introduce and use Driverstation.reportWarning()

The following allows you to start a command asynchronously:

```java
Command runMotor = ...; // see previous example

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would just put the previous code there instead so viewers don't have to keep scrolling up to reference it. In addition, you could put a comment like //code from previous example on top so viewers know where the code is coming from if that's helpful

will run before the `runMotor` command completes.

But the vast majority of the time, you want a command to run when a button is pressed or held down.
To do this, we use a `CommandGamepad` instead of a `Gamepad`, like so:

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At this point, they don't know what a Gamepad is so it's probably not worth mentioning

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't they have to know it due to section 1a being about coding a kitbot?


In this case, the `runMotor` command will run once the left trigger is pressed.
If it is desired to cancel the runMotor command once the left trigger is released,
the `onTrue` statement can be replaced with `whileTrue`:

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would explain more on why that is the case

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Trigger binding functions could use their own section with the nice graphs from that one site


# An overview of Mechanisms

A `Mechanism`, on the surface level, is a part of the robot, like a double-jointed arm or a shooter.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It also might help to briefly explain the connection between Commands and Mechanisms. Could be as simple as explaining how Mechanism use Commands to move a part of the robot. Like spinning a motor on a shooter to shot a ball.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think a mechanism is any part of the robot you want to control separately from any other mechanism. Mechanisms run a single command at a time. If you want to run two separate commands, you need two mechanisms. Sometimes this corresponds to subsystem-level components, but they really should be thought of as two separate ways of grouping the robot. The mapping of real world mechanisms to command mechanisms is not always 1:1

# An overview of Mechanisms

A `Mechanism`, on the surface level, is a part of the robot, like a double-jointed arm or a shooter.
If you've used commands V2 before, they're the exact same thing as subsystems (and in that case, feel free

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might be worth putting that in a note rather than in a paragraph

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And at the top probably

Comment thread src/content/docs/section-2-commands/why-mechanisms.mdx Outdated
Comment thread src/content/docs/section-2-commands/why-commands.mdx Outdated
Comment thread src/content/docs/section-2-commands/why-commands.mdx Outdated
Comment thread src/config/sidebarConfig.ts Outdated
Comment on lines +15 to +29
# What's wrong with methods?

Let's say you're writing a method that prints "hello world!" to the console,
then sets a motor to 5 volts indefinitely. Your first instinct might be to do this:
```java
public void printHiAndRunMotor() {
System.out.println("Hello World!");
while (true) {
motor.setVoltage(5.0);
}
}
```
Here, the problem is with the while loop. While it's running, we are only setting the voltage of the motor;
not listening to button presses, logging data, and running other background tasks. To function properly, WPILib
requires many of these background tasks to be run periodically(at a 0.02 second or smaller interval).

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is a poor example of explaining the benefits of command-based, since it's solved in iterative robots.

I don't think the comparison between commands and methods necessarily needs to happen. Commands at their heart are methods, the power of the paradigm is the declarative nature and deferred execution.

Comment thread src/content/docs/section-2-commands/why-commands.mdx Outdated
Comment thread src/content/docs/section-2-commands/why-commands.mdx Outdated
Comment thread src/content/docs/section-2-commands/why-commands.mdx Outdated
Comment thread src/content/docs/section-2-commands/why-commands.mdx Outdated
Comment thread src/content/docs/section-2-commands/why-mechanisms.mdx Outdated
Comment thread src/content/docs/section-2-commands/why-mechanisms.mdx Outdated
Comment thread src/content/docs/section-2-commands/why-mechanisms.mdx Outdated
Comment thread src/content/docs/section-2-commands/why-mechanisms.mdx Outdated
Comment thread src/content/docs/section-2-commands/why-mechanisms.mdx Outdated

### Defining Mechanisms
<Aside type="note">
Mechanisms in Commands V3 are identical to Subsystems in Commands V2.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think there could be something here that makes it clear that V2 is "older" to avoid new students thinking that they missed something. Could be something like adding "For those already familiar with Command Based: " to the start of that line

.named("Set to Full Throttle");
```

Notice that:

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would use this part to expand a bit on the syntax of a command. Mainly explaining what is "run", what is "coroutine".
Also I think it might be work putting in a line about how setThrottle is used to set the speed of the motor

```java
public class Robot {
private final CommandXboxController xbox = new CommandXboxController(0);
private final CommandDualSenseController dualSense = new CommandDualSenseController(1);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think a small explanation on what CommandXboxController and CommandDualSenseController are can be helpful to those with no FRC programming background. It's also not clear on what the difference between the two are.
If it's helpful, you could also link wpilib docs or such so the reader can get additional information.


Think of calling `schedule()` as ordering a robot to start washing the dishes
without waiting for it to finish. In this case, the `println("Hello!")` statement
will run before the `runMotor` command completes.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is runMotor? runMotor is only mentioned once and that's here

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops, that was a relic from the previous docs

}
```

Example OpMode usage:

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we might need to explain OpMode after Commands? Right now it's not really explained but explaining OpMode and Commands Based might be a lot? Unsure

}
```

Can you figure out why the error message says "bind it to a trigger"? (this is left as an exercise to the reader.)

@Adrianamm Adrianamm Jun 18, 2026

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it might be helpful to give the answer here. Seeing an explanation of the answer might help the reader understand why there is an error message if they were struggling to understand in the first place. With the operators section, I put the answers in an accordion drop down so the answer wasn't right in front of them.

<details class="accordion">
text here
</details>

Comment thread src/content/docs/section-2-commands/the-command-body.mdx Outdated
Comment thread src/content/docs/section-2-commands/the-command-body.mdx Outdated
System.out.println("Full Speed Baby!");
while (true) {
motor.setThrottle(1.0);
coroutine.yield();

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think // Confused? We'll explain this in the section below should be here first. Since it's the first time the reader is seeing yield(). You don't need to repeat that comment in the below example if the comment is moved up here

Co-authored-by: Adriana  <adrianammassie@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants