-
Notifications
You must be signed in to change notification settings - Fork 0
/
track.py
152 lines (104 loc) · 3.46 KB
/
track.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
#!/usr/bin/env python
import os, os.path
import random
import string
import time
import datetime
import pdb
import progaconstants
from referencetrack import Point3D
import cherrypy
class Track(object):
def __init__(self, track_id = ''):
self.track_id = track_id
self.path = []
self.pointer = None
self.startAt = 0;
self.started = False
self.declaredIntent = None
self.firstTime = True;
def addStep(self, timestamp, lat, lon, altitude, vx, vy, vz, heading, pitch, bank, onground, airspeed):
if len(self.path) == 0:
self.pointer = 0
p3d = Point3D(lon, lat, altitude)
xy = p3d.xyFromLonLat(lon, lat)
self.path.append({'timestamp':timestamp, 'float_timestamp':float(timestamp), 'x':xy[0], 'y':xy[1], 'z':altitude, 'lat':lat, 'lon':lon, 'h':altitude, 'vx':vx, 'vy':vy, 'vz':vz, 'heading':heading, 'pitch':pitch, 'bank':bank, 'onground':onground, 'airspeed':airspeed})
def getPath(self):
return self.path
#sets when the flight is supposed to start moving.
#startTime = 0 means it starts with no delay when the whole simulation starts
#startTime = t (seconds), makes this flight start t seconds after the start of the simulation
def setStart(self, startTime):
#self.pointer = startTime
self.startAt = startTime
def hasStarted(self):
return self.started
def startTrack(self):
self.started = True
def getCurrentState(self):
if self.pointer != None:
ret = self.path[self.pointer]
ret['flight_id'] = self.track_id
ret['started'] = self.started
return ret
return None
def getFutureState(self, lookahead=4):
if self.pointer == None:
return False
#se per la prima volta inviamo la futureposition, in realta inviamo quella attuale perche
#il flight simulator la utilizzera solo per inizializzare l aereo
if self.firstTime: return self.path[self.pointer]
futurePointer = self.pointer+1
found = False
difference = 0
while not found:
try:
p = self.path[self.pointer]['float_timestamp']
n = self.path[futurePointer]['float_timestamp']
except IndexError:
return False
if n-p >=lookahead:
found = True
else:
futurePointer += 1
futureStatus = self.path[futurePointer]
return futureStatus
def next(self, elapsedtime, increment=1):
#pdb.set_trace()
if (self.startAt >= 0):
elapsedtime = elapsedtime - self.startAt
found = False
if self.pointer == None:
self.pointer = 0
while not found:
#if len(self.path)-self.pointer <=1:
#pdb.set_trace()
#cherrypy.log("almost finished", context="DEBUG_FINISH")
try:
p = self.path[self.pointer]['float_timestamp']
n = self.path[self.pointer+1]['float_timestamp']
except IndexError:
#cherrypy.log("Flight %s Finished"%(self.track_id), context="DEBUG_FINISH")
return False
if elapsedtime <= p:
found = True
continue
if (p <= elapsedtime and n > elapsedtime):
found = True
else:
#pdb.set_trace()
self.pointer += 1
#cherrypy.log("pointer:%d"%(self.pointer),context="DEBUG_FINISH")
status = self.path[self.pointer]
#cherrypy.log("pointer:%d"%(self.pointer),context="DEBUG_FINISH")
#cherrypy.log("%s,%s,%f"%(self.track_id,status['timestamp'],elapsedtime),context="DEBUG_FINISH")
return status
def getTrackId(self):
return self.track_id
def getStartTime(self):
return self.startAt
#intent must be a ReferenceTrack object
def setDeclaredFlightIntent(self, intent):
self.declaredIntent = intent
def getDeclaredIntent(self):
return self.declaredIntent