How to use the bluesky.traf function in bluesky

To help you get started, we’ve selected a few bluesky examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github TUDelft-CNS-ATM / bluesky / bluesky / ui / pygame / screen.py View on Github external
self.win.blit(self.editwin.bmp, (self.editwin.winx, self.editwin.winy))

            # Draw frames
            pg.draw.rect(self.win, white, self.editwin.rect, 1)
            pg.draw.rect(self.win, white, pg.Rect(1, 1, self.width - 1, self.height - 1), 1)

            # Add debug line
            self.fontsys.printat(self.win, 10, 2, str(bs.sim.utc.replace(microsecond=0)))
            self.fontsys.printat(self.win, 10, 18, tim2txt(bs.sim.simt))
            self.fontsys.printat(self.win, 10+80, 2, \
                                 "ntraf = " + str(bs.traf.ntraf))
            self.fontsys.printat(self.win, 10+160, 2, \
                                 "Freq=" + str(int(len(self.dts) / max(0.001, sum(self.dts)))))

            self.fontsys.printat(self.win, 10+240, 2, \
                                 "#LOS      = " + str(len(bs.traf.asas.lospairs_unique)))
            self.fontsys.printat(self.win, 10+240, 18, \
                                 "Total LOS = " + str(len(bs.traf.asas.lospairs_all)))
            self.fontsys.printat(self.win, 10+240, 34, \
                                 "#Con      = " + str(len(bs.traf.asas.confpairs_unique)))
            self.fontsys.printat(self.win, 10+240, 50, \
                                 "Total Con = " + str(len(bs.traf.asas.confpairs_all)))

            # Frame ready, flip to screen
            pg.display.flip()

            # If needed, take a screenshot
            if self.screenshot:
                pg.image.save(self.win,self.screenshotname)
                self.screenshot=False
        return
github TUDelft-CNS-ATM / bluesky / bluesky / ui / pygame / screen.py View on Github external
pg.draw.circle(self.win,green,(int(trafx[i]),int(trafy[i])),pixelrad,1)
                else:
                    self.win.blit(self.ambacsymbol[isymb], pos)
                    if self.swsep and not toosmall:
                        pg.draw.circle(self.win,amber,(int(trafx[i]),int(trafy[i])),pixelrad,1)


                # Draw last trail part
                if bs.traf.trails.active:
                    pg.draw.line(self.win, tuple(bs.traf.trails.accolor[i]),
                                 (ltx[i], lty[i]), (trafx[i], trafy[i]))

                # Label text
                label = []
                if self.swlabel > 0:
                    label.append(bs.traf.id[i])  # Line 1 of label: id
                else:
                    label.append(" ")
                if self.swlabel > 1:
                    if bs.traf.alt[i]>bs.traf.translvl:
                        label.append("FL"+str(int(round(bs.traf.alt[i] / (100.*ft)))))  # Line 2 of label: altitude
                    else:
                        label.append(str(int(round(bs.traf.alt[i] / ft))))  # Line 2 of label: altitude
                else:
                    label.append(" ")
                if self.swlabel > 2:
                    cas = bs.traf.cas[i] / kts
                    label.append(str(int(round(cas))))  # line 3 of label: speed
                else:
                    label.append(" ")
github TUDelft-CNS-ATM / bluesky / bluesky / traffic / route.py View on Github external
del self.wpname[idx]
        del self.wplat[idx]
        del self.wplon[idx]
        del self.wpalt[idx]
        del self.wpspd[idx]
        del self.wprta[idx]
        del self.wptype[idx]
        if self.iactwp > idx:
            self.iactwp = max(0, self.iactwp - 1)

        self.iactwp = min(self.iactwp, self.nwp - 1)

        # If no waypoints left, make sure to disable LNAV/VNAV
        if self.nwp==0 and (iac or iac==0):
            bs.traf.swlnav[iac]    =  False
            bs.traf.swvnav[iac]    =  False
            bs.traf.swvnavspd[iac] =  False

        return True
