WPILibC++ 2025.2.1
Loading...
Searching...
No Matches
PIDSubsystem.h
Go to the documentation of this file.
1// Copyright (c) FIRST and other WPILib contributors.
2// Open Source Software; you can modify and/or share it under the terms of
3// the WPILib BSD license file in the root directory of this project.
4
5#pragma once
6
8
10
11namespace frc2 {
12/**
13 * A subsystem that uses a PIDController to control an output. The controller
14 * is run synchronously from the subsystem's periodic() method.
15 *
16 * This class is provided by the NewCommands VendorDep
17 *
18 * @see PIDController
19 * @deprecated Use a PIDController instead
20 */
21class [[deprecated("Use a PIDController instead")]] PIDSubsystem
22 : public SubsystemBase {
23 public:
24 /**
25 * Creates a new PIDSubsystem.
26 *
27 * @param controller the PIDController to use
28 * @param initialPosition the initial setpoint of the subsystem
29 */
30 explicit PIDSubsystem(frc::PIDController controller,
31 double initialPosition = 0);
32
33 void Periodic() override;
34
35 /**
36 * Sets the setpoint for the subsystem.
37 *
38 * @param setpoint the setpoint for the subsystem
39 */
40 void SetSetpoint(double setpoint);
41
42 /**
43 * Gets the setpoint for the subsystem.
44 *
45 * @return the setpoint for the subsystem
46 */
47 double GetSetpoint() const;
48
49 /**
50 * Enables the PID control. Resets the controller.
51 */
52 virtual void Enable();
53
54 /**
55 * Disables the PID control. Sets output to zero.
56 */
57 virtual void Disable();
58
59 /**
60 * Returns whether the controller is enabled.
61 *
62 * @return Whether the controller is enabled.
63 */
64 bool IsEnabled();
65
66 /**
67 * Returns the PIDController.
68 *
69 * @return The controller.
70 */
72
73 protected:
74 /// PID controller.
76
77 /// Whether PID controller output is enabled.
78 bool m_enabled{false};
79
80 /**
81 * Returns the measurement of the process variable used by the PIDController.
82 *
83 * @return the measurement of the process variable
84 */
85 virtual double GetMeasurement() = 0;
86
87 /**
88 * Uses the output from the PIDController.
89 *
90 * @param output the output of the PIDController
91 * @param setpoint the setpoint of the PIDController (for feedforward)
92 */
93 virtual void UseOutput(double output, double setpoint) = 0;
94};
95} // namespace frc2
A subsystem that uses a PIDController to control an output.
Definition PIDSubsystem.h:22
bool IsEnabled()
Returns whether the controller is enabled.
virtual void Enable()
Enables the PID control.
virtual void UseOutput(double output, double setpoint)=0
Uses the output from the PIDController.
frc::PIDController & GetController()
Returns the PIDController.
double GetSetpoint() const
Gets the setpoint for the subsystem.
PIDSubsystem(frc::PIDController controller, double initialPosition=0)
Creates a new PIDSubsystem.
virtual void Disable()
Disables the PID control.
void Periodic() override
This method is called periodically by the CommandScheduler.
virtual double GetMeasurement()=0
Returns the measurement of the process variable used by the PIDController.
void SetSetpoint(double setpoint)
Sets the setpoint for the subsystem.
frc::PIDController m_controller
PID controller.
Definition PIDSubsystem.h:75
A base for subsystems that handles registration in the constructor, and provides a more intuitive met...
Definition SubsystemBase.h:24
Implements a PID control loop.
Definition PIDController.h:29
Definition FunctionalCommand.h:13