コード例 #1
0
    def simulation(self, waypoint_index=4, latitude=34.362, longitude=-85.764):
        """
        Run simulation

        Parameters
        ----------
        waypoint_index : int
            Waypoint index (appears to be 0-based) that the response
            function input values will control
        latitude : float
            Waypoint latitude value to set
        longitude : float
            Waypoint longitude value to set
        """

        NATS_SIMULATION_STATUS_PAUSE = NatsEnvironment.get_nats_constant(
            'GNATS_SIMULATION_STATUS_PAUSE')
        NATS_SIMULATION_STATUS_ENDED = NatsEnvironment.get_nats_constant(
            'GNATS_SIMULATION_STATUS_ENDED')

        natsStandalone = NatsEnvironment.get_nats_standalone()

        simulationInterface = natsStandalone.getSimulationInterface()

        entityInterface = natsStandalone.getEntityInterface()
        controllerInterface = entityInterface.getControllerInterface()
        pilotInterface = entityInterface.getPilotInterface()

        environmentInterface = natsStandalone.getEnvironmentInterface()

        equipmentInterface = natsStandalone.getEquipmentInterface()
        aircraftInterface = equipmentInterface.getAircraftInterface()

        if simulationInterface is None:
            natsStandalone.stop()
            raise RuntimeError("Can't get SimulationInterface")

        simulationInterface.clear_trajectory()
        DIR_share = NatsEnvironment.share_dir

        environmentInterface.load_rap(DIR_share + "/tg/rap")
        aircraftInterface.load_aircraft(self.TRX_NAME, self.MFL_NAME)

        aclist = aircraftInterface.getAllAircraftId()

        simulationInterface.setupSimulation(30000, 1)

        simulationInterface.start()

        while True:
            runtime_sim_status = simulationInterface.get_runtime_sim_status()
            if (runtime_sim_status == NATS_SIMULATION_STATUS_ENDED):
                break
            else:
                time.sleep(1)

        # Store attribute for access by write_output and cleanup:
        self.simulationInterface = simulationInterface
        self.environmentInterface = environmentInterface
        self.aircraftInterface = aircraftInterface
コード例 #2
0
    def __init__(self, cfg):
        """
        extract input as self variable
        initialize NATS standalone server, retrieve NATS interfaces as self variable
        get simulation constant

        Parameters
        ----------
        cfg : dictionary
            inputs to VCAS simulation
            
            'fp_file' :  str
                directory tp flight plan file for NATS simulation
            'mfl_file' : str
                directory to mfl file for NATS simulation
            'cmd_file' : str
                directory to text command as .csv file
            'data_file' : srt
                directory to actual trajectory data as .csv file
            'sim_time' : int/float
                total simulation duration
        """
        self.fp_file = cfg['fp_file']
        self.mfl_file = cfg['mfl_file']
        self.cmd_file = cfg['cmd_file']
        self.sim_time = cfg['sim_time']
        self.track_file = cfg['data_file']
        self.real = pd.read_csv(cfg['data_file'])

        NatsEnvironment.start_jvm(nats_home=None)
        self.NATS_SIMULATION_STATUS_PAUSE = NatsEnvironment.get_nats_constant(
            'GNATS_SIMULATION_STATUS_PAUSE')
        self.NATS_SIMULATION_STATUS_ENDED = NatsEnvironment.get_nats_constant(
            'GNATS_SIMULATION_STATUS_ENDED')

        natsStandalone = NatsEnvironment.get_nats_standalone()

        self.simulationInterface = natsStandalone.getSimulationInterface()

        self.entityInterface = natsStandalone.getEntityInterface()
        self.controllerInterface = self.entityInterface.getControllerInterface(
        )
        self.pilotInterface = self.entityInterface.getPilotInterface()

        self.environmentInterface = natsStandalone.getEnvironmentInterface()

        self.equipmentInterface = natsStandalone.getEquipmentInterface()
        self.aircraftInterface = self.equipmentInterface.getAircraftInterface()

        if self.simulationInterface is None:
            natsStandalone.stop()
            raise RuntimeError("Can't get SimulationInterface")

        self.simulationInterface.clear_trajectory()
