Пример #1
0
    def calculate_params(self, probe_positions, distances):
        height_positions = self.manual_heights + probe_positions
        # Setup for coordinate descent analysis
        kin = self.printer.lookup_object('toolhead').get_kinematics()
        orig_delta_params = odp = kin.get_calibration()
        adj_params, params = odp.coordinate_descent_params(distances)
        logging.info(
            "Calculating delta_calibrate with:\n%s\n%s\n"
            "Initial delta_calibrate parameters: %s", height_positions,
            distances, params)
        z_weight = 1.
        if distances:
            z_weight = len(distances) / (MEASURE_WEIGHT * len(probe_positions))
        # Perform coordinate descent
        def delta_errorfunc(params):
            try:
                # Build new delta_params for params under test
                delta_params = orig_delta_params.new_calibration(params)
                getpos = delta_params.get_position_from_stable
                # Calculate z height errors
                total_error = 0.
                for z_offset, stable_pos in height_positions:
                    x, y, z = getpos(stable_pos)
                    total_error += (z - z_offset)**2
                total_error *= z_weight
                # Calculate distance errors
                for dist, stable_pos1, stable_pos2 in distances:
                    x1, y1, z1 = getpos(stable_pos1)
                    x2, y2, z2 = getpos(stable_pos2)
                    d = math.sqrt((x1 - x2)**2 + (y1 - y2)**2 + (z1 - z2)**2)
                    total_error += (d - dist)**2
                return total_error
            except ValueError:
                return 9999999999999.9

        new_params = mathutil.background_coordinate_descent(
            self.printer, adj_params, params, delta_errorfunc)
        # Log and report results
        logging.info("Calculated delta_calibrate parameters: %s", new_params)
        new_delta_params = orig_delta_params.new_calibration(new_params)
        for z_offset, spos in height_positions:
            logging.info("height orig: %.6f new: %.6f goal: %.6f",
                         orig_delta_params.get_position_from_stable(spos)[2],
                         new_delta_params.get_position_from_stable(spos)[2],
                         z_offset)
        for dist, spos1, spos2 in distances:
            x1, y1, z1 = orig_delta_params.get_position_from_stable(spos1)
            x2, y2, z2 = orig_delta_params.get_position_from_stable(spos2)
            orig_dist = math.sqrt((x1 - x2)**2 + (y1 - y2)**2 + (z1 - z2)**2)
            x1, y1, z1 = new_delta_params.get_position_from_stable(spos1)
            x2, y2, z2 = new_delta_params.get_position_from_stable(spos2)
            new_dist = math.sqrt((x1 - x2)**2 + (y1 - y2)**2 + (z1 - z2)**2)
            logging.info("distance orig: %.6f new: %.6f goal: %.6f", orig_dist,
                         new_dist, dist)
        # Store results for SAVE_CONFIG
        self.save_state(probe_positions, distances, new_delta_params)
        self.gcode.respond_info(
            "The SAVE_CONFIG command will update the printer config file\n"
            "with these parameters and restart the printer.")
Пример #2
0
    def calculate_params(self, probe_positions, distances):
        # Setup for coordinate descent analysis
        kin = self.printer.lookup_object('toolhead').get_kinematics()
        params = kin.get_calibrate_params()
        orig_delta_params = build_delta_params(params)
        logging.info(
            "Calculating delta_calibrate with:\n%s\n%s\n"
            "Initial delta_calibrate parameters: %s", probe_positions,
            distances, params)
        adj_params = ('radius', 'angle_a', 'angle_b', 'endstop_a', 'endstop_b',
                      'endstop_c')
        z_weight = 1.
        if distances:
            adj_params += ('arm_a', 'arm_b', 'arm_c')
            z_weight = len(distances) / (MEASURE_WEIGHT * len(probe_positions))
        # Perform coordinate descent
        def delta_errorfunc(params):
            # Build new delta_params for params under test
            delta_params = build_delta_params(params)
            # Calculate z height errors
            total_error = 0.
            for z_offset, stable_pos in probe_positions:
                x, y, z = get_position_from_stable(stable_pos, delta_params)
                total_error += (z - z_offset)**2
            total_error *= z_weight
            # Calculate distance errors
            for dist, stable_pos1, stable_pos2 in distances:
                x1, y1, z1 = get_position_from_stable(stable_pos1,
                                                      delta_params)
                x2, y2, z2 = get_position_from_stable(stable_pos2,
                                                      delta_params)
                d = math.sqrt((x1 - x2)**2 + (y1 - y2)**2 + (z1 - z2)**2)
                total_error += (d - dist)**2
            return total_error

        new_params = mathutil.background_coordinate_descent(
            self.printer, adj_params, params, delta_errorfunc)
        # Log and report results
        logging.info("Calculated delta_calibrate parameters: %s", new_params)
        new_delta_params = build_delta_params(new_params)
        for z_offset, spos in probe_positions:
            logging.info("height orig: %.6f new: %.6f goal: %.6f",
                         get_position_from_stable(spos, orig_delta_params)[2],
                         get_position_from_stable(spos, new_delta_params)[2],
                         z_offset)
        for dist, spos1, spos2 in distances:
            x1, y1, z1 = get_position_from_stable(spos1, orig_delta_params)
            x2, y2, z2 = get_position_from_stable(spos2, orig_delta_params)
            orig_dist = math.sqrt((x1 - x2)**2 + (y1 - y2)**2 + (z1 - z2)**2)
            x1, y1, z1 = get_position_from_stable(spos1, new_delta_params)
            x2, y2, z2 = get_position_from_stable(spos2, new_delta_params)
            new_dist = math.sqrt((x1 - x2)**2 + (y1 - y2)**2 + (z1 - z2)**2)
            logging.info("distance orig: %.6f new: %.6f goal: %.6f", orig_dist,
                         new_dist, dist)
        self.gcode.respond_info(
            "stepper_a: position_endstop: %.6f angle: %.6f arm: %.6f\n"
            "stepper_b: position_endstop: %.6f angle: %.6f arm: %.6f\n"
            "stepper_c: position_endstop: %.6f angle: %.6f arm: %.6f\n"
            "delta_radius: %.6f\n"
            "The SAVE_CONFIG command will update the printer config file\n"
            "with these parameters and restart the printer." %
            (new_params['endstop_a'], new_params['angle_a'],
             new_params['arm_a'], new_params['endstop_b'],
             new_params['angle_b'], new_params['arm_b'],
             new_params['endstop_c'], new_params['angle_c'],
             new_params['arm_c'], new_params['radius']))
        # Store results for SAVE_CONFIG
        self.save_state(probe_positions, distances, new_params)
