rims-arduino-library  v3.1.1
Recirculation infusion mash system library for Arduino
Public Member Functions | Protected Member Functions | List of all members
RimsTuner Class Reference

Toolkit to automatically tune PID without a process model. More...

#include <RimsTuner.h>

Inheritance diagram for RimsTuner:
Rims

Public Member Functions

 RimsTuner (UIRims *uiRims, byte analogPinTherm, byte ssrPin, double *currentTemp, double *ssrControl, double *settedTemp)
 Consructor. More...
 
void setFlowSensor (byte pinFlow, float flowFactor, float lowBound=-1, float upBound=100, float critalFlow=-1)
 Same as Rims::setFlowSensor. More...
 
- Public Member Functions inherited from Rims
 Rims (UIRims *uiRims, byte analogPinPV, byte ssrPin, double *currentTemp, double *ssrControl, double *settedTemp)
 Constructor. More...
 
void setTempProbe (byte probeType, float probeCoefs[], float res1)
 Set temperature probe (RTD, thermistor or custom) parameters. More...
 
void setPinLED (byte pinLED)
 Set pin for heater LED indicator. More...
 
void setFlowSensor (byte pinFlow, float flowFactor, float lowBound=DEFAULTFLOWLOWBOUND, float upBound=DEFAULTFLOWUPBOUND, float criticalFlow=DEFAULTFLOWLOWBOUND)
 Set pin for flow sensor and parameters. More...
 
void setHeaterPowerDetect (char pinHeaterVolt)
 Set pin to detect if there is voltage applied on heater. More...
 
void setTuningPID (float Kp, float Ki, float Kd, float tauFilter, int mashWaterQty=-1)
 Set tuning for PID object. More...
 
void setMemCSPin (byte csPin)
 Set pin for flash memory chip select. More...
 
void checkMemAccessMode ()
 Check if enterring in USB memory access mode. More...
 
void run ()
 Start and run Rims instance. More...
 
float getTempPV ()
 Get temperature from temperature probe (RTD, thermistor or custom). More...
 
float getFlow ()
 Get flow from hall-effect flow sensor. More...
 
bool getHeaterVoltage ()
 Check if heater is powered or not. More...
 
void stopHeating (bool state)
 Stop heater no matter what PID output. More...
 

Protected Member Functions

void _initialize ()
 Initialize RimsTuner before iterations.
 
void _iterate ()
 Iterations for RimsTuner instance. More...
 
void _refreshTuner ()
 Refresh relay identification and compute critical point parameters. More...
 
void _relayInit ()
 Init relay for identification procedure.
 
bool _relayAction ()
 Save a signal sample for amplitude evaluation and switch relay output if treshold is reached. More...
 
bool _relayStartNewPeriod ()
 Start new relay identification period. More...
 
void _relayEnd ()
 Evaluate PID coefficients and show them on UIRims.
 
float _evalAmplitude ()
 Evaluate fundamental harmonic amplitude of previously saved samples. More...
 
void _calcTuningPID (float T, float A)
 Calculate auto-tuned PID coefficients after tuning procedure. More...
 
- Protected Member Functions inherited from Rims
void _initSession ()
 Init all attributes and I/O for starting a brew session.
 
void _endSession ()
 Attributes treatments for ending a brew session.
 
void _refreshTimer ()
 Refresh time related values. More...
 
void _refreshDisplay ()
 Refresh display used by UIRims instance.
 
void _refreshSSR ()
 Refresh solid state relay. SSR will be refreshed in function of _controlValPtr (duty-cycle in percentage) and SSRWINDOWSIZE (mSec) values.
 
void _serialPrintBrewData ()
 Print current data points values to the Serial logger. Serial port (UART) need to be initialized in the main sketch with Serial.begin()
 
unsigned int _memCountSessions ()
 Count how many brew sessions were saved in flash mem. More...
 
unsigned long _memCountSessionData ()
 Count how many data point were taken. More...
 
void _memInitSP ()
 Initialize flash memory. More...
 
void _memAddBrewData ()
 Add data point to the flash memory. More...
 
void _memDumpBrewData ()
 Dump brew session data on USB serial port.
 
void _memFreeSpace ()
 Show free memory on flash mem via USB serial port.
 
void _memClearAll ()
 Clear all memory via USB serial port.
 

Detailed Description

Toolkit to automatically tune PID without a process model.

It tests differents values to the SSR and monitors the resulting temperature to automatically calculate proper PID coefficients. The resulting PID tuning is printed on the serial monitor at the end of the procedure. Open the serial monitor before stating the auto-tuning procedure.

The total required time for the auto-tuning procedure is unknown. It can last approximately from 30 minutes to 2 hours on the RIMS process.

It's based on two methods :

  1. Relay feedback (with hysteresis) process identification
  2. Ziegler-Nichols PID tuning method

