async def run(self): # Setting up background processes ttncData = self.__getDataTTNC attitudeData = self.__getDataAttitude deployData = DeployData(self.saveobject) self.__tasks.append(asyncio.create_task(pythonInterrupt.interrupt())) self.__tasks.append(asyncio.create_task( ttncData.collectTTNCData(3))) # Boom deploy is mode 3 self.__tasks.append( asyncio.create_task(attitudeData.collectAttitudeData())) self.__tasks.append(asyncio.create_task( deployData.collectDeployData())) self.__tasks.append(asyncio.create_task( self.safeMode.thresholdCheck())) self.__tasks.append(asyncio.create_task(self.safeMode.heartBeat())) # Deploy boom, take picture await asyncio.sleep(5) deployer = boomDeployer.BoomDeployer() cam = camera.Camera() await deployer.deploy( ) #From LOGAN: Deployer.deploy is now an asyncio method, run it like the others #cam.takePicture() #cam.compressLowResToFiles() No longer necessary #cam.compressHighResToFiles() No longer necessary await asyncio.sleep(5) self.cancelAllTasks(self.__tasks) # Cancel all background tasks return True # Go to post-boom deploy
async def run(self): # Setting up background processes self.__tasks.append( asyncio.create_task(self.__heartBeatObj.heartBeatRun())) self.__tasks.append( asyncio.create_task( pythonInterrupt.interrupt(self.__transmit, self.__packetProcessing))) self.__tasks.append( asyncio.create_task(self.__getTTNCData.collectTTNCData( 3))) # Boom deploy is mode 3 self.__tasks.append( asyncio.create_task(self.__getAttitudeData.collectAttitudeData())) self.__tasks.append( asyncio.create_task(self.__getDeployData.collectDeployData())) print("Starting boom deploy") # Deploy boom, take picture await asyncio.sleep(5) deployer = boomDeployer.BoomDeployer() await deployer.deploy() try: print("Taking picture") self.__cam.takePicture() except Exception as e: print("Failed to take a picture because we received excpetion:", repr(e)) await asyncio.sleep(5) # await asyncio.sleep(60) #sleep if a transmission is running self.cancelAllTasks(self.__tasks) # Cancel all background tasks return True # Go to post-boom deploy
async def run(self): self.__tasks.append( asyncio.create_task(self.__heartBeatObj.heartBeatRun())) self.__tasks.append( asyncio.create_task( pythonInterrupt.interrupt(self.__transmit, self.__packetProcessing))) self.__tasks.append( asyncio.create_task( self.__getTTNCData.collectTTNCData(2))) #Pre-Boom is mode 2 self.__tasks.append( asyncio.create_task(self.__getAttitudeData.collectAttitudeData())) self.__tasks.append(asyncio.create_task(self.sunCheck())) self.__tasks.append(asyncio.create_task(self.batteryCheck())) """This code was intended to find out when to deploy the boom based on how long GASPACS was in the light. This was commented out because there is no need for this functionality if there is no resin in the boom""" while True: print("checking for sunlight") if ((self.sunlightData > self.darkVoltage) and self.batteryStatusOk == True): self.cancelAllTasks( self.__tasks ) #Cancel all background processes, this depolys the boom basically print('Returning and exiting') return True #Go on to Boom Deploy Mode if the battery is Ok await asyncio.sleep(5) #Run this whole while loop every 15 seconds
async def run(self): #Set up background processes print("Inside of run in postBoomDeploy") self.__tasks.append(asyncio.create_task(self.__heartBeatObj.heartBeatRun())) self.__tasks.append(asyncio.create_task(pythonInterrupt.interrupt(self.__transmit, self.__packet))) self.__tasks.append(asyncio.create_task(self.__getTTNCData.collectTTNCData(4))) #Post-boom is mode 4 self.__tasks.append(asyncio.create_task(self.__getAttitudeData.collectAttitudeData())) print("Initalized all tasks.") while True: # Don't remove this print statement, the while loop is an integral part # of making sure that postBoomDeploy doesn't crash and it needs to # have something in there so it doesn't crash and suffer print('This is post Boom Deploy') await asyncio.sleep(10)
async def run(self): print('Antenna Deploy Running!') ttncData = self.__getDataTTNC attitudeData = self.__getDataAttitude self.__tasks.append(asyncio.create_task(pythonInterrupt.interrupt())) self.__tasks.append(asyncio.create_task( ttncData.collectTTNCData(1))) #Antenna deploy is mission mode 1 self.__tasks.append( asyncio.create_task(attitudeData.collectAttitudeData())) self.__tasks.append( asyncio.create_task(self.__safeMode.thresholdCheck()) ) #Check battery conditions, run safe mode if battery drops below safe level self.__tasks.append(asyncio.create_task(self.__safeMode.heartBeat())) eps = EPS() while True: #Runs antenna deploy loop if (eps.getBusVoltage() > self.deployVoltage): await asyncio.gather(self.__antennaDeployer.deployPrimary() ) #Fire Primary Backup Resistor doorStatus = self.__antennaDoor.readDoorStatus( ) #Check Door status if doorStatus == ( 1, 1, 1, 1): #probably need to change this to actually work self.cancelAllTasks(self.__tasks) print('Doors are open, returning true') return True else: print( 'Firing secondary, primary did not work. Returning True' ) await asyncio.gather( self.__antennaDeployer.deploySecondary()) self.cancelAllTasks(self.__tasks) return True else: if (self.timeWaited > self.maximumWaitTime): self.__safeMode.run(10) #1 hour await asyncio.sleep( 5 ) #This is an artifact of testing, and will not matter for the actual flight software else: #Wait 1 minute print('Waiting 1 minute until battery status resolves') self.timeWaited = self.timeWaited + 1 await asyncio.sleep(60)
async def run(self): ttncData = self.__getDataTTNC attitudeData = self.__getDataAttitude self.__tasks.append(asyncio.create_task(pythonInterrupt.interrupt())) self.__tasks.append(asyncio.create_task(ttncData.collectTTNCData(2))) #Pre-Boom is mode 2 self.__tasks.append(asyncio.create_task(attitudeData.collectAttitudeData())) self.__tasks.append(asyncio.create_task(self.safeMode.thresholdCheck())) self.__tasks.append(asyncio.create_task(self.safeMode.heartBeat())) self.__tasks.append(asyncio.create_task(self.sunCheck())) self.__tasks.append(asyncio.create_task(self.batteryCheck())) while True: #iterate through array, checking for set amount of dark minutes, then set amount of light minutes no greater than the maximum. When light minutes are greater than the maximum, empties array i=0 darkLength = 0 lastDark = 0 while i < len(self.sunlightData): #Loop through sunlightData, checking for X minutes of darkness if(self.sunlightData[i]<self.darkVoltage): darkLength+=1 #It was in the dark for the 10 seconds recorded in the ith position of sunlightData else: darkLength = 0 #Maybe darkLength -=1 to avoid damage from one bad measurement? Maybe a smoother running average? if(darkLength>self.darkMinutes*6): #If GASPACS has been in dark longer than the preset amount lastDark = i break i+=1 print('Last Dark ' + str(lastDark)) if lastDark != 0: #Condition from previous while loop has been met q=lastDark lightLength = 0 print("In Sunlight, looking for min minutes") while q < len(self.sunlightData): if(self.sunlightData[q]>=self.darkVoltage): lightLength+=1 else: lightLength = 0 #Maybe lightLength -=1 to avoid 1 bad measurement resetting everything if(lightLength>self.lightMaximumMinutes*6): #Has been in the light for too long self.sunlightData.clear() #Reset array of data break if(lightLength>self.lightMinimumMinutes*6 and self.batteryStatusOk==True): self.cancelAllTasks(self.__tasks) #Cancel all background processes print('Returning and exiting') return True #Go on to Boom Deploy Mode if the battery is Ok q += 1 await asyncio.sleep(15) #Run this whole while loop every 15 seconds
async def run(self): #Set up background processes ttncData = self.__getDataTTNC attitudeData = self.__getDataAttitude self.__tasks.append(asyncio.create_task(pythonInterrupt.interrupt())) self.__tasks.append(asyncio.create_task( ttncData.collectTTNCData(4))) #Post-boom is mode 4 self.__tasks.append( asyncio.create_task(attitudeData.collectAttitudeData())) self.__tasks.append( asyncio.create_task(self.__safeMode.thresholdCheck())) fileChecker.checkFile("../TXISR/data/txWindows.txt") self.__tasks.append(asyncio.create_task(self.__safeMode.heartBeat())) self.__tasks.append(asyncio.create_task(self.readNextTransferWindow())) self.__tasks.append(asyncio.create_task(self.rebootLoop())) while True: #if close enough, prep files #wait until 5 seconds before, return True if (self.__timeToNextWindow is not -1 and self.__timeToNextWindow < 60): #If next window is in 2 minutes or less if (self.__datatype < 3): #Attitude, TTNC, or Deployment data prepareFiles.prepareData(self.__duration, self.__datatype) else: prepareFiles.preparePicture(self.__duration, self.__datatype, self.pictureNumber) break await asyncio.sleep(5) windowTime = self.__nextWindowTime while True: if ((windowTime - time.time()) <= 5): # Check the files before adding them as objects fileChecker.checkFile("../TXISR/data/transmissionFlag.txt") txisrCodePath = '../TXISR/TXServiceCode/TXService.run' os.system(txisrCodePath + ' ' + str(self.__datatype)) #Call TXISR Code return True await asyncio.sleep( 0.1 ) #Check at 10Hz until the window time gap is less than 5 seconds
async def executeFlightLogic( ): # Open the file save object, start TXISR, camera obj, and start Boot Mode data collection baseFile = open("/home/pi/lastBase.txt") codeBase = int(baseFile.read()) cameraObj = Camera() # Variable setup delay = 35 * 60 # 35 minute delay #TODO: set this delay to 35 min antennaVoltageCheckWait = 22 * 60 * 60 # 22 hour wait for the voltage to increase past the threshold. This is arbitrary for now boot = True saveObject = saveTofiles.save() # startTXISR(save) ttncData = getDriverData.TTNCData(saveObject) attitudeData = getDriverData.AttitudeData(saveObject) # safeModeObject = safe.safe(saveObject) transmitObject = Transmitting(codeBase, cameraObj) packet = packetProcessing(transmitObject, cameraObj) heartBeatObj = heart_beat() antennaDoorObj = antennaDoor() print( 'Starting data collection') #Setting up Background tasks for BOOT mode tasks = [] tasks.append(asyncio.create_task( heartBeatObj.heartBeatRun())) # starting heart beat tasks.append( asyncio.create_task(pythonInterrupt.interrupt( transmitObject, packet))) # starting rx monitoring tasks.append(asyncio.create_task( ttncData.collectTTNCData(0))) # Boot Mode is classified as 0 tasks.append(asyncio.create_task( attitudeData.collectAttitudeData())) # collecting attitude data # Initialize all mission mode objects # NOTE: the comms-tx is the only exception to this rule as it is to be handled differently than other mission modes # NOTE: Boot Mode is defined and executed in this document, instead of a separate mission mode # safeModeObject was deleted below in the init parameters after saveObject antennaDeploy = antennaMode(saveObject, transmitObject, packet) preBoomDeploy = preBoomMode(saveObject, transmitObject, packet) postBoomDeploy = postBoomMode(saveObject, transmitObject, packet) boomDeploy = boomMode(saveObject, transmitObject, cameraObj, packet) # Check the boot record if it doesn't exist recreate it if (readData() == (None, None, None)): print('Files are empty') bootCount, antennaDeployed, lastMode = 0, False, 0 # otherwise save the last mission mode else: bootCount, antennaDeployed, lastMode = readData() bootCount += 1 # Increment boot count # save data recordData(bootCount, antennaDeployed, lastMode) if lastMode not in range(0, 7): #Mission Mode invalid lastMode = 0 antennaDeployed = False recordData(bootCount, antennaDeployed, lastMode) # This is the implementation of the BOOT mode logic. if not antennaDeployed: # First, sleep for 35 minutes print('Antenna is undeployed, waiting 35 minutes') await asyncio.sleep(delay) # Sleep for 35 minutes while (transmitObject.isRunning()): await asyncio.sleep(60) #sleep if a transmission is running print("Moving on to check antenna door status") #deploy the antenna, if it fails we will do nothing eps = EPS() voltageCount = 0 try: while True: try: BusVoltage = eps.getBusVoltage() except: #if we fail to check the bus voltage we will set it to the max value plus one BusVoltage = 5.1 + 1 if antennaDeployed == True: break elif (not antennaDeployed) and (BusVoltage > 3.75): antennaDoorObj.deployAntennaMain( ) #wait for the antenna to deploy await asyncio.sleep(300) break elif ((antennaVoltageCheckWait / 10) < voltageCount): antennaDoorObj.deployAntennaMain( ) #wait for the antenna to deploy await asyncio.sleep(300) break else: voltageCount += 1 await asyncio.sleep(10) except: print("____Failed to deploy the antenna_____") # status is set True if all 4 doors are deployed, else it is False try: status = antennaDoorObj.readDoorStatus() except: status = False print("Failed to check antenna door status") if antennaDeployed == True: pass elif status == True: antennaDeployed = True else: antennaDeployed = False recordData(bootCount, antennaDeployed, lastMode) try: # Cancels attitude collection tasks for t in tasks: t.cancel() print('Successfully cancelled BOOT mode background tasks') except asyncio.exceptions.CancelledError: print("Exception thrown cancelling task - This is normal") if not antennaDeployed: await asyncio.gather(antennaDeploy.run()) print('Running Antenna Deployment Mode') antennaDeployed = True print("Antenna Deployed = ", antennaDeployed) recordData(bootCount, antennaDeployed, lastMode) # Save into files elif lastMode == 4: print('Running Post Boom Deploy') lastMode = 4 recordData(bootCount, antennaDeployed, lastMode) # Save into files await asyncio.gather(postBoomDeploy.run()) else: print('Running preBoom Deploy') lastMode = 2 recordData(bootCount, antennaDeployed, lastMode) # Save into files await asyncio.gather(preBoomDeploy.run()) lastMode = 3 recordData(bootCount, antennaDeploy, lastMode) print("Finished running preBoomDeploy") while True: # This loop executes the rest of the flight logic # pre boom deploy print("Entered the loop that chooses the next mission mode.") recordData(bootCount, antennaDeployed, lastMode) # Save into files if ((antennaDeployed == True) and (lastMode != 3) and (lastMode != 4)): print('Running pre-Boom deploy') lastMode = 2 recordData(bootCount, antennaDeployed, lastMode) await asyncio.gather( preBoomDeploy.run() ) # Execute pre-boom deploy, then move to post-boom deploy print("Finished preBoomDeploy") lastMode = 3 recordData(bootCount, antennaDeployed, lastMode) elif ((antennaDeployed == True) and (lastMode == 3)): print('Running Boom Deploy') await asyncio.gather( boomDeploy.run() ) # Execute boom deployment, start post-boom deploy lastMode = 4 recordData(bootCount, antennaDeployed, lastMode) else: # Post-Boom Deploy print('Running post-Boom Deploy') recordData(bootCount, antennaDeployed, lastMode) # Save into files await asyncio.gather(postBoomDeploy.run())
async def executeFlightLogic(): # Open the file save object, start TXISR, and start Boot Mode data collection # Variable setup delay = 1*60 # 35 minute delay boot = True save = saveTofiles.save() # startTXISR(save) ttncData = getDriverData.TTNCData(save) attitudeData = getDriverData.AttitudeData(save) safeMode = safe.safe(save) #interruptObject = INTERRUPT() print('Starting data collection') #Setting up Background tasks for BOOT mode tasks=[] tasks.append(asyncio.create_task(pythonInterrupt.interrupt())) tasks.append(asyncio.create_task(ttncData.collectTTNCData(0))) #Boot Mode is classified as 0 tasks.append(asyncio.create_task(attitudeData.collectAttitudeData())) tasks.append(asyncio.create_task(safeMode.thresholdCheck())) tasks.append(asyncio.create_task(safeMode.heartBeat())) # Initialize all mission mode objects # NOTE: the comms-tx is the only exception to this rule as it is to be handled differently than other mission modes # NOTE: Boot Mode is defined and executed in this document, instead of a separate mission mode antennaDeploy = antennaMode(save) preBoomDeploy = preBoomMode(save) postBoomDeploy = postBoomMode(save) boomDeploy = boomMode(save) if(readData() == (None, None, None)): print('Files are empty') bootCount, antennaDeployed, lastMode = 0,False,0 else: bootCount, antennaDeployed, lastMode = readData() # Read in data from files bootCount += 1 # Increment boot count recordData(bootCount, antennaDeployed, lastMode) if lastMode not in range(0,7): #Mission Mode invalid lastMode = 0 antennaDeployed = False # This is the implementation of the BOOT mode logic. if not antennaDeployed: # First, sleep for 35 minutes print('Antenna is undeployed, waiting 35 minutes') await asyncio.sleep(delay) # Sleep for 35 minutes try: # Cancels attitude collection tasks for t in tasks: t.cancel() print('Successfully cancelled BOOT mode background tasks') except asyncio.exceptions.CancelledError: print("Exception thrown cancelling task - This is normal") # how do we check if the antenna doors are open? # TODO, check of antenna doors are open print('Moving on to check antenna door status') status = antennaDoor().readDoorStatus() # this checks the bytes returned by the antennaDoor if any are 0 then doorOpen gets set to false if antennaDeployed == True: pass elif status == (1,1,1,1): #This will need to be changed to reflect the real antenna antennaDeployed = True else: antennaDeployed = False recordData(bootCount, antennaDeployed, lastMode) if not antennaDeployed: print('Running Antenna Deployment Mode') await asyncio.gather(antennaDeploy.run()) antennaDeployed = True print(antennaDeployed) recordData(bootCount, antennaDeployed, lastMode) # Save into files elif lastMode == 4: print('Running Post Boom Deploy') lastMode = 4 await asyncio.gather(postBoomDeploy.run()) else: print('Running preBoom Deploy') lastMode = 2 await asyncio.gather(preBoomDeploy.run()) while True: # This loop executes the rest of the flight logic # pre boom deploy if antennaDeployed == True and lastMode not in (3,4): print('Running pre-Boom deploy') lastMode = 2 recordData(bootCount, antennaDeployed, lastMode) await asyncio.gather(preBoomDeploy.run()) # Execute pre-boom deploy, then move to post-boom deploy lastMode = 3 recordData(bootCount, antennaDeployed, lastMode) elif antennaDeployed == True and lastMode == 3: print('Running Boom Deploy') await asyncio.gather(boomDeploy.run()) # Execute boom deployment, start post-boom deploy lastMode = 4 recordData(bootCount, antennaDeployed, lastMode) else: # Post-Boom Deploy print('Running post-Boom Deploy') await asyncio.gather(postBoomDeploy.run()) def recordData(bootCount, antennaDeployed, lastMode): fileCheck.checkFile("/home/pi/testingStartup/flightLogicData/bootRecords.txt") # write to the boot file, "w" option in write overwrites the file new = open("/home/pi/testingStartup/flightLogicData/bootRecords.txt", "w+") new.write(str(bootCount) + '\n') if antennaDeployed: new.write(str(1)+'\n') else: new.write(str(0)+'\n') new.write(str(lastMode) + '\n') new.close() # write to the the back up file fileCheck.checkFile("/home/pi/testingStartup/flightLogicData/backupBootRecords.txt") new = open("/home/pi/testingStartup/flightLogicData/backupBootRecords.txt", "w+") new.write(str(bootCount) + '\n') if antennaDeployed: new.write(str(1)+'\n') else: new.write(str(0)+'\n') new.write(str(lastMode) + '\n') new.close() def readData(): # This function reads in data from the files, it was previously in the main function but is better as its own function # bootRecords file format # Line 1 = boot count # Line 2 = antenna deployed? # Line 2 = last mission mode bootCount,antennaDeployed,lastMode = None, None, None fileCheck.checkFile("/home/pi/testingStartup/flightLogicData/bootRecords.txt") try: bootFile = open("/home/pi/testingStartup/flightLogicData/bootRecords.txt", "r") bootCount = int(bootFile.readline().rstrip()) antennaDeployed = bool(int(bootFile.readline().rstrip())) lastMode = int(bootFile.readline().rstrip()) bootFile.close() except: try: print('File exception') fileCheck.checkFile("/home/pi/testingStartup/flightLogicData/backupBootRecords.txt") bootFile = open("/home/pi/testingStartup/flightLogicData/backupBootRecords.txt", "r") bootCount = int(bootFile.readline().rstrip()) antennaDeployed = bool(int(bootFile.readline().rstrip())) lastMode = int(bootFile.readline().rstrip()) bootFile.close() # In this except statement, the files are corrupted, so we rewrite both of them except: print('Double File exception - are both files non-existant?') fileCheck.checkFile("/home/pi/testingStartup/flightLogicData/bootRecords.txt") bootFile = open("/home/pi/testingStartup/flightLogicData/bootRecords.txt", "w") fileCheck.checkFile("/home/pi/testingStartup/flightLogicData/backupBootRecords.txt") backupBootFile = open("/home/pi/testingStartup/flightLogicData/backupBootRecords.txt", "w") bootFile.write('0\n0\n0\n') backupBootFile.write('0\n0\n0\n') recordData(bootCount, antennaDeployed, lastMode) return bootCount, antennaDeployed, lastMode # def startTXISR(saveobject): # Setup for TXISR # This sets up the interupt on the uart pin that triggers when we get commincation over uart # thread.start(interrupt.watchReceptions(saveobject)) <-- TODO fix that import
async def run(self): """ Deploys the antenna when the battery voltage is high enough. Runs async tasks pythonInterrupt, collectTTNCData, collectAttitudeData, thresholdcheck, skipToPostBoom, readNextTransferWindow, trasmit """ print('Antenna Deploy Running!') self.__tasks.append( asyncio.create_task(self.__heartBeatObj.heartBeatRun())) self.__tasks.append( asyncio.create_task( pythonInterrupt.interrupt(self.__transmit, self.__packetProcessing))) self.__tasks.append( asyncio.create_task(self.__getTTNCData.collectTTNCData( 1))) #Antenna deploy is mission mode 1 self.__tasks.append( asyncio.create_task(self.__getAttitudeData.collectAttitudeData())) eps = EPS() #If ground station has sent command to skip to post boom # if await self.skipToPostBoom(): # return True #Finish this mode and move on while True: #Runs antenna deploy loop try: BattVoltage = eps.getBusVoltage() if ((BattVoltage < BattVoltageMin) or (BattVoltage > BattVoltageMax)): print("BattVoltageInt: ", BattVoltage, "BattVoltage: ", BattVoltage) raise unexpectedValue except Exception as e: BattVoltage = 4.18 print("failed to retrieve BattVoltage. Exception: ", repr(e), getframeinfo(currentframe()).filename, getframeinfo(currentframe()).lineno, "Received: ", BattVoltage) if (BattVoltage > self.deployVoltage): #If the bus voltage is high enough await asyncio.gather(self.__antennaDeployer.deployPrimary() ) #Fire Primary Backup Resistor try: doorStatus = self.__antennaDoor.readDoorStatus( ) #Returns True if all doors are deployed except: doorStatus = False print("Failed to check door status") if doorStatus == True: self.cancelAllTasks(self.__tasks) print('Doors are open, returning true') return True else: print( 'Firing secondary, primary did not work. Returning True' ) await asyncio.gather( self.__antennaDeployer.deploySecondary()) self.cancelAllTasks(self.__tasks) return True else: if (self.timeWaited > self.maximumWaitTime): await asyncio.gather( self.__antennaDeployer.deployPrimary() ) #Fire Primary Backup Resistor try: doorStatus = self.__antennaDoor.readDoorStatus( ) #Returns True if all doors are deployed except: print("Failed to check door status") if doorStatus == True: self.cancelAllTasks(self.__tasks) print('Doors are open, returning true') return True else: print( 'Firing secondary, primary did not work. Returning True' ) await asyncio.gather( self.__antennaDeployer.deploySecondary()) self.cancelAllTasks(self.__tasks) return True else: #Wait 1 minute print('Waiting 1 minute until battery status resolves') self.timeWaited = self.timeWaited + 1 await asyncio.sleep(60)
import asyncio import sys sys.path.append('../') from TXISR import pythonInterrupt asyncio.run(pythonInterrupt.interrupt())