Pre-sleep() replacement in favor of a timer in order to customizs data logging

This commit is contained in:
cs-powell
2025-04-10 20:45:37 -04:00
parent 35365e0a01
commit 75c178f1e1
5 changed files with 84 additions and 25 deletions

View File

@@ -388,7 +388,6 @@ class AircraftLandingModel(pyactr.ACTRModel):
# Send all controls simultaneously to X-Plane # Send all controls simultaneously to X-Plane
self.send_controls_to_xplane(yoke_pull, yoke_steer+additive, 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): def send_controls_to_xplane(self, yoke_pull, yoke_steer, rudder, throttle):
""" """
Sends all control inputs to X-Plane using XPlaneConnect Sends all control inputs to X-Plane using XPlaneConnect

View File

@@ -1,8 +1,28 @@
Experiment Number,Starting Altitude (AGL),Wind Layer Altitude,Wind Direction,Wind Speed Wind Experiments,Starting Altitude (AGL),Wind Layer Altitude,Wind Direction,Wind Speed,Direction Offset(Setup Only),Main Heading
1,2000,0,179,0 1,2000,0,139,5,-40,179
2,2000,0,179,5 2,2000,0,149,5,-30,
3,2000,0,179,10 3,2000,0,159,5,-20,
4,2000,0,179,15 4,2000,0,169,5,-10,
5,2000,0,179,20 5,2000,0,179,5,0,
6,2000,0,179,25 6,2000,0,189,5,10,
7,2000,0,179,30 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 Experiment Number Wind Experiments Starting Altitude (AGL) Wind Layer Altitude Wind Direction Wind Speed Direction Offset(Setup Only) Main Heading
2 1 1 2000 0 179 139 0 5 -40 179
3 2 2 2000 0 179 149 5 -30
4 3 3 2000 0 179 159 10 5 -20
5 4 4 2000 0 179 169 15 5 -10
6 5 5 2000 0 179 20 5 0
7 6 6 2000 0 179 189 25 5 10
8 7 7 2000 0 179 199 30 5 20
9 8 2000 0 209 5 30
10 9 2000 0 219 5 40
11 10 2000 0 139 10 -40
12 11 2000 0 149 10 -30
13 12 2000 0 159 10 -20
14 13 2000 0 169 10 -10
15 14 2000 0 179 10 0
16 15 2000 0 189 10 10
17 16 2000 0 199 10 20
18 17 2000 0 209 10 30
19 18 2000 0 219 10 40
20 19 2000 0 139 15 -40
21 20 2000 0 149 15 -30
22 21 2000 0 159 15 -20
23 22 2000 0 169 15 -10
24 23 2000 0 179 15 0
25 24 2000 0 189 15 10
26 25 2000 0 199 15 20
27 26 2000 0 209 15 30
28 27 2000 0 219 15 40

View File

