Last active
October 24, 2021 09:43
-
-
Save cooliscool/5d54c6478da2b7fc107d07c993f10f8a to your computer and use it in GitHub Desktop.
To Run Flight Gear simulations
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import time | |
import requests as g | |
import csv | |
port= 8089 | |
hostname='localhost' | |
latDegToMet = 111000 | |
metToFeet = 3.28084 | |
radToDeg = 180/3.14159 | |
xScalingFactor = 1.0/latDegToMet*10 | |
yScalingFactor = 1.0/latDegToMet*10 | |
zScalingFactor = 1.0/metToFeet * 50 | |
timeScaling = 0.01 | |
# initial parameters | |
altitude_offset = 1300.0 # feet | |
lats_offset = 50.107981 # deg | |
longs_offset = 14.24542# deg | |
apiDict ={ | |
'latitude' : '/json/position/latitude-deg', | |
'longitude' : '/json/position/longitude-deg', | |
'altitude' : '/json/position/altitude-ft', | |
'phi' : '/json/orientation/heading-deg', | |
'theta' : '/json/orientation/pitch-deg', | |
'psi' : '/json/orientation/roll-deg' | |
}; | |
paramKeys = { | |
0 : 'latitude' , | |
1 : 'longitude', | |
2 : 'altitude', | |
5 : 'phi', | |
4 : 'theta', | |
3 : 'psi' | |
} | |
# headers = { | |
# 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8', | |
# 'X-Requested-With':'XMLHttpRequest' | |
# } | |
tBuffer = -1 | |
with open('routedb2.csv','rb' ) as csvfile: | |
dbreader = csv.reader(csvfile) | |
for p in dbreader: | |
val = [0.0,0.0 ,0.0 ,0.0 ,0.0 ,0.0 ] | |
# p = [ x y z phi theta psi t] | |
val[0] = float(p[0])*xScalingFactor + lats_offset | |
val[1] = float(p[1])*yScalingFactor + longs_offset | |
val[2] = -1*float(p[2])*zScalingFactor + altitude_offset | |
val[3] = float(p[3])*radToDeg | |
val[4] = float(p[4])*radToDeg | |
val[5] = float(p[5])*radToDeg | |
tNow = float(p[6]) | |
print str(val) | |
for i in range(6): | |
requrl = 'http://' + hostname + ':' + str(port) + apiDict[paramKeys[i]]; | |
payloadjson = { 'value' : str(val[i])} | |
# req = g.Request('POST', requrl, json=payloadjson) | |
g.post(requrl, json=payloadjson) | |
# reqtext = req.prepare() | |
# print reqtext.url + '\t' + reqtext.body | |
tSleep = tNow - tBuffer | |
time.sleep(tSleep*timeScaling) | |
# print tSleep | |
tBuffer = tNow |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment