WPILibC++ 2023.4.3-108-ge5452e3
frc2::FunctionalCommand Class Reference

A command that allows the user to pass in functions for each of the basic command methods through the constructor. More...

#include <frc2/command/FunctionalCommand.h>

Inheritance diagram for frc2::FunctionalCommand:
frc2::CommandHelper< CommandBase, FunctionalCommand >

Public Member Functions

 FunctionalCommand (std::function< void()> onInit, std::function< void()> onExecute, std::function< void(bool)> onEnd, std::function< bool()> isFinished, std::initializer_list< Subsystem * > requirements)
 Creates a new FunctionalCommand. More...
 
 FunctionalCommand (std::function< void()> onInit, std::function< void()> onExecute, std::function< void(bool)> onEnd, std::function< bool()> isFinished, std::span< Subsystem *const > requirements={})
 Creates a new FunctionalCommand. More...
 
 FunctionalCommand (FunctionalCommand &&other)=default
 
 FunctionalCommand (const FunctionalCommand &other)=default
 
void Initialize () override
 
void Execute () override
 
void End (bool interrupted) override
 
bool IsFinished () override
 
- Public Member Functions inherited from frc2::CommandHelper< CommandBase, FunctionalCommand >
 CommandHelper ()=default
 
CommandPtr ToPtr () &&override
 

Additional Inherited Members

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

Detailed Description

A command that allows the user to pass in functions for each of the basic command methods through the constructor.

Useful for inline definitions of complex commands - note, however, that if a command is beyond a certain complexity it is usually better practice to write a proper class for it than to inline it.

This class is provided by the NewCommands VendorDep

Constructor & Destructor Documentation

◆ FunctionalCommand() [1/4]

frc2::FunctionalCommand::FunctionalCommand ( std::function< void()>  onInit,
std::function< void()>  onExecute,
std::function< void(bool)>  onEnd,
std::function< bool()>  isFinished,
std::initializer_list< Subsystem * >  requirements 
)

Creates a new FunctionalCommand.

Parameters
onInitthe function to run on command initialization
onExecutethe function to run on command execution
onEndthe function to run on command end
isFinishedthe function that determines whether the command has finished
requirementsthe subsystems required by this command

◆ FunctionalCommand() [2/4]

frc2::FunctionalCommand::FunctionalCommand ( std::function< void()>  onInit,
std::function< void()>  onExecute,
std::function< void(bool)>  onEnd,
std::function< bool()>  isFinished,
std::span< Subsystem *const >  requirements = {} 
)

Creates a new FunctionalCommand.

Parameters
onInitthe function to run on command initialization
onExecutethe function to run on command execution
onEndthe function to run on command end
isFinishedthe function that determines whether the command has finished
requirementsthe subsystems required by this command

◆ FunctionalCommand() [3/4]

frc2::FunctionalCommand::FunctionalCommand ( FunctionalCommand &&  other)
default

◆ FunctionalCommand() [4/4]

frc2::FunctionalCommand::FunctionalCommand ( const FunctionalCommand other)
default

Member Function Documentation

◆ End()

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

◆ Execute()

void frc2::FunctionalCommand::Execute ( )
override

◆ Initialize()

void frc2::FunctionalCommand::Initialize ( )
override

◆ IsFinished()

bool frc2::FunctionalCommand::IsFinished ( )
override

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