|
ADBLib
0.5
A simple library for rapid robot code development
|
#include <SimplePID.h>
Public Member Functions | |
| SimplePID (double p, double i, double d, bool continuous, double period=0.05) | |
| ~SimplePID () | |
| double | getOutput () |
| void | setInputRange (double minimumInput, double maximumInput) |
| void | setOutputRange (double mimimumOutput, double maximumOutput) |
| void | setPID (double p, double i, double d) |
| void | setMV (double mv) |
| void | setSetpoint (double setpoint) |
| double | setSetpoint () |
| double | setError () |
| void | setTolerance (double percent) |
| bool | onTarget () |
| void | enable () |
| void | disable () |
| void | reset () |
Protected Member Functions | |
| void | calculate () |
Static Protected Member Functions | |
| static void | callCalculate (void *controller) |
Protected Attributes | |
| double | m_P |
| double | m_I |
| double | m_D |
| double | m_maximumOutput |
| double | m_minimumOutput |
| double | m_maximumInput |
| double | m_minimumInput |
| bool | m_continuous |
| bool | m_enabled |
| double | m_prevError |
| double | m_totalError |
| double | m_tolerance |
| double | m_setpoint |
| double | m_error |
| double | m_result |
| double | m_period |
| double | m_measuredValue |
| Notifier * | m_controlLoop |
Class for doing PID calculations without slaving an output into a PIDController object. Class originally by Parker Stebbins, adapted for use in ADBLib in 2016.
To use this class, first give it your PID values, select whether input is continuous, and select a control period (default is 50 ms). To provide sensor input, call setMV() and provide your sensor input. To set a setpoint, use setSetpoint(). To get the calculated value that your output should be set to, call getOutput().
| ADBLib::SimplePID::SimplePID | ( | double | Kp, |
| double | Ki, | ||
| double | Kd, | ||
| bool | continuous, | ||
| double | period = 0.05 |
||
| ) |
Create a PID object with the given constants for P, I, D. Default values for min/max IO are -1 and 1 respectively, continuous input is disabled, tolerance is set to 5%, and the SimplePID starts as disabled (zero output).
| Kp | The proportional coefficient |
| Ki | The integral coefficient |
| Kd | The derivative coefficient |
| period | The loop time for doing calculations in seconds. This particularly affects calculations of the integral and differential terms. The default is 50 ms. |

| ADBLib::SimplePID::~SimplePID | ( | ) |
Destroys this object.
|
protected |
Internal function. Performs necessary PID calculations.

|
staticprotected |
Internal function. Calls the calculate function... for some reason.
| controller | A pointer to a SimplePID object. |


| void ADBLib::SimplePID::disable | ( | ) |
Disables the SimplePID, zeroing output from getOutput().

| void ADBLib::SimplePID::enable | ( | ) |
Enables the SimplePID, starting output from getOutput().
| double ADBLib::SimplePID::getOutput | ( | ) |
Gets the output as calculated using input and setpoint.
| bool ADBLib::SimplePID::onTarget | ( | ) |
Returns the status of whether this PID controller is on target or not to within tolerance set by the SetTolerance function. Tolerance is set at 5% by default. Calculation is done by getting the absolute value of error and checking whether it's less than the tolerance times the input range.
| void ADBLib::SimplePID::reset | ( | ) |
Resets the SimplePID, disabling it and resetting all error and calculated output.

| double ADBLib::SimplePID::setError | ( | ) |
| void ADBLib::SimplePID::setInputRange | ( | double | minimumInput, |
| double | maximumInput | ||
| ) |
Sets the input range this object expects. For example. a gyro could output from -180 to 180, so you would call this function with Set
| minimumInput | The minimum input expected. Can be negative. |
| maximumInput | The maximum input expected. |

| void ADBLib::SimplePID::setMV | ( | double | mv | ) |
Sets the measured value, presumably from sensors.
| mv | The measured value as a double. |
| void ADBLib::SimplePID::setOutputRange | ( | double | minimumOutput, |
| double | maximumOutput | ||
| ) |
Sets the output range delivered. For example, if you have a drivebase expecting values between -512 and 512, call this function with -512 and 512, respectively.
| minimumOutput | The minimum output delivered. Can be negative. |
| maximumOutput | The maximum output delivered. |
| void ADBLib::SimplePID::setPID | ( | double | p, |
| double | i, | ||
| double | d | ||
| ) |
Sets PID constants.
| p | The proportional constant. Multiplied by the error. |
| i | The integral constant. Multiplied by the sum of error. |
| d | The derivative constant. Multiplied by the rate at which error is changing. |
| void ADBLib::SimplePID::setSetpoint | ( | double | setpoint | ) |
Sets the point that PID calculations will try to work towards. This value should be somewhere within the output range, which by default is from -1 to 1. This function can and should be used similarly to motor set functions.
| setpoint | The desired setpoint. |
| double ADBLib::SimplePID::setSetpoint | ( | ) |

| void ADBLib::SimplePID::setTolerance | ( | double | tolerance | ) |
Sets the tolerance to error.
| tolerance | Tolerance as a percent (eg. 0.02) |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |