Esempio n. 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()
Esempio n. 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
Esempio n. 3
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()
Esempio n. 4
0
def prime_pump():
    """
    Primes pump by drawing in and pushing out solution.
    Depends on limit switches installed
    """
    interfaces.lcd_out("How many pumps?", 1)
    selection = interfaces.read_user_input()
    sel = int(selection)
    while sel > 0:
        while sel > 0:
            interfaces.drive_step_stick(10000, 0)
            interfaces.drive_step_stick(10000, 1)
            sel = sel - 1
        interfaces.lcd_out("How many more?", 1)
        selection = interfaces.read_user_input()
        sel = int(selection)
Esempio n. 5
0
def calibration():
    """Routine for letting the user pick the sensor to calibrate. Call another routine to calibrate the sensor"""
    interfaces.display_list(constants.SENSOR_OPTIONS)
    sensor_selection = interfaces.read_user_input()
    if sensor_selection == "1" or sensor_selection == constants.KEY_1:
        _calibrate_pH()
    elif sensor_selection == "2" or sensor_selection == constants.KEY_2:
        _calibrate_temperature()
    analysis.save_calibration_data()
Esempio n. 6
0
def test_mode():
    """Function for running specific tests for the program"""
    page = 1
    user_choice = None
    while True:
        # Swap page display if user chooses *
        if user_choice == constants.KEY_STAR:
            if page == 1:
                page = 2
            else:
                page = 1
        # Display the proper page
        if page == 1:
            interfaces.display_list(constants.TEST_OPTIONS_1)
        else:
            interfaces.display_list(constants.TEST_OPTIONS_2)

        user_choice = interfaces.read_user_input()

        if user_choice == "6" or user_choice == constants.KEY_6:
            break
        else:
            test_mode_selection(user_choice)
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()
Esempio n. 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()
Esempio n. 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()
Esempio n. 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()
Esempio n. 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()