コード例 #3
0
    def __init__(self, cfg):
        """

        Parameters
        ----------
        cfg : dictionary
            inputs to Aviation Risk simulation
            
            'fp_file' :  str
                directory tp flight plan file for NATS simulation
            'mfl_file' : str
                directory to mfl file for NATS simulation
            'data_file' : str
                required data for accident simulation and risk estimation
            'model_file' : srt
                directory to pre-trained model
            'sim_time' : int/float
                total simulation duration
        """
        self.fp_file = cfg['fp_file']
        self.mfl_file = cfg['mfl_file']
        self.data = cfg['data_file']
        self.case = self.data + 'case.pickle'
        self.refer = self.data + 'refer.pickle'
        self.model = cfg['model_file']
        self.sim_time = cfg['sim_time']


        NatsEnvironment.start_jvm(nats_home=None)
        self.NATS_SIMULATION_STATUS_PAUSE = NatsEnvironment.get_nats_constant('NATS_SIMULATION_STATUS_PAUSE')
        self.NATS_SIMULATION_STATUS_ENDED = NatsEnvironment.get_nats_constant('NATS_SIMULATION_STATUS_ENDED')

        natsStandalone = NatsEnvironment.get_nats_standalone()

        self.simulationInterface = natsStandalone.getSimulationInterface()

        self.entityInterface = natsStandalone.getEntityInterface()
        self.controllerInterface = self.entityInterface.getControllerInterface()
        self.pilotInterface = self.entityInterface.getPilotInterface()

        self.environmentInterface = natsStandalone.getEnvironmentInterface()

        self.equipmentInterface = natsStandalone.getEquipmentInterface()
        self.aircraftInterface = self.equipmentInterface.getAircraftInterface()

        if self.simulationInterface is None:
            natsStandalone.stop()
            raise RuntimeError("Can't get SimulationInterface")

        self.simulationInterface.clear_trajectory()
コード例 #4
0
    input_file, output_file = sys.argv[1:]
    print('Input file is:', input_file)
    with open(input_file, 'r') as f:
        input_data = [float(x) for x in f.readline().split()]

    print('Running NATS simulation with input:', input_data)
    sim = TwoAcSim()
    # Execute the simulation.  Note that we also explicitly pass a
    # value for output_file, so that we get a record of the output
    # file.  Conveniently, UQpy coordinates each run in a separate
    # directory, so we will have a record of the NATS trajectory
    # output for each individual simulation that is performed.
    df = sim(output_file='nats_output.csv',
             latitude=input_data[0],
             longitude=input_data[1])['trajectory']
    sep = calc_sep_distance_vs_time(df)
    result = sep['sep'].iloc[-1]
    print('Separation distance:', result)
    print('Wrote results to:', output_file)
    # Running NATS requires a directory change.  By stopping the JVM
    # here, PARA-ATM will automatically return us to the original
    # working directory.  This is necessary so that the output file
    # goes to the right place. (PARA-ATM will automatically stop the
    # JVM when the Python process exits, but we want to do it here
    # prior to writing the output file.)

    NatsEnvironment.stop_jvm()

    with open(output_file, 'w') as f:
        f.write('{}\n'.format(result))
コード例 #5
0
 def tearDownClass(cls):
     NatsEnvironment.stop_jvm()
