Library containing essential automation elements with parameters in continuous Laplace domain, and implemented with fixed sample time. This means that "out" member functions should be called using Ticker object.

Dependents:   CurrentMeasurement Zavrsni_rad_NXP_cup HC-SR04 Nucleo_SSD1306_DS1302_ESP8266_AM2320_BME280 ... more

Committer:
tbjazic
Date:
Thu Jan 22 12:44:37 2015 +0000
Revision:
1:b9e11da0f2eb
Parent:
0:3dd7aeceee65
Added header file "AutomationElements.h".

Who changed what in which revision?

UserRevisionLine numberNew contents of line
tbjazic 0:3dd7aeceee65 1 #include "PT1.h"
tbjazic 0:3dd7aeceee65 2
tbjazic 0:3dd7aeceee65 3 PT1::PT1() {
tbjazic 0:3dd7aeceee65 4 u = y = u_p1 = y_p1 = 0;
tbjazic 0:3dd7aeceee65 5 setParameters(1, 1, 0.1);
tbjazic 0:3dd7aeceee65 6 }
tbjazic 0:3dd7aeceee65 7
tbjazic 0:3dd7aeceee65 8 PT1::PT1(double K_, double T_1_, double T_d_) {
tbjazic 0:3dd7aeceee65 9 u = y = u_p1 = y_p1 = 0;
tbjazic 0:3dd7aeceee65 10 setParameters(K_, T_1_, T_d_);
tbjazic 0:3dd7aeceee65 11 }
tbjazic 0:3dd7aeceee65 12
tbjazic 0:3dd7aeceee65 13 void PT1::setParameters(double K_, double T_1_, double T_d_) {
tbjazic 0:3dd7aeceee65 14 if (T_d_ > 0)
tbjazic 0:3dd7aeceee65 15 T_d = T_d_;
tbjazic 0:3dd7aeceee65 16 else
tbjazic 0:3dd7aeceee65 17 T_d = 0.1;
tbjazic 0:3dd7aeceee65 18 K = K_;
tbjazic 0:3dd7aeceee65 19 T_1 = T_1_;
tbjazic 0:3dd7aeceee65 20 a_1 = -exp(-T_d/T_1);
tbjazic 0:3dd7aeceee65 21 b_1 = K * (1 + a_1);
tbjazic 0:3dd7aeceee65 22 }
tbjazic 0:3dd7aeceee65 23
tbjazic 0:3dd7aeceee65 24 double PT1::out() {
tbjazic 0:3dd7aeceee65 25 y = -a_1 * y_p1 + b_1 * u_p1;
tbjazic 0:3dd7aeceee65 26 y_p1 = y;
tbjazic 0:3dd7aeceee65 27 u_p1 = u;
tbjazic 0:3dd7aeceee65 28 return y;
tbjazic 0:3dd7aeceee65 29 }
tbjazic 0:3dd7aeceee65 30
tbjazic 0:3dd7aeceee65 31 void PT1::in(double u_) {
tbjazic 0:3dd7aeceee65 32 u = u_;
tbjazic 0:3dd7aeceee65 33 }