WPILibC++ 2023.4.3-108-ge5452e3
frc2::cmd Namespace Reference

Namespace for command factories. More...

Namespaces

namespace  impl
 

Functions

CommandPtr None ()
 Constructs a command that does nothing, finishing immediately. More...
 
CommandPtr RunOnce (std::function< void()> action, std::initializer_list< Subsystem * > requirements)
 Constructs a command that runs an action once and finishes. More...
 
CommandPtr RunOnce (std::function< void()> action, std::span< Subsystem *const > requirements={})
 Constructs a command that runs an action once and finishes. More...
 
CommandPtr Run (std::function< void()> action, std::initializer_list< Subsystem * > requirements)
 Constructs a command that runs an action every iteration until interrupted. More...
 
CommandPtr Run (std::function< void()> action, std::span< Subsystem *const > requirements={})
 Constructs a command that runs an action every iteration until interrupted. More...
 
CommandPtr StartEnd (std::function< void()> start, std::function< void()> end, std::initializer_list< Subsystem * > requirements)
 Constructs a command that runs an action once and another action when the command is interrupted. More...
 
CommandPtr StartEnd (std::function< void()> start, std::function< void()> end, std::span< Subsystem *const > requirements={})
 Constructs a command that runs an action once and another action when the command is interrupted. More...
 
CommandPtr RunEnd (std::function< void()> run, std::function< void()> end, std::initializer_list< Subsystem * > requirements)
 Constructs a command that runs an action every iteration until interrupted, and then runs a second action. More...
 
CommandPtr RunEnd (std::function< void()> run, std::function< void()> end, std::span< Subsystem *const > requirements={})
 Constructs a command that runs an action every iteration until interrupted, and then runs a second action. More...
 
CommandPtr Print (std::string_view msg)
 Constructs a command that prints a message and finishes. More...
 
CommandPtr Wait (units::second_t duration)
 Constructs a command that does nothing, finishing after a specified duration. More...
 
CommandPtr WaitUntil (std::function< bool()> condition)
 Constructs a command that does nothing, finishing once a condition becomes true. More...
 
CommandPtr Either (CommandPtr &&onTrue, CommandPtr &&onFalse, std::function< bool()> selector)
 Runs one of two commands, based on the boolean selector function. More...
 
template<typename Key , std::convertible_to< CommandPtr >... CommandPtrs>
CommandPtr Select (std::function< Key()> selector, std::pair< Key, CommandPtrs > &&... commands)
 Runs one of several commands, based on the selector function. More...
 
CommandPtr Sequence (std::vector< CommandPtr > &&commands)
 Runs a group of commands in series, one after the other. More...
 
template<std::convertible_to< CommandPtr >... CommandPtrs>
CommandPtr Sequence (CommandPtrs &&... commands)
 Runs a group of commands in series, one after the other. More...
 
CommandPtr RepeatingSequence (std::vector< CommandPtr > &&commands)
 Runs a group of commands in series, one after the other. More...
 
template<std::convertible_to< CommandPtr >... CommandPtrs>
CommandPtr RepeatingSequence (CommandPtrs &&... commands)
 Runs a group of commands in series, one after the other. More...
 
CommandPtr Parallel (std::vector< CommandPtr > &&commands)
 Runs a group of commands at the same time. More...
 
template<std::convertible_to< CommandPtr >... CommandPtrs>
CommandPtr Parallel (CommandPtrs &&... commands)
 Runs a group of commands at the same time. More...
 
CommandPtr Race (std::vector< CommandPtr > &&commands)
 Runs a group of commands at the same time. More...
 
template<std::convertible_to< CommandPtr >... CommandPtrs>
CommandPtr Race (CommandPtrs &&... commands)
 Runs a group of commands at the same time. More...
 
CommandPtr Deadline (CommandPtr &&deadline, std::vector< CommandPtr > &&others)
 Runs a group of commands at the same time. More...
 
template<std::convertible_to< CommandPtr >... CommandPtrs>
CommandPtr Deadline (CommandPtr &&deadline, CommandPtrs &&... commands)
 Runs a group of commands at the same time. More...
 

Detailed Description

Namespace for command factories.

Function Documentation

◆ Deadline() [1/2]

template<std::convertible_to< CommandPtr >... CommandPtrs>
CommandPtr frc2::cmd::Deadline ( CommandPtr &&  deadline,
CommandPtrs &&...  commands 
)

Runs a group of commands at the same time.

Ends once a specific command finishes, and cancels the others.

◆ Deadline() [2/2]

CommandPtr frc2::cmd::Deadline ( CommandPtr &&  deadline,
std::vector< CommandPtr > &&  others 
)

Runs a group of commands at the same time.

Ends once a specific command finishes, and cancels the others.

◆ Either()

CommandPtr frc2::cmd::Either ( CommandPtr &&  onTrue,
CommandPtr &&  onFalse,
std::function< bool()>  selector 
)

Runs one of two commands, based on the boolean selector function.

Parameters
onTruethe command to run if the selector function returns true
onFalsethe command to run if the selector function returns false
selectorthe selector function

◆ None()

CommandPtr frc2::cmd::None ( )

Constructs a command that does nothing, finishing immediately.

◆ Parallel() [1/2]

template<std::convertible_to< CommandPtr >... CommandPtrs>
CommandPtr frc2::cmd::Parallel ( CommandPtrs &&...  commands)