コード例 #6
0
    def simulation(self, cont_resp=10.):
        """
        Run simulation

        Parameters
        ----------
        waypoint_index : int
            Waypoint index (appears to be 0-based) that the response
            function input values will control
        latitude : float
            Waypoint latitude value to set
        longitude : float
            Waypoint longitude value to set
        """

        NATS_SIMULATION_STATUS_PAUSE = NatsEnvironment.get_nats_constant(
            'GNATS_SIMULATION_STATUS_PAUSE')
        NATS_SIMULATION_STATUS_ENDED = NatsEnvironment.get_nats_constant(
            'GNATS_SIMULATION_STATUS_ENDED')

        AIRCRAFT_CLEARANCE_PUSHBACK = NatsEnvironment.get_nats_clearance(
            "AIRCRAFT_CLEARANCE_PUSHBACK")
        AIRCRAFT_CLEARANCE_TAXI_DEPARTING = NatsEnvironment.get_nats_clearance(
            "AIRCRAFT_CLEARANCE_TAXI_DEPARTING")
        AIRCRAFT_CLEARANCE_TAKEOFF = NatsEnvironment.get_nats_clearance(
            "AIRCRAFT_CLEARANCE_TAKEOFF")
        AIRCRAFT_CLEARANCE_ENTER_ARTC = NatsEnvironment.get_nats_clearance(
            "AIRCRAFT_CLEARANCE_ENTER_ARTC")
        AIRCRAFT_CLEARANCE_DESCENT_FROM_CRUISE = NatsEnvironment.get_nats_clearance(
            "AIRCRAFT_CLEARANCE_DESCENT_FROM_CRUISE")
        AIRCRAFT_CLEARANCE_ENTER_TRACON = NatsEnvironment.get_nats_clearance(
            "AIRCRAFT_CLEARANCE_ENTER_TRACON")
        AIRCRAFT_CLEARANCE_APPROACH = NatsEnvironment.get_nats_clearance(
            "AIRCRAFT_CLEARANCE_APPROACH")
        AIRCRAFT_CLEARANCE_TOUCHDOWN = NatsEnvironment.get_nats_clearance(
            "AIRCRAFT_CLEARANCE_TOUCHDOWN")
        AIRCRAFT_CLEARANCE_TAXI_LANDING = NatsEnvironment.get_nats_clearance(
            "AIRCRAFT_CLEARANCE_TAXI_LANDING")
        AIRCRAFT_CLEARANCE_RAMP_LANDING = NatsEnvironment.get_nats_clearance(
            "AIRCRAFT_CLEARANCE_RAMP_LANDING")

        acClearances = [
            AIRCRAFT_CLEARANCE_PUSHBACK, AIRCRAFT_CLEARANCE_TAXI_DEPARTING,
            AIRCRAFT_CLEARANCE_TAKEOFF, AIRCRAFT_CLEARANCE_ENTER_ARTC,
            AIRCRAFT_CLEARANCE_DESCENT_FROM_CRUISE,
            AIRCRAFT_CLEARANCE_ENTER_TRACON, AIRCRAFT_CLEARANCE_APPROACH,
            AIRCRAFT_CLEARANCE_TOUCHDOWN, AIRCRAFT_CLEARANCE_TAXI_LANDING,
            AIRCRAFT_CLEARANCE_RAMP_LANDING
        ]

        natsStandalone = NatsEnvironment.get_nats_standalone()

        simulationInterface = natsStandalone.getSimulationInterface()

        entityInterface = natsStandalone.getEntityInterface()
        controllerInterface = entityInterface.getControllerInterface()
        pilotInterface = entityInterface.getPilotInterface()

        environmentInterface = natsStandalone.getEnvironmentInterface()

        equipmentInterface = natsStandalone.getEquipmentInterface()
        aircraftInterface = equipmentInterface.getAircraftInterface()

        if simulationInterface is None:
            natsStandalone.stop()
            raise RuntimeError("Can't get SimulationInterface")

        simulationInterface.clear_trajectory()
        DIR_share = NatsEnvironment.share_dir

        environmentInterface.load_rap(DIR_share + "/tg/rap")
        aircraftInterface.load_aircraft(
            NatsEnvironment.build_path(self.TRX_NAME),
            NatsEnvironment.build_path(self.MFL_NAME))
        aclist = list(aircraftInterface.getAllAircraftId())

        simulationInterface.setupSimulation(7200, 1)

        for ac in aclist:
            for acClearance in acClearances:
                controllerInterface.setDelayPeriod(ac, acClearance, cont_resp)

        simulationInterface.start()
        print('Running Simulation...')

        while True:
            runtime_sim_status = simulationInterface.get_runtime_sim_status()
            if (runtime_sim_status == NATS_SIMULATION_STATUS_ENDED):
                break
            else:
                time.sleep(1)

        # Store attribute for access by write_output and cleanup:
        self.simulationInterface = simulationInterface
        self.environmentInterface = environmentInterface
        self.aircraftInterface = aircraftInterface
コード例 #7
0
    def simulation(self, waypoint_index=4, latitude=34.362, longitude=-85.764):
        """
        Run simulation

        Parameters
        ----------
        waypoint_index : int
            Waypoint index (appears to be 0-based) that the response
            function input values will control
        latitude : float
            Waypoint latitude value to set
        longitude : float
            Waypoint longitude value to set
        """

        NATS_SIMULATION_STATUS_PAUSE = NatsEnvironment.get_nats_constant(
            'GNATS_SIMULATION_STATUS_PAUSE')
        NATS_SIMULATION_STATUS_ENDED = NatsEnvironment.get_nats_constant(
            'GNATS_SIMULATION_STATUS_ENDED')

        natsStandalone = NatsEnvironment.get_nats_standalone()

        simulationInterface = natsStandalone.getSimulationInterface()

        entityInterface = natsStandalone.getEntityInterface()
        controllerInterface = entityInterface.getControllerInterface()
        pilotInterface = entityInterface.getPilotInterface()

        environmentInterface = natsStandalone.getEnvironmentInterface()

        equipmentInterface = natsStandalone.getEquipmentInterface()
        aircraftInterface = equipmentInterface.getAircraftInterface()

        if simulationInterface is None:
            natsStandalone.stop()
            raise RuntimeError("Can't get SimulationInterface")

        simulationInterface.clear_trajectory()
        DIR_share = NatsEnvironment.share_dir

        environmentInterface.load_rap(DIR_share + "/tg/rap")
        aircraftInterface.load_aircraft(
            NatsEnvironment.build_path('demo_2ac.trx'),
            NatsEnvironment.build_path('demo_2ac_mfl.trx'))

        aclist = aircraftInterface.getAllAircraftId()
        ac = aircraftInterface.select_aircraft(aclist[0])

        ac.setFlight_plan_latitude_deg(waypoint_index, latitude)
        ac.setFlight_plan_longitude_deg(waypoint_index, longitude)

        # Useful print statements to either check the initial waypoint
        # coordinates or to verify that the setFlight_plan function is
        # working as expected
        # print('lat:', ac.getFlight_plan_latitude_array())
        # print('long:', ac.getFlight_plan_longitude_array())

        simulationInterface.setupSimulation(30000, 30)

        simulationInterface.start()

        while True:
            runtime_sim_status = simulationInterface.get_runtime_sim_status()
            if (runtime_sim_status == NATS_SIMULATION_STATUS_ENDED):
                break
            else:
                time.sleep(1)

        # Store attribute for access by write_output and cleanup:
        self.simulationInterface = simulationInterface
        self.environmentInterface = environmentInterface
        self.aircraftInterface = aircraftInterface
