/*
 * Siemens AG (R) Fuzzy-C Compiler Version 3.0.0
 *
 * Source file: "C:\SIEFUZZY\EXAMPLES\PEND\PENDEX.FPL"
 *
 * Compiled Thu Feb 10 14:58:54 1994
 *
 * Option settings
 * ---------------
 *   Belief type:                           fixed unsigned byte
 *   C format:                              ANSI
 *   Expression complexity:                 32767
 *   Default inference/defuz method (IDM):  Maxdot_Centroid
 *   Default lookup table size:             256
 *   Default public code:                   OFF
 *   Default dynamic init of USER/IDM:      OFF
 *   Emit lookup tables for members:        OFF
 *   Generate debug code:                   OFF
 *   Maximum name length:                   40
 *   Emit unused members:                   OFF
 *   Verbose compiler messages:             ON
 *   Implement operators as functions:      OFF
 *   Error file:                            OFF
 *   Disable if on rule right hand side:    OFF
 *   Disable inline conclusions:            OFF
 *   Parameter structures:                  OFF
 *   Return rule alphas:                    OFF
 *   Output files base name:                
 */

/*
 * Portability definitions and internal structures.
 */

#define FCC_STDC_STYLE 1

#include <stdlib.h>
#include <math.h>
#include <fcdslib.h>
#include "PENDEX.h"

FLOAT FCC_Integrator_Sum;

/*
 * Externally defined USER implementation functions
 */

static void Integrator_Init (void);

/*
 * Initializes all statically initialized user-defined objects and IDMs
 */

void FCC_user_init(void)
{
    Integrator_Init ();
}

/*
 * FPL objects.
 */

/*
 * VAR Error
 */

/*
 * MEMBER N
 */

const static struct FCCptfb FCC_Error_N_pts[] = {
    { -1.00000000000, 255u },
    { -0.400000000000, 255u },
    { 0.000000000000, 0u }
};

/*
 * MEMBER Z
 */

const static struct FCCptfb FCC_Error_Z_pts[] = {
    { -0.400000000000, 0u },
    { 0.000000000000, 255u },
    { 0.400000000000, 0u }
};

/*
 * MEMBER P
 */

const static struct FCCptfb FCC_Error_P_pts[] = {
    { 0.000000000000, 0u },
    { 0.400000000000, 255u },
    { 1.00000000000, 255u }
};

/*
 * VAR dError
 */

/*
 * MEMBER N
 */

const static struct FCCptfb FCC_dError_N_pts[] = {
    { -1.00000000000, 255u },
    { -0.400000000000, 255u },
    { 0.000000000000, 0u }
};

/*
 * MEMBER Z
 */

const static struct FCCptfb FCC_dError_Z_pts[] = {
    { -0.400000000000, 0u },
    { 0.000000000000, 255u },
    { 0.400000000000, 0u }
};

/*
 * MEMBER P
 */

const static struct FCCptfb FCC_dError_P_pts[] = {
    { 0.000000000000, 0u },
    { 0.400000000000, 255u },
    { 1.00000000000, 255u }
};

/*
 * VAR Current
 */

/*
 * MEMBER Z
 */

/*
 * MEMBER NB
 */

/*
 * MEMBER PB
 */

/*
 * MEMBER PS
 */

/*
 * MEMBER NS
 */

/*
 * VAR IntegralError
 */

/*
 * RULEBASE Pendulum
 */

static void Pendulum (FLOAT Error, FLOAT dError, FLOAT *Current);