Пример #3
0
 def calculate_params(self, probe_positions, distances):
     # Setup for coordinate descent analysis
     kin = self.printer.lookup_object('toolhead').get_kinematics()
     params = kin.get_calibrate_params()
     orig_delta_params = build_delta_params(params)
     logging.info("Calculating delta_calibrate with:\n%s\n%s\n"
                  "Initial delta_calibrate parameters: %s",
                  probe_positions, distances, params)
     adj_params = ('radius', 'angle_a', 'angle_b',
                   'endstop_a', 'endstop_b', 'endstop_c')
     z_weight = 1.
     if distances:
         adj_params += ('arm_a', 'arm_b', 'arm_c')
         z_weight = len(distances) / (MEASURE_WEIGHT * len(probe_positions))
     # Perform coordinate descent
     def delta_errorfunc(params):
         # Build new delta_params for params under test
         delta_params = build_delta_params(params)
         # Calculate z height errors
         total_error = 0.
         for z_offset, stable_pos in probe_positions:
             x, y, z = get_position_from_stable(stable_pos, delta_params)
             total_error += (z - z_offset)**2
         total_error *= z_weight
         # Calculate distance errors
         for dist, stable_pos1, stable_pos2 in distances:
             x1, y1, z1 = get_position_from_stable(stable_pos1, delta_params)
             x2, y2, z2 = get_position_from_stable(stable_pos2, delta_params)
             d = math.sqrt((x1-x2)**2 + (y1-y2)**2 + (z1-z2)**2)
             total_error += (d - dist)**2
         return total_error
     new_params = mathutil.background_coordinate_descent(
         self.printer, adj_params, params, delta_errorfunc)
     # Log and report results
     logging.info("Calculated delta_calibrate parameters: %s", new_params)
     new_delta_params = build_delta_params(new_params)
     for z_offset, spos in probe_positions:
         logging.info("height orig: %.6f new: %.6f goal: %.6f",
                      get_position_from_stable(spos, orig_delta_params)[2],
                      get_position_from_stable(spos, new_delta_params)[2],
                      z_offset)
     for dist, spos1, spos2 in distances:
         x1, y1, z1 = get_position_from_stable(spos1, orig_delta_params)
         x2, y2, z2 = get_position_from_stable(spos2, orig_delta_params)
         orig_dist = math.sqrt((x1-x2)**2 + (y1-y2)**2 + (z1-z2)**2)
         x1, y1, z1 = get_position_from_stable(spos1, new_delta_params)
         x2, y2, z2 = get_position_from_stable(spos2, new_delta_params)
         new_dist = math.sqrt((x1-x2)**2 + (y1-y2)**2 + (z1-z2)**2)
         logging.info("distance orig: %.6f new: %.6f goal: %.6f",
                      orig_dist, new_dist, dist)
     self.gcode.respond_info(
         "stepper_a: position_endstop: %.6f angle: %.6f arm: %.6f\n"
         "stepper_b: position_endstop: %.6f angle: %.6f arm: %.6f\n"
         "stepper_c: position_endstop: %.6f angle: %.6f arm: %.6f\n"
         "delta_radius: %.6f\n"
         "The SAVE_CONFIG command will update the printer config file\n"
         "with these parameters and restart the printer." % (
             new_params['endstop_a'], new_params['angle_a'],
             new_params['arm_a'],
             new_params['endstop_b'], new_params['angle_b'],
             new_params['arm_b'],
             new_params['endstop_c'], new_params['angle_c'],
             new_params['arm_c'],
             new_params['radius']))
     # Store results for SAVE_CONFIG
     self.save_state(probe_positions, distances, new_params)