Skip to content

Commit

Permalink
New conditional command ATDIST added, in addition to ATALT and ATSPD:
Browse files Browse the repository at this point in the history
Example usage:
acid ATDIST pos dist[nm]  cmd
KL204 ATDIST LOPIK 15 ECHO I'M ALMOST THERE 

ATDIST will trigger command when the distance to the waypoint/latlon is passed, either from within or from outside. Hence it only works once (like all conditional commands)
  • Loading branch information
ProfHoekstra committed Apr 28, 2021
1 parent 6e56b03 commit d173b13
Show file tree
Hide file tree
Showing 299 changed files with 37 additions and 85,967 deletions.
6 changes: 6 additions & 0 deletions bluesky/stack/basecmds.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,12 @@ def initbasecmds():
bs.traf.cond.ataltcmd,
"When a/c at given altitude , execute a command cmd",
],
"ATDIST": [
"acid ATDIST pos dist cmd ",
"acid,latlon,float,string",
bs.traf.cond.atdistcmd,
"When a/c passing this distance[nm] to position, execute the command cmd",
],
"ATSPD": [
"acid ATSPD spd cmd ",
"acid,spd,string",
Expand Down
40 changes: 30 additions & 10 deletions bluesky/traffic/conditional.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@
import numpy as np
import bluesky as bs
from bluesky import stack
from bluesky.tools.geo import qdrdist

# Enumerated condtion types
alttype, spdtype = 0, 1
alttype, spdtype, postype = 0, 1, 2


class Condition():
Expand All @@ -17,8 +18,9 @@ def __init__(self):

self.id = [] # Id of aircraft of condition
self.condtype = np.array([],dtype=int) # Condition type (0=alt,1=spd)
self.target = np.array([],dtype=float) # Target value
self.target = np.array([],dtype=float) # Target value (alt,speed,distance[nm])
self.lastdif = np.array([],dtype=float) # Difference during last update
self.posdata = [] # Data for postype: tuples lat[deg],lon[deg] of ref position
self.cmd = [] # Commands to be issued

def update(self):
Expand All @@ -34,16 +36,25 @@ def update(self):
self.condtype = np.delete(self.condtype, i)
self.target = np.delete(self.target, i)
self.lastdif = np.delete(self.lastdif, i)
del (self.cmd[i])
del self.posdata[i]
del self.cmd[i]

self.ncond = len(self.id)
if self.ncond==0:
return
acidxlst = np.array(bs.traf.id2idx(self.id))

# Check condition types
actdist = np.ones(self.ncond)*999e9 # Invalid number which never triggers anything is extremely large
for j in range(self.ncond):
if self.condtype[j] == postype:
qdr,dist = qdrdist(bs.traf.lat[acidxlst[j]],bs.traf.lon[acidxlst[j]],self.posdata[j][0],self.posdata[j][1])
actdist[j] = dist # [nm]

# Get relevant actual value using index list as index to numpy arrays
self.actual = (self.condtype == alttype) * bs.traf.alt[acidxlst] + \
(self.condtype == spdtype) * bs.traf.cas[acidxlst]
(self.condtype == spdtype) * bs.traf.cas[acidxlst] + \
(self.condtype == postype) * actdist

# Compare sign of actual difference with sign of last difference
actdif = self.target - self.actual
Expand All @@ -54,20 +65,24 @@ def update(self):
if idxtrue==None or len(idxtrue)==0:
return


# Execute commands found to have true condition
for i in idxtrue:
if i>=0:
stack.stack(self.cmd[i])
# debug
# stack.stack(" ECHO Conditional command issued: "+self.cmd[i])

# Delete executed commands to clean up arrays and lists
# from highest index to lowest for consistency
for i in idxtrue[::-1]:
if i>=0:
del(self.id[i])
del self.id[i]
self.condtype = np.delete(self.condtype,i)
self.target = np.delete(self.target,i)
self.lastdif = np.delete(self.lastdif,i)
del (self.cmd[i])
del self.posdata[i]
del self.cmd[i]

# Adjust number of conditions
self.ncond = len(self.id)
Expand All @@ -76,7 +91,6 @@ def update(self):
print ("self.ncond=",self.ncond)
print ("self.cmd=",self.cmd)
print ("traffic/conditional.py: self.delcondition: invalid condition array size")

return

def ataltcmd(self,acidx,targalt,cmdtxt):
Expand All @@ -86,11 +100,16 @@ def ataltcmd(self,acidx,targalt,cmdtxt):

def atspdcmd(self, acidx, targspd, cmdtxt):
actspd = bs.traf.tas[acidx]
self.addcondition(acidx,spdtype,targspd,actspd,cmdtxt)
self.addcondition(acidx, spdtype, targspd, actspd,cmdtxt)
return True

def atdistcmd(self, acidx, lat, lon, targdist, cmdtxt):
qdr, actdist = qdrdist(bs.traf.lat[acidx], bs.traf.lon[acidx], lat, lon)
self.addcondition(acidx, postype, targdist, actdist, cmdtxt, (lat,lon))
return True

def addcondition(self,acidx, icondtype, target, actual, cmdtxt):
#print ("addcondition:", acidx, icondtype, target, actual, cmdtxt)
def addcondition(self,acidx, icondtype, target, actual, cmdtxt,latlon=None):
#print ("addcondition:", acidx, icondtype, target, actual, cmdtxt, latlon)

# Add condition to arrays
self.id.append(bs.traf.id[acidx])
Expand All @@ -99,6 +118,7 @@ def addcondition(self,acidx, icondtype, target, actual, cmdtxt):
self.target = np.append(self.target,target)
self.lastdif = np.append(self.lastdif,target - actual)

self.posdata.append(latlon)
self.cmd.append(cmdtxt)

self.ncond = self.ncond+1
Expand Down
1 change: 1 addition & 0 deletions run-a-scenario-on-windows-from-commandline.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
python BlueSky.py --scenfile demo.scn
21 changes: 0 additions & 21 deletions scenario/0-COND-TEST.SCN

This file was deleted.

8 changes: 0 additions & 8 deletions scenario/0-LNAV-WIND.scn

This file was deleted.

7 changes: 0 additions & 7 deletions scenario/0-Takeoff.SCN

This file was deleted.

16 changes: 0 additions & 16 deletions scenario/0-VNAV-Fullflight.SCN

This file was deleted.

12 changes: 0 additions & 12 deletions scenario/0-VNAV-Landing.SCN

This file was deleted.

16 changes: 0 additions & 16 deletions scenario/0-VNAV-Testscenario.SCN

This file was deleted.

95 changes: 0 additions & 95 deletions scenario/0_BLUESKY_flight.scn

This file was deleted.

30 changes: 0 additions & 30 deletions scenario/ASAS/ASAS-01.scn

This file was deleted.

33 changes: 0 additions & 33 deletions scenario/ASAS/ASAS-02.scn

This file was deleted.

Loading

0 comments on commit d173b13

Please sign in to comment.