コード例 #8
0
    def simulation(self, *args, **kwargs):

        NATS_SIMULATION_STATUS_PAUSE = NatsEnvironment.get_nats_constant(
            'NATS_SIMULATION_STATUS_PAUSE')
        NATS_SIMULATION_STATUS_ENDED = NatsEnvironment.get_nats_constant(
            'NATS_SIMULATION_STATUS_ENDED')

        natsStandalone = NatsEnvironment.get_nats_standalone()

        simulationInterface = natsStandalone.getSimulationInterface()

        entityInterface = natsStandalone.getEntityInterface()
        controllerInterface = entityInterface.getControllerInterface()
        pilotInterface = entityInterface.getPilotInterface()

        environmentInterface = natsStandalone.getEnvironmentInterface()

        equipmentInterface = natsStandalone.getEquipmentInterface()
        aircraftInterface = equipmentInterface.getAircraftInterface()

        if simulationInterface is None:
            natsStandalone.stop()
            raise RuntimeError("Can't get SimulationInterface")

        simulationInterface.clear_trajectory()

        environmentInterface.load_rap("share/tg/rap")

        aircraftInterface.load_aircraft(
            "share/tg/trx/TRX_DEMO_SFO_PHX_GateToGate.trx",
            "share/tg/trx/TRX_DEMO_SFO_PHX_mfl.trx")

        #     # Controller to set human error: delay time
        #     # Users can try the following setting and see the difference in trajectory
        #controllerInterface.setDelayPeriod("SWA1897", AIRCRAFT_CLEARANCE_PUSHBACK, 7)
        #controllerInterface.setDelayPeriod("SWA1897", AIRCRAFT_CLEARANCE_TAKEOFF, 20)

        simulationInterface.setupSimulation(12000, 30)  # SFO - PHX

        simulationInterface.start(660)

        # Use a while loop to constantly check simulation status.  When the simulation finishes, continue to output the trajectory data
        while True:
            runtime_sim_status = simulationInterface.get_runtime_sim_status()
            if (runtime_sim_status == NATS_SIMULATION_STATUS_PAUSE):
                break
            else:
                time.sleep(1)

        # Pilot to set error scenarios
        # Users can try the following setting and see the difference in trajectory
        #pilotInterface.skipFlightPhase('SWA1897', 'FLIGHT_PHASE_CLIMB_TO_CRUISE_ALTITUDE')
        #pilotInterface.setActionRepeat('SWA1897', "VERTICAL_SPEED")
        #pilotInterface.setWrongAction('SWA1897', "AIRSPEED", "FLIGHT_LEVEL")
        #pilotInterface.setActionReversal('SWA1897', 'VERTICAL_SPEED')
        #pilotInterface.setPartialAction('SWA1897', 'COURSE', 200, 50)
        #pilotInterface.skipChangeAction('SWA1897', 'COURSE')
        #pilotInterface.setActionLag('SWA1897', 'COURSE', 10, 0.05, 60)

        simulationInterface.resume()

        while True:
            runtime_sim_status = simulationInterface.get_runtime_sim_status()
            if (runtime_sim_status == NATS_SIMULATION_STATUS_ENDED):
                break
            else:
                time.sleep(1)

        # Store attribute for access by write_output and cleanup:
        self.simulationInterface = simulationInterface
        self.environmentInterface = environmentInterface
        self.aircraftInterface = aircraftInterface