blob: 4287e4cf239ec337743e71acb2963ced595ea893 [file] [log] [blame]
jerrymf1579332013-02-07 01:56:28 +00001/*----------------------------------------------------------------------------*/
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
12PIDCommand::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
18PIDCommand::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
23PIDCommand::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
29PIDCommand::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
35PIDCommand::PIDCommand(double p, double i, double d)
36{
37 m_controller = new PIDController(p, i, d, this, this);
38}
39
40PIDCommand::PIDCommand(double p, double i, double d, double period)
41{
42 m_controller = new PIDController(p, i, d, this, this, period);
43}
44
45PIDCommand::~PIDCommand()
46{
47 delete m_controller;
48}
49
50void PIDCommand::_Initialize()
51{
52 m_controller->Enable();
53}
54
55void PIDCommand::_End()
56{
57 m_controller->Disable();
58}
59
60void PIDCommand::_Interrupted()
61{
62 _End();
63}
64
65void PIDCommand::SetSetpointRelative(double deltaSetpoint)
66{
67 SetSetpoint(GetSetpoint() + deltaSetpoint);
68}
69
70void PIDCommand::PIDWrite(float output)
71{
72 UsePIDOutput(output);
73}
74
75double PIDCommand::PIDGet()
76{
77 return ReturnPIDInput();
78}
79
80PIDController *PIDCommand::GetPIDController()
81{
82 return m_controller;
83}
84
85void PIDCommand::SetSetpoint(double setpoint)
86{
87 m_controller->SetSetpoint(setpoint);
88}
89
90double PIDCommand::GetSetpoint()
91{
92 return m_controller->GetSetpoint();
93}
94
95double PIDCommand::GetPosition()
96{
97 return ReturnPIDInput();
98}
99
100std::string PIDCommand::GetSmartDashboardType(){
101 return "PIDCommand";
102}
103void PIDCommand::InitTable(ITable* table){
104 m_controller->InitTable(table);
105 Command::InitTable(table);
106}