def test_gpio(self): for i in range(5): SensorManager.gpio_output(PAYLOAD_HTR_A_GPIO, ON) time.sleep(0.2) retval = SensorManager.gpio_output(PAYLOAD_HTR_A_GPIO, OFF) time.sleep(0.2) self.assertEqual(True, retval)
def main(): ds1624 = [TEMP_PAYLOAD_A, TEMP_BAT_1] ds18b20 = [PANEL0, PANEL1] for temp_sensor in ds1624: SensorManager.init_temp_sensor(temp_sensor) SensorManager.gpio_output(PSS_HTR_EN_1_GPIO, ON) with open("/root/csdc3/src/sensors/temp_log.txt", "a") as f: for i in range(1): start = time.time() temperatures = [] for temp_sensor in ds1624: value = SensorManager.read_temp_sensor(temp_sensor) temperatures.append(value) for temp_sensor in ds18b20: value = SensorManager.get_panel_data(temp_sensor) temperatures.append(value) readtime = time.time() - start temperatures.append(readtime) f.write(str(temperatures) + '\n') SensorManager.gpio_output(PSS_HTR_EN_1_GPIO, OFF) for temp_sensor in ds1624: SensorManager.stop_temp_sensor(temp_sensor)
def ShutAllBatteryHeaters(): """ shut all heaters off """ heaterIdentifers = (PSS_HTR_EN_1_GPIO, PSS_HTR_EN_2_GPIO,\ PSS_HTR_EN_3_GPIO, PSS_HTR_EN_4_GPIO) SensorManager.gpio_output(PSS_HTR_MUX_SEL_GPIO, OFF) for iden in heaterIdentifers: SensorManager.gpio_output(heaterIdentifers[i], OFF)
def set_heaters(self, experiment=0, state=False): if state == False: SensorManager.gpio_output(self.heater, OFF) else: SensorManager.gpio_output(self.heater, ON) return True
def main(): parser = argparse.ArgumentParser(description="Deployment script", formatter_class=argparse.ArgumentDefaultsHelpFormatter) parser.add_argument("-t", "--time", type=int, default=5, help="Time deployment switch is on") args = parser.parse_args() deploy_time = args.time SensorManager.gpio_output(DEPLOYMENT_SW_A_GPIO, ON) sleep(deploy_time) SensorManager.gpio_output(DEPLOYMENT_SW_A_GPIO, OFF)
def set_power(self, isOn=False): insertDebugLog(NOTICE, "Power to %d" % (isOn), PAYLOAD, int(time.time())) print("Setting power for payload: ", isOn) if isOn == False: SensorManager.gpio_output(PAYLOAD_EN_GPIO, OFF) SensorManager.gpio_output(OLD_PAYLOAD_EN_GPIO, OFF) else: SensorManager.gpio_output(PAYLOAD_EN_GPIO, ON) SensorManager.gpio_output(OLD_PAYLOAD_EN_GPIO, ON) SensorManager.gpio_output(SENSORS_EN_GPIO, ON) return True
def adc_driver_test(): SensorManager.gpio_output(PAYLOAD_EN_GPIO, ON) SensorManager.init_adc_driver() try: while True: for i in range(7): value = SensorManager.read_adc_driver(i) print value, print time.sleep(1) except KeyboardInterrupt: SensorManager.gpio_output(PAYLOAD_EN_GPIO, OFF)
def main(): SensorManager.gpio_output(PAYLOAD_EN_GPIO, ON) SensorManager.init_adc(ADC) start_time = time.time() try: while True: strain, force, adc_temp = SensorManager.read_adc(0, ADC) elapsed = time.time() - start_time print("[" + str(round(elapsed, 3)) + " s] ") print(strain, force, adc_temp) time.sleep(2) except KeyboardInterrupt: SensorManager.stop_adc_sensor(ADC) SensorManager.gpio_output(PAYLOAD_EN_GPIO, OFF)
def test_pss_gpio(self): gpios = [PSS_HTR_EN_1_GPIO, PSS_HTR_EN_2_GPIO, PSS_HTR_EN_3_GPIO, \ PSS_HTR_EN_4_GPIO, PSS_HTR_MUX_SEL_GPIO] for gpio in gpios: retval = SensorManager.gpio_output(gpio, self.gpioState) self.assertEqual(True, retval)
def main(): ser = init_transceiver() SensorManager.gpio_output(RADIO_EN_GPIO, ON) time.sleep(5) if ser.isOpen(): for i in range(5): curr_time = int(time.time()) power_tuple = selectTelemetryLog(POWER) cdh_brd_temp = selectTelemetryLog(TEMP_CDH_BRD) power = power_tuple[0][1] temp = cdh_brd_temp[0][1] print(temp) SC_writeCallback(SC_transmit("POWER:%s| CDH_TEMP:%s | %d" % (power, temp, curr_time)), ser) time.sleep(5) else: ser.open() SensorManager.gpio_output(RADIO_EN_GPIO, OFF)
def main(): while True: SensorManager.gpio_output(WATCHDOG_GPIO, ON) time.sleep(1) SensorManager.gpio_output(WATCHDOG_GPIO, OFF) time.sleep(10)
def check_health(self): """ Determines whether battery chargers must be set manually """ # Check if sensors are reading data in the system # if areSensorsAcquiringData(): # return print('Threshold voltage:', self.thresholdVoltage) # Get temperature inputs tempIdentifiers = (TEMP_BAT_1) #, TEMP_BAT_2, TEMP_BAT_3, TEMP_BAT_4) tempValues = [] for iden in tempIdentifiers: SensorManager.init_temp_sensor(iden) valueList = [] # Get median of 5 value readings to remove outliers for i in range(0,5): valueList.append(SensorManager.read_temp_sensor(iden)) tempValue = median(valueList) print('Current temperature:', tempValue) SensorManager.stop_temp_sensor(iden) # Keep final value of sensor tempValues.append(tempValue) # Get status identifiers statusIdentifiers = (PSS_HTR_STAT_1_GPIO, PSS_HTR_STAT_2_GPIO,\ PSS_HTR_STAT_3_GPIO, PSS_HTR_STAT_4_GPIO) statusValues = [] for iden in statusIdentifiers: statusValues.append(SensorManager.gpio_input(iden,0)) # Define manual heater identifiers heaterIdentifiers = (PSS_HTR_EN_1_GPIO, PSS_HTR_EN_2_GPIO,\ PSS_HTR_EN_3_GPIO, PSS_HTR_EN_4_GPIO) # Check if ShutAllBatteryHeaters is running if self.heaterShutDownLock.isLocked(): # Shut all battery heaters off print('Battery heaters must remain shut off') self.controlStatus = True SensorManager.gpio_output(PSS_HTR_MUX_SEL_GPIO, OFF) for heater in heaterIdentifiers: SensorManager.gpio_output(heater, OFF) return # Check if payload is running if self.isPayloadAcquiringData(): # Shut all battery heaters off print('Payload is running... shutting off all battery heaters') self.controlStatus = True SensorManager.gpio_output(PSS_HTR_MUX_SEL_GPIO, OFF) for heater in heaterIdentifiers: SensorManager.gpio_output(heater, OFF) return # Take control if required for i in range(0,len(tempValues)): if self.temp_threshold(tempValues[i], 'GT') and statusValues[i] == 0: print('Case 1: [Analog] Heaters are turned on') self.controlStatus = False SensorManager.gpio_output(PSS_HTR_MUX_SEL_GPIO, ON) return elif self.temp_threshold(tempValues[i], 'GT') and statusValues[i] == 1: print('Case 2: [Digital] Heaters are turned off') self.controlStatus = True SensorManager.gpio_output(PSS_HTR_MUX_SEL_GPIO, OFF) SensorManager.gpio_output(heaterIdentifiers[i], OFF) return elif self.temp_threshold(tempValues[i], 'LT') and statusValues[i] == 0: print('Case 3: [Digital] Heaters are turned on') self.controlStatus = True SensorManager.gpio_output(PSS_HTR_MUX_SEL_GPIO, OFF) if self.is_battery_safe(): SensorManager.gpio_output(heaterIdentifiers[i], ON) return elif self.temp_threshold(tempValues[i], 'LT') and statusValues[i] == 1: print('Case 4: [Analog] Heaters are turned off') self.controlStatus = False SensorManager.gpio_output(PSS_HTR_MUX_SEL_GPIO, ON) return
def test_deployment_gpio(self): gpios = [DEPLOYMENT_SW_A_GPIO, DEPLOYMENT_SW_B_GPIO] for gpio in gpios: retval = SensorManager.gpio_output(gpio, self.gpioState) self.assertEqual(True, retval)
def test_cdh_gpio(self): gpios = [WATCHDOG_GPIO, SENSORS_EN_GPIO, RADIO_EN_GPIO, I2C_MUX_RESET_GPIO] for gpio in gpios: retval = SensorManager.gpio_output(gpio, self.gpioState) self.assertEqual(True, retval)
def main(): parser = argparse.ArgumentParser(description="Script to toggle switches", formatter_class=argparse.ArgumentDefaultsHelpFormatter) parser.add_argument("-d", "--deploy", action="store_true", help="Switch to deploy antenna") parser.add_argument("-r", "--radio", action="store_true", help="Turn on radio") parser.add_argument("-p", "--payload", action="store_true", help="Turn on payload") parser.add_argument("-s", "--sensors", action="store_false", help="Turn off sensors") args = parser.parse_args() deploy = args.deploy radio = args.radio payload = args.payload sensors = args.sensors SensorManager.gpio_output(RADIO_EN_GPIO, radio) SensorManager.gpio_output(SENSORS_EN_GPIO, sensors) SensorManager.gpio_output(PAYLOAD_EN_GPIO, payload) SensorManager.gpio_output(PAYLOAD_HTR_A_GPIO, OFF) SensorManager.gpio_output(PAYLOAD_HTR_B_GPIO, OFF) SensorManager.gpio_output(PSS_HTR_EN_1_GPIO, OFF) SensorManager.gpio_output(PSS_HTR_EN_2_GPIO, OFF) SensorManager.gpio_output(PSS_HTR_EN_3_GPIO, OFF) SensorManager.gpio_output(PSS_HTR_EN_4_GPIO, OFF) SensorManager.gpio_output(PSS_HTR_MUX_SEL_GPIO, OFF) SensorManager.gpio_output(PSS_HTR_EN_1_GPIO, OFF) if deploy: SensorManager.gpio_output(DEPLOYMENT_SW_A_GPIO, deploy) sleep(10) SensorManager.gpio_output(DEPLOYMENT_SW_A_GPIO, OFF) SensorManager.gpio_output(DEPLOYMENT_SW_B_GPIO, OFF) """
def test_payload_gpio(self): gpios = [PAYLOAD_HTR_A_GPIO, PAYLOAD_HTR_B_GPIO, PAYLOAD_EN_GPIO] for gpio in gpios: retval = SensorManager.gpio_output(gpio, self.gpioState) self.assertEqual(True, retval)
def main(): while True: SensorManager.gpio_output(PAYLOAD_EN_GPIO, ON) time.sleep(2) SensorManager.gpio_output(PAYLOAD_EN_GPIO, OFF) time.sleep(2)
def check_health(self): """ Determines whether battery chargers must be set manually """ # Check if sensors are reading data in the system # if areSensorsAcquiringData(): # return # Check if ShutAllBatteryHeaters is running if self.heaterShutDownLock.isLocked(): # Shut all battery heaters off print('Battery heaters must remain shut off') self.controlStatus = True SensorManager.gpio_output(PSS_HTR_MUX_SEL_GPIO, OFF) for heater in heaterIdentifers: SensorManager.gpio_output(heater, OFF) return # # Get temperature inputs # tempIdentifiers = (TEMP_BAT_1,) # TEMP_BAT_2, TEMP_BAT_3, TEMP_BAT_4) # tempValues = [] # for iden in tempIdentifiers: # SensorManager.init_temp_sensor(iden) # valueList = [] # # Get median of 5 value readings to remove outliers # for i in range(0,5): # valueList.append(SensorManager.read_temp_sensor(iden)) # tempValue = median(valueList) # print(tempValue) # SensorManager.stop_temp_sensor(iden) # # Keep final value of sensor # tempValues.append(tempValue) # # # Get status identifiers # statusIdentifiers = (PSS_HTR_STAT_1_GPIO, PSS_HTR_STAT_2_GPIO,\ # PSS_HTR_STAT_3_GPIO, PSS_HTR_STAT_4_GPIO) # statusValues = [] # for iden in statusIdentifiers: # statusValues.append(SensorManager.gpio_input(iden,0)) batteryTempAndStatusDict = BatteryHeatersReader() tempValues = [item["temp"] for item in batteryTempAndStatusDict] statusValues = [item["heaters"] for item in batteryTempAndStatusDict] # Define manual heater identifiers heaterIdentifers = (PSS_HTR_EN_1_GPIO, PSS_HTR_EN_2_GPIO,\ PSS_HTR_EN_3_GPIO, PSS_HTR_EN_4_GPIO) print('Status value: ' + str(statusValues[0])) print('Is analog:', SensorManager.gpio_input(PSS_HTR_MUX_SEL_GPIO, time.time())) # Check if payload is running if self.isPayloadAcquiringData(): # Shut all battery heaters off print('Payload is running... shutting off all battery heaters') self.controlStatus = True SensorManager.gpio_output(PSS_HTR_MUX_SEL_GPIO, OFF) for heater in heaterIdentifers: SensorManager.gpio_output(heater, OFF) return # Find out if analog or OBC is in control for i in range(0,len(tempValues)): if (self.temp_threshold(tempValues[i], 'GT') and statusValues[i] == 1)\ or (self.temp_threshold(tempValues[i], 'LT') and statusValues[i] == 0): # OBC will take control self.controlStatus = True SensorManager.gpio_output(PSS_HTR_MUX_SEL_GPIO, OFF) break else: # Analog will take control self.controlStatus = False SensorManager.gpio_output(PSS_HTR_MUX_SEL_GPIO, ON) # Perform OBC control if required if self.controlStatus == True: for i in range(0,len(tempValues)): if tempValues[i] != None: if self.temp_threshold(tempValues[i], 'GT') and statusValues[i] == 0: print('Case 1: Temp > threshold, heaters off, no action required') elif self.temp_threshold(tempValues[i], 'GT') and statusValues[i] == 1: print('Case 2: Temp > threshold, heaters on, OBC must shut off heater') SensorManager.gpio_output(heaterIdentifers[i], OFF) elif self.temp_threshold(tempValues[i], 'LT') and statusValues[i] == 0: print('Case 3: Temp < threshold, heaters off, OBC must activate heater') if self.is_battery_safe(): SensorManager.gpio_output(heaterIdentifers[i], ON) elif self.temp_threshold(tempValues[i], 'LT') and statusValues[i] == 1: print('Case 4: Temp < threshold, heaters on, no action required')
def test_payload_switches(self): SensorManager.gpio_output(PAYLOAD_EN_GPIO, ON) SensorManager.gpio_output(PAYLOAD_HTR_A_GPIO, ON) time.sleep(1) SensorManager.gpio_output(PAYLOAD_EN_GPIO, OFF) SensorManager.gpio_output(PAYLOAD_HTR_A_GPIO, OFF)