middle of major changes for setting location
This commit is contained in:
@@ -288,54 +288,7 @@ class AircraftLandingModel(pyactr.ACTRModel):
|
|||||||
|
|
||||||
self.client.sendCTRL([yoke_pull, yoke_steer, rudder, throttle, -998, -998]) # Control inputs: [yoke_pull, yoke_steer, rudder, throttle]
|
self.client.sendCTRL([yoke_pull, yoke_steer, rudder, throttle, -998, -998]) # Control inputs: [yoke_pull, yoke_steer, rudder, throttle]
|
||||||
|
|
||||||
|
def conditionChecks(self):
|
||||||
|
|
||||||
# Update the model's DM based on X-Plane data
|
|
||||||
def update_aircraft_state(self):
|
|
||||||
"""
|
|
||||||
Slower Method
|
|
||||||
"""
|
|
||||||
# print("In aircraft state")
|
|
||||||
# print("Entered Update Aircraft State")
|
|
||||||
# Retrieve current data from X-Plane
|
|
||||||
# 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")
|
|
||||||
# descent_rate = self.client.getDREF("sim/flightmodel/position/vh_ind_fpm")
|
|
||||||
# altitudeAGL = self.client.getDREF("sim/flightmodel/position/y_agl")
|
|
||||||
|
|
||||||
# pitch = self.client.getDREF("sim/flightmodel/position/true_theta")
|
|
||||||
|
|
||||||
# brake = self.client.getDREF("sim/cockpit2/controls/parking_brake_ratio")
|
|
||||||
# wheelS = self.client.getDREF("sim/flightmodel2/gear/tire_rotation_speed_rad_sec")
|
|
||||||
# wheelW = self.client.getDREF("sim/flightmodel/parts/tire_vrt_def_veh")
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# self.airspeed = airspeed[0]
|
|
||||||
# self.roll = roll[0]
|
|
||||||
# self.heading = heading[0]
|
|
||||||
# self.descent_rate = descent_rate[0]
|
|
||||||
# self.altitude = altitudeAGL[0]
|
|
||||||
# self.pitch = pitch[0]
|
|
||||||
# self.wheelSpeed = wheelS[0]
|
|
||||||
# self.wheelWeight = wheelW[0]
|
|
||||||
# self.brakes = brake[0]
|
|
||||||
|
|
||||||
# #Phase Change Indicator
|
|
||||||
# wheelWeight = self.client.getDREF("sim/flightmodel/parts/tire_vrt_def_veh") #Strut deflection, Weight on the wheels
|
|
||||||
# wheelRate = self.client.getDREF("sim/flightmodel2/gear/tire_rotation_speed_rad_sec") #Wheel Rotation Rate
|
|
||||||
|
|
||||||
"""
|
|
||||||
Faster Method
|
|
||||||
"""
|
|
||||||
self.getAndLoadDREFS()
|
|
||||||
|
|
||||||
if(self.altitude <= 20):
|
|
||||||
self.flare = True
|
|
||||||
self.Ki = 0.01 ## Increase Control Authority to compensate for decreasing airspeed
|
|
||||||
print("Altitude < 500; Flare Set True")
|
|
||||||
|
|
||||||
if(self.wheelWeight > 0.01 and self.wheelSpeed > 1):
|
if(self.wheelWeight > 0.01 and self.wheelSpeed > 1):
|
||||||
#Two Parameters to Confirm Touchdown and wheel contact
|
#Two Parameters to Confirm Touchdown and wheel contact
|
||||||
# "sim/flightmodel/parts/tire_vrt_def_veh" #Gear Strut Deflection (Weight on wheels)
|
# "sim/flightmodel/parts/tire_vrt_def_veh" #Gear Strut Deflection (Weight on wheels)
|
||||||
@@ -343,46 +296,23 @@ class AircraftLandingModel(pyactr.ACTRModel):
|
|||||||
self.rollOut = True
|
self.rollOut = True
|
||||||
print("Hit the brakes")
|
print("Hit the brakes")
|
||||||
|
|
||||||
|
if(self.altitude <= 20):
|
||||||
|
self.flare = True
|
||||||
|
self.Ki = 0.01 ## Increase Control Authority to compensate for decreasing airspeed
|
||||||
|
print("Altitude < 500; Flare Set True")
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# Update the model's DM based on X-Plane data
|
||||||
|
def update_aircraft_state(self):
|
||||||
|
"""
|
||||||
|
Faster Method
|
||||||
|
"""
|
||||||
|
self.getAndLoadDREFS()
|
||||||
|
self.conditionChecks()
|
||||||
|
|
||||||
# def logData(self):
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# def rules(self):
|
# def logData(self):
|
||||||
# """
|
|
||||||
# Define the rules for descent control using proportional-integral control for all controls at once.
|
|
||||||
# """
|
|
||||||
# return [
|
|
||||||
# # Rule to adjust all controls simultaneously based on PI control for each parameter
|
|
||||||
# pyactr.Production(
|
|
||||||
# condition=pyactr.Condition("airspeed", "airspeed") &
|
|
||||||
# pyactr.Condition("roll", "roll") &
|
|
||||||
# pyactr.Condition("heading", "heading") &
|
|
||||||
# pyactr.Condition("descent_rate", "descent_rate") &
|
|
||||||
# pyactr.Condition("target_airspeed", "target_airspeed") &
|
|
||||||
# pyactr.Condition("target_roll", "target_roll") &
|
|
||||||
# pyactr.Condition("target_heading", "target_heading") &
|
|
||||||
# pyactr.Condition("target_descent_rate", "target_descent_rate"),
|
|
||||||
# action=self.update_controls_simultaneously(),
|
|
||||||
# ),
|
|
||||||
# ]
|
|
||||||
|
|
||||||
|
|
||||||
# # Function to get the current dataref value for a given parameter
|
|
||||||
# def getDref(parameter_name):
|
|
||||||
# # Depending on the parameter name, you would query X-Plane datarefs
|
|
||||||
# if parameter_name == "Airspeed":
|
|
||||||
# # Get airspeed dataref
|
|
||||||
# return client.getData([DATAREF_AIRSPEED])
|
|
||||||
# elif parameter_name == "Roll":
|
|
||||||
# # Get roll angle dataref
|
|
||||||
# return client.getData([DATAREF_ROLL])
|
|
||||||
# elif parameter_name == "Hdg":
|
|
||||||
# # Get heading dataref
|
|
||||||
# return client.getData([DATAREF_HEADING])
|
|
||||||
# elif parameter_name == "DescentRate":
|
|
||||||
# # Get descent rate dataref
|
|
||||||
# return client.getData([DATAREF_DESCENT_RATE])
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ Qualitative
|
|||||||
Disturbances & Disturbance Tests (Demonstrate the limitations of the model)
|
Disturbances & Disturbance Tests (Demonstrate the limitations of the model)
|
||||||
--Wind (& Wobbliness)
|
--Wind (& Wobbliness)
|
||||||
Currently, lack of authority (and some missing control inputs) to stay back on track
|
Currently, lack of authority (and some missing control inputs) to stay back on track
|
||||||
|
-- Wind, Gusting Wind, Turbulence(Rough Air),
|
||||||
|
|
||||||
##Model
|
##Model
|
||||||
-- What are ways in which it is realistic/Not realistic
|
-- What are ways in which it is realistic/Not realistic
|
||||||
|
|||||||
@@ -2,8 +2,9 @@ import time
|
|||||||
from time import sleep
|
from time import sleep
|
||||||
import xpc
|
import xpc
|
||||||
from cognitiveModel import AircraftLandingModel
|
from cognitiveModel import AircraftLandingModel
|
||||||
|
import shutil
|
||||||
|
|
||||||
def ex():
|
def runExperiment():
|
||||||
|
|
||||||
print("Model Test: Xplane setting up connection")
|
print("Model Test: Xplane setting up connection")
|
||||||
print("Setting up simulation")
|
print("Setting up simulation")
|
||||||
@@ -64,38 +65,68 @@ def ex():
|
|||||||
# ]
|
# ]
|
||||||
# client.sendDATA(data)
|
# client.sendDATA(data)
|
||||||
|
|
||||||
|
groundLevel = 5434
|
||||||
|
offset = 4000
|
||||||
|
altitudeFEET = groundLevel + offset
|
||||||
|
altitudeMETERS = altitudeFEET/3.281
|
||||||
|
altitude = altitudeMETERS
|
||||||
"""
|
"""
|
||||||
Set orientation and Position
|
Set orientation and Position
|
||||||
|
1 - Time
|
||||||
|
3- Speeds: [3, V-indicated, 3, 2, 2, -998, VindMPH, V trueMPHas, vtrue MPHgs],\
|
||||||
16 - Angular Velocities
|
16 - Angular Velocities
|
||||||
17 - PitchRoll and Headings
|
17 - PitchRoll and Headings: [17, Pitch, Roll, Heading True, -998, -998, -998, -998, -998],\
|
||||||
18 - Angle of Attack
|
18 - Angle of Attack
|
||||||
20 - Latitude and Longitude
|
20 - Latitude and Longitude
|
||||||
"""
|
"""
|
||||||
print("Setting orientation for test")
|
location1 = [20, groundLevel + 3000, 39.96239, -104.69713, -998, -998, -998, -998, -998]
|
||||||
data = [\
|
testLocation = [20, -998, 27.20579, -80.08621, altitude, -998, -998, -998, -998] # 27.20579°N/80.08621°W
|
||||||
[16, -998, -998, -998, -998, -998, -998, -998, -998],
|
|
||||||
[17, -998, -998, -998, -998, -998, -998, -998, -998],\
|
|
||||||
[18, -998, -998, -998, -998, -998, -998, -998, -998],\
|
|
||||||
[19, -998, -998, -998, -998, -998, -998, -998, -998],\
|
|
||||||
[20, -998, -998, -998, -998, -998, -998, -998, -998]\
|
|
||||||
]
|
|
||||||
client.sendDATA(data)
|
|
||||||
|
|
||||||
|
kias = -998
|
||||||
|
keas = -998
|
||||||
|
ktas = -998
|
||||||
|
ktgs = -998
|
||||||
|
mph = -998
|
||||||
|
mphas = 80
|
||||||
|
mphgs = 80
|
||||||
|
|
||||||
|
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)
|
||||||
|
|
||||||
|
client.pauseSim(False)
|
||||||
|
|
||||||
|
# 39.96239°N/104.69713°W
|
||||||
|
runModel = True
|
||||||
# Set control surfaces and throttle of the player aircraft using sendCTRL
|
# Set control surfaces and throttle of the player aircraft using sendCTRL
|
||||||
print("Setting controls")
|
print("Setting controls")
|
||||||
ctrl = [0.0, 0.0, 0.0, 0.0]
|
ctrl = [0.0, 0.0, 0.0, 0.0]
|
||||||
client.sendCTRL(ctrl)
|
client.sendCTRL(ctrl)
|
||||||
# Pitch, Roll, Rudder, Throttle
|
# Pitch, Roll, Rudder, Throttle
|
||||||
# Pause the sim
|
# Pause the sim
|
||||||
client.pauseSim(False)
|
# client.pauseSim(False)
|
||||||
count = 0
|
count = 0
|
||||||
innercount = 0
|
innercount = 0
|
||||||
clockStart = time.time()
|
clockStart = time.time()
|
||||||
#Doing stuff In between Test SECOND INCREMENTS
|
#Doing stuff In between Test SECOND INCREMENTS
|
||||||
while(count < 1000000):
|
while(count < 1000000 and runModel):
|
||||||
clockStart = time.time() #START TIMER
|
clockStart = time.time() #START TIMER
|
||||||
client.pauseSim(True) # Pause Simulator
|
# client.pauseSim(True) # Pause Simulator
|
||||||
|
|
||||||
#Run Model
|
#Run Model
|
||||||
cogModel.update_aircraft_state()
|
cogModel.update_aircraft_state()
|
||||||
@@ -107,11 +138,21 @@ def ex():
|
|||||||
print("Clock Time: " + str(clockEnd - clockStart)) ## LOG TIME TAKEN
|
print("Clock Time: " + str(clockEnd - clockStart)) ## LOG TIME TAKEN
|
||||||
sleep(0.05) # LET Simulator Run 50 Milliseconds
|
sleep(0.05) # LET Simulator Run 50 Milliseconds
|
||||||
|
|
||||||
#
|
|
||||||
print("Model has finished running")
|
print("Model has finished running")
|
||||||
#Copy data.txt to the cloudddddd using python magic and accurate filepaths
|
#Copy data.txt to the cloudddddd using python magic and accurate filepaths
|
||||||
|
shutil.copy("/Users/flyingtopher/X-Plane 11/Data.txt", "/Users/flyingtopher/Desktop/Test Destination")
|
||||||
|
|
||||||
input("Press any key to exit...")
|
input("Press any key to exit...")
|
||||||
|
## Copy Data.txt to the repository file for analysis
|
||||||
|
|
||||||
|
##Reset the sim with the keyboard shortcut (wrapper around model that waits for reconnection)
|
||||||
|
|
||||||
|
def ex():
|
||||||
|
count = 0
|
||||||
|
while(count<2):
|
||||||
|
runExperiment()
|
||||||
|
count+=1
|
||||||
|
print("Experiment Battery Complete")
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
ex()
|
ex()
|
||||||
@@ -310,7 +310,9 @@ class XPlaneConnect(object):
|
|||||||
if len(value) > 255:
|
if len(value) > 255:
|
||||||
raise ValueError("value must have less than 256 items.")
|
raise ValueError("value must have less than 256 items.")
|
||||||
fmt = "<B{0:d}sB{1:d}f".format(len(dref), len(value))
|
fmt = "<B{0:d}sB{1:d}f".format(len(dref), len(value))
|
||||||
buffer += struct.pack(fmt.encode(), len(dref), dref.encode(), len(value), value)
|
# buffer += struct.pack(fmt.encode(), len(dref), dref.encode(), len(value), value)
|
||||||
|
buffer += struct.pack(fmt.encode(), len(dref), dref.encode(), 2, *value)
|
||||||
|
|
||||||
else:
|
else:
|
||||||
fmt = "<B{0:d}sBf".format(len(dref))
|
fmt = "<B{0:d}sBf".format(len(dref))
|
||||||
buffer += struct.pack(fmt.encode(), len(dref), dref.encode(), 1, value)
|
buffer += struct.pack(fmt.encode(), len(dref), dref.encode(), 1, value)
|
||||||
|
|||||||
Reference in New Issue
Block a user