Now you can download a copy of these docs so you can use them offline! Download now
PIDSubsystem.cpp
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 #include "Commands/PIDSubsystem.h"
8 #include "PIDController.h"
9 #include "float.h"
10 
11 // XXX max and min are not used?
12 
20 PIDSubsystem::PIDSubsystem(const char *name, double p, double i, double d) :
21  Subsystem(name)
22 {
23  m_controller = new PIDController(p, i, d, this, this);
24 }
25 
34 PIDSubsystem::PIDSubsystem(const char *name, double p, double i, double d, double f) :
35  Subsystem(name)
36 {
37  m_controller = new PIDController(p, i, d, f, this, this);
38 }
39 
50 PIDSubsystem::PIDSubsystem(const char *name, double p, double i, double d, double f,
51  double period) :
52  Subsystem(name)
53 {
54  m_controller = new PIDController(p, i, d, f, this, this, period);
55 }
56 
64 PIDSubsystem::PIDSubsystem(double p, double i, double d) :
65  Subsystem("PIDSubsystem")
66 {
67  m_controller = new PIDController(p, i, d, this, this);
68 }
69 
78 PIDSubsystem::PIDSubsystem(double p, double i, double d, double f) :
79  Subsystem("PIDSubsystem")
80 {
81  m_controller = new PIDController(p, i, d, f, this, this);
82 }
83 
95 PIDSubsystem::PIDSubsystem(double p, double i, double d, double f, double period) :
96  Subsystem("PIDSubsystem")
97 {
98  m_controller = new PIDController(p, i, d, f, this, this, period);
99 }
100 
101 PIDSubsystem::~PIDSubsystem()
102 {
103  delete m_controller;
104 }
105 
110 {
111  m_controller->Enable();
112 }
113 
118 {
119  m_controller->Disable();
120 }
121 
122 
130 {
131  return m_controller;
132 }
133 
141 void PIDSubsystem::SetSetpoint(double setpoint)
142 {
143  m_controller->SetSetpoint(setpoint);
144 }
145 
152 void PIDSubsystem::SetSetpointRelative(double deltaSetpoint)
153 {
154  SetSetpoint(GetSetpoint() + deltaSetpoint);
155 }
156 
162 {
163  return m_controller->GetSetpoint();
164 }
165 
172 void PIDSubsystem::SetInputRange(float minimumInput, float maximumInput)
173 {
174  m_controller->SetInputRange(minimumInput, maximumInput);
175 }
176 
177 /*
178  * Set the absolute error which is considered tolerable for use with
179  * OnTarget.
180  * @param percentage error which is tolerable
181  */
182 void PIDSubsystem::SetAbsoluteTolerance(float absValue) {
183  m_controller->SetAbsoluteTolerance(absValue);
184 }
185 
186 /*
187  * Set the percentage error which is considered tolerable for use with
188  * OnTarget.
189  * @param percentage error which is tolerable
190  */
191 void PIDSubsystem::SetPercentTolerance(float percent) {
192  m_controller->SetPercentTolerance(percent);
193 }
194 
195 /*
196  * Return true if the error is within the percentage of the total input range,
197  * determined by SetTolerance. This asssumes that the maximum and minimum input
198  * were set using SetInput. Use OnTarget() in the IsFinished() method of commands
199  * that use this subsystem.
200  *
201  * Currently this just reports on target as the actual value passes through the setpoint.
202  * Ideally it should be based on being within the tolerance for some period of time.
203  *
204  * @return true if the error is within the percentage tolerance of the input range
205  */
206 bool PIDSubsystem::OnTarget()
207 {
208  return m_controller->OnTarget();
209 }
210 
216 {
217  return ReturnPIDInput();
218 }
219 
220 void PIDSubsystem::PIDWrite(float output)
221 {
222  UsePIDOutput(output);
223 }
224 
225 double PIDSubsystem::PIDGet()
226 {
227  return ReturnPIDInput();
228 }
229 
230 
232  return "PIDCommand";
233 }
235  m_controller->InitTable(table);
236  Subsystem::InitTable(table);
237 }
virtual void SetSetpoint(float setpoint)
void SetInputRange(float minimumInput, float maximumInput)
Definition: ITable.h:26
void SetSetpoint(double setpoint)
double GetPosition()
PIDController * GetPIDController()
virtual void Enable()
virtual void InitTable(ITable *table)
PIDSubsystem(const char *name, double p, double i, double d)
virtual float GetSetpoint()
void SetSetpointRelative(double deltaSetpoint)
virtual void InitTable(ITable *table)
Definition: Subsystem.cpp:158
virtual std::string GetSmartDashboardType()
virtual void Disable()
virtual void SetInputRange(float minimumInput, float maximumInput)
double GetSetpoint()
virtual void InitTable(ITable *table)

Generated on Sat Apr 26 2014 12:26:45 for WPILibC++ by doxygen 1.8.6