I am really begining to hate this
Code:
(* CONTROL *)
DATA_BLOCK dbControl
TITLE='dbControl'
STRUCT
Kc: REAL; // Controller gain
Ti: REAL; // Integrator gain
Td: REAL; // Derivative gain
DeltaT: REAL; // Simulation update time interval
CO: REAL; // Control Output -100 to 100%
ER: ARRAY[0..2] OF REAL; // Engineering units
K: ARRAY[0..2] OF REAL; // Gains
MinCO: REAL;
MaxCO: REAL;
END_STRUCT;
BEGIN
DeltaT:=0.01; // Update time 0.01 seconds or minutes but stay consistent
ER[0]:=0.0;
ER[1]:=0.0;
K[0]:=0.0;
END_DATA_BLOCK
FUNCTION_BLOCK fbControl
TITLE='fbControl'
VAR_INPUT
SP: REAL;
PV: REAL;
END_VAR
VAR_TEMP
CO: REAL;
END_VAR
IF dbControl.K[0]=0.0 THEN
dbControl.K[0]:=dbControl.Kc*(dbControl.DeltaT/dbControl.Ti+1.0+dbControl.Td/dbControl.DeltaT);
dbControl.K[1]:=-dbControl.Kc-2*dbControl.Td/dbControl.DeltaT;
dbControl.K[2]:=dbControl.Kc*dbControl.Td/dbControl.DeltaT;
END_IF;
dbControl.ER[2]:=dbControl.ER[1];
dbControl.ER[1]:=dbControl.ER[0];
dbControl.ER[0]:=SP-PV;
CO:=dbControl.CO+dbControl.K[0]*dbControl.ER[0]+dbControl.K[1]*dbControl.ER[1]+dbControl.K[2]*dbControl.ER[2];
CO:=LIMIT(MN:=0.0, IN:=CO, MX:=100.0);
dbControl.CO:=CO;
END_FUNCTION_BLOCK
Code:
(* SYSTEM OF DIFFERENTIAL EQUATIONS *)
DATA_BLOCK dbSODE
TITLE='dbSODE'
STRUCT
K: REAL; // System gain
A0: REAL;
A1: REAL;
A2: REAL;
DeadTime: REAL;
PVss: REAL; // ******t PV
dydt: REAL;
END_STRUCT;
BEGIN
END_DATA_BLOCK
FUNCTION_BLOCK fbSODE
TITLE='fbSODE'
VAR_INPUT
I: INT;
X: REAL;
Y: ARRAY[0..3] OF REAL;
END_VAR
CASE I OF
0: dbSODE.dydt:=Y[1];
1: dbSODE.dydt:=Y[2];
2: fbControl.dbControl(SP:=100.0, PV:=Y[0]); // ERRORS HERE
dbSODE.dydt:=-dbSODE.A2*Y[2]-dbSODE.A1*Y[1]+dbSODE.A1*db_RK4.K*dbControl.CO+dbSODE.PVss;
END_CASE;
END_FUNCTION_BLOCK
The CONTROL module compiles. The SODE module gives me an error at line 29 saying the system table enetry for instance DB or DB of type UDT does not match the called FB or UDT.
I compile the CONTROL module first. That should define the dbControl. However, the SODE module doesn't seem to understand that the dbControl has been defined.
I am begining to hate this. I have seen nothing in the documentation that say that modules must be compiled in a certain order but that seems to be the case and even so the Simatic manager appears to not update the symbol table.
There is definitely something wrong. I deleted fbControl and dbControl from the symbol table and recompile Control again. The symbol table should have been updated with new entries for fbControl and dbControl but it wasn't. Does the symbol table know about the fields in the DB?
1. Linear approximation, on something more advanced than least squares method.
Least squares is the way to go if you want linear approximation. I provided an example of second order or quadratic AND cubic approximation last week and no one but Norm seemed to care. How many points are going to be used in the approximation? Start a thread on this topic.
2. Exponential approximation.
At the moment, I have a fairly simply linear approximation based on least squares. Works OK, but the method puts too much weight on "outliers".
Do you need the approximation over a wide range? That is when it gets difficult. It is best if one know around which point the approximation is going to be over. It is easy to do smoothing after the fact where there are N points before and N points after the point that is being smoothed and then the smoothing filter is moved over all the data. There is an algoithm called Savitsky-Golay which is basically what I was trying to show last week in my movie.
A four pole Butterworth filter should be easy.
4. Alternative timer.
Sporting functions such as memorizing the last time clocked, "pause" input, "reset" input. And based on DINT milliseconds rather than TIME, for easy calculation of the setpoint in other functions.
That isn't hard IF one can find a real time clock. I know real time clock has been mentioned above but I have had my head up Siemen's a$$ trying to figure this **** put.
5. Alternative analog scaling.
Making a Rockwell like SCP function is easy.
With integral alarm levels, and filtering.
I think I know what you mean.
6. Alarm system.
Scanning of alarms, with memory, acknowledge, acknowledge to/from HMI.
To fit nicely into WinCC Flex and Protool alarm system.
I have some of the above already. But they could do with a complete rewrite
I am thinking more along the lines of tricky math algorithms.