jerrym | f157933 | 2013-02-07 01:56:28 +0000 | [diff] [blame^] | 1 | /*----------------------------------------------------------------------------*/
|
| 2 | /* Copyright (c) FIRST 2011. 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 $(WIND_BASE)/WPILib. */
|
| 5 | /*----------------------------------------------------------------------------*/
|
| 6 |
|
| 7 | #include "Commands/PIDCommand.h"
|
| 8 |
|
| 9 | #include "PIDController.h"
|
| 10 | #include "float.h"
|
| 11 |
|
| 12 | PIDCommand::PIDCommand(const char *name, double p, double i, double d, double f, double period) :
|
| 13 | Command(name)
|
| 14 | {
|
| 15 | m_controller = new PIDController(p, i, d, this, this, period);
|
| 16 | }
|
| 17 |
|
| 18 | PIDCommand::PIDCommand(double p, double i, double d, double f, double period)
|
| 19 | {
|
| 20 | m_controller = new PIDController(p, i, d, f, this, this, period);
|
| 21 | }
|
| 22 |
|
| 23 | PIDCommand::PIDCommand(const char *name, double p, double i, double d) :
|
| 24 | Command(name)
|
| 25 | {
|
| 26 | m_controller = new PIDController(p, i, d, this, this);
|
| 27 | }
|
| 28 |
|
| 29 | PIDCommand::PIDCommand(const char *name, double p, double i, double d, double period) :
|
| 30 | Command(name)
|
| 31 | {
|
| 32 | m_controller = new PIDController(p, i, d, this, this, period);
|
| 33 | }
|
| 34 |
|
| 35 | PIDCommand::PIDCommand(double p, double i, double d)
|
| 36 | {
|
| 37 | m_controller = new PIDController(p, i, d, this, this);
|
| 38 | }
|
| 39 |
|
| 40 | PIDCommand::PIDCommand(double p, double i, double d, double period)
|
| 41 | {
|
| 42 | m_controller = new PIDController(p, i, d, this, this, period);
|
| 43 | }
|
| 44 |
|
| 45 | PIDCommand::~PIDCommand()
|
| 46 | {
|
| 47 | delete m_controller;
|
| 48 | }
|
| 49 |
|
| 50 | void PIDCommand::_Initialize()
|
| 51 | {
|
| 52 | m_controller->Enable();
|
| 53 | }
|
| 54 |
|
| 55 | void PIDCommand::_End()
|
| 56 | {
|
| 57 | m_controller->Disable();
|
| 58 | }
|
| 59 |
|
| 60 | void PIDCommand::_Interrupted()
|
| 61 | {
|
| 62 | _End();
|
| 63 | }
|
| 64 |
|
| 65 | void PIDCommand::SetSetpointRelative(double deltaSetpoint)
|
| 66 | {
|
| 67 | SetSetpoint(GetSetpoint() + deltaSetpoint);
|
| 68 | }
|
| 69 |
|
| 70 | void PIDCommand::PIDWrite(float output)
|
| 71 | {
|
| 72 | UsePIDOutput(output);
|
| 73 | }
|
| 74 |
|
| 75 | double PIDCommand::PIDGet()
|
| 76 | {
|
| 77 | return ReturnPIDInput();
|
| 78 | }
|
| 79 |
|
| 80 | PIDController *PIDCommand::GetPIDController()
|
| 81 | {
|
| 82 | return m_controller;
|
| 83 | }
|
| 84 |
|
| 85 | void PIDCommand::SetSetpoint(double setpoint)
|
| 86 | {
|
| 87 | m_controller->SetSetpoint(setpoint);
|
| 88 | }
|
| 89 |
|
| 90 | double PIDCommand::GetSetpoint()
|
| 91 | {
|
| 92 | return m_controller->GetSetpoint();
|
| 93 | }
|
| 94 |
|
| 95 | double PIDCommand::GetPosition()
|
| 96 | {
|
| 97 | return ReturnPIDInput();
|
| 98 | }
|
| 99 |
|
| 100 | std::string PIDCommand::GetSmartDashboardType(){
|
| 101 | return "PIDCommand";
|
| 102 | }
|
| 103 | void PIDCommand::InitTable(ITable* table){
|
| 104 | m_controller->InitTable(table);
|
| 105 | Command::InitTable(table);
|
| 106 | }
|