Skip to content

Commit

Permalink
moved AP variables to AP
Browse files Browse the repository at this point in the history
  • Loading branch information
jooste committed Aug 18, 2021
1 parent 4a0047a commit ceea561
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 22 deletions.
2 changes: 1 addition & 1 deletion bluesky/traffic/activewpdata.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def Reached(self, qdr, dist, flyby, flyturn, turnradnm,swlastwp):
# First calculate turn distance
next_qdr = np.where(self.next_qdr < -900., qdr, self.next_qdr)
turntas = np.where(bs.traf.actwp.turnspd<0.0,bs.traf.tas,bs.traf.actwp.turnspd)
flybyturndist,turnrad = self.calcturn(turntas,bs.traf.bank,qdr,next_qdr,turnradnm)
flybyturndist,turnrad = self.calcturn(turntas,bs.traf.ap.bankdef,qdr,next_qdr,turnradnm)

# Turb dist iz ero for flyover, calculated distance for others
self.turndist = np.logical_or(flyby,flyturn)*flybyturndist
Expand Down
26 changes: 19 additions & 7 deletions bluesky/traffic/autopilot.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from bluesky.tools import geo
from bluesky.tools.misc import degto180
from bluesky.tools.position import txt2pos
from bluesky.tools.aero import ft, nm, vcasormach2tas, vcas2tas, tas2cas, cas2tas, g0
from bluesky.tools.aero import ft, nm, fpm, vcasormach2tas, vcas2tas, tas2cas, cas2tas, g0
from bluesky.core import Entity, timed_function
from .route import Route

Expand Down Expand Up @@ -47,6 +47,13 @@ def __init__(self):
self.orig = [] # Four letter code of origin airport
self.dest = [] # Four letter code of destination airport

# Default values
self.bankdef = np.array([]) # nominal bank angle, [radians]
self.vsdef = np.array([]) # [m/s]default vertical speed of autopilot

# Currently used roll/bank angle [rad]
self.turnphi = np.array([]) # [rad] bank angle setting of autopilot

# Route objects
self.route = []

Expand All @@ -65,6 +72,11 @@ def create(self, n=1):
# VNAV Variables
self.dist2vs[-n:] = -999.

# Traffic performance data
#(temporarily default values)
self.vsdef[-n:] = 1500. * fpm # default vertical speed of autopilot
self.bankdef[-n:] = np.radians(25.)

# Route objects
for ridx, acid in enumerate(bs.traf.id[-n:]):
self.route[ridx - n] = Route(acid)
Expand Down Expand Up @@ -99,12 +111,12 @@ def update_fms(self, qdr, dist):
turnspd = bs.traf.tas[i]

if bs.traf.actwp.turnrad[i] > 0.:
bs.traf.aphi[i] = atan(turnspd*turnspd/(bs.traf.actwp.turnrad[i]*nm*g0)) # [rad]
self.turnphi[i] = atan(turnspd*turnspd/(bs.traf.actwp.turnrad[i]*nm*g0)) # [rad]
else:
bs.traf.aphi[i] = 0.0 # [rad] or leave untouched???
self.turnphi[i] = 0.0 # [rad] or leave untouched???

else:
bs.traf.aphi[i] = 0.0 #[rad] or leave untouched???
self.turnphi[i] = 0.0 #[rad] or leave untouched???

# Get next wp, if there still is one
if not bs.traf.actwp.swlastwp[i]:
Expand Down Expand Up @@ -181,7 +193,7 @@ def update_fms(self, qdr, dist):

# 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],
bs.traf.actwp.calcturn(bs.traf.tas[i], self.bankdef[i],
qdr[i], local_next_qdr,turnrad) # update turn distance for VNAV

# Reduce turn dist for reduced turnspd
Expand Down Expand Up @@ -262,8 +274,8 @@ def update(self):
self.vnavvs = np.where(self.swvnavvs, bs.traf.actwp.vs, self.vnavvs)
#was: self.vnavvs = np.where(self.swvnavvs, self.steepness * bs.traf.gs, self.vnavvs)

# self.vs = np.where(self.swvnavvs, self.vnavvs, bs.traf.apvsdef * bs.traf.limvs_flag)
selvs = np.where(abs(bs.traf.selvs) > 0.1, bs.traf.selvs, bs.traf.apvsdef) # m/s
# self.vs = np.where(self.swvnavvs, self.vnavvs, self.vsdef * bs.traf.limvs_flag)
selvs = np.where(abs(bs.traf.selvs) > 0.1, bs.traf.selvs, self.vsdef) # m/s
self.vs = np.where(self.swvnavvs, self.vnavvs, selvs)
self.alt = np.where(self.swvnavvs, bs.traf.actwp.nextaltco, bs.traf.selalt)

