Brian Silverman | f7f267a | 2017-02-04 16:16:08 -0800 | [diff] [blame^] | 1 | /*----------------------------------------------------------------------------*/ |
| 2 | /* Copyright (c) FIRST 2011-2017. All Rights Reserved. */ |
| 3 | /* Open Source Software - may be modified and shared by FRC teams. The code */ |
| 4 | /* must be accompanied by the FIRST BSD license file in the root directory of */ |
| 5 | /* the project. */ |
| 6 | /*----------------------------------------------------------------------------*/ |
| 7 | |
| 8 | #include "Commands/PIDCommand.h" |
| 9 | |
| 10 | #include <cfloat> |
| 11 | |
| 12 | using namespace frc; |
| 13 | |
| 14 | PIDCommand::PIDCommand(const std::string& name, double p, double i, double d, |
| 15 | double f, double period) |
| 16 | : Command(name) { |
| 17 | m_controller = std::make_shared<PIDController>(p, i, d, this, this, period); |
| 18 | } |
| 19 | |
| 20 | PIDCommand::PIDCommand(double p, double i, double d, double f, double period) { |
| 21 | m_controller = |
| 22 | std::make_shared<PIDController>(p, i, d, f, this, this, period); |
| 23 | } |
| 24 | |
| 25 | PIDCommand::PIDCommand(const std::string& name, double p, double i, double d) |
| 26 | : Command(name) { |
| 27 | m_controller = std::make_shared<PIDController>(p, i, d, this, this); |
| 28 | } |
| 29 | |
| 30 | PIDCommand::PIDCommand(const std::string& name, double p, double i, double d, |
| 31 | double period) |
| 32 | : Command(name) { |
| 33 | m_controller = std::make_shared<PIDController>(p, i, d, this, this, period); |
| 34 | } |
| 35 | |
| 36 | PIDCommand::PIDCommand(double p, double i, double d) { |
| 37 | m_controller = std::make_shared<PIDController>(p, i, d, this, this); |
| 38 | } |
| 39 | |
| 40 | PIDCommand::PIDCommand(double p, double i, double d, double period) { |
| 41 | m_controller = std::make_shared<PIDController>(p, i, d, this, this, period); |
| 42 | } |
| 43 | |
| 44 | void PIDCommand::_Initialize() { m_controller->Enable(); } |
| 45 | |
| 46 | void PIDCommand::_End() { m_controller->Disable(); } |
| 47 | |
| 48 | void PIDCommand::_Interrupted() { _End(); } |
| 49 | |
| 50 | void PIDCommand::SetSetpointRelative(double deltaSetpoint) { |
| 51 | SetSetpoint(GetSetpoint() + deltaSetpoint); |
| 52 | } |
| 53 | |
| 54 | void PIDCommand::PIDWrite(double output) { UsePIDOutput(output); } |
| 55 | |
| 56 | double PIDCommand::PIDGet() { return ReturnPIDInput(); } |
| 57 | |
| 58 | std::shared_ptr<PIDController> PIDCommand::GetPIDController() const { |
| 59 | return m_controller; |
| 60 | } |
| 61 | |
| 62 | void PIDCommand::SetSetpoint(double setpoint) { |
| 63 | m_controller->SetSetpoint(setpoint); |
| 64 | } |
| 65 | |
| 66 | double PIDCommand::GetSetpoint() const { return m_controller->GetSetpoint(); } |
| 67 | |
| 68 | double PIDCommand::GetPosition() { return ReturnPIDInput(); } |
| 69 | |
| 70 | std::string PIDCommand::GetSmartDashboardType() const { return "PIDCommand"; } |
| 71 | |
| 72 | void PIDCommand::InitTable(std::shared_ptr<ITable> subtable) { |
| 73 | m_controller->InitTable(subtable); |
| 74 | Command::InitTable(subtable); |
| 75 | } |