@@ -1,5 +1,3 @@
import datetime import datetime
from math import cos, pi, sin, sqrt from math import cos, pi, sin, sqrt
import os import os
@@ -10,6 +8,12 @@ from cognitiveModel import AircraftLandingModel
import shutil import shutil
import csv import csv
from enum import Enum from enum import Enum
from playsound import playsound
import threading as threading
# import pyautogui as pag
class messageType(Enum): class messageType(Enum):
@@ -150,7 +154,13 @@ def experimentSetUp(client,currentConditions,newExperiment):
else: else:
print("Experiment currently in progress, not resetting position and environmental conditions") print("Experiment currently in progress, not resetting position and environmental conditions")
def runExperiment(title,currentConditions,allowPrinting,isNewExperiment): def printLoop(status,data):
while(status):
print(str(data))
if(not status):
print("Thread Should Finish Now")
def runExperiment(title,currentConditions,allowPrinting,isNewExperiment,experimentCount):
specialPrint("New Experiment\nSetting Up the Simulation",False,messageType.REGULAR) specialPrint("New Experiment\nSetting Up the Simulation",False,messageType.REGULAR)
startTime = 0 startTime = 0
endTime = 0 endTime = 0
@@ -160,7 +170,7 @@ def runExperiment(title,currentConditions,allowPrinting,isNewExperiment):
newExperiment = isNewExperiment newExperiment = isNewExperiment
while(timeElapsed <= timeoutLimit and experimentInProgress): while(timeElapsed <= timeoutLimit and experimentInProgress):
# print("Time Elapsed: -----> " + str(timeElapsed))
try: try:
with xpc.XPlaneConnect() as client: with xpc.XPlaneConnect() as client:
""" """
@@ -180,14 +190,21 @@ def runExperiment(title,currentConditions,allowPrinting,isNewExperiment):
cogModel.client.pauseSim(False) cogModel.client.pauseSim(False)
newExperiment = False newExperiment = False
"""
SETUP DATA THREAD
"""
# thread = threading.Thread(target=printLoop(cogModel.getSimulationStatus(),cogModel.destinations.get("airspeed")))
# thread.start()
""" """
Single Experiment Loop Single Experiment Loop
""" """
file = open("/Users/flyingtopher/X-Plane 11/Data.txt")
while(experimentInProgress): while(experimentInProgress):
cogModel.update_aircraft_state() cogModel.update_aircraft_state()
cogModel.update_controls_simultaneously() cogModel.update_controls_simultaneously()
client.pauseSim(False) #Unpause Simulator client.pauseSim(False) #Unpause Simulator
sleep(0.05) # Let Simulator Run 50 Milliseconds sleep(2) # Let Simulator Run 50 Milliseconds
startTime = time.time() startTime = time.time()
experimentInProgress = cogModel.getSimulationStatus() experimentInProgress = cogModel.getSimulationStatus()
except: except:
@@ -210,28 +227,45 @@ def runExperiment(title,currentConditions,allowPrinting,isNewExperiment):
""" """
Ask Experimenter if they would like to exit experiment battery early 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 = input("Press 'y' or any key to continue, press 'n' to exit...")
exitDecision = "yes"
if(exitDecision == "n"): if(exitDecision == "n"):
exitExperimentLoop = True exitExperimentLoop = True
else: else:
exitExperimentLoop = False exitExperimentLoop = False
return exitExperimentLoop 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(): def setUp():
open("/Users/flyingtopher/X-Plane 11/Data.txt", 'w') open("/Users/flyingtopher/X-Plane 11/Data.txt", 'w')
specialPrint("Data Collection File Ready",False,messageType.REGULAR) specialPrint("Data Collection File Ready",False,messageType.REGULAR)
def cleanUp(title): def cleanUp(count,title):
now = datetime.datetime now = datetime.datetime
shutil.copy("/Users/flyingtopher/X-Plane 11/Data.txt", "/Users/flyingtopher/Desktop/Test Destination/" + title + "_" + str(now.now()) + "_" + ".txt") # 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/" + title + "_"+ str(count) + "_" + ".txt")
print("CLEAN UP: Data File Deleted and Reset") print("CLEAN UP: Data File Deleted and Reset")
specialPrint("Data File Ready",False,messageType.REGULAR) specialPrint("Data File Ready",False,messageType.REGULAR)
def specialPrint(text, inputRequested,type): def specialPrint(text, inputRequested,type):
if(type == messageType.REGULAR): if(type == messageType.REGULAR):
print("-" * 81) print("-" * 81)
print(text) print('====> ', end='')
print(text, end= " <====\n")
print("-" * 81 + "\n") print("-" * 81 + "\n")
if(inputRequested): if(inputRequested):
inputReceived = input() inputReceived = input()
@@ -242,26 +276,32 @@ def specialPrint(text, inputRequested,type):
print("*" * 81 + "\n") print("*" * 81 + "\n")
def ex(): def ex():
# playSound()
""" """
One Time experimental setup One Time experimental setup
""" """
title = specialPrint("Please Enter Experiment Set Title, leave blank for trial runs\n", True, messageType.REGULAR) title = specialPrint("Please Enter Experiment Set Title, leave blank for trial runs", False, messageType.REGULAR)
startAt = input("Start At Experiment #")
experimentConditionMatrix = loadFile() experimentConditionMatrix = loadFile()
allowPrinting = True title = str(experimentConditionMatrix[0][0])
specialPrint("Title is: " + title, False, messageType.REGULAR)
allowPrinting = False
isNewExperiment = True isNewExperiment = True
experimentCount = 0 experimentCount = int(startAt)
""" """
Experiment Loop Experiment Loop
""" """
while(experimentCount<len(experimentConditionMatrix)): while(experimentCount<len(experimentConditionMatrix)):
setUp() setUp()
currentConditions = experimentConditionMatrix[experimentCount+1] currentConditions = experimentConditionMatrix[experimentCount]
exitExperimentLoop = runExperiment(title,currentConditions,allowPrinting,isNewExperiment) exitExperimentLoop = runExperiment(title,currentConditions,allowPrinting,isNewExperiment,(experimentCount+1))
if(exitExperimentLoop): if(exitExperimentLoop):
break break
experimentCount+=1 experimentCount+=1
cleanUp(title) cleanUp((experimentCount),title)
# pag.alert(text="Experiment " + str(experimentCount+1) + " complete. Starting new Experiment", title="EXPERIMENT STATUS UPDATE")
""" """
End of Experiments End of Experiments
""" """