Beispiel #1
0
    def execute(self, g):
        if g.has_letter("E"):
            if int(g.get_value_by_letter("E")) == 0:
                heater = self.printer.heaters["E"]
            elif int(g.get_value_by_letter("E")) == 1:
                heater = self.printer.heaters["H"]
            elif int(g.get_value_by_letter("E")) == -1:
                heater = self.printer.heaters["HBP"]
        else:
            heater = self.printer.heaters["E"]

        if g.has_letter("S"):
            temp = float(g.get_value_by_letter("S"))
        else:
            temp = 100.0

        if g.has_letter("C"):
            cycles = int(g.get_value_by_letter("C"))
        else:
            cycles = 3

        tuner = Autotune(heater, temp, cycles)
        tuner.run()
        logging.info("Max temp: {}, Min temp: {}, Ku: {}, Pu: {}".format(
            tuner.max_temp, tuner.min_temp, tuner.Ku, tuner.Pu))
        logging.info("P: {}, I: {}, D: {}".format(heater.P, heater.I,
                                                  heater.D))
        self.printer.send_message(
            g.prot, "Max temp: {}, Min temp: {}, Ku: {}, Pu: {}".format(
                tuner.max_temp, tuner.min_temp, tuner.Ku, tuner.Pu))
        self.printer.send_message(
            g.prot, "P: {}, I: {}, D: {}".format(heater.P, heater.I, heater.D))
Beispiel #2
0
    def execute(self, g):
        if g.has_letter("E"):
            if int(g.get_value_by_letter("E")) == 0:
                heater = self.printer.heaters["E"]
            elif int(g.get_value_by_letter("E")) == 1:
                heater = self.printer.heaters["H"]
            elif int(g.get_value_by_letter("E")) == -1:
                heater = self.printer.heaters["HBP"]
        else:
            heater = self.printer.heaters["E"]

        if g.has_letter("S"):
            temp = float(g.get_value_by_letter("S"))
        else:
            temp = 100.0

        if g.has_letter("C"):
            cycles = int(g.get_value_by_letter("C"))
        else:
            cycles = 3
        
        tuner = Autotune(heater, temp, cycles, g, self.printer)
        tuner.run()
        logging.info("Max temp: {}, Min temp: {}, Ku: {}, Pu: {}".format(tuner.max_temp, tuner.min_temp, tuner.Ku, tuner.Pu))
        logging.info("P: {}, I: {}, D: {}".format(heater.P, heater.I, heater.D))
        self.printer.send_message(g.prot,"Max temp: {}, Min temp: {}, Ku: {}, Pu: {}".format(tuner.max_temp, tuner.min_temp, tuner.Ku, tuner.Pu))
        self.printer.send_message(g.prot, "P: {}, I: {}, D: {}".format(heater.P, heater.I, heater.D))
def main():
    setDefaultSettings()
    #select_excecution_environment()
    if Settings.OPENCL == 1:
        [ctx, queue] = init_OpenCL()
    #test()
    [scene, collimators, leaf_array] = init_scene(Settings.PIECES)
    settingsList = define_settings(scene, leaf_array)
    oclu = OpenCLUtility.OpenCLUtility()

    if Settings.AUTOTUNE == 1:
        list = []
        list.append(Parameter("LINE_TRIANGLE_INTERSECTION_ALGORITHM", [2], True))
        list.append(Parameter("WG_LIGHT_SAMPLING_X", [1,2,4,8,16,32,64,128], False))
        list.append(Parameter("WG_LIGHT_SAMPLING_Y", [1,2,4,8,16,32,64,128], False))
        list.append(Parameter("WG_LIGHT_SAMPLING_Z", [1,2,4,8,16], False))
        list.append(Parameter("PIECES", [1,2,4,10,20], False))
        list.append(Parameter("RAY_AS", [0], True))
        list.append(Parameter("LEAF_AS", [1], True))
        list.append(Parameter("LEAF_DATA_AS", [2], True))
        list.append(Parameter("SCENE_AS", [2], True))
        list.append(Parameter("DEPTH_FIRST", [0], True))

        fluence_data = numpy.zeros(shape=(Settings.FLX,Settings.FLY), dtype=numpy.float32)
        intensities = numpy.zeros(shape=(Settings.FLX,Settings.FLY,Settings.LSAMPLESSQR), dtype=numpy.float32)

        at = Autotune(ParameterSet(list), run_OpenCL, (oclu, ctx, queue, scene, leaf_array, fluence_data, intensities, settingsList))

        at.findOptimizationParameters()

        #print at.getTable()
        at.saveCSV()

        [fluence_data_OpenCL, total_time_OpenCL, calculation_time_OpenCL, samplesPerSecond_OpenCL] = run_OpenCL(oclu, ctx, queue, scene, leaf_array, fluence_data, intensities, settingsList, at.best_parameters)
    else:
        fluence_data = numpy.zeros(shape=(Settings.FLX,Settings.FLY), dtype=numpy.float32)
        intensities = numpy.zeros(shape=(Settings.FLX,Settings.FLY,Settings.LSAMPLESSQR), dtype=numpy.float32)
        [fluence_data_OpenCL, total_time_OpenCL, calculation_time_OpenCL, samplesPerSecond_OpenCL] = run_OpenCL(oclu, ctx, queue, scene, leaf_array, fluence_data, intensities, settingsList, Settings.getDefaultOptimizationParameterList())

    if Settings.SHOW_PLOT == 1:
        if Settings.PYTHON == 1:
            show_plot(scene, fluence_data_Python, time_Python, samplesPerSecond_Python)
        if Settings.OPENCL == 1:
            show_plot(scene, fluence_data_OpenCL, total_time_OpenCL, samplesPerSecond_OpenCL)
    if Settings.SHOW_3D_SCENE == 1:
        show_3D_scene(scene, leaf_array, collimators)
Beispiel #4
0
    def execute(self, g):
        heater_nr = g.get_int_by_letter("E", 0)
        heater_name = ["HBP", "E", "H", "A", "B", "C"][heater_nr+1] # Map to name
        if not heater_name in self.printer.heaters:
            logging.warning("M303: Heater does not exist")
            return
        heater = self.printer.heaters[heater_name]
        temp     = g.get_float_by_letter("S", 200.0)        
        cycles   = min(3, g.get_int_by_letter("C", 4))       
        pre_cal  = bool(g.get_int_by_letter("P", 0))
        tuning_algo_nr = g.get_int_by_letter("Q", 0)
        if tuning_algo_nr not in [0, 1]:
            logging.warning("Unknown uning algorithm '{}'. Use one of 0, 1. Choosing 0.".format(tuning_algo_nr))
            tuning_algo_nr = 0
        tuning_algo = ["TL","ZN"][tuning_algo_nr]

        tuner = Autotune(heater, temp, cycles, g, self.printer, pre_cal, tuning_algo)
        tuner.run()
        logging.info("Max temp: {}, Min temp: {}, Ku: {}, Pu: {}".format(tuner.max_temp, tuner.min_temp, tuner.Ku, tuner.Pu))
        logging.info("Kp: {}, Ti: {}, Td: {}".format(heater.Kp, heater.Ti, heater.Td))
        self.printer.send_message(g.prot,"Max temp: {}, Min temp: {}, Ku: {}, Pu: {}".format(tuner.max_temp, tuner.min_temp, tuner.Ku, tuner.Pu))
        self.printer.send_message(g.prot, "Kp: {}, Ti: {}, Td: {}".format(heater.Kp, heater.Ti, heater.Td))
        self.printer.send_message(g.prot, "Settings by G-code: \n")
        self.printer.send_message(g.prot, "M130 P{} S{:.4f}\n".format(heater_nr, heater.Kp))
        self.printer.send_message(g.prot, "M131 P{} S{:.4f}\n".format(heater_nr, heater.Ti))
        self.printer.send_message(g.prot, "M132 P{} S{:.4f}\n".format(heater_nr, heater.Td))
        self.printer.send_message(g.prot, "Settings in local.cfg: \n")
        self.printer.send_message(g.prot, "pid_{}_Kp = {:.4f}\n".format(heater_name.lower(), heater.Kp))
        self.printer.send_message(g.prot, "pid_{}_Ti = {:.4f}\n".format(heater_name.lower(), heater.Ti))
        self.printer.send_message(g.prot, "pid_{}_Td = {:.4f}".format(heater_name.lower(), heater.Td))

        tune_data = {
            "tune_data": tuner.plot_temps,
            "tune_gcode": g.message,
            "replicape_key": self.printer.replicape_key}

        Alarm.action_command("pid_tune_data", json.dumps(tune_data))