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