void unified_bed_leveling::reset() { const bool was_enabled = planner.leveling_active; set_bed_leveling_enabled(false); storage_slot = -1; #if ENABLED(ENABLE_LEVELING_FADE_HEIGHT) planner.set_z_fade_height(10.0); #endif ZERO(z_values); if (was_enabled) report_current_position(); }
void Bed_level::mesh_probing_done() { mbl.set_has_mesh(true); home_all_axes(); set_bed_leveling_enabled(true); #if ENABLED(MESH_G28_REST_ORIGIN) mechanics.current_position[Z_AXIS] = LOGICAL_Z_POSITION(Z_MIN_POS); mechanics.set_destination_to_current(); mechanics.line_to_destination(mechanics.homing_feedrate_mm_s[Z_AXIS]); stepper.synchronize(); #endif }
/** * Reset calibration results to zero. */ void Bed_level::reset_bed_level() { set_bed_leveling_enabled(false); #if ENABLED(MESH_BED_LEVELING) if (leveling_is_valid()) { mbl.reset(); mbl.set_has_mesh(false); } #else #if ENABLED(DEBUG_LEVELING_FEATURE) if (DEBUGGING(LEVELING)) SERIAL_EM("Reset Bed Level"); #endif #if ABL_PLANAR bed_level_matrix.set_to_identity(); #elif ENABLED(AUTO_BED_LEVELING_BILINEAR) bilinear_start[X_AXIS] = bilinear_start[Y_AXIS] = bilinear_grid_spacing[X_AXIS] = bilinear_grid_spacing[Y_AXIS] = 0; for (uint8_t x = 0; x < GRID_MAX_POINTS_X; x++) for (uint8_t y = 0; y < GRID_MAX_POINTS_Y; y++) z_values[x][y] = NAN; #endif #endif }
/** * Perform a tool-change, which may result in moving the * previous tool out of the way and the new tool into place. */ void tool_change(const uint8_t tmp_extruder, const float fr_mm_s/*=0.0*/, bool no_move/*=false*/) { #if ENABLED(MIXING_EXTRUDER) UNUSED(fr_mm_s); UNUSED(no_move); if (tmp_extruder >= MIXING_VIRTUAL_TOOLS) return invalid_extruder_error(tmp_extruder); #if MIXING_VIRTUAL_TOOLS > 1 // T0-Tnnn: Switch virtual tool by changing the index to the mix mixer.T(tmp_extruder); #endif #elif ENABLED(PRUSA_MMU2) UNUSED(fr_mm_s); UNUSED(no_move); mmu2.toolChange(tmp_extruder); #elif EXTRUDERS < 2 UNUSED(fr_mm_s); UNUSED(no_move); if (tmp_extruder) invalid_extruder_error(tmp_extruder); return; #else // EXTRUDERS > 1 planner.synchronize(); #if ENABLED(DUAL_X_CARRIAGE) // Only T0 allowed if the Printer is in DXC_DUPLICATION_MODE or DXC_MIRRORED_MODE if (tmp_extruder != 0 && dxc_is_duplicating()) return invalid_extruder_error(tmp_extruder); #endif #if HAS_LEVELING // Set current position to the physical position const bool leveling_was_active = planner.leveling_active; set_bed_leveling_enabled(false); #endif if (tmp_extruder >= EXTRUDERS) return invalid_extruder_error(tmp_extruder); if (!no_move && !all_axes_homed()) { no_move = true; if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPGM("No move on toolchange"); } #if HAS_LCD_MENU ui.return_to_status(); #endif #if ENABLED(TOOLCHANGE_FILAMENT_SWAP) const bool should_swap = !no_move && toolchange_settings.swap_length; #if ENABLED(PREVENT_COLD_EXTRUSION) const bool too_cold = !DEBUGGING(DRYRUN) && (thermalManager.targetTooColdToExtrude(active_extruder) || thermalManager.targetTooColdToExtrude(tmp_extruder)); #else constexpr bool too_cold = false; #endif if (should_swap) { if (too_cold) { SERIAL_ECHO_MSG(MSG_ERR_HOTEND_TOO_COLD); #if ENABLED(SINGLENOZZLE) active_extruder = tmp_extruder; return; #endif } else { #if ENABLED(ADVANCED_PAUSE_FEATURE) do_pause_e_move(-toolchange_settings.swap_length, MMM_TO_MMS(toolchange_settings.retract_speed)); #else current_position[E_AXIS] -= toolchange_settings.swap_length / planner.e_factor[active_extruder]; planner.buffer_line(current_position, MMM_TO_MMS(toolchange_settings.retract_speed), active_extruder); #endif } } #endif // TOOLCHANGE_FILAMENT_SWAP if (tmp_extruder != active_extruder) { #if SWITCHING_NOZZLE_TWO_SERVOS raise_nozzle(active_extruder); #endif const float old_feedrate_mm_s = fr_mm_s > 0.0 ? fr_mm_s : feedrate_mm_s; feedrate_mm_s = fr_mm_s > 0.0 ? fr_mm_s : XY_PROBE_FEEDRATE_MM_S; #if HAS_SOFTWARE_ENDSTOPS && ENABLED(DUAL_X_CARRIAGE) update_software_endstops(X_AXIS, active_extruder, tmp_extruder); #endif set_destination_from_current(); if (!no_move) { #if DISABLED(SWITCHING_NOZZLE) // Do a small lift to avoid the workpiece in the move back (below) #if ENABLED(TOOLCHANGE_PARK) current_position[X_AXIS] = toolchange_settings.change_point.x; current_position[Y_AXIS] = toolchange_settings.change_point.y; #endif current_position[Z_AXIS] += toolchange_settings.z_raise; #if HAS_SOFTWARE_ENDSTOPS NOMORE(current_position[Z_AXIS], soft_endstop[Z_AXIS].max); #endif planner.buffer_line(current_position, feedrate_mm_s, active_extruder); #endif planner.synchronize(); } #if HAS_HOTEND_OFFSET #if ENABLED(DUAL_X_CARRIAGE) constexpr float xdiff = 0; #else const float xdiff = hotend_offset[X_AXIS][tmp_extruder] - hotend_offset[X_AXIS][active_extruder]; #endif const float ydiff = hotend_offset[Y_AXIS][tmp_extruder] - hotend_offset[Y_AXIS][active_extruder], zdiff = hotend_offset[Z_AXIS][tmp_extruder] - hotend_offset[Z_AXIS][active_extruder]; #else constexpr float xdiff = 0, ydiff = 0, zdiff = 0; #endif #if ENABLED(DUAL_X_CARRIAGE) dualx_tool_change(tmp_extruder, no_move); #elif ENABLED(PARKING_EXTRUDER) // Dual Parking extruder parking_extruder_tool_change(tmp_extruder, no_move); #elif ENABLED(MAGNETIC_PARKING_EXTRUDER) // Magnetic Parking extruder magnetic_parking_extruder_tool_change(tmp_extruder); #elif ENABLED(SWITCHING_TOOLHEAD) // Switching Toolhead switching_toolhead_tool_change(tmp_extruder, fr_mm_s, no_move); #elif ENABLED(SWITCHING_NOZZLE) && !SWITCHING_NOZZLE_TWO_SERVOS // Raise by a configured distance to avoid workpiece, except with // SWITCHING_NOZZLE_TWO_SERVOS, as both nozzles will lift instead. current_position[Z_AXIS] += MAX(-zdiff, 0.0) + toolchange_settings.z_raise; #if HAS_SOFTWARE_ENDSTOPS NOMORE(current_position[Z_AXIS], soft_endstop[Z_AXIS].max); #endif if (!no_move) fast_line_to_current(Z_AXIS); move_nozzle_servo(tmp_extruder); #endif if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPAIR("Offset Tool XY by { ", xdiff, ", ", ydiff, ", ", zdiff, " }"); // The newly-selected extruder XY is actually at... current_position[X_AXIS] += xdiff; current_position[Y_AXIS] += ydiff; current_position[Z_AXIS] += zdiff; // Set the new active extruder if not already done in tool specific function above active_extruder = tmp_extruder; // Tell the planner the new "current position" sync_plan_position(); #if ENABLED(DELTA) //LOOP_XYZ(i) update_software_endstops(i); // or modify the constrain function const bool safe_to_move = current_position[Z_AXIS] < delta_clip_start_height - 1; #else constexpr bool safe_to_move = true; #endif // Return to position and lower again if (safe_to_move && !no_move && IsRunning()) { if (DEBUGGING(LEVELING)) DEBUG_POS("Move back", destination); #if ENABLED(SINGLENOZZLE) #if FAN_COUNT > 0 singlenozzle_fan_speed[active_extruder] = thermalManager.fan_speed[0]; thermalManager.fan_speed[0] = singlenozzle_fan_speed[tmp_extruder]; #endif singlenozzle_temp[active_extruder] = thermalManager.temp_hotend[0].target; if (singlenozzle_temp[tmp_extruder] && singlenozzle_temp[tmp_extruder] != singlenozzle_temp[active_extruder]) { thermalManager.setTargetHotend(singlenozzle_temp[tmp_extruder], 0); #if EITHER(ULTRA_LCD, EXTENSIBLE_UI) thermalManager.set_heating_message(0); #endif (void)thermalManager.wait_for_hotend(0, false); // Wait for heating or cooling } active_extruder = tmp_extruder; #endif #if ENABLED(TOOLCHANGE_FILAMENT_SWAP) if (should_swap && !too_cold) { #if ENABLED(ADVANCED_PAUSE_FEATURE) do_pause_e_move(toolchange_settings.swap_length + TOOLCHANGE_FIL_EXTRA_PRIME, toolchange_settings.prime_speed); #else current_position[E_AXIS] += (toolchange_settings.swap_length + TOOLCHANGE_FIL_EXTRA_PRIME) / planner.e_factor[tmp_extruder]; planner.buffer_line(current_position, toolchange_settings.prime_speed, tmp_extruder); #endif planner.synchronize(); #if TOOLCHANGE_FIL_EXTRA_PRIME planner.set_e_position_mm((destination[E_AXIS] = current_position[E_AXIS] = current_position[E_AXIS] - (TOOLCHANGE_FIL_EXTRA_PRIME))); #endif } #endif // Prevent a move outside physical bounds apply_motion_limits(destination); // Move back to the original (or tweaked) position do_blocking_move_to(destination); #if ENABLED(DUAL_X_CARRIAGE) active_extruder_parked = false; #endif feedrate_mm_s = old_feedrate_mm_s; } #if ENABLED(SWITCHING_NOZZLE) else { // Move back down. (Including when the new tool is higher.) do_blocking_move_to_z(destination[Z_AXIS], planner.settings.max_feedrate_mm_s[Z_AXIS]); } #endif #if ENABLED(PRUSA_MMU2) mmu2.toolChange(tmp_extruder); #endif #if SWITCHING_NOZZLE_TWO_SERVOS lower_nozzle(active_extruder); #endif #if ENABLED(TOOLCHANGE_FILAMENT_SWAP) && ADVANCED_PAUSE_RESUME_PRIME != 0 if (should_swap && !too_cold) { const float resume_eaxis = current_position[E_AXIS]; #if ENABLED(ADVANCED_PAUSE_FEATURE) do_pause_e_move(toolchange_settings.swap_length, toolchange_settings.prime_speed); #else current_position[E_AXIS] += (ADVANCED_PAUSE_RESUME_PRIME) / planner.e_factor[active_extruder]; planner.buffer_line(current_position, ADVANCED_PAUSE_PURGE_FEEDRATE, active_extruder); #endif planner.synchronize(); planner.set_e_position_mm((destination[E_AXIS] = current_position[E_AXIS] = resume_eaxis)); } #endif } // (tmp_extruder != active_extruder) planner.synchronize(); #if ENABLED(EXT_SOLENOID) && DISABLED(PARKING_EXTRUDER) disable_all_solenoids(); enable_solenoid_on_active_extruder(); #endif #if ENABLED(MK2_MULTIPLEXER) if (tmp_extruder >= E_STEPPERS) return invalid_extruder_error(tmp_extruder); select_multiplexed_stepper(tmp_extruder); #endif #if DO_SWITCH_EXTRUDER planner.synchronize(); move_extruder_servo(active_extruder); #endif #if HAS_FANMUX fanmux_switch(active_extruder); #endif #if HAS_LEVELING // Restore leveling to re-establish the logical position set_bed_leveling_enabled(leveling_was_active); #endif SERIAL_ECHO_START(); SERIAL_ECHOLNPAIR(MSG_ACTIVE_EXTRUDER, int(active_extruder)); #endif // EXTRUDERS > 1 }
/** * G28: Home all axes according to settings * * Parameters * * None Home to all axes with no parameters. * With QUICK_HOME enabled XY will home together, then Z. * * O Home only if position is unknown * * Rn Raise by n mm/inches before homing * * Cartesian/SCARA parameters * * X Home to the X endstop * Y Home to the Y endstop * Z Home to the Z endstop * */ void GcodeSuite::G28(const bool always_home_all) { #if ENABLED(DEBUG_LEVELING_FEATURE) if (DEBUGGING(LEVELING)) { SERIAL_ECHOLNPGM(">>> G28"); log_machine_info(); } #endif #if ENABLED(DUAL_X_CARRIAGE) bool IDEX_saved_duplication_state = extruder_duplication_enabled; DualXMode IDEX_saved_mode = dual_x_carriage_mode; #endif #if ENABLED(MARLIN_DEV_MODE) if (parser.seen('S')) { LOOP_XYZ(a) set_axis_is_at_home((AxisEnum)a); sync_plan_position(); SERIAL_ECHOLNPGM("Simulated Homing"); report_current_position(); #if ENABLED(DEBUG_LEVELING_FEATURE) if (DEBUGGING(LEVELING)) SERIAL_ECHOLNPGM("<<< G28"); #endif return; } #endif if (parser.boolval('O')) { if ( #if ENABLED(HOME_AFTER_DEACTIVATE) all_axes_known() // homing needed anytime steppers deactivate #else all_axes_homed() // homing needed only if never homed #endif ) { #if ENABLED(DEBUG_LEVELING_FEATURE) if (DEBUGGING(LEVELING)) { SERIAL_ECHOLNPGM("> homing not needed, skip"); SERIAL_ECHOLNPGM("<<< G28"); } #endif return; } } // Wait for planner moves to finish! planner.synchronize(); // Disable the leveling matrix before homing #if HAS_LEVELING // Cancel the active G29 session #if ENABLED(PROBE_MANUALLY) g29_in_progress = false; #endif #if ENABLED(RESTORE_LEVELING_AFTER_G28) const bool leveling_was_active = planner.leveling_active; #endif set_bed_leveling_enabled(false); #endif #if ENABLED(CNC_WORKSPACE_PLANES) workspace_plane = PLANE_XY; #endif #if ENABLED(BLTOUCH) bltouch_init(); #endif #if ENABLED(IMPROVE_HOMING_RELIABILITY) slow_homing_t slow_homing{0}; slow_homing.acceleration.x = planner.settings.max_acceleration_mm_per_s2[X_AXIS]; slow_homing.acceleration.y = planner.settings.max_acceleration_mm_per_s2[Y_AXIS]; slow_homing.jerk.x = planner.max_jerk[X_AXIS]; slow_homing.jerk.y = planner.max_jerk[Y_AXIS]; planner.settings.max_acceleration_mm_per_s2[X_AXIS] = 100; planner.settings.max_acceleration_mm_per_s2[Y_AXIS] = 100; planner.max_jerk[X_AXIS] = 0; planner.max_jerk[Y_AXIS] = 0; // steps per sq second need to be updated to agree with the units per sq second (as they are what is used in the planner) planner.reset_acceleration_rates(); #endif // Always home with tool 0 active #if HOTENDS > 1 #if DISABLED(DELTA) || ENABLED(DELTA_HOME_TO_SAFE_ZONE) const uint8_t old_tool_index = active_extruder; #endif tool_change(0, 0, true); #endif #if ENABLED(DUAL_X_CARRIAGE) || ENABLED(DUAL_NOZZLE_DUPLICATION_MODE) extruder_duplication_enabled = false; #endif setup_for_endstop_or_probe_move(); #if ENABLED(DEBUG_LEVELING_FEATURE) if (DEBUGGING(LEVELING)) SERIAL_ECHOLNPGM("> endstops.enable(true)"); #endif endstops.enable(true); // Enable endstops for next homing move #if ENABLED(DELTA) home_delta(); UNUSED(always_home_all); #else // NOT DELTA const bool homeX = always_home_all || parser.seen('X'), homeY = always_home_all || parser.seen('Y'), homeZ = always_home_all || parser.seen('Z'), home_all = (!homeX && !homeY && !homeZ) || (homeX && homeY && homeZ); set_destination_from_current(); #if Z_HOME_DIR > 0 // If homing away from BED do Z first if (home_all || homeZ) homeaxis(Z_AXIS); #endif const float z_homing_height = ( #if ENABLED(UNKNOWN_Z_NO_RAISE) !TEST(axis_known_position, Z_AXIS) ? 0 : #endif (parser.seenval('R') ? parser.value_linear_units() : Z_HOMING_HEIGHT) ); if (z_homing_height && (home_all || homeX || homeY)) { // Raise Z before homing any other axes and z is not already high enough (never lower z) destination[Z_AXIS] = z_homing_height; if (destination[Z_AXIS] > current_position[Z_AXIS]) { #if ENABLED(DEBUG_LEVELING_FEATURE) if (DEBUGGING(LEVELING)) SERIAL_ECHOLNPAIR("Raise Z (before homing) to ", destination[Z_AXIS]); #endif do_blocking_move_to_z(destination[Z_AXIS]); } } #if ENABLED(QUICK_HOME) if (home_all || (homeX && homeY)) quick_home_xy(); #endif // Home Y (before X) #if ENABLED(HOME_Y_BEFORE_X) if (home_all || homeY #if ENABLED(CODEPENDENT_XY_HOMING) || homeX #endif ) homeaxis(Y_AXIS); #endif // Home X if (home_all || homeX #if ENABLED(CODEPENDENT_XY_HOMING) && DISABLED(HOME_Y_BEFORE_X) || homeY #endif ) { #if ENABLED(DUAL_X_CARRIAGE) // Always home the 2nd (right) extruder first active_extruder = 1; homeaxis(X_AXIS); // Remember this extruder's position for later tool change inactive_extruder_x_pos = current_position[X_AXIS]; // Home the 1st (left) extruder active_extruder = 0; homeaxis(X_AXIS); // Consider the active extruder to be parked COPY(raised_parked_position, current_position); delayed_move_time = 0; active_extruder_parked = true; #else homeaxis(X_AXIS); #endif } // Home Y (after X) #if DISABLED(HOME_Y_BEFORE_X) if (home_all || homeY) homeaxis(Y_AXIS); #endif // Home Z last if homing towards the bed #if Z_HOME_DIR < 0 if (home_all || homeZ) { #if ENABLED(Z_SAFE_HOMING) home_z_safely(); #else homeaxis(Z_AXIS); #endif #if HOMING_Z_WITH_PROBE && defined(Z_AFTER_PROBING) move_z_after_probing(); #endif } // home_all || homeZ #endif // Z_HOME_DIR < 0 sync_plan_position(); #endif // !DELTA (G28) /** * Preserve DXC mode across a G28 for IDEX printers in DXC_DUPLICATION_MODE. * This is important because it lets a user use the LCD Panel to set an IDEX Duplication mode, and * then print a standard GCode file that contains a single print that does a G28 and has no other * IDEX specific commands in it. */ #if ENABLED(DUAL_X_CARRIAGE) if (dxc_is_duplicating()) { // Always home the 2nd (right) extruder first active_extruder = 1; homeaxis(X_AXIS); // Remember this extruder's position for later tool change inactive_extruder_x_pos = current_position[X_AXIS]; // Home the 1st (left) extruder active_extruder = 0; homeaxis(X_AXIS); // Consider the active extruder to be parked COPY(raised_parked_position, current_position); delayed_move_time = 0; active_extruder_parked = true; extruder_duplication_enabled = IDEX_saved_duplication_state; extruder_duplication_enabled = false; dual_x_carriage_mode = IDEX_saved_mode; stepper.set_directions(); } #endif // DUAL_X_CARRIAGE endstops.not_homing(); #if ENABLED(DELTA) && ENABLED(DELTA_HOME_TO_SAFE_ZONE) // move to a height where we can use the full xy-area do_blocking_move_to_z(delta_clip_start_height); #endif #if HAS_LEVELING && ENABLED(RESTORE_LEVELING_AFTER_G28) set_bed_leveling_enabled(leveling_was_active); #endif clean_up_after_endstop_or_probe_move(); // Restore the active tool after homing #if HOTENDS > 1 && (DISABLED(DELTA) || ENABLED(DELTA_HOME_TO_SAFE_ZONE)) #if ENABLED(PARKING_EXTRUDER) #define NO_FETCH false // fetch the previous toolhead #else #define NO_FETCH true #endif tool_change(old_tool_index, 0, NO_FETCH); #endif #if ENABLED(IMPROVE_HOMING_RELIABILITY) planner.settings.max_acceleration_mm_per_s2[X_AXIS] = slow_homing.acceleration.x; planner.settings.max_acceleration_mm_per_s2[Y_AXIS] = slow_homing.acceleration.y; planner.max_jerk[X_AXIS] = slow_homing.jerk.x; planner.max_jerk[Y_AXIS] = slow_homing.jerk.y; // steps per sq second need to be updated to agree with the units per sq second (as they are what is used in the planner) planner.reset_acceleration_rates(); #endif ui.refresh(); report_current_position(); #if ENABLED(NANODLP_Z_SYNC) #if ENABLED(NANODLP_ALL_AXIS) #define _HOME_SYNC true // For any axis, output sync text. #else #define _HOME_SYNC (home_all || homeZ) // Only for Z-axis #endif if (_HOME_SYNC) SERIAL_ECHOLNPGM(MSG_Z_MOVE_COMP); #endif #if ENABLED(DEBUG_LEVELING_FEATURE) if (DEBUGGING(LEVELING)) SERIAL_ECHOLNPGM("<<< G28"); #endif #if HAS_DRIVER(L6470) // Set L6470 absolute position registers to counts for (uint8_t j = 1; j <= L6470::chain[0]; j++) { const uint8_t cv = L6470::chain[j]; L6470.set_param(cv, L6470_ABS_POS, stepper.position((AxisEnum)L6470.axis_xref[cv])); } #endif }
void unified_bed_leveling::invalidate() { set_bed_leveling_enabled(false); set_all_mesh_points_to_value(NAN); }
/** * M48: Z probe repeatability measurement function. * * Usage: * M48 <P#> <X#> <Y#> <V#> <E> <L#> <S> * P = Number of sampled points (4-50, default 10) * X = Sample X position * Y = Sample Y position * V = Verbose level (0-4, default=1) * E = Engage Z probe for each reading * L = Number of legs of movement before probe * S = Schizoid (Or Star if you prefer) * * This function requires the machine to be homed before invocation. */ void GcodeSuite::M48() { if (axis_unhomed_error()) return; const int8_t verbose_level = parser.byteval('V', 1); if (!WITHIN(verbose_level, 0, 4)) { SERIAL_ECHOLNPGM("?(V)erbose level is implausible (0-4)."); return; } if (verbose_level > 0) SERIAL_ECHOLNPGM("M48 Z-Probe Repeatability Test"); const int8_t n_samples = parser.byteval('P', 10); if (!WITHIN(n_samples, 4, 50)) { SERIAL_ECHOLNPGM("?Sample size not plausible (4-50)."); return; } const ProbePtRaise raise_after = parser.boolval('E') ? PROBE_PT_STOW : PROBE_PT_RAISE; float X_current = current_position[X_AXIS], Y_current = current_position[Y_AXIS]; const float X_probe_location = parser.linearval('X', X_current + X_PROBE_OFFSET_FROM_EXTRUDER), Y_probe_location = parser.linearval('Y', Y_current + Y_PROBE_OFFSET_FROM_EXTRUDER); if (!position_is_reachable_by_probe(X_probe_location, Y_probe_location)) { SERIAL_ECHOLNPGM("? (X,Y) out of bounds."); return; } bool seen_L = parser.seen('L'); uint8_t n_legs = seen_L ? parser.value_byte() : 0; if (n_legs > 15) { SERIAL_ECHOLNPGM("?Number of legs in movement not plausible (0-15)."); return; } if (n_legs == 1) n_legs = 2; const bool schizoid_flag = parser.boolval('S'); if (schizoid_flag && !seen_L) n_legs = 7; /** * Now get everything to the specified probe point So we can safely do a * probe to get us close to the bed. If the Z-Axis is far from the bed, * we don't want to use that as a starting point for each probe. */ if (verbose_level > 2) SERIAL_ECHOLNPGM("Positioning the probe..."); // Disable bed level correction in M48 because we want the raw data when we probe #if HAS_LEVELING const bool was_enabled = planner.leveling_active; set_bed_leveling_enabled(false); #endif setup_for_endstop_or_probe_move(); float mean = 0.0, sigma = 0.0, min = 99999.9, max = -99999.9, sample_set[n_samples]; // Move to the first point, deploy, and probe const float t = probe_pt(X_probe_location, Y_probe_location, raise_after, verbose_level); bool probing_good = !isnan(t); if (probing_good) { randomSeed(millis()); for (uint8_t n = 0; n < n_samples; n++) { if (n_legs) { const int dir = (random(0, 10) > 5.0) ? -1 : 1; // clockwise or counter clockwise float angle = random(0, 360); const float radius = random( #if ENABLED(DELTA) (int) (0.1250000000 * (DELTA_PRINTABLE_RADIUS)), (int) (0.3333333333 * (DELTA_PRINTABLE_RADIUS)) #else (int) 5.0, (int) (0.125 * MIN(X_BED_SIZE, Y_BED_SIZE)) #endif ); if (verbose_level > 3) { SERIAL_ECHOPAIR("Starting radius: ", radius); SERIAL_ECHOPAIR(" angle: ", angle); SERIAL_ECHOPGM(" Direction: "); if (dir > 0) SERIAL_ECHOPGM("Counter-"); SERIAL_ECHOLNPGM("Clockwise"); } for (uint8_t l = 0; l < n_legs - 1; l++) { float delta_angle; if (schizoid_flag) // The points of a 5 point star are 72 degrees apart. We need to // skip a point and go to the next one on the star. delta_angle = dir * 2.0 * 72.0; else // If we do this line, we are just trying to move further // around the circle. delta_angle = dir * (float) random(25, 45); angle += delta_angle; while (angle > 360.0) // We probably do not need to keep the angle between 0 and 2*PI, but the angle -= 360.0; // Arduino documentation says the trig functions should not be given values while (angle < 0.0) // outside of this range. It looks like they behave correctly with angle += 360.0; // numbers outside of the range, but just to be safe we clamp them. X_current = X_probe_location - (X_PROBE_OFFSET_FROM_EXTRUDER) + cos(RADIANS(angle)) * radius; Y_current = Y_probe_location - (Y_PROBE_OFFSET_FROM_EXTRUDER) + sin(RADIANS(angle)) * radius; #if DISABLED(DELTA) X_current = constrain(X_current, X_MIN_POS, X_MAX_POS); Y_current = constrain(Y_current, Y_MIN_POS, Y_MAX_POS); #else // If we have gone out too far, we can do a simple fix and scale the numbers // back in closer to the origin. while (!position_is_reachable_by_probe(X_current, Y_current)) { X_current *= 0.8; Y_current *= 0.8; if (verbose_level > 3) { SERIAL_ECHOPAIR("Pulling point towards center:", X_current); SERIAL_ECHOLNPAIR(", ", Y_current); } } #endif if (verbose_level > 3) { SERIAL_ECHOPGM("Going to:"); SERIAL_ECHOPAIR(" X", X_current); SERIAL_ECHOPAIR(" Y", Y_current); SERIAL_ECHOLNPAIR(" Z", current_position[Z_AXIS]); } do_blocking_move_to_xy(X_current, Y_current); } // n_legs loop } // n_legs // Probe a single point sample_set[n] = probe_pt(X_probe_location, Y_probe_location, raise_after, 0); // Break the loop if the probe fails probing_good = !isnan(sample_set[n]); if (!probing_good) break; /** * Get the current mean for the data points we have so far */ float sum = 0.0; for (uint8_t j = 0; j <= n; j++) sum += sample_set[j]; mean = sum / (n + 1); NOMORE(min, sample_set[n]); NOLESS(max, sample_set[n]); /** * Now, use that mean to calculate the standard deviation for the * data points we have so far */ sum = 0.0; for (uint8_t j = 0; j <= n; j++) sum += sq(sample_set[j] - mean); sigma = SQRT(sum / (n + 1)); if (verbose_level > 0) { if (verbose_level > 1) { SERIAL_ECHO(n + 1); SERIAL_ECHOPAIR(" of ", (int)n_samples); SERIAL_ECHOPAIR_F(": z: ", sample_set[n], 3); if (verbose_level > 2) { SERIAL_ECHOPAIR_F(" mean: ", mean, 4); SERIAL_ECHOPAIR_F(" sigma: ", sigma, 6); SERIAL_ECHOPAIR_F(" min: ", min, 3); SERIAL_ECHOPAIR_F(" max: ", max, 3); SERIAL_ECHOPAIR_F(" range: ", max-min, 3); } SERIAL_EOL(); } } } // n_samples loop } STOW_PROBE(); if (probing_good) { SERIAL_ECHOLNPGM("Finished!"); if (verbose_level > 0) { SERIAL_ECHOPAIR_F("Mean: ", mean, 6); SERIAL_ECHOPAIR_F(" Min: ", min, 3); SERIAL_ECHOPAIR_F(" Max: ", max, 3); SERIAL_ECHOLNPAIR_F(" Range: ", max-min, 3); } SERIAL_ECHOLNPAIR_F("Standard Deviation: ", sigma, 6); SERIAL_EOL(); } clean_up_after_endstop_or_probe_move(); // Re-enable bed level correction if it had been on #if HAS_LEVELING set_bed_leveling_enabled(was_enabled); #endif report_current_position(); }
/** * G26: Mesh Validation Pattern generation. * * Used to interactively edit the mesh by placing the * nozzle in a problem area and doing a G29 P4 R command. * * Parameters: * * B Bed Temperature * C Continue from the Closest mesh point * D Disable leveling before starting * F Filament diameter * H Hotend Temperature * K Keep heaters on when completed * L Layer Height * O Ooze extrusion length * P Prime length * Q Retraction multiplier * R Repetitions (number of grid points) * S Nozzle Size (diameter) in mm * T Tool index to change to, if included * U Random deviation (50 if no value given) * X X position * Y Y position */ void GcodeSuite::G26() { SERIAL_ECHOLNPGM("G26 starting..."); // Don't allow Mesh Validation without homing first, // or if the parameter parsing did not go OK, abort if (axis_unhomed_error()) return; // Change the tool first, if specified if (parser.seenval('T')) tool_change(parser.value_int()); g26_extrusion_multiplier = EXTRUSION_MULTIPLIER; g26_retraction_multiplier = RETRACTION_MULTIPLIER; g26_layer_height = MESH_TEST_LAYER_HEIGHT; g26_prime_length = PRIME_LENGTH; g26_bed_temp = MESH_TEST_BED_TEMP; g26_hotend_temp = MESH_TEST_HOTEND_TEMP; g26_prime_flag = 0; float g26_nozzle = MESH_TEST_NOZZLE_SIZE, g26_filament_diameter = DEFAULT_NOMINAL_FILAMENT_DIA, g26_ooze_amount = parser.linearval('O', OOZE_AMOUNT); bool g26_continue_with_closest = parser.boolval('C'), g26_keep_heaters_on = parser.boolval('K'); if (parser.seenval('B')) { g26_bed_temp = parser.value_celsius(); if (g26_bed_temp && !WITHIN(g26_bed_temp, 40, 140)) { SERIAL_ECHOLNPGM("?Specified bed temperature not plausible (40-140C)."); return; } } if (parser.seenval('L')) { g26_layer_height = parser.value_linear_units(); if (!WITHIN(g26_layer_height, 0.0, 2.0)) { SERIAL_ECHOLNPGM("?Specified layer height not plausible."); return; } } if (parser.seen('Q')) { if (parser.has_value()) { g26_retraction_multiplier = parser.value_float(); if (!WITHIN(g26_retraction_multiplier, 0.05, 15.0)) { SERIAL_ECHOLNPGM("?Specified Retraction Multiplier not plausible."); return; } } else { SERIAL_ECHOLNPGM("?Retraction Multiplier must be specified."); return; } } if (parser.seenval('S')) { g26_nozzle = parser.value_float(); if (!WITHIN(g26_nozzle, 0.1, 1.0)) { SERIAL_ECHOLNPGM("?Specified nozzle size not plausible."); return; } } if (parser.seen('P')) { if (!parser.has_value()) { #if HAS_LCD_MENU g26_prime_flag = -1; #else SERIAL_ECHOLNPGM("?Prime length must be specified when not using an LCD."); return; #endif } else { g26_prime_flag++; g26_prime_length = parser.value_linear_units(); if (!WITHIN(g26_prime_length, 0.0, 25.0)) { SERIAL_ECHOLNPGM("?Specified prime length not plausible."); return; } } } if (parser.seenval('F')) { g26_filament_diameter = parser.value_linear_units(); if (!WITHIN(g26_filament_diameter, 1.0, 4.0)) { SERIAL_ECHOLNPGM("?Specified filament size not plausible."); return; } } g26_extrusion_multiplier *= sq(1.75) / sq(g26_filament_diameter); // If we aren't using 1.75mm filament, we need to // scale up or down the length needed to get the // same volume of filament g26_extrusion_multiplier *= g26_filament_diameter * sq(g26_nozzle) / sq(0.3); // Scale up by nozzle size if (parser.seenval('H')) { g26_hotend_temp = parser.value_celsius(); if (!WITHIN(g26_hotend_temp, 165, 280)) { SERIAL_ECHOLNPGM("?Specified nozzle temperature not plausible."); return; } } if (parser.seen('U')) { randomSeed(millis()); // This setting will persist for the next G26 random_deviation = parser.has_value() ? parser.value_float() : 50.0; } int16_t g26_repeats; #if HAS_LCD_MENU g26_repeats = parser.intval('R', GRID_MAX_POINTS + 1); #else if (!parser.seen('R')) { SERIAL_ECHOLNPGM("?(R)epeat must be specified when not using an LCD."); return; } else g26_repeats = parser.has_value() ? parser.value_int() : GRID_MAX_POINTS + 1; #endif if (g26_repeats < 1) { SERIAL_ECHOLNPGM("?(R)epeat value not plausible; must be at least 1."); return; } g26_x_pos = parser.seenval('X') ? RAW_X_POSITION(parser.value_linear_units()) : current_position[X_AXIS]; g26_y_pos = parser.seenval('Y') ? RAW_Y_POSITION(parser.value_linear_units()) : current_position[Y_AXIS]; if (!position_is_reachable(g26_x_pos, g26_y_pos)) { SERIAL_ECHOLNPGM("?Specified X,Y coordinate out of bounds."); return; } /** * Wait until all parameters are verified before altering the state! */ set_bed_leveling_enabled(!parser.seen('D')); if (current_position[Z_AXIS] < Z_CLEARANCE_BETWEEN_PROBES) { do_blocking_move_to_z(Z_CLEARANCE_BETWEEN_PROBES); set_current_from_destination(); } if (turn_on_heaters() != G26_OK) goto LEAVE; current_position[E_AXIS] = 0.0; sync_plan_position_e(); if (g26_prime_flag && prime_nozzle() != G26_OK) goto LEAVE; /** * Bed is preheated * * Nozzle is at temperature * * Filament is primed! * * It's "Show Time" !!! */ ZERO(circle_flags); ZERO(horizontal_mesh_line_flags); ZERO(vertical_mesh_line_flags); // Move nozzle to the specified height for the first layer set_destination_from_current(); destination[Z_AXIS] = g26_layer_height; move_to(destination, 0.0); move_to(destination, g26_ooze_amount); #if HAS_LCD_MENU ui.capture(); #endif //debug_current_and_destination(PSTR("Starting G26 Mesh Validation Pattern.")); #if DISABLED(ARC_SUPPORT) /** * Pre-generate radius offset values at 30 degree intervals to reduce CPU load. */ #define A_INT 30 #define _ANGS (360 / A_INT) #define A_CNT (_ANGS / 2) #define _IND(A) ((A + _ANGS * 8) % _ANGS) #define _COS(A) (trig_table[_IND(A) % A_CNT] * (_IND(A) >= A_CNT ? -1 : 1)) #define _SIN(A) (-_COS((A + A_CNT / 2) % _ANGS)) #if A_CNT & 1 #error "A_CNT must be a positive value. Please change A_INT." #endif float trig_table[A_CNT]; for (uint8_t i = 0; i < A_CNT; i++) trig_table[i] = INTERSECTION_CIRCLE_RADIUS * cos(RADIANS(i * A_INT)); #endif // !ARC_SUPPORT mesh_index_pair location; do { location = g26_continue_with_closest ? find_closest_circle_to_print(current_position[X_AXIS], current_position[Y_AXIS]) : find_closest_circle_to_print(g26_x_pos, g26_y_pos); // Find the closest Mesh Intersection to where we are now. if (location.x_index >= 0 && location.y_index >= 0) { const float circle_x = _GET_MESH_X(location.x_index), circle_y = _GET_MESH_Y(location.y_index); // If this mesh location is outside the printable_radius, skip it. if (!position_is_reachable(circle_x, circle_y)) continue; // Determine where to start and end the circle, // which is always drawn counter-clockwise. const uint8_t xi = location.x_index, yi = location.y_index; const bool f = yi == 0, r = xi >= GRID_MAX_POINTS_X - 1, b = yi >= GRID_MAX_POINTS_Y - 1; #if ENABLED(ARC_SUPPORT) #define ARC_LENGTH(quarters) (INTERSECTION_CIRCLE_RADIUS * M_PI * (quarters) / 2) float sx = circle_x + INTERSECTION_CIRCLE_RADIUS, // default to full circle ex = circle_x + INTERSECTION_CIRCLE_RADIUS, sy = circle_y, ey = circle_y, arc_length = ARC_LENGTH(4); // Figure out where to start and end the arc - we always print counterclockwise if (xi == 0) { // left edge sx = f ? circle_x + INTERSECTION_CIRCLE_RADIUS : circle_x; ex = b ? circle_x + INTERSECTION_CIRCLE_RADIUS : circle_x; sy = f ? circle_y : circle_y - (INTERSECTION_CIRCLE_RADIUS); ey = b ? circle_y : circle_y + INTERSECTION_CIRCLE_RADIUS; arc_length = (f || b) ? ARC_LENGTH(1) : ARC_LENGTH(2); } else if (r) { // right edge sx = b ? circle_x - (INTERSECTION_CIRCLE_RADIUS) : circle_x; ex = f ? circle_x - (INTERSECTION_CIRCLE_RADIUS) : circle_x; sy = b ? circle_y : circle_y + INTERSECTION_CIRCLE_RADIUS; ey = f ? circle_y : circle_y - (INTERSECTION_CIRCLE_RADIUS); arc_length = (f || b) ? ARC_LENGTH(1) : ARC_LENGTH(2); } else if (f) { sx = circle_x + INTERSECTION_CIRCLE_RADIUS; ex = circle_x - (INTERSECTION_CIRCLE_RADIUS); sy = ey = circle_y; arc_length = ARC_LENGTH(2); } else if (b) { sx = circle_x - (INTERSECTION_CIRCLE_RADIUS); ex = circle_x + INTERSECTION_CIRCLE_RADIUS; sy = ey = circle_y; arc_length = ARC_LENGTH(2); } const float arc_offset[2] = { circle_x - sx, circle_y - sy }; const float dx_s = current_position[X_AXIS] - sx, // find our distance from the start of the actual circle dy_s = current_position[Y_AXIS] - sy, dist_start = HYPOT2(dx_s, dy_s); const float endpoint[XYZE] = { ex, ey, g26_layer_height, current_position[E_AXIS] + (arc_length * g26_e_axis_feedrate * g26_extrusion_multiplier) }; if (dist_start > 2.0) { retract_filament(destination); //todo: parameterize the bump height with a define move_to(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS] + 0.500, 0.0); // Z bump to minimize scraping move_to(sx, sy, g26_layer_height + 0.500, 0.0); // Get to the starting point with no extrusion while bumped } move_to(sx, sy, g26_layer_height, 0.0); // Get to the starting point with no extrusion / un-Z bump recover_filament(destination); const float save_feedrate = feedrate_mm_s; feedrate_mm_s = PLANNER_XY_FEEDRATE() / 10.0; if (g26_debug_flag) { SERIAL_ECHOPAIR(" plan_arc(ex=", endpoint[X_AXIS]); SERIAL_ECHOPAIR(", ey=", endpoint[Y_AXIS]); SERIAL_ECHOPAIR(", ez=", endpoint[Z_AXIS]); SERIAL_ECHOPAIR(", len=", arc_length); SERIAL_ECHOPAIR(") -> (ex=", current_position[X_AXIS]); SERIAL_ECHOPAIR(", ey=", current_position[Y_AXIS]); SERIAL_ECHOPAIR(", ez=", current_position[Z_AXIS]); SERIAL_CHAR(')'); SERIAL_EOL(); } plan_arc(endpoint, arc_offset, false); // Draw a counter-clockwise arc feedrate_mm_s = save_feedrate; set_destination_from_current(); #if HAS_LCD_MENU if (user_canceled()) goto LEAVE; // Check if the user wants to stop the Mesh Validation #endif #else // !ARC_SUPPORT int8_t start_ind = -2, end_ind = 9; // Assume a full circle (from 5:00 to 5:00) if (xi == 0) { // Left edge? Just right half. start_ind = f ? 0 : -3; // 03:00 to 12:00 for front-left end_ind = b ? 0 : 2; // 06:00 to 03:00 for back-left } else if (r) { // Right edge? Just left half. start_ind = b ? 6 : 3; // 12:00 to 09:00 for front-right end_ind = f ? 5 : 8; // 09:00 to 06:00 for back-right } else if (f) { // Front edge? Just back half. start_ind = 0; // 03:00 end_ind = 5; // 09:00 } else if (b) { // Back edge? Just front half. start_ind = 6; // 09:00 end_ind = 11; // 03:00 } for (int8_t ind = start_ind; ind <= end_ind; ind++) { #if HAS_LCD_MENU if (user_canceled()) goto LEAVE; // Check if the user wants to stop the Mesh Validation #endif float rx = circle_x + _COS(ind), // For speed, these are now a lookup table entry ry = circle_y + _SIN(ind), xe = circle_x + _COS(ind + 1), ye = circle_y + _SIN(ind + 1); #if IS_KINEMATIC // Check to make sure this segment is entirely on the bed, skip if not. if (!position_is_reachable(rx, ry) || !position_is_reachable(xe, ye)) continue; #else // not, we need to skip rx = constrain(rx, X_MIN_POS + 1, X_MAX_POS - 1); // This keeps us from bumping the endstops ry = constrain(ry, Y_MIN_POS + 1, Y_MAX_POS - 1); xe = constrain(xe, X_MIN_POS + 1, X_MAX_POS - 1); ye = constrain(ye, Y_MIN_POS + 1, Y_MAX_POS - 1); #endif print_line_from_here_to_there(rx, ry, g26_layer_height, xe, ye, g26_layer_height); SERIAL_FLUSH(); // Prevent host M105 buffer overrun. } #endif // !ARC_SUPPORT if (look_for_lines_to_connect()) goto LEAVE; } SERIAL_FLUSH(); // Prevent host M105 buffer overrun. } while (--g26_repeats && location.x_index >= 0 && location.y_index >= 0); LEAVE: ui.set_status_P(PSTR("Leaving G26"), -1); retract_filament(destination); destination[Z_AXIS] = Z_CLEARANCE_BETWEEN_PROBES; //debug_current_and_destination(PSTR("ready to do Z-Raise.")); move_to(destination, 0); // Raise the nozzle //debug_current_and_destination(PSTR("done doing Z-Raise.")); destination[X_AXIS] = g26_x_pos; // Move back to the starting position destination[Y_AXIS] = g26_y_pos; //destination[Z_AXIS] = Z_CLEARANCE_BETWEEN_PROBES; // Keep the nozzle where it is move_to(destination, 0); // Move back to the starting position //debug_current_and_destination(PSTR("done doing X/Y move.")); #if HAS_LCD_MENU ui.release(); // Give back control of the LCD #endif if (!g26_keep_heaters_on) { #if HAS_HEATED_BED thermalManager.setTargetBed(0); #endif thermalManager.setTargetHotend(active_extruder, 0); } }
/** * M420: Enable/Disable Bed Leveling and/or set the Z fade height. * * S[bool] Turns leveling on or off * Z[height] Sets the Z fade height (0 or none to disable) * V[bool] Verbose - Print the leveling grid * * With AUTO_BED_LEVELING_UBL only: * * L[index] Load UBL mesh from index (0 is default) * T[map] 0:Human-readable 1:CSV 2:"LCD" 4:Compact * * With mesh-based leveling only: * * C Center mesh on the mean of the lowest and highest * * With MARLIN_DEV_MODE: * S2 Create a simple random mesh and enable */ void GcodeSuite::M420() { const bool seen_S = parser.seen('S'), to_enable = seen_S ? parser.value_bool() : planner.leveling_active; #if ENABLED(MARLIN_DEV_MODE) if (parser.intval('S') == 2) { #if ENABLED(AUTO_BED_LEVELING_BILINEAR) bilinear_start[X_AXIS] = MIN_PROBE_X; bilinear_start[Y_AXIS] = MIN_PROBE_Y; bilinear_grid_spacing[X_AXIS] = (MAX_PROBE_X - (MIN_PROBE_X)) / (GRID_MAX_POINTS_X - 1); bilinear_grid_spacing[Y_AXIS] = (MAX_PROBE_Y - (MIN_PROBE_Y)) / (GRID_MAX_POINTS_Y - 1); #endif for (uint8_t x = 0; x < GRID_MAX_POINTS_X; x++) for (uint8_t y = 0; y < GRID_MAX_POINTS_Y; y++) Z_VALUES(x, y) = 0.001 * random(-200, 200); SERIAL_ECHOPGM("Simulated " STRINGIFY(GRID_MAX_POINTS_X) "x" STRINGIFY(GRID_MAX_POINTS_X) " mesh "); SERIAL_ECHOPAIR(" (", MIN_PROBE_X); SERIAL_CHAR(','); SERIAL_ECHO(MIN_PROBE_Y); SERIAL_ECHOPAIR(")-(", MAX_PROBE_X); SERIAL_CHAR(','); SERIAL_ECHO(MAX_PROBE_Y); SERIAL_ECHOLNPGM(")"); } #endif // If disabling leveling do it right away // (Don't disable for just M420 or M420 V) if (seen_S && !to_enable) set_bed_leveling_enabled(false); const float oldpos[] = { current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS] }; #if ENABLED(AUTO_BED_LEVELING_UBL) // L to load a mesh from the EEPROM if (parser.seen('L')) { set_bed_leveling_enabled(false); #if ENABLED(EEPROM_SETTINGS) const int8_t storage_slot = parser.has_value() ? parser.value_int() : ubl.storage_slot; const int16_t a = settings.calc_num_meshes(); if (!a) { SERIAL_ECHOLNPGM("?EEPROM storage not available."); return; } if (!WITHIN(storage_slot, 0, a - 1)) { SERIAL_ECHOLNPGM("?Invalid storage slot."); SERIAL_ECHOLNPAIR("?Use 0 to ", a - 1); return; } settings.load_mesh(storage_slot); ubl.storage_slot = storage_slot; #else SERIAL_ECHOLNPGM("?EEPROM storage not available."); return; #endif } // L or V display the map info if (parser.seen('L') || parser.seen('V')) { ubl.display_map(parser.byteval('T')); SERIAL_ECHOPGM("Mesh is "); if (!ubl.mesh_is_valid()) SERIAL_ECHOPGM("in"); SERIAL_ECHOLNPAIR("valid\nStorage slot: ", ubl.storage_slot); } #endif // AUTO_BED_LEVELING_UBL const bool seenV = parser.seen('V'); #if HAS_MESH if (leveling_is_valid()) { // Subtract the given value or the mean from all mesh values if (parser.seen('C')) { const float cval = parser.value_float(); #if ENABLED(AUTO_BED_LEVELING_UBL) set_bed_leveling_enabled(false); ubl.adjust_mesh_to_mean(true, cval); #else #if ENABLED(M420_C_USE_MEAN) // Get the sum and average of all mesh values float mesh_sum = 0; for (uint8_t x = GRID_MAX_POINTS_X; x--;) for (uint8_t y = GRID_MAX_POINTS_Y; y--;) mesh_sum += Z_VALUES(x, y); const float zmean = mesh_sum / float(GRID_MAX_POINTS); #else // Find the low and high mesh values float lo_val = 100, hi_val = -100; for (uint8_t x = GRID_MAX_POINTS_X; x--;) for (uint8_t y = GRID_MAX_POINTS_Y; y--;) { const float z = Z_VALUES(x, y); NOMORE(lo_val, z); NOLESS(hi_val, z); } // Take the mean of the lowest and highest const float zmean = (lo_val + hi_val) / 2.0 + cval; #endif // If not very close to 0, adjust the mesh if (!NEAR_ZERO(zmean)) { set_bed_leveling_enabled(false); // Subtract the mean from all values for (uint8_t x = GRID_MAX_POINTS_X; x--;) for (uint8_t y = GRID_MAX_POINTS_Y; y--;) Z_VALUES(x, y) -= zmean; #if ENABLED(ABL_BILINEAR_SUBDIVISION) bed_level_virt_interpolate(); #endif } #endif } } else if (to_enable || seenV) { SERIAL_ECHO_MSG("Invalid mesh."); goto EXIT_M420; } #endif // HAS_MESH // V to print the matrix or mesh if (seenV) { #if ABL_PLANAR planner.bed_level_matrix.debug(PSTR("Bed Level Correction Matrix:")); #else if (leveling_is_valid()) { #if ENABLED(AUTO_BED_LEVELING_BILINEAR) print_bilinear_leveling_grid(); #if ENABLED(ABL_BILINEAR_SUBDIVISION) print_bilinear_leveling_grid_virt(); #endif #elif ENABLED(MESH_BED_LEVELING) SERIAL_ECHOLNPGM("Mesh Bed Level data:"); mbl.report_mesh(); #endif } #endif } #if ENABLED(ENABLE_LEVELING_FADE_HEIGHT) if (parser.seen('Z')) set_z_fade_height(parser.value_linear_units(), false); #endif // Enable leveling if specified, or if previously active set_bed_leveling_enabled(to_enable); #if HAS_MESH EXIT_M420: #endif // Error if leveling failed to enable or reenable if (to_enable && !planner.leveling_active) SERIAL_ERROR_MSG(MSG_ERR_M420_FAILED); SERIAL_ECHO_START(); SERIAL_ECHOPGM("Bed Leveling "); serialprintln_onoff(planner.leveling_active); #if ENABLED(ENABLE_LEVELING_FADE_HEIGHT) SERIAL_ECHO_START(); SERIAL_ECHOPGM("Fade Height "); if (planner.z_fade_height > 0.0) SERIAL_ECHOLN(planner.z_fade_height); else SERIAL_ECHOLNPGM(MSG_OFF); #endif // Report change in position if (memcmp(oldpos, current_position, sizeof(oldpos))) report_current_position(); }
/** * This function used to be inline code in G26. But there are so many * parameters it made sense to turn them into static globals and get * this code out of sight of the main routine. */ bool unified_bed_leveling::parse_G26_parameters() { g26_extrusion_multiplier = EXTRUSION_MULTIPLIER; g26_retraction_multiplier = RETRACTION_MULTIPLIER; g26_nozzle = NOZZLE; g26_filament_diameter = FILAMENT; g26_layer_height = LAYER_HEIGHT; g26_prime_length = PRIME_LENGTH; g26_bed_temp = BED_TEMP; g26_hotend_temp = HOTEND_TEMP; g26_prime_flag = 0; g26_ooze_amount = parser.linearval('O', OOZE_AMOUNT); g26_keep_heaters_on = parser.boolval('K'); g26_continue_with_closest = parser.boolval('C'); if (parser.seenval('B')) { g26_bed_temp = parser.value_celsius(); if (!WITHIN(g26_bed_temp, 15, 140)) { SERIAL_PROTOCOLLNPGM("?Specified bed temperature not plausible."); return UBL_ERR; } } if (parser.seenval('L')) { g26_layer_height = parser.value_linear_units(); if (!WITHIN(g26_layer_height, 0.0, 2.0)) { SERIAL_PROTOCOLLNPGM("?Specified layer height not plausible."); return UBL_ERR; } } if (parser.seen('Q')) { if (parser.has_value()) { g26_retraction_multiplier = parser.value_float(); if (!WITHIN(g26_retraction_multiplier, 0.05, 15.0)) { SERIAL_PROTOCOLLNPGM("?Specified Retraction Multiplier not plausible."); return UBL_ERR; } } else { SERIAL_PROTOCOLLNPGM("?Retraction Multiplier must be specified."); return UBL_ERR; } } if (parser.seenval('S')) { g26_nozzle = parser.value_float(); if (!WITHIN(g26_nozzle, 0.1, 1.0)) { SERIAL_PROTOCOLLNPGM("?Specified nozzle size not plausible."); return UBL_ERR; } } if (parser.seen('P')) { if (!parser.has_value()) { #if ENABLED(NEWPANEL) g26_prime_flag = -1; #else SERIAL_PROTOCOLLNPGM("?Prime length must be specified when not using an LCD."); return UBL_ERR; #endif } else { g26_prime_flag++; g26_prime_length = parser.value_linear_units(); if (!WITHIN(g26_prime_length, 0.0, 25.0)) { SERIAL_PROTOCOLLNPGM("?Specified prime length not plausible."); return UBL_ERR; } } } if (parser.seenval('F')) { g26_filament_diameter = parser.value_linear_units(); if (!WITHIN(g26_filament_diameter, 1.0, 4.0)) { SERIAL_PROTOCOLLNPGM("?Specified filament size not plausible."); return UBL_ERR; } } g26_extrusion_multiplier *= sq(1.75) / sq(g26_filament_diameter); // If we aren't using 1.75mm filament, we need to // scale up or down the length needed to get the // same volume of filament g26_extrusion_multiplier *= g26_filament_diameter * sq(g26_nozzle) / sq(0.3); // Scale up by nozzle size if (parser.seenval('H')) { g26_hotend_temp = parser.value_celsius(); if (!WITHIN(g26_hotend_temp, 165, 280)) { SERIAL_PROTOCOLLNPGM("?Specified nozzle temperature not plausible."); return UBL_ERR; } } if (parser.seen('U')) { randomSeed(millis()); // This setting will persist for the next G26 random_deviation = parser.has_value() ? parser.value_float() : 50.0; } #if ENABLED(NEWPANEL) g26_repeats = parser.intval('R', GRID_MAX_POINTS + 1); #else if (!parser.seen('R')) { SERIAL_PROTOCOLLNPGM("?(R)epeat must be specified when not using an LCD."); return UBL_ERR; } else g26_repeats = parser.has_value() ? parser.value_int() : GRID_MAX_POINTS + 1; #endif if (g26_repeats < 1) { SERIAL_PROTOCOLLNPGM("?(R)epeat value not plausible; must be at least 1."); return UBL_ERR; } g26_x_pos = parser.linearval('X', current_position[X_AXIS]); g26_y_pos = parser.linearval('Y', current_position[Y_AXIS]); if (!position_is_reachable_xy(g26_x_pos, g26_y_pos)) { SERIAL_PROTOCOLLNPGM("?Specified X,Y coordinate out of bounds."); return UBL_ERR; } /** * Wait until all parameters are verified before altering the state! */ set_bed_leveling_enabled(!parser.seen('D')); return UBL_OK; }