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

A command that controls an output with a PIDController. More...

#include <frc2/command/PIDCommand.h>

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

Public Member Functions

 PIDCommand (PIDController controller, std::function< double()> measurementSource, std::function< double()> setpointSource, std::function< void(double)> useOutput, std::initializer_list< Subsystem * > requirements)
 Creates a new PIDCommand, which controls the given output with a PIDController. More...
 
 PIDCommand (PIDController controller, std::function< double()> measurementSource, std::function< double()> setpointSource, std::function< void(double)> useOutput, std::span< Subsystem *const > requirements={})
 Creates a new PIDCommand, which controls the given output with a PIDController. More...
 
 PIDCommand (PIDController controller, std::function< double()> measurementSource, double setpoint, std::function< void(double)> useOutput, std::initializer_list< Subsystem * > requirements)
 Creates a new PIDCommand, which controls the given output with a PIDController with a constant setpoint. More...
 
 PIDCommand (PIDController controller, std::function< double()> measurementSource, double setpoint, std::function< void(double)> useOutput, std::span< Subsystem *const > requirements={})
 Creates a new PIDCommand, which controls the given output with a PIDController with a constant setpoint. More...
 
 PIDCommand (PIDCommand &&other)=default
 
 PIDCommand (const PIDCommand &other)=default
 
void Initialize () override
 
void Execute () override
 
void End (bool interrupted) override
 
PIDControllerGetController ()
 Returns the PIDController used by the command. More...
 
- Public Member Functions inherited from frc2::CommandHelper< CommandBase, PIDCommand >
 CommandHelper ()=default
 
CommandPtr ToPtr () &&override
 

Protected Attributes

PIDController m_controller
 
std::function< double()> m_measurement
 
std::function< double()> m_setpoint
 
std::function< void(double)> m_useOutput
 

Additional Inherited Members

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

Detailed Description

A command that controls an output with a PIDController.

Runs forever by default - to add exit conditions and/or other behavior, subclass this class. The controller calculation and output are performed synchronously in the command's execute() method.

This class is provided by the NewCommands VendorDep

See also
PIDController

Constructor & Destructor Documentation

◆ PIDCommand() [1/6]

frc2::PIDCommand::PIDCommand ( PIDController  controller,
std::function< double()>  measurementSource,
std::function< double()>  setpointSource,
std::function< void(double)>  useOutput,
std::initializer_list< Subsystem * >  requirements 
)

Creates a new PIDCommand, which controls the given output with a PIDController.

Parameters
controllerthe controller that controls the output.
measurementSourcethe measurement of the process variable
setpointSourcethe controller's reference (aka setpoint)
useOutputthe controller's output
requirementsthe subsystems required by this command

◆ PIDCommand() [2/6]

frc2::PIDCommand::PIDCommand ( PIDController  controller,
std::function< double()>  measurementSource,
std::function< double()>  setpointSource,
std::function< void(double)>  useOutput,
std::span< Subsystem *const >  requirements = {} 
)

Creates a new PIDCommand, which controls the given output with a PIDController.

Parameters
controllerthe controller that controls the output.
measurementSourcethe measurement of the process variable
setpointSourcethe controller's reference (aka setpoint)
useOutputthe controller's output
requirementsthe subsystems required by this command

◆ PIDCommand() [3/6]

frc2::PIDCommand::PIDCommand ( PIDController  controller,
std::function< double()>  measurementSource,
double  setpoint,
std::function< void(double)>  useOutput,
std::initializer_list< Subsystem * >  requirements 
)

Creates a new PIDCommand, which controls the given output with a PIDController with a constant setpoint.

Parameters
controllerthe controller that controls the output.
measurementSourcethe measurement of the process variable
setpointthe controller's setpoint (aka setpoint)
useOutputthe controller's output
requirementsthe subsystems required by this command

◆ PIDCommand() [4/6]

frc2::PIDCommand::PIDCommand ( PIDController  controller,
std::function< double()>  measurementSource,
double  setpoint,
std::function< void(double)>  useOutput,
std::span< Subsystem *const >  requirements = {} 
)

Creates a new PIDCommand, which controls the given output with a PIDController with a constant setpoint.

Parameters
controllerthe controller that controls the output.
measurementSourcethe measurement of the process variable
setpointthe controller's setpoint (aka setpoint)
useOutputthe controller's output
requirementsthe subsystems required by this command

◆ PIDCommand() [5/6]

frc2::PIDCommand::PIDCommand ( PIDCommand &&  other)
default

◆ PIDCommand() [6/6]

frc2::PIDCommand::PIDCommand ( const PIDCommand other)
default

Member Function Documentation

◆ End()

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

◆ Execute()

void frc2::PIDCommand::Execute ( )
override

◆ GetController()

PIDController & frc2::PIDCommand::GetController ( )

Returns the PIDController used by the command.

Returns
The PIDController

◆ Initialize()

void frc2::PIDCommand::Initialize ( )
override

Member Data Documentation

◆ m_controller

PIDController frc2::PIDCommand::m_controller
protected

◆ m_measurement

std::function<double()> frc2::PIDCommand::m_measurement
protected

◆ m_setpoint

std::function<double()> frc2::PIDCommand::m_setpoint
protected

◆ m_useOutput

std::function<void(double)> frc2::PIDCommand::m_useOutput
protected

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