WPILibC++ 2024.3.2-63-g0f8aa8a
frc2::DeferredCommand Class Reference

Defers Command construction to runtime. More...

#include <frc2/command/DeferredCommand.h>

Inheritance diagram for frc2::DeferredCommand:
frc2::CommandHelper< Command, DeferredCommand >

Public Member Functions

 DeferredCommand (wpi::unique_function< CommandPtr()> supplier, Requirements requirements)
 Creates a new DeferredCommand that directly runs the supplied command when initialized, and ends when it ends. More...
 
 DeferredCommand (DeferredCommand &&other)=default
 
void Initialize () override
 
void Execute () override
 
void End (bool interrupted) override
 
bool IsFinished () override
 
void InitSendable (wpi::SendableBuilder &builder) override
 
- Public Member Functions inherited from frc2::CommandHelper< Command, DeferredCommand >
 CommandHelper ()=default
 
CommandPtr ToPtr () &&override
 

Additional Inherited Members

- Protected Member Functions inherited from frc2::CommandHelper< Command, DeferredCommand >
std::unique_ptr< CommandTransferOwnership () &&override
 

Detailed Description

Defers Command construction to runtime.

Runs the command returned by a supplier when this command is initialized, and ends when it ends. Useful for performing runtime tasks before creating a new command. If this command is interrupted, it will cancel the command.

Note that the supplier must create a new Command each call. For selecting one of a preallocated set of commands, use SelectCommand.

This class is provided by the NewCommands VendorDep

Constructor & Destructor Documentation

◆ DeferredCommand() [1/2]

frc2::DeferredCommand::DeferredCommand ( wpi::unique_function< CommandPtr()>  supplier,
Requirements  requirements 
)

Creates a new DeferredCommand that directly runs the supplied command when initialized, and ends when it ends.

Useful for lazily creating commands when the DeferredCommand is initialized, such as if the supplied command depends on runtime state. The supplier will be called each time this command is initialized. The supplier must create a new Command each call.

Parameters
supplierThe command supplier
requirementsThe command requirements.

◆ DeferredCommand() [2/2]

frc2::DeferredCommand::DeferredCommand ( DeferredCommand &&  other)
default

Member Function Documentation

◆ End()

void frc2::DeferredCommand::End ( bool  interrupted)
override

◆ Execute()

void frc2::DeferredCommand::Execute ( )
override

◆ Initialize()

void frc2::DeferredCommand::Initialize ( )
override

◆ InitSendable()

void frc2::DeferredCommand::InitSendable ( wpi::SendableBuilder builder)
override

◆ IsFinished()

bool frc2::DeferredCommand::IsFinished ( )
override

The documentation for this class was generated from the following file: