blob: c6ac919669f91a48cbae3f62bb521b030f002c33 [file] [log] [blame]
Brian Silverman26e4e522015-12-17 01:56:40 -05001/*----------------------------------------------------------------------------*/
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
12PIDCommand::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
18PIDCommand::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
22PIDCommand::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
27PIDCommand::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
33PIDCommand::PIDCommand(double p, double i, double d) {
34 m_controller = std::make_shared<PIDController>(p, i, d, this, this);
35}
36
37PIDCommand::PIDCommand(double p, double i, double d, double period) {
38 m_controller = std::make_shared<PIDController>(p, i, d, this, this, period);
39}
40
41void PIDCommand::_Initialize() { m_controller->Enable(); }
42
43void PIDCommand::_End() { m_controller->Disable(); }
44
45void PIDCommand::_Interrupted() { _End(); }
46
47void PIDCommand::SetSetpointRelative(double deltaSetpoint) {
48 SetSetpoint(GetSetpoint() + deltaSetpoint);
49}
50
51void PIDCommand::PIDWrite(float output) { UsePIDOutput(output); }
52
53double PIDCommand::PIDGet() { return ReturnPIDInput(); }
54
55std::shared_ptr<PIDController> PIDCommand::GetPIDController() const {
56 return m_controller;
57}
58
59void PIDCommand::SetSetpoint(double setpoint) {
60 m_controller->SetSetpoint(setpoint);
61}
62
63double PIDCommand::GetSetpoint() const { return m_controller->GetSetpoint(); }
64
65double PIDCommand::GetPosition() { return ReturnPIDInput(); }
66
67std::string PIDCommand::GetSmartDashboardType() const { return "PIDCommand"; }
68void PIDCommand::InitTable(std::shared_ptr<ITable> table) {
69 m_controller->InitTable(table);
70 Command::InitTable(table);
71}