async def batteryCheck(self): eps = EPS() while True: #Checking the battery voltage to see if it's ready for deployment, if it is too low for too long --> SAFE try: BusVoltage = eps.getBusVoltage() #NOTE: This line is for testing! DO NOT if (BusVoltage < getBusVoltageMin) or (BusVoltage > getBusVoltageMax): raise unexpectedValue except Exception as e: BusVoltage = 4.18 print("Failed to retrieve BusVoltage, got", BusVoltage, "instead. Received error: ", repr(e), getframeinfo(currentframe()).filename, getframeinfo(currentframe()).lineno) if (BusVoltage > self.thresholdVoltage): print('Battery above threshold voltage for deployment') self.batteryStatusOk = True await asyncio.sleep(5) else: self.batteryStatusOk = False #Wait 5 more seconds await asyncio.sleep(5) #Check battery every 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())
import sys sys.path.append('../') from Drivers.eps import EPS from time import sleep epsTest = EPS() #Test all read functions print("MCU Temp in C: " + str(epsTest.getMCUTemp())) print("Cell 1 Temp in C: " + str(epsTest.getCell1Temp())) print("Cell 2 Temp in C: " + str(epsTest.getCell2Temp())) print("Bus Voltage in V: " + str(epsTest.getBusVoltage())) print("Bus Current in A: " + str(epsTest.getBusCurrent())) print("Battery Charge Regulator Voltage in V: " + str(epsTest.getBCRVoltage())) print("Battery Charge Regulator Current in A: " + str(epsTest.getBCRCurrent())) print("3V3 Current in A: " + str(epsTest.get3V3Current())) print("5V Current in A: " + str(epsTest.get5VCurrent())) print("X-Axis Solar Panel Voltage in V: " + str(epsTest.getSPXVoltage())) print("X- Solar Panel Current in A: " + str(epsTest.getSPXMinusCurrent())) print("X+ Solar Panel Current in A: " + str(epsTest.getSPXPlusCurrent())) print("Y-Axis Solar Panel Voltage in V: " + str(epsTest.getSPYVoltage())) print("Y- Solar Panel Current in A: " + str(epsTest.getSPYMinusCurrent())) print("Y+ Solar Panel Current in A: " + str(epsTest.getSPYPlusCurrent())) print("Z-Axis Solar Panel Voltage in V: " + str(epsTest.getSPZVoltage())) print("Tests done. Exiting.")
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 sys sys.path.append('../') from Drivers.eps import EPS from time import sleep epsTest = EPS() #Test battery raw disable/enable epsTest.enableRaw() print("Raw Battery Voltage Enabled for 10 seconds") sleep(10) epsTest.disableRaw() print("Raw Battery Voltage Disabled for 10 seconds") sleep(10) epsTest.enableRaw() print("Raw Battery Voltage Re-enabled for 10 seconds")
import sys sys.path.append('../') from Drivers.eps import EPS from time import sleep epsTest = EPS() #Test solar panel charge functions print("Bus Voltage in V: " + str(epsTest.getBusVoltage())) print("Bus Current in A: " + str(epsTest.getBusCurrent())) print("Battery Charge Regulator Voltage in V: " + str(epsTest.getBCRVoltage())) print("Battery Charge Regulator Current in A: " + str(epsTest.getBCRCurrent())) print("X-Axis Solar Panel Voltage in V: " + str(epsTest.getSPXVoltage())) print("X+ Solar Panel Current in A: " + str(epsTest.getSPXPlusCurrent()))