def isenginerunning(self): n_engines = DataRef.get_i("sim/aircraft/engine/acf_num_engines") running = DataRef.get_vi("sim/flightmodel/engine/ENGN_running", n_engines) if 1 in running: return True return False
def import_from_xsb(self): try: xsb_status = DataRef.get_i("xsquawkbox/login/status") if (xsb_status != 1): Logger.log("XSquawkbox not online. Skipping.") return except: Logger.log("XSquawkbox not found") return -1 Logger.log("Importing flight plan from XSquawkbox") self.online_pilot_id = DataRef.get_string("xsquawkbox/login/pilot_id") self.number = DataRef.get_string('xsquawkbox/login/callsign') self.aircraft_type = DataRef.get_string("xsquawkbox/login/model") self.flight_type = DataRef.get_i("xsquawkbox/fp/flight_type") # int, either I, V, D, or S self.origin = DataRef.get_string("xsquawkbox/fp/departure_airport") # string, ICAO code self.altitude = DataRef.get_string("xsquawkbox/fp/cruise_altitude") # string, either FLxxx or yyyyy self.destination = DataRef.get_string("xsquawkbox/fp/arrival_airport") # string, ICAO code self.alternate = DataRef.get_string("xsquawkbox/fp/alternate_airport") # string, ICAO code self.route = DataRef.get_string("xsquawkbox/fp/route") self.remarks = 'Imported from XSquawkbox'
def find_nearest_airport(self): lat = DataRef.get_d('sim/flightmodel/position/latitude') lon = DataRef.get_d('sim/flightmodel/position/longitude') navref = XPLMFindNavAid(None, None, lat, lon, None, xplm_Nav_Airport) if (navref == XPLM_NAV_NOT_FOUND): return None outLat = [] outLon = [] outID = [] outName = [] XPLMGetNavAidInfo(navref, None, outLat, outLon, None, None, None, outID, outName, None) airport = { 'icao': outID, 'name': outName, 'lat': outLat, 'lon': outLon } Logger.info("Nearest airport is %s" % airport['icao']) return airport
def loop_callback(self): time = DataRef.get_f('sim/time/total_flight_time_sec') # Sample rate limit if time - self.time < 1 / self.sample_rate: return self.update_status(time) self.time = time self.flight_phase.update() # sample rate adjustment according to phase of flight if self.flight_phase.phase == self.flight_phase.PHASE_LANDING: self.sample_rate = self.SAMPLE_RATE_HIGH_HZ elif self.flight_phase.phase == self.flight_phase.PHASE_CRUISE: self.sample_rate = self.SAMPLE_RATE_LOW_HZ else: self.sample_rate = self.SAMPLE_RATE_MEDIUM_HZ if not self.recording: return self.record()
def verticalspeed(self): return DataRef.get_f("sim/flightmodel/position/vh_ind_fpm")
def ias(self): return DataRef.get_f("sim/flightmodel/position/indicated_airspeed")
def height(self): return DataRef.get_f( "sim/cockpit2/gauges/indicators/radio_altimeter_height_ft_pilot")
def groundspeed(self): return DataRef.get_f("sim/flightmodel/position/groundspeed")
def isonground(self): gear_force = DataRef.get_f("sim/flightmodel/forces/fnrml_gear") return gear_force > 0
def record(self): Logger.log('recording sample') sample = {} # Recorded flight parameters sample['time_s'] = round( DataRef.get_f('sim/time/total_flight_time_sec'), 2) sample['baro_ref'] = round( DataRef.get_f('sim/cockpit/misc/barometer_setting'), 2) sample['altitude_ft'] = round( DataRef.get_f('sim/flightmodel/misc/h_ind')) sample['vertical_speed_fpm'] = round( DataRef.get_f("sim/flightmodel/position/vh_ind_fpm")) sample['height_ft'] = round( DataRef.get_f( "sim/cockpit2/gauges/indicators/radio_altimeter_height_ft_pilot" )) sample['latitude_deg'] = DataRef.get_f( 'sim/flightmodel/position/latitude') sample['longitude_deg'] = DataRef.get_f( 'sim/flightmodel/position/longitude') sample['heading_deg'] = round( DataRef.get_f( "sim/cockpit2/gauges/indicators/heading_vacuum_deg_mag_pilot")) sample['track_mag_deg'] = round( DataRef.get_f( "sim/cockpit2/gauges/indicators/ground_track_mag_pilot")) sample['gear_force'] = round( DataRef.get_f("sim/flightmodel/forces/fnrml_gear"), 1) sample['ias_kt'] = round( DataRef.get_f("sim/flightmodel/position/indicated_airspeed")) sample['tas_kt'] = round( DataRef.get_f( "sim/cockpit2/gauges/indicators/true_airspeed_kts_pilot")) sample['mach_no'] = round(DataRef.get_f("sim/flightmodel/misc/machno"), 2) sample['groundspeed_kt'] = round( DataRef.get_f("sim/flightmodel/position/groundspeed") * self.METERS_PER_SEC_TO_KT) sample['pitch_deg'] = round( DataRef.get_f("sim/flightmodel/position/true_theta")) sample['alpha_deg'] = round( DataRef.get_f("sim/flightmodel/position/alpha")) sample['load_factor_g'] = round( DataRef.get_f("sim/flightmodel/misc/g_total"), 1) sample['bank_deg'] = round( DataRef.get_f("sim/flightmodel/position/true_phi")) sample['sideslip_deg'] = round( DataRef.get_f("sim/cockpit2/gauges/indicators/sideslip_degrees")) sample['cabin_alt_ft'] = round( DataRef.get_f("sim/cockpit/pressure/cabin_altitude_actual_m_msl") * self.METERS_TO_FEET) sample['cabin_vs_fpm'] = round( DataRef.get_f("sim/cockpit/pressure/cabin_vvi_actual_m_msec") * self.METERS_PER_SEC_TO_FPM) sample['nav1_freq_hz'] = round( DataRef.get_f("sim/cockpit/radios/nav1_freq_hz"), 3) sample['nav1_nav_id'] = DataRef.get_string( "sim/cockpit2/radios/indicators/nav1_nav_id") sample['nav1_hdev_dot'] = round( DataRef.get_f("sim/cockpit/radios/nav1_hdef_dot"), 2) sample['nav1_vdef_dot'] = round( DataRef.get_f("sim/cockpit/radios/nav1_vdef_dot"), 2) sample['dme_freq_hz'] = round( DataRef.get_f("sim/cockpit/radios/dme_freq_hz"), 3) sample['dme_nav_id'] = DataRef.get_string( "sim/cockpit2/radios/indicators/dme_nav_id") sample['dme_distance_nm'] = round( DataRef.get_f( "sim/cockpit2/radios/indicators/hsi_dme_distance_nm_pilot"), 1) sample['yoke_pitch'] = round( DataRef.get_f("sim/cockpit2/controls/yoke_pitch_ratio"), 2) sample['yoke_roll'] = round( DataRef.get_f("sim/cockpit2/controls/yoke_roll_ratio"), 2) sample['yoke_yaw'] = round( DataRef.get_f("sim/cockpit2/controls/yoke_heading_ratio"), 2) sample['speedbrake_ratio'] = round( DataRef.get_f("sim/cockpit2/controls/speedbrake_ratio"), 1) sample['flap_ratio'] = round( DataRef.get_f("sim/cockpit2/controls/flap_ratio"), 1) sample['left_brake_ratio'] = round( DataRef.get_f("sim/cockpit2/controls/left_brake_ratio"), 2) sample['right_brake_ratio'] = round( DataRef.get_f("sim/cockpit2/controls/right_brake_ratio"), 2) sample['parking_brake_ratio'] = round( DataRef.get_f("sim/cockpit2/controls/parking_brake_ratio"), 1) self.flight_data.append(sample) if self.time - self.flush_time >= self.flush_interval_sec: self.flush()