github TUDelft-CNS-ATM / bluesky / bluesky / ui / pygame / screen.py View on Github external
def update(self):
        """Draw a new frame"""
        # First check for keys & mouse
        self.keyb.update()
        # Navdisp mode: get center:
        if self.swnavdisp:
            i = bs.traf.id2idx(self.ndacid)
            if i >= 0:
                self.ndlat = bs.traf.lat[i]
                self.ndlon = bs.traf.lon[i]
                self.ndcrs = bs.traf.hdg[i]
            else:
                self.swnavdisp = False
        else:
            self.ndcrs = 0.0

        # Simulation: keep track of timestep
        # For measuring game loop frequency
        self.dts.append(bs.sim.simdt)
        if len(self.dts) > 20:
                del self.dts[0]

        # Radar window
        # --------------Background--------------

        if self.redrawradbg or self.swnavdisp:
            if self.swnavdisp or not self.swsat:
github TUDelft-CNS-ATM / bluesky / bluesky / stack / stack.py View on Github external
+ ","
            + repr(bs.traf.lat[i])
            + ","
            + repr(bs.traf.lon[i])
            + ","
            + repr(bs.traf.trk[i])
            + ","
            + repr(bs.traf.alt[i] / ft)
            + ","
            + repr(tas2cas(bs.traf.tas[i], bs.traf.alt[i]) / kts)
        )

        f.write(timtxt + cmdline + "\n")

        # VS acid,vs
        if abs(bs.traf.vs[i]) > 0.05:  # 10 fpm dead band
            if abs(bs.traf.ap.vs[i]) > 0.05:
                vs_ = bs.traf.ap.vs[i] / fpm
            else:
                vs_ = bs.traf.vs[i] / fpm

            cmdline = "VS " + bs.traf.id[i] + "," + repr(vs_)
            f.write(timtxt + cmdline + "\n")

        # Autopilot commands
        # Altitude
        if abs(bs.traf.alt[i] - bs.traf.ap.alt[i]) > 10.0:
            cmdline = "ALT " + bs.traf.id[i] + "," + repr(bs.traf.ap.alt[i] / ft)
            f.write(timtxt + cmdline + "\n")

        # Heading as well when heading select
        delhdg = (bs.traf.hdg[i] - bs.traf.ap.trk[i] + 180.0) % 360.0 - 180.0
github TUDelft-CNS-ATM / bluesky / bluesky / traffic / turbulence.py View on Github external
# Horizontal wing direction
        turbhw=np.random.normal(0,self.sd[1]*timescale,bs.traf.ntraf) #[m]

        # Vertical direction
        turbalt=np.random.normal(0,self.sd[2]*timescale,bs.traf.ntraf) #[m]

        trkrad=np.radians(bs.traf.trk)
        # Lateral, longitudinal direction
        turblat=np.cos(trkrad)*turbhf-np.sin(trkrad)*turbhw #[m]
        turblon=np.sin(trkrad)*turbhf+np.cos(trkrad)*turbhw #[m]

        # Update the aircraft locations
        bs.traf.alt = bs.traf.alt + turbalt
        bs.traf.lat = bs.traf.lat + np.degrees(turblat/Rearth)
        bs.traf.lon = bs.traf.lon + np.degrees(turblon/Rearth/bs.traf.coslat)