For more details, see "Automatic Tuning of Simple Regulators with Specifications on Phase and Amplitude Margins" (Aström et al., 1984)

Warning
In most situations, manual PID tuning with a process model (using RimsIdent) is more robust and faster to disturbances.
Author
Francis Gagnon
Examples:
rimsTunerBasic.ino.

Constructor & Destructor Documentation

◆ RimsTuner()

RimsTuner::RimsTuner ( UIRims uiRims,
byte  analogPinTherm,
byte  ssrPin,
double *  currentTemp,
double *  ssrControl,
double *  settedTemp 
)

Consructor.

Parameters
uiRims: UIRims*. Pointer to UIRims instance
analogPinTherm: byte. Analog pin to temperature probe
ssrPin: byte. Pin to control heater's solid state relay.
currentTemp: double*. Pointer to a double that will be used for current temparature
ssrControl: double*. Pointer to a double that will use to control SSR
settedTemp: double*. Pointer to a double that will be use to store setted temperature

Member Function Documentation

◆ _calcTuningPID()

void RimsTuner::_calcTuningPID ( float  T,
float  A 
)
protected

Calculate auto-tuned PID coefficients after tuning procedure.

Classic Ziegler-Nichols method is applied on the critical (or ultimate) gain and period. PID coefficients are converted from the ideal form to the parallel form. Derivative filter time constant is fixed at \(\tau = 0.1K_d\). For more info : http://tinyurl.com/mwamcj5

Parameters
T: float. relay identification signal period in sec
A: float. relay identification signal amplitudes

◆ _evalAmplitude()

float RimsTuner::_evalAmplitude ( )
protected

Evaluate fundamental harmonic amplitude of previously saved samples.

The discrete Fourier serie (equivalent to FFT) is used to evaluate the signal amplitude of the first harmonic (more reliable than signal peak detection) :

\[ \begin{align} a_1 & = \frac{2t_s}{T} \sum_{n=0}^{N-1}y[n]\cos\left(\frac{2\pi nt_s}{T}\right)\\ b_1 & = \frac{2t_s}{T} \sum_{n=0}^{N-1}y[n]\sin\left(\frac{2\pi nt_s}{T}\right) \end{align} \]

where \(T\) is the \(y[n]\) period, \(N\) is \(y\) sample quantity and \(t_s\) is the sampling time. Then, \(y[n]\) amplitude \(A\) is evaluated with :

\[ A \approx \sqrt{a_1^2+b_1^2} \]

For more info : http://tinyurl.com/z3wtjyl

Returns
float. Calculated fundamental harmonic amplitude value

◆ _iterate()

void RimsTuner::_iterate ( )
protectedvirtual

Iterations for RimsTuner instance.

Auto-tuning procedure duration is unknown (~0.5-2 hours). It starts at STEP0VALUE % for STEADYTIMELENGTH (long enough for temperature stabilization in steady-state.). Average temperature is measured at the end of the signal stabilization phase. Relay identification is then perform on the RIMS.

All information related to the tuning procedure is printed in the Serial monitor of the Arduino IDE. PID coefficients is printed at the end. Data is stored in the flash memory if correctly connected.

Reimplemented from Rims.

◆ _refreshTuner()

void RimsTuner::_refreshTuner ( )
protected

Refresh relay identification and compute critical point parameters.

Because of Arduino lack of SRAM, it's impossible to store in an array all temperature measurements for a complete relay period (to evaluate signal amplitude afterward). Because of that, relay identification sampling time is increased at RELAYSAMPLEFACTOR*SAMPLETIME mSec (under-sampling). It should not induce precision problems since it is still quite fast relative to RIMS slow dynamics.

◆ _relayAction()

bool RimsTuner::_relayAction ( )
protected

Save a signal sample for amplitude evaluation and switch relay output if treshold is reached.

Returns
boolean. True if the relay identification goes on, false otherwise.

◆ _relayStartNewPeriod()

bool RimsTuner::_relayStartNewPeriod ( )
protected

Start new relay identification period.

Period and amplitude measurements are saved in arrays. Some variables is initialized for the next relay period and tuning is finished if limit-cycle is reached or if max relay periods is reached. Limit-cycle is considered stable if current period and amplitude measurement is whithin MODELPARAMTOL*100% (default of 5%) of the last measurement.

Returns
boolean. True if a new period is started, false if not.

◆ setFlowSensor()

void RimsTuner::setFlowSensor ( byte  pinFlow,
float  flowFactor,
float  lowBound = -1,
float  upBound = 100,
float  critalFlow = -1 
)

Same as Rims::setFlowSensor.

Redefinied to force criticalFlow at -1 and default bounds are fixed at -1 and 100 so you can auto-tune at any flowrate.


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