libnxter  0.1
Data Structures | Functions
PID.nxc File Reference

Generic PID controller implementation. More...

This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  PIDControl
 PID controller class. More...


void PIDControlInit (PIDControl &pidControl, long PIDScale, long PValue, long IValue, long DValue, int steadyStateCountThreshold, long outputGain, long absMaxOutput)
 Initializes a PID controller with the given P, I and D values, output parameters. More...
void PIDControlSetIntegralLimit (PIDControl &pidControl, long absIntegralLimit)
 Sets integral output absolute maximum used to prevent integral windup. The default is set to absMaxOutput.
void PIDControlSetPoint (PIDControl &pidControl, long setPoint)
 Sets a new set point for the controller. The controller state is reset and the new target is pursued.
bool PIDControlCheckEnd (PIDControl &pidControl)
 Checks if the PID controller has ended. More...
long PIDControlGetLastError (PIDControl &pidControl)
 Gets the error from the last step.
long PIDControlStep (PIDControl &pidControl, long currentPoint)
 Steps the PID controller. currentPoint is the current state of the system. The return value is the output of the controller that should be applied to the input of the system (e.g. motor). Call this method in regular (sampling) period.

Detailed Description

Generic PID controller implementation.

Definition in file PID.nxc.

Function Documentation

bool PIDControlCheckEnd ( PIDControl pidControl)

Checks if the PID controller has ended.

PID controller ends if it has settled at set point for steadyStateCountThreshold steps, or it is not changing that steadyStateCountThreshold many steps (usually because of system overload and therefore ending is good). When the controller is ended it only outputs 0. If the controller is running in continous mode, i.e. steadyStateCountThreshold = 0, this method always return false.

Definition at line 120 of file PID.nxc.

References PIDControl::steadyStateCountThreshold.

Referenced by MotorRotateAngle(), MotorRotateAngleDiff(), MotorRotateAngleSync(), PIDControlStep(), and SonarSweep().

void PIDControlInit ( PIDControl pidControl,
long  PIDScale,
long  PValue,
long  IValue,
long  DValue,
int  steadyStateCountThreshold,
long  outputGain,
long  absMaxOutput 

Initializes a PID controller with the given P, I and D values, output parameters.

The P, I and D parameters are normally fractions and to accomodate them in integer form, they should be scaled by a number. The scale value is given as PIDScale (1000 is a good choice). If error does not change for 'steadyStateCountThreshold' many steps, the control is ended. It could be either because the system state has settled (error stays at 0) or it is stuck, in which case it is usually good to end to avoid overloading. If steadyStateCountThreshold is given as '0', the PID controller runs in continous mode and the control never ends. When running PIDController in continous mode, keep setting new set points with PIDControlSetPoint() as needed. outputGain is the multiplying factor to current PID output to get actual output. The output is clipped, both positive side and negative side, at the absolute value absMaxOutput.

Definition at line 71 of file PID.nxc.

References PIDControl::absIntegralLimit, PIDControl::absMaxOutput, PIDControl::DValue, PIDControl::integral, PIDControl::IValue, PIDControl::lastError, PIDControl::outputGain, PIDControl::PIDScale, PIDControl::PValue, PIDControl::setPoint, and PIDControl::steadyStateCountThreshold.

Referenced by MotorRotateAngle(), MotorRotateAngleDiff(), MotorRotateAngleSync(), and SonarInit().