-- 0 Park-- 1 Take Off-- 2 Fly -- 3 landing-- 4 TaxiPhaseOfFlight = 0function phases()VSI = xp.getDataref("sim/cockpit2/gauges/indicators/vvi_fpm_pilot") -- velocidad verticalget_VSI=xp.getFloat(VSI) -- velocidad vertical en ft/min ALTG= xp.getDataref("sim/flightmodel/position/y_agl") get_ALTG=xp.getFloat(ALTG) --Altura en metros AGLget_ALTG_ft = get_ALTG*3.28 -- Altura en pies AGL Cambio de metros a piesthro=xp.getDataref("sim/flightmodel/engine/ENGN_thro") -- Cantidad de Aceleradorget_thro=xp.getFloatV(thro,1,4)contact_sol=xp.getDataref("sim/flightmodel/parts/tire_vrt_def_veh") -- Contacto de las ruedas sobre la pista > 0 En el piso < 0 Esta en el aireget_contact_sol=xp.getFloatV(contact_sol,1,3) -- Por que tiene tres brazos el tren de aterrizajeif (get_ALTG_ft < 5) and (acf.getKIAS() < 5 ) and (get_contact_sol > 0 ) then -- Condicional ParkPhaseOfFlight = 0endif (get_ALTG_ft < 5) and (acf.getKIAS() > 80) and (get_contact_sol > 0 ) then -- Condicional Take OffPhaseOfFlight = 1endif (get_ALTG_ft >10000 ) and (acf.getKIAS() > 100 ) then -- Condicional FlyPhaseOfFlight = 2endif (get_VSI < -1) and (get_ALTG_ft < 2200) and (acf.getKIAS() < 250 ) then -- Condicional landing PhaseOfFlight = 3endif (get_ALTG_ft < 5) and (acf.getKIAS() < 50) and (acf.getKIAS() > 6 ) and (get_contact_sol > 0) then -- Condicional taxiPhaseOfFlight = 4endif(PhaseOfFlight == 0) then -- park park_stuff() endif(PhaseOfFlight == 3) then -- landing landing_stuff() gear_down() flare() braking()endif(PhaseOfFlight == 4) then -- Taxi taxi_stuff()endend
function taxi_stuff() --1 On, 0 Offdref_nav_lights = xp.getDataref("sim/cockpit/electrical/nav_lights_on")dref_land_lights = xp.getDataref("sim/cockpit/electrical/landing_lights_on")dref_taxi_lights = xp.getDataref("sim/cockpit/electrical/taxi_light_on") dref_strobe_lights = xp.getDataref("sim/cockpit/electrical/strobe_lights_on") dref_belts = xp.getDataref("sim/cockpit/switches/fasten_seat_belts") dref_smoking = xp.getDataref("sim/cockpit/switches/no_smoking") dref_TransP = xp.getDataref("sim/cockpit/radios/transponder_mode") dref_beacon_lights = xp.getDataref("sim/cockpit/electrical/beacon_lights_on")xp.setInt(dref_nav_lights,0) --Luces de Navegacion Apagadasxp.setInt(dref_land_lights,0) --Luces de Aterrizaje Apagadasxp.setInt(dref_taxi_lights,1) --Luces de Taxi Encendidasxp.setInt(dref_strobe_lights,0) --Luces de Strobe Apagadasxp.setInt(dref_smoking,1) --Luces de No fumar Encendidasxp.setInt(dref_TransP,2) --Luces de Transponder Modo Stand Byxp.setInt(dref_belts,1) --Cinturon de seguridad Encendidasxp.setInt(dref_beacon_lights,1) --Luces de Faros Encendidasend
function braking()ALTG= xp.getDataref("sim/flightmodel/position/y_agl") get_ALTG=xp.getFloat(ALTG)get_ALTG_ft = get_ALTG*3.28 -- Meters to FtIAS=xp.getDataref("sim/cockpit2/gauges/indicators/airspeed_kts_pilot") get_IAS=xp.getFloat(IAS)-- Logica : si el avion esta en el piso y la velocidad esta entre 30 y 80 aplicar los frenos al maximo if(get_ALTG_ft < 3) then xp.commandOnceByName("sim/flight_controls/speed_brakes_down_all") if ( get_IAS < 80) and ( get_IAS > 30) then xp.commandOnceByName("sim/flight_controls/brakes_max") end end
function flare()AUTOPILOT = xp.getDataref("sim/cockpit/autopilot/autopilot_mode")ALTG= xp.getDataref("sim/flightmodel/position/y_agl") get_ALTG=xp.getFloat(ALTG)get_ALTG_ft = get_ALTG*3.28 -- Meters to FtVSI=xp.getDataref("sim/cockpit2/gauges/indicators/vvi_fpm_pilot") get_VSI=xp.getFloat(VSI)IAS=xp.getDataref("sim/cockpit2/gauges/indicators/airspeed_kts_pilot") get_IAS=xp.getFloat(IAS)thro=xp.getDataref("sim/flightmodel/engine/ENGN_thro") get_thro=xp.getFloatV(thro,1,4) --caution here you need to give your engine count : 4 engines -> xp.getFloatV(thro,1,4)appr=xp.getDataref("sim/cockpit2/autopilot/approach_status")get_appr=xp.getInt(appr)EFIS_map_range_selector=xp.getDataref("sim/cockpit/switches/EFIS_map_range_selector")xp.setInt(EFIS_map_range_selector,0)EFIS_shows_waypoints = xp.getDataref("sim/cockpit/switches/EFIS_shows_waypoints")xp.setInt(EFIS_shows_waypoints,0)EFIS_shows_VORs = xp.getDataref("sim/cockpit/switches/EFIS_shows_VORs")xp.setInt(EFIS_shows_VORs,0)EFIS_shows_NDBs = xp.getDataref("sim/cockpit/switches/EFIS_shows_NDBs")xp.setInt(EFIS_shows_NDBs,0)if ( get_ALTG_ft < 50 and get_ALTG_ft >10 ) then -- en 10 sirve gain = 0.0001 target_vsi = -100 -- La velocidad Vertical que quiero lograr en este caso - 100 ft/min delta_vsi = (get_VSI - target_vsi) thro1 = xp.getFloatV(thro,1,1) -- Motor 1 thro2 = xp.getFloatV(thro,2,1) -- Motor 2 thro3 = xp.getFloatV(thro,3,1) -- Motor 3 thro4 = xp.getFloatV(thro,4,1) -- Motor 4 custom_throttle1 = (thro1 - (delta_vsi * gain)) if (custom_throttle1 > 1) then --- Protejo el Motor uno para que solo llegue hasta el 100 % custom_throttle1=1 end custom_throttle2 = (thro2 - (delta_vsi * gain)) if (custom_throttle2 > 1) then --- Protejo el Motor dos para que solo llegue hasta el 100 % custom_throttle2=1 end custom_throttle3 = (thro3 - (delta_vsi * gain)) if (custom_throttle3 > 1 )then --- Protejo el Motor tres para que solo llegue hasta el 100 % custom_throttle3=1 end custom_throttle4 = (thro4 - (delta_vsi * gain)) if (custom_throttle4 > 1 )then --- Protejo el Motor cuatro para que solo llegue hasta el 100 % custom_throttle4=1 end xp.setFloatV(thro, 1, custom_throttle1, custom_throttle2, custom_throttle3, custom_throttle4) elseif (get_ALTG_ft < 5 ) then --- Si ya esta casi en la pista xp.setFloatV(speedbreak,1) -- Pongo los Speed Brakes xp.commandOnceByName("sim/autopilot/nose_down_pitch_mode") custom_throttle1 = 0 -- Corto el Motor 1 custom_throttle2 = 0 -- Corto el Motor 2 custom_throttle3 = 0 -- Corto el Motor 3 custom_throttle4 = 0 --- Corto el Motor 4 xp.setFloatV(thro, 1, custom_throttle1, custom_throttle2, custom_throttle3, custom_throttle4) elseif ( get_ALTG_ft < 9 and get_ALTG_ft >4 ) then -- en 10 sirve xp.commandOnceByName("sim/autopilot/nose_down_pitch_mode") xp.commandOnceByName("sim/autopilot/autothrottle_off") xp.setInt(AUTOPILOT,0)end
# The states an aircraft can be inSTATES = {"NOT_MOVED" : 0, "TAXYING": 1, "STOPPED": 2, "AIRBORNE": 3}class Aircraft: """ Superclass for all aircraft types """ def __init__(self, callsign, XATC): ............. # The current state self.currentState = STATES["NOT_MOVED"] ..............def work(self): """ This is the main work method for the Aircraft. Subclasses must implement this method to do their stuff periodically. """ # We need to update the state we are in, based on what the aircraft is currently doing newState = self.currentState if (self.getAGL() > 1): newState = STATES["AIRBORNE"] elif (self.getGroundspeed() > 3): newState = STATES["TAXYING"] elif (self.currentState != STATES["NOT_MOVED"]): newState = STATES["STOPPED"] if (newState != self.currentState): self.currentState = newState self.stateChanged() return None