Runs a group of commands at the same time.

Ends once all commands in the group finish.

◆ Parallel() [2/2]

CommandPtr frc2::cmd::Parallel ( std::vector< CommandPtr > &&  commands)

Runs a group of commands at the same time.

Ends once all commands in the group finish.

◆ Print()

CommandPtr frc2::cmd::Print ( std::string_view  msg)

Constructs a command that prints a message and finishes.

Parameters
msgthe message to print

◆ Race() [1/2]

template<std::convertible_to< CommandPtr >... CommandPtrs>
CommandPtr frc2::cmd::Race ( CommandPtrs &&...  commands)

Runs a group of commands at the same time.

Ends once any command in the group finishes, and cancels the others.

◆ Race() [2/2]

CommandPtr frc2::cmd::Race ( std::vector< CommandPtr > &&  commands)

Runs a group of commands at the same time.

Ends once any command in the group finishes, and cancels the others.

◆ RepeatingSequence() [1/2]

template<std::convertible_to< CommandPtr >... CommandPtrs>
CommandPtr frc2::cmd::RepeatingSequence ( CommandPtrs &&...  commands)

Runs a group of commands in series, one after the other.

Once the last command ends, the group is restarted.

◆ RepeatingSequence() [2/2]

CommandPtr frc2::cmd::RepeatingSequence ( std::vector< CommandPtr > &&  commands)

Runs a group of commands in series, one after the other.

Once the last command ends, the group is restarted.

◆ Run() [1/2]

CommandPtr frc2::cmd::Run ( std::function< void()>  action,
std::initializer_list< Subsystem * >  requirements 
)

Constructs a command that runs an action every iteration until interrupted.

Parameters
actionthe action to run
requirementssubsystems the action requires

◆ Run() [2/2]

CommandPtr frc2::cmd::Run ( std::function< void()>  action,
std::span< Subsystem *const >  requirements = {} 
)

Constructs a command that runs an action every iteration until interrupted.

Parameters
actionthe action to run
requirementssubsystems the action requires

◆ RunEnd() [1/2]

CommandPtr frc2::cmd::RunEnd ( std::function< void()>  run,
std::function< void()>  end,
std::initializer_list< Subsystem * >  requirements 
)

Constructs a command that runs an action every iteration until interrupted, and then runs a second action.

Parameters
runthe action to run every iteration
endthe action to run on interrupt
requirementssubsystems the action requires

◆ RunEnd() [2/2]

CommandPtr frc2::cmd::RunEnd ( std::function< void()>  run,
std::function< void()>  end,
std::span< Subsystem *const >  requirements = {} 
)

Constructs a command that runs an action every iteration until interrupted, and then runs a second action.

Parameters
runthe action to run every iteration
endthe action to run on interrupt
requirementssubsystems the action requires

◆ RunOnce() [1/2]

CommandPtr frc2::cmd::RunOnce ( std::function< void()>  action,
std::initializer_list< Subsystem * >  requirements 
)

Constructs a command that runs an action once and finishes.

Parameters
actionthe action to run
requirementssubsystems the action requires

◆ RunOnce() [2/2]

CommandPtr frc2::cmd::RunOnce ( std::function< void()>  action,
std::span< Subsystem *const >  requirements = {} 
)

Constructs a command that runs an action once and finishes.

Parameters
actionthe action to run
requirementssubsystems the action requires

◆ Select()

template<typename Key , std::convertible_to< CommandPtr >... CommandPtrs>
CommandPtr frc2::cmd::Select ( std::function< Key()>  selector,
std::pair< Key, CommandPtrs > &&...  commands 
)

Runs one of several commands, based on the selector function.

Parameters
selectorthe selector function
commandsmap of commands to select from

◆ Sequence() [1/2]

template<std::convertible_to< CommandPtr >... CommandPtrs>
CommandPtr frc2::cmd::Sequence ( CommandPtrs &&...  commands)

Runs a group of commands in series, one after the other.

◆ Sequence() [2/2]

CommandPtr frc2::cmd::Sequence ( std::vector< CommandPtr > &&  commands)

Runs a group of commands in series, one after the other.

◆ StartEnd() [1/2]

CommandPtr frc2::cmd::StartEnd ( std::function< void()>  start,
std::function< void()>  end,
std::initializer_list< Subsystem * >  requirements 
)

Constructs a command that runs an action once and another action when the command is interrupted.

Parameters
startthe action to run on start
endthe action to run on interrupt
requirementssubsystems the action requires

◆ StartEnd() [2/2]

CommandPtr frc2::cmd::StartEnd ( std::function< void()>  start,
std::function< void()>  end,
std::span< Subsystem *const >  requirements = {} 
)

Constructs a command that runs an action once and another action when the command is interrupted.

Parameters
startthe action to run on start
endthe action to run on interrupt
requirementssubsystems the action requires

◆ Wait()

CommandPtr frc2::cmd::Wait ( units::second_t  duration)

Constructs a command that does nothing, finishing after a specified duration.

Parameters
durationafter how long the command finishes

◆ WaitUntil()

CommandPtr frc2::cmd::WaitUntil ( std::function< bool()>  condition)

Constructs a command that does nothing, finishing once a condition becomes true.

Parameters
conditionthe condition