-
Notifications
You must be signed in to change notification settings - Fork 0
/
PIDController.java
31 lines (25 loc) · 1007 Bytes
/
PIDController.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
public class MyPIDController
{
private PIDSource source;
private PIDOutput output;
public PIDController(PIDSource source, PIDOutput output)
{
this.source = source;
this.output = output;
}
// This method could be called from another class or performed in
// a loop in a thread. It's job is to read the source value from
// the source object (for example an encoder's current counts) and
// calculate an output value and write that output value to the
// output object (for example a motor to change the motor's power).
// The key is that this code does not care what the source and
// output objects actually are, it just reads, calculates and writes.
public void calculate()
{
double sourceValue;
double outputValue;
sourceValue = source.pidGet();
outputValue = some calculation or process using sourceValue;
output.pidWrite(outputValue);
}
}