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