TinyRobotics
Loading...
Searching...
No Matches
Classes | Public Member Functions | Protected Types | Protected Member Functions | Protected Attributes | List of all members
PIDAutoTuner Class Reference

Automatic PID tuning using the relay (Åström-Hägglund) method. More...

#include <PIDAutoTuner.h>

Classes

struct  Result
 

Public Member Functions

 PIDAutoTuner (float target, float relayAmp, float dt)
 
void reset ()
 
float update (float y)
 
bool isFinished () const
 
Result getResult () const
 
void setHysteresis (float h)
 

Protected Types

enum class  State { INIT , RUNNING }
 

Protected Member Functions

void detectPeaks (float y)
 
void registerPeak (bool isMax)
 

Protected Attributes

float target
 
float relayAmp
 
float dt
 
float hysteresis = 0.01f
 
float output = 0
 
float time = 0
 
float lastY = 0
 
float maxY = -1e9
 
float minY = 1e9
 
float avgMax = 0
 
float avgMin = 0
 
float avgPeriod = 0
 
float lastPeakTime = 0
 
int peakCount = 0
 
bool lastWasMax = false
 
bool success = false
 
State state = State::INIT
 

Detailed Description

Automatic PID tuning using the relay (Åström-Hägglund) method.

This class implements an automatic PID tuning algorithm based on the relay (bang-bang) method, also known as the Åström-Hägglund relay auto-tuning technique. It applies a relay (on/off) control to the system and analyzes the resulting oscillations to estimate the ultimate gain (Ku) and period (Tu). These values are then used to compute PID parameters using the Ziegler-Nichols tuning rules.

Usage Example:

PIDAutoTuner tuner(target, relayAmp, dt);
while (!tuner.isFinished()) {
float control = tuner.update(measuredValue);
// Apply 'control' to actuator
}
auto result = tuner.getResult();
if (result.success) {
// Use result.Kp, result.Ki, result.Kd
}
Automatic PID tuning using the relay (Åström-Hägglund) method.
Definition: PIDAutoTuner.h:46
See also
setHysteresis, getResult, isFinished, update, reset
Author
Phil Schatzmann

The documentation for this class was generated from the following file: