Machine implementation
[Programmable logic controllers (plc)]


Detailed Description

The machine object implements the PLC code.

On Windows machines, it compiles the code using mingw, which must be installed on your computer and is provided with the GridLAB-D distribution for that purpose. On Linux machines it uses gcc to compile the code.

The following is a sample of PLC code that implements a simple residential thermostat

    #define HEAT 0
    #define COOL 1
    #define OFF 2
    #define HYST 1.0
    #define LOCKOUT 300.0

    int state = OFF;
    BEGIN_DATA
        DOUBLE(Tair)
        DOUBLE(heating_setpoint)
        DOUBLE(cooling_setpoint)
    END_DATA

    #define Tair DATA(double,0)
    #define heating_setpoint DATA(double,1)
    #define cooling_setpoint DATA(double,2)

    INIT 
    {
        state=OFF;
        return 0;
    }

    CODE(dt,dev)
    {
        switch (state) {
        case OFF:
            if (Tair<heating_setpoint-HYST)
            {
                state=HEAT; 
                return 0;
            }
            else if (Tair>cooling_setpoint+HYST)
            {
                state=COOL; 
                return 0;
            }
            break;
        case HEAT:
            if (Tair>heating_setpoint+HYST)
            {
                state=OFF;
                return LOCKOUT;
            }
            break;
        case COOL:
            if (Tair<cooling_setpoint-HYST)
            {
                state=OFF;
                return LOCKOUT;
            }
            break;
        default:
            break;
        }
        return 1;
    }


GridLAB-DTM Version 2.0
An open-source project initiated by the US Department of Energy