Expand Down
2 changes: 1 addition & 1 deletion bluesky/traffic/performance/bada/perfbada.py
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,7 @@ def update(self, dt):
# flight phase
self.phase, self.bank = phases(bs.traf.alt, bs.traf.gs, delalt,
bs.traf.cas, self.vmto, self.vmic, self.vmap, self.vmcr, self.vmld,
bs.traf.bank, bs.traf.bphase, bs.traf.swhdgsel, swbada)
bs.traf.ap.bankdef, bs.traf.bphase, bs.traf.swhdgsel, swbada)

# AERODYNAMICS
# Lift
Expand Down
2 changes: 1 addition & 1 deletion bluesky/traffic/performance/legacy/perfbs.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ def update(self, dt):
# allocate aircraft to their flight phase
self.phase, self.bank = phases(bs.traf.alt, bs.traf.gs, delalt,
bs.traf.cas, self.vmto, self.vmic, self.vmap, self.vmcr, self.vmld,
bs.traf.bank, bs.traf.bphase, bs.traf.swhdgsel,swbada)
bs.traf.ap.bankdef, bs.traf.bphase, bs.traf.swhdgsel,swbada)

# AERODYNAMICS
# compute CL: CL = 2*m*g/(VTAS^2*rho*S)
Expand Down
2 changes: 1 addition & 1 deletion bluesky/traffic/route.py
Original file line number Diff line number Diff line change
Expand Up @@ -1325,7 +1325,7 @@ def findact(self,i):

# we only turn to the first waypoint if we can reach the required
# heading before reaching the waypoint
time_turn = max(0.01,bs.traf.tas[i])*radians(delhdg)/(g0*tan(bs.traf.bank[i]))
time_turn = max(0.01,bs.traf.tas[i])*radians(delhdg)/(g0*tan(bs.traf.ap.bankdef[i]))
time_straight= sqrt(dist2[iwpnear])*60.*nm/max(0.01,bs.traf.tas[i])

if time_turn > time_straight:
Expand Down
14 changes: 4 additions & 10 deletions bluesky/traffic/traffic.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,9 @@ def __init__(self):
self.M = np.array([]) # mach number
self.vs = np.array([]) # vertical speed [m/s]

# Acceleration
self.ax = np.array([]) # [m/s2] current longitudinal acceleration

# Atmosphere
self.p = np.array([]) # air pressure [N/m2]
self.rho = np.array([]) # air density [kg/m3]
Expand Down Expand Up @@ -138,10 +141,6 @@ def __init__(self):
self.groups = TrafficGroups()

# Traffic autopilot data
self.apvsdef = np.array([]) # [m/s]default vertical speed of autopilot
self.aphi = np.array([]) # [rad] bank angle setting of autopilot
self.ax = np.array([]) # [m/s2] current longitudinal acceleration
self.bank = np.array([]) # nominal bank angle, [radians]
self.swhdgsel = np.array([], dtype=np.bool) # determines whether aircraft is turning

# Traffic autothrottle settings
Expand Down Expand Up @@ -265,11 +264,6 @@ def cre(self, acid, actype="B744", aclat=52., aclon=4., achdg=None, acalt=0, acs
self.windnorth[-n:] = 0.0
self.windeast[-n:] = 0.0

# Traffic performance data
#(temporarily default values)
self.apvsdef[-n:] = 1500. * fpm # default vertical speed of autopilot
self.bank[-n:] = np.radians(25.)

# Traffic autopilot settings
self.selspd[-n:] = self.cas[-n:]
self.aptas[-n:] = self.tas[-n:]
Expand Down Expand Up @@ -441,7 +435,7 @@ def update_airspeed(self):
self.M = vtas2mach(self.tas, self.alt)

# Turning
turnrate = np.degrees(g0 * np.tan(np.where(self.aphi>self.eps,self.aphi,self.bank) \
turnrate = np.degrees(g0 * np.tan(np.where(self.ap.turnphi>self.eps,self.ap.turnphi,self.ap.bankdef) \
/ np.maximum(self.tas, self.eps)))
delhdg = (self.aporasas.hdg - self.hdg + 180) % 360 - 180 # [deg]
self.swhdgsel = np.abs(delhdg) > np.abs(bs.sim.simdt * turnrate)
Expand Down
2 changes: 1 addition & 1 deletion extra/CRmethods/Difgame.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ def resolve(dbconf, traf):
np.where(bankcontrol>0,traf.trk+90,traf.trk-90))%360

# Set bank angle for aircraft in conflict
traf.aphi=np.radians(np.where(dbconf.asasactive,np.abs(bankcontrol),25.))
traf.ap.aphi=np.radians(np.where(dbconf.asasactive,np.abs(bankcontrol),25.))

# Change autopilot desired altitude
traf.aalt=np.where(climbcontrol==0,traf.alt,\
Expand Down

0 comments on commit ceea561

Please sign in to comment.