Skip to content

Add preliminary articles for commands V3#21

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

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

Conversation

@Daniel1464
Copy link
Copy Markdown

No description provided.

{ label: 'The Command Scheduler', slug: 'section-2-commands/the-command-scheduler' },
],
}
]
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.

missing a , should be ],

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

# What is a Command?
Copy link
Copy Markdown
Collaborator

@Adrianamm Adrianamm May 25, 2026

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.

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

without waiting for it to finish. In this case, the `println("Hello!")` statement
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.
Copy link
Copy Markdown
Collaborator

@Adrianamm Adrianamm May 25, 2026

Choose a reason for hiding this comment

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

"on a controller" so it's clear where the buttons are coming from?

But the vast majority of the time, you want a command to run when a button on a controller is pressed or held down

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

}
```

In this case, the `runMotor` command will run once the left trigger is pressed.
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.

Another "on a controller" so it's clear where the buttons are coming from

In this case, the runMotor command will run once the left trigger on the controller is pressed.


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

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.

2 participants