// Generated by STruC++ - IEC 61131-3 Structured Text to C++ Compiler
// Do not edit this file manually.

#include "generated.hpp"

namespace strucpp {

FB_LEVEL_CTRL::FB_LEVEL_CTRL()
    : SCAN_S(0.1), KP(12.0), TI(120.0), INTEG(38.0)
{
    // Initialize variables
}

void FB_LEVEL_CTRL::operator()() {
    if (!ENABLE) {
        INTEG = MINSPEED;
        SPEED = MINSPEED;
    } else {
        ERR = LEVEL - SETPOINT;
        RAW = KP * ERR + INTEG;
        INTEGRATE = false;
        if (((RAW > MINSPEED)) & ((RAW < MAXSPEED))) {
            INTEGRATE = true;
        } else if (((RAW >= MAXSPEED)) & ((ERR < 0.0))) {
            INTEGRATE = true;
        } else if (((RAW <= MINSPEED)) & ((ERR > 0.0))) {
            INTEGRATE = true;
        }
        if (INTEGRATE) {
            INTEG = INTEG + (KP / TI) * ERR * SCAN_S;
        }
        RAW = KP * ERR + INTEG;
        if (RAW > MAXSPEED) {
            SPEED = MAXSPEED;
        } else if (RAW < MINSPEED) {
            SPEED = MINSPEED;
        } else {
            SPEED = RAW;
        }
    }
}

}  // namespace strucpp