diff --git a/Python3/src/cognitiveModel.py b/Python3/src/cognitiveModel.py index fcdc79f..98fbd2c 100644 --- a/Python3/src/cognitiveModel.py +++ b/Python3/src/cognitiveModel.py @@ -284,105 +284,35 @@ class AircraftLandingModel(pyactr.ACTRModel): #Hit the Brakes brakedref = "sim/cockpit2/controls/parking_brake_ratio" brake = 1 - self.client.sendDREF(brakedref,brake) + self.client.sendDREF(brakedref,brake) self.client.sendCTRL([yoke_pull, yoke_steer, rudder, throttle, -998, -998]) # Control inputs: [yoke_pull, yoke_steer, rudder, throttle] - - - # 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() + def conditionChecks(self): + if(self.wheelWeight > 0.01 and self.wheelSpeed > 1): + #Two Parameters to Confirm Touchdown and wheel contact + # "sim/flightmodel/parts/tire_vrt_def_veh" #Gear Strut Deflection (Weight on wheels) + # "sim/flightmodel2/gear/tire_rotation_rate_rad_sec" #Tire Rotation Rate + self.rollOut = True + 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") + + - if(self.wheelWeight > 0.01 and self.wheelSpeed > 1): - #Two Parameters to Confirm Touchdown and wheel contact - # "sim/flightmodel/parts/tire_vrt_def_veh" #Gear Strut Deflection (Weight on wheels) - # "sim/flightmodel2/gear/tire_rotation_rate_rad_sec" #Tire Rotation Rate - self.rollOut = True - print("Hit the brakes") + # 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): - # """ - # 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]) - - diff --git a/Python3/src/notes.txt b/Python3/src/notes.txt index 1b8acc1..c6637a2 100644 --- a/Python3/src/notes.txt +++ b/Python3/src/notes.txt @@ -19,6 +19,7 @@ Qualitative Disturbances & Disturbance Tests (Demonstrate the limitations of the model) --Wind (& Wobbliness) Currently, lack of authority (and some missing control inputs) to stay back on track + -- Wind, Gusting Wind, Turbulence(Rough Air), ##Model -- What are ways in which it is realistic/Not realistic diff --git a/Python3/src/testPlatform.py b/Python3/src/testPlatform.py index 706eb00..23339df 100644 --- a/Python3/src/testPlatform.py +++ b/Python3/src/testPlatform.py @@ -2,8 +2,9 @@ import time from time import sleep import xpc from cognitiveModel import AircraftLandingModel +import shutil -def ex(): +def runExperiment(): print("Model Test: Xplane setting up connection") print("Setting up simulation") @@ -64,38 +65,68 @@ def ex(): # ] # 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 - 17 - PitchRoll and Headings + 17 - PitchRoll and Headings: [17, Pitch, Roll, Heading True, -998, -998, -998, -998, -998],\ 18 - Angle of Attack 20 - Latitude and Longitude """ - print("Setting orientation for test") - data = [\ - [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) + location1 = [20, groundLevel + 3000, 39.96239, -104.69713, -998, -998, -998, -998, -998] + testLocation = [20, -998, 27.20579, -80.08621, altitude, -998, -998, -998, -998] # 27.20579°N/80.08621°W + + 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 print("Setting controls") ctrl = [0.0, 0.0, 0.0, 0.0] client.sendCTRL(ctrl) # Pitch, Roll, Rudder, Throttle # Pause the sim - client.pauseSim(False) + # client.pauseSim(False) count = 0 innercount = 0 clockStart = time.time() #Doing stuff In between Test SECOND INCREMENTS - while(count < 1000000): + while(count < 1000000 and runModel): clockStart = time.time() #START TIMER - client.pauseSim(True) # Pause Simulator + # client.pauseSim(True) # Pause Simulator #Run Model cogModel.update_aircraft_state() @@ -107,11 +138,21 @@ def ex(): print("Clock Time: " + str(clockEnd - clockStart)) ## LOG TIME TAKEN sleep(0.05) # LET Simulator Run 50 Milliseconds - # print("Model has finished running") #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...") + ## 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__": ex() \ No newline at end of file diff --git a/Python3/src/xpc/__init__.py b/Python3/src/xpc/__init__.py index c7f5ec9..7851450 100644 --- a/Python3/src/xpc/__init__.py +++ b/Python3/src/xpc/__init__.py @@ -310,7 +310,9 @@ class XPlaneConnect(object): if len(value) > 255: raise ValueError("value must have less than 256 items.") fmt = "