static void Pendulum (FLOAT Error, FLOAT dError, FLOAT *Current)
{

    FUBYTE FCC_alpha;
    FUBYTE FCC_Error_is_N;
    FUBYTE FCC_Error_is_Z;
    FUBYTE FCC_Error_is_P;
    FUBYTE FCC_dError_is_N;
    FUBYTE FCC_dError_is_Z;
    FUBYTE FCC_dError_is_P;
    struct FCCif FCC_Current_temp;

    FCC_Current_temp.n = 0.0;
    FCC_Current_temp.d = 0.0;

    FCC_Error_is_N = FCCpfb (Error, 3, FCC_Error_N_pts);
    FCC_Error_is_Z = FCCpfb (Error, 3, FCC_Error_Z_pts);
    FCC_Error_is_P = FCCpfb (Error, 3, FCC_Error_P_pts);
    FCC_dError_is_N = FCCpfb (dError, 3, FCC_dError_N_pts);
    FCC_dError_is_Z = FCCpfb (dError, 3, FCC_dError_Z_pts);
    FCC_dError_is_P = FCCpfb (dError, 3, FCC_dError_P_pts);

/*
 * RULE Rule1
 */

    FCC_alpha = FCCmandb(FCC_Error_is_N,FCC_dError_is_Z);

    if (FCC_alpha != 0u)
    {
        /* Current = PB */

        FCC_Current_temp.n += FCC_alpha * 32492.1796875;
        FCC_Current_temp.d += FCC_alpha * 31699.6875000;
    }

/*
 * RULE Rule2
 */

    FCC_alpha = FCCmandb(FCC_Error_is_N,FCC_dError_is_P);

    if (FCC_alpha != 0u)
    {
        /* Current = PS */

        FCC_Current_temp.n += FCC_alpha * 26115.6656250;
        FCC_Current_temp.d += FCC_alpha * 34138.1250000;
    }

/*
 * RULE Rule3
 */

    FCC_alpha = FCCmandb(FCC_Error_is_Z,FCC_dError_is_P);

    if (FCC_alpha != 0u)
    {
        /* Current = NS */

        FCC_Current_temp.n += FCC_alpha * -26115.6656250;
        FCC_Current_temp.d += FCC_alpha * 34138.1250000;
    }

/*
 * RULE Rule4
 */

    FCC_alpha = FCCmandb(FCC_Error_is_Z,FCC_dError_is_Z);

    if (FCC_alpha != 0u)
    {
        /* Current = Z */

        FCC_Current_temp.n += FCC_alpha * 0.000000000000;
        FCC_Current_temp.d += FCC_alpha * 6827.62500000;
    }

/*
 * RULE Rule5
 */

    FCC_alpha = FCCmandb(FCC_Error_is_Z,FCC_dError_is_N);

    if (FCC_alpha != 0u)
    {
        /* Current = PS */

        FCC_Current_temp.n += FCC_alpha * 26115.6656250;
        FCC_Current_temp.d += FCC_alpha * 34138.1250000;
    }

/*
 * RULE Rule6
 */

    FCC_alpha = FCCmandb(FCC_Error_is_P,FCC_dError_is_N);

    if (FCC_alpha != 0u)
    {
        /* Current = NS */

        FCC_Current_temp.n += FCC_alpha * -26115.6656250;
        FCC_Current_temp.d += FCC_alpha * 34138.1250000;
    }

/*
 * RULE Rule7
 */

    FCC_alpha = FCCmandb(FCC_Error_is_P,FCC_dError_is_Z);

    if (FCC_alpha != 0u)
    {
        /* Current = NB */

        FCC_Current_temp.n += FCC_alpha * -32492.1796875;
        FCC_Current_temp.d += FCC_alpha * 31699.6875000;
    }

    if (FCC_Current_temp.d != 0.000000000000)
        *Current = (FCC_Current_temp.n / FCC_Current_temp.d);
    else
        *Current = 0.000000000000;
}

/*
 * PROCUNIT Integrator
 */

static void Integrator_Init(void)
{
    FCC_Integrator_Sum = 0.000000000000;
}

static void Integrator (FLOAT Error, FLOAT *IntegralError);

static void Integrator (FLOAT Error, FLOAT *IntegralError)
{

    FCC_Integrator_Sum = (FCC_Integrator_Sum)+(Error);
    *IntegralError = FCC_Integrator_Sum;
}

/*
 * PROJECT Pend
 */

void Pend (FLOAT Error, FLOAT dError, FLOAT *Current, FLOAT *IntegralError)
{

/*
 * RULEBASE Pendulum
 */

    Pendulum (Error, dError, Current);

/*
 * PROCUNIT Integrator
 */

    Integrator (Error, IntegralError);

}

