WPILibC++ 2024.1.1-beta-4
frc2::ConditionalCommand Class Reference

A command composition that runs one of two commands, depending on the value of the given condition when this command is initialized. More...

#include <frc2/command/ConditionalCommand.h>

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

Public Member Functions

template<std::derived_from< Command > Command1, std::derived_from< Command > Command2>
 ConditionalCommand (Command1 &&onTrue, Command2 &&onFalse, std::function< bool()> condition)
 Creates a new ConditionalCommand. More...
 
 ConditionalCommand (std::unique_ptr< Command > &&onTrue, std::unique_ptr< Command > &&onFalse, std::function< bool()> condition)
 Creates a new ConditionalCommand. More...
 
 ConditionalCommand (ConditionalCommand &&other)=default
 
 ConditionalCommand (const ConditionalCommand &other)=delete
 
void Initialize () override
 
void Execute () override
 
void End (bool interrupted) override
 
bool IsFinished () override
 
bool RunsWhenDisabled () const override
 
InterruptionBehavior GetInterruptionBehavior () const override
 
void InitSendable (wpi::SendableBuilder &builder) override
 
- Public Member Functions inherited from frc2::CommandHelper< Command, ConditionalCommand >
 CommandHelper ()=default
 
CommandPtr ToPtr () &&override
 

Additional Inherited Members

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

Detailed Description

A command composition that runs one of two commands, depending on the value of the given condition when this command is initialized.

The rules for command compositions apply: command instances that are passed to it are owned by the composition and cannot be added to any other composition or scheduled individually, and the composition requires all subsystems its components require.

This class is provided by the NewCommands VendorDep

See also
ScheduleCommand

Constructor & Destructor Documentation

◆ ConditionalCommand() [1/4]

template<std::derived_from< Command > Command1, std::derived_from< Command > Command2>
frc2::ConditionalCommand::ConditionalCommand ( Command1 &&  onTrue,
Command2 &&  onFalse,
std::function< bool()>  condition 
)
inline

Creates a new ConditionalCommand.

Parameters
onTruethe command to run if the condition is true
onFalsethe command to run if the condition is false
conditionthe condition to determine which command to run

◆ ConditionalCommand() [2/4]

frc2::ConditionalCommand::ConditionalCommand ( std::unique_ptr< Command > &&  onTrue,
std::unique_ptr< Command > &&  onFalse,
std::function< bool()>  condition 
)

Creates a new ConditionalCommand.

Parameters
onTruethe command to run if the condition is true
onFalsethe command to run if the condition is false
conditionthe condition to determine which command to run

◆ ConditionalCommand() [3/4]

frc2::ConditionalCommand::ConditionalCommand ( ConditionalCommand &&  other)
default

◆ ConditionalCommand() [4/4]

frc2::ConditionalCommand::ConditionalCommand ( const ConditionalCommand other)
delete

Member Function Documentation

◆ End()

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

◆ Execute()

void frc2::ConditionalCommand::Execute ( )
override

◆ GetInterruptionBehavior()

InterruptionBehavior frc2::ConditionalCommand::GetInterruptionBehavior ( ) const
override

◆ Initialize()

void frc2::ConditionalCommand::Initialize ( )
override

◆ InitSendable()

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

◆ IsFinished()

bool frc2::ConditionalCommand::IsFinished ( )
override

◆ RunsWhenDisabled()

bool frc2::ConditionalCommand::RunsWhenDisabled ( ) const
override

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