github TUDelft-CNS-ATM / bluesky / bluesky / traffic / autopilot.py View on Github external
if bs.traf.swvnavspd[i] and bs.traf.actwp.spd[i]> 0.0:
                    bs.traf.selspd[i] = bs.traf.actwp.spd[i]

            # Update qdr and turndist for this new waypoint for ComputeVNAV
            qdr[i], dummy = geo.qdrdist(bs.traf.lat[i], bs.traf.lon[i],
                                        bs.traf.actwp.lat[i], bs.traf.actwp.lon[i])

            # Update turndist so ComputeVNAV works, is there a next leg direction or not?
            if bs.traf.actwp.next_qdr[i] < -900.:
                local_next_qdr = qdr[i]
            else:
                local_next_qdr = bs.traf.actwp.next_qdr[i]

            # Calculate turn dist (and radius which we do not use) now for scalar variable [i]
            bs.traf.actwp.turndist[i], dummy = \
                bs.traf.actwp.calcturn(bs.traf.tas[i], bs.traf.bank[i],
                                        qdr[i], local_next_qdr)  # update turn distance for VNAV


            # VNAV = FMS ALT/SPD mode incl. RTA
            self.ComputeVNAV(i, toalt, bs.traf.actwp.xtoalt[i], bs.traf.actwp.torta[i],
                             bs.traf.actwp.xtorta[i])

        # Continuous guidance when speed constraint on active leg

        # If still an RTA in the route and currently no speed constraint
        for iac in np.where((bs.traf.actwp.torta > -99.)*(bs.traf.actwp.spdcon<0.0))[0]:
            iwp = bs.traf.ap.route[iac].iactwp
            if bs.traf.ap.route[iac].wprta[iwp]>-99.:

                 # For all a/c flying to an RTA waypoint, recalculate speed more often
                dist2go4rta = geo.kwikdist(bs.traf.lat[iac],bs.traf.lon[iac], \
github TUDelft-CNS-ATM / bluesky / bluesky / traffic / metric.py View on Github external
#         traf_selected_alt = np.append(traf_selected_alt,bs.traf.alt[i])
        #         traf_selected_tas = np.append(traf_selected_tas,bs.traf.tas[i])
        #         traf_selected_trk = np.append( traf_selected_trk,bs.traf.trk[i])
        #         traf_selected_ntraf = traf_selected_ntraf + 1

        # CIRCLE AREA (FIR Circle)
        for i in range(0,bs.traf.ntraf):

            dist = latlondist(bs.sim.metric.fir_circle_point[0],\
                              bs.sim.metric.fir_circle_point[1],\
                              bs.traf.lat[i],bs.traf.lon[i])

            if  dist/nm < bs.sim.metric.fir_circle_radius:
                traf_selected_lat = np.append(traf_selected_lat,bs.traf.lat[i])
                traf_selected_lon = np.append(traf_selected_lon,bs.traf.lon[i])
                traf_selected_alt = np.append(traf_selected_alt,bs.traf.alt[i])
                traf_selected_tas = np.append(traf_selected_tas,bs.traf.tas[i])
                traf_selected_trk = np.append( traf_selected_trk,bs.traf.trk[i])
                traf_selected_ntraf = traf_selected_ntraf + 1


        return traf_selected_lat,traf_selected_lon,traf_selected_alt,traf_selected_tas,traf_selected_trk,traf_selected_ntraf
github TUDelft-CNS-ATM / bluesky / bluesky / traffic / autopilot.py View on Github external
# VNAV speeds are always FROM-speed, so we accelerate/decellerate at the waypoint
            # where this speed is specified, so we need to save it for use now
            # before getting the new data for the next waypoint

            # Get speed for next leg from the waypoint we now
            bs.traf.actwp.spd[i]    = bs.traf.actwp.nextspd[i]
            bs.traf.actwp.spdcon[i] = bs.traf.actwp.nextspd[i]

            # Get next wp (lnavon = False if no more waypoints)
            lat, lon, alt, bs.traf.actwp.nextspd[i], bs.traf.actwp.xtoalt[i], toalt, \
                bs.traf.actwp.xtorta[i], bs.traf.actwp.torta[i], \
                lnavon, flyby, bs.traf.actwp.next_qdr[i] =      \
                self.route[i].getnextwp()  # note: xtoalt,toalt in [m]

            # End of route/no more waypoints: switch off LNAV
            bs.traf.swlnav[i] = bs.traf.swlnav[i] and lnavon

            # In case of no LNAV, do not allow VNAV mode on its own
            bs.traf.swvnav[i] = bs.traf.swvnav[i] and bs.traf.swlnav[i]

            bs.traf.actwp.lat[i] = lat  # [deg]
            bs.traf.actwp.lon[i] = lon  # [deg]
            # 1.0 in case of fly by, else fly over
            bs.traf.actwp.flyby[i] = int(flyby)

            # User has entered an altitude for this waypoint
            if alt >= -0.01:
                bs.traf.actwp.nextaltco[i] = alt  # [m]

            if not bs.traf.swlnav[i]:
                bs.traf.actwp.spd[i] = -999.