def stack_all_commands(self): """create and stack command""" params = ('lat', 'lon', 'alt', 'speed', 'heading', 'callsign') for i, d in self.acpool.items(): # check if all needed keys are in dict if set(params).issubset(d): acid = d['callsign'] # check is aircraft is already beening displayed if (self.traf.id2idx(acid) < 0): mdl = self.default_ac_mdl v = aero.tas2cas(d['speed'], d['alt'] * aero.ft) cmdstr = 'CRE %s, %s, %f, %f, %f, %d, %d' % \ (acid, mdl, d['lat'], d['lon'], d['heading'], d['alt'], v) stack.stack(cmdstr) else: cmdstr = 'MOVE %s, %f, %f, %d' % \ (acid, d['lat'], d['lon'], d['alt']) stack.stack(cmdstr) cmdstr = 'HDG %s, %f' % (acid, d['heading']) stack.stack(cmdstr) v_cas = aero.tas2cas(d['speed'], d['alt'] * aero.ft) cmdstr = 'SPD %s, %f' % (acid, v_cas) stack.stack(cmdstr) return
def stack_all_commands(self): """create and stack command""" params = ('lat', 'lon', 'alt', 'speed', 'heading', 'callsign') for i, d in self.acpool.items(): # check if all needed keys are in dict if set(params).issubset(d): acid = d['callsign'] # check is aircraft is already beening displayed if(self.traf.id2idx(acid) < 0): mdl = self.default_ac_mdl v = aero.tas2cas(d['speed'], d['alt'] * aero.ft) cmdstr = 'CRE %s, %s, %f, %f, %f, %d, %d' % \ (acid, mdl, d['lat'], d['lon'], d['heading'], d['alt'], v) self.stack.stack(cmdstr) else: cmdstr = 'MOVE %s, %f, %f, %d' % \ (acid, d['lat'], d['lon'], d['alt']) self.stack.stack(cmdstr) cmdstr = 'HDG %s, %f' % (acid, d['heading']) self.stack.stack(cmdstr) v_cas = aero.tas2cas(d['speed'], d['alt'] * aero.ft) cmdstr = 'SPD %s, %f' % (acid, v_cas) self.stack.stack(cmdstr) return
def stack_all_commands(self): keys = ('lat', 'lon', 'alt', 'speed', 'heading') for ac, acdata in self.acdata_pool.items(): # check if all needed keys are in dict if set(keys).issubset(acdata): acid = ac # acid = acdata['acid'] # check is aircraft is already beening displayed if(self.tmx.traf.id2idx(acid) < 0): v_cas = aero.tas2cas(acdata['speed'], acdata['alt']/3.2808) cmdstr = 'CRE %s, %s, %f, %f, %f, %d, %d' % \ (acid, 'B738', acdata['lat'], acdata['lon'], \ acdata['heading'], acdata['alt'], v_cas) self.tmx.cmd.stack(cmdstr) else: cmdstr = 'MOVE %s, %f, %f, %d' % \ (acid, acdata['lat'], acdata['lon'], acdata['alt']) self.tmx.cmd.stack(cmdstr) cmdstr = 'HDG %s, %f' % (acid, acdata['heading']) self.tmx.cmd.stack(cmdstr) v_cas = aero.tas2cas(acdata['speed'], acdata['alt']/3.2808) cmdstr = 'SPD %s, %f' % (acid, v_cas) self.tmx.cmd.stack(cmdstr) return
def create(self, acid, actype, aclat, aclon, achdg, acalt, acspd): # Check if not already exist if self.id.count(acid.upper()) > 0: return # already exists do nothing # Increase number of aircraft self.ntraf = self.ntraf + 1 # Process input self.id.append(acid.upper()) self.type.append(actype) self.lat = np.append(self.lat, aclat) self.lon = np.append(self.lon, aclon) self.trk = np.append(self.trk, achdg) # TBD: add conversion hdg => trk self.alt = np.append(self.alt, acalt) self.vs = np.append(self.vs, 0.) self.rho = np.append(self.rho, density(acalt)) self.tas = np.append(self.tas, acspd) self.cas = np.append(self.cas, tas2cas(acspd, acalt)) # Type specific data (temporarily default values) self.avsdef = np.append(self.avsdef, 1500. * fpm) # default vertical speed of autopilot self.aphi = np.append(self.aphi, radians(25.)) # bank angle setting of autopilot self.ax = np.append( self.ax, kts) # absolute value of longitudinal accelleration # Traffic autopilot settings: hdg[deg], spd (CAS,m/s), alt[m], vspd[m/s] self.ahdg = np.append(self.ahdg, achdg) # selected heading [deg] self.aspd = np.append(self.aspd, tas2eas(acspd, acalt)) # selected spd(eas) [m/s] self.aalt = np.append(self.aalt, acalt) # selected alt[m] self.avs = np.append(self.avs, 0.) # selected vertical speed [m/s] # Traffic navigation information self.dest.append("") self.orig.append("") # LNAV route navigation self.swlnav = np.append(self.swlnav, False) # Lateral (HDG) based on nav self.swvnav = np.append( self.swvnav, False) # Vertical/longitudinal (ALT+SPD) based on nav info self.actwplat = np.append(self.actwplat, 0.0) # Active WP latitude self.actwplon = np.append(self.actwplon, 0.0) # Active WP longitude self.actwpalt = np.append(self.actwpalt, 0.0) # Active WP altitude self.actwpspd = np.append(self.actwpspd, 0.0) # Active WP speed # Route info self.route.append(Route( self.navdb)) # create empty route connected with nav databse # ASAS info: no conflict => -1 self.iconf = np.append( self.iconf, -1.0) # index in 'conflicting' aircraft database # Area variable set to False to avoid deletion upon creation outside self.inside.append(False) # Display information on label self.label.append(['', '', '', 0]) # Bread crumbs for trails self.trailcol.append(self.trails.defcolor) self.lastlat = np.append(self.lastlat, aclat) self.lastlon = np.append(self.lastlon, aclon) self.lasttim = np.append(self.lasttim, 0.0) return
def saveic(self, fname, sim, traf): # Add extension .scn if not already present if fname.find(".scn") < 0 and fname.find(".SCN"): fname = fname + ".scn" # If it is with path don't touch it, else add path if fname.find("/") < 0: scenfile = "./scenario/" + fname.lower() # Open file try: f = open(scenfile, "w") except: return -1 # Write files timtxt = "00:00:00.00>" for i in range(traf.ntraf): # CRE acid,type,lat,lon,hdg,alt,spd cmdline = "CRE " + traf.id[i] + "," + traf.type[i] + "," + \ repr(traf.lat[i]) + "," + repr(traf.lon[i]) + "," + \ repr(traf.trk[i]) + "," + repr(traf.alt[i] / ft) + "," + \ repr(tas2cas(traf.tas[i], traf.alt[i]) / kts) f.write(timtxt + cmdline + chr(13) + chr(10)) # VS acid,vs if abs(traf.vs[i]) > 0.05: # 10 fpm dead band if traf.avs[i] > 0.05: vs_ = traf.avs[i] / fpm else: vs_ = traf.vs[i] / fpm cmdline = "VS " + traf.id[i] + "," + repr(vs_) f.write(timtxt + cmdline + chr(13) + chr(10)) # Autopilot commands # Altitude if abs(traf.alt[i] - traf.aalt[i]) > 10.: cmdline = "ALT " + traf.id[i] + "," + repr(traf.aalt[i] / ft) # Heading as well when heading select delhdg = (traf.trk[i] - traf.ahdg[i] + 180.) % 360. - 180. if abs(delhdg) > 0.5: cmdline = "ALT " + traf.id[i] + "," + repr(traf.aalt[i] / ft) # Speed select? => Record rho = density(traf.alt[i]) # alt in m! aptas = sqrt(1.225 / rho) * traf.aspd[i] delspd = aptas - traf.tas[i] if abs(delspd) > 0.4: cmdline = "SPD " + traf.id[i] + "," + repr(traf.aspd[i] / kts) # DEST acid,dest-apt if traf.dest[i] != "": cmdline = "DEST " + traf.id[i] + "," + traf.dest[i] f.write(timtxt + cmdline + chr(13) + chr(10)) # ORIG acid,orig-apt if traf.orig[i] != "": cmdline = "ORIG " + traf.id[i] + "," + \ traf.dest[i] f.write(timtxt + cmdline + chr(13) + chr(10)) # Saveic: should close f.close() return 0