def _calibrate_temperature(): """Routine for calibrating the temperature probe.""" expected_temperature = interfaces.read_user_value( "Ref solution temperature?") interfaces.lcd_out("Put probe in sol", style=constants.LCD_CENT_JUST, line=1) interfaces.lcd_out("", line=2) interfaces.lcd_out("Press 1 to", style=constants.LCD_CENT_JUST, line=3) interfaces.lcd_out("record value", style=constants.LCD_CENT_JUST, line=4) # Waits for user to press enter interfaces.read_user_input() expected_resistance = analysis.calculate_expected_resistance( expected_temperature) actual_temperature, actual_resistance = interfaces.read_temperature() interfaces.lcd_clear() interfaces.lcd_out( "Recorded temperature: {0:0.3f}".format(actual_temperature), line=1) diff = expected_resistance - actual_resistance new_ref_resistance = ( constants.TEMPERATURE_REF_RESISTANCE + diff * constants.TEMPERATURE_REF_RESISTANCE / expected_resistance) constants.TEMPERATURE_REF_RESISTANCE = float(new_ref_resistance) # reinitialize sensors with calibrated values interfaces.lcd_out("{}".format(new_ref_resistance), line=2) interfaces.setup_interfaces()
def _test_temperature(): """Tests the temperature probe""" for i in range(5): temperature, res = interfaces.read_temperature() interfaces.lcd_out("Temperature: {0:0.3f}C".format(temperature), 1) interfaces.lcd_out("Res: {0:0.3f} Ohms".format(res), 2) interfaces.delay(0.5)
def wait_pH_stable(total_sol, data): """ Continually polls probes until pH values are stable :param total_sol: total amount of HCl added to the solution so far :param data: list of recorded temperature, pH, and solution volume data so far :return: mean stable pH value of last 10 values """ # keep track of 10 most recent pH values to ensure pH is stable pH_values = [0] * 10 # a counter used for updating values in pH_values pH_list_counter = 0 # flag to ensure at least 10 pH readings have been made before adding solution valid_num_values_tested = False while True: pH_reading, pH_volts = interfaces.read_pH() temperature_reading = interfaces.read_temperature()[0] interfaces.lcd_out("pH: {0:>4.5f} pH".format(pH_reading), line=1) interfaces.lcd_out("pH V: {0:>3.4f} mV".format(pH_volts * 1000), line=2) interfaces.lcd_out("Temp: {0:>4.3f} C".format(temperature_reading), line=3) pH_values[pH_list_counter] = pH_reading if pH_list_counter == 9: valid_num_values_tested = True # Check that the temperature of the solution is within bounds if (abs(temperature_reading - constants.TARGET_TEMPERATURE) > constants.TEMPERATURE_ACCURACY): # interfaces.lcd_out("TEMPERATURE OUT OF BOUNDS") # TODO output to error log pass # Record data point (temperature, pH volts, total HCl) data.append( (temperature_reading, pH_volts, total_sol, None, None, None, None)) pH_list_counter = 0 if pH_list_counter >= 9 else pH_list_counter + 1 if (valid_num_values_tested and analysis.std_deviation(pH_values) < constants.TARGET_STD_DEVIATION): return pH_reading interfaces.delay(constants.TITRATION_WAIT_TIME)
def test_mode_read_values(numVals=60, timestep=0.5): numVals = numVals timestep = timestep timeVals = np.zeros(numVals) tempVals = np.zeros(numVals) resVals = np.zeros(numVals) pHVals = np.zeros(numVals) voltVals = np.zeros(numVals) for i in range(numVals): temp, res = interfaces.read_temperature() pH_reading, pH_volts = interfaces.read_pH() interfaces.lcd_out("Temp: {0:>4.3f} C".format(temp), line=1) interfaces.lcd_out("Res: {0:>4.3f} Ohms".format(res), line=2) interfaces.lcd_out("pH: {0:>4.5f} pH".format(pH_reading), line=3) interfaces.lcd_out("pH V: {0:>3.4f} mV".format(pH_volts * 1000), line=4) interfaces.lcd_out("Reading: {}".format(i), 1, console=True) timeVals[i] = timestep * i tempVals[i] = temp resVals[i] = res pHVals[i] = pH_reading voltVals[i] = pH_volts interfaces.delay(timestep)