WPILibC++ 2024.3.2
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< Command, PIDCommand >

Public Member Functions

 PIDCommand (frc::PIDController controller, std::function< double()> measurementSource, std::function< double()> setpointSource, std::function< void(double)> useOutput, Requirements requirements={})
 Creates a new PIDCommand, which controls the given output with a PIDController. More...
 
 PIDCommand (frc::PIDController controller, std::function< double()> measurementSource, double setpoint, std::function< void(double)> useOutput, Requirements 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
 
frc::PIDControllerGetController ()
 Returns the PIDController used by the command. More...
 
- Public Member Functions inherited from frc2::CommandHelper< Command, PIDCommand >
 CommandHelper ()=default
 
CommandPtr ToPtr () &&override
 

Protected Attributes

frc::PIDController m_controller
 PID controller. More...
 
std::function< double()> m_measurement
 Measurement getter. More...
 
std::function< double()> m_setpoint
 Setpoint getter. More...
 
std::function< void(double)> m_useOutput
 PID controller output consumer. More...
 

Additional Inherited Members

- Protected Member Functions inherited from frc2::CommandHelper< Command, 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/4]

frc2::PIDCommand::PIDCommand ( frc::PIDController  controller,
std::function< double()>  measurementSource,
std::function< double()>  setpointSource,
std::function< void(double)>  useOutput,
Requirements  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/4]

frc2::PIDCommand::PIDCommand ( frc::PIDController  controller,
std::function< double()>  measurementSource,
double  setpoint,
std::function< void(double)>  useOutput,
Requirements  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() [3/4]

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

◆ PIDCommand() [4/4]

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()

frc::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

frc::PIDController frc2::PIDCommand::m_controller
protected

PID controller.

◆ m_measurement

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

Measurement getter.

◆ m_setpoint

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

Setpoint getter.

◆ m_useOutput

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

PID controller output consumer.


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