-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathGNSS.py
218 lines (189 loc) · 6.29 KB
/
GNSS.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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
# import folium as folium
try:
from _global import *
except:
from ._global import *
from PySide6.QtWidgets import QApplication, QWidget, QBoxLayout, QVBoxLayout
from PySide6.QtWebEngineWidgets import QWebEngineView
class GNSS:
'''
Get latitude longitude altitude and magnetometer from ground station.
Get latitude longitude and altutude from cansat.
'''
def __init__(self, lat_g, lng_g, lat_c, lng_c, alt_g, alt_c, x, y, z):
self.lat_g = math.radians(float(lat_g))
self.lat_c = math.radians(float(lat_c))
self.lng_g = math.radians(float(lng_g))
self.lng_c = math.radians(float(lng_c))
self.dlon = self.lng_c - self.lng_g
self.dlat = self.lat_c - self.lat_g
self.alt_g = float(alt_g)
self.alt_c = float(alt_c)
self.alt = self.alt_c - self.alt_g
self.x = float(x)
self.y = float(y)
self.z = float(z)
def arc(self):
'''
Return arc of the 2 given points.
'''
a = (math.sin(self.dlat / 2) ** 2)
a += (math.cos(self.lat_g) * math.cos(self.lat_c)
* ((math.sin(self.dlon / 2)) ** 2))
x = math.sqrt(a)
y = math.sqrt(1 - a)
c = 2 * math.atan2(x, y)
return c
def ground_distance(self):
'''
Return ground distance in meters.
'''
R0 = 6371000
d = R0 * self.arc()
return d
def line_of_sight(self):
'''
Return line of sight distance in meters.
'''
R0 = 6371000
R = R0 + self.alt_g
baselength = 2 * R * math.cos((math.pi - self.arc()) / 2)
heightlength = self.alt
los = baselength ** 2 + heightlength ** 2 - 2 * baselength * \
heightlength * math.cos((math.pi + self.arc()) / 2)
los = math.fabs(los)
los = math.sqrt(los)
return los
def azimuth(self):
'''
Return azimuth in degrees for locating cansat.
'''
a = math.sin(self.dlon) * math.cos(self.lat_c)
b = math.cos(self.lat_g) * math.sin(self.lat_c) - \
math.sin(self.lat_g) * math.cos(self.lat_c) * math.cos(self.dlon)
theta = math.atan2(a, b)
theta = math.degrees(theta)
return theta
def heading(self):
'''
Return heading in degree for locating cansat.
'''
ht = self.azimuth() - self.z
ht = ht % 360
return ht
def elevation(self):
'''
Return elevation in degree for locating cansat.
'''
elev = math.atan2(self.alt, self.ground_distance())
elev = math.degrees(elev)
elev = elev - self.x
elev = elev % 360
return elev
def roll(self):
ty = self.y
ty = ty % 360
return ty
def pythagorus(self):
'''
Find distance of the remaining pythagorus.
'''
pyx = math.atan2((self.lng_c - self.lng_g), (self.lat_c-self.lat_g))
return pyx * 180/math.pi
class FoliumMap:
def __init__(self, map, ground, tiles='OpenStreetMap') -> None:
"""
get a QWebEngineView and start position
[optional] Tiles
- “OpenStreetMap”
- “Mapbox Bright” (Limited levels of zoom for free tiles)
- “Mapbox Control Room” (Limited levels of zoom for free tiles)
- “Stamen” (Terrain, Toner, and Watercolor)
- “Cloudmade” (Must pass API key)
- “Mapbox” (Must pass API key)
- “CartoDB” (positron and dark_matter)
"""
self.ground = ground
self.coord = []
self.map = map
self.alt = []
self.tiles = tiles
self._map = folium.Map(
location=self.ground,
tiles=self.tiles,
zoom_start=16,
min_zoom=10
)
def plot(self, index, coord: tuple, alt):
'''
Plot each position in number of position, tuple, and altitude.
'''
self.coord.append(coord)
folium.Marker(
loaction=coord,
popup=f'[{index}] {alt}:{coord[0]}:{coord[1]}',
icon=folium.Icon()).add_to(self._map)
folium.PolyLine(self.coord, color="red", weight=2.5,
opacity=1).add_to(self._map)
data = io.BytesIO()
self._map.save(data, close_file=False)
self.map.setHtml(data.getvalue().decode())
class myapp(QWidget):
'''
Test
'''
def __init__(self) -> None:
super().__init__()
self.setWindowTitle("map")
self.window_width, self.window_height = 1600, 1200
self.setMinimumSize(self.window_width, self.window_height)
layout = QVBoxLayout()
self.setLayout(layout)
with open("D:\Code\Space_Us-paper\GCS\Data_log\Comtestall_Oct-05-2021_17_57.csv", 'r') as file:
datas = file.readlines()
C = []
SP1 = []
SP2 = []
for data in datas:
data = data.replace('\n', '')
data = data.split(',')
if len(data) > 3:
if data[2] == 'C':
C.append(data)
elif data[2] == 'SP1':
SP1.append(data)
elif data[2] == 'SP2':
SP2.append(data)
C_coord = []
S1_coord = []
S2_coord = []
for i in C:
if float(i[3]) == 0 and float(i[4]) == 0:
pass
else:
C_coord.append((float(i[3]), float(i[4])))
for i in SP2:
if float(i[3]) == 0 and float(i[4]) == 0:
pass
else:
S2_coord.append((float(i[3]), float(i[4])))
self._map = folium.Map(
location=C_coord[0],
tiles='OpenStreetMap',
zoom_start=16
# min_zoom=10
)
folium.PolyLine(C_coord, color="red", weight=2.5,
opacity=1).add_to(self._map)
folium.PolyLine(S2_coord, color="green", weight=2.5,
opacity=1).add_to(self._map)
data = io.BytesIO()
self._map.save(data, close_file=False)
webView = QWebEngineView()
webView.setHtml(data.getvalue().decode())
layout.addWidget(webView)
if __name__ == "__main__":
app = QApplication(sys.argv)
ma = myapp()
ma.show()
sys.exit(app.exec_())