Brian Silverman | f7f267a | 2017-02-04 16:16:08 -0800 | [diff] [blame^] | 1 | /*----------------------------------------------------------------------------*/ |
| 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 | #pragma once |
| 9 | |
| 10 | #include <memory> |
| 11 | #include <string> |
| 12 | |
| 13 | #include "Commands/Subsystem.h" |
| 14 | #include "PIDController.h" |
| 15 | #include "PIDOutput.h" |
| 16 | #include "PIDSource.h" |
| 17 | |
| 18 | namespace frc { |
| 19 | |
| 20 | /** |
| 21 | * This class is designed to handle the case where there is a {@link Subsystem} |
| 22 | * which uses a single {@link PIDController} almost constantly (for instance, |
| 23 | * an elevator which attempts to stay at a constant height). |
| 24 | * |
| 25 | * <p>It provides some convenience methods to run an internal {@link |
| 26 | * PIDController}. It also allows access to the internal {@link PIDController} |
| 27 | * in order to give total control to the programmer.</p> |
| 28 | * |
| 29 | */ |
| 30 | class PIDSubsystem : public Subsystem, public PIDOutput, public PIDSource { |
| 31 | public: |
| 32 | PIDSubsystem(const std::string& name, double p, double i, double d); |
| 33 | PIDSubsystem(const std::string& name, double p, double i, double d, double f); |
| 34 | PIDSubsystem(const std::string& name, double p, double i, double d, double f, |
| 35 | double period); |
| 36 | PIDSubsystem(double p, double i, double d); |
| 37 | PIDSubsystem(double p, double i, double d, double f); |
| 38 | PIDSubsystem(double p, double i, double d, double f, double period); |
| 39 | virtual ~PIDSubsystem() = default; |
| 40 | |
| 41 | void Enable(); |
| 42 | void Disable(); |
| 43 | |
| 44 | // PIDOutput interface |
| 45 | virtual void PIDWrite(double output); |
| 46 | |
| 47 | // PIDSource interface |
| 48 | virtual double PIDGet(); |
| 49 | void SetSetpoint(double setpoint); |
| 50 | void SetSetpointRelative(double deltaSetpoint); |
| 51 | void SetInputRange(double minimumInput, double maximumInput); |
| 52 | void SetOutputRange(double minimumOutput, double maximumOutput); |
| 53 | double GetSetpoint(); |
| 54 | double GetPosition(); |
| 55 | double GetRate(); |
| 56 | |
| 57 | virtual void SetAbsoluteTolerance(double absValue); |
| 58 | virtual void SetPercentTolerance(double percent); |
| 59 | virtual bool OnTarget() const; |
| 60 | |
| 61 | protected: |
| 62 | std::shared_ptr<PIDController> GetPIDController(); |
| 63 | |
| 64 | virtual double ReturnPIDInput() = 0; |
| 65 | virtual void UsePIDOutput(double output) = 0; |
| 66 | |
| 67 | private: |
| 68 | /** The internal {@link PIDController} */ |
| 69 | std::shared_ptr<PIDController> m_controller; |
| 70 | |
| 71 | public: |
| 72 | void InitTable(std::shared_ptr<ITable> subtable) override; |
| 73 | std::string GetSmartDashboardType() const override; |
| 74 | }; |
| 75 | |
| 76 | } // namespace frc |