示例#1
0
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()
示例#2
0
def _calibrate_pH():
    """Routine for calibrating pH sensor."""
    # get first buffer pH
    buffer1_actual_pH = interfaces.read_user_value("Enter buffer pH:")
    interfaces.lcd_out("Put sensor in buffer",
                       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()
    buffer1_measured_volts = float(interfaces.read_raw_pH())
    interfaces.lcd_clear()
    interfaces.lcd_out("Recorded pH and volts:", line=1)
    interfaces.lcd_out(
        "{0:>2.5f} pH, {1:>3.4f} V".format(buffer1_actual_pH,
                                           buffer1_measured_volts),
        line=2,
    )
    interfaces.lcd_out("Press any button",
                       style=constants.LCD_CENT_JUST,
                       line=3)
    interfaces.lcd_out("to continue", style=constants.LCD_CENT_JUST, line=4)
    interfaces.read_user_input()

    # set calibration constants
    constants.PH_REF_VOLTAGE = buffer1_measured_volts
    constants.PH_REF_PH = buffer1_actual_pH
示例#3
0
def degas(seconds):
    interfaces.lcd_clear()
    interfaces.lcd_out("Degassing {0:.0f}".format(seconds), line=1)
    interfaces.lcd_out("seconds", line=2)
    interfaces.stir_speed_fast()
    interfaces.delay(seconds, countdown=True)
    interfaces.stir_speed_slow()
示例#4
0
def test_mode_pump():
    p_volume = interfaces.read_user_value("Volume: ")

    while True:
        p_direction = interfaces.read_user_value("Direction (0/1):")
        if p_direction == 0 or p_direction == 1:
            interfaces.lcd_clear()
            interfaces.pump_volume(float(p_volume), int(p_direction))
            break
示例#5
0
def test_mode_read_volume():
    interfaces.lcd_clear()
    interfaces.lcd_out("Pump Vol: ", line=1)
    interfaces.lcd_out(
        "{0:1.2f}".format(constants.volume_in_pump),
        style=constants.LCD_CENT_JUST,
        line=2,
    )
    interfaces.lcd_out("Press any to cont.", line=3)
    interfaces.read_user_input()
示例#6
0
def titration(pH_target,
              solution_increment_amount,
              data,
              total_sol_added,
              degas_time=0):
    """
    Incrementally adds HCl depending on the input parameters, until target pH is reached
    :param pH_target: target pH for the titration
    :param solution_increment_amount: amount of HCl to add to solution. Units of mL
    :param data: list of recorded temperature, pH, and solution volume data so far
    :param total_sol_added: total amount of HCl added to the solution so far
    :param degas_time: optional parameter defining the de-gas time for the solution after the target pH has been reached
    :return: total solution added so far
    """
    interfaces.lcd_out(
        "Titrating to {} pH".format(str(pH_target)),
        style=constants.LCD_CENT_JUST,
        line=4,
    )
    # total HCl added
    total_sol = total_sol_added

    current_pH = wait_pH_stable(total_sol, data)

    while current_pH - pH_target > constants.PH_ACCURACY:
        interfaces.pump_volume(solution_increment_amount, 1)
        if constants.volume_in_pump < 0.05:
            # pump in 1 mL
            interfaces.pump_volume(1.0, 0)
        total_sol += solution_increment_amount

        # TESTING SETTLING
        interfaces.lcd_out("Mixing...", style=constants.LCD_CENT_JUST, line=4)
        interfaces.delay(10)  # allow it to mix before taking measurements

        current_pH = wait_pH_stable(total_sol, data)
        interfaces.temperature_controller.update()

    interfaces.lcd_clear()
    interfaces.lcd_out("pH value {} reached".format(current_pH), line=1)
    interfaces.lcd_out("Degassing " + str(degas_time) + " seconds", line=2)

    interfaces.delay(degas_time, countdown=True)
    return total_sol
def run():
    """Main driver for the program. Initializes components and queries the user for next steps"""

    try:
        # initialize components
        initialize_components()
        # output prompt to LCD screen
        routine_selection = "0"

        page = 1
        while routine_selection != "6" or routine_selection != constants.KEY_6:
            if routine_selection is constants.KEY_STAR:
                if page == 1:
                    page = 2
                else:
                    page = 1
            if page == 1:
                interfaces.display_list(constants.ROUTINE_OPTIONS_1)
            else:
                interfaces.display_list(constants.ROUTINE_OPTIONS_2)

            # wait for user input to select which routine (polling should be fine here)
            routine_selection = interfaces.read_user_input()
            routines.run_routine(routine_selection)

        analysis.save_calibration_data()
        interfaces.temperature_controller.deactivate()
        interfaces.lcd_clear()
        interfaces.ui_lcd.lcd_backlight(False)
    except Exception:
        # Deactivate the SSR if any crash occurs
        if interfaces.temperature_controller is not None:
            interfaces.temperature_controller.deactivate()
        print("\nDeactivated SSR")

        print(sys.exc_info()[0])
        traceback.print_exc()
示例#8
0
def edit_settings():
    """Resets calibration constants to default"""
    interfaces.lcd_out("Reset calibration", line=1)
    interfaces.lcd_out("settings to default?", line=2)
    interfaces.lcd_out("1: Yes", line=3)
    interfaces.lcd_out("2: No", line=4)
    selection = interfaces.read_user_input()
    if selection != "n" or selection != "N":
        analysis.reset_calibration()
        analysis.save_calibration_data()
        interfaces.lcd_clear()
        interfaces.lcd_out("Default constants restored", 1)
        interfaces.lcd_out("Press any to cont.", 3)
        interfaces.read_user_input()

    interfaces.lcd_out("Set volume in pump? (Y/n)", 1)
    selection = interfaces.read_user_input()
    if selection != "n" or selection != "N":
        vol_in_pump = interfaces.read_user_value("Volume in pump: ")
        constants.volume_in_pump = vol_in_pump
        analysis.save_calibration_data()
        interfaces.lcd_out("Volume in pump set", 1)
        interfaces.lcd_out("Press any to cont.", 3)
        interfaces.read_user_input()
示例#9
0
def run():
    """Main driver for the program. Initializes components and queries the user for next steps"""

    try:
        # initialize components
        initialize_components()
        # output prompt to LCD screen
        routine_selection = "0"

        page = 1
        while routine_selection != "6" or routine_selection != constants.KEY_6:
            if routine_selection is constants.KEY_STAR:
                if page == 1:
                    page = 2
                else:
                    page = 1
            if page == 1:
                interfaces.display_list(constants.ROUTINE_OPTIONS_1)
            else:
                interfaces.display_list(constants.ROUTINE_OPTIONS_2)

            # wait for user input to select which routine (polling should be fine here)
            routine_selection = interfaces.read_user_input()
            routines.run_routine(routine_selection)

        analysis.save_calibration_data()
        interfaces.temperature_controller.deactivate()
        interfaces.lcd_clear()
        interfaces.ui_lcd.lcd_backlight(False)
    except (BaseException, Exception):
        # Deactivate the SSR if any crash occurs
        if interfaces.temperature_controller is not None:
            interfaces.temperature_controller.deactivate()
        print("\n************************\nDeactivated SSR\n************************\n")

        try:
            interfaces.lcd_clear()
        except BaseException:
            pass
        try:
            interfaces.lcd_out("Deactivated SSR", 1)
        except BaseException:
            pass

        # Attempt to save calibration data, this will save syringe position
        # and any recent calibrations
        try:
            analysis.save_calibration_data()
            print(
                "\n************************\nCalibration Saved\n************************\n"
            )
            try:
                interfaces.lcd_out("Calibration Saved", 2)
            except Exception:
                pass
        except Exception:
            print(
                "\n!!!!!!!!!!!!!!!!!!!!!!!!\nUnable to save calibration data\n!!!!!!!!!!!!!!!!!!!!!!!!\n"
            )
            try:
                interfaces.lcd_out("Calibration UNSAVED", 2)
            except Exception:
                pass
        print(sys.exc_info()[0])
        traceback.print_exc()
示例#10
0
def total_alkalinity_titration():
    """Runs through the full titration routine to find total alkalinity"""
    # pull in 1 ml of solution into pump for use in titration
    if constants.volume_in_pump < 1.0:
        p_volume = 1.0 - constants.volume_in_pump
        interfaces.pump_volume(float(p_volume), 0)
    # data object to hold recorded data
    data = [(
        "temperature",
        "pH V",
        "solution volume",
        "weight",
        "salinity",
        "Buffer pH",
        "Buffer pH V",
    )]

    # query user for initial solution weight
    initial_weight = interfaces.read_user_value("Sol. weight (g):")
    salinity = interfaces.read_user_value("Sol. salinity (ppt):")
    buffer_ph = constants.PH_REF_PH
    buffer_v = constants.PH_REF_VOLTAGE

    interfaces.lcd_clear()
    interfaces.lcd_out("Calibrate pH probe?", line=1)
    interfaces.lcd_out("Yes: 1", line=2)
    interfaces.lcd_out("No (use old): 0", line=3)
    interfaces.lcd_out("{0:>2.3f} pH: {1:>2.4f} V".format(buffer_ph, buffer_v),
                       line=4)
    selection = interfaces.read_user_input()
    if selection == constants.KEY_1:
        _calibrate_pH()

    data.append(
        (None, None, None, initial_weight, salinity, buffer_ph, buffer_v))

    # while not initial_weight.replace('.', '').isdigit():
    # interfaces.lcd_out("Please enter a numeric value.", console=True)
    # initial_weight = interfaces.read_user_input()

    # initial titration (bring solution close to 3.5)
    # todo set stir speed slow
    total_sol = 0
    interfaces.lcd_out("Bring pH to 3.5:", line=1)
    interfaces.lcd_out("Manual: 1", line=2)
    interfaces.lcd_out("Automatic: 2", line=3)
    interfaces.lcd_out("Stir speed: slow", line=4)
    user_choice = interfaces.read_user_input()

    # wait until solution is up to temperature
    interfaces.temperature_controller.activate()
    interfaces.lcd_clear()
    interfaces.lcd_out("Heating to 30 C...", line=1)
    interfaces.lcd_out("Please wait...", style=constants.LCD_CENT_JUST, line=3)
    if user_choice == "1":
        interfaces.lcd_out("MANUAL SELECTED",
                           style=constants.LCD_CENT_JUST,
                           line=4)
    else:
        interfaces.lcd_out("AUTO SELECTED",
                           style=constants.LCD_CENT_JUST,
                           line=4)
    while not interfaces.temperature_controller.at_temperature():
        interfaces.temperature_controller.update()
        temperature = interfaces.temperature_controller.get_last_temperature()
        interfaces.lcd_out(
            "Temp: {0:>4.3f} C".format(temperature),
            style=constants.LCD_CENT_JUST,
            line=2,
        )

    if user_choice == "1":
        # Manual
        while user_choice == "1":
            p_volume = interfaces.read_user_value("Volume: ")
            interfaces.lcd_clear()
            interfaces.lcd_out("Direction (0/1): ", line=1)
            p_direction = interfaces.read_user_input()
            p_volume = float(p_volume)
            p_direction = int(p_direction)
            if p_direction == 1:
                total_sol += p_volume
            if p_direction == 0 or p_direction == 1:
                interfaces.pump_volume(p_volume, p_direction)
            current_pH = wait_pH_stable(total_sol, data)
            interfaces.lcd_out("Current pH: {0:>4.5f}".format(current_pH),
                               line=1)
            interfaces.lcd_out("Continue adding solution?", line=2)
            interfaces.lcd_out("(0 - No, 1 - Yes)", line=3)
            interfaces.lcd_out("", line=4)

            user_choice = interfaces.read_user_input()
    else:
        # Automatic
        total_sol = titration(constants.TARGET_PH_INIT,
                              constants.INCREMENT_AMOUNT_INIT, data, 0, 0)
        total_sol = titration(
            constants.TARGET_PH_MID,
            constants.INCREMENT_AMOUNT_MID,
            data,
            total_sol,
            600,
        )

    # 3.5 -> 3.0
    # todo set stir speed fast
    interfaces.lcd_out("Stir speed: fast", line=4)
    titration(constants.TARGET_PH_FINAL, constants.INCREMENT_AMOUNT_FINAL,
              data, total_sol)
    # save data to csv
    analysis.write_titration_data(data)
    interfaces.temperature_controller.deactivate()
示例#11
0
def test_mode_toggle_test_mode():
    constants.IS_TEST = not constants.IS_TEST
    interfaces.lcd_clear()
    interfaces.lcd_out("Testing: {}".format(constants.IS_TEST), line=1)
    interfaces.lcd_out("Press any to cont.", line=3)
    interfaces.read_user_input()