blob: 44d96a65ce86fe1dcf336af157a06122226e6b34 [file] [log] [blame]
Brian Silvermanf7f267a2017-02-04 16:16:08 -08001/*----------------------------------------------------------------------------*/
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
12using namespace frc;
13
14PIDCommand::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
20PIDCommand::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
25PIDCommand::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
30PIDCommand::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
36PIDCommand::PIDCommand(double p, double i, double d) {
37 m_controller = std::make_shared<PIDController>(p, i, d, this, this);
38}
39
40PIDCommand::PIDCommand(double p, double i, double d, double period) {
41 m_controller = std::make_shared<PIDController>(p, i, d, this, this, period);
42}
43
44void PIDCommand::_Initialize() { m_controller->Enable(); }
45
46void PIDCommand::_End() { m_controller->Disable(); }
47
48void PIDCommand::_Interrupted() { _End(); }
49
50void PIDCommand::SetSetpointRelative(double deltaSetpoint) {
51 SetSetpoint(GetSetpoint() + deltaSetpoint);
52}
53
54void PIDCommand::PIDWrite(double output) { UsePIDOutput(output); }
55
56double PIDCommand::PIDGet() { return ReturnPIDInput(); }
57
58std::shared_ptr<PIDController> PIDCommand::GetPIDController() const {
59 return m_controller;
60}
61
62void PIDCommand::SetSetpoint(double setpoint) {
63 m_controller->SetSetpoint(setpoint);
64}
65
66double PIDCommand::GetSetpoint() const { return m_controller->GetSetpoint(); }
67
68double PIDCommand::GetPosition() { return ReturnPIDInput(); }
69
70std::string PIDCommand::GetSmartDashboardType() const { return "PIDCommand"; }
71
72void PIDCommand::InitTable(std::shared_ptr<ITable> subtable) {
73 m_controller->InitTable(subtable);
74 Command::InitTable(subtable);
75}