2019-08-25 23:55:59 -04:00
|
|
|
/*----------------------------------------------------------------------------*/
|
2020-06-20 16:30:21 -07:00
|
|
|
/* Copyright (c) 2019-2020 FIRST. All Rights Reserved. */
|
2019-08-25 23:55:59 -04:00
|
|
|
/* Open Source Software - may be modified and shared by FRC teams. The code */
|
|
|
|
|
/* must be accompanied by the FIRST BSD license file in the root directory of */
|
|
|
|
|
/* the project. */
|
|
|
|
|
/*----------------------------------------------------------------------------*/
|
|
|
|
|
|
|
|
|
|
#include "frc2/command/PIDSubsystem.h"
|
|
|
|
|
|
|
|
|
|
using namespace frc2;
|
|
|
|
|
|
2019-12-23 02:09:25 -05:00
|
|
|
PIDSubsystem::PIDSubsystem(PIDController controller, double initialPosition)
|
|
|
|
|
: m_controller{controller} {
|
|
|
|
|
SetSetpoint(initialPosition);
|
2020-10-19 20:04:18 -07:00
|
|
|
AddChild("PID Controller", &m_controller);
|
2019-12-23 02:09:25 -05:00
|
|
|
}
|
2019-08-25 23:55:59 -04:00
|
|
|
|
|
|
|
|
void PIDSubsystem::Periodic() {
|
|
|
|
|
if (m_enabled) {
|
2019-11-26 00:46:47 -05:00
|
|
|
UseOutput(m_controller.Calculate(GetMeasurement(), m_setpoint), m_setpoint);
|
2019-08-25 23:55:59 -04:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-11-26 00:46:47 -05:00
|
|
|
void PIDSubsystem::SetSetpoint(double setpoint) { m_setpoint = setpoint; }
|
|
|
|
|
|
2020-06-20 16:30:21 -07:00
|
|
|
double PIDSubsystem::GetSetpoint() const { return m_setpoint; }
|
|
|
|
|
|
2019-08-25 23:55:59 -04:00
|
|
|
void PIDSubsystem::Enable() {
|
|
|
|
|
m_controller.Reset();
|
|
|
|
|
m_enabled = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void PIDSubsystem::Disable() {
|
2019-11-26 00:46:47 -05:00
|
|
|
UseOutput(0, 0);
|
2019-08-25 23:55:59 -04:00
|
|
|
m_enabled = false;
|
|
|
|
|
}
|
|
|
|
|
|
2019-11-26 00:46:47 -05:00
|
|
|
bool PIDSubsystem::IsEnabled() { return m_enabled; }
|
|
|
|
|
|
2019-08-25 23:55:59 -04:00
|
|
|
PIDController& PIDSubsystem::GetController() { return m_controller; }
|