TMCALGO V2R1: Algorithm Compiler

Altitude Example

This partition was extracted verbatim from the Chlorine Nitrate instrument flight algorithm. It converts pressure (altitude) into states (ON_GROUND, BELOW_CLOUDS, ABOVE_CLOUDS). The threshold pressures each have two values - one for the flight up and the other for the flight down. This provides hysteresis and prevents bouncing.


PARTITION

%{ /* Altitude definitions */
    double P_ground_up = 500.;
    double P_ground_dn = 550.;
    double P_clouds_up = 280.;
    double P_clouds_dn = 370.;
    int using_swp = 0;
%}

# note on 960718 it was 10 min to below the clouds
# and +7 min to above the clouds

State ON_GROUND {
    { using_swp = 0; }
    >   Set SW Status 1 to 0
    { if ( SW1_S == 1 ) {
        using_swp = 1;
        validate BELOW_CLOUDS;
    } else if (convert(SD1_P) < P_ground_up)
        validate BELOW_CLOUDS;
    }
}

State BELOW_CLOUDS {
    >   Set SW Status 1 to 0

    { if ((using_swp && SW1_S == 2) ||
          (!using_swp && convert(SD1_P) < P_clouds_up))
        validate ABOVE_CLOUDS;
      else if ((using_swp && SW1_S == 4) ||
          (!using_swp && convert(SD1_P) > P_ground_dn))
        validate ON_GROUND;
    }
}

State ABOVE_CLOUDS {
    >   Set SW Status 1 to 0

    { if ( (using_swp && SW1_S == 3) ||
          (!using_swp && convert(SD1_P) > P_clouds_dn))
        validate BELOW_CLOUDS;
    }
}

Return to Manuals Guide. Written by Norton T. Allen
Copyright © 2001 by the President and Fellows of Harvard College