Intro to FRC Programming - Romi
  • INTRODUCTION
    • Overview
    • Important Links
  • 💽Setup
    • Setting up the Romi's Software
    • Downloading Essential Tools
    • APCS vs FRC
  • How To Code in VSC
    • VSC- Intro
    • A Tour Through VSC
    • Creating a Regular Java Project
  • Intro to Java
    • What is Java?
    • Beginning Steps
    • 🟩Fundimentals of Java
      • Variables
      • Operations
      • Methods
      • Comments
      • If Statements and Conditions
      • Boolean Zen
      • Loops
      • Challenge- Create a Box House
    • 🟨Advanced Concepts
      • Objects
      • Scanners
      • Null Objects
      • Arrays
      • Errors
      • For-Each Loops
    • 🟥Object Oriented Programming
      • Basics of OOP
      • Instance Classes
      • Static Classes
  • 🕑Romi Curriculum- Timed Base
    • Romi Curriculum- Introduction
    • Creating a WPILIB Project
    • Running Your Code
    • The Robot Class
    • Subsystems
      • RomiDrivetrain
    • Cool stuff i will rename this category later
      • Spark Motors
      • PIDs
      • External Controllers
      • Encoders
  • 🖥️Romi Curriculum- Command Based
    • Command Based Code
    • RobotContainer
    • Commands
    • CommandScheduler
  • UNRELATED IMPORTANT CODING KNOWLEDGE
    • Constants
  • SAMPLE CODE
    • Tank Drive Example
      • RobotContainer
      • TankDriveSubsystem
      • MoveRobotCommand
    • Worktop Systems Sample Java Code
      • Belt Elevator Sample Code
      • Rotating Arm Sample Code
Powered by GitBook
On this page
  • Constructor
  • Behavior Methods
  • void Intializalize()
  • void Execute()
  • void End(boolean interrupted)
  • boolean IsFinished()
  1. Romi Curriculum- Command Based

Commands

PreviousRobotContainerNextCommandScheduler

Last updated 2 months ago

Commands are used to execute specific actions or sequences of code at a particular time. They achieve this by interacting with and controlling Subsystems.

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.

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 single parameter— elevatorPosition.

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

Behavior Methods

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

void Intializalize()

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.

The Execute() method runs repeatedly while the command is scheduled, similar to the Periodic() method in a subsystem. Each time the runs, this method is executed. It contains the core logic of the command.

void End(boolean interrupted)

End() 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 the 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.

🖥️
CommandScheduler