Beispiel für einen C-Baustein (Deprecated)

In diesem Artikel finden Sie ein Beispiel für einen C-Baustein, der in logi.CAD 3 erstellt wurde. Der C-Baustein berechnet Parameter für einen Regler aus der OSCAT-Bibliothek.

ST-Schnittstelle für C-Baustein

Siehe "Schnittstelle für C-Baustein oder C++-Baustein erstellen (Deprecated)" für Informationen, wie eine ST-Schnittstelle erstellt wird.

Beispiel: Inhalt der ST-Schnittstelle
{extern_c}
FUNCTION_BLOCK CONTROL_SET2
VAR_INPUT
KS : REAL;
TU : REAL;
TG : REAL;
PI : BOOL;
PID : BOOL;
END_VAR
VAR_INPUT CONSTANT
P_K : REAL := 1.0;
PI_K : REAL := 0.9;
PI_TN : REAL := 3.33;
PID_K : REAL := 1.2;
PID_TN : REAL := 2.0;
PID_TV : REAL := 0.5;
END_VAR
VAR_OUTPUT
KP : REAL;
TN : REAL;
TV : REAL;
KI : REAL;
KD : REAL;
END_VAR
END_FUNCTION_BLOCK

Code im C-Baustein

Siehe "Code im C-Baustein oder C++-Baustein erstellen (Deprecated)" für Informationen zum C-Baustein.

Beispiel: Inhalt der C-Datei
#ifndef LC_PROT_LCFU___CONTROL_SET2__C
#define LC_PROT_LCFU___CONTROL_SET2__C
 
#include <lcfu___control_set2.h>
 
#define V(VAR) (LC_this->LC_VD_##VAR)
 
void lcfu___CONTROL_SET2(LC_TD_FunctionBlock_CONTROL_SET2* LC_this,
struct _lcoplck_epdb_1_impl* pEPDB)
{
LC_TD_REAL TX;
 
if (V(TU) > 0.0 && V(KS) > 0.0)
{
TX = V(TG) / V(TU) / V(KS);
}
if (V(PI) && V(PID))
{
V(KP) = 0.0;
V(TN) = 0.0;
V(TV) = 0.0;
}
else
{
if (V(PID))
{
V(KP) = V(PID_K) * TX;
V(TN) = V(PID_TN) * V(TU);
V(TV) = V(PID_TV) * V(TU);
}
else
{
if (V(PI))
{
V(KP) = V(PI_K) * TX;
V(TN) = V(PI_TN) * V(TU);
}
else
{
V(KP) = V(P_K) * TX;
}
}
}
 
/* KI and KD are calculated */
if (V(TN) > 0.0)
{
V(KI) = V(KP) / V(TN);
}
else
{
V(KI) = 0.0;
}
V(KD) = V(KP) * V(TV);
}
#endif