> For the complete documentation index, see [llms.txt](https://velocity-raptors-9450.gitbook.io/intro-to-frc-programming-romi/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://velocity-raptors-9450.gitbook.io/intro-to-frc-programming-romi/romi-command-based/commands.md).

# Commands

Commands are used to execute specific actions or sequences of code at a particular time. They achieve this by interacting with and controlling [Subsystems](/intro-to-frc-programming-romi/romi-command-based/subsystems.md).

Commands are scheduled to be checked by your code's [Side Tangent- CommandScheduler](/intro-to-frc-programming-romi/romi-command-based/commands/side-tangent-commandscheduler.md) (usually it's done automatically, so you won't have to worry about it too much). For now- just know that you make commands to use them in Triggers, and CommandScheduler runs them. &#x20;

## Constructor

The constructor will depend on the command's function. For example, a `MoveElevator` command would have a vastly different constructor than a `GrabComponent()` command. But for this page, we'll cover the basic command that comes with the FRC Template project.&#x20;

The constructor of a command depends on its specific functionality. Generally, you'd put important fields through a parameter. For example, a `MoveElevator` command could have a constructor with a two parameters— a double `elevatorPosition` and an ElevatorSubsystem `elevatorSubsystem.`

The constructor typically initializes any necessary variables or dependencies (generally other`Subsystems`) required for the command to function. But for this page, we'll cover the basic command that comes with the FRC Template project.&#x20;

## Behavior Methods

These three methods give the command its behavior. Generally, stick most of your code in these three.

## void Initialize()

`Initialize()` runs once— right when the command is scheduled. In this part of the code, you should get your command ready for the `execute()` method.

The `Initialize()` method runs once, immediately when the command is scheduled. This is where you should perform any setup or preparation needed before the command begins execution.

## `void Execute()`

`Execute()` runs while the command is scheduled, similar to `periodic()` in a subsystem. Every time the CommandScheduler runs its commands, this method is run as well.&#x20;

The `Execute()` method runs repeatedly while the command is scheduled, similar to the `Periodic()` method in a subsystem. Each time the [`CommandScheduler`](/intro-to-frc-programming-romi/romi-command-based/commands/side-tangent-commandscheduler.md) runs, this method is executed. It contains the core logic of the command.

## void End(boolean interrupted)

<kbd>End()</kbd> runs when the command is ended, naturally or forcibly.

Its parameter `interrupted` returns true if the command was manually canceled, like using the `cancel()` method. Otherwise, it would return false.

Typically, here you'd try to wrap up your code and reset everything.

The `End()` method is called when the command finishes, either naturally or due to interruption. The `interrupted` parameter is `true` if the command was forcibly canceled (e.g., using the `cancel()` method), and `false` if it ended normally. This method is typically used to clean up resources, reset states, or perform any final actions.

### boolean IsFinished()

`IsFinished()` tells CommandScheduler when to end this command by returning a boolean. When this method returns true, the command will automatically finish and `End()` will run.

The `IsFinished()` method tells  `CommandScheduler` when to end the command. It returns a boolean value: `true` indicates that the command should finish, and `false` means it should continue running. When this method returns `true`, the `End()` method will automatically be run, stopping the command.
