forked from KK4TEE/Control-Panel
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtelemachus_plugin.py
292 lines (221 loc) · 7.69 KB
/
telemachus_plugin.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
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
# This allows you to more conveniently write scripts that can interface with
# Telemachus
#url = 'http://127.0.0.1:8085/telemachus/datalink?alt='
#url = 'http://192.168.1.3:8085/telemachus/datalink?alt='
# This is the URL that Telemachus can be found at.
# Adjust it based on your firewall settings.
import json
import urllib2
import time
import os
import math
import config
import socket
url = config.url()
# set time out to 2 second.
socket.setdefaulttimeout(1)
# Telemachus Definitions
#The readings are for the active vessel unless otherwise noted
def read_angularvelocity():
fresh_json = json.load(urllib2.urlopen(url + 'v.angularVelocity'))
result = fresh_json["alt"]
return result
def read_asl():
fresh_json = json.load(urllib2.urlopen(url + 'v.altitude'))
result = fresh_json[u'alt']
return result
def read_apoapsis():
fresh_json = json.load(urllib2.urlopen(url + 'o.ApA'))
result = fresh_json["alt"]
return result
def read_body():
fresh_json = json.load(urllib2.urlopen(url + 'v.body'))
result = fresh_json["alt"]
return result
def read_eccentricity():
fresh_json = json.load(urllib2.urlopen(url + 'o.eccentricity'))
result = fresh_json["alt"]
return result
def read_facing(dimension):
if dimension in ['pitch']:
fresh_json = json.load(urllib2.urlopen(url + 'n.pitch'))
result = math.radians(int(fresh_json["alt"]))
elif dimension in ['yaw']:
fresh_json = json.load(urllib2.urlopen(url + 'n.heading'))
result = math.radians(int(fresh_json["alt"]))
elif dimension in ['roll']:
fresh_json = json.load(urllib2.urlopen(url + 'n.roll'))
result = math.radians(int(fresh_json["alt"]))
else:
result = -1
return result
def read_heading():
#Note: This returns facing:yaw, not your heading over land
#Basically what the navball shows, not 'true' heading
fresh_json = json.load(urllib2.urlopen(url + 'n.heading'))
result = math.radians(int(fresh_json["alt"]))
return result
def read_inclination():
fresh_json = json.load(urllib2.urlopen(url + 'o.inclination'))
result = math.radians(int(fresh_json["alt"]))
return result
def read_missiontime():
fresh_json = json.load(urllib2.urlopen(url + 'v.missionTime'))
result = fresh_json["alt"]
return result
def read_orbitalperiod():
fresh_json = json.load(urllib2.urlopen(url + 'o.period'))
result = fresh_json["alt"]
return result
def read_orbitalvelocity():
fresh_json = json.load(urllib2.urlopen(url + 'v.orbitalVelocity'))
result = fresh_json["alt"]
return result
def read_periapsis():
fresh_json = json.load(urllib2.urlopen(url + 'o.PeA'))
result = fresh_json["alt"]
return result
def read_resource(resource):
reformated_resource = url + 'r.resource' + '[' + resource + ']'
fresh_json = json.load(urllib2.urlopen(reformated_resource))
result = fresh_json["alt"]
return result
def read_resource_max(resource):
reformated_resource = url + 'r.resourceMax' + '[' + resource + ']'
fresh_json = json.load(urllib2.urlopen(reformated_resource))
result = fresh_json["alt"]
return result
def read_surfacespeed():
fresh_json = json.load(urllib2.urlopen(url + 'v.surfaceSpeed'))
result = fresh_json["alt"]
return result
def read_throttle():
fresh_json = json.load(urllib2.urlopen(url + 'f.throttle'))
result = fresh_json["alt"]
return result
def read_time_to_ap():
fresh_json = json.load(urllib2.urlopen(url + 'o.timeToAp'))
result = fresh_json["alt"]
return result
def read_time_to_pe():
fresh_json = json.load(urllib2.urlopen(url + 'o.timeToPe'))
result = fresh_json["alt"]
return result
def read_universaltime():
fresh_json = json.load(urllib2.urlopen(url + 't.universalTime'))
result = fresh_json["alt"]
return result
def read_verticalspeed():
fresh_json = json.load(urllib2.urlopen(url + 'v.verticalSpeed'))
result = fresh_json["alt"]
return result
# Output Definitions
def abort():
urllib2.urlopen(url + 'f.abort')
def fly_by_wire(var):
urllib2.urlopen(url + 'v.setFbW' + '[' + str(var) + ']')
def brake(var):
if var == 2:
fresh_json = json.load(urllib2.urlopen(url + 'v.brakeValue'))
if fresh_json["alt"] == "True":
return 1
elif fresh_json["alt"] == "False":
return 0
else:
return fresh_json["alt"]
elif var == 1:
urllib2.urlopen(url + 'f.brake' + '[' + 'true' + ']')
#print 'Setting Brake to on'
elif var == 0:
urllib2.urlopen(url + 'f.brake' + '[' + 'false' + ']')
#print 'Setting Brake to off'
else:
return (-1)
#print 'Brake value was set wrong'
def gear(var):
if var == 2:
fresh_json = json.load(urllib2.urlopen(url + 'v.gearValue'))
if fresh_json["alt"] == "True":
return 1
elif fresh_json["alt"] == "False":
return 0
else:
return fresh_json["alt"]
elif var == 1:
urllib2.urlopen(url + 'f.gear' + '[' + 'true' + ']')
#print 'Setting Gear to on'
elif var == 0:
urllib2.urlopen(url + 'f.gear' + '[' + 'false' + ']')
#print 'Setting Gear to off'
else:
return (-1)
#print 'Gear value was set wrong'
def light(var):
if var == 2:
fresh_json = json.load(urllib2.urlopen(url + 'v.lightValue'))
if fresh_json["alt"] == "True":
return 1
elif fresh_json["alt"] == "False":
return 0
else:
return fresh_json["alt"]
elif var == 1:
urllib2.urlopen(url + 'f.light' + '[' + 'true' + ']')
#print 'Setting Light to TRUE'
elif var == 0:
urllib2.urlopen(url + 'f.light' + '[' + 'false' + ']')
#print 'Setting Light to False'
else:
return (-1)
#print 'Light value was set wrong'
def rcs(var):
if var == 2:
fresh_json = json.load(urllib2.urlopen(url + 'v.rcsValue'))
if fresh_json["alt"] == "True":
return 1
elif fresh_json["alt"] == "False":
return 0
else:
return fresh_json["alt"]
elif var == 1:
urllib2.urlopen(url + 'f.rcs' + '[' + 'true' + ']')
#print 'Setting RCS to TRUE'
elif var == 0:
urllib2.urlopen(url + 'f.rcs' + '[' + 'false' + ']')
#print 'Setting RCS to False'
else:
return (-1)
#print 'RCS value was set wrong'
def sas(var):
if var == 2:
fresh_json = json.load(urllib2.urlopen(url + 'v.sasValue'))
if fresh_json["alt"] == "True":
return 1
elif fresh_json["alt"] == "False":
return 0
else:
return fresh_json["alt"]
elif var == 1:
urllib2.urlopen(url + 'f.sas' + '[' + 'true' + ']')
#print 'Setting SAS to TRUE'
elif var == 0:
urllib2.urlopen(url + 'f.sas' + '[' + 'false' + ']')
#print 'Setting SAS to False'
else:
return (-1)
#print 'SAS value was set wrong'
def stage():
urllib2.urlopen(url + 'f.stage')
def set_facing(dimension, angle):
#This is done by setting relative positions from 0 to 1, as a percent
#This is based on the three bars in the lower left corner, NOT the Navball
if dimension in ['pitch']:
urllib2.urlopen(url + 'v.setPitch' + '[' + str(angle) + ']')
elif dimension in ['yaw']:
urllib2.urlopen(url + 'v.setYaw' + '[' + str(angle) + ']')
elif dimension in ['roll']:
urllib2.urlopen(url + 'v.setRoll' + '[' + str(angle) + ']')
def set_throttle(throttle):
urllib2.urlopen(url + 'f.setThrottle' + '[' + str(throttle) + ']')
def toggle_ag(agn):
urllib2.urlopen(url + 'f.ag' + agn)