tcas-mod-crown.c
tcas-mod-crown.c — C source code, 4 kB (5038 bytes)
File contents
#include <stdio.h> #include <stdlib.h> #define OLEV 600 /* in feets/minute */ #define MAXALTDIFF 600 /* max altitude difference in feet */ #define MINSEP 300 /* min separation in feet */ #define NOZCROSS 100 /* in feet */ /* variables */ typedef int bool; int Cur_Vertical_Sep; bool High_Confidence; bool Two_of_Three_Reports_Valid; int Own_Tracked_Alt; int Own_Tracked_Alt_Rate; int Other_Tracked_Alt; int Alt_Layer_Value; /* 0, 1, 2, 3 */ int Positive_RA_Alt_Thresh[4]; int Up_Separation; int Down_Separation; /* state variables */ int Other_RAC; /* NO_INTENT, DO_NOT_CLIMB, DO_NOT_DESCEND */ #define NO_INTENT 0 #define DO_NOT_CLIMB 1 #define DO_NOT_DESCEND 2 int Other_Capability; /* TCAS_TA, OTHER */ #define TCAS_TA 1 #define OTHER 2 int Climb_Inhibit; /* true/false */ #define UNRESOLVED 0 #define UPWARD_RA 1 #define DOWNWARD_RA 2 bool Own_Above_Threat(); bool Own_Below_Threat(); void initialize() { Positive_RA_Alt_Thresh[0] = 400; Positive_RA_Alt_Thresh[1] = 500; Positive_RA_Alt_Thresh[2] = 640; Positive_RA_Alt_Thresh[3] = 740; } int ALIM () { return Positive_RA_Alt_Thresh[Alt_Layer_Value]; } int Inhibit_Biased_Climb () { return (Climb_Inhibit ? Up_Separation + NOZCROSS : Up_Separation); } bool Non_Crossing_Biased_Climb() { int upward_preferred; int upward_crossing_situation; bool result; upward_preferred = Inhibit_Biased_Climb() > Down_Separation; if (upward_preferred) { result = !(Own_Below_Threat()) || ((Own_Below_Threat()) && (!(Down_Separation >= ALIM()))); } else { result = Own_Above_Threat() && (Cur_Vertical_Sep >= MINSEP) && (Up_Separation >= ALIM()); } return result; } bool Non_Crossing_Biased_Descend() { int upward_preferred; int upward_crossing_situation; bool result; upward_preferred = Inhibit_Biased_Climb() > Down_Separation; if (upward_preferred) { result = Own_Below_Threat() && (Cur_Vertical_Sep >= MINSEP) && (Down_Separation >= ALIM()); } else { result = !(Own_Above_Threat()) || ((Own_Above_Threat()) && (Up_Separation >= ALIM())); } return result; } bool Own_Below_Threat() { return (Own_Tracked_Alt < Other_Tracked_Alt); } bool Own_Above_Threat() { return (Other_Tracked_Alt < Own_Tracked_Alt); } int alt_sep_test() { bool enabled, tcas_equipped, intent_not_known; bool need_upward_RA, need_downward_RA; int alt_sep; enabled = High_Confidence && (Own_Tracked_Alt_Rate <= OLEV) && (Cur_Vertical_Sep > MAXALTDIFF); tcas_equipped = Other_Capability == TCAS_TA; intent_not_known = Two_of_Three_Reports_Valid && Other_RAC == NO_INTENT; alt_sep = UNRESOLVED; if (enabled && ((tcas_equipped && intent_not_known) || !tcas_equipped)) { need_upward_RA = Non_Crossing_Biased_Climb() && Own_Below_Threat(); need_downward_RA = Non_Crossing_Biased_Descend() && Own_Above_Threat(); if (need_upward_RA && need_downward_RA) alt_sep = UNRESOLVED; else if (need_upward_RA) alt_sep = UPWARD_RA; else if (need_downward_RA) alt_sep = DOWNWARD_RA; else alt_sep = UNRESOLVED; } return alt_sep; } int main(argc, argv) int argc; char *argv[]; { if(argc < 13) { fprintf(stdout, "Error: Command line arguments are\n"); fprintf(stdout, "Cur_Vertical_Sep, High_Confidence, Two_of_Three_Reports_Valid\n"); fprintf(stdout, "Own_Tracked_Alt, Own_Tracked_Alt_Rate, Other_Tracked_Alt\n"); fprintf(stdout, "Alt_Layer_Value, Up_Separation, Down_Separation\n"); fprintf(stdout, "Other_RAC, Other_Capability, Climb_Inhibit\n"); exit(1); } Cur_Vertical_Sep = atoi(argv[1]); High_Confidence = atoi(argv[2]); Two_of_Three_Reports_Valid = atoi(argv[3]); Own_Tracked_Alt = atoi(argv[4]); Own_Tracked_Alt_Rate = atoi(argv[5]); Other_Tracked_Alt = atoi(argv[6]); Alt_Layer_Value = atoi(argv[7]); Up_Separation = atoi(argv[8]); Down_Separation = atoi(argv[9]); Other_RAC = atoi(argv[10]); Other_Capability = atoi(argv[11]); Climb_Inhibit = atoi(argv[12]); initialize(); fprintf(stdout, "Control inputs:\n"); printf("Cur_Vertical_Sep = %10d\n",Cur_Vertical_Sep); printf("High_Confidence = %10d\n",High_Confidence ); printf("Two_of_Three_Reports_Valid = %10d\n",Two_of_Three_Reports_Valid ); printf("Own_Tracked_Alt = %10d\n",Own_Tracked_Alt ); printf("Own_Tracked_Alt_Rate = %10d\n",Own_Tracked_Alt_Rate ); printf("Other_Tracked_Alt = %10d\n",Other_Tracked_Alt); printf("Alt_Layer_Value = %10d\n",Alt_Layer_Value); printf("Up_Separation = %10d\n",Up_Separation ); printf("Down_Separation = %10d\n",Down_Separation ); printf("Other_RAC = %10d\n",Other_RAC ); printf("Other_Capability = %10d\n",Other_Capability ); printf("Climb_Inhibit = %10d\n",Climb_Inhibit ); fprintf(stdout, "Control output: %d\n", alt_sep_test()); // Main TCAS logic exit(0); }