Compare commits
10 Commits
5c33f652ef
...
8680a19302
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
8680a19302 | ||
|
|
dcfff34b36 | ||
|
|
537bc9474e | ||
|
|
8b6e14720c | ||
|
|
bce3ecbf08 | ||
|
|
9caf3ddf43 | ||
|
|
75c178f1e1 | ||
|
|
35365e0a01 | ||
|
|
6245ecddcc | ||
|
|
99fa386567 |
3
.vscode/settings.json
vendored
Normal file
3
.vscode/settings.json
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"cmake.sourceDirectory": "/Users/flyingtopher/Desktop/Code Citadel/School/2. Research/Fork Clone/XPlaneConnectCSP/C"
|
||||
}
|
||||
@@ -4,14 +4,14 @@ import xpc
|
||||
import math
|
||||
# import geopy
|
||||
from geographiclib.geodesic import Geodesic as geo
|
||||
|
||||
|
||||
from rich import print
|
||||
|
||||
# Initialize XPlaneConnect client
|
||||
class scaleFactor():
|
||||
SCALEYOKEPULL = 10
|
||||
SCALEYOKESTEER = 10
|
||||
SCALERUDDER = 10
|
||||
SCALELATITUDERUDDER = 0.001
|
||||
SCALETHROTTLE = 1000
|
||||
|
||||
###Define variables/parameters for aircraft class/category : Wisdom of Raju
|
||||
@@ -22,13 +22,15 @@ class AircraftLandingModel(pyactr.ACTRModel):
|
||||
self.inProgress = True
|
||||
self.printControlsFlag = printFlag
|
||||
self.targetLat = 39.895791
|
||||
self.targetLong = -104.696085
|
||||
self.targetLong = -104.696032
|
||||
"""
|
||||
Setting DREF variables and loading into drefs array
|
||||
"""
|
||||
airspeedDREF = "sim/cockpit2/gauges/indicators/airspeed_kts_pilot"
|
||||
rollDREF = "sim/cockpit2/gauges/indicators/roll_AHARS_deg_pilot"
|
||||
magneticHeadingDREF = "sim/cockpit2/gauges/indicators/heading_AHARS_deg_mag_pilot"
|
||||
latitudeDREF = "sim/flightmodel/position/latitude" ## Lat
|
||||
longitudeDREF = "sim/flightmodel/position/longitude" ##Long
|
||||
verticalSpeedDREF = "sim/flightmodel/position/vh_ind_fpm"
|
||||
altitudeAGLDREF = "sim/flightmodel/position/y_agl"
|
||||
pitchDREF = "sim/flightmodel/position/true_theta"
|
||||
@@ -41,6 +43,8 @@ class AircraftLandingModel(pyactr.ACTRModel):
|
||||
"airspeed" : airspeedDREF,
|
||||
"roll" : rollDREF,
|
||||
"heading" : magneticHeadingDREF,
|
||||
"latitude": latitudeDREF,
|
||||
"longitude": longitudeDREF,
|
||||
"vertical speed" : verticalSpeedDREF,
|
||||
"altitude": altitudeAGLDREF,
|
||||
"pitch" : pitchDREF,
|
||||
@@ -55,6 +59,8 @@ class AircraftLandingModel(pyactr.ACTRModel):
|
||||
airspeed = self.client.getDREF("sim/cockpit2/gauges/indicators/airspeed_kts_pilot")
|
||||
roll = self.client.getDREF("sim/cockpit2/gauges/indicators/roll_AHARS_deg_pilot")
|
||||
heading = self.client.getDREF("sim/cockpit2/gauges/indicators/heading_AHARS_deg_mag_pilot")
|
||||
latitude = self.client.getDREF("sim/flightmodel/position/latitude") ##Current Lat
|
||||
longitude = self.client.getDREF("sim/flightmodel/position/longitude") ##Current Long
|
||||
descent_rate = self.client.getDREF("sim/flightmodel/position/vh_ind_fpm")
|
||||
altitude = self.client.getDREF("sim/flightmodel/position/y_agl")
|
||||
pitch = self.client.getDREF("sim/flightmodel/position/true_theta")
|
||||
@@ -67,6 +73,8 @@ class AircraftLandingModel(pyactr.ACTRModel):
|
||||
self.airspeed = airspeed[0]
|
||||
self.roll = roll[0]
|
||||
self.heading = HARDCODE_HEADING
|
||||
self.latitude = latitude[0]
|
||||
self.longitude = longitude[0]
|
||||
self.descent_rate = descent_rate[0]
|
||||
self.altitude = altitude[0]
|
||||
self.pitch = pitch[0]
|
||||
@@ -79,6 +87,8 @@ class AircraftLandingModel(pyactr.ACTRModel):
|
||||
"airspeed" : self.airspeed,
|
||||
"roll" : self.roll,
|
||||
"heading" : self.heading,
|
||||
"latitude": self.latitude,
|
||||
"longitude": self.longitude,
|
||||
"vertical speed" : self.descent_rate,
|
||||
"altitude": self.altitude,
|
||||
"pitch" : self.pitch,
|
||||
@@ -93,10 +103,12 @@ class AircraftLandingModel(pyactr.ACTRModel):
|
||||
self.target_airspeed = 80
|
||||
self.target_roll = 0
|
||||
self.target_heading = self.heading #Track heading from initialization[DEPRECATED]
|
||||
self.target_Lat = 39.895791
|
||||
self.target_Long = -104.696032
|
||||
self.target_descent_rate = 500
|
||||
self.target_altitude = -998
|
||||
self.target_pitch = 20
|
||||
self.targets = [self.target_airspeed,self.target_roll,self.target_heading,self.target_descent_rate,self.target_altitude,self.target_pitch]
|
||||
self.target_pitch = 25
|
||||
self.targets = [self.target_airspeed,self.target_roll,self.target_heading,self.target_Lat,self.target_Long,self.target_descent_rate,self.target_altitude,self.target_pitch]
|
||||
|
||||
|
||||
#State Flags (Boolean) & Current State (Integer)
|
||||
@@ -122,6 +134,8 @@ class AircraftLandingModel(pyactr.ACTRModel):
|
||||
self.integral_airspeed = 0
|
||||
self.integral_roll = 0
|
||||
self.integral_heading = 0
|
||||
self.integral_Latitude = 0
|
||||
self.integral_Longitude = 0
|
||||
self.integral_descent_rate = 0
|
||||
|
||||
#Flare Specific Parameters
|
||||
@@ -159,7 +173,7 @@ class AircraftLandingModel(pyactr.ACTRModel):
|
||||
def get_bearing(self,lat1, lat2, long1, long2):
|
||||
brng = geo.WGS84.Inverse(lat1, long1, lat2, long2)['azi1']
|
||||
self.target_heading = brng
|
||||
print("TARGET BEARING: " + str(brng))
|
||||
# print("TARGET BEARING: " + str(brng))
|
||||
|
||||
def getAndLoadDREFS(self):
|
||||
results = self.client.getDREFs(self.sources.values())
|
||||
@@ -171,6 +185,7 @@ class AircraftLandingModel(pyactr.ACTRModel):
|
||||
lat = self.client.getDREF("sim/flightmodel/position/latitude") ##Current Lat
|
||||
long = self.client.getDREF("sim/flightmodel/position/longitude") ##Current Long
|
||||
self.get_bearing(lat[0],self.targetLat,long[0],self.targetLong)
|
||||
|
||||
|
||||
# print("getDrefs: " + str(results[1][0]))
|
||||
# print("current destination: " + str(self.destinations["airspeed"]))
|
||||
@@ -193,11 +208,36 @@ class AircraftLandingModel(pyactr.ACTRModel):
|
||||
# print("*Parameter,Target,Current,Yoke Steer: " + "Roll, " + str(self.target_roll) + "," + str(self.destinations["roll"])+ "," + str(yokeSteer))
|
||||
# print("*Parameter,Target,Current,Rudder: " + "Heading, " + str(self.target_heading) + "," + str(self.heading)+ "," + str(rudder))
|
||||
# print("*Parameter,Target,Current,Throttle: " + "Descent Rate, " + str(self.target_descent_rate) + "," + str(self.descent_rate)+ "," + str(throttle))
|
||||
parameter = ["Airspeed","Roll","Heading","Descent Rate","Altitude","Flare: Pitch", "Brakes: Wheel Speed", "Brakes: Wheel Weight"]
|
||||
target = [str(round(self.target_airspeed)),str(round(self.target_roll)),str(round(self.target_heading,3)),str(round(self.target_descent_rate,3)),str(round(self.altitude,3)),str(round(self.target_pitch,3)),0, 0]
|
||||
current = [str(round(self.dictionaryAccess(self.destinations,"pitch"),3)),str(round(self.dictionaryAccess(self.destinations,"roll"),3)),str(round(self.dictionaryAccess(self.destinations,"heading"),3)),str(round(self.dictionaryAccess(self.destinations,"vertical speed"),3)),
|
||||
str(round(self.dictionaryAccess(self.destinations,"altitude"),3)),str(round(self.dictionaryAccess(self.destinations,"pitch"),3)),str(round(self.dictionaryAccess(self.destinations,"wheelSpeed"),3)),str(round(self.dictionaryAccess(self.destinations,"wheelWeight"),3))]
|
||||
controlVal = [str(round(yokePull,3)),str(round(yokeSteer,3)),str(round(rudder,3)),str(round(throttle,3)),str(round(self.altitude,3)),str(self.dictionaryAccess(self.phaseFlags,"flare")),str(round(self.dictionaryAccess(self.destinations,"brakes"),3)),str(round(self.dictionaryAccess(self.destinations,"brakes"),3))]
|
||||
parameter = ["Airspeed","Roll","Heading","Longitude","Descent Rate","Altitude","Flare: Pitch", "Brakes: Wheel Speed", "Brakes: Wheel Weight"]
|
||||
target = [str(round(self.target_airspeed)),
|
||||
str(round(self.target_roll)),
|
||||
str(round(self.target_heading,3)),
|
||||
str(round(self.target_Long,6)),
|
||||
str(round(self.target_descent_rate,3)),
|
||||
str(round(self.altitude,3)),
|
||||
str(round(self.target_pitch,3)),
|
||||
0,
|
||||
0]
|
||||
|
||||
current = [str(round(self.dictionaryAccess(self.destinations,"airspeed"),3)),
|
||||
str(round(self.dictionaryAccess(self.destinations,"roll"),3)),
|
||||
str(round(self.dictionaryAccess(self.destinations,"heading"),3)),
|
||||
str(round(self.dictionaryAccess(self.destinations,"longitude"),6)),
|
||||
|
||||
str(round(self.dictionaryAccess(self.destinations,"vertical speed"),3)),
|
||||
str(round(self.dictionaryAccess(self.destinations,"altitude"),3)),
|
||||
str(round(self.dictionaryAccess(self.destinations,"pitch"),3)),
|
||||
str(round(self.dictionaryAccess(self.destinations,"wheelSpeed"),3)),
|
||||
str(round(self.dictionaryAccess(self.destinations,"wheelWeight"),3))]
|
||||
controlVal = [str(round(yokePull,3)),
|
||||
str(round(yokeSteer,3)),
|
||||
str(round(rudder,3)),
|
||||
str(round(rudder,3)),
|
||||
str(round(throttle,3)),
|
||||
str(round(self.altitude,3)),
|
||||
str(self.dictionaryAccess(self.phaseFlags,"flare")),
|
||||
str(round(self.dictionaryAccess(self.destinations,"brakes"),3)),
|
||||
str(round(self.dictionaryAccess(self.destinations,"brakes"),3))]
|
||||
|
||||
header_row = "{:<20} {:<20} {:<20} {:>10}"
|
||||
headers = "Parameter Target Current Control_Value".split()
|
||||
@@ -270,7 +310,7 @@ class AircraftLandingModel(pyactr.ACTRModel):
|
||||
scaleFactor.SCALEYOKEPULL)
|
||||
|
||||
if(self.dictionaryAccess(self.phaseFlags,"flare") == False):
|
||||
self.target_pitch = 10
|
||||
self.target_pitch = 20
|
||||
yoke_pull, self.integral_airspeed = self.proportionalIntegralControl(1,self.dictionaryAccess(self.destinations,"pitch"),
|
||||
self.target_pitch,
|
||||
self.integral_pitch,
|
||||
@@ -281,7 +321,21 @@ class AircraftLandingModel(pyactr.ACTRModel):
|
||||
# scaleFactor.SCALEYOKEPULL)
|
||||
|
||||
yoke_steer, self.integral_roll = self.proportionalIntegralControl(0,self.dictionaryAccess(self.destinations,"roll"), self.target_roll, self.integral_roll,scaleFactor.SCALEYOKESTEER)
|
||||
rudder, self.integral_heading = self.proportionalIntegralControl(0,self.dictionaryAccess(self.destinations,"heading"), self.target_heading, self.integral_heading,scaleFactor.SCALERUDDER)
|
||||
|
||||
"""
|
||||
RUDDER CONTROLS
|
||||
"""
|
||||
#ORIGINAL
|
||||
# rudder, self.integral_heading = self.proportionalIntegralControl(0,self.dictionaryAccess(self.destinations,"heading"), self.target_heading, self.integral_heading,scaleFactor.SCALERUDDER)
|
||||
#lATITUDE/LONGITUDE
|
||||
if(self.destinations,"longitude" == self.target_Long):
|
||||
self.integral_Longitude = 0
|
||||
|
||||
rudder, self.integral_Longitude = self.proportionalIntegralControl(0,self.dictionaryAccess(self.destinations,"longitude"), self.target_Long, self.integral_Longitude,scaleFactor.SCALELATITUDERUDDER)
|
||||
|
||||
|
||||
|
||||
|
||||
throttle, self.integral_descent_rate = self.proportionalIntegralControl(0,self.dictionaryAccess(self.destinations,"vertical speed"), self.target_descent_rate, self.integral_descent_rate,scaleFactor.SCALETHROTTLE)
|
||||
### 1. For Calculated Yoke and Throttle Values
|
||||
#Invert Throttle Control & divide by 5 to scale
|
||||
@@ -323,13 +377,14 @@ class AircraftLandingModel(pyactr.ACTRModel):
|
||||
|
||||
##Method 2: Same Control Statements with Change in Parameter to decided pitch from Airspeed ---> Local Pitch Relative to the Horizon
|
||||
|
||||
|
||||
rudder = rudder * -1
|
||||
additive = rudder*1.0
|
||||
|
||||
#Switch Target for Pitch to Local Pitch Axis (ex. +10 Degrees nose up)
|
||||
if(self.printControlsFlag):
|
||||
self.printControls(1,0,yoke_pull,yoke_steer,rudder,throttle) #PRINT CONTROLS
|
||||
self.printControls(1,0,yoke_pull,yoke_steer+additive,rudder,throttle) #PRINT CONTROLS
|
||||
# Send all controls simultaneously to X-Plane
|
||||
self.send_controls_to_xplane(yoke_pull, yoke_steer, rudder, throttle)
|
||||
|
||||
self.send_controls_to_xplane(yoke_pull, yoke_steer+additive, rudder, throttle)
|
||||
|
||||
def send_controls_to_xplane(self, yoke_pull, yoke_steer, rudder, throttle):
|
||||
"""
|
||||
@@ -383,7 +438,7 @@ class AircraftLandingModel(pyactr.ACTRModel):
|
||||
and self.dictionaryAccess(self.destinations,"brakes") == 1):
|
||||
self.inProgress = False
|
||||
|
||||
def simulationStatus(self):
|
||||
def getSimulationStatus(self):
|
||||
return self.inProgress
|
||||
|
||||
|
||||
|
||||
Binary file not shown.
Binary file not shown.
61
Python3/src/experiments/weather_files/turbulence.csv
Normal file
61
Python3/src/experiments/weather_files/turbulence.csv
Normal file
@@ -0,0 +1,61 @@
|
||||
Turbulence Experiments,Starting Altitude (AGL),Wind Layer Altitude,Wind Direction,Wind Speed,Turbulence,Thermal Rate,Thermal Percent,Thermal Altitude,Cognitive Delay
|
||||
0,2900,0,179,0,1,500,0.9,15000,0.05
|
||||
1,2900,0,179,0,1,500,0.9,15000,0.15
|
||||
2,2900,0,179,0,1,500,0.9,15000,0.25
|
||||
3,2900,0,179,0,1,500,0.9,15000,0.35
|
||||
4,2900,0,179,0,1,500,0.9,15000,0.45
|
||||
5,2900,0,179,0,1,500,0.9,15000,0.55
|
||||
6,2900,0,179,0,2,500,0.9,15000,0.05
|
||||
7,2900,0,179,0,2,500,0.9,15000,0.15
|
||||
8,2900,0,179,0,2,500,0.9,15000,0.25
|
||||
9,2900,0,179,0,2,500,0.9,15000,0.35
|
||||
10,2900,0,179,0,2,500,0.9,15000,0.45
|
||||
11,2900,0,179,0,2,500,0.9,15000,0.55
|
||||
12,2900,0,179,0,3,500,0.9,15000,0.05
|
||||
13,2900,0,179,0,3,500,0.9,15000,0.15
|
||||
14,2900,0,179,0,3,500,0.9,15000,0.25
|
||||
15,2900,0,179,0,3,500,0.9,15000,0.35
|
||||
16,2900,0,179,0,3,500,0.9,15000,0.45
|
||||
17,2900,0,179,0,3,500,0.9,15000,0.55
|
||||
18,2900,0,179,0,4,500,0.9,15000,0.05
|
||||
19,2900,0,179,0,4,500,0.9,15000,0.15
|
||||
20,2900,0,179,0,4,500,0.9,15000,0.25
|
||||
21,2900,0,179,0,4,500,0.9,15000,0.35
|
||||
22,2900,0,179,0,4,500,0.9,15000,0.45
|
||||
23,2900,0,179,0,4,500,0.9,15000,0.55
|
||||
24,2900,0,179,0,5,500,0.9,15000,0.05
|
||||
25,2900,0,179,0,5,500,0.9,15000,0.15
|
||||
26,2900,0,179,0,5,500,0.9,15000,0.25
|
||||
27,2900,0,179,0,5,500,0.9,15000,0.35
|
||||
28,2900,0,179,0,5,500,0.9,15000,0.45
|
||||
29,2900,0,179,0,5,500,0.9,15000,0.55
|
||||
30,2900,0,179,0,6,500,0.9,15000,0.05
|
||||
31,2900,0,179,0,6,500,0.9,15000,0.15
|
||||
32,2900,0,179,0,6,500,0.9,15000,0.25
|
||||
33,2900,0,179,0,6,500,0.9,15000,0.35
|
||||
34,2900,0,179,0,6,500,0.9,15000,0.45
|
||||
35,2900,0,179,0,6,500,0.9,15000,0.55
|
||||
36,2900,0,179,0,7,500,0.9,15000,0.05
|
||||
37,2900,0,179,0,7,500,0.9,15000,0.15
|
||||
38,2900,0,179,0,7,500,0.9,15000,0.25
|
||||
39,2900,0,179,0,7,500,0.9,15000,0.35
|
||||
40,2900,0,179,0,7,500,0.9,15000,0.45
|
||||
41,2900,0,179,0,7,500,0.9,15000,0.55
|
||||
42,2900,0,179,0,8,500,0.9,15000,0.05
|
||||
43,2900,0,179,0,8,500,0.9,15000,0.15
|
||||
44,2900,0,179,0,8,500,0.9,15000,0.25
|
||||
45,2900,0,179,0,8,500,0.9,15000,0.35
|
||||
46,2900,0,179,0,8,500,0.9,15000,0.45
|
||||
47,2900,0,179,0,8,500,0.9,15000,0.55
|
||||
48,2900,0,179,0,9,500,0.9,15000,0.05
|
||||
49,2900,0,179,0,9,500,0.9,15000,0.15
|
||||
50,2900,0,179,0,9,500,0.9,15000,0.25
|
||||
51,2900,0,179,0,9,500,0.9,15000,0.35
|
||||
52,2900,0,179,0,9,500,0.9,15000,0.45
|
||||
53,2900,0,179,0,9,500,0.9,15000,0.55
|
||||
54,2900,0,179,0,10,500,0.9,15000,0.05
|
||||
55,2900,0,179,0,10,500,0.9,15000,0.15
|
||||
56,2900,0,179,0,10,500,0.9,15000,0.25
|
||||
57,2900,0,179,0,10,500,0.9,15000,0.35
|
||||
58,2900,0,179,0,10,500,0.9,15000,0.45
|
||||
59,2900,0,179,0,10,500,0.9,15000,0.55
|
||||
|
28
Python3/src/experiments/weather_files/weather.csv
Normal file
28
Python3/src/experiments/weather_files/weather.csv
Normal file
@@ -0,0 +1,28 @@
|
||||
Wind Experiments,Starting Altitude (AGL),Wind Layer Altitude,Wind Direction,Wind Speed,Direction Offset(Setup Only),Main Heading
|
||||
1,2000,0,139,5,-40,179
|
||||
2,2000,0,149,5,-30,
|
||||
3,2000,0,159,5,-20,
|
||||
4,2000,0,169,5,-10,
|
||||
5,2000,0,179,5,0,
|
||||
6,2000,0,189,5,10,
|
||||
7,2000,0,199,5,20,
|
||||
8,2000,0,209,5,30,
|
||||
9,2000,0,219,5,40,
|
||||
10,2000,0,139,10,-40,
|
||||
11,2000,0,149,10,-30,
|
||||
12,2000,0,159,10,-20,
|
||||
13,2000,0,169,10,-10,
|
||||
14,2000,0,179,10,0,
|
||||
15,2000,0,189,10,10,
|
||||
16,2000,0,199,10,20,
|
||||
17,2000,0,209,10,30,
|
||||
18,2000,0,219,10,40,
|
||||
19,2000,0,139,15,-40,
|
||||
20,2000,0,149,15,-30,
|
||||
21,2000,0,159,15,-20,
|
||||
22,2000,0,169,15,-10,
|
||||
23,2000,0,179,15,0,
|
||||
24,2000,0,189,15,10,
|
||||
25,2000,0,199,15,20,
|
||||
26,2000,0,209,15,30,
|
||||
27,2000,0,219,15,40,
|
||||
|
@@ -1,5 +0,0 @@
|
||||
Wind,2,3,4
|
||||
Altitudes,3,4,5
|
||||
Turtles,4,5,6
|
||||
Ducks,5,6,7
|
||||
Penguins,6,7,8
|
||||
|
@@ -7,9 +7,17 @@ import xpc
|
||||
from cognitiveModel import AircraftLandingModel
|
||||
import shutil
|
||||
import csv
|
||||
from enum import Enum
|
||||
from playsound import playsound
|
||||
import threading as threading
|
||||
|
||||
|
||||
|
||||
|
||||
class messageType(Enum):
|
||||
REGULAR = 1
|
||||
ERROR = 2
|
||||
|
||||
def eulerToQuat(psiInput,thetaInput,phiInput):
|
||||
|
||||
psi = float(pi / 360 * psiInput)
|
||||
@@ -24,33 +32,30 @@ def eulerToQuat(psiInput,thetaInput,phiInput):
|
||||
quat = [q0/e,q1/e,q2/e,q3/e]
|
||||
return quat
|
||||
|
||||
|
||||
def loadFile(index):
|
||||
filename = "Python3/src/experiments/weather_files/weather_" + str(index) + ".csv"
|
||||
def loadFile():
|
||||
filename = "Python3/src/experiments/weather_files/weather.csv"
|
||||
filename = "Python3/src/experiments/weather_files/turbulence.csv"
|
||||
with open(filename,"r") as f:
|
||||
matrix = list(csv.reader(f,delimiter=','))
|
||||
print(matrix)
|
||||
return matrix
|
||||
|
||||
|
||||
|
||||
def selectWeather(matrix,experimentNumber):
|
||||
return matrix[experimentNumber]
|
||||
|
||||
|
||||
|
||||
def experimentSetUp(client,altitudeInput,newExperiment):
|
||||
loadFile(2)
|
||||
def experimentSetUp(client,currentConditions,newExperiment,file):
|
||||
# input("Check The Loaded File Now")
|
||||
print("Entered: EXPERIMENTSETUP")
|
||||
if(newExperiment):
|
||||
#Location:
|
||||
groundLevel = 5434
|
||||
offset = altitudeInput
|
||||
offset = float(currentConditions[1])
|
||||
altitudeFEET = groundLevel + offset
|
||||
altitudeMETERS = altitudeFEET/3.281
|
||||
altitude = altitudeMETERS
|
||||
print(str(altitude))
|
||||
location1 = [20, -998, 39.96239, -104.69713, altitude, -998, -998, -998, -998]
|
||||
location1 = [20, -998, 39.96239, -104.696032, altitude, -998, -998, -998, -998]
|
||||
# testLocation = [20, -998, 27.20579, -80.08621, altitude, -998, -998, -998, -998] # 27.20579°N/80.08621°W
|
||||
data = [
|
||||
location1\
|
||||
@@ -58,6 +63,7 @@ def experimentSetUp(client,altitudeInput,newExperiment):
|
||||
client.sendDATA(data)
|
||||
|
||||
|
||||
|
||||
print("Zero velocities")
|
||||
x = "sim/flightmodel/position/local_vx"
|
||||
y = "sim/flightmodel/position/local_vy"
|
||||
@@ -104,19 +110,31 @@ def experimentSetUp(client,altitudeInput,newExperiment):
|
||||
# result = client.getDREF(windLayer)
|
||||
# print("Wind:" + str(result))
|
||||
print("Setting Wind Layers")
|
||||
client.sendDREF(windLayer,6000)
|
||||
client.sendDREF(windLayer2,15000)
|
||||
client.sendDREF(windLayer3,15000)
|
||||
client.sendDREF(windLayer,float(currentConditions[2]))
|
||||
# client.sendDREF(windLayer2,15000)
|
||||
# client.sendDREF(windLayer3,15000)
|
||||
print("Setting Wind Direction and Speed")
|
||||
client.sendDREF(windDirection,170)
|
||||
client.sendDREF(windDirection,float(currentConditions[3]))
|
||||
print("Set 1")
|
||||
|
||||
client.sendDREF(windSpeed,40)
|
||||
client.sendDREF(windSpeed,float(currentConditions[4]))
|
||||
print("Set 2")
|
||||
|
||||
|
||||
# client.sendDREF(turbulence,turbulencePercentage)
|
||||
print("Setting Turbulence Level")
|
||||
turbulenceDREF = "sim/weather/turbulence[0]"
|
||||
client.sendDREF(turbulenceDREF,float(currentConditions[5]))
|
||||
|
||||
print("Setting Thermals")
|
||||
thermalRateDREF = "sim/weather/thermal_rate_ms"
|
||||
thermalPercentDREF = "sim/weather/thermal_percent"
|
||||
thermalAltitudeDREF = "sim/weather/thermal_altitude_msl_m"
|
||||
client.sendDREF(thermalRateDREF,float(currentConditions[6]))
|
||||
client.sendDREF(thermalPercentDREF,float(currentConditions[7]))
|
||||
client.sendDREF(thermalAltitudeDREF,float(currentConditions[8]))
|
||||
|
||||
|
||||
|
||||
# client.sendDREF(turbulence,turbulencePercentage)
|
||||
# preset = "sim/weather/region/weather_preset"
|
||||
# value = 8
|
||||
# client.sendDREF(preset,value)
|
||||
@@ -125,11 +143,17 @@ def experimentSetUp(client,altitudeInput,newExperiment):
|
||||
client.pauseSim(False)
|
||||
print("Setting initial velocity")
|
||||
zInit = "sim/flightmodel/position/local_vz"
|
||||
client.sendDREF(zInit, 80)
|
||||
client.sendDREF(zInit, 50)
|
||||
|
||||
|
||||
|
||||
print("Setting Fuel to Experiment Level")
|
||||
# fuel = "sim/aircraft/weight/acf_m_fuel_tot"
|
||||
fuel = "sim/flightmodel/weight/m_fuel"
|
||||
fuelLevels = [20,20]
|
||||
client.sendDREF(fuel, fuelLevels)
|
||||
print("setup complete")
|
||||
|
||||
|
||||
|
||||
"""
|
||||
Set orientation and Position
|
||||
1 - Time
|
||||
@@ -139,121 +163,228 @@ def experimentSetUp(client,altitudeInput,newExperiment):
|
||||
18 - Angle of Attack
|
||||
20 - Latitude and Longitude
|
||||
"""
|
||||
kias = -998
|
||||
keas = -998
|
||||
ktas = -998
|
||||
ktgs = -998
|
||||
mph = -998
|
||||
mphas = 80
|
||||
mphgs = 80
|
||||
message = "Conditions are set as\n" \
|
||||
"Experiment #: {} \n"\
|
||||
"Starting Altitude: {} \n" \
|
||||
"Layer Altitude: {} \n" \
|
||||
"Wind Direction: {} \n" \
|
||||
"Wind Speed: {} \n" \
|
||||
"Turbulence: {} \n" \
|
||||
"Thermal Rate: {} \n" \
|
||||
"Thermal Percent: {}\n" \
|
||||
"Thermal Altitude: {}\n" \
|
||||
"Cognitive Delay: {}\n".format(currentConditions[0],currentConditions[1],currentConditions[2],currentConditions[3],currentConditions[4],
|
||||
currentConditions[5],currentConditions[6],currentConditions[7],currentConditions[8],currentConditions[9])
|
||||
specialPrint(message,False,messageType.REGULAR)
|
||||
# file.write("[[[" + message + "]]]")
|
||||
|
||||
print("Setting orientation for test")
|
||||
# client.sendDREF("sim/operation/override/override_planepath",1)
|
||||
# client.pauseSim(True)
|
||||
|
||||
# client.sendDREF("sim/flightmodel/position/local_y",2000)
|
||||
# client.sendDREFs(["sim/flightmodel/position/P","sim/flightmodel/position/Q","sim/flightmodel/position/R"],[0,0,0])
|
||||
# client.sendDREF("sim/flightmodel/position/q",[0.3, 0, 0, 0.6])
|
||||
|
||||
# data = [\
|
||||
# [3, -998, -998, -998, -998, -998, -998, mphas, mphgs],\
|
||||
# [16, 0, 0, 0, -998, -998, -998, -998, -998],\
|
||||
# [17, 0, 0, 0, -998, -998, -998, -998, -998],\
|
||||
# [18, -998, -998, -998, -998, -998, -998, -998, -998],\
|
||||
# [19, -998, -998, -998, -998, -998, -998, -998, -998],\
|
||||
# testLocation\
|
||||
# ]
|
||||
# client.sendDATA(data)
|
||||
# client.sendDREF("sim/operation/override/override_planepath",0)
|
||||
|
||||
# Set control surfaces and throttle of the player aircraft using sendCTRL
|
||||
# print("Setting controls")
|
||||
# ctrl = [0.0, 0.0, 0.0, 0.0]
|
||||
# cogModel.client.sendCTRL(ctrl)
|
||||
# print("past setting controls")
|
||||
|
||||
else:
|
||||
print("Experiment currently in progress, not resetting position and environmental conditions")
|
||||
|
||||
def runExperiment(title,printFlag,experimentStart):
|
||||
print("Model Test: Xplane setting up connection")
|
||||
print("Setting up simulation")
|
||||
def printLoop(status,data):
|
||||
while(status):
|
||||
print(str(data))
|
||||
if(not status):
|
||||
print("Thread Should Finish Now")
|
||||
|
||||
|
||||
def log(cogModel, file,timeElapsed):
|
||||
airspeedDREF = "sim/cockpit2/gauges/indicators/airspeed_kts_pilot"
|
||||
rollDREF = "sim/cockpit2/gauges/indicators/roll_AHARS_deg_pilot"
|
||||
magneticHeadingDREF = "sim/cockpit2/gauges/indicators/heading_AHARS_deg_mag_pilot"
|
||||
latitudeDREF = "sim/flightmodel/position/latitude" ## Lat
|
||||
longitudeDREF = "sim/flightmodel/position/longitude" ##Long
|
||||
verticalSpeedDREF = "sim/flightmodel/position/vh_ind_fpm"
|
||||
altitudeAGLDREF = "sim/flightmodel/position/y_agl"
|
||||
pitchDREF = "sim/flightmodel/position/true_theta"
|
||||
brakeDREF = "sim/cockpit2/controls/parking_brake_ratio"
|
||||
wheelSpeedDREF = "sim/flightmodel2/gear/tire_rotation_speed_rad_sec"
|
||||
wheelWeightDREF = "sim/flightmodel/parts/tire_vrt_def_veh"
|
||||
sources = [latitudeDREF, longitudeDREF,altitudeAGLDREF, pitchDREF,rollDREF]
|
||||
data = cogModel.client.getDREFs(sources)
|
||||
mainString = []
|
||||
# data = client.readDATA()
|
||||
mainString.append(str(timeElapsed))
|
||||
mainString.append(",")
|
||||
for d in data:
|
||||
mainString.append(str(d[0]))
|
||||
mainString.append(",")
|
||||
|
||||
mainString[len(mainString)-1] = "\n"
|
||||
finalString = "".join(mainString)
|
||||
file.write(finalString)
|
||||
file.flush()
|
||||
# file.write(str(timeElapsed) + "," + str(data[0][0]) + "," + str(data[1][0]) + "," + str(data[2][0]) + "," + str(data[3][0]) +"\n")
|
||||
|
||||
|
||||
def runExperiment(title,currentConditions,allowPrinting,isNewExperiment,experimentCount,file):
|
||||
specialPrint("New Experiment\nSetting Up the Simulation",False,messageType.REGULAR)
|
||||
startTime = 0
|
||||
endTime = 0
|
||||
difference = endTime - startTime
|
||||
experimentLive = True
|
||||
timeElapsed = endTime - startTime
|
||||
experimentInProgress = True
|
||||
timeoutLimit = 10
|
||||
newExperiment = experimentStart
|
||||
while(difference < timeoutLimit and experimentLive):
|
||||
print("Time Elapsed: -----> " + str(difference))
|
||||
newExperiment = isNewExperiment
|
||||
while(timeElapsed <= timeoutLimit and experimentInProgress):
|
||||
try:
|
||||
with xpc.XPlaneConnect() as client:
|
||||
# Verify connection
|
||||
"""
|
||||
Test Connection
|
||||
"""
|
||||
client.getDREF("sim/test/test_float")
|
||||
cogModel = AircraftLandingModel(client,printFlag)
|
||||
experimentSetUp(cogModel.client,2000,newExperiment)
|
||||
|
||||
"""
|
||||
Setup Model
|
||||
"""
|
||||
cogModel = AircraftLandingModel(client,allowPrinting)
|
||||
"""
|
||||
Set Simulator Conditions
|
||||
"""
|
||||
experimentSetUp(cogModel.client,currentConditions,newExperiment,file)
|
||||
|
||||
currentDelay = float(currentConditions[9])
|
||||
"""
|
||||
"""
|
||||
cogModel.client.pauseSim(False)
|
||||
count = 0
|
||||
innercount = 0
|
||||
clockStart = time.time()
|
||||
retry = 0
|
||||
newExperiment = False
|
||||
while(cogModel.simulationStatus()):
|
||||
clockStart = time.time() #START TIMER
|
||||
#Run Model
|
||||
cogModel.update_aircraft_state()
|
||||
cogModel.update_controls_simultaneously()
|
||||
client.pauseSim(False) #Unpause Simulator
|
||||
clockEnd = time.time() # STOP TIMER
|
||||
count+=1
|
||||
# print("Clock Time: " + str(clockEnd - clockStart)) ## LOG TIME TAKEN
|
||||
sleep(0.05) # LET Simulator Run 50 Milliseconds
|
||||
startTime = time.time()
|
||||
experimentLive = cogModel.simulationStatus()
|
||||
"""
|
||||
SETUP DATA THREAD
|
||||
"""
|
||||
# thread = threading.Thread(target=printLoop(cogModel.getSimulationStatus(),cogModel.destinations.get("airspeed")))
|
||||
# thread.start()
|
||||
"""
|
||||
Single Experiment Loop
|
||||
"""
|
||||
startTime = time.time()
|
||||
endTime = time.time()
|
||||
elapsed = endTime - startTime
|
||||
while(experimentInProgress):
|
||||
elapsed = endTime - startTime
|
||||
if(elapsed > currentDelay):
|
||||
cogModel.update_aircraft_state()
|
||||
cogModel.update_controls_simultaneously()
|
||||
client.pauseSim(False) #Unpause Simulator
|
||||
startTime = time.time()
|
||||
# sleep(2) # Let Simulator Run 50 Milliseconds
|
||||
log(cogModel,file,elapsed)
|
||||
experimentInProgress = cogModel.getSimulationStatus()
|
||||
endTime = time.time()
|
||||
except:
|
||||
print("except detected")
|
||||
endTime = time.time()
|
||||
print("Start Time:" + str(startTime))
|
||||
print("End Time:" + str(endTime))
|
||||
difference = endTime - startTime
|
||||
timeElapsed = endTime - startTime
|
||||
message = "Except detected\nStart Time: {a}\nEnd Time: {b}\n" \
|
||||
"Time Elapsed: -----> {c} ".format(a= startTime, b=endTime,c=timeElapsed)
|
||||
specialPrint(message,False,messageType.ERROR)
|
||||
continue
|
||||
if(difference >= timeoutLimit):
|
||||
print("Timeout[" + str(difference) +"]:"+"Error, please run test again")
|
||||
|
||||
"""
|
||||
Parse End Condition: Succesful Run or Timeout-Induced End
|
||||
"""
|
||||
if(timeElapsed >= timeoutLimit):
|
||||
print("Timeout[" + str(timeElapsed) +"]:"+"Error, please run test again")
|
||||
else:
|
||||
print("Model has finished running")
|
||||
|
||||
#Copy data.txt to the cloudddddd using python magic and accurate filepaths
|
||||
now = datetime.datetime
|
||||
shutil.copy("/Users/flyingtopher/X-Plane 11/Data.txt", "/Users/flyingtopher/Desktop/Test Destination/" + title + "_" + str(now.now()) + "_" + ".txt")
|
||||
# print("CLEAN UP: Data File Copied and saved")
|
||||
# os.remove("/Users/flyingtopher/X-Plane 11/Data.txt")
|
||||
print("CLEAN UP: Data File Deleted and Reset")
|
||||
# exit = input("Press 'y' or any key to continue, press 'n' to exit...")
|
||||
exit = False
|
||||
if(exit == "n"):
|
||||
exit = True
|
||||
else:
|
||||
exit = False
|
||||
return exit
|
||||
##Reset the sim with the keyboard shortcut (wrapper around model that waits for reconnection)
|
||||
|
||||
def ex():
|
||||
##Store Experiment Battery
|
||||
##Different paramters on every run of the model
|
||||
## Nested loops:
|
||||
##wind conditions, pilot conditions
|
||||
# title = input("Please Enter Experiment Set Title, leave blank for trial runs")
|
||||
title = 'test'
|
||||
count = 0
|
||||
while(count<7):
|
||||
# input("Press Enter to Start Experiment #" + str(count) + ": ")
|
||||
print("Data File Reset")
|
||||
f = open("/Users/flyingtopher/X-Plane 11/Data.txt", 'w')
|
||||
exit = runExperiment(title,False,True)
|
||||
if(exit):
|
||||
break
|
||||
count+=1
|
||||
|
||||
print("Experiment Battery Complete")
|
||||
"""
|
||||
Ask Experimenter if they would like to exit experiment battery early
|
||||
"""
|
||||
# exitDecision = input("Press 'y' or any key to continue, press 'n' to exit...")
|
||||
exitDecision = "yes"
|
||||
|
||||
if(exitDecision == "n"):
|
||||
exitExperimentLoop = True
|
||||
else:
|
||||
exitExperimentLoop = False
|
||||
return exitExperimentLoop
|
||||
|
||||
|
||||
def say(msg = "Finish", voice = "Victoria"):
|
||||
os.system(f'say -v {voice} {"Hello"}')
|
||||
|
||||
# def playSound():
|
||||
# # wave_obj = sa.WaveObject.from_wave_file("Python3/src/experiments/terrain-terrain,-pull-up!-pull-up!-made-with-Voicemod.wav")
|
||||
# # wave_obj.play()
|
||||
# # # play_obj.wait_done()
|
||||
# # song = AudioSegment.from_wav("Python3/src/experiments/terrain-terrain,-pull-up!-pull-up!-made-with-Voicemod.wav")
|
||||
# # play(song)
|
||||
# # playsound('Python3/src/experiments/terrain-terrain,-pull-up!-pull-up!-made-with-Voicemod.wav')
|
||||
|
||||
|
||||
|
||||
def setUp():
|
||||
file = open("/Users/flyingtopher/X-Plane 11/Data.txt", 'w')
|
||||
file.close()
|
||||
specialPrint("Data Collection File Ready",False,messageType.REGULAR)
|
||||
|
||||
def cleanUp(count,title):
|
||||
now = datetime.datetime
|
||||
# shutil.copy("/Users/flyingtopher/X-Plane 11/Data.txt", "/Users/flyingtopher/Desktop/Test Destination/" + title + "_"+ count + "_" + str(now.now()) + "_" + ".txt")
|
||||
shutil.copy("/Users/flyingtopher/X-Plane 11/Data.txt", "/Users/flyingtopher/Desktop/Test Destination/Current Experiment/" + str(count)+ "_" + title + ".txt")
|
||||
print("CLEAN UP: Data File Deleted and Reset")
|
||||
specialPrint("Data File Ready",False,messageType.REGULAR)
|
||||
|
||||
def specialPrint(text, inputRequested,type):
|
||||
if(type == messageType.REGULAR):
|
||||
print("-" * 81)
|
||||
print('====> ', end='')
|
||||
print(text, end= " <====\n")
|
||||
print("-" * 81 + "\n")
|
||||
if(inputRequested):
|
||||
inputReceived = input()
|
||||
return inputReceived
|
||||
if(type == messageType.ERROR):
|
||||
print("*" * 81)
|
||||
print(text)
|
||||
print("*" * 81 + "\n")
|
||||
|
||||
|
||||
|
||||
def ex():
|
||||
# playSound()
|
||||
"""
|
||||
One Time experimental setup
|
||||
"""
|
||||
prefix = specialPrint("Please Enter Experiment Set Title, leave blank for trial runs", True, messageType.REGULAR)
|
||||
experimentConditionMatrix = loadFile()
|
||||
startAt = input("Start At Experiment # 1 to " + str(len(experimentConditionMatrix)-1))
|
||||
|
||||
title = str(prefix + "--" + experimentConditionMatrix[0][0])
|
||||
specialPrint("Title is: " + title, False, messageType.REGULAR)
|
||||
allowPrinting = False
|
||||
isNewExperiment = True
|
||||
experimentCount = int(startAt)
|
||||
header = "Cycle Time,Latitude, Longitude, Altitude, Pitch, Roll\n"
|
||||
file2 = open("/Users/flyingtopher/Desktop/Test Destination/Current Experiment/CurrentExperimentList.txt", 'w')
|
||||
file2.write(str(title) + "\n")
|
||||
startTime = time.time()
|
||||
"""
|
||||
Experiment Loop
|
||||
"""
|
||||
while(experimentCount<len(experimentConditionMatrix)):
|
||||
setUp()
|
||||
file = open("/Users/flyingtopher/X-Plane 11/Data.txt", 'a')
|
||||
file.write(str(header)) #Write Header to File$
|
||||
currentConditions = experimentConditionMatrix[experimentCount]
|
||||
file2.write(str(experimentCount) +" // " + str(currentConditions))
|
||||
file2.flush()
|
||||
exitExperimentLoop = runExperiment(title,currentConditions,allowPrinting,isNewExperiment,experimentCount,file)
|
||||
if(exitExperimentLoop):
|
||||
break
|
||||
cleanUp(experimentCount,title)
|
||||
experimentCount+=1
|
||||
endTime = time.time()
|
||||
elapsed = endTime-startTime
|
||||
file2.write(" " + str(elapsed) + "\n")
|
||||
# pag.alert(text="Experiment " + str(experimentCount+1) + " complete. Starting new Experiment", title="EXPERIMENT STATUS UPDATE")
|
||||
"""
|
||||
End of Experiments
|
||||
"""
|
||||
now = datetime.datetime
|
||||
##Adding something to copy all the battery files into a safe folder so they don't get overwritten
|
||||
shutil.copytree("/Users/flyingtopher/Desktop/Test Destination/Current Experiment", ("/Users/flyingtopher/Desktop/Test Destination/Data Storage/" + title + " " + str(now.now())), dirs_exist_ok=True)
|
||||
specialPrint("Experiment Battery Complete", False,messageType.REGULAR)
|
||||
|
||||
if __name__ == "__main__":
|
||||
ex()
|
||||
@@ -6,6 +6,8 @@ class XPlaneConnect(object):
|
||||
socket = None
|
||||
|
||||
# Basic Functions
|
||||
# def __init__(self, xpHost='localhost', xpPort=49009, port=0, timeout=100):
|
||||
|
||||
def __init__(self, xpHost='localhost', xpPort=49009, port=0, timeout=100):
|
||||
"""Sets up a new connection to an X-Plane Connect plugin running in X-Plane.
|
||||
|
||||
|
||||
Reference in New Issue
Block a user