code
stringlengths
1
1.05M
repo_name
stringlengths
6
83
path
stringlengths
3
242
language
stringclasses
222 values
license
stringclasses
20 values
size
int64
1
1.05M
/** * Marlin 3D Printer Firmware * Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin] * * Based on Sprinter and grbl. * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <https://www.gnu.org/licenses/>. * */ /** * G29.cpp - Mesh Bed Leveling */ #include "../../../inc/MarlinConfig.h" #if ENABLED(MESH_BED_LEVELING) #include "../../../feature/bedlevel/bedlevel.h" #include "../../gcode.h" #include "../../queue.h" #include "../../../libs/buzzer.h" #include "../../../lcd/marlinui.h" #include "../../../module/motion.h" #include "../../../module/planner.h" #if ENABLED(EXTENSIBLE_UI) #include "../../../lcd/extui/ui_api.h" #endif #define DEBUG_OUT ENABLED(DEBUG_LEVELING_FEATURE) #include "../../../core/debug_out.h" // Save 130 bytes with non-duplication of PSTR inline void echo_not_entered(const char c) { SERIAL_CHAR(c); SERIAL_ECHOLNPGM(" not entered."); } /** * G29: Mesh-based Z probe, probes a grid and produces a * mesh to compensate for variable bed height * * Parameters With MESH_BED_LEVELING: * * S0 Report the current mesh values * S1 Start probing mesh points * S2 Probe the next mesh point * S3 In Jn Zn.nn Manually modify a single point * S4 Zn.nn Set z offset. Positive away from bed, negative closer to bed. * S5 Reset and disable mesh */ void GcodeSuite::G29() { DEBUG_SECTION(log_G29, "G29", true); // G29 Q is also available if debugging #if ENABLED(DEBUG_LEVELING_FEATURE) const bool seenQ = parser.seen_test('Q'); if (seenQ || DEBUGGING(LEVELING)) { log_machine_info(); if (seenQ) return; } #endif static int mbl_probe_index = -1; MeshLevelingState state = (MeshLevelingState)parser.byteval('S', (int8_t)MeshReport); if (!WITHIN(state, 0, 5)) { SERIAL_ECHOLNPGM("S out of range (0-5)."); return; } TERN_(FULL_REPORT_TO_HOST_FEATURE, set_and_report_grblstate(M_PROBE)); int8_t ix, iy; ix = iy = 0; switch (state) { case MeshReport: SERIAL_ECHOPGM("Mesh Bed Leveling "); if (leveling_is_valid()) { serialprintln_onoff(planner.leveling_active); bedlevel.report_mesh(); } else SERIAL_ECHOLNPGM("has no data."); break; case MeshStart: bedlevel.reset(); mbl_probe_index = 0; if (!ui.wait_for_move) { if (parser.seen_test('N')) queue.inject(F("G28" TERN_(CAN_SET_LEVELING_AFTER_G28, "L0"))); // Position bed horizontally and Z probe vertically. #if HAS_SAFE_BED_LEVELING xyze_pos_t safe_position = current_position; #ifdef SAFE_BED_LEVELING_START_X safe_position.x = SAFE_BED_LEVELING_START_X; #endif #ifdef SAFE_BED_LEVELING_START_Y safe_position.y = SAFE_BED_LEVELING_START_Y; #endif #ifdef SAFE_BED_LEVELING_START_Z safe_position.z = SAFE_BED_LEVELING_START_Z; #endif #ifdef SAFE_BED_LEVELING_START_I safe_position.i = SAFE_BED_LEVELING_START_I; #endif #ifdef SAFE_BED_LEVELING_START_J safe_position.j = SAFE_BED_LEVELING_START_J; #endif #ifdef SAFE_BED_LEVELING_START_K safe_position.k = SAFE_BED_LEVELING_START_K; #endif #ifdef SAFE_BED_LEVELING_START_U safe_position.u = SAFE_BED_LEVELING_START_U; #endif #ifdef SAFE_BED_LEVELING_START_V safe_position.v = SAFE_BED_LEVELING_START_V; #endif #ifdef SAFE_BED_LEVELING_START_W safe_position.w = SAFE_BED_LEVELING_START_W; #endif do_blocking_move_to(safe_position); #endif // HAS_SAFE_BED_LEVELING queue.inject(F("G29S2")); TERN_(EXTENSIBLE_UI, ExtUI::onLevelingStart()); return; } state = MeshNext; case MeshNext: if (mbl_probe_index < 0) { SERIAL_ECHOLNPGM("Start mesh probing with \"G29 S1\" first."); return; } // For each G29 S2... if (mbl_probe_index == 0) { // Move close to the bed before the first point do_blocking_move_to_z( #ifdef MANUAL_PROBE_START_Z MANUAL_PROBE_START_Z #else 0.4f #endif ); } else { // Save Z for the previous mesh position bedlevel.set_zigzag_z(mbl_probe_index - 1, current_position.z); TERN_(EXTENSIBLE_UI, ExtUI::onMeshUpdate(ix, iy, current_position.z)); SET_SOFT_ENDSTOP_LOOSE(false); } // If there's another point to sample, move there with optional lift. if (mbl_probe_index < GRID_MAX_POINTS) { // Disable software endstops to allow manual adjustment // If G29 is left hanging without completion they won't be re-enabled! SET_SOFT_ENDSTOP_LOOSE(true); bedlevel.zigzag(mbl_probe_index++, ix, iy); _manual_goto_xy({ bedlevel.index_to_xpos[ix], bedlevel.index_to_ypos[iy] }); } else { // Move to the after probing position current_position.z = ( #ifdef Z_AFTER_PROBING Z_AFTER_PROBING #else Z_CLEARANCE_BETWEEN_MANUAL_PROBES #endif ); line_to_current_position(); planner.synchronize(); // After recording the last point, activate home and activate mbl_probe_index = -1; SERIAL_ECHOLNPGM("Mesh probing done."); TERN_(HAS_STATUS_MESSAGE, LCD_MESSAGE(MSG_MESH_DONE)); OKAY_BUZZ(); home_all_axes(); set_bed_leveling_enabled(true); #if ENABLED(MESH_G28_REST_ORIGIN) current_position.z = 0; line_to_current_position(homing_feedrate(Z_AXIS)); planner.synchronize(); #endif TERN_(LCD_BED_LEVELING, ui.wait_for_move = false); TERN_(EXTENSIBLE_UI, ExtUI::onLevelingDone()); } break; case MeshSet: if (parser.seenval('I')) { ix = parser.value_int(); if (!WITHIN(ix, 0, (GRID_MAX_POINTS_X) - 1)) { SERIAL_ECHOLNPGM("I out of range (0-", (GRID_MAX_POINTS_X) - 1, ")"); return; } } else return echo_not_entered('J'); if (parser.seenval('J')) { iy = parser.value_int(); if (!WITHIN(iy, 0, (GRID_MAX_POINTS_Y) - 1)) { SERIAL_ECHOLNPGM("J out of range (0-", (GRID_MAX_POINTS_Y) - 1, ")"); return; } } else return echo_not_entered('J'); if (parser.seenval('Z')) { bedlevel.z_values[ix][iy] = parser.value_linear_units(); TERN_(EXTENSIBLE_UI, ExtUI::onMeshUpdate(ix, iy, bedlevel.z_values[ix][iy])); } else return echo_not_entered('Z'); break; case MeshSetZOffset: if (parser.seenval('Z')) bedlevel.z_offset = parser.value_linear_units(); else return echo_not_entered('Z'); break; case MeshReset: reset_bed_level(); break; } // switch(state) if (state == MeshNext) { SERIAL_ECHOLNPGM("MBL G29 point ", _MIN(mbl_probe_index, GRID_MAX_POINTS), " of ", GRID_MAX_POINTS); if (mbl_probe_index > 0) TERN_(HAS_STATUS_MESSAGE, ui.status_printf(0, F(S_FMT " %i/%i"), GET_TEXT_F(MSG_PROBING_POINT), _MIN(mbl_probe_index, GRID_MAX_POINTS), int(GRID_MAX_POINTS))); } report_current_position(); TERN_(FULL_REPORT_TO_HOST_FEATURE, set_and_report_grblstate(M_IDLE)); } #endif // MESH_BED_LEVELING
2301_81045437/Marlin
Marlin/src/gcode/bedlevel/mbl/G29.cpp
C++
agpl-3.0
8,191
/** * Marlin 3D Printer Firmware * Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin] * * Based on Sprinter and grbl. * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <https://www.gnu.org/licenses/>. * */ /** * M421.cpp - Mesh Bed Leveling */ #include "../../../inc/MarlinConfig.h" #if ENABLED(MESH_BED_LEVELING) #include "../../gcode.h" #include "../../../module/motion.h" #include "../../../feature/bedlevel/mbl/mesh_bed_leveling.h" /** * M421: Set a single Mesh Bed Leveling Z coordinate * * Usage: * M421 X<linear> Y<linear> Z<linear> * M421 X<linear> Y<linear> Q<offset> * M421 I<xindex> J<yindex> Z<linear> * M421 I<xindex> J<yindex> Q<offset> */ void GcodeSuite::M421() { const bool hasX = parser.seen('X'), hasI = parser.seen('I'); const int8_t ix = hasI ? parser.value_int() : hasX ? bedlevel.probe_index_x(RAW_X_POSITION(parser.value_linear_units())) : -1; const bool hasY = parser.seen('Y'), hasJ = parser.seen('J'); const int8_t iy = hasJ ? parser.value_int() : hasY ? bedlevel.probe_index_y(RAW_Y_POSITION(parser.value_linear_units())) : -1; const bool hasZ = parser.seen('Z'), hasQ = !hasZ && parser.seen('Q'); if (int(hasI && hasJ) + int(hasX && hasY) != 1 || !(hasZ || hasQ)) SERIAL_ERROR_MSG(STR_ERR_M421_PARAMETERS); else if (ix < 0 || iy < 0) SERIAL_ERROR_MSG(STR_ERR_MESH_XY); else bedlevel.set_z(ix, iy, parser.value_linear_units() + (hasQ ? bedlevel.z_values[ix][iy] : 0)); } #endif // MESH_BED_LEVELING
2301_81045437/Marlin
Marlin/src/gcode/bedlevel/mbl/M421.cpp
C++
agpl-3.0
2,136
/** * Marlin 3D Printer Firmware * Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin] * * Based on Sprinter and grbl. * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <https://www.gnu.org/licenses/>. * */ /** * G29.cpp - Unified Bed Leveling */ #include "../../../inc/MarlinConfig.h" #if ENABLED(AUTO_BED_LEVELING_UBL) #include "../../gcode.h" #include "../../../feature/bedlevel/bedlevel.h" #if ENABLED(FULL_REPORT_TO_HOST_FEATURE) #include "../../../module/motion.h" #endif void GcodeSuite::G29() { TERN_(FULL_REPORT_TO_HOST_FEATURE, set_and_report_grblstate(M_PROBE)); bedlevel.G29(); TERN_(FULL_REPORT_TO_HOST_FEATURE, set_and_report_grblstate(M_IDLE)); } #endif // AUTO_BED_LEVELING_UBL
2301_81045437/Marlin
Marlin/src/gcode/bedlevel/ubl/G29.cpp
C++
agpl-3.0
1,369
/** * Marlin 3D Printer Firmware * Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin] * * Based on Sprinter and grbl. * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <https://www.gnu.org/licenses/>. * */ /** * M421.cpp - Unified Bed Leveling */ #include "../../../inc/MarlinConfig.h" #if ENABLED(AUTO_BED_LEVELING_UBL) #include "../../gcode.h" #include "../../../feature/bedlevel/bedlevel.h" #if ENABLED(EXTENSIBLE_UI) #include "../../../lcd/extui/ui_api.h" #endif /** * M421: Set a single Mesh Bed Leveling Z coordinate * * Usage: * M421 I<xindex> J<yindex> Z<linear> : Set the Mesh Point IJ to the Z value * M421 I<xindex> J<yindex> Q<offset> : Add the Q value to the Mesh Point IJ * M421 I<xindex> J<yindex> N : Set the Mesh Point IJ to NAN (not set) * M421 C Z<linear> : Set the closest Mesh Point to the Z value * M421 C Q<offset> : Add the Q value to the closest Mesh Point */ void GcodeSuite::M421() { xy_int8_t ij = { int8_t(parser.intval('I', -1)), int8_t(parser.intval('J', -1)) }; const bool hasI = ij.x >= 0, hasJ = ij.y >= 0, hasC = parser.seen_test('C'), hasN = parser.seen_test('N'), hasZ = parser.seen('Z'), hasQ = !hasZ && parser.seen('Q'); if (hasC) ij = bedlevel.find_closest_mesh_point_of_type(CLOSEST, current_position); // Test for bad parameter combinations if (int(hasC) + int(hasI && hasJ) != 1 || !(hasZ || hasQ || hasN)) SERIAL_ERROR_MSG(STR_ERR_M421_PARAMETERS); // Test for I J out of range else if (!WITHIN(ij.x, 0, GRID_MAX_POINTS_X - 1) || !WITHIN(ij.y, 0, GRID_MAX_POINTS_Y - 1)) SERIAL_ERROR_MSG(STR_ERR_MESH_XY); else { float &zval = bedlevel.z_values[ij.x][ij.y]; // Altering this Mesh Point zval = hasN ? NAN : parser.value_linear_units() + (hasQ ? zval : 0); // N=NAN, Z=NEWVAL, or Q=ADDVAL TERN_(EXTENSIBLE_UI, ExtUI::onMeshUpdate(ij.x, ij.y, zval)); // Ping ExtUI in case it's showing the mesh } } #endif // AUTO_BED_LEVELING_UBL
2301_81045437/Marlin
Marlin/src/gcode/bedlevel/ubl/M421.cpp
C++
agpl-3.0
2,748
/** * Marlin 3D Printer Firmware * Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin] * * Based on Sprinter and grbl. * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <https://www.gnu.org/licenses/>. * */ #include "../../inc/MarlinConfig.h" #include "../gcode.h" #include "../../module/endstops.h" #include "../../module/planner.h" #include "../../module/stepper.h" // for various #if HAS_MULTI_HOTEND #include "../../module/tool_change.h" #endif #if HAS_LEVELING #include "../../feature/bedlevel/bedlevel.h" #endif #if ENABLED(SENSORLESS_HOMING) #include "../../feature/tmc_util.h" #endif #include "../../module/probe.h" #if ENABLED(BLTOUCH) #include "../../feature/bltouch.h" #endif #include "../../lcd/marlinui.h" #if ENABLED(EXTENSIBLE_UI) #include "../../lcd/extui/ui_api.h" #elif ENABLED(DWIN_CREALITY_LCD) #include "../../lcd/e3v2/creality/dwin.h" #endif #if ENABLED(LASER_FEATURE) #include "../../feature/spindle_laser.h" #endif #define DEBUG_OUT ENABLED(DEBUG_LEVELING_FEATURE) #include "../../core/debug_out.h" #if ENABLED(QUICK_HOME) static void quick_home_xy() { // Pretend the current position is 0,0 current_position.set(0.0, 0.0); sync_plan_position(); const int x_axis_home_dir = TOOL_X_HOME_DIR(active_extruder); // Use a higher diagonal feedrate so axes move at homing speed const float minfr = _MIN(homing_feedrate(X_AXIS), homing_feedrate(Y_AXIS)), fr_mm_s = HYPOT(minfr, minfr); #if ENABLED(SENSORLESS_HOMING) sensorless_t stealth_states { NUM_AXIS_LIST( TERN0(X_SENSORLESS, tmc_enable_stallguard(stepperX)), TERN0(Y_SENSORLESS, tmc_enable_stallguard(stepperY)), false, false, false, false, false, false, false ) , TERN0(X2_SENSORLESS, tmc_enable_stallguard(stepperX2)) , TERN0(Y2_SENSORLESS, tmc_enable_stallguard(stepperY2)) }; #endif do_blocking_move_to_xy(1.5 * max_length(X_AXIS) * x_axis_home_dir, 1.5 * max_length(Y_AXIS) * Y_HOME_DIR, fr_mm_s); endstops.validate_homing_move(); current_position.set(0.0, 0.0); #if ENABLED(SENSORLESS_HOMING) && DISABLED(ENDSTOPS_ALWAYS_ON_DEFAULT) TERN_(X_SENSORLESS, tmc_disable_stallguard(stepperX, stealth_states.x)); TERN_(X2_SENSORLESS, tmc_disable_stallguard(stepperX2, stealth_states.x2)); TERN_(Y_SENSORLESS, tmc_disable_stallguard(stepperY, stealth_states.y)); TERN_(Y2_SENSORLESS, tmc_disable_stallguard(stepperY2, stealth_states.y2)); #endif } #endif // QUICK_HOME #if ENABLED(Z_SAFE_HOMING) inline void home_z_safely() { DEBUG_SECTION(log_G28, "home_z_safely", DEBUGGING(LEVELING)); // Disallow Z homing if X or Y homing is needed if (homing_needed_error(_BV(X_AXIS) | _BV(Y_AXIS))) return; sync_plan_position(); /** * Move the Z probe (or just the nozzle) to the safe homing point * (Z is already at the right height) */ constexpr xy_float_t safe_homing_xy = { Z_SAFE_HOMING_X_POINT, Z_SAFE_HOMING_Y_POINT }; destination.set(safe_homing_xy, current_position.z); TERN_(HOMING_Z_WITH_PROBE, destination -= probe.offset_xy); if (position_is_reachable(destination)) { if (DEBUGGING(LEVELING)) DEBUG_POS("home_z_safely", destination); // Free the active extruder for movement TERN_(DUAL_X_CARRIAGE, idex_set_parked(false)); TERN_(SENSORLESS_HOMING, safe_delay(500)); // Short delay needed to settle do_blocking_move_to_xy(destination); homeaxis(Z_AXIS); } else { LCD_MESSAGE(MSG_ZPROBE_OUT); SERIAL_ECHO_MSG(STR_ZPROBE_OUT_SER); } } #endif // Z_SAFE_HOMING #if ENABLED(IMPROVE_HOMING_RELIABILITY) motion_state_t begin_slow_homing() { motion_state_t motion_state{0}; motion_state.acceleration.set(planner.settings.max_acceleration_mm_per_s2[X_AXIS], planner.settings.max_acceleration_mm_per_s2[Y_AXIS] OPTARG(DELTA, planner.settings.max_acceleration_mm_per_s2[Z_AXIS]) ); planner.settings.max_acceleration_mm_per_s2[X_AXIS] = 100; planner.settings.max_acceleration_mm_per_s2[Y_AXIS] = 100; TERN_(DELTA, planner.settings.max_acceleration_mm_per_s2[Z_AXIS] = 100); #if ENABLED(CLASSIC_JERK) motion_state.jerk_state = planner.max_jerk; planner.max_jerk.set(0, 0 OPTARG(DELTA, 0)); #endif planner.refresh_acceleration_rates(); return motion_state; } void end_slow_homing(const motion_state_t &motion_state) { planner.settings.max_acceleration_mm_per_s2[X_AXIS] = motion_state.acceleration.x; planner.settings.max_acceleration_mm_per_s2[Y_AXIS] = motion_state.acceleration.y; TERN_(DELTA, planner.settings.max_acceleration_mm_per_s2[Z_AXIS] = motion_state.acceleration.z); TERN_(CLASSIC_JERK, planner.max_jerk = motion_state.jerk_state); planner.refresh_acceleration_rates(); } #endif // IMPROVE_HOMING_RELIABILITY /** * 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. * * L<bool> Force leveling state ON (if possible) or OFF after homing (Requires RESTORE_LEVELING_AFTER_G28 or ENABLE_LEVELING_AFTER_G28) * O Home only if the position is not known and trusted * R<linear> 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() { DEBUG_SECTION(log_G28, "G28", DEBUGGING(LEVELING)); if (DEBUGGING(LEVELING)) log_machine_info(); #if ENABLED(MARLIN_DEV_MODE) if (parser.seen_test('S')) { LOOP_NUM_AXES(a) set_axis_is_at_home((AxisEnum)a); sync_plan_position(); SERIAL_ECHOLNPGM("Simulated Homing"); report_current_position(); return; } #endif /** * Set the laser power to false to stop the planner from processing the current power setting. */ #if ENABLED(LASER_FEATURE) planner.laser_inline.status.isPowered = false; #endif // Home (O)nly if position is unknown if (!axes_should_home() && parser.seen_test('O')) { if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPGM("> homing not needed, skip"); return; } #if ENABLED(FULL_REPORT_TO_HOST_FEATURE) const M_StateEnum old_grblstate = M_State_grbl; set_and_report_grblstate(M_HOMING); #endif TERN_(DWIN_CREALITY_LCD, dwinHomingStart()); TERN_(EXTENSIBLE_UI, ExtUI::onHomingStart()); planner.synchronize(); // Wait for planner moves to finish! // Count this command as movement / activity reset_stepper_timeout(); #if NUM_AXES #if ENABLED(DUAL_X_CARRIAGE) bool IDEX_saved_duplication_state = extruder_duplication_enabled; DualXMode IDEX_saved_mode = dual_x_carriage_mode; #endif SET_SOFT_ENDSTOP_LOOSE(false); // Reset a leftover 'loose' motion state // Disable the leveling matrix before homing #if CAN_SET_LEVELING_AFTER_G28 const bool leveling_restore_state = parser.boolval('L', TERN1(RESTORE_LEVELING_AFTER_G28, planner.leveling_active)); #endif // Cancel any prior G29 session TERN_(PROBE_MANUALLY, g29_in_progress = false); // Disable leveling before homing TERN_(HAS_LEVELING, set_bed_leveling_enabled(false)); // Reset to the XY plane TERN_(CNC_WORKSPACE_PLANES, workspace_plane = PLANE_XY); #define _OR_HAS_CURR_HOME(N) HAS_CURRENT_HOME(N) || #if MAIN_AXIS_MAP(_OR_HAS_CURR_HOME) MAP(_OR_HAS_CURR_HOME, X2, Y2, Z2, Z3, Z4) 0 #define HAS_HOMING_CURRENT 1 #endif #if HAS_HOMING_CURRENT #if ENABLED(DEBUG_LEVELING_FEATURE) auto debug_current = [](FSTR_P const s, const int16_t a, const int16_t b) { if (DEBUGGING(LEVELING)) { DEBUG_ECHOLN(s, F(" current: "), a, F(" -> "), b); } }; #else #define debug_current(...) #endif #define _SAVE_SET_CURRENT(A) \ const int16_t saved_current_##A = stepper##A.getMilliamps(); \ stepper##A.rms_current(A##_CURRENT_HOME); \ debug_current(F(STR_##A), saved_current_##A, A##_CURRENT_HOME) #if HAS_CURRENT_HOME(X) _SAVE_SET_CURRENT(X); #endif #if HAS_CURRENT_HOME(X2) _SAVE_SET_CURRENT(X2); #endif #if HAS_CURRENT_HOME(Y) _SAVE_SET_CURRENT(Y); #endif #if HAS_CURRENT_HOME(Y2) _SAVE_SET_CURRENT(Y2); #endif #if HAS_CURRENT_HOME(Z) _SAVE_SET_CURRENT(Z); #endif #if HAS_CURRENT_HOME(Z2) _SAVE_SET_CURRENT(Z2); #endif #if HAS_CURRENT_HOME(Z3) _SAVE_SET_CURRENT(Z3); #endif #if HAS_CURRENT_HOME(Z4) _SAVE_SET_CURRENT(Z4); #endif #if HAS_CURRENT_HOME(I) _SAVE_SET_CURRENT(I); #endif #if HAS_CURRENT_HOME(J) _SAVE_SET_CURRENT(J); #endif #if HAS_CURRENT_HOME(K) _SAVE_SET_CURRENT(K); #endif #if HAS_CURRENT_HOME(U) _SAVE_SET_CURRENT(U); #endif #if HAS_CURRENT_HOME(V) _SAVE_SET_CURRENT(V); #endif #if HAS_CURRENT_HOME(W) _SAVE_SET_CURRENT(W); #endif #if SENSORLESS_STALLGUARD_DELAY safe_delay(SENSORLESS_STALLGUARD_DELAY); // Short delay needed to settle #endif #endif // HAS_HOMING_CURRENT #if ENABLED(IMPROVE_HOMING_RELIABILITY) motion_state_t saved_motion_state = begin_slow_homing(); #endif // Always home with tool 0 active #if HAS_MULTI_HOTEND #if DISABLED(DELTA) || ENABLED(DELTA_HOME_TO_SAFE_ZONE) const uint8_t old_tool_index = active_extruder; #endif // PARKING_EXTRUDER homing requires different handling of movement / solenoid activation, depending on the side of homing #if ENABLED(PARKING_EXTRUDER) const bool pe_final_change_must_unpark = parking_extruder_unpark_after_homing(old_tool_index, X_HOME_DIR + 1 == old_tool_index * 2); #endif tool_change(0, true); #endif TERN_(HAS_DUPLICATION_MODE, set_duplication_enabled(false)); remember_feedrate_scaling_off(); endstops.enable(true); // Enable endstops for next homing move #if HAS_Z_AXIS bool finalRaiseZ = false; #endif #if ENABLED(DELTA) constexpr bool doZ = true; // for NANODLP_Z_SYNC if your DLP is on a DELTA home_delta(); TERN_(IMPROVE_HOMING_RELIABILITY, end_slow_homing(saved_motion_state)); #elif ENABLED(AXEL_TPARA) constexpr bool doZ = true; // for NANODLP_Z_SYNC if your DLP is on a TPARA home_TPARA(); #else // !DELTA && !AXEL_TPARA #define _UNSAFE(A) (homeZ && TERN0(Z_SAFE_HOMING, axes_should_home(_BV(A##_AXIS)))) const bool homeZ = TERN0(HAS_Z_AXIS, parser.seen_test('Z')), NUM_AXIS_LIST_( // Other axes should be homed before Z safe-homing needX = _UNSAFE(X), needY = _UNSAFE(Y), needZ = false, // UNUSED needI = _UNSAFE(I), needJ = _UNSAFE(J), needK = _UNSAFE(K), needU = _UNSAFE(U), needV = _UNSAFE(V), needW = _UNSAFE(W) ) NUM_AXIS_LIST_( // Home each axis if needed or flagged homeX = needX || parser.seen_test('X'), homeY = needY || parser.seen_test('Y'), homeZZ = homeZ, homeI = needI || parser.seen_test(AXIS4_NAME), homeJ = needJ || parser.seen_test(AXIS5_NAME), homeK = needK || parser.seen_test(AXIS6_NAME), homeU = needU || parser.seen_test(AXIS7_NAME), homeV = needV || parser.seen_test(AXIS8_NAME), homeW = needW || parser.seen_test(AXIS9_NAME) ) home_all = NUM_AXIS_GANG_( // Home-all if all or none are flagged homeX == homeX, && homeY == homeX, && homeZ == homeX, && homeI == homeX, && homeJ == homeX, && homeK == homeX, && homeU == homeX, && homeV == homeX, && homeW == homeX ) NUM_AXIS_LIST( doX = home_all || homeX, doY = home_all || homeY, doZ = home_all || homeZ, doI = home_all || homeI, doJ = home_all || homeJ, doK = home_all || homeK, doU = home_all || homeU, doV = home_all || homeV, doW = home_all || homeW ); #if !HAS_Y_AXIS constexpr bool doY = false; #endif #if HAS_Z_AXIS UNUSED(needZ); UNUSED(homeZZ); // Z may home first, e.g., when homing away from the bed. // This is also permitted when homing with a Z endstop. if (TERN0(HOME_Z_FIRST, doZ)) homeaxis(Z_AXIS); // 'R' to specify a specific raise. 'R0' indicates no raise, e.g., for recovery.resume // When 'R0' is used, there should already be adequate clearance, e.g., from homing Z to max. const bool seenR = parser.seenval('R'); // Use raise given by 'R' or Z_CLEARANCE_FOR_HOMING (above the probe trigger point) float z_homing_height = seenR ? parser.value_linear_units() : Z_CLEARANCE_FOR_HOMING; // Check for any lateral motion that might require clearance const bool may_skate = seenR NUM_AXIS_GANG(|| doX, || doY, || TERN0(Z_SAFE_HOMING, doZ), || doI, || doJ, || doK, || doU, || doV, || doW); if (seenR && z_homing_height == 0) { if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPGM("R0 = No Z raise"); } else { bool with_probe = ENABLED(HOMING_Z_WITH_PROBE); // Raise above the current Z (which should be synced in the planner) // The "height" for Z is a coordinate. But if Z is not trusted/homed make it relative. if (seenR || !TERN(HOME_AFTER_DEACTIVATE, axis_is_trusted, axis_was_homed)(Z_AXIS)) { z_homing_height += current_position.z; with_probe = false; } if (may_skate) { // Apply Z clearance before doing any lateral motion if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPGM("Raise Z before homing:"); do_z_clearance(z_homing_height, with_probe); } } // Init BLTouch ahead of any lateral motion, even if not homing with the probe TERN_(BLTOUCH, if (may_skate) bltouch.init()); #endif // HAS_Z_AXIS // Diagonal move first if both are homing TERN_(QUICK_HOME, if (doX && doY) quick_home_xy()); #if HAS_Y_AXIS // Home Y (before X) if (ENABLED(HOME_Y_BEFORE_X) && (doY || TERN0(CODEPENDENT_XY_HOMING, doX))) homeaxis(Y_AXIS); #endif // Home X #if HAS_X_AXIS if (doX || (doY && ENABLED(CODEPENDENT_XY_HOMING) && DISABLED(HOME_Y_BEFORE_X))) { #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 = current_position.x; // Home the 1st (left) extruder active_extruder = 0; homeaxis(X_AXIS); // Consider the active extruder to be in its "parked" position idex_set_parked(); #else homeaxis(X_AXIS); #endif } #endif // HAS_X_AXIS #if ALL(FOAMCUTTER_XYUV, HAS_I_AXIS) // Home I (after X) if (doI) homeaxis(I_AXIS); #endif #if HAS_Y_AXIS // Home Y (after X) if (DISABLED(HOME_Y_BEFORE_X) && doY) homeaxis(Y_AXIS); #endif #if ALL(FOAMCUTTER_XYUV, HAS_J_AXIS) // Home J (after Y) if (doJ) homeaxis(J_AXIS); #endif TERN_(IMPROVE_HOMING_RELIABILITY, end_slow_homing(saved_motion_state)); #if ENABLED(FOAMCUTTER_XYUV) // Skip homing of unused Z axis for foamcutters if (doZ) set_axis_is_at_home(Z_AXIS); #elif HAS_Z_AXIS // Home Z last if homing towards the bed #if DISABLED(HOME_Z_FIRST) if (doZ) { #if ANY(Z_MULTI_ENDSTOPS, Z_STEPPER_AUTO_ALIGN) stepper.set_all_z_lock(false); stepper.set_separate_multi_axis(false); #endif #if ENABLED(Z_SAFE_HOMING) if (TERN1(POWER_LOSS_RECOVERY, !parser.seen_test('H'))) home_z_safely(); else homeaxis(Z_AXIS); #else homeaxis(Z_AXIS); #endif #if ANY(Z_HOME_TO_MIN, ALLOW_Z_AFTER_HOMING) finalRaiseZ = true; #endif } #endif SECONDARY_AXIS_CODE( if (doI) homeaxis(I_AXIS), if (doJ) homeaxis(J_AXIS), if (doK) homeaxis(K_AXIS), if (doU) homeaxis(U_AXIS), if (doV) homeaxis(V_AXIS), if (doW) homeaxis(W_AXIS) ); #endif // HAS_Z_AXIS sync_plan_position(); #endif /** * 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 G-Code 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 (idex_is_duplicating()) { TERN_(IMPROVE_HOMING_RELIABILITY, saved_motion_state = begin_slow_homing()); // 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 = current_position.x; // Home the 1st (left) extruder active_extruder = 0; homeaxis(X_AXIS); // Consider the active extruder to be parked idex_set_parked(); dual_x_carriage_mode = IDEX_saved_mode; set_duplication_enabled(IDEX_saved_duplication_state); TERN_(IMPROVE_HOMING_RELIABILITY, end_slow_homing(saved_motion_state)); } #endif // DUAL_X_CARRIAGE endstops.not_homing(); // Clear endstop state for polled stallGuard endstops TERN_(SPI_ENDSTOPS, endstops.clear_endstop_state()); #if HAS_HOMING_CURRENT if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPGM("Restore driver current..."); #if HAS_CURRENT_HOME(X) stepperX.rms_current(saved_current_X); #endif #if HAS_CURRENT_HOME(X2) stepperX2.rms_current(saved_current_X2); #endif #if HAS_CURRENT_HOME(Y) stepperY.rms_current(saved_current_Y); #endif #if HAS_CURRENT_HOME(Y2) stepperY2.rms_current(saved_current_Y2); #endif #if HAS_CURRENT_HOME(Z) stepperZ.rms_current(saved_current_Z); #endif #if HAS_CURRENT_HOME(Z2) stepperZ2.rms_current(saved_current_Z2); #endif #if HAS_CURRENT_HOME(Z3) stepperZ3.rms_current(saved_current_Z3); #endif #if HAS_CURRENT_HOME(Z4) stepperZ4.rms_current(saved_current_Z4); #endif #if HAS_CURRENT_HOME(I) stepperI.rms_current(saved_current_I); #endif #if HAS_CURRENT_HOME(J) stepperJ.rms_current(saved_current_J); #endif #if HAS_CURRENT_HOME(K) stepperK.rms_current(saved_current_K); #endif #if HAS_CURRENT_HOME(U) stepperU.rms_current(saved_current_U); #endif #if HAS_CURRENT_HOME(V) stepperV.rms_current(saved_current_V); #endif #if HAS_CURRENT_HOME(W) stepperW.rms_current(saved_current_W); #endif #if SENSORLESS_STALLGUARD_DELAY safe_delay(SENSORLESS_STALLGUARD_DELAY); // Short delay needed to settle #endif #endif // HAS_HOMING_CURRENT // Move to a height where we can use the full xy-area TERN_(DELTA_HOME_TO_SAFE_ZONE, do_blocking_move_to_z(delta_clip_start_height)); #if HAS_Z_AXIS // Move to the configured Z only if Z was homed to MIN, because machines that // home to MAX historically expect 'G28 Z' to be safe to use at the end of a // print, and do_move_after_z_homing is not very nuanced. if (finalRaiseZ) do_move_after_z_homing(); #endif TERN_(CAN_SET_LEVELING_AFTER_G28, if (leveling_restore_state) set_bed_leveling_enabled()); // Restore the active tool after homing #if HAS_MULTI_HOTEND && (DISABLED(DELTA) || ENABLED(DELTA_HOME_TO_SAFE_ZONE)) tool_change(old_tool_index, TERN(PARKING_EXTRUDER, !pe_final_change_must_unpark, DISABLED(DUAL_X_CARRIAGE))); // Do move if one of these #endif #ifdef XY_AFTER_HOMING if (!axes_should_home(_BV(X_AXIS) | _BV(Y_AXIS))) do_blocking_move_to(xy_pos_t(XY_AFTER_HOMING)); #endif restore_feedrate_and_scaling(); if (ENABLED(NANODLP_Z_SYNC) && (ENABLED(NANODLP_ALL_AXIS) || TERN0(HAS_Z_AXIS, doZ))) SERIAL_ECHOLNPGM(STR_Z_MOVE_COMP); #endif // NUM_AXES ui.refresh(); TERN_(DWIN_CREALITY_LCD, dwinHomingDone()); TERN_(EXTENSIBLE_UI, ExtUI::onHomingDone()); report_current_position(); TERN_(FULL_REPORT_TO_HOST_FEATURE, set_and_report_grblstate(old_grblstate)); #ifdef EVENT_GCODE_AFTER_HOMING gcode.process_subcommands_now(F(EVENT_GCODE_AFTER_HOMING)); #endif }
2301_81045437/Marlin
Marlin/src/gcode/calibrate/G28.cpp
C++
agpl-3.0
22,019
/** * Marlin 3D Printer Firmware * Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin] * * Based on Sprinter and grbl. * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <https://www.gnu.org/licenses/>. * */ #include "../../inc/MarlinConfig.h" #if ENABLED(DELTA_AUTO_CALIBRATION) #include "../gcode.h" #include "../../module/delta.h" #include "../../module/motion.h" #include "../../module/planner.h" #include "../../module/endstops.h" #include "../../lcd/marlinui.h" #if HAS_BED_PROBE #include "../../module/probe.h" #endif #if HAS_LEVELING #include "../../feature/bedlevel/bedlevel.h" #endif constexpr uint8_t _7P_STEP = 1, // 7-point step - to change number of calibration points _4P_STEP = _7P_STEP * 2, // 4-point step NPP = _7P_STEP * 6; // number of calibration points on the radius enum CalEnum : char { // the 7 main calibration points - add definitions if needed CEN = 0, __A = 1, _AB = __A + _7P_STEP, __B = _AB + _7P_STEP, _BC = __B + _7P_STEP, __C = _BC + _7P_STEP, _CA = __C + _7P_STEP, }; #define LOOP_CAL_PT(VAR, S, N) for (uint8_t VAR=S; VAR<=NPP; VAR+=N) #define F_LOOP_CAL_PT(VAR, S, N) for (float VAR=S; VAR<NPP+0.9999; VAR+=N) #define I_LOOP_CAL_PT(VAR, S, N) for (float VAR=S; VAR>CEN+0.9999; VAR-=N) #define LOOP_CAL_ALL(VAR) LOOP_CAL_PT(VAR, CEN, 1) #define LOOP_CAL_RAD(VAR) LOOP_CAL_PT(VAR, __A, _7P_STEP) #define LOOP_CAL_ACT(VAR, _4P, _OP) LOOP_CAL_PT(VAR, _OP ? _AB : __A, _4P ? _4P_STEP : _7P_STEP) float lcd_probe_pt(const xy_pos_t &xy); void ac_home() { endstops.enable(true); TERN_(SENSORLESS_HOMING, endstops.set_z_sensorless_current(true)); home_delta(); TERN_(SENSORLESS_HOMING, endstops.set_z_sensorless_current(false)); endstops.not_homing(); } void ac_setup(const bool reset_bed) { TERN_(HAS_BED_PROBE, probe.use_probing_tool()); planner.synchronize(); remember_feedrate_scaling_off(); #if HAS_LEVELING if (reset_bed) reset_bed_level(); // After full calibration bed-level data is no longer valid #endif } void ac_cleanup() { TERN_(DELTA_HOME_TO_SAFE_ZONE, do_blocking_move_to_z(delta_clip_start_height)); TERN_(HAS_BED_PROBE, probe.stow()); restore_feedrate_and_scaling(); TERN_(HAS_BED_PROBE, probe.use_probing_tool(false)); } void print_signed_float(FSTR_P const prefix, const_float_t f) { SERIAL_ECHO(F(" "), prefix, C(':')); serial_offset(f); } /** * - Print the delta settings */ static void print_calibration_settings(const bool end_stops, const bool tower_angles) { SERIAL_ECHOPGM(".Height:", delta_height); if (end_stops) { print_signed_float(F("Ex"), delta_endstop_adj.a); print_signed_float(F("Ey"), delta_endstop_adj.b); print_signed_float(F("Ez"), delta_endstop_adj.c); } if (end_stops && tower_angles) { SERIAL_ECHOLNPGM(" Radius:", delta_radius); SERIAL_CHAR('.'); SERIAL_ECHO_SP(13); } if (tower_angles) { print_signed_float(F("Tx"), delta_tower_angle_trim.a); print_signed_float(F("Ty"), delta_tower_angle_trim.b); print_signed_float(F("Tz"), delta_tower_angle_trim.c); } if (end_stops != tower_angles) SERIAL_ECHOPGM(" Radius:", delta_radius); SERIAL_EOL(); } /** * - Print the probe results */ static void print_calibration_results(const float z_pt[NPP + 1], const bool tower_points, const bool opposite_points) { SERIAL_ECHOPGM(". "); print_signed_float(F("c"), z_pt[CEN]); if (tower_points) { print_signed_float(F(" x"), z_pt[__A]); print_signed_float(F(" y"), z_pt[__B]); print_signed_float(F(" z"), z_pt[__C]); } if (tower_points && opposite_points) { SERIAL_EOL(); SERIAL_CHAR('.'); SERIAL_ECHO_SP(13); } if (opposite_points) { print_signed_float(F("yz"), z_pt[_BC]); print_signed_float(F("zx"), z_pt[_CA]); print_signed_float(F("xy"), z_pt[_AB]); } SERIAL_EOL(); } /** * - Calculate the standard deviation from the zero plane */ static float std_dev_points(float z_pt[NPP + 1], const bool _0p_cal, const bool _1p_cal, const bool _4p_cal, const bool _4p_opp) { if (!_0p_cal) { float S2 = sq(z_pt[CEN]); int16_t N = 1; if (!_1p_cal) { // std dev from zero plane LOOP_CAL_ACT(rad, _4p_cal, _4p_opp) { S2 += sq(z_pt[rad]); N++; } return LROUND(SQRT(S2 / N) * 1000.0f) / 1000.0f + 0.00001f; } } return 0.00001f; } /** * - Probe a point */ static float calibration_probe(const xy_pos_t &xy, const bool stow, const bool probe_at_offset) { #if HAS_BED_PROBE return probe.probe_at_point(xy, stow ? PROBE_PT_STOW : PROBE_PT_RAISE, 0, probe_at_offset, false, Z_PROBE_LOW_POINT, Z_TWEEN_SAFE_CLEARANCE, true); #else UNUSED(stow); return lcd_probe_pt(xy); #endif } /** * - Probe a grid */ static bool probe_calibration_points(float z_pt[NPP + 1], const int8_t probe_points, const float dcr, const bool towers_set, const bool stow_after_each, const bool probe_at_offset) { const bool _0p_calibration = probe_points == 0, _1p_calibration = probe_points == 1 || probe_points == -1, _4p_calibration = probe_points == 2, _4p_opposite_points = _4p_calibration && !towers_set, _7p_calibration = probe_points >= 3, _7p_no_intermediates = probe_points == 3, _7p_1_intermediates = probe_points == 4, _7p_2_intermediates = probe_points == 5, _7p_4_intermediates = probe_points == 6, _7p_6_intermediates = probe_points == 7, _7p_8_intermediates = probe_points == 8, _7p_11_intermediates = probe_points == 9, _7p_14_intermediates = probe_points == 10, _7p_intermed_points = probe_points >= 4, _7p_6_center = probe_points >= 5 && probe_points <= 7, _7p_9_center = probe_points >= 8; LOOP_CAL_ALL(rad) z_pt[rad] = 0.0f; if (!_0p_calibration) { if (!_7p_no_intermediates && !_7p_4_intermediates && !_7p_11_intermediates) { // probe the center const xy_pos_t center{0}; z_pt[CEN] += calibration_probe(center, stow_after_each, probe_at_offset); if (isnan(z_pt[CEN])) return false; } if (_7p_calibration) { // probe extra center points const float start = _7p_9_center ? float(_CA) + _7P_STEP / 3.0f : _7p_6_center ? float(_CA) : float(__C), steps = _7p_9_center ? _4P_STEP / 3.0f : _7p_6_center ? _7P_STEP : _4P_STEP; I_LOOP_CAL_PT(rad, start, steps) { const float a = RADIANS(210 + (360 / NPP) * (rad - 1)), r = dcr * 0.1; const xy_pos_t vec = { cos(a), sin(a) }; z_pt[CEN] += calibration_probe(vec * r, stow_after_each, probe_at_offset); if (isnan(z_pt[CEN])) return false; } z_pt[CEN] /= float(_7p_2_intermediates ? 7 : probe_points); } if (!_1p_calibration) { // probe the radius const CalEnum start = _4p_opposite_points ? _AB : __A; const float steps = _7p_14_intermediates ? _7P_STEP / 15.0f : // 15r * 6 + 10c = 100 _7p_11_intermediates ? _7P_STEP / 12.0f : // 12r * 6 + 9c = 81 _7p_8_intermediates ? _7P_STEP / 9.0f : // 9r * 6 + 10c = 64 _7p_6_intermediates ? _7P_STEP / 7.0f : // 7r * 6 + 7c = 49 _7p_4_intermediates ? _7P_STEP / 5.0f : // 5r * 6 + 6c = 36 _7p_2_intermediates ? _7P_STEP / 3.0f : // 3r * 6 + 7c = 25 _7p_1_intermediates ? _7P_STEP / 2.0f : // 2r * 6 + 4c = 16 _7p_no_intermediates ? _7P_STEP : // 1r * 6 + 3c = 9 _4P_STEP; // .5r * 6 + 1c = 4 bool zig_zag = true; F_LOOP_CAL_PT(rad, start, _7p_9_center ? steps * 3 : steps) { const int8_t offset = _7p_9_center ? 2 : 0; for (int8_t circle = 0; circle <= offset; circle++) { const float a = RADIANS(210 + (360 / NPP) * (rad - 1)), r = dcr * (1 - 0.1 * (zig_zag ? offset - circle : circle)), interpol = FMOD(rad, 1); const xy_pos_t vec = { cos(a), sin(a) }; const float z_temp = calibration_probe(vec * r, stow_after_each, probe_at_offset); if (isnan(z_temp)) return false; // split probe point to neighbouring calibration points z_pt[uint8_t(LROUND(rad - interpol + NPP - 1)) % NPP + 1] += z_temp * sq(cos(RADIANS(interpol * 90))); z_pt[uint8_t(LROUND(rad - interpol)) % NPP + 1] += z_temp * sq(sin(RADIANS(interpol * 90))); } zig_zag = !zig_zag; } if (_7p_intermed_points) LOOP_CAL_RAD(rad) z_pt[rad] /= _7P_STEP / steps; do_blocking_move_to_xy(0.0f, 0.0f); } } return true; } /** * kinematics routines and auto tune matrix scaling parameters: * see https://github.com/LVD-AC/Marlin-AC/tree/1.1.x-AC/documentation for * - formulae for approximative forward kinematics in the end-stop displacement matrix * - definition of the matrix scaling parameters */ static void reverse_kinematics_probe_points(float z_pt[NPP + 1], abc_float_t mm_at_pt_axis[NPP + 1], const float dcr) { xyz_pos_t pos{0}; LOOP_CAL_ALL(rad) { const float a = RADIANS(210 + (360 / NPP) * (rad - 1)), r = (rad == CEN ? 0.0f : dcr); pos.set(cos(a) * r, sin(a) * r, z_pt[rad]); inverse_kinematics(pos); mm_at_pt_axis[rad] = delta; } } static void forward_kinematics_probe_points(abc_float_t mm_at_pt_axis[NPP + 1], float z_pt[NPP + 1], const float dcr) { const float r_quot = dcr / delta_radius; #define ZPP(N,I,A) (((1.0f + r_quot * (N)) / 3.0f) * mm_at_pt_axis[I].A) #define Z00(I, A) ZPP( 0, I, A) #define Zp1(I, A) ZPP(+1, I, A) #define Zm1(I, A) ZPP(-1, I, A) #define Zp2(I, A) ZPP(+2, I, A) #define Zm2(I, A) ZPP(-2, I, A) z_pt[CEN] = Z00(CEN, a) + Z00(CEN, b) + Z00(CEN, c); z_pt[__A] = Zp2(__A, a) + Zm1(__A, b) + Zm1(__A, c); z_pt[__B] = Zm1(__B, a) + Zp2(__B, b) + Zm1(__B, c); z_pt[__C] = Zm1(__C, a) + Zm1(__C, b) + Zp2(__C, c); z_pt[_BC] = Zm2(_BC, a) + Zp1(_BC, b) + Zp1(_BC, c); z_pt[_CA] = Zp1(_CA, a) + Zm2(_CA, b) + Zp1(_CA, c); z_pt[_AB] = Zp1(_AB, a) + Zp1(_AB, b) + Zm2(_AB, c); } static void calc_kinematics_diff_probe_points(float z_pt[NPP + 1], const float dcr, abc_float_t delta_e, const float delta_r, abc_float_t delta_t) { const float z_center = z_pt[CEN]; abc_float_t diff_mm_at_pt_axis[NPP + 1], new_mm_at_pt_axis[NPP + 1]; reverse_kinematics_probe_points(z_pt, diff_mm_at_pt_axis, dcr); delta_radius += delta_r; delta_tower_angle_trim += delta_t; recalc_delta_settings(); reverse_kinematics_probe_points(z_pt, new_mm_at_pt_axis, dcr); LOOP_CAL_ALL(rad) diff_mm_at_pt_axis[rad] -= new_mm_at_pt_axis[rad] + delta_e; forward_kinematics_probe_points(diff_mm_at_pt_axis, z_pt, dcr); LOOP_CAL_RAD(rad) z_pt[rad] -= z_pt[CEN] - z_center; z_pt[CEN] = z_center; delta_radius -= delta_r; delta_tower_angle_trim -= delta_t; recalc_delta_settings(); } static float auto_tune_h(const float dcr) { const float r_quot = dcr / delta_radius; return RECIPROCAL(r_quot / (2.0f / 3.0f)); // (2/3)/CR } static float auto_tune_r(const float dcr) { constexpr float diff = 0.01f, delta_r = diff; float r_fac = 0.0f, z_pt[NPP + 1] = { 0.0f }; abc_float_t delta_e = { 0.0f }, delta_t = { 0.0f }; calc_kinematics_diff_probe_points(z_pt, dcr, delta_e, delta_r, delta_t); r_fac = -(z_pt[__A] + z_pt[__B] + z_pt[__C] + z_pt[_BC] + z_pt[_CA] + z_pt[_AB]) / 6.0f; r_fac = diff / r_fac / 3.0f; // 1/(3*delta_Z) return r_fac; } static float auto_tune_a(const float dcr) { constexpr float diff = 0.01f, delta_r = 0.0f; float a_fac = 0.0f, z_pt[NPP + 1] = { 0.0f }; abc_float_t delta_e = { 0.0f }, delta_t = { 0.0f }; delta_t.reset(); LOOP_NUM_AXES(axis) { delta_t[axis] = diff; calc_kinematics_diff_probe_points(z_pt, dcr, delta_e, delta_r, delta_t); delta_t[axis] = 0; a_fac += z_pt[uint8_t((axis * _4P_STEP) - _7P_STEP + NPP) % NPP + 1] / 6.0f; a_fac -= z_pt[uint8_t((axis * _4P_STEP) + 1 + _7P_STEP)] / 6.0f; } a_fac = diff / a_fac / 3.0f; // 1/(3*delta_Z) return a_fac; } /** * G33 - Delta '1-4-7-point' Auto-Calibration * Calibrate height, z_offset, endstops, delta radius, and tower angles. * * Parameters: * * Pn Number of probe points: * P0 Normalizes calibration. * P1 Calibrates height only with center probe. * P2 Probe center and towers. Calibrate height, endstops and delta radius. * P3 Probe all positions: center, towers and opposite towers. Calibrate all. * P4-P10 Probe all positions at different intermediate locations and average them. * * Rn.nn Temporary reduce the probe grid by the specified amount (mm) * * T Don't calibrate tower angle corrections * * Cn.nn Calibration precision; when omitted calibrates to maximum precision * * Fn Force to run at least n iterations and take the best result * * Vn Verbose level: * V0 Dry-run mode. Report settings and probe results. No calibration. * V1 Report start and end settings only * V2 Report settings at each iteration * V3 Report settings and probe results * * E Engage the probe for each point * * O Probe at offsetted probe positions (this is wrong but it seems to work) * * With SENSORLESS_PROBING: * Use these flags to calibrate stall sensitivity: (e.g., `G33 P1 Y Z` to calibrate X only.) * X Don't activate stallguard on X. * Y Don't activate stallguard on Y. * Z Don't activate stallguard on Z. * * S Save offset_sensorless_adj */ void GcodeSuite::G33() { TERN_(FULL_REPORT_TO_HOST_FEATURE, set_and_report_grblstate(M_PROBE)); const int8_t probe_points = parser.intval('P', DELTA_CALIBRATION_DEFAULT_POINTS); if (!WITHIN(probe_points, 0, 10)) { SERIAL_ECHOLNPGM(GCODE_ERR_MSG("(P)oints implausible (0-10).")); return; } const bool probe_at_offset = TERN0(HAS_PROBE_XY_OFFSET, parser.seen_test('O')), towers_set = !parser.seen_test('T'); // The calibration radius is set to a calculated value float dcr = probe_at_offset ? PRINTABLE_RADIUS : PRINTABLE_RADIUS - PROBING_MARGIN; #if HAS_PROBE_XY_OFFSET const float total_offset = HYPOT(probe.offset_xy.x, probe.offset_xy.y); dcr -= probe_at_offset ? _MAX(total_offset, PROBING_MARGIN) : total_offset; #endif NOMORE(dcr, PRINTABLE_RADIUS); if (parser.seenval('R')) dcr -= _MAX(parser.value_float(), 0.0f); TERN_(HAS_DELTA_SENSORLESS_PROBING, dcr *= sensorless_radius_factor); const float calibration_precision = parser.floatval('C', 0.0f); if (calibration_precision < 0) { SERIAL_ECHOLNPGM(GCODE_ERR_MSG("(C)alibration precision implausible (>=0).")); return; } const int8_t force_iterations = parser.intval('F', 0); if (!WITHIN(force_iterations, 0, 30)) { SERIAL_ECHOLNPGM(GCODE_ERR_MSG("(F)orce iteration implausible (0-30).")); return; } const int8_t verbose_level = parser.byteval('V', 1); if (!WITHIN(verbose_level, 0, 3)) { SERIAL_ECHOLNPGM(GCODE_ERR_MSG("(V)erbose level implausible (0-3).")); return; } const bool stow_after_each = parser.seen_test('E'); #if HAS_DELTA_SENSORLESS_PROBING probe.test_sensitivity = { !parser.seen_test('X'), !parser.seen_test('Y'), !parser.seen_test('Z') }; const bool do_save_offset_adj = parser.seen_test('S'); #endif const bool _0p_calibration = probe_points == 0, _1p_calibration = probe_points == 1 || probe_points == -1, _4p_calibration = probe_points == 2, _4p_opposite_points = _4p_calibration && !towers_set, _7p_9_center = probe_points >= 8, _tower_results = (_4p_calibration && towers_set) || probe_points >= 3, _opposite_results = (_4p_calibration && !towers_set) || probe_points >= 3, _endstop_results = probe_points != 1 && probe_points != -1 && probe_points != 0, _angle_results = probe_points >= 3 && towers_set; int8_t iterations = 0; float test_precision, zero_std_dev = (verbose_level ? 999.0f : 0.0f), // 0.0 in dry-run mode : forced end zero_std_dev_min = zero_std_dev, zero_std_dev_old = zero_std_dev, h_factor, r_factor, a_factor, r_old = delta_radius, h_old = delta_height; abc_pos_t e_old = delta_endstop_adj, a_old = delta_tower_angle_trim; SERIAL_ECHOLNPGM("G33 Auto Calibrate"); // Report settings FSTR_P const checkingac = F("Checking... AC"); SERIAL_ECHO(checkingac, F(" at radius:"), dcr); if (verbose_level == 0) SERIAL_ECHOPGM(" (DRY-RUN)"); SERIAL_EOL(); ui.set_status(checkingac); print_calibration_settings(_endstop_results, _angle_results); ac_setup(!_0p_calibration && !_1p_calibration); if (!_0p_calibration) ac_home(); #if HAS_DELTA_SENSORLESS_PROBING if (verbose_level > 0 && do_save_offset_adj) { offset_sensorless_adj.reset(); auto caltower = [&](Probe::sense_bool_t s) { float z_at_pt[NPP + 1]; LOOP_CAL_ALL(rad) z_at_pt[rad] = 0.0f; probe.test_sensitivity = s; if (probe_calibration_points(z_at_pt, 1, dcr, false, false, probe_at_offset)) probe.set_offset_sensorless_adj(z_at_pt[CEN]); }; caltower({ true, false, false }); // A caltower({ false, true, false }); // B caltower({ false, false, true }); // C probe.test_sensitivity = { true, true, true }; // reset to all } #endif do { // start iterations float z_at_pt[NPP + 1] = { 0.0f }; test_precision = zero_std_dev_old != 999.0f ? (zero_std_dev + zero_std_dev_old) / 2.0f : zero_std_dev; iterations++; // Probe the points zero_std_dev_old = zero_std_dev; if (!probe_calibration_points(z_at_pt, probe_points, dcr, towers_set, stow_after_each, probe_at_offset)) { SERIAL_ECHOLNPGM("Correct delta settings with M665 and M666"); return ac_cleanup(); } zero_std_dev = std_dev_points(z_at_pt, _0p_calibration, _1p_calibration, _4p_calibration, _4p_opposite_points); // Solve matrices if ((zero_std_dev < test_precision || iterations <= force_iterations) && zero_std_dev > calibration_precision) { #if !HAS_BED_PROBE test_precision = 0.0f; // forced end #endif if (zero_std_dev < zero_std_dev_min) { // set roll-back point e_old = delta_endstop_adj; r_old = delta_radius; h_old = delta_height; a_old = delta_tower_angle_trim; } abc_float_t e_delta = { 0.0f }, t_delta = { 0.0f }; float r_delta = 0.0f; /** * convergence matrices: * see https://github.com/LVD-AC/Marlin-AC/tree/1.1.x-AC/documentation for * - definition of the matrix scaling parameters * - matrices for 4 and 7 point calibration */ #define ZP(N,I) ((N) * z_at_pt[I] / 4.0f) // 4.0 = divider to normalize to integers #define Z12(I) ZP(12, I) #define Z4(I) ZP(4, I) #define Z2(I) ZP(2, I) #define Z1(I) ZP(1, I) #define Z0(I) ZP(0, I) // calculate factors if (_7p_9_center) dcr *= 0.9f; h_factor = auto_tune_h(dcr); r_factor = auto_tune_r(dcr); a_factor = auto_tune_a(dcr); if (_7p_9_center) dcr /= 0.9f; switch (probe_points) { case 0: test_precision = 0.0f; // forced end break; case 1: test_precision = 0.0f; // forced end LOOP_NUM_AXES(axis) e_delta[axis] = +Z4(CEN); break; case 2: if (towers_set) { // see 4 point calibration (towers) matrix e_delta.set((+Z4(__A) -Z2(__B) -Z2(__C)) * h_factor +Z4(CEN), (-Z2(__A) +Z4(__B) -Z2(__C)) * h_factor +Z4(CEN), (-Z2(__A) -Z2(__B) +Z4(__C)) * h_factor +Z4(CEN)); r_delta = (+Z4(__A) +Z4(__B) +Z4(__C) -Z12(CEN)) * r_factor; } else { // see 4 point calibration (opposites) matrix e_delta.set((-Z4(_BC) +Z2(_CA) +Z2(_AB)) * h_factor +Z4(CEN), (+Z2(_BC) -Z4(_CA) +Z2(_AB)) * h_factor +Z4(CEN), (+Z2(_BC) +Z2(_CA) -Z4(_AB)) * h_factor +Z4(CEN)); r_delta = (+Z4(_BC) +Z4(_CA) +Z4(_AB) -Z12(CEN)) * r_factor; } break; default: // see 7 point calibration (towers & opposites) matrix e_delta.set((+Z2(__A) -Z1(__B) -Z1(__C) -Z2(_BC) +Z1(_CA) +Z1(_AB)) * h_factor +Z4(CEN), (-Z1(__A) +Z2(__B) -Z1(__C) +Z1(_BC) -Z2(_CA) +Z1(_AB)) * h_factor +Z4(CEN), (-Z1(__A) -Z1(__B) +Z2(__C) +Z1(_BC) +Z1(_CA) -Z2(_AB)) * h_factor +Z4(CEN)); r_delta = (+Z2(__A) +Z2(__B) +Z2(__C) +Z2(_BC) +Z2(_CA) +Z2(_AB) -Z12(CEN)) * r_factor; if (towers_set) { // see 7 point tower angle calibration (towers & opposites) matrix t_delta.set((+Z0(__A) -Z4(__B) +Z4(__C) +Z0(_BC) -Z4(_CA) +Z4(_AB) +Z0(CEN)) * a_factor, (+Z4(__A) +Z0(__B) -Z4(__C) +Z4(_BC) +Z0(_CA) -Z4(_AB) +Z0(CEN)) * a_factor, (-Z4(__A) +Z4(__B) +Z0(__C) -Z4(_BC) +Z4(_CA) +Z0(_AB) +Z0(CEN)) * a_factor); } break; } delta_endstop_adj += e_delta; delta_radius += r_delta; delta_tower_angle_trim += t_delta; } else if (zero_std_dev >= test_precision) { // roll back delta_endstop_adj = e_old; delta_radius = r_old; delta_height = h_old; delta_tower_angle_trim = a_old; } if (verbose_level != 0) { // !dry run // Normalize angles to least-squares if (_angle_results) { float a_sum = 0.0f; LOOP_NUM_AXES(axis) a_sum += delta_tower_angle_trim[axis]; LOOP_NUM_AXES(axis) delta_tower_angle_trim[axis] -= a_sum / 3.0f; } // adjust delta_height and endstops by the max amount const float z_temp = _MAX(delta_endstop_adj.a, delta_endstop_adj.b, delta_endstop_adj.c); delta_height -= z_temp; LOOP_NUM_AXES(axis) delta_endstop_adj[axis] -= z_temp; } recalc_delta_settings(); NOMORE(zero_std_dev_min, zero_std_dev); // print report if (verbose_level == 3 || verbose_level == 0) { print_calibration_results(z_at_pt, _tower_results, _opposite_results); #if HAS_DELTA_SENSORLESS_PROBING if (verbose_level == 0 && probe_points == 1) { if (do_save_offset_adj) probe.set_offset_sensorless_adj(z_at_pt[CEN]); else probe.refresh_largest_sensorless_adj(); } #endif } if (verbose_level != 0) { // !dry run if ((zero_std_dev >= test_precision && iterations > force_iterations) || zero_std_dev <= calibration_precision) { // end iterations SERIAL_ECHOPGM("Calibration OK"); SERIAL_ECHO_SP(32); #if HAS_BED_PROBE if (zero_std_dev >= test_precision && !_1p_calibration && !_0p_calibration) SERIAL_ECHOPGM("rolling back."); else #endif { SERIAL_ECHOPGM("std dev:", p_float_t(zero_std_dev_min, 3)); } SERIAL_EOL(); MString<20> msg(F("Calibration sd:")); if (zero_std_dev_min < 1) msg.appendf(F("0.%03i"), (int)LROUND(zero_std_dev_min * 1000.0f)); else msg.appendf(F("%03i.x"), (int)LROUND(zero_std_dev_min)); ui.set_status(msg); print_calibration_settings(_endstop_results, _angle_results); SERIAL_ECHOLNPGM("Save with M500 and/or copy to Configuration.h"); } else { // !end iterations SString<15> msg; if (iterations < 31) msg.setf(F("Iteration : %02i"), (unsigned int)iterations); else msg.set(F("No convergence")); msg.echo(); SERIAL_ECHO_SP(32); SERIAL_ECHOLNPGM("std dev:", p_float_t(zero_std_dev, 3)); ui.set_status(msg); if (verbose_level > 1) print_calibration_settings(_endstop_results, _angle_results); } } else { // dry run FSTR_P const enddryrun = F("End DRY-RUN"); SERIAL_ECHO(enddryrun); SERIAL_ECHO_SP(35); SERIAL_ECHOLNPGM("std dev:", p_float_t(zero_std_dev, 3)); MString<30> msg(enddryrun, F(" sd:")); if (zero_std_dev < 1) msg.appendf(F("0.%03i"), (int)LROUND(zero_std_dev * 1000.0f)); else msg.appendf(F("%03i.x"), (int)LROUND(zero_std_dev)); ui.set_status(msg); } ac_home(); } while (((zero_std_dev < test_precision && iterations < 31) || iterations <= force_iterations) && zero_std_dev > calibration_precision); ac_cleanup(); TERN_(FULL_REPORT_TO_HOST_FEATURE, set_and_report_grblstate(M_IDLE)); #if HAS_DELTA_SENSORLESS_PROBING probe.test_sensitivity = { true, true, true }; #endif } #endif // DELTA_AUTO_CALIBRATION
2301_81045437/Marlin
Marlin/src/gcode/calibrate/G33.cpp
C++
agpl-3.0
25,915
/** * Marlin 3D Printer Firmware * Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin] * * Based on Sprinter and grbl. * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <https://www.gnu.org/licenses/>. * */ #include "../../inc/MarlinConfigPre.h" #if ENABLED(MECHANICAL_GANTRY_CALIBRATION) #include "../gcode.h" #include "../../module/motion.h" #include "../../module/endstops.h" #if ANY(HAS_MOTOR_CURRENT_SPI, HAS_MOTOR_CURRENT_PWM, HAS_TRINAMIC_CONFIG) #include "../../module/stepper.h" #endif #if HAS_LEVELING #include "../../feature/bedlevel/bedlevel.h" #endif #define DEBUG_OUT ENABLED(DEBUG_LEVELING_FEATURE) #include "../../core/debug_out.h" /** * G34 - Align the ends of the X gantry. See https://youtu.be/3jAFQdTk8iw * * - The carriage moves to GANTRY_CALIBRATION_SAFE_POSITION, also called the “pounce” position. * - If possible, the Z stepper current is reduced to the value specified by 'S' * (or GANTRY_CALIBRATION_CURRENT) to prevent damage to steppers and other parts. * The reduced current should be just high enough to move the Z axis when not blocked. * - The Z axis is jogged past the Z limit, only as far as the specified Z distance * (or GANTRY_CALIBRATION_EXTRA_HEIGHT) at the GANTRY_CALIBRATION_FEEDRATE. * - The Z axis is moved back to the working area (also at GANTRY_CALIBRATION_FEEDRATE). * - Stepper current is restored back to normal. * - The machine is re-homed, according to GANTRY_CALIBRATION_COMMANDS_POST. * * Parameters: * [S<mA>] - Current value to use for the raise move. (Default: GANTRY_CALIBRATION_CURRENT) * [Z<linear>] - Extra distance past Z_MAX_POS to move the Z axis. (Default: GANTRY_CALIBRATION_EXTRA_HEIGHT) */ void GcodeSuite::G34() { // Home before the alignment procedure home_if_needed(); TERN_(HAS_LEVELING, TEMPORARY_BED_LEVELING_STATE(false)); SET_SOFT_ENDSTOP_LOOSE(true); TemporaryGlobalEndstopsState unlock_z(false); #ifdef GANTRY_CALIBRATION_COMMANDS_PRE process_subcommands_now(F(GANTRY_CALIBRATION_COMMANDS_PRE)); if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPGM("Sub Commands Processed"); #endif #ifdef GANTRY_CALIBRATION_SAFE_POSITION // Move XY to safe position if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPGM("Parking XY"); const xy_pos_t safe_pos = GANTRY_CALIBRATION_SAFE_POSITION; do_blocking_move_to_xy(safe_pos, MMM_TO_MMS(GANTRY_CALIBRATION_XY_PARK_FEEDRATE)); #endif const float move_distance = parser.intval('Z', GANTRY_CALIBRATION_EXTRA_HEIGHT), zbase = ENABLED(GANTRY_CALIBRATION_TO_MIN) ? Z_MIN_POS : Z_MAX_POS, zpounce = zbase - move_distance, zgrind = zbase + move_distance; // Move Z to pounce position if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPGM("Setting Z Pounce"); do_blocking_move_to_z(zpounce, homing_feedrate(Z_AXIS)); // Store current motor settings, then apply reduced value #define _REDUCE_CURRENT ANY(HAS_MOTOR_CURRENT_SPI, HAS_MOTOR_CURRENT_PWM, HAS_MOTOR_CURRENT_DAC, HAS_MOTOR_CURRENT_I2C, HAS_TRINAMIC_CONFIG) #if _REDUCE_CURRENT if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPGM("Reducing Current"); #endif #if HAS_MOTOR_CURRENT_SPI const uint16_t target_current = parser.intval('S', GANTRY_CALIBRATION_CURRENT); const uint32_t previous_current = stepper.motor_current_setting[Z_AXIS]; stepper.set_digipot_current(Z_AXIS, target_current); #elif HAS_MOTOR_CURRENT_PWM const uint16_t target_current = parser.intval('S', GANTRY_CALIBRATION_CURRENT); const uint32_t previous_current = stepper.motor_current_setting[1]; // Z stepper.set_digipot_current(1, target_current); #elif HAS_MOTOR_CURRENT_DAC const float target_current = parser.floatval('S', GANTRY_CALIBRATION_CURRENT); const float previous_current = dac_amps(Z_AXIS, target_current); stepper_dac.set_current_value(Z_AXIS, target_current); #elif HAS_MOTOR_CURRENT_I2C const uint16_t target_current = parser.intval('S', GANTRY_CALIBRATION_CURRENT); previous_current = dac_amps(Z_AXIS); digipot_i2c.set_current(Z_AXIS, target_current) #elif HAS_TRINAMIC_CONFIG const uint16_t target_current = parser.intval('S', GANTRY_CALIBRATION_CURRENT); static uint16_t previous_current_arr[NUM_Z_STEPPERS]; #if AXIS_IS_TMC(Z) previous_current_arr[0] = stepperZ.getMilliamps(); stepperZ.rms_current(target_current); #endif #if AXIS_IS_TMC(Z2) previous_current_arr[1] = stepperZ2.getMilliamps(); stepperZ2.rms_current(target_current); #endif #if AXIS_IS_TMC(Z3) previous_current_arr[2] = stepperZ3.getMilliamps(); stepperZ3.rms_current(target_current); #endif #if AXIS_IS_TMC(Z4) previous_current_arr[3] = stepperZ4.getMilliamps(); stepperZ4.rms_current(target_current); #endif #endif // Do Final Z move to adjust if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPGM("Final Z Move"); do_blocking_move_to_z(zgrind, MMM_TO_MMS(GANTRY_CALIBRATION_FEEDRATE)); #if _REDUCE_CURRENT // Reset current to original values if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPGM("Restore Current"); #endif #if HAS_MOTOR_CURRENT_SPI stepper.set_digipot_current(Z_AXIS, previous_current); #elif HAS_MOTOR_CURRENT_PWM stepper.set_digipot_current(1, previous_current); #elif HAS_MOTOR_CURRENT_DAC stepper_dac.set_current_value(Z_AXIS, previous_current); #elif HAS_MOTOR_CURRENT_I2C digipot_i2c.set_current(Z_AXIS, previous_current) #elif HAS_TRINAMIC_CONFIG #if AXIS_IS_TMC(Z) stepperZ.rms_current(previous_current_arr[0]); #endif #if AXIS_IS_TMC(Z2) stepperZ2.rms_current(previous_current_arr[1]); #endif #if AXIS_IS_TMC(Z3) stepperZ3.rms_current(previous_current_arr[2]); #endif #if AXIS_IS_TMC(Z4) stepperZ4.rms_current(previous_current_arr[3]); #endif #endif // Back off end plate, back to normal motion range if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPGM("Z Backoff"); do_blocking_move_to_z(zpounce, MMM_TO_MMS(GANTRY_CALIBRATION_FEEDRATE)); #ifdef GANTRY_CALIBRATION_COMMANDS_POST if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPGM("Running Post Commands"); process_subcommands_now(F(GANTRY_CALIBRATION_COMMANDS_POST)); #endif SET_SOFT_ENDSTOP_LOOSE(false); } #endif // MECHANICAL_GANTRY_CALIBRATION
2301_81045437/Marlin
Marlin/src/gcode/calibrate/G34.cpp
C++
agpl-3.0
6,929
/** * Marlin 3D Printer Firmware * Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin] * * Based on Sprinter and grbl. * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <https://www.gnu.org/licenses/>. * */ #include "../../inc/MarlinConfigPre.h" #if ANY(Z_MULTI_ENDSTOPS, Z_STEPPER_AUTO_ALIGN) #include "../../feature/z_stepper_align.h" #include "../gcode.h" #include "../../module/motion.h" #include "../../module/stepper.h" #include "../../module/planner.h" #include "../../module/probe.h" #include "../../lcd/marlinui.h" // for LCD_MESSAGE #if HAS_LEVELING #include "../../feature/bedlevel/bedlevel.h" #endif #if HAS_Z_STEPPER_ALIGN_STEPPER_XY #include "../../libs/least_squares_fit.h" #endif #if ENABLED(BLTOUCH) #include "../../feature/bltouch.h" #endif #define DEBUG_OUT ENABLED(DEBUG_LEVELING_FEATURE) #include "../../core/debug_out.h" #if NUM_Z_STEPPERS >= 3 #define TRIPLE_Z 1 #if NUM_Z_STEPPERS >= 4 #define QUAD_Z 1 #endif #endif /** * G34: Z-Stepper automatic alignment * * Manual stepper lock controls (reset by G28): * L Unlock all steppers * Z<1-4> Z stepper to lock / unlock * S<state> 0=UNLOCKED 1=LOCKED. If omitted, assume LOCKED. * * Examples: * G34 Z1 ; Lock Z1 * G34 L Z2 ; Unlock all, then lock Z2 * G34 Z2 S0 ; Unlock Z2 * * With Z_STEPPER_AUTO_ALIGN: * I<iterations> Number of tests. If omitted, Z_STEPPER_ALIGN_ITERATIONS. * T<accuracy> Target Accuracy factor. If omitted, Z_STEPPER_ALIGN_ACC. * A<amplification> Provide an Amplification value. If omitted, Z_STEPPER_ALIGN_AMP. * R Flag to recalculate points based on current probe offsets */ void GcodeSuite::G34() { DEBUG_SECTION(log_G34, "G34", DEBUGGING(LEVELING)); if (DEBUGGING(LEVELING)) log_machine_info(); planner.synchronize(); // Prevent damage const bool seenL = parser.seen('L'); if (seenL) stepper.set_all_z_lock(false); const bool seenZ = parser.seenval('Z'); if (seenZ) { const bool state = parser.boolval('S', true); switch (parser.intval('Z')) { case 1: stepper.set_z1_lock(state); break; case 2: stepper.set_z2_lock(state); break; #if TRIPLE_Z case 3: stepper.set_z3_lock(state); break; #if QUAD_Z case 4: stepper.set_z4_lock(state); break; #endif #endif } } if (seenL || seenZ) { stepper.set_separate_multi_axis(seenZ); return; } #if ENABLED(Z_STEPPER_AUTO_ALIGN) do { // break out on error const int8_t z_auto_align_iterations = parser.intval('I', Z_STEPPER_ALIGN_ITERATIONS); if (!WITHIN(z_auto_align_iterations, 1, 30)) { SERIAL_ECHOLNPGM(GCODE_ERR_MSG("(I)teration out of bounds (1-30).")); break; } const float z_auto_align_accuracy = parser.floatval('T', Z_STEPPER_ALIGN_ACC); if (!WITHIN(z_auto_align_accuracy, 0.001f, 1.0f)) { SERIAL_ECHOLNPGM(GCODE_ERR_MSG("(T)arget accuracy out of bounds (0.001-1.0).")); break; } const float z_auto_align_amplification = TERN(HAS_Z_STEPPER_ALIGN_STEPPER_XY, Z_STEPPER_ALIGN_AMP, parser.floatval('A', Z_STEPPER_ALIGN_AMP)); if (!WITHIN(ABS(z_auto_align_amplification), 0.5f, 2.0f)) { SERIAL_ECHOLNPGM(GCODE_ERR_MSG("(A)mplification out of bounds (0.5-2.0).")); break; } if (parser.seen('R')) z_stepper_align.reset_to_default(); const ProbePtRaise raise_after = parser.boolval('E') ? PROBE_PT_STOW : PROBE_PT_RAISE; // Disable the leveling matrix before auto-aligning #if HAS_LEVELING #if ENABLED(RESTORE_LEVELING_AFTER_G34) const bool leveling_was_active = planner.leveling_active; #endif set_bed_leveling_enabled(false); #endif TERN_(CNC_WORKSPACE_PLANES, workspace_plane = PLANE_XY); probe.use_probing_tool(); TERN_(HAS_DUPLICATION_MODE, set_duplication_enabled(false)); // Compute a worst-case clearance height to probe from. After the first // iteration this will be re-calculated based on the actual bed position auto magnitude2 = [&](const uint8_t i, const uint8_t j) { const xy_pos_t diff = z_stepper_align.xy[i] - z_stepper_align.xy[j]; return HYPOT2(diff.x, diff.y); }; const float zoffs = (probe.offset.z < 0) ? -probe.offset.z : 0.0f; float z_probe = (Z_TWEEN_SAFE_CLEARANCE + zoffs) + (G34_MAX_GRADE) * 0.01f * SQRT(_MAX(0, magnitude2(0, 1) #if TRIPLE_Z , magnitude2(2, 1), magnitude2(2, 0) #if QUAD_Z , magnitude2(3, 2), magnitude2(3, 1), magnitude2(3, 0) #endif #endif )); // Home before the alignment procedure home_if_needed(); #if !HAS_Z_STEPPER_ALIGN_STEPPER_XY float last_z_align_move[NUM_Z_STEPPERS] = ARRAY_N_1(NUM_Z_STEPPERS, 10000.0f); #else float last_z_align_level_indicator = 10000.0f; #endif float z_measured[NUM_Z_STEPPERS] = { 0 }, z_maxdiff = 0.0f, amplification = z_auto_align_amplification; #if !HAS_Z_STEPPER_ALIGN_STEPPER_XY bool adjustment_reverse = false; #endif #if HAS_STATUS_MESSAGE PGM_P const msg_iteration = GET_TEXT(MSG_ITERATION); const uint8_t iter_str_len = strlen_P(msg_iteration); #endif // Final z and iteration values will be used after breaking the loop float z_measured_min; uint8_t iteration = 0; bool err_break = false; // To break out of nested loops while (iteration < z_auto_align_iterations) { if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPGM("> probing all positions."); const int iter = iteration + 1; SERIAL_ECHOLNPGM("\nG34 Iteration: ", iter); #if HAS_STATUS_MESSAGE char str[iter_str_len + 2 + 1]; sprintf_P(str, msg_iteration, iter); ui.set_status(str); #endif // Initialize minimum value z_measured_min = 100000.0f; float z_measured_max = -100000.0f; // Probe all positions (one per Z-Stepper) for (uint8_t i = 0; i < NUM_Z_STEPPERS; ++i) { // iteration odd/even --> downward / upward stepper sequence const uint8_t iprobe = (iteration & 1) ? NUM_Z_STEPPERS - 1 - i : i; xy_pos_t &ppos = z_stepper_align.xy[iprobe]; if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPGM_P(PSTR("Probing X"), ppos.x, SP_Y_STR, ppos.y); // Probe a Z height for each stepper. // Probing sanity check is disabled, as it would trigger even in normal cases because // current_position.z has been manually altered in the "dirty trick" above. const float z_probed_height = probe.probe_at_point(DIFF_TERN(HAS_HOME_OFFSET, ppos, xy_pos_t(home_offset)), raise_after, 0, true, false, (Z_PROBE_LOW_POINT) - z_probe * 0.5f, z_probe * 0.5f); if (isnan(z_probed_height)) { SERIAL_ECHOLNPGM(STR_ERR_PROBING_FAILED); LCD_MESSAGE(MSG_LCD_PROBING_FAILED); err_break = true; break; } // Add height to each value, to provide a more useful target height for // the next iteration of probing. This allows adjustments to be made away from the bed. z_measured[iprobe] = z_probed_height + (Z_TWEEN_SAFE_CLEARANCE + zoffs); //do we need to add the clearance to this? if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPGM("> Z", iprobe + 1, " measured position is ", z_measured[iprobe]); // Remember the minimum measurement to calculate the correction later on z_measured_min = _MIN(z_measured_min, z_measured[iprobe]); z_measured_max = _MAX(z_measured_max, z_measured[iprobe]); } // for (i) if (err_break) break; // Adapt the next probe clearance height based on the new measurements. // Safe_height = lowest distance to bed (= highest measurement) plus highest measured misalignment. z_maxdiff = z_measured_max - z_measured_min; z_probe = (Z_TWEEN_SAFE_CLEARANCE + zoffs) + z_measured_max + z_maxdiff; //Not sure we need z_maxdiff, but leaving it in for safety. #if HAS_Z_STEPPER_ALIGN_STEPPER_XY // Replace the initial values in z_measured with calculated heights at // each stepper position. This allows the adjustment algorithm to be // shared between both possible probing mechanisms. // This must be done after the next z_probe height is calculated, so that // the height is calculated from actual print area positions, and not // extrapolated motor movements. // Compute the least-squares fit for all probed points. // Calculate the Z position of each stepper and store it in z_measured. // This allows the actual adjustment logic to be shared by both algorithms. linear_fit_data lfd; incremental_LSF_reset(&lfd); for (uint8_t i = 0; i < NUM_Z_STEPPERS; ++i) { SERIAL_ECHOLNPGM("PROBEPT_", i, ": ", z_measured[i]); incremental_LSF(&lfd, z_stepper_align.xy[i], z_measured[i]); } finish_incremental_LSF(&lfd); z_measured_min = 100000.0f; for (uint8_t i = 0; i < NUM_Z_STEPPERS; ++i) { z_measured[i] = -(lfd.A * z_stepper_align.stepper_xy[i].x + lfd.B * z_stepper_align.stepper_xy[i].y + lfd.D); z_measured_min = _MIN(z_measured_min, z_measured[i]); } SERIAL_ECHOLNPGM( LIST_N(DOUBLE(NUM_Z_STEPPERS), "Calculated Z1=", z_measured[0], " Z2=", z_measured[1], " Z3=", z_measured[2], " Z4=", z_measured[3] ) ); #endif SERIAL_EOL(); SString<15 + TERN0(TRIPLE_Z, 30) + TERN0(QUAD_Z, 45)> msg(F("1:2="), p_float_t(ABS(z_measured[1] - z_measured[0]), 3)); #if TRIPLE_Z msg.append(F(" 3-2="), p_float_t(ABS(z_measured[2] - z_measured[1]), 3)) .append(F(" 3-1="), p_float_t(ABS(z_measured[2] - z_measured[0]), 3)); #endif #if QUAD_Z msg.append(F(" 4-3="), p_float_t(ABS(z_measured[3] - z_measured[2]), 3)) .append(F(" 4-2="), p_float_t(ABS(z_measured[3] - z_measured[1]), 3)) .append(F(" 4-1="), p_float_t(ABS(z_measured[3] - z_measured[0]), 3)); #endif msg.echoln(); ui.set_status(msg); auto decreasing_accuracy = [](const_float_t v1, const_float_t v2) { if (v1 < v2 * 0.7f) { SERIAL_ECHOLNPGM("Decreasing Accuracy Detected."); LCD_MESSAGE(MSG_DECREASING_ACCURACY); return true; } return false; }; #if HAS_Z_STEPPER_ALIGN_STEPPER_XY // Check if the applied corrections go in the correct direction. // Calculate the sum of the absolute deviations from the mean of the probe measurements. // Compare to the last iteration to ensure it's getting better. // Calculate mean value as a reference float z_measured_mean = 0.0f; for (uint8_t zstepper = 0; zstepper < NUM_Z_STEPPERS; ++zstepper) z_measured_mean += z_measured[zstepper]; z_measured_mean /= NUM_Z_STEPPERS; // Calculate the sum of the absolute deviations from the mean value float z_align_level_indicator = 0.0f; for (uint8_t zstepper = 0; zstepper < NUM_Z_STEPPERS; ++zstepper) z_align_level_indicator += ABS(z_measured[zstepper] - z_measured_mean); // If it's getting worse, stop and throw an error err_break = decreasing_accuracy(last_z_align_level_indicator, z_align_level_indicator); if (err_break) break; last_z_align_level_indicator = z_align_level_indicator; #endif // The following correction actions are to be enabled for select Z-steppers only stepper.set_separate_multi_axis(true); bool success_break = true; // Correct the individual stepper offsets for (uint8_t zstepper = 0; zstepper < NUM_Z_STEPPERS; ++zstepper) { // Calculate current stepper move float z_align_move = z_measured[zstepper] - z_measured_min; const float z_align_abs = ABS(z_align_move); #if !HAS_Z_STEPPER_ALIGN_STEPPER_XY // Optimize one iteration's correction based on the first measurements if (z_align_abs) amplification = (iteration == 1) ? _MIN(last_z_align_move[zstepper] / z_align_abs, 2.0f) : z_auto_align_amplification; // Check for less accuracy compared to last move if (decreasing_accuracy(last_z_align_move[zstepper], z_align_abs)) { if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPGM("> Z", zstepper + 1, " last_z_align_move = ", last_z_align_move[zstepper]); if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPGM("> Z", zstepper + 1, " z_align_abs = ", z_align_abs); adjustment_reverse = !adjustment_reverse; } // Remember the alignment for the next iteration, but only if steppers move, // otherwise it would be just zero (in case this stepper was at z_measured_min already) if (z_align_abs > 0) last_z_align_move[zstepper] = z_align_abs; #endif // Stop early if all measured points achieve accuracy target if (z_align_abs > z_auto_align_accuracy) success_break = false; if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPGM("> Z", zstepper + 1, " corrected by ", z_align_move); // Lock all steppers except one stepper.set_all_z_lock(true, zstepper); #if !HAS_Z_STEPPER_ALIGN_STEPPER_XY // Decreasing accuracy was detected so move was inverted. // Will match reversed Z steppers on dual steppers. Triple will need more work to map. if (adjustment_reverse) { z_align_move = -z_align_move; if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPGM("> Z", zstepper + 1, " correction reversed to ", z_align_move); } #endif // Do a move to correct part of the misalignment for the current stepper do_blocking_move_to_z(amplification * z_align_move + current_position.z); } // for (zstepper) // Back to normal stepper operations stepper.set_all_z_lock(false); stepper.set_separate_multi_axis(false); if (err_break) break; if (success_break) { SERIAL_ECHOLNPGM("Target accuracy achieved."); LCD_MESSAGE(MSG_ACCURACY_ACHIEVED); break; } iteration++; } // while (iteration < z_auto_align_iterations) if (err_break) SERIAL_ECHOLNPGM("G34 aborted."); else { SERIAL_ECHOLNPGM("Did ", iteration + (iteration != z_auto_align_iterations), " of ", z_auto_align_iterations); SERIAL_ECHOLNPGM("Accuracy: ", p_float_t(z_maxdiff, 2)); } // Stow the probe because the last call to probe.probe_at_point(...) // leaves the probe deployed when it's successful. IF_DISABLED(TOUCH_MI_PROBE, probe.stow()); #if ENABLED(HOME_AFTER_G34) // Home Z after the alignment procedure process_subcommands_now(F("G28Z")); #else // Use the probed height from the last iteration to determine the Z height. // z_measured_min is used, because all steppers are aligned to z_measured_min. // Ideally, this would be equal to the 'z_probe * 0.5f' which was added earlier. current_position.z -= z_measured_min - (Z_TWEEN_SAFE_CLEARANCE + zoffs); //we shouldn't want to subtract the clearance from here right? (Depends if we added it further up) sync_plan_position(); #endif probe.use_probing_tool(false); #if ALL(HAS_LEVELING, RESTORE_LEVELING_AFTER_G34) set_bed_leveling_enabled(leveling_was_active); #endif }while(0); probe.use_probing_tool(false); #endif // Z_STEPPER_AUTO_ALIGN } #endif // Z_MULTI_ENDSTOPS || Z_STEPPER_AUTO_ALIGN #if ENABLED(Z_STEPPER_AUTO_ALIGN) /** * M422: Set a Z-Stepper automatic alignment XY point. * Use repeatedly to set multiple points. * * S<index> : Index of the probe point to set * * With Z_STEPPER_ALIGN_STEPPER_XY: * W<index> : Index of the Z stepper position to set * The W and S parameters may not be combined. * * S and W require an X and/or Y parameter * X<pos> : X position to set (Unchanged if omitted) * Y<pos> : Y position to set (Unchanged if omitted) * * R : Recalculate points based on current probe offsets */ void GcodeSuite::M422() { if (!parser.seen_any()) return M422_report(); if (parser.seen('R')) { z_stepper_align.reset_to_default(); return; } const bool is_probe_point = parser.seen_test('S'); if (TERN0(HAS_Z_STEPPER_ALIGN_STEPPER_XY, is_probe_point && parser.seen_test('W'))) { SERIAL_ECHOLNPGM(GCODE_ERR_MSG("(S) and (W) may not be combined.")); return; } xy_pos_t * const pos_dest = ( TERN_(HAS_Z_STEPPER_ALIGN_STEPPER_XY, !is_probe_point ? z_stepper_align.stepper_xy :) z_stepper_align.xy ); if (!is_probe_point && TERN1(HAS_Z_STEPPER_ALIGN_STEPPER_XY, !parser.seen_test('W'))) { SERIAL_ECHOLNPGM(GCODE_ERR_MSG("(S)" TERN_(HAS_Z_STEPPER_ALIGN_STEPPER_XY, " or (W)") " is required.")); return; } // Get the Probe Position Index or Z Stepper Index int8_t position_index = 1; FSTR_P err_string = F("?(S) Probe-position"); if (is_probe_point) position_index = parser.intval('S'); else { #if HAS_Z_STEPPER_ALIGN_STEPPER_XY err_string = F("?(W) Z-stepper"); position_index = parser.intval('W'); #endif } if (!WITHIN(position_index, 1, NUM_Z_STEPPERS)) { SERIAL_ECHOLN(err_string, F(" index invalid (1.." STRINGIFY(NUM_Z_STEPPERS) ").")); return; } --position_index; const xy_pos_t pos = { parser.floatval('X', pos_dest[position_index].x), parser.floatval('Y', pos_dest[position_index].y) }; if (is_probe_point) { if (!probe.can_reach(pos.x, Y_CENTER)) { SERIAL_ECHOLNPGM(GCODE_ERR_MSG("(X) out of bounds.")); return; } if (!probe.can_reach(pos)) { SERIAL_ECHOLNPGM(GCODE_ERR_MSG("(Y) out of bounds.")); return; } } pos_dest[position_index] = pos; } void GcodeSuite::M422_report(const bool forReplay/*=true*/) { TERN_(MARLIN_SMALL_BUILD, return); report_heading(forReplay, F(STR_Z_AUTO_ALIGN)); for (uint8_t i = 0; i < NUM_Z_STEPPERS; ++i) { report_echo_start(forReplay); SERIAL_ECHOLNPGM_P( PSTR(" M422 S"), i + 1, SP_X_STR, z_stepper_align.xy[i].x, SP_Y_STR, z_stepper_align.xy[i].y ); } #if HAS_Z_STEPPER_ALIGN_STEPPER_XY for (uint8_t i = 0; i < NUM_Z_STEPPERS; ++i) { report_echo_start(forReplay); SERIAL_ECHOLNPGM_P( PSTR(" M422 W"), i + 1, SP_X_STR, z_stepper_align.stepper_xy[i].x, SP_Y_STR, z_stepper_align.stepper_xy[i].y ); } #endif } #endif // Z_STEPPER_AUTO_ALIGN
2301_81045437/Marlin
Marlin/src/gcode/calibrate/G34_M422.cpp
C++
agpl-3.0
19,830
/** * Marlin 3D Printer Firmware * Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin] * * Based on Sprinter and grbl. * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <https://www.gnu.org/licenses/>. * */ #include "../../MarlinCore.h" #if ENABLED(CALIBRATION_GCODE) #include "../gcode.h" #if ENABLED(BACKLASH_GCODE) #include "../../feature/backlash.h" #endif #include "../../lcd/marlinui.h" #include "../../module/motion.h" #include "../../module/planner.h" #include "../../module/endstops.h" #include "../../feature/bedlevel/bedlevel.h" #if HAS_MULTI_HOTEND #include "../../module/tool_change.h" #endif #if !AXIS_CAN_CALIBRATE(X) #undef CALIBRATION_MEASURE_LEFT #undef CALIBRATION_MEASURE_RIGHT #endif #if !AXIS_CAN_CALIBRATE(Y) #undef CALIBRATION_MEASURE_FRONT #undef CALIBRATION_MEASURE_BACK #endif #if !AXIS_CAN_CALIBRATE(Z) #undef CALIBRATION_MEASURE_AT_TOP_EDGES #endif /** * G425 backs away from the calibration object by various distances * depending on the confidence level: * * UNKNOWN - No real notion on where the calibration object is on the bed * UNCERTAIN - Measurement may be uncertain due to backlash * CERTAIN - Measurement obtained with backlash compensation */ #ifndef CALIBRATION_MEASUREMENT_UNKNOWN #define CALIBRATION_MEASUREMENT_UNKNOWN 5.0 // mm #endif #ifndef CALIBRATION_MEASUREMENT_UNCERTAIN #define CALIBRATION_MEASUREMENT_UNCERTAIN 1.0 // mm #endif #ifndef CALIBRATION_MEASUREMENT_CERTAIN #define CALIBRATION_MEASUREMENT_CERTAIN 0.5 // mm #endif #if ALL(HAS_X_AXIS, CALIBRATION_MEASURE_LEFT, CALIBRATION_MEASURE_RIGHT) #define HAS_X_CENTER 1 #endif #if ALL(HAS_Y_AXIS, CALIBRATION_MEASURE_FRONT, CALIBRATION_MEASURE_BACK) #define HAS_Y_CENTER 1 #endif #if ALL(HAS_I_AXIS, CALIBRATION_MEASURE_IMIN, CALIBRATION_MEASURE_IMAX) #define HAS_I_CENTER 1 #endif #if ALL(HAS_J_AXIS, CALIBRATION_MEASURE_JMIN, CALIBRATION_MEASURE_JMAX) #define HAS_J_CENTER 1 #endif #if ALL(HAS_K_AXIS, CALIBRATION_MEASURE_KMIN, CALIBRATION_MEASURE_KMAX) #define HAS_K_CENTER 1 #endif #if ALL(HAS_U_AXIS, CALIBRATION_MEASURE_UMIN, CALIBRATION_MEASURE_UMAX) #define HAS_U_CENTER 1 #endif #if ALL(HAS_V_AXIS, CALIBRATION_MEASURE_VMIN, CALIBRATION_MEASURE_VMAX) #define HAS_V_CENTER 1 #endif #if ALL(HAS_W_AXIS, CALIBRATION_MEASURE_WMIN, CALIBRATION_MEASURE_WMAX) #define HAS_W_CENTER 1 #endif enum side_t : uint8_t { TOP, RIGHT, FRONT, LEFT, BACK, NUM_SIDES, LIST_N(DOUBLE(SECONDARY_AXES), IMINIMUM, IMAXIMUM, JMINIMUM, JMAXIMUM, KMINIMUM, KMAXIMUM, UMINIMUM, UMAXIMUM, VMINIMUM, VMAXIMUM, WMINIMUM, WMAXIMUM) }; static constexpr xyz_pos_t true_center CALIBRATION_OBJECT_CENTER; static constexpr xyz_float_t dimensions CALIBRATION_OBJECT_DIMENSIONS; static constexpr xy_float_t nod = { CALIBRATION_NOZZLE_OUTER_DIAMETER, CALIBRATION_NOZZLE_OUTER_DIAMETER }; struct measurements_t { xyz_pos_t obj_center = true_center; // Non-static must be assigned from xyz_pos_t float obj_side[NUM_SIDES], backlash[NUM_SIDES]; xyz_float_t pos_error; xy_float_t nozzle_outer_dimension = nod; }; #if ENABLED(BACKLASH_GCODE) class restorer_correction { const uint8_t val_; public: restorer_correction(const uint8_t temp_val) : val_(backlash.get_correction_uint8()) { backlash.set_correction_uint8(temp_val); } ~restorer_correction() { backlash.set_correction_uint8(val_); } }; #define TEMPORARY_BACKLASH_CORRECTION(value) restorer_correction restorer_tbst(value) #else #define TEMPORARY_BACKLASH_CORRECTION(value) #endif #if ENABLED(BACKLASH_GCODE) && defined(BACKLASH_SMOOTHING_MM) class restorer_smoothing { const float val_; public: restorer_smoothing(const float temp_val) : val_(backlash.get_smoothing_mm()) { backlash.set_smoothing_mm(temp_val); } ~restorer_smoothing() { backlash.set_smoothing_mm(val_); } }; #define TEMPORARY_BACKLASH_SMOOTHING(value) restorer_smoothing restorer_tbsm(value) #else #define TEMPORARY_BACKLASH_SMOOTHING(value) #endif inline void calibration_move() { do_blocking_move_to((xyz_pos_t)current_position, MMM_TO_MMS(CALIBRATION_FEEDRATE_TRAVEL)); } /** * Move to the exact center above the calibration object * * m in - Measurement record * uncertainty in - How far away from the object top to park */ inline void park_above_object(measurements_t &m, const float uncertainty) { // Move to safe distance above calibration object current_position.z = m.obj_center.z + dimensions.z / 2 + uncertainty; calibration_move(); // Move to center of calibration object in XY current_position = xy_pos_t(m.obj_center); calibration_move(); } #if HAS_MULTI_HOTEND inline void set_nozzle(measurements_t &m, const uint8_t extruder) { if (extruder != active_extruder) { park_above_object(m, CALIBRATION_MEASUREMENT_UNKNOWN); tool_change(extruder); } } #endif #if HAS_HOTEND_OFFSET inline void normalize_hotend_offsets() { for (uint8_t e = 1; e < HOTENDS; ++e) hotend_offset[e] -= hotend_offset[0]; hotend_offset[0].reset(); } #endif #if !PIN_EXISTS(CALIBRATION) #include "../../module/probe.h" #endif inline bool read_calibration_pin() { return ( #if PIN_EXISTS(CALIBRATION) READ(CALIBRATION_PIN) != CALIBRATION_PIN_INVERTING #else PROBE_TRIGGERED() #endif ); } /** * Move along axis in the specified dir until the probe value becomes stop_state, * then return the axis value. * * axis in - Axis along which the measurement will take place * dir in - Direction along that axis (-1 or 1) * stop_state in - Move until probe pin becomes this value * fast in - Fast vs. precise measurement */ float measuring_movement(const AxisEnum axis, const int dir, const bool stop_state, const bool fast) { const float step = fast ? 0.25 : CALIBRATION_MEASUREMENT_RESOLUTION; const feedRate_t mms = fast ? MMM_TO_MMS(CALIBRATION_FEEDRATE_FAST) : MMM_TO_MMS(CALIBRATION_FEEDRATE_SLOW); const float limit = fast ? 50 : 5; destination = current_position; for (float travel = 0; travel < limit; travel += step) { destination[axis] += dir * step; do_blocking_move_to((xyz_pos_t)destination, mms); planner.synchronize(); if (read_calibration_pin() == stop_state) break; } return destination[axis]; } /** * Move along axis until the probe is triggered. Move toolhead to its starting * point and return the measured value. * * axis in - Axis along which the measurement will take place * dir in - Direction along that axis (-1 or 1) * stop_state in - Move until probe pin becomes this value * backlash_ptr in/out - When not nullptr, measure and record axis backlash * uncertainty in - If uncertainty is CALIBRATION_MEASUREMENT_UNKNOWN, do a fast probe. */ inline float measure(const AxisEnum axis, const int dir, const bool stop_state, float * const backlash_ptr, const float uncertainty) { const bool fast = uncertainty == CALIBRATION_MEASUREMENT_UNKNOWN; // Save the current position of the specified axis const float start_pos = current_position[axis]; // Take a measurement. Only the specified axis will be affected. const float measured_pos = measuring_movement(axis, dir, stop_state, fast); // Measure backlash if (backlash_ptr && !fast) { const float release_pos = measuring_movement(axis, -dir, !stop_state, fast); *backlash_ptr = ABS(release_pos - measured_pos); } // Move back to the starting position destination = current_position; destination[axis] = start_pos; do_blocking_move_to((xyz_pos_t)destination, MMM_TO_MMS(CALIBRATION_FEEDRATE_TRAVEL)); return measured_pos; } /** * Probe one side of the calibration object * * m in/out - Measurement record, m.obj_center and m.obj_side will be updated. * uncertainty in - How far away from the calibration object to begin probing * side in - Side of probe where probe will occur * probe_top_at_edge in - When probing sides, probe top of calibration object nearest edge * to find out height of edge */ inline void probe_side(measurements_t &m, const float uncertainty, const side_t side, const bool probe_top_at_edge=false) { const xyz_float_t dimensions = CALIBRATION_OBJECT_DIMENSIONS; AxisEnum axis; float dir = 1; park_above_object(m, uncertainty); #define _ACASE(N,A,B) case A: dir = -1; case B: axis = N##_AXIS; break #define _PCASE(N) _ACASE(N, N##MINIMUM, N##MAXIMUM) switch (side) { #if AXIS_CAN_CALIBRATE(X) _ACASE(X, RIGHT, LEFT); #endif #if AXIS_CAN_CALIBRATE(Y) _ACASE(Y, BACK, FRONT); #endif #if AXIS_CAN_CALIBRATE(Z) case TOP: { const float measurement = measure(Z_AXIS, -1, true, &m.backlash[TOP], uncertainty); m.obj_center.z = measurement - dimensions.z / 2; m.obj_side[TOP] = measurement; return; } #endif #if AXIS_CAN_CALIBRATE(I) _PCASE(I); #endif #if AXIS_CAN_CALIBRATE(J) _PCASE(J); #endif #if AXIS_CAN_CALIBRATE(K) _PCASE(K); #endif #if AXIS_CAN_CALIBRATE(U) _PCASE(U); #endif #if AXIS_CAN_CALIBRATE(V) _PCASE(V); #endif #if AXIS_CAN_CALIBRATE(W) _PCASE(W); #endif default: return; } if (probe_top_at_edge) { #if AXIS_CAN_CALIBRATE(Z) // Probe top nearest the side we are probing current_position[axis] = m.obj_center[axis] + (-dir) * (dimensions[axis] / 2 - m.nozzle_outer_dimension[axis]); calibration_move(); m.obj_side[TOP] = measure(Z_AXIS, -1, true, &m.backlash[TOP], uncertainty); m.obj_center.z = m.obj_side[TOP] - dimensions.z / 2; #endif } if ((AXIS_CAN_CALIBRATE(X) && axis == X_AXIS) || (AXIS_CAN_CALIBRATE(Y) && axis == Y_AXIS)) { // Move to safe distance to the side of the calibration object current_position[axis] = m.obj_center[axis] + (-dir) * (dimensions[axis] / 2 + m.nozzle_outer_dimension[axis] / 2 + uncertainty); calibration_move(); // Plunge below the side of the calibration object and measure current_position.z = m.obj_side[TOP] - (CALIBRATION_NOZZLE_TIP_HEIGHT) * 0.7f; calibration_move(); const float measurement = measure(axis, dir, true, &m.backlash[side], uncertainty); m.obj_center[axis] = measurement + dir * (dimensions[axis] / 2 + m.nozzle_outer_dimension[axis] / 2); m.obj_side[side] = measurement; } } /** * Probe all sides of the calibration calibration object * * m in/out - Measurement record: center, backlash and error values be updated. * uncertainty in - How far away from the calibration object to begin probing */ inline void probe_sides(measurements_t &m, const float uncertainty) { #if ENABLED(CALIBRATION_MEASURE_AT_TOP_EDGES) constexpr bool probe_top_at_edge = true; #else // Probing at the exact center only works if the center is flat. Probing on a washer // or bolt will require probing the top near the side edges, away from the center. constexpr bool probe_top_at_edge = false; probe_side(m, uncertainty, TOP); #endif TERN_(CALIBRATION_MEASURE_RIGHT, probe_side(m, uncertainty, RIGHT, probe_top_at_edge)); TERN_(CALIBRATION_MEASURE_FRONT, probe_side(m, uncertainty, FRONT, probe_top_at_edge)); TERN_(CALIBRATION_MEASURE_LEFT, probe_side(m, uncertainty, LEFT, probe_top_at_edge)); TERN_(CALIBRATION_MEASURE_BACK, probe_side(m, uncertainty, BACK, probe_top_at_edge)); TERN_(CALIBRATION_MEASURE_IMIN, probe_side(m, uncertainty, IMINIMUM, probe_top_at_edge)); TERN_(CALIBRATION_MEASURE_IMAX, probe_side(m, uncertainty, IMAXIMUM, probe_top_at_edge)); TERN_(CALIBRATION_MEASURE_JMIN, probe_side(m, uncertainty, JMINIMUM, probe_top_at_edge)); TERN_(CALIBRATION_MEASURE_JMAX, probe_side(m, uncertainty, JMAXIMUM, probe_top_at_edge)); TERN_(CALIBRATION_MEASURE_KMIN, probe_side(m, uncertainty, KMINIMUM, probe_top_at_edge)); TERN_(CALIBRATION_MEASURE_KMAX, probe_side(m, uncertainty, KMAXIMUM, probe_top_at_edge)); TERN_(CALIBRATION_MEASURE_UMIN, probe_side(m, uncertainty, UMINIMUM, probe_top_at_edge)); TERN_(CALIBRATION_MEASURE_UMAX, probe_side(m, uncertainty, UMAXIMUM, probe_top_at_edge)); TERN_(CALIBRATION_MEASURE_VMIN, probe_side(m, uncertainty, VMINIMUM, probe_top_at_edge)); TERN_(CALIBRATION_MEASURE_VMAX, probe_side(m, uncertainty, VMAXIMUM, probe_top_at_edge)); TERN_(CALIBRATION_MEASURE_WMIN, probe_side(m, uncertainty, WMINIMUM, probe_top_at_edge)); TERN_(CALIBRATION_MEASURE_WMAX, probe_side(m, uncertainty, WMAXIMUM, probe_top_at_edge)); // Compute the measured center of the calibration object. TERN_(HAS_X_CENTER, m.obj_center.x = (m.obj_side[LEFT] + m.obj_side[RIGHT]) / 2); TERN_(HAS_Y_CENTER, m.obj_center.y = (m.obj_side[FRONT] + m.obj_side[BACK]) / 2); TERN_(HAS_I_CENTER, m.obj_center.i = (m.obj_side[IMINIMUM] + m.obj_side[IMAXIMUM]) / 2); TERN_(HAS_J_CENTER, m.obj_center.j = (m.obj_side[JMINIMUM] + m.obj_side[JMAXIMUM]) / 2); TERN_(HAS_K_CENTER, m.obj_center.k = (m.obj_side[KMINIMUM] + m.obj_side[KMAXIMUM]) / 2); TERN_(HAS_U_CENTER, m.obj_center.u = (m.obj_side[UMINIMUM] + m.obj_side[UMAXIMUM]) / 2); TERN_(HAS_V_CENTER, m.obj_center.v = (m.obj_side[VMINIMUM] + m.obj_side[VMAXIMUM]) / 2); TERN_(HAS_W_CENTER, m.obj_center.w = (m.obj_side[WMINIMUM] + m.obj_side[WMAXIMUM]) / 2); // Compute the outside diameter of the nozzle at the height // at which it makes contact with the calibration object TERN_(HAS_X_CENTER, m.nozzle_outer_dimension.x = m.obj_side[RIGHT] - m.obj_side[LEFT] - dimensions.x); TERN_(HAS_Y_CENTER, m.nozzle_outer_dimension.y = m.obj_side[BACK] - m.obj_side[FRONT] - dimensions.y); park_above_object(m, uncertainty); // The difference between the known and the measured location // of the calibration object is the positional error NUM_AXIS_CODE( m.pos_error.x = TERN0(HAS_X_CENTER, true_center.x - m.obj_center.x), m.pos_error.y = TERN0(HAS_Y_CENTER, true_center.y - m.obj_center.y), m.pos_error.z = true_center.z - m.obj_center.z, m.pos_error.i = TERN0(HAS_I_CENTER, true_center.i - m.obj_center.i), m.pos_error.j = TERN0(HAS_J_CENTER, true_center.j - m.obj_center.j), m.pos_error.k = TERN0(HAS_K_CENTER, true_center.k - m.obj_center.k), m.pos_error.u = TERN0(HAS_U_CENTER, true_center.u - m.obj_center.u), m.pos_error.v = TERN0(HAS_V_CENTER, true_center.v - m.obj_center.v), m.pos_error.w = TERN0(HAS_W_CENTER, true_center.w - m.obj_center.w) ); } #if ENABLED(CALIBRATION_REPORTING) inline void report_measured_faces(const measurements_t &m) { SERIAL_ECHOLNPGM("Sides:"); #if AXIS_CAN_CALIBRATE(Z) SERIAL_ECHOLNPGM(" Top: ", m.obj_side[TOP]); #endif #if HAS_X_AXIS #if ENABLED(CALIBRATION_MEASURE_LEFT) SERIAL_ECHOLNPGM(" Left: ", m.obj_side[LEFT]); #endif #if ENABLED(CALIBRATION_MEASURE_RIGHT) SERIAL_ECHOLNPGM(" Right: ", m.obj_side[RIGHT]); #endif #endif #if HAS_Y_AXIS #if ENABLED(CALIBRATION_MEASURE_FRONT) SERIAL_ECHOLNPGM(" Front: ", m.obj_side[FRONT]); #endif #if ENABLED(CALIBRATION_MEASURE_BACK) SERIAL_ECHOLNPGM(" Back: ", m.obj_side[BACK]); #endif #endif #if HAS_I_AXIS #if ENABLED(CALIBRATION_MEASURE_IMIN) SERIAL_ECHOLNPGM(" " STR_I_MIN ": ", m.obj_side[IMINIMUM]); #endif #if ENABLED(CALIBRATION_MEASURE_IMAX) SERIAL_ECHOLNPGM(" " STR_I_MAX ": ", m.obj_side[IMAXIMUM]); #endif #endif #if HAS_J_AXIS #if ENABLED(CALIBRATION_MEASURE_JMIN) SERIAL_ECHOLNPGM(" " STR_J_MIN ": ", m.obj_side[JMINIMUM]); #endif #if ENABLED(CALIBRATION_MEASURE_JMAX) SERIAL_ECHOLNPGM(" " STR_J_MAX ": ", m.obj_side[JMAXIMUM]); #endif #endif #if HAS_K_AXIS #if ENABLED(CALIBRATION_MEASURE_KMIN) SERIAL_ECHOLNPGM(" " STR_K_MIN ": ", m.obj_side[KMINIMUM]); #endif #if ENABLED(CALIBRATION_MEASURE_KMAX) SERIAL_ECHOLNPGM(" " STR_K_MAX ": ", m.obj_side[KMAXIMUM]); #endif #endif #if HAS_U_AXIS #if ENABLED(CALIBRATION_MEASURE_UMIN) SERIAL_ECHOLNPGM(" " STR_U_MIN ": ", m.obj_side[UMINIMUM]); #endif #if ENABLED(CALIBRATION_MEASURE_UMAX) SERIAL_ECHOLNPGM(" " STR_U_MAX ": ", m.obj_side[UMAXIMUM]); #endif #endif #if HAS_V_AXIS #if ENABLED(CALIBRATION_MEASURE_VMIN) SERIAL_ECHOLNPGM(" " STR_V_MIN ": ", m.obj_side[VMINIMUM]); #endif #if ENABLED(CALIBRATION_MEASURE_VMAX) SERIAL_ECHOLNPGM(" " STR_V_MAX ": ", m.obj_side[VMAXIMUM]); #endif #endif #if HAS_W_AXIS #if ENABLED(CALIBRATION_MEASURE_WMIN) SERIAL_ECHOLNPGM(" " STR_W_MIN ": ", m.obj_side[WMINIMUM]); #endif #if ENABLED(CALIBRATION_MEASURE_WMAX) SERIAL_ECHOLNPGM(" " STR_W_MAX ": ", m.obj_side[WMAXIMUM]); #endif #endif SERIAL_EOL(); } inline void report_measured_center(const measurements_t &m) { SERIAL_ECHOLNPGM("Center:"); #if HAS_X_CENTER SERIAL_ECHOLNPGM_P(SP_X_STR, m.obj_center.x); #endif #if HAS_Y_CENTER SERIAL_ECHOLNPGM_P(SP_Y_STR, m.obj_center.y); #endif SERIAL_ECHOLNPGM_P(SP_Z_STR, m.obj_center.z); #if HAS_I_CENTER SERIAL_ECHOLNPGM_P(SP_I_STR, m.obj_center.i); #endif #if HAS_J_CENTER SERIAL_ECHOLNPGM_P(SP_J_STR, m.obj_center.j); #endif #if HAS_K_CENTER SERIAL_ECHOLNPGM_P(SP_K_STR, m.obj_center.k); #endif #if HAS_U_CENTER SERIAL_ECHOLNPGM_P(SP_U_STR, m.obj_center.u); #endif #if HAS_V_CENTER SERIAL_ECHOLNPGM_P(SP_V_STR, m.obj_center.v); #endif #if HAS_W_CENTER SERIAL_ECHOLNPGM_P(SP_W_STR, m.obj_center.w); #endif SERIAL_EOL(); } inline void report_measured_backlash(const measurements_t &m) { SERIAL_ECHOLNPGM("Backlash:"); #if AXIS_CAN_CALIBRATE(X) #if ENABLED(CALIBRATION_MEASURE_LEFT) SERIAL_ECHOLNPGM(" Left: ", m.backlash[LEFT]); #endif #if ENABLED(CALIBRATION_MEASURE_RIGHT) SERIAL_ECHOLNPGM(" Right: ", m.backlash[RIGHT]); #endif #endif #if AXIS_CAN_CALIBRATE(Y) #if ENABLED(CALIBRATION_MEASURE_FRONT) SERIAL_ECHOLNPGM(" Front: ", m.backlash[FRONT]); #endif #if ENABLED(CALIBRATION_MEASURE_BACK) SERIAL_ECHOLNPGM(" Back: ", m.backlash[BACK]); #endif #endif #if AXIS_CAN_CALIBRATE(Z) SERIAL_ECHOLNPGM(" Top: ", m.backlash[TOP]); #endif #if AXIS_CAN_CALIBRATE(I) #if ENABLED(CALIBRATION_MEASURE_IMIN) SERIAL_ECHOLNPGM(" " STR_I_MIN ": ", m.backlash[IMINIMUM]); #endif #if ENABLED(CALIBRATION_MEASURE_IMAX) SERIAL_ECHOLNPGM(" " STR_I_MAX ": ", m.backlash[IMAXIMUM]); #endif #endif #if AXIS_CAN_CALIBRATE(J) #if ENABLED(CALIBRATION_MEASURE_JMIN) SERIAL_ECHOLNPGM(" " STR_J_MIN ": ", m.backlash[JMINIMUM]); #endif #if ENABLED(CALIBRATION_MEASURE_JMAX) SERIAL_ECHOLNPGM(" " STR_J_MAX ": ", m.backlash[JMAXIMUM]); #endif #endif #if AXIS_CAN_CALIBRATE(K) #if ENABLED(CALIBRATION_MEASURE_KMIN) SERIAL_ECHOLNPGM(" " STR_K_MIN ": ", m.backlash[KMINIMUM]); #endif #if ENABLED(CALIBRATION_MEASURE_KMAX) SERIAL_ECHOLNPGM(" " STR_K_MAX ": ", m.backlash[KMAXIMUM]); #endif #endif #if AXIS_CAN_CALIBRATE(U) #if ENABLED(CALIBRATION_MEASURE_UMIN) SERIAL_ECHOLNPGM(" " STR_U_MIN ": ", m.backlash[UMINIMUM]); #endif #if ENABLED(CALIBRATION_MEASURE_UMAX) SERIAL_ECHOLNPGM(" " STR_U_MAX ": ", m.backlash[UMAXIMUM]); #endif #endif #if AXIS_CAN_CALIBRATE(V) #if ENABLED(CALIBRATION_MEASURE_VMIN) SERIAL_ECHOLNPGM(" " STR_V_MIN ": ", m.backlash[VMINIMUM]); #endif #if ENABLED(CALIBRATION_MEASURE_VMAX) SERIAL_ECHOLNPGM(" " STR_V_MAX ": ", m.backlash[VMAXIMUM]); #endif #endif #if AXIS_CAN_CALIBRATE(W) #if ENABLED(CALIBRATION_MEASURE_WMIN) SERIAL_ECHOLNPGM(" " STR_W_MIN ": ", m.backlash[WMINIMUM]); #endif #if ENABLED(CALIBRATION_MEASURE_WMAX) SERIAL_ECHOLNPGM(" " STR_W_MAX ": ", m.backlash[WMAXIMUM]); #endif #endif SERIAL_EOL(); } inline void report_measured_positional_error(const measurements_t &m) { SERIAL_CHAR('T'); SERIAL_ECHO(active_extruder); SERIAL_ECHOLNPGM(" Positional Error:"); #if HAS_X_CENTER && AXIS_CAN_CALIBRATE(X) SERIAL_ECHOLNPGM_P(SP_X_STR, m.pos_error.x); #endif #if HAS_Y_CENTER && AXIS_CAN_CALIBRATE(Y) SERIAL_ECHOLNPGM_P(SP_Y_STR, m.pos_error.y); #endif #if AXIS_CAN_CALIBRATE(Z) SERIAL_ECHOLNPGM_P(SP_Z_STR, m.pos_error.z); #endif #if HAS_I_CENTER && AXIS_CAN_CALIBRATE(I) SERIAL_ECHOLNPGM_P(SP_I_STR, m.pos_error.i); #endif #if HAS_J_CENTER && AXIS_CAN_CALIBRATE(J) SERIAL_ECHOLNPGM_P(SP_J_STR, m.pos_error.j); #endif #if HAS_K_CENTER && AXIS_CAN_CALIBRATE(K) SERIAL_ECHOLNPGM_P(SP_K_STR, m.pos_error.k); #endif #if HAS_U_CENTER && AXIS_CAN_CALIBRATE(U) SERIAL_ECHOLNPGM_P(SP_U_STR, m.pos_error.u); #endif #if HAS_V_CENTER && AXIS_CAN_CALIBRATE(V) SERIAL_ECHOLNPGM_P(SP_V_STR, m.pos_error.v); #endif #if HAS_W_CENTER && AXIS_CAN_CALIBRATE(W) SERIAL_ECHOLNPGM_P(SP_W_STR, m.pos_error.w); #endif SERIAL_EOL(); } inline void report_measured_nozzle_dimensions(const measurements_t &m) { SERIAL_ECHOLNPGM("Nozzle Tip Outer Dimensions:"); #if HAS_X_CENTER SERIAL_ECHOLNPGM_P(SP_X_STR, m.nozzle_outer_dimension.x); #endif #if HAS_Y_CENTER SERIAL_ECHOLNPGM_P(SP_Y_STR, m.nozzle_outer_dimension.y); #endif SERIAL_EOL(); UNUSED(m); } #if HAS_HOTEND_OFFSET // // This function requires normalize_hotend_offsets() to be called // inline void report_hotend_offsets() { for (uint8_t e = 1; e < HOTENDS; ++e) SERIAL_ECHOLNPGM_P(PSTR("T"), e, PSTR(" Hotend Offset X"), hotend_offset[e].x, SP_Y_STR, hotend_offset[e].y, SP_Z_STR, hotend_offset[e].z); } #endif #endif // CALIBRATION_REPORTING /** * Probe around the calibration object to measure backlash * * m in/out - Measurement record, updated with new readings * uncertainty in - How far away from the object to begin probing */ inline void calibrate_backlash(measurements_t &m, const float uncertainty) { // Backlash compensation should be off while measuring backlash { // New scope for TEMPORARY_BACKLASH_CORRECTION TEMPORARY_BACKLASH_CORRECTION(backlash.all_off); TEMPORARY_BACKLASH_SMOOTHING(0.0f); probe_sides(m, uncertainty); #if ENABLED(BACKLASH_GCODE) #if HAS_X_CENTER backlash.set_distance_mm(X_AXIS, (m.backlash[LEFT] + m.backlash[RIGHT]) / 2); #elif ENABLED(CALIBRATION_MEASURE_LEFT) backlash.set_distance_mm(X_AXIS, m.backlash[LEFT]); #elif ENABLED(CALIBRATION_MEASURE_RIGHT) backlash.set_distance_mm(X_AXIS, m.backlash[RIGHT]); #endif #if HAS_Y_CENTER backlash.set_distance_mm(Y_AXIS, (m.backlash[FRONT] + m.backlash[BACK]) / 2); #elif ENABLED(CALIBRATION_MEASURE_FRONT) backlash.set_distance_mm(Y_AXIS, m.backlash[FRONT]); #elif ENABLED(CALIBRATION_MEASURE_BACK) backlash.set_distance_mm(Y_AXIS, m.backlash[BACK]); #endif TERN_(HAS_Z_AXIS, if (AXIS_CAN_CALIBRATE(Z)) backlash.set_distance_mm(Z_AXIS, m.backlash[TOP])); #if HAS_I_CENTER backlash.set_distance_mm(I_AXIS, (m.backlash[IMINIMUM] + m.backlash[IMAXIMUM]) / 2); #elif ENABLED(CALIBRATION_MEASURE_IMIN) backlash.set_distance_mm(I_AXIS, m.backlash[IMINIMUM]); #elif ENABLED(CALIBRATION_MEASURE_IMAX) backlash.set_distance_mm(I_AXIS, m.backlash[IMAXIMUM]); #endif #if HAS_J_CENTER backlash.set_distance_mm(J_AXIS, (m.backlash[JMINIMUM] + m.backlash[JMAXIMUM]) / 2); #elif ENABLED(CALIBRATION_MEASURE_JMIN) backlash.set_distance_mm(J_AXIS, m.backlash[JMINIMUM]); #elif ENABLED(CALIBRATION_MEASURE_JMAX) backlash.set_distance_mm(J_AXIS, m.backlash[JMAXIMUM]); #endif #if HAS_K_CENTER backlash.set_distance_mm(K_AXIS, (m.backlash[KMINIMUM] + m.backlash[KMAXIMUM]) / 2); #elif ENABLED(CALIBRATION_MEASURE_KMIN) backlash.set_distance_mm(K_AXIS, m.backlash[KMINIMUM]); #elif ENABLED(CALIBRATION_MEASURE_KMAX) backlash.set_distance_mm(K_AXIS, m.backlash[KMAXIMUM]); #endif #if HAS_U_CENTER backlash.distance_mm.u = (m.backlash[UMINIMUM] + m.backlash[UMAXIMUM]) / 2; #elif ENABLED(CALIBRATION_MEASURE_UMIN) backlash.distance_mm.u = m.backlash[UMINIMUM]; #elif ENABLED(CALIBRATION_MEASURE_UMAX) backlash.distance_mm.u = m.backlash[UMAXIMUM]; #endif #if HAS_V_CENTER backlash.distance_mm.v = (m.backlash[VMINIMUM] + m.backlash[VMAXIMUM]) / 2; #elif ENABLED(CALIBRATION_MEASURE_VMIN) backlash.distance_mm.v = m.backlash[VMINIMUM]; #elif ENABLED(CALIBRATION_MEASURE_UMAX) backlash.distance_mm.v = m.backlash[VMAXIMUM]; #endif #if HAS_W_CENTER backlash.distance_mm.w = (m.backlash[WMINIMUM] + m.backlash[WMAXIMUM]) / 2; #elif ENABLED(CALIBRATION_MEASURE_WMIN) backlash.distance_mm.w = m.backlash[WMINIMUM]; #elif ENABLED(CALIBRATION_MEASURE_WMAX) backlash.distance_mm.w = m.backlash[WMAXIMUM]; #endif #endif // BACKLASH_GCODE } #if ENABLED(BACKLASH_GCODE) // Turn on backlash compensation and move in all // allowed directions to take up any backlash { // New scope for TEMPORARY_BACKLASH_CORRECTION TEMPORARY_BACKLASH_CORRECTION(backlash.all_on); TEMPORARY_BACKLASH_SMOOTHING(0.0f); const xyz_float_t move = NUM_AXIS_ARRAY( AXIS_CAN_CALIBRATE(X) * 3, AXIS_CAN_CALIBRATE(Y) * 3, AXIS_CAN_CALIBRATE(Z) * 3, AXIS_CAN_CALIBRATE(I) * 3, AXIS_CAN_CALIBRATE(J) * 3, AXIS_CAN_CALIBRATE(K) * 3, AXIS_CAN_CALIBRATE(U) * 3, AXIS_CAN_CALIBRATE(V) * 3, AXIS_CAN_CALIBRATE(W) * 3 ); current_position += move; calibration_move(); current_position -= move; calibration_move(); } #endif } inline void update_measurements(measurements_t &m, const AxisEnum axis) { current_position[axis] += m.pos_error[axis]; m.obj_center[axis] = true_center[axis]; m.pos_error[axis] = 0; } /** * Probe around the calibration object. Adjust the position and toolhead offset * using the deviation from the known position of the calibration object. * * m in/out - Measurement record, updated with new readings * uncertainty in - How far away from the object to begin probing * extruder in - What extruder to probe * * Prerequisites: * - Call calibrate_backlash() beforehand for best accuracy */ inline void calibrate_toolhead(measurements_t &m, const float uncertainty, const uint8_t extruder) { TEMPORARY_BACKLASH_CORRECTION(backlash.all_on); TEMPORARY_BACKLASH_SMOOTHING(0.0f); TERN(HAS_MULTI_HOTEND, set_nozzle(m, extruder), UNUSED(extruder)); probe_sides(m, uncertainty); // Adjust the hotend offset #if HAS_HOTEND_OFFSET if (ENABLED(HAS_X_CENTER) && AXIS_CAN_CALIBRATE(X)) hotend_offset[extruder].x += m.pos_error.x; if (ENABLED(HAS_Y_CENTER) && AXIS_CAN_CALIBRATE(Y)) hotend_offset[extruder].y += m.pos_error.y; if (AXIS_CAN_CALIBRATE(Z)) hotend_offset[extruder].z += m.pos_error.z; normalize_hotend_offsets(); #endif // Correct for positional error, so the object // is at the known actual spot planner.synchronize(); if (ENABLED(HAS_X_CENTER) && AXIS_CAN_CALIBRATE(X)) update_measurements(m, X_AXIS); if (ENABLED(HAS_Y_CENTER) && AXIS_CAN_CALIBRATE(Y)) update_measurements(m, Y_AXIS); if (AXIS_CAN_CALIBRATE(Z)) update_measurements(m, Z_AXIS); TERN_(HAS_I_CENTER, update_measurements(m, I_AXIS)); TERN_(HAS_J_CENTER, update_measurements(m, J_AXIS)); TERN_(HAS_K_CENTER, update_measurements(m, K_AXIS)); TERN_(HAS_U_CENTER, update_measurements(m, U_AXIS)); TERN_(HAS_V_CENTER, update_measurements(m, V_AXIS)); TERN_(HAS_W_CENTER, update_measurements(m, W_AXIS)); sync_plan_position(); } /** * Probe around the calibration object for all toolheads, adjusting the coordinate * system for the first nozzle and the nozzle offset for subsequent nozzles. * * m in/out - Measurement record, updated with new readings * uncertainty in - How far away from the object to begin probing */ inline void calibrate_all_toolheads(measurements_t &m, const float uncertainty) { TEMPORARY_BACKLASH_CORRECTION(backlash.all_on); TEMPORARY_BACKLASH_SMOOTHING(0.0f); HOTEND_LOOP() calibrate_toolhead(m, uncertainty, e); TERN_(HAS_HOTEND_OFFSET, normalize_hotend_offsets()); TERN_(HAS_MULTI_HOTEND, set_nozzle(m, 0)); } /** * Perform a full auto-calibration routine: * * 1) For each nozzle, touch top and sides of object to determine object position and * nozzle offsets. Do a fast but rough search over a wider area. * 2) With the first nozzle, touch top and sides of object to determine backlash values * for all axes (if BACKLASH_GCODE is enabled) * 3) For each nozzle, touch top and sides of object slowly to determine precise * position of object. Adjust coordinate system and nozzle offsets so probed object * location corresponds to known object location with a high degree of precision. */ inline void calibrate_all() { measurements_t m; TERN_(HAS_HOTEND_OFFSET, reset_hotend_offsets()); TEMPORARY_BACKLASH_CORRECTION(backlash.all_on); TEMPORARY_BACKLASH_SMOOTHING(0.0f); // Do a fast and rough calibration of the toolheads calibrate_all_toolheads(m, CALIBRATION_MEASUREMENT_UNKNOWN); TERN_(BACKLASH_GCODE, calibrate_backlash(m, CALIBRATION_MEASUREMENT_UNCERTAIN)); // Cycle the toolheads so the servos settle into their "natural" positions #if HAS_MULTI_HOTEND HOTEND_LOOP() set_nozzle(m, e); #endif // Do a slow and precise calibration of the toolheads calibrate_all_toolheads(m, CALIBRATION_MEASUREMENT_UNCERTAIN); current_position.x = X_CENTER; calibration_move(); // Park nozzle away from calibration object } /** * G425: Perform calibration with calibration object. * * B - Perform calibration of backlash only. * T<extruder> - Perform calibration of toolhead only. * V - Probe object and print position, error, backlash and hotend offset. * U - Uncertainty, how far to start probe away from the object (mm) * * no args - Perform entire calibration sequence (backlash + position on all toolheads) */ void GcodeSuite::G425() { #ifdef CALIBRATION_SCRIPT_PRE process_subcommands_now(F(CALIBRATION_SCRIPT_PRE)); #endif if (homing_needed_error()) return; TEMPORARY_BED_LEVELING_STATE(false); SET_SOFT_ENDSTOP_LOOSE(true); measurements_t m; const float uncertainty = parser.floatval('U', CALIBRATION_MEASUREMENT_UNCERTAIN); if (parser.seen_test('B')) calibrate_backlash(m, uncertainty); else if (parser.seen_test('T')) calibrate_toolhead(m, uncertainty, parser.intval('T', active_extruder)); #if ENABLED(CALIBRATION_REPORTING) else if (parser.seen('V')) { probe_sides(m, uncertainty); SERIAL_EOL(); report_measured_faces(m); report_measured_center(m); report_measured_backlash(m); report_measured_nozzle_dimensions(m); report_measured_positional_error(m); #if HAS_HOTEND_OFFSET normalize_hotend_offsets(); report_hotend_offsets(); #endif } #endif else calibrate_all(); SET_SOFT_ENDSTOP_LOOSE(false); #ifdef CALIBRATION_SCRIPT_POST process_subcommands_now(F(CALIBRATION_SCRIPT_POST)); #endif } #endif // CALIBRATION_GCODE
2301_81045437/Marlin
Marlin/src/gcode/calibrate/G425.cpp
C++
agpl-3.0
32,877
/** * Marlin 3D Printer Firmware * Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin] * * Based on Sprinter and grbl. * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <https://www.gnu.org/licenses/>. * */ /** * G76_M871.cpp - Temperature calibration/compensation for z-probing */ #include "../../inc/MarlinConfig.h" #if HAS_PTC #include "../gcode.h" #include "../../module/motion.h" #include "../../module/planner.h" #include "../../module/probe.h" #include "../../feature/bedlevel/bedlevel.h" #include "../../module/temperature.h" #include "../../feature/probe_temp_comp.h" #include "../../lcd/marlinui.h" /** * G76: calibrate probe and/or bed temperature offsets * Notes: * - When calibrating probe, bed temperature is held constant. * Compensation values are deltas to first probe measurement at probe temp. = 30°C. * - When calibrating bed, probe temperature is held constant. * Compensation values are deltas to first probe measurement at bed temp. = 60°C. * - The hotend will not be heated at any time. * - On my Průša MK3S clone I put a piece of paper between the probe and the hotend * so the hotend fan would not cool my probe constantly. Alternatively you could just * make sure the fan is not running while running the calibration process. * * Probe calibration: * - Moves probe to cooldown point. * - Heats up bed to 100°C. * - Moves probe to probing point (1mm above heatbed). * - Waits until probe reaches target temperature (30°C). * - Does a z-probing (=base value) and increases target temperature by 5°C. * - Waits until probe reaches increased target temperature. * - Does a z-probing (delta to base value will be a compensation value) and increases target temperature by 5°C. * - Repeats last two steps until max. temperature reached or timeout (i.e. probe does not heat up any further). * - Compensation values of higher temperatures will be extrapolated (using linear regression first). * While this is not exact by any means it is still better than simply using the last compensation value. * * Bed calibration: * - Moves probe to cooldown point. * - Heats up bed to 60°C. * - Moves probe to probing point (1mm above heatbed). * - Waits until probe reaches target temperature (30°C). * - Does a z-probing (=base value) and increases bed temperature by 5°C. * - Moves probe to cooldown point. * - Waits until probe is below 30°C and bed has reached target temperature. * - Moves probe to probing point and waits until it reaches target temperature (30°C). * - Does a z-probing (delta to base value will be a compensation value) and increases bed temperature by 5°C. * - Repeats last four points until max. bed temperature reached (110°C) or timeout. * - Compensation values of higher temperatures will be extrapolated (using linear regression first). * While this is not exact by any means it is still better than simply using the last compensation value. * * G76 [B | P] * - no flag - Both calibration procedures will be run. * - `B` - Run bed temperature calibration. * - `P` - Run probe temperature calibration. */ #if ALL(PTC_PROBE, PTC_BED) static void say_waiting_for() { SERIAL_ECHOPGM("Waiting for "); } static void say_waiting_for_probe_heating() { say_waiting_for(); SERIAL_ECHOLNPGM("probe heating."); } static void say_successfully_calibrated() { SERIAL_ECHOPGM("Successfully calibrated"); } static void say_failed_to_calibrate() { SERIAL_ECHOPGM("!Failed to calibrate"); } void GcodeSuite::G76() { auto report_temps = [](millis_t &ntr, millis_t timeout=0) { idle_no_sleep(); const millis_t ms = millis(); if (ELAPSED(ms, ntr)) { ntr = ms + 1000; thermalManager.print_heater_states(active_extruder); } return (timeout && ELAPSED(ms, timeout)); }; auto wait_for_temps = [&](const celsius_t tb, const celsius_t tp, millis_t &ntr, const millis_t timeout=0) { say_waiting_for(); SERIAL_ECHOLNPGM("bed and probe temperature."); while (thermalManager.wholeDegBed() != tb || thermalManager.wholeDegProbe() > tp) if (report_temps(ntr, timeout)) return true; return false; }; auto g76_probe = [](const TempSensorID sid, celsius_t &targ, const xy_pos_t &nozpos) { ptc.set_enabled(false); const float measured_z = probe.probe_at_point(nozpos, PROBE_PT_STOW, 0, false); // verbose=0, probe_relative=false ptc.set_enabled(true); if (isnan(measured_z)) SERIAL_ECHOLNPGM("!Received NAN. Aborting."); else { SERIAL_ECHOLNPGM("Measured: ", p_float_t(measured_z, 2)); if (targ == ProbeTempComp::cali_info[sid].start_temp) ptc.prepare_new_calibration(measured_z); else ptc.push_back_new_measurement(sid, measured_z); targ += ProbeTempComp::cali_info[sid].temp_resolution; } return measured_z; }; #if ENABLED(BLTOUCH) // Make sure any BLTouch error condition is cleared bltouch_command(BLTOUCH_RESET, BLTOUCH_RESET_DELAY); set_bltouch_deployed(false); #endif bool do_bed_cal = parser.boolval('B'), do_probe_cal = parser.boolval('P'); if (!do_bed_cal && !do_probe_cal) do_bed_cal = do_probe_cal = true; // Synchronize with planner planner.synchronize(); #ifndef PTC_PROBE_HEATING_OFFSET #define PTC_PROBE_HEATING_OFFSET 0 #endif const xyz_pos_t parkpos = PTC_PARK_POS, probe_pos_xyz = xyz_pos_t(PTC_PROBE_POS) + xyz_pos_t({ 0.0f, 0.0f, PTC_PROBE_HEATING_OFFSET }), noz_pos_xyz = probe_pos_xyz - probe.offset_xy; // Nozzle position based on probe position if (do_bed_cal || do_probe_cal) { // Ensure park position is reachable bool reachable = position_is_reachable(parkpos) || WITHIN(parkpos.z, Z_MIN_POS - fslop, Z_MAX_POS + fslop); if (!reachable) SERIAL_ECHOLNPGM("!Park"); else { // Ensure probe position is reachable reachable = probe.can_reach(probe_pos_xyz); if (!reachable) SERIAL_ECHOLNPGM("!Probe"); } if (!reachable) { SERIAL_ECHOLNPGM(" position unreachable - aborting."); return; } process_subcommands_now(FPSTR(G28_STR)); } remember_feedrate_scaling_off(); /****************************************** * Calibrate bed temperature offsets ******************************************/ // Report temperatures every second and handle heating timeouts millis_t next_temp_report = millis() + 1000; auto report_targets = [&](const celsius_t tb, const celsius_t tp) { SERIAL_ECHOLNPGM("Target Bed:", tb, " Probe:", tp); }; if (do_bed_cal) { celsius_t target_bed = PTC_BED_START, target_probe = PTC_PROBE_TEMP; say_waiting_for(); SERIAL_ECHOLNPGM(" cooling."); while (thermalManager.wholeDegBed() > target_bed || thermalManager.wholeDegProbe() > target_probe) report_temps(next_temp_report); // Disable leveling so it won't mess with us TERN_(HAS_LEVELING, set_bed_leveling_enabled(false)); for (uint8_t idx = 0; idx <= PTC_BED_COUNT; idx++) { thermalManager.setTargetBed(target_bed); report_targets(target_bed, target_probe); // Park nozzle do_blocking_move_to(parkpos); // Wait for heatbed to reach target temp and probe to cool below target temp if (wait_for_temps(target_bed, target_probe, next_temp_report, millis() + MIN_TO_MS(15))) { SERIAL_ECHOLNPGM("!Bed heating timeout."); break; } // Move the nozzle to the probing point and wait for the probe to reach target temp do_blocking_move_to(noz_pos_xyz); say_waiting_for_probe_heating(); SERIAL_EOL(); while (thermalManager.wholeDegProbe() < target_probe) report_temps(next_temp_report); const float measured_z = g76_probe(TSI_BED, target_bed, noz_pos_xyz); if (isnan(measured_z) || target_bed > (BED_MAX_TARGET)) break; } SERIAL_ECHOLNPGM("Retrieved measurements: ", ptc.get_index()); if (ptc.finish_calibration(TSI_BED)) { say_successfully_calibrated(); SERIAL_ECHOLNPGM(" bed."); } else { say_failed_to_calibrate(); SERIAL_ECHOLNPGM(" bed. Values reset."); } // Cleanup thermalManager.setTargetBed(0); TERN_(HAS_LEVELING, set_bed_leveling_enabled(true)); } // do_bed_cal /******************************************** * Calibrate probe temperature offsets ********************************************/ if (do_probe_cal) { // Park nozzle do_blocking_move_to(parkpos); // Initialize temperatures const celsius_t target_bed = BED_MAX_TARGET; thermalManager.setTargetBed(target_bed); celsius_t target_probe = PTC_PROBE_START; report_targets(target_bed, target_probe); // Wait for heatbed to reach target temp and probe to cool below target temp wait_for_temps(target_bed, target_probe, next_temp_report); // Disable leveling so it won't mess with us TERN_(HAS_LEVELING, set_bed_leveling_enabled(false)); bool timeout = false; for (uint8_t idx = 0; idx <= PTC_PROBE_COUNT; idx++) { // Move probe to probing point and wait for it to reach target temperature do_blocking_move_to(noz_pos_xyz); say_waiting_for_probe_heating(); SERIAL_ECHOLNPGM(" Bed:", target_bed, " Probe:", target_probe); const millis_t probe_timeout_ms = millis() + MIN_TO_MS(15); while (thermalManager.degProbe() < target_probe) { if (report_temps(next_temp_report, probe_timeout_ms)) { SERIAL_ECHOLNPGM("!Probe heating timed out."); timeout = true; break; } } if (timeout) break; const float measured_z = g76_probe(TSI_PROBE, target_probe, noz_pos_xyz); if (isnan(measured_z)) break; } SERIAL_ECHOLNPGM("Retrieved measurements: ", ptc.get_index()); if (ptc.finish_calibration(TSI_PROBE)) say_successfully_calibrated(); else say_failed_to_calibrate(); SERIAL_ECHOLNPGM(" probe."); // Cleanup thermalManager.setTargetBed(0); TERN_(HAS_LEVELING, set_bed_leveling_enabled(true)); SERIAL_ECHOLNPGM("Final compensation values:"); ptc.print_offsets(); } // do_probe_cal restore_feedrate_and_scaling(); } #endif // PTC_PROBE && PTC_BED /** * M871: Report / reset temperature compensation offsets. * Note: This does not affect values in EEPROM until M500. * * M871 [ R | B | P | E ] * * No Parameters - Print current offset values. * * Select only one of these flags: * R - Reset all offsets to zero (i.e., disable compensation). * B - Manually set offset for bed * P - Manually set offset for probe * E - Manually set offset for extruder * * With B, P, or E: * I[index] - Index in the array * V[value] - Adjustment in µm */ void GcodeSuite::M871() { if (parser.seen('R')) { // Reset z-probe offsets to factory defaults ptc.clear_all_offsets(); SERIAL_ECHOLNPGM("Offsets reset to default."); } else if (parser.seen("BPE")) { if (!parser.seenval('V')) return; const int16_t offset_val = parser.value_int(); if (!parser.seenval('I')) return; const int16_t idx = parser.value_int(); const TempSensorID mod = TERN_(PTC_BED, parser.seen_test('B') ? TSI_BED :) TERN_(PTC_HOTEND, parser.seen_test('E') ? TSI_EXT :) TERN_(PTC_PROBE, parser.seen_test('P') ? TSI_PROBE :) TSI_COUNT; if (mod == TSI_COUNT) SERIAL_ECHOLNPGM("!Invalid sensor."); else if (idx > 0 && ptc.set_offset(mod, idx - 1, offset_val)) SERIAL_ECHOLNPGM("Set value: ", offset_val); else SERIAL_ECHOLNPGM("!Invalid index. Failed to set value (note: value at index 0 is constant)."); } else // Print current Z-probe adjustments. Note: Values in EEPROM might differ. ptc.print_offsets(); } #endif // HAS_PTC
2301_81045437/Marlin
Marlin/src/gcode/calibrate/G76_M871.cpp
C++
agpl-3.0
12,878
/** * Marlin 3D Printer Firmware * Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin] * * Based on Sprinter and grbl. * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <https://www.gnu.org/licenses/>. * */ #include "../../inc/MarlinConfig.h" #if ENABLED(M100_FREE_MEMORY_WATCHER) #include "../gcode.h" #include "../queue.h" #include "../../libs/hex_print.h" #include "../../MarlinCore.h" // for idle() /** * M100 Free Memory Watcher * * This code watches the free memory block between the bottom of the heap and the top of the stack. * This memory block is initialized and watched via the M100 command. * * M100 I Initializes the free memory block and prints vitals statistics about the area * * M100 F Identifies how much of the free memory block remains free and unused. It also * detects and reports any corruption within the free memory block that may have * happened due to errant firmware. * * M100 D Does a hex display of the free memory block along with a flag for any errant * data that does not match the expected value. * * M100 C x Corrupts x locations within the free memory block. This is useful to check the * correctness of the M100 F and M100 D commands. * * Also, there are two support functions that can be called from a developer's C code. * * uint16_t check_for_free_memory_corruption(PGM_P const free_memory_start); * void M100_dump_routine(FSTR_P const title, const char * const start, const uintptr_t size); * * Initial version by Roxy-3D */ #define M100_FREE_MEMORY_DUMPER // Enable for the `M100 D` Dump sub-command #define M100_FREE_MEMORY_CORRUPTOR // Enable for the `M100 C` Corrupt sub-command #define TEST_BYTE ((char) 0xE5) #if ANY(__AVR__, IS_32BIT_TEENSY) extern char __bss_end; char *end_bss = &__bss_end, *free_memory_start = end_bss, *free_memory_end = 0, *stacklimit = 0, *heaplimit = 0; #define MEMORY_END_CORRECTION 0 #elif defined(TARGET_LPC1768) extern char __bss_end__, __StackLimit, __HeapLimit; char *end_bss = &__bss_end__, *stacklimit = &__StackLimit, *heaplimit = &__HeapLimit; #define MEMORY_END_CORRECTION 0x200 char *free_memory_start = heaplimit, *free_memory_end = stacklimit - MEMORY_END_CORRECTION; #elif defined(__SAM3X8E__) extern char _ebss; char *end_bss = &_ebss, *free_memory_start = end_bss, *free_memory_end = 0, *stacklimit = 0, *heaplimit = 0; #define MEMORY_END_CORRECTION 0x10000 // need to stay well below 0x20080000 or M100 F crashes #elif defined(__SAMD51__) extern unsigned int __bss_end__, __StackLimit, __HeapLimit; extern "C" void * _sbrk(int incr); void *end_bss = &__bss_end__, *stacklimit = &__StackLimit, *heaplimit = &__HeapLimit; #define MEMORY_END_CORRECTION 0x400 char *free_memory_start = (char *)_sbrk(0) + 0x200, // Leave some heap space *free_memory_end = (char *)stacklimit - MEMORY_END_CORRECTION; #else #error "M100 - unsupported CPU" #endif // // Utility functions // #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wreturn-local-addr" // Location of a variable in its stack frame. // The returned address will be above the stack (after it returns). char *top_of_stack() { char x; return &x + 1; // x is pulled on return; } #pragma GCC diagnostic pop // Count the number of test bytes at the specified location. inline int32_t count_test_bytes(const char * const start_free_memory) { for (uint32_t i = 0; i < 32000; i++) if (char(start_free_memory[i]) != TEST_BYTE) return i - 1; return -1; } // // M100 sub-commands // #if ENABLED(M100_FREE_MEMORY_DUMPER) /** * M100 D * Dump the free memory block from brkval to the stack pointer. * malloc() eats memory from the start of the block and the stack grows * up from the bottom of the block. Solid test bytes indicate nothing has * used that memory yet. There should not be anything but test bytes within * the block. If so, it may indicate memory corruption due to a bad pointer. * Unexpected bytes are flagged in the right column. */ void dump_free_memory(char *start_free_memory, char *end_free_memory) { // // Start and end the dump on a nice 16 byte boundary // (even though the values are not 16-byte aligned). // start_free_memory = (char*)(uintptr_t(uint32_t(start_free_memory) & ~0xFUL)); // Align to 16-byte boundary end_free_memory = (char*)(uintptr_t(uint32_t(end_free_memory) | 0xFUL)); // Align end_free_memory to the 15th byte (at or above end_free_memory) // Dump command main loop while (start_free_memory < end_free_memory) { print_hex_address(start_free_memory); // Print the address SERIAL_CHAR(':'); for (uint8_t i = 0; i < 16; ++i) { // and 16 data bytes if (i == 8) SERIAL_CHAR('-'); print_hex_byte(start_free_memory[i]); SERIAL_CHAR(' '); } serial_delay(25); SERIAL_CHAR('|'); // Point out non test bytes for (uint8_t i = 0; i < 16; ++i) { char ccc = (char)start_free_memory[i]; // cast to char before automatically casting to char on assignment, in case the compiler is broken ccc = (ccc == TEST_BYTE) ? ' ' : '?'; SERIAL_CHAR(ccc); } SERIAL_EOL(); start_free_memory += 16; serial_delay(25); idle(); } } void M100_dump_routine(FSTR_P const title, const char * const start, const uintptr_t size) { SERIAL_ECHOLN(title); // // Round the start and end locations to produce full lines of output // const char * const end = start + size - 1; dump_free_memory( (char*)(uintptr_t(uint32_t(start) & ~0xFUL)), // Align to 16-byte boundary (char*)(uintptr_t(uint32_t(end) | 0xFUL)) // Align end_free_memory to the 15th byte (at or above end_free_memory) ); } #endif // M100_FREE_MEMORY_DUMPER inline int check_for_free_memory_corruption(FSTR_P const title) { SERIAL_ECHO(title); char *start_free_memory = free_memory_start, *end_free_memory = free_memory_end; int n = end_free_memory - start_free_memory; SERIAL_ECHOLNPGM("\nfmc() n=", n, "\nfree_memory_start=", hex_address(free_memory_start), " end=", hex_address(end_free_memory)); if (end_free_memory < start_free_memory) { SERIAL_ECHOPGM(" end_free_memory < Heap "); //SET_INPUT_PULLUP(63); // if the developer has a switch wired up to their controller board //safe_delay(5); // this code can be enabled to pause the display as soon as the //while ( READ(63)) // malfunction is detected. It is currently defaulting to a switch // idle(); // being on pin-63 which is unassigend and available on most controller //safe_delay(20); // boards. //while ( !READ(63)) // idle(); serial_delay(20); #if ENABLED(M100_FREE_MEMORY_DUMPER) M100_dump_routine(F(" Memory corruption detected with end_free_memory<Heap\n"), (const char*)0x1B80, 0x0680); #endif } // Scan through the range looking for the biggest block of 0xE5's we can find int block_cnt = 0; for (int i = 0; i < n; i++) { if (start_free_memory[i] == TEST_BYTE) { int32_t j = count_test_bytes(start_free_memory + i); if (j > 8) { //SERIAL_ECHOPGM("Found ", j); //SERIAL_ECHOLNPGM(" bytes free at ", hex_address(start_free_memory + i)); i += j; block_cnt++; SERIAL_ECHOLNPGM(" (", block_cnt, ") found=", j); } } } SERIAL_ECHOPGM(" block_found=", block_cnt); if (block_cnt != 1) SERIAL_ECHOLNPGM("\nMemory Corruption detected in free memory area."); if (block_cnt == 0) // Make sure the special case of no free blocks shows up as an block_cnt = -1; // error to the calling code! SERIAL_ECHOPGM(" return="); if (block_cnt == 1) { SERIAL_CHAR('0'); // If the block_cnt is 1, nothing has broken up the free memory SERIAL_EOL(); // area and it is appropriate to say 'no corruption'. return 0; } SERIAL_ECHOLNPGM("true"); return block_cnt; } /** * M100 F * Return the number of free bytes in the memory pool, * with other vital statistics defining the pool. */ inline void free_memory_pool_report(char * const start_free_memory, const int32_t size) { int32_t max_cnt = -1, block_cnt = 0; char *max_addr = nullptr; // Find the longest block of test bytes in the buffer for (int32_t i = 0; i < size; i++) { char *addr = start_free_memory + i; if (*addr == TEST_BYTE) { const int32_t j = count_test_bytes(addr); if (j > 8) { SERIAL_ECHOLNPGM("Found ", j, " bytes free at ", hex_address(addr)); if (j > max_cnt) { max_cnt = j; max_addr = addr; } i += j; block_cnt++; } } } if (block_cnt > 1) SERIAL_ECHOLNPGM( "\nMemory Corruption detected in free memory area." "\nLargest free block is ", max_cnt, " bytes at ", hex_address(max_addr) ); SERIAL_ECHOLNPGM("check_for_free_memory_corruption() = ", check_for_free_memory_corruption(F("M100 F "))); } #if ENABLED(M100_FREE_MEMORY_CORRUPTOR) /** * M100 C<num> * Corrupt <num> locations in the free memory pool and report the corrupt addresses. * This is useful to check the correctness of the M100 D and the M100 F commands. */ inline void corrupt_free_memory(char *start_free_memory, const uintptr_t size) { start_free_memory += 8; const uint32_t near_top = top_of_stack() - start_free_memory - 250, // -250 to avoid interrupt activity that's altered the stack. j = near_top / (size + 1); SERIAL_ECHOLNPGM("Corrupting free memory block."); for (uint32_t i = 1; i <= size; i++) { char * const addr = start_free_memory + i * j; *addr = i; SERIAL_ECHOPGM("\nCorrupting address: ", hex_address(addr)); } SERIAL_EOL(); } #endif // M100_FREE_MEMORY_CORRUPTOR /** * M100 I * Init memory for the M100 tests. (Automatically applied on the first M100.) */ inline void init_free_memory(char *start_free_memory, int32_t size) { SERIAL_ECHOLNPGM("Initializing free memory block.\n\n"); size -= 250; // -250 to avoid interrupt activity that's altered the stack. if (size < 0) { SERIAL_ECHOLNPGM("Unable to initialize.\n"); return; } start_free_memory += 8; // move a few bytes away from the heap just because we // don't want to be altering memory that close to it. memset(start_free_memory, TEST_BYTE, size); SERIAL_ECHO(size); SERIAL_ECHOLNPGM(" bytes of memory initialized.\n"); for (int32_t i = 0; i < size; i++) { if (start_free_memory[i] != TEST_BYTE) { SERIAL_ECHOPGM("? address : ", hex_address(start_free_memory + i)); SERIAL_ECHOLNPGM("=", hex_byte(start_free_memory[i])); SERIAL_EOL(); } } } /** * M100: Free Memory Check */ void GcodeSuite::M100() { char *sp = top_of_stack(); if (!free_memory_end) free_memory_end = sp - MEMORY_END_CORRECTION; SERIAL_ECHOPGM("\nbss_end : ", hex_address(end_bss)); if (heaplimit) SERIAL_ECHOPGM("\n__heaplimit : ", hex_address(heaplimit)); SERIAL_ECHOPGM("\nfree_memory_start : ", hex_address(free_memory_start)); if (stacklimit) SERIAL_ECHOPGM("\n__stacklimit : ", hex_address(stacklimit)); SERIAL_ECHOPGM("\nfree_memory_end : ", hex_address(free_memory_end)); if (MEMORY_END_CORRECTION) SERIAL_ECHOPGM("\nMEMORY_END_CORRECTION : ", MEMORY_END_CORRECTION); SERIAL_ECHOLNPGM("\nStack Pointer : ", hex_address(sp)); // Always init on the first invocation of M100 static bool m100_not_initialized = true; if (m100_not_initialized || parser.seen('I')) { m100_not_initialized = false; init_free_memory(free_memory_start, free_memory_end - free_memory_start); } #if ENABLED(M100_FREE_MEMORY_DUMPER) if (parser.seen('D')) return dump_free_memory(free_memory_start, free_memory_end); #endif if (parser.seen('F')) return free_memory_pool_report(free_memory_start, free_memory_end - free_memory_start); #if ENABLED(M100_FREE_MEMORY_CORRUPTOR) if (parser.seen('C')) return corrupt_free_memory(free_memory_start, parser.value_int()); #endif } #endif // M100_FREE_MEMORY_WATCHER
2301_81045437/Marlin
Marlin/src/gcode/calibrate/M100.cpp
C++
agpl-3.0
13,232
/** * Marlin 3D Printer Firmware * Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin] * * Based on Sprinter and grbl. * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <https://www.gnu.org/licenses/>. * */ #include "../../inc/MarlinConfigPre.h" #if ENABLED(EXTERNAL_CLOSED_LOOP_CONTROLLER) #include "../gcode.h" #include "../../module/planner.h" #include "../../feature/closedloop.h" void GcodeSuite::M12() { planner.synchronize(); if (parser.seenval('S')) closedloop.set(parser.value_int()); // Force a CLC set } #endif
2301_81045437/Marlin
Marlin/src/gcode/calibrate/M12.cpp
C++
agpl-3.0
1,193
/** * Marlin 3D Printer Firmware * Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin] * * Based on Sprinter and grbl. * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <https://www.gnu.org/licenses/>. * */ #include "../../inc/MarlinConfig.h" #if ENABLED(BACKLASH_GCODE) #include "../../feature/backlash.h" #include "../../module/planner.h" #include "../gcode.h" /** * M425: Enable and tune backlash correction. * * F<fraction> Enable/disable/fade-out backlash correction (0.0 to 1.0) * S<smoothing_mm> Distance over which backlash correction is spread * X<distance_mm> Set the backlash distance on X (0 to disable) * Y<distance_mm> ... on Y * Z<distance_mm> ... on Z * X If a backlash measurement was done on X, copy that value * Y ... on Y * Z ... on Z * * Type M425 without any arguments to show active values. */ void GcodeSuite::M425() { bool noArgs = true; auto axis_can_calibrate = [](const uint8_t a) -> bool { #define _CAN_CASE(N) case N##_AXIS: return bool(AXIS_CAN_CALIBRATE(N)); switch (a) { MAIN_AXIS_MAP(_CAN_CASE) default: break; } return false; }; LOOP_NUM_AXES(a) { if (axis_can_calibrate(a) && parser.seen(AXIS_CHAR(a))) { planner.synchronize(); backlash.set_distance_mm((AxisEnum)a, parser.has_value() ? parser.value_axis_units((AxisEnum)a) : backlash.get_measurement((AxisEnum)a)); noArgs = false; } } if (parser.seen('F')) { planner.synchronize(); backlash.set_correction(parser.value_float()); noArgs = false; } #ifdef BACKLASH_SMOOTHING_MM if (parser.seen('S')) { planner.synchronize(); backlash.set_smoothing_mm(parser.value_linear_units()); noArgs = false; } #endif if (noArgs) { SERIAL_ECHOPGM("Backlash Correction "); if (!backlash.get_correction_uint8()) SERIAL_ECHOPGM("in"); SERIAL_ECHOLNPGM("active:"); SERIAL_ECHOLNPGM(" Correction Amount/Fade-out: F", backlash.get_correction(), " (F1.0 = full, F0.0 = none)"); SERIAL_ECHOPGM(" Backlash Distance (mm): "); LOOP_NUM_AXES(a) if (axis_can_calibrate(a)) { SERIAL_ECHOLNPGM_P((PGM_P)pgm_read_ptr(&SP_AXIS_STR[a]), backlash.get_distance_mm((AxisEnum)a)); } #ifdef BACKLASH_SMOOTHING_MM SERIAL_ECHOLNPGM(" Smoothing (mm): S", backlash.get_smoothing_mm()); #endif #if ENABLED(MEASURE_BACKLASH_WHEN_PROBING) SERIAL_ECHOPGM(" Average measured backlash (mm):"); if (backlash.has_any_measurement()) { LOOP_NUM_AXES(a) if (axis_can_calibrate(a) && backlash.has_measurement(AxisEnum(a))) { SERIAL_ECHOPGM_P((PGM_P)pgm_read_ptr(&SP_AXIS_STR[a]), backlash.get_measurement((AxisEnum)a)); } } else SERIAL_ECHOPGM(" (Not yet measured)"); SERIAL_EOL(); #endif } } void GcodeSuite::M425_report(const bool forReplay/*=true*/) { TERN_(MARLIN_SMALL_BUILD, return); report_heading_etc(forReplay, F(STR_BACKLASH_COMPENSATION)); SERIAL_ECHOLNPGM_P( PSTR(" M425 F"), backlash.get_correction() #ifdef BACKLASH_SMOOTHING_MM , PSTR(" S"), LINEAR_UNIT(backlash.get_smoothing_mm()) #endif #if NUM_AXES , LIST_N(DOUBLE(NUM_AXES), SP_X_STR, LINEAR_UNIT(backlash.get_distance_mm(X_AXIS)), SP_Y_STR, LINEAR_UNIT(backlash.get_distance_mm(Y_AXIS)), SP_Z_STR, LINEAR_UNIT(backlash.get_distance_mm(Z_AXIS)), SP_I_STR, I_AXIS_UNIT(backlash.get_distance_mm(I_AXIS)), SP_J_STR, J_AXIS_UNIT(backlash.get_distance_mm(J_AXIS)), SP_K_STR, K_AXIS_UNIT(backlash.get_distance_mm(K_AXIS)), SP_U_STR, U_AXIS_UNIT(backlash.get_distance_mm(U_AXIS)), SP_V_STR, V_AXIS_UNIT(backlash.get_distance_mm(V_AXIS)), SP_W_STR, W_AXIS_UNIT(backlash.get_distance_mm(W_AXIS)) ) #endif ); } #endif // BACKLASH_GCODE
2301_81045437/Marlin
Marlin/src/gcode/calibrate/M425.cpp
C++
agpl-3.0
4,688
/** * Marlin 3D Printer Firmware * Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin] * * Based on Sprinter and grbl. * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <https://www.gnu.org/licenses/>. * */ #include "../../inc/MarlinConfig.h" #if ENABLED(Z_MIN_PROBE_REPEATABILITY_TEST) #include "../gcode.h" #include "../../module/motion.h" #include "../../module/probe.h" #include "../../lcd/marlinui.h" #include "../../feature/bedlevel/bedlevel.h" #if HAS_LEVELING #include "../../module/planner.h" #endif #if HAS_PTC #include "../../feature/probe_temp_comp.h" #endif /** * M48: Z probe repeatability measurement function. * * Usage: * M48 <P#> <X#> <Y#> <V#> <E> <L#> <S> <C#> * 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) * C = Enable probe temperature compensation (0 or 1, default 1) * * This function requires the machine to be homed before invocation. */ void GcodeSuite::M48() { if (homing_needed_error()) return; const int8_t verbose_level = parser.byteval('V', 1); if (!WITHIN(verbose_level, 0, 4)) { SERIAL_ECHOLNPGM(GCODE_ERR_MSG("(V)erbose level implausible (0-4).")); return; } const int8_t n_samples = parser.byteval('P', 10); if (!WITHIN(n_samples, 4, 50)) { SERIAL_ECHOLNPGM(GCODE_ERR_MSG("Sample size not plausible (4-50).")); return; } const ProbePtRaise raise_after = parser.boolval('E') ? PROBE_PT_STOW : PROBE_PT_RAISE; // Test at the current position by default, overridden by X and Y const xy_pos_t test_position = { parser.linearval('X', current_position.x + probe.offset_xy.x), // If no X use the probe's current X position parser.linearval('Y', current_position.y + probe.offset_xy.y) // If no Y, ditto }; if (!probe.can_reach(test_position)) { LCD_MESSAGE_MAX(MSG_M48_OUT_OF_BOUNDS); SERIAL_ECHOLNPGM(GCODE_ERR_MSG(" (X,Y) out of bounds.")); return; } // Get the number of leg moves per test-point bool seen_L = parser.seen('L'); uint8_t n_legs = seen_L ? parser.value_byte() : 0; if (n_legs > 15) { SERIAL_ECHOLNPGM(GCODE_ERR_MSG("Legs of movement implausible (0-15).")); return; } if (n_legs == 1) n_legs = 2; // Schizoid motion as an optional stress-test const bool schizoid_flag = parser.boolval('S'); if (schizoid_flag && !seen_L) n_legs = 7; if (verbose_level > 0) SERIAL_ECHOLNPGM("M48 Z-Probe Repeatability Test"); if (verbose_level > 2) SERIAL_ECHOLNPGM("Positioning the probe..."); // Always disable Bed Level correction before probing... #if HAS_LEVELING const bool was_enabled = planner.leveling_active; set_bed_leveling_enabled(false); #endif TERN_(HAS_PTC, ptc.set_enabled(parser.boolval('C', true))); // Work with reasonable feedrates remember_feedrate_scaling_off(); // Working variables float mean = 0.0, // The average of all points so far, used to calculate deviation sigma = 0.0, // Standard deviation of all points so far min = 99999.9, // Smallest value sampled so far max = -99999.9, // Largest value sampled so far sample_set[n_samples]; // Storage for sampled values auto dev_report = [](const bool verbose, const_float_t mean, const_float_t sigma, const_float_t min, const_float_t max, const bool final=false) { if (verbose) { SERIAL_ECHOPGM("Mean: ", p_float_t(mean, 6)); if (!final) SERIAL_ECHOPGM(" Sigma: ", p_float_t(sigma, 6)); SERIAL_ECHOPGM(" Min: ", p_float_t(min, 3), " Max: ", p_float_t(max, 3), " Range: ", p_float_t(max-min, 3)); if (final) SERIAL_EOL(); } if (final) { SERIAL_ECHOLNPGM("Standard Deviation: ", p_float_t(sigma, 6)); SERIAL_EOL(); } }; // Move to the first point, deploy, and probe const float t = probe.probe_at_point(test_position, raise_after, verbose_level); bool probing_good = !isnan(t); if (probing_good) { randomSeed(millis()); float sample_sum = 0.0; for (uint8_t n = 0; n < n_samples; ++n) { #if HAS_STATUS_MESSAGE // Display M48 progress in the status bar ui.status_printf(0, F(S_FMT ": %d/%d"), GET_TEXT_F(MSG_M48_POINT), int(n + 1), int(n_samples)); #endif // When there are "legs" of movement move around the point before probing if (n_legs) { // Pick a random direction, starting angle, and radius 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 * (PRINTABLE_RADIUS)), int(0.3333333333 * (PRINTABLE_RADIUS)) #else int(5), int(0.125 * _MIN(X_BED_SIZE, Y_BED_SIZE)) #endif ); if (verbose_level > 3) { SERIAL_ECHOPGM("Start radius:", radius, " angle:", angle, " dir:"); if (dir > 0) SERIAL_CHAR('C'); SERIAL_ECHOLNPGM("CW"); } // Move from leg to leg in rapid succession for (uint8_t l = 0; l < n_legs - 1; ++l) { // Move some distance around the perimeter float delta_angle; if (schizoid_flag) { // The points of a 5 point star are 72 degrees apart. // Skip a point and go to the next one on the star. delta_angle = dir * 2.0 * 72.0; } else { // Just move further along the perimeter. delta_angle = dir * (float)random(25, 45); } angle += delta_angle; // Trig functions work without clamping, but just to be safe... while (angle > 360.0) angle -= 360.0; while (angle < 0.0) angle += 360.0; // Choose the next position as an offset to chosen test position const xy_pos_t noz_pos = test_position - probe.offset_xy; xy_pos_t next_pos = { noz_pos.x + float(cos(RADIANS(angle))) * radius, noz_pos.y + float(sin(RADIANS(angle))) * radius }; #if ENABLED(DELTA) // If the probe can't reach the point on a round bed... // Simply scale the numbers to bring them closer to origin. while (!probe.can_reach(next_pos)) { next_pos *= 0.8f; if (verbose_level > 3) SERIAL_ECHOLN(F("Moving inward: X"), next_pos.x, FPSTR(SP_Y_STR), next_pos.y); } #elif HAS_ENDSTOPS // For a rectangular bed just keep the probe in bounds LIMIT(next_pos.x, X_MIN_POS, X_MAX_POS); LIMIT(next_pos.y, Y_MIN_POS, Y_MAX_POS); #endif if (verbose_level > 3) SERIAL_ECHOLN(F("Going to: X"), next_pos.x, FPSTR(SP_Y_STR), next_pos.y); do_blocking_move_to_xy(next_pos); } // n_legs loop } // n_legs // Probe a single point const float pz = probe.probe_at_point(test_position, raise_after); // Break the loop if the probe fails probing_good = !isnan(pz); if (!probing_good) break; // Store the new sample sample_set[n] = pz; // Keep track of the largest and smallest samples NOMORE(min, pz); NOLESS(max, pz); // Get the mean value of all samples thus far sample_sum += pz; mean = sample_sum / (n + 1); // Calculate the standard deviation so far. // The value after the last sample will be the final output. float dev_sum = 0.0; for (uint8_t j = 0; j <= n; ++j) dev_sum += sq(sample_set[j] - mean); sigma = SQRT(dev_sum / (n + 1)); if (verbose_level > 1) { SERIAL_ECHO(n + 1, F(" of "), n_samples, F(": z: "), p_float_t(pz, 3), C(' ')); dev_report(verbose_level > 2, mean, sigma, min, max); SERIAL_EOL(); } } // n_samples loop } probe.stow(); if (probing_good) { SERIAL_ECHOLNPGM("Finished!"); dev_report(verbose_level > 0, mean, sigma, min, max, true); #if HAS_STATUS_MESSAGE // Display M48 results in the status bar ui.set_status_and_level(MString<30>(GET_TEXT_F(MSG_M48_DEVIATION), F(": "), w_float_t(sigma, 2, 6))); #endif } restore_feedrate_and_scaling(); // Re-enable bed level correction if it had been on TERN_(HAS_LEVELING, set_bed_leveling_enabled(was_enabled)); // Re-enable probe temperature correction TERN_(HAS_PTC, ptc.set_enabled(true)); report_current_position(); } #endif // Z_MIN_PROBE_REPEATABILITY_TEST
2301_81045437/Marlin
Marlin/src/gcode/calibrate/M48.cpp
C++
agpl-3.0
9,352
/** * Marlin 3D Printer Firmware * Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin] * * Based on Sprinter and grbl. * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <https://www.gnu.org/licenses/>. * */ #include "../../inc/MarlinConfig.h" #if IS_KINEMATIC #include "../gcode.h" #include "../../module/motion.h" #if ENABLED(DELTA) #include "../../module/delta.h" /** * M665: Set delta configurations * * H = delta height * L = diagonal rod * R = delta radius * S = segments per second * X = Alpha (Tower 1) angle trim * Y = Beta (Tower 2) angle trim * Z = Gamma (Tower 3) angle trim * A = Alpha (Tower 1) diagonal rod trim * B = Beta (Tower 2) diagonal rod trim * C = Gamma (Tower 3) diagonal rod trim */ void GcodeSuite::M665() { if (!parser.seen_any()) return M665_report(); if (parser.seenval('H')) delta_height = parser.value_linear_units(); if (parser.seenval('L')) delta_diagonal_rod = parser.value_linear_units(); if (parser.seenval('R')) delta_radius = parser.value_linear_units(); if (parser.seenval('S')) segments_per_second = parser.value_float(); if (parser.seenval('X')) delta_tower_angle_trim.a = parser.value_float(); if (parser.seenval('Y')) delta_tower_angle_trim.b = parser.value_float(); if (parser.seenval('Z')) delta_tower_angle_trim.c = parser.value_float(); if (parser.seenval('A')) delta_diagonal_rod_trim.a = parser.value_float(); if (parser.seenval('B')) delta_diagonal_rod_trim.b = parser.value_float(); if (parser.seenval('C')) delta_diagonal_rod_trim.c = parser.value_float(); recalc_delta_settings(); } void GcodeSuite::M665_report(const bool forReplay/*=true*/) { TERN_(MARLIN_SMALL_BUILD, return); report_heading_etc(forReplay, F(STR_DELTA_SETTINGS)); SERIAL_ECHOLNPGM_P( PSTR(" M665 L"), LINEAR_UNIT(delta_diagonal_rod) , PSTR(" R"), LINEAR_UNIT(delta_radius) , PSTR(" H"), LINEAR_UNIT(delta_height) , PSTR(" S"), segments_per_second , SP_X_STR, LINEAR_UNIT(delta_tower_angle_trim.a) , SP_Y_STR, LINEAR_UNIT(delta_tower_angle_trim.b) , SP_Z_STR, LINEAR_UNIT(delta_tower_angle_trim.c) , PSTR(" A"), LINEAR_UNIT(delta_diagonal_rod_trim.a) , PSTR(" B"), LINEAR_UNIT(delta_diagonal_rod_trim.b) , PSTR(" C"), LINEAR_UNIT(delta_diagonal_rod_trim.c) ); } #elif IS_SCARA #include "../../module/scara.h" /** * M665: Set SCARA settings * * Parameters: * * S[segments] - Segments-per-second * * Without NO_WORKSPACE_OFFSETS: * * P[theta-psi-offset] - Theta-Psi offset, added to the shoulder (A/X) angle * T[theta-offset] - Theta offset, added to the elbow (B/Y) angle * Z[z-offset] - Z offset, added to Z * * A, P, and X are all aliases for the shoulder angle * B, T, and Y are all aliases for the elbow angle */ void GcodeSuite::M665() { if (!parser.seen_any()) return M665_report(); if (parser.seenval('S')) segments_per_second = parser.value_float(); #if HAS_SCARA_OFFSET if (parser.seenval('Z')) scara_home_offset.z = parser.value_linear_units(); const bool hasA = parser.seenval('A'), hasP = parser.seenval('P'), hasX = parser.seenval('X'); const uint8_t sumAPX = hasA + hasP + hasX; if (sumAPX) { if (sumAPX == 1) scara_home_offset.a = parser.value_float(); else { SERIAL_ERROR_MSG("Only one of A, P, or X is allowed."); return; } } const bool hasB = parser.seenval('B'), hasT = parser.seenval('T'), hasY = parser.seenval('Y'); const uint8_t sumBTY = hasB + hasT + hasY; if (sumBTY) { if (sumBTY == 1) scara_home_offset.b = parser.value_float(); else { SERIAL_ERROR_MSG("Only one of B, T, or Y is allowed."); return; } } #endif // HAS_SCARA_OFFSET } void GcodeSuite::M665_report(const bool forReplay/*=true*/) { TERN_(MARLIN_SMALL_BUILD, return); report_heading_etc(forReplay, F(STR_SCARA_SETTINGS " (" STR_S_SEG_PER_SEC TERN_(HAS_SCARA_OFFSET, " " STR_SCARA_P_T_Z) ")")); SERIAL_ECHOLNPGM_P( PSTR(" M665 S"), segments_per_second #if HAS_SCARA_OFFSET , SP_P_STR, scara_home_offset.a , SP_T_STR, scara_home_offset.b , SP_Z_STR, LINEAR_UNIT(scara_home_offset.z) #endif ); } #elif ENABLED(POLARGRAPH) #include "../../module/polargraph.h" /** * M665: Set POLARGRAPH settings * * Parameters: * * S[segments] - Segments-per-second * L[left] - Work area minimum X * R[right] - Work area maximum X * T[top] - Work area maximum Y * B[bottom] - Work area minimum Y * H[length] - Maximum belt length */ void GcodeSuite::M665() { if (!parser.seen_any()) return M665_report(); if (parser.seenval('S')) segments_per_second = parser.value_float(); if (parser.seenval('L')) draw_area_min.x = parser.value_linear_units(); if (parser.seenval('R')) draw_area_max.x = parser.value_linear_units(); if (parser.seenval('T')) draw_area_max.y = parser.value_linear_units(); if (parser.seenval('B')) draw_area_min.y = parser.value_linear_units(); if (parser.seenval('H')) polargraph_max_belt_len = parser.value_linear_units(); } void GcodeSuite::M665_report(const bool forReplay/*=true*/) { TERN_(MARLIN_SMALL_BUILD, return); report_heading_etc(forReplay, F(STR_POLARGRAPH_SETTINGS)); SERIAL_ECHOLNPGM_P( PSTR(" M665 S"), LINEAR_UNIT(segments_per_second), PSTR(" L"), LINEAR_UNIT(draw_area_min.x), PSTR(" R"), LINEAR_UNIT(draw_area_max.x), SP_T_STR, LINEAR_UNIT(draw_area_max.y), SP_B_STR, LINEAR_UNIT(draw_area_min.y), PSTR(" H"), LINEAR_UNIT(polargraph_max_belt_len) ); } #elif ENABLED(POLAR) #include "../../module/polar.h" /** * M665: Set POLAR settings * Parameters: * S[segments] - Segments-per-second */ void GcodeSuite::M665() { if (!parser.seen_any()) return M665_report(); if (parser.seenval('S')) segments_per_second = parser.value_float(); } void GcodeSuite::M665_report(const bool forReplay/*=true*/) { TERN_(MARLIN_SMALL_BUILD, return); report_heading_etc(forReplay, F(STR_POLAR_SETTINGS)); SERIAL_ECHOLNPGM_P(PSTR(" M665 S"), segments_per_second); } #endif // POLAR #endif // IS_KINEMATIC
2301_81045437/Marlin
Marlin/src/gcode/calibrate/M665.cpp
C++
agpl-3.0
7,192
/** * Marlin 3D Printer Firmware * Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin] * * Based on Sprinter and grbl. * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <https://www.gnu.org/licenses/>. * */ #include "../../inc/MarlinConfig.h" #if ANY(DELTA, HAS_EXTRA_ENDSTOPS) #include "../gcode.h" #if ENABLED(DELTA) #include "../../module/delta.h" #include "../../module/motion.h" #else #include "../../module/endstops.h" #endif #define DEBUG_OUT ENABLED(DEBUG_LEVELING_FEATURE) #include "../../core/debug_out.h" #if ENABLED(DELTA) /** * M666: Set delta endstop adjustment */ void GcodeSuite::M666() { DEBUG_SECTION(log_M666, "M666", DEBUGGING(LEVELING)); bool is_err = false, is_set = false; LOOP_NUM_AXES(i) { if (parser.seenval(AXIS_CHAR(i))) { is_set = true; const float v = parser.value_linear_units(); if (v > 0) is_err = true; else { delta_endstop_adj[i] = v; if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPGM("delta_endstop_adj[", C(AXIS_CHAR(i)), "] = ", v); } } } if (is_err) SERIAL_ECHOLNPGM(GCODE_ERR_MSG("M666 offsets must be <= 0")); if (!is_set) M666_report(); } void GcodeSuite::M666_report(const bool forReplay/*=true*/) { TERN_(MARLIN_SMALL_BUILD, return); report_heading_etc(forReplay, F(STR_ENDSTOP_ADJUSTMENT)); SERIAL_ECHOLNPGM_P( PSTR(" M666 X"), LINEAR_UNIT(delta_endstop_adj.a) , SP_Y_STR, LINEAR_UNIT(delta_endstop_adj.b) , SP_Z_STR, LINEAR_UNIT(delta_endstop_adj.c) ); } #else /** * M666: Set Dual Endstops offsets for X, Y, and/or Z. * With no parameters report current offsets. * * For Triple / Quad Z Endstops: * Set Z2 Only: M666 S2 Z<offset> * Set Z3 Only: M666 S3 Z<offset> * Set Z4 Only: M666 S4 Z<offset> * Set All: M666 Z<offset> */ void GcodeSuite::M666() { if (!parser.seen_any()) return M666_report(); #if ENABLED(X_DUAL_ENDSTOPS) if (parser.seenval('X')) endstops.x2_endstop_adj = parser.value_linear_units(); #endif #if ENABLED(Y_DUAL_ENDSTOPS) if (parser.seenval('Y')) endstops.y2_endstop_adj = parser.value_linear_units(); #endif #if ENABLED(Z_MULTI_ENDSTOPS) if (parser.seenval('Z')) { const float z_adj = parser.value_linear_units(); #if NUM_Z_STEPPERS == 2 endstops.z2_endstop_adj = z_adj; #else const int ind = parser.intval('S'); #define _SET_ZADJ(N) if (!ind || ind == N) endstops.z##N##_endstop_adj = z_adj; REPEAT_S(2, INCREMENT(NUM_Z_STEPPERS), _SET_ZADJ) #endif } #endif } void GcodeSuite::M666_report(const bool forReplay/*=true*/) { TERN_(MARLIN_SMALL_BUILD, return); report_heading_etc(forReplay, F(STR_ENDSTOP_ADJUSTMENT)); SERIAL_ECHOPGM(" M666"); #if ENABLED(X_DUAL_ENDSTOPS) SERIAL_ECHOLNPGM_P(SP_X_STR, LINEAR_UNIT(endstops.x2_endstop_adj)); #endif #if ENABLED(Y_DUAL_ENDSTOPS) SERIAL_ECHOLNPGM_P(SP_Y_STR, LINEAR_UNIT(endstops.y2_endstop_adj)); #endif #if ENABLED(Z_MULTI_ENDSTOPS) #if NUM_Z_STEPPERS >= 3 SERIAL_ECHOPGM(" S2 Z", LINEAR_UNIT(endstops.z3_endstop_adj)); report_echo_start(forReplay); SERIAL_ECHOPGM(" M666 S3 Z", LINEAR_UNIT(endstops.z3_endstop_adj)); #if NUM_Z_STEPPERS >= 4 report_echo_start(forReplay); SERIAL_ECHOPGM(" M666 S4 Z", LINEAR_UNIT(endstops.z4_endstop_adj)); #endif #else SERIAL_ECHOLNPGM_P(SP_Z_STR, LINEAR_UNIT(endstops.z2_endstop_adj)); #endif #endif } #endif // HAS_EXTRA_ENDSTOPS #endif // DELTA || HAS_EXTRA_ENDSTOPS
2301_81045437/Marlin
Marlin/src/gcode/calibrate/M666.cpp
C++
agpl-3.0
4,361
/** * Marlin 3D Printer Firmware * Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin] * * Based on Sprinter and grbl. * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <https://www.gnu.org/licenses/>. * */ #include "../../inc/MarlinConfig.h" #if ENABLED(SKEW_CORRECTION_GCODE) #include "../gcode.h" #include "../../module/planner.h" /** * M852: Get or set the machine skew factors. Reports current values with no arguments. * * S[xy_factor] - Alias for 'I' * I[xy_factor] - New XY skew factor * J[xz_factor] - New XZ skew factor * K[yz_factor] - New YZ skew factor */ void GcodeSuite::M852() { if (!parser.seen("SIJK")) return M852_report(); uint8_t badval = 0, setval = 0; if (parser.seenval('I') || parser.seenval('S')) { const float value = parser.value_linear_units(); if (WITHIN(value, SKEW_FACTOR_MIN, SKEW_FACTOR_MAX)) { if (planner.skew_factor.xy != value) { planner.skew_factor.xy = value; ++setval; } } else ++badval; } #if ENABLED(SKEW_CORRECTION_FOR_Z) if (parser.seenval('J')) { const float value = parser.value_linear_units(); if (WITHIN(value, SKEW_FACTOR_MIN, SKEW_FACTOR_MAX)) { if (planner.skew_factor.xz != value) { planner.skew_factor.xz = value; ++setval; } } else ++badval; } if (parser.seenval('K')) { const float value = parser.value_linear_units(); if (WITHIN(value, SKEW_FACTOR_MIN, SKEW_FACTOR_MAX)) { if (planner.skew_factor.yz != value) { planner.skew_factor.yz = value; ++setval; } } else ++badval; } #endif if (badval) SERIAL_ECHOLNPGM(STR_SKEW_MIN " " STRINGIFY(SKEW_FACTOR_MIN) " " STR_SKEW_MAX " " STRINGIFY(SKEW_FACTOR_MAX)); // When skew is changed the current position changes if (setval) { set_current_from_steppers_for_axis(ALL_AXES_ENUM); sync_plan_position(); report_current_position(); } } void GcodeSuite::M852_report(const bool forReplay/*=true*/) { TERN_(MARLIN_SMALL_BUILD, return); report_heading_etc(forReplay, F(STR_SKEW_FACTOR)); SERIAL_ECHOPGM(" M852 I", p_float_t(planner.skew_factor.xy, 6)); #if ENABLED(SKEW_CORRECTION_FOR_Z) SERIAL_ECHOLNPGM(" J", p_float_t(planner.skew_factor.xz, 6), " K", p_float_t(planner.skew_factor.yz, 6), " ; XY, XZ, YZ"); #else SERIAL_ECHOLNPGM(" ; XY"); #endif } #endif // SKEW_CORRECTION_GCODE
2301_81045437/Marlin
Marlin/src/gcode/calibrate/M852.cpp
C++
agpl-3.0
3,118
/** * Marlin 3D Printer Firmware * Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin] * * Based on Sprinter and grbl. * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <https://www.gnu.org/licenses/>. * */ #include "../gcode.h" #include "../../MarlinCore.h" #include "../../module/planner.h" #if DISABLED(NO_VOLUMETRICS) /** * M200: Set filament diameter and set E axis units to cubic units * * T<extruder> - Optional extruder number. Current extruder if omitted. * D<linear> - Set filament diameter and enable. D0 disables volumetric. * S<bool> - Turn volumetric ON or OFF. * * With VOLUMETRIC_EXTRUDER_LIMIT: * * L<float> - Volumetric extruder limit (in mm^3/sec). L0 disables the limit. */ void GcodeSuite::M200() { if (!parser.seen("DST" TERN_(VOLUMETRIC_EXTRUDER_LIMIT, "L"))) return M200_report(); const int8_t target_extruder = get_target_extruder_from_command(); if (target_extruder < 0) return; bool vol_enable = parser.volumetric_enabled, can_enable = true; if (parser.seenval('D')) { const float dval = parser.value_linear_units(); if (dval) { // Set filament size for volumetric calculation planner.set_filament_size(target_extruder, dval); vol_enable = true; // Dn = enable for compatibility } else can_enable = false; // D0 = disable for compatibility } // Enable or disable with S1 / S0 parser.volumetric_enabled = can_enable && parser.boolval('S', vol_enable); #if ENABLED(VOLUMETRIC_EXTRUDER_LIMIT) if (parser.seenval('L')) { // Set volumetric limit (in mm^3/sec) const float lval = parser.value_float(); if (WITHIN(lval, 0, VOLUMETRIC_EXTRUDER_LIMIT_MAX)) planner.set_volumetric_extruder_limit(target_extruder, lval); else SERIAL_ECHOLNPGM(GCODE_ERR_MSG("L value out of range (0-" STRINGIFY(VOLUMETRIC_EXTRUDER_LIMIT_MAX) ").")); } #endif planner.calculate_volumetric_multipliers(); } void GcodeSuite::M200_report(const bool forReplay/*=true*/) { TERN_(MARLIN_SMALL_BUILD, return); if (!forReplay) { report_heading(forReplay, F(STR_FILAMENT_SETTINGS), false); if (!parser.volumetric_enabled) SERIAL_ECHOPGM(" (Disabled):"); SERIAL_EOL(); report_echo_start(forReplay); } #if EXTRUDERS == 1 { SERIAL_ECHOLNPGM( " M200 S", parser.volumetric_enabled, " D", LINEAR_UNIT(planner.filament_size[0]) #if ENABLED(VOLUMETRIC_EXTRUDER_LIMIT) , " L", LINEAR_UNIT(planner.volumetric_extruder_limit[0]) #endif ); } #else SERIAL_ECHOLNPGM(" M200 S", parser.volumetric_enabled); EXTRUDER_LOOP() { report_echo_start(forReplay); SERIAL_ECHOLNPGM( " M200 T", e, " D", LINEAR_UNIT(planner.filament_size[e]) #if ENABLED(VOLUMETRIC_EXTRUDER_LIMIT) , " L", LINEAR_UNIT(planner.volumetric_extruder_limit[e]) #endif ); } #endif } #endif // !NO_VOLUMETRICS /** * M201: Set max acceleration in units/s^2 for print moves. * * X<accel> : Max Acceleration for X * Y<accel> : Max Acceleration for Y * Z<accel> : Max Acceleration for Z * ... : etc * E<accel> : Max Acceleration for Extruder * T<index> : Extruder index to set * * With XY_FREQUENCY_LIMIT: * F<Hz> : Frequency limit for XY...IJKUVW * S<percent> : Speed factor percentage. */ void GcodeSuite::M201() { if (!parser.seen("T" STR_AXES_LOGICAL TERN_(XY_FREQUENCY_LIMIT, "FS"))) return M201_report(); const int8_t target_extruder = get_target_extruder_from_command(); if (target_extruder < 0) return; #ifdef XY_FREQUENCY_LIMIT if (parser.seenval('F')) planner.set_frequency_limit(parser.value_byte()); if (parser.seenval('S')) planner.xy_freq_min_speed_factor = constrain(parser.value_float(), 1, 100) / 100; #endif LOOP_LOGICAL_AXES(i) { if (parser.seenval(AXIS_CHAR(i))) { const AxisEnum a = TERN(HAS_EXTRUDERS, (i == E_AXIS ? E_AXIS_N(target_extruder) : (AxisEnum)i), (AxisEnum)i); planner.set_max_acceleration(a, parser.value_axis_units(a)); } } } void GcodeSuite::M201_report(const bool forReplay/*=true*/) { TERN_(MARLIN_SMALL_BUILD, return); report_heading_etc(forReplay, F(STR_MAX_ACCELERATION)); #if NUM_AXES SERIAL_ECHOPGM_P( LIST_N(DOUBLE(NUM_AXES), PSTR(" M201 X"), LINEAR_UNIT(planner.settings.max_acceleration_mm_per_s2[X_AXIS]), SP_Y_STR, LINEAR_UNIT(planner.settings.max_acceleration_mm_per_s2[Y_AXIS]), SP_Z_STR, LINEAR_UNIT(planner.settings.max_acceleration_mm_per_s2[Z_AXIS]), SP_I_STR, I_AXIS_UNIT(planner.settings.max_acceleration_mm_per_s2[I_AXIS]), SP_J_STR, J_AXIS_UNIT(planner.settings.max_acceleration_mm_per_s2[J_AXIS]), SP_K_STR, K_AXIS_UNIT(planner.settings.max_acceleration_mm_per_s2[K_AXIS]), SP_U_STR, U_AXIS_UNIT(planner.settings.max_acceleration_mm_per_s2[U_AXIS]), SP_V_STR, V_AXIS_UNIT(planner.settings.max_acceleration_mm_per_s2[V_AXIS]), SP_W_STR, W_AXIS_UNIT(planner.settings.max_acceleration_mm_per_s2[W_AXIS]) ) ); #endif #if HAS_EXTRUDERS && DISABLED(DISTINCT_E_FACTORS) SERIAL_ECHOPGM_P(SP_E_STR, VOLUMETRIC_UNIT(planner.settings.max_acceleration_mm_per_s2[E_AXIS])); #endif #if NUM_AXES || (HAS_EXTRUDERS && DISABLED(DISTINCT_E_FACTORS)) SERIAL_EOL(); #endif #if ENABLED(DISTINCT_E_FACTORS) for (uint8_t i = 0; i < E_STEPPERS; ++i) { report_echo_start(forReplay); SERIAL_ECHOLNPGM_P( PSTR(" M201 T"), i , SP_E_STR, VOLUMETRIC_UNIT(planner.settings.max_acceleration_mm_per_s2[E_AXIS_N(i)]) ); } #endif } /** * M203: Set maximum feedrate that your machine can sustain (M203 X200 Y200 Z300 E10000) in units/sec * * With multiple extruders use T to specify which one. */ void GcodeSuite::M203() { if (!parser.seen("T" STR_AXES_LOGICAL)) return M203_report(); const int8_t target_extruder = get_target_extruder_from_command(); if (target_extruder < 0) return; LOOP_LOGICAL_AXES(i) if (parser.seenval(AXIS_CHAR(i))) { const AxisEnum a = TERN(HAS_EXTRUDERS, (i == E_AXIS ? E_AXIS_N(target_extruder) : (AxisEnum)i), (AxisEnum)i); planner.set_max_feedrate(a, parser.value_axis_units(a)); } } void GcodeSuite::M203_report(const bool forReplay/*=true*/) { TERN_(MARLIN_SMALL_BUILD, return); report_heading_etc(forReplay, F(STR_MAX_FEEDRATES)); #if NUM_AXES SERIAL_ECHOPGM_P( LIST_N(DOUBLE(NUM_AXES), PSTR(" M203 X"), LINEAR_UNIT(planner.settings.max_feedrate_mm_s[X_AXIS]), SP_Y_STR, LINEAR_UNIT(planner.settings.max_feedrate_mm_s[Y_AXIS]), SP_Z_STR, LINEAR_UNIT(planner.settings.max_feedrate_mm_s[Z_AXIS]), SP_I_STR, LINEAR_UNIT(planner.settings.max_feedrate_mm_s[I_AXIS]), SP_J_STR, LINEAR_UNIT(planner.settings.max_feedrate_mm_s[J_AXIS]), SP_K_STR, LINEAR_UNIT(planner.settings.max_feedrate_mm_s[K_AXIS]), SP_U_STR, LINEAR_UNIT(planner.settings.max_feedrate_mm_s[U_AXIS]), SP_V_STR, LINEAR_UNIT(planner.settings.max_feedrate_mm_s[V_AXIS]), SP_W_STR, LINEAR_UNIT(planner.settings.max_feedrate_mm_s[W_AXIS]) ) ); #endif #if HAS_EXTRUDERS && DISABLED(DISTINCT_E_FACTORS) SERIAL_ECHOPGM_P(SP_E_STR, VOLUMETRIC_UNIT(planner.settings.max_feedrate_mm_s[E_AXIS])); #endif #if NUM_AXES || (HAS_EXTRUDERS && DISABLED(DISTINCT_E_FACTORS)) SERIAL_EOL(); #endif #if ENABLED(DISTINCT_E_FACTORS) for (uint8_t i = 0; i < E_STEPPERS; ++i) { if (!forReplay) SERIAL_ECHO_START(); SERIAL_ECHOLNPGM_P( PSTR(" M203 T"), i , SP_E_STR, VOLUMETRIC_UNIT(planner.settings.max_feedrate_mm_s[E_AXIS_N(i)]) ); } #endif } /** * M204: Set Accelerations in units/sec^2 (M204 P1200 R3000 T3000) * * P<accel> Printing moves * R<accel> Retract only (no X, Y, Z) moves * T<accel> Travel (non printing) moves */ void GcodeSuite::M204() { if (!parser.seen("PRST")) return M204_report(); else { //planner.synchronize(); // 'S' for legacy compatibility. Should NOT BE USED for new development if (parser.seenval('S')) planner.settings.travel_acceleration = planner.settings.acceleration = parser.value_linear_units(); if (parser.seenval('P')) planner.settings.acceleration = parser.value_linear_units(); if (parser.seenval('R')) planner.settings.retract_acceleration = parser.value_linear_units(); if (parser.seenval('T')) planner.settings.travel_acceleration = parser.value_linear_units(); } } void GcodeSuite::M204_report(const bool forReplay/*=true*/) { TERN_(MARLIN_SMALL_BUILD, return); report_heading_etc(forReplay, F(STR_ACCELERATION_P_R_T)); SERIAL_ECHOLNPGM_P( PSTR(" M204 P"), LINEAR_UNIT(planner.settings.acceleration) , PSTR(" R"), LINEAR_UNIT(planner.settings.retract_acceleration) , SP_T_STR, LINEAR_UNIT(planner.settings.travel_acceleration) ); } #if AXIS_COLLISION('B') #define M205_MIN_SEG_TIME_PARAM 'D' #define M205_MIN_SEG_TIME_STR "D" #warning "Use 'M205 D' for Minimum Segment Time." #else #define M205_MIN_SEG_TIME_PARAM 'B' #define M205_MIN_SEG_TIME_STR "B" #endif /** * M205: Set Advanced Settings * * B<µs> : Min Segment Time * S<units/s> : Min Feed Rate * T<units/s> : Min Travel Feed Rate * * With CLASSIC_JERK: * X<units/sec^2> : Max X Jerk * Y<units/sec^2> : Max Y Jerk * Z<units/sec^2> : Max Z Jerk * ... : etc * E<units/sec^2> : Max E Jerk * * Without CLASSIC_JERK: * J(mm) : Junction Deviation */ void GcodeSuite::M205() { if (!parser.seen_any()) return M205_report(); //planner.synchronize(); if (parser.seenval(M205_MIN_SEG_TIME_PARAM)) planner.settings.min_segment_time_us = parser.value_ulong(); if (parser.seenval('S')) planner.settings.min_feedrate_mm_s = parser.value_linear_units(); if (parser.seenval('T')) planner.settings.min_travel_feedrate_mm_s = parser.value_linear_units(); #if HAS_JUNCTION_DEVIATION if (parser.seenval('J')) { const float junc_dev = parser.value_linear_units(); if (WITHIN(junc_dev, 0.01f, 0.3f)) { planner.junction_deviation_mm = junc_dev; TERN_(HAS_LINEAR_E_JERK, planner.recalculate_max_e_jerk()); } else SERIAL_ERROR_MSG("?J out of range (0.01 to 0.3)"); } #endif #if ENABLED(CLASSIC_JERK) bool seenZ = false; LOGICAL_AXIS_CODE( if (parser.seenval('E')) planner.set_max_jerk(E_AXIS, parser.value_linear_units()), if (parser.seenval('X')) planner.set_max_jerk(X_AXIS, parser.value_linear_units()), if (parser.seenval('Y')) planner.set_max_jerk(Y_AXIS, parser.value_linear_units()), if ((seenZ = parser.seenval('Z'))) planner.set_max_jerk(Z_AXIS, parser.value_linear_units()), if (parser.seenval(AXIS4_NAME)) planner.set_max_jerk(I_AXIS, parser.TERN(AXIS4_ROTATES, value_float, value_linear_units)()), if (parser.seenval(AXIS5_NAME)) planner.set_max_jerk(J_AXIS, parser.TERN(AXIS5_ROTATES, value_float, value_linear_units)()), if (parser.seenval(AXIS6_NAME)) planner.set_max_jerk(K_AXIS, parser.TERN(AXIS6_ROTATES, value_float, value_linear_units)()), if (parser.seenval(AXIS7_NAME)) planner.set_max_jerk(U_AXIS, parser.TERN(AXIS7_ROTATES, value_float, value_linear_units)()), if (parser.seenval(AXIS8_NAME)) planner.set_max_jerk(V_AXIS, parser.TERN(AXIS8_ROTATES, value_float, value_linear_units)()), if (parser.seenval(AXIS9_NAME)) planner.set_max_jerk(W_AXIS, parser.TERN(AXIS9_ROTATES, value_float, value_linear_units)()) ); #if HAS_MESH && DISABLED(LIMITED_JERK_EDITING) if (seenZ && planner.max_jerk.z <= 0.1f) SERIAL_ECHOLNPGM("WARNING! Low Z Jerk may lead to unwanted pauses."); #endif #endif // CLASSIC_JERK } void GcodeSuite::M205_report(const bool forReplay/*=true*/) { TERN_(MARLIN_SMALL_BUILD, return); report_heading_etc(forReplay, F( "Advanced (" M205_MIN_SEG_TIME_STR "<min_segment_time_us> S<min_feedrate> T<min_travel_feedrate>" TERN_(HAS_JUNCTION_DEVIATION, " J<junc_dev>") #if ENABLED(CLASSIC_JERK) NUM_AXIS_GANG( " X<max_jerk>", " Y<max_jerk>", " Z<max_jerk>", " " STR_I "<max_jerk>", " " STR_J "<max_jerk>", " " STR_K "<max_jerk>", " " STR_U "<max_jerk>", " " STR_V "<max_jerk>", " " STR_W "<max_jerk>" ) #endif TERN_(HAS_CLASSIC_E_JERK, " E<max_jerk>") ")" )); SERIAL_ECHOLNPGM_P( PSTR(" M205 " M205_MIN_SEG_TIME_STR), LINEAR_UNIT(planner.settings.min_segment_time_us) , PSTR(" S"), LINEAR_UNIT(planner.settings.min_feedrate_mm_s) , SP_T_STR, LINEAR_UNIT(planner.settings.min_travel_feedrate_mm_s) #if HAS_JUNCTION_DEVIATION , PSTR(" J"), LINEAR_UNIT(planner.junction_deviation_mm) #endif #if ENABLED(CLASSIC_JERK) && NUM_AXES , LIST_N(DOUBLE(NUM_AXES), SP_X_STR, LINEAR_UNIT(planner.max_jerk.x), SP_Y_STR, LINEAR_UNIT(planner.max_jerk.y), SP_Z_STR, LINEAR_UNIT(planner.max_jerk.z), SP_I_STR, I_AXIS_UNIT(planner.max_jerk.i), SP_J_STR, J_AXIS_UNIT(planner.max_jerk.j), SP_K_STR, K_AXIS_UNIT(planner.max_jerk.k), SP_U_STR, U_AXIS_UNIT(planner.max_jerk.u), SP_V_STR, V_AXIS_UNIT(planner.max_jerk.v), SP_W_STR, W_AXIS_UNIT(planner.max_jerk.w) ) #if HAS_CLASSIC_E_JERK , SP_E_STR, LINEAR_UNIT(planner.max_jerk.e) #endif #endif ); }
2301_81045437/Marlin
Marlin/src/gcode/config/M200-M205.cpp
C++
agpl-3.0
14,271
/** * Marlin 3D Printer Firmware * Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin] * * Based on Sprinter and grbl. * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <https://www.gnu.org/licenses/>. * */ #include "../../inc/MarlinConfigPre.h" #if HAS_MULTI_EXTRUDER #include "../gcode.h" #if HAS_TOOLCHANGE #include "../../module/tool_change.h" #endif #if ENABLED(TOOLCHANGE_MIGRATION_FEATURE) #include "../../module/motion.h" // for active_extruder #endif /** * M217 - Set toolchange parameters * * // Tool change command * Q Prime active tool and exit * * // Tool change settings * S[linear] Swap length * B[linear] Extra Swap resume length * E[linear] Extra Prime length (as used by M217 Q) * G[linear] Cutting wipe retract length (<=100mm) * R[linear/min] Retract speed * U[linear/min] UnRetract speed * P[linear/min] Prime speed * V[linear] 0/1 Enable auto prime first extruder used * W[linear] 0/1 Enable park & Z Raise * X[linear] Park X (Requires TOOLCHANGE_PARK) * Y[linear] Park Y (Requires TOOLCHANGE_PARK and NUM_AXES >= 2) * I[linear] Park I (Requires TOOLCHANGE_PARK and NUM_AXES >= 4) * J[linear] Park J (Requires TOOLCHANGE_PARK and NUM_AXES >= 5) * K[linear] Park K (Requires TOOLCHANGE_PARK and NUM_AXES >= 6) * C[linear] Park U (Requires TOOLCHANGE_PARK and NUM_AXES >= 7) * H[linear] Park V (Requires TOOLCHANGE_PARK and NUM_AXES >= 8) * O[linear] Park W (Requires TOOLCHANGE_PARK and NUM_AXES >= 9) * Z[linear] Z Raise * F[speed] Fan Speed 0-255 * D[seconds] Fan time * * Tool migration settings * A[0|1] Enable auto-migration on runout * L[index] Last extruder to use for auto-migration * * Tool migration command * T[index] Migrate to next extruder or the given extruder */ void GcodeSuite::M217() { #if ENABLED(TOOLCHANGE_FILAMENT_SWAP) static constexpr float max_extrude = TERN(PREVENT_LENGTHY_EXTRUDE, EXTRUDE_MAXLENGTH, 500); if (parser.seen('Q')) { tool_change_prime(); return; } if (parser.seenval('S')) { const float v = parser.value_linear_units(); toolchange_settings.swap_length = constrain(v, 0, max_extrude); } if (parser.seenval('B')) { const float v = parser.value_linear_units(); toolchange_settings.extra_resume = constrain(v, -10, 10); } if (parser.seenval('E')) { const float v = parser.value_linear_units(); toolchange_settings.extra_prime = constrain(v, 0, max_extrude); } if (parser.seenval('P')) { const int16_t v = parser.value_linear_units(); toolchange_settings.prime_speed = constrain(v, 10, 5400); } if (parser.seenval('G')) { const int16_t v = parser.value_linear_units(); toolchange_settings.wipe_retract = constrain(v, 0, 100); } if (parser.seenval('R')) { const int16_t v = parser.value_linear_units(); toolchange_settings.retract_speed = constrain(v, 10, 5400); } if (parser.seenval('U')) { const int16_t v = parser.value_linear_units(); toolchange_settings.unretract_speed = constrain(v, 10, 5400); } #if TOOLCHANGE_FS_FAN >= 0 && HAS_FAN if (parser.seenval('F')) { const uint16_t v = parser.value_ushort(); toolchange_settings.fan_speed = constrain(v, 0, 255); } if (parser.seenval('D')) { const uint16_t v = parser.value_ushort(); toolchange_settings.fan_time = constrain(v, 1, 30); } #endif #endif #if ENABLED(TOOLCHANGE_FS_PRIME_FIRST_USED) if (parser.seenval('V')) { enable_first_prime = parser.value_linear_units(); } #endif #if ENABLED(TOOLCHANGE_PARK) if (parser.seenval('W')) { toolchange_settings.enable_park = parser.value_linear_units(); } #if HAS_X_AXIS if (parser.seenval('X')) { const int16_t v = parser.value_linear_units(); toolchange_settings.change_point.x = constrain(v, X_MIN_POS, X_MAX_POS); } #endif #if HAS_Y_AXIS if (parser.seenval('Y')) { const int16_t v = parser.value_linear_units(); toolchange_settings.change_point.y = constrain(v, Y_MIN_POS, Y_MAX_POS); } #endif #if HAS_I_AXIS if (parser.seenval('I')) { const int16_t v = parser.TERN(AXIS4_ROTATES, value_int, value_linear_units)(); toolchange_settings.change_point.i = constrain(v, I_MIN_POS, I_MAX_POS); } #endif #if HAS_J_AXIS if (parser.seenval('J')) { const int16_t v = parser.TERN(AXIS5_ROTATES, value_int, value_linear_units)(); toolchange_settings.change_point.j = constrain(v, J_MIN_POS, J_MAX_POS); } #endif #if HAS_K_AXIS if (parser.seenval('K')) { const int16_t v = parser.TERN(AXIS6_ROTATES, value_int, value_linear_units)(); toolchange_settings.change_point.k = constrain(v, K_MIN_POS, K_MAX_POS); } #endif #if HAS_U_AXIS if (parser.seenval('C')) { const int16_t v = parser.TERN(AXIS7_ROTATES, value_int, value_linear_units)(); toolchange_settings.change_point.u = constrain(v, U_MIN_POS, U_MAX_POS); } #endif #if HAS_V_AXIS if (parser.seenval('H')) { const int16_t v = parser.TERN(AXIS8_ROTATES, value_int, value_linear_units)(); toolchange_settings.change_point.v = constrain(v, V_MIN_POS, V_MAX_POS); } #endif #if HAS_W_AXIS if (parser.seenval('O')) { const int16_t v = parser.TERN(AXIS9_ROTATES, value_int, value_linear_units)(); toolchange_settings.change_point.w = constrain(v, W_MIN_POS, W_MAX_POS); } #endif #endif #if HAS_Z_AXIS && HAS_TOOLCHANGE if (parser.seenval('Z')) { toolchange_settings.z_raise = parser.value_linear_units(); } #endif #if ENABLED(TOOLCHANGE_MIGRATION_FEATURE) migration.target = 0; // 0 = disabled if (parser.seenval('L')) { // Last const int16_t lval = parser.value_int(); if (WITHIN(lval, 0, EXTRUDERS - 1)) { migration.last = lval; migration.automode = (active_extruder < migration.last); } } if (parser.seen('A')) // Auto on/off migration.automode = parser.value_bool(); if (parser.seen('T')) { // Migrate now if (parser.has_value()) { const int16_t tval = parser.value_int(); if (WITHIN(tval, 0, EXTRUDERS - 1) && tval != active_extruder) { migration.target = tval + 1; extruder_migration(); migration.target = 0; // disable return; } else migration.target = 0; // disable } else { extruder_migration(); return; } } #endif M217_report(); } void GcodeSuite::M217_report(const bool forReplay/*=true*/) { TERN_(MARLIN_SMALL_BUILD, return); report_heading_etc(forReplay, F(STR_TOOL_CHANGING)); SERIAL_ECHOPGM(" M217"); #if ENABLED(TOOLCHANGE_FILAMENT_SWAP) SERIAL_ECHOPGM_P( PSTR(" S"), LINEAR_UNIT(toolchange_settings.swap_length), SP_B_STR, LINEAR_UNIT(toolchange_settings.extra_resume), SP_E_STR, LINEAR_UNIT(toolchange_settings.extra_prime), SP_P_STR, LINEAR_UNIT(toolchange_settings.prime_speed), PSTR(" G"), LINEAR_UNIT(toolchange_settings.wipe_retract), PSTR(" R"), LINEAR_UNIT(toolchange_settings.retract_speed), PSTR(" U"), LINEAR_UNIT(toolchange_settings.unretract_speed), PSTR(" F"), toolchange_settings.fan_speed, PSTR(" D"), toolchange_settings.fan_time ); #if ENABLED(TOOLCHANGE_MIGRATION_FEATURE) SERIAL_ECHOPGM(" A", migration.automode, " L", LINEAR_UNIT(migration.last)); #endif #if ENABLED(TOOLCHANGE_PARK) SERIAL_ECHOPGM(" W", LINEAR_UNIT(toolchange_settings.enable_park)); #if NUM_AXES { SERIAL_ECHOPGM_P( SP_X_STR, LINEAR_UNIT(toolchange_settings.change_point.x) #if HAS_Y_AXIS , SP_Y_STR, LINEAR_UNIT(toolchange_settings.change_point.y) #endif #if SECONDARY_AXES >= 1 , LIST_N(DOUBLE(SECONDARY_AXES) , SP_I_STR, I_AXIS_UNIT(toolchange_settings.change_point.i) , SP_J_STR, J_AXIS_UNIT(toolchange_settings.change_point.j) , SP_K_STR, K_AXIS_UNIT(toolchange_settings.change_point.k) , SP_C_STR, U_AXIS_UNIT(toolchange_settings.change_point.u) , PSTR(" H"), V_AXIS_UNIT(toolchange_settings.change_point.v) , PSTR(" O"), W_AXIS_UNIT(toolchange_settings.change_point.w) ) #endif ); } #endif #endif #if ENABLED(TOOLCHANGE_FS_PRIME_FIRST_USED) SERIAL_ECHOPGM(" V", LINEAR_UNIT(enable_first_prime)); #endif #endif SERIAL_ECHOLNPGM_P(SP_Z_STR, LINEAR_UNIT(toolchange_settings.z_raise)); } #endif // HAS_MULTI_EXTRUDER
2301_81045437/Marlin
Marlin/src/gcode/config/M217.cpp
C++
agpl-3.0
9,216
/** * Marlin 3D Printer Firmware * Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin] * * Based on Sprinter and grbl. * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <https://www.gnu.org/licenses/>. * */ #include "../../inc/MarlinConfig.h" #if HAS_HOTEND_OFFSET #include "../gcode.h" #include "../../module/motion.h" #if ENABLED(DELTA) #include "../../module/planner.h" #endif /** * M218 - set hotend offset (in linear units) * * T<tool> * X<xoffset> * Y<yoffset> * Z<zoffset> */ void GcodeSuite::M218() { if (!parser.seen_any()) return M218_report(); const int8_t target_extruder = get_target_extruder_from_command(); if (target_extruder < 0) return; #if HAS_X_AXIS if (parser.seenval('X')) hotend_offset[target_extruder].x = parser.value_linear_units(); #endif #if HAS_Y_AXIS if (parser.seenval('Y')) hotend_offset[target_extruder].y = parser.value_linear_units(); #endif #if HAS_Z_AXIS if (parser.seenval('Z')) hotend_offset[target_extruder].z = parser.value_linear_units(); #endif #if ENABLED(DELTA) if (target_extruder == active_extruder) do_blocking_move_to_xy(current_position, planner.settings.max_feedrate_mm_s[X_AXIS]); #endif } void GcodeSuite::M218_report(const bool forReplay/*=true*/) { TERN_(MARLIN_SMALL_BUILD, return); report_heading_etc(forReplay, F(STR_HOTEND_OFFSETS)); for (uint8_t e = 1; e < HOTENDS; ++e) { report_echo_start(forReplay); SERIAL_ECHOLNPGM_P( PSTR(" M218 T"), e, SP_X_STR, LINEAR_UNIT(hotend_offset[e].x), SP_Y_STR, LINEAR_UNIT(hotend_offset[e].y), SP_Z_STR, p_float_t(LINEAR_UNIT(hotend_offset[e].z), 3) ); } } #endif // HAS_HOTEND_OFFSET
2301_81045437/Marlin
Marlin/src/gcode/config/M218.cpp
C++
agpl-3.0
2,353
/** * Marlin 3D Printer Firmware * Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin] * * Based on Sprinter and grbl. * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <https://www.gnu.org/licenses/>. * */ #include "../gcode.h" #include "../../module/motion.h" /** * M220: Set speed percentage factor, aka "Feed Rate" * * Parameters * S<percent> : Set the feed rate percentage factor * * Report the current speed percentage factor if no parameter is specified * * For MMU2 and MMU2S devices... * B : Flag to back up the current factor * R : Flag to restore the last-saved factor */ void GcodeSuite::M220() { if (!parser.seen_any()) { SERIAL_ECHOLNPGM("FR:", feedrate_percentage, "%"); return; } static int16_t backup_feedrate_percentage = 100; const int16_t now_feedrate_perc = feedrate_percentage; if (parser.seen_test('R')) feedrate_percentage = backup_feedrate_percentage; if (parser.seen_test('B')) backup_feedrate_percentage = now_feedrate_perc; if (parser.seenval('S')) feedrate_percentage = parser.value_int(); }
2301_81045437/Marlin
Marlin/src/gcode/config/M220.cpp
C++
agpl-3.0
1,719
/** * Marlin 3D Printer Firmware * Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin] * * Based on Sprinter and grbl. * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <https://www.gnu.org/licenses/>. * */ #include "../gcode.h" #include "../../module/planner.h" #if HAS_EXTRUDERS /** * M221: Set extrusion percentage (M221 T0 S95) */ void GcodeSuite::M221() { const int8_t target_extruder = get_target_extruder_from_command(); if (target_extruder < 0) return; if (parser.seenval('S')) planner.set_flow(target_extruder, parser.value_int()); else { SERIAL_ECHO_START(); SERIAL_CHAR('E', '0' + target_extruder); SERIAL_ECHOPGM(" Flow: ", planner.flow_percentage[target_extruder]); SERIAL_CHAR('%'); SERIAL_EOL(); } } #endif // EXTRUDERS
2301_81045437/Marlin
Marlin/src/gcode/config/M221.cpp
C++
agpl-3.0
1,432
/** * Marlin 3D Printer Firmware * Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin] * * Based on Sprinter and grbl. * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <https://www.gnu.org/licenses/>. * */ #include "../../inc/MarlinConfig.h" #if ENABLED(EDITABLE_SERVO_ANGLES) #include "../gcode.h" #include "../../module/servo.h" /** * M281 - Edit / Report Servo Angles * * P<index> - Servo to update * L<angle> - Deploy Angle * U<angle> - Stowed Angle */ void GcodeSuite::M281() { if (!parser.seen_any()) return M281_report(); if (!parser.seenval('P')) return; const int servo_index = parser.value_int(); if (WITHIN(servo_index, 0, NUM_SERVOS - 1)) { #if ENABLED(BLTOUCH) if (servo_index == Z_PROBE_SERVO_NR) { SERIAL_ERROR_MSG("BLTouch angles can't be changed."); return; } #endif if (parser.seenval('L')) servo_angles[servo_index][0] = parser.value_int(); if (parser.seenval('U')) servo_angles[servo_index][1] = parser.value_int(); } else SERIAL_ERROR_MSG("Servo ", servo_index, " out of range"); } void GcodeSuite::M281_report(const bool forReplay/*=true*/) { TERN_(MARLIN_SMALL_BUILD, return); report_heading_etc(forReplay, F(STR_SERVO_ANGLES)); for (uint8_t i = 0; i < NUM_SERVOS; ++i) { switch (i) { default: break; #if ENABLED(SWITCHING_EXTRUDER) case SWITCHING_EXTRUDER_SERVO_NR: #if EXTRUDERS > 3 case SWITCHING_EXTRUDER_E23_SERVO_NR: #endif #elif ENABLED(SWITCHING_NOZZLE) case SWITCHING_NOZZLE_SERVO_NR: #if ENABLED(SWITCHING_NOZZLE_TWO_SERVOS) case SWITCHING_NOZZLE_E1_SERVO_NR: #endif #elif ENABLED(BLTOUCH) || (HAS_Z_SERVO_PROBE && defined(Z_SERVO_ANGLES)) case Z_PROBE_SERVO_NR: #endif report_echo_start(forReplay); SERIAL_ECHOLNPGM(" M281 P", i, " L", servo_angles[i][0], " U", servo_angles[i][1]); } } } #endif // EDITABLE_SERVO_ANGLES
2301_81045437/Marlin
Marlin/src/gcode/config/M281.cpp
C++
agpl-3.0
2,632
/** * Marlin 3D Printer Firmware * Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin] * * Based on Sprinter and grbl. * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <https://www.gnu.org/licenses/>. * */ #include "../../inc/MarlinConfig.h" #if ENABLED(PIDTEMP) #include "../gcode.h" #include "../../module/temperature.h" /** * M301: Set PID parameters P I D (and optionally C, L) * * E[extruder] Default: 0 * * P[float] Kp term * I[float] Ki term (unscaled) * D[float] Kd term (unscaled) * * With PID_EXTRUSION_SCALING: * * C[float] Kc term * L[int] LPQ length * * With PID_FAN_SCALING: * * F[float] Kf term */ void GcodeSuite::M301() { // multi-extruder PID patch: M301 updates or prints a single extruder's PID values // default behavior (omitting E parameter) is to update for extruder 0 only int8_t e = E_TERN0(parser.byteval('E', -1)); // extruder being updated if (!parser.seen("PID" TERN_(PID_EXTRUSION_SCALING, "CL") TERN_(PID_FAN_SCALING, "F"))) return M301_report(true E_OPTARG(e)); if (e == -1) e = 0; if (e < HOTENDS) { // catch bad input value if (parser.seenval('P')) SET_HOTEND_PID(Kp, e, parser.value_float()); if (parser.seenval('I')) SET_HOTEND_PID(Ki, e, parser.value_float()); if (parser.seenval('D')) SET_HOTEND_PID(Kd, e, parser.value_float()); #if ENABLED(PID_EXTRUSION_SCALING) if (parser.seenval('C')) SET_HOTEND_PID(Kc, e, parser.value_float()); if (parser.seenval('L')) thermalManager.lpq_len = parser.value_int(); LIMIT(thermalManager.lpq_len, 0, LPQ_MAX_LEN); #endif #if ENABLED(PID_FAN_SCALING) if (parser.seenval('F')) SET_HOTEND_PID(Kf, e, parser.value_float()); #endif thermalManager.updatePID(); } else SERIAL_ERROR_MSG(STR_INVALID_EXTRUDER); } void GcodeSuite::M301_report(const bool forReplay/*=true*/ E_OPTARG(const int8_t eindex/*=-1*/)) { TERN_(MARLIN_SMALL_BUILD, return); report_heading(forReplay, F(STR_HOTEND_PID)); IF_DISABLED(HAS_MULTI_EXTRUDER, constexpr int8_t eindex = -1); HOTEND_LOOP() { if (e == eindex || eindex == -1) { const hotend_pid_t &pid = thermalManager.temp_hotend[e].pid; report_echo_start(forReplay); SERIAL_ECHOPGM_P( #if ENABLED(PID_PARAMS_PER_HOTEND) PSTR(" M301 E"), e, SP_P_STR #else PSTR(" M301 P") #endif , pid.p(), PSTR(" I"), pid.i(), PSTR(" D"), pid.d() ); #if ENABLED(PID_EXTRUSION_SCALING) SERIAL_ECHOPGM_P(SP_C_STR, pid.c()); if (e == 0) SERIAL_ECHOPGM(" L", thermalManager.lpq_len); #endif #if ENABLED(PID_FAN_SCALING) SERIAL_ECHOPGM(" F", pid.f()); #endif SERIAL_EOL(); } } } #endif // PIDTEMP
2301_81045437/Marlin
Marlin/src/gcode/config/M301.cpp
C++
agpl-3.0
3,405
/** * Marlin 3D Printer Firmware * Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin] * * Based on Sprinter and grbl. * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <https://www.gnu.org/licenses/>. * */ #include "../../inc/MarlinConfig.h" #if ENABLED(PREVENT_COLD_EXTRUSION) #include "../gcode.h" #if ENABLED(EXTENSIBLE_UI) #include "../../lcd/extui/ui_api.h" #endif #include "../../module/temperature.h" /** * M302: Allow cold extrudes, or set the minimum extrude temperature * * S<temperature> sets the minimum extrude temperature * P<bool> enables (1) or disables (0) cold extrusion * * Examples: * * M302 ; report current cold extrusion state * M302 P0 ; enable cold extrusion checking * M302 P1 ; disable cold extrusion checking * M302 S0 ; always allow extrusion (disables checking) * M302 S170 ; only allow extrusion above 170 * M302 S170 P1 ; set min extrude temp to 170 but leave disabled */ void GcodeSuite::M302() { const bool seen_S = parser.seen('S'); if (seen_S) { thermalManager.extrude_min_temp = parser.value_celsius(); TERN_(EXTENSIBLE_UI, ExtUI::onSetMinExtrusionTemp(thermalManager.extrude_min_temp)); } const bool seen_P = parser.seen('P'); if (seen_P || seen_S) { thermalManager.allow_cold_extrude = (thermalManager.extrude_min_temp == 0) || (seen_P && parser.value_bool()); } else { // Report current state SERIAL_ECHO_START(); SERIAL_ECHOLN(F("Cold extrudes are "), thermalManager.allow_cold_extrude ? F("en") : F("dis"), F("abled (min temp "), thermalManager.extrude_min_temp, F("C)")); } } #endif // PREVENT_COLD_EXTRUSION
2301_81045437/Marlin
Marlin/src/gcode/config/M302.cpp
C++
agpl-3.0
2,347
/** * Marlin 3D Printer Firmware * Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin] * * Based on Sprinter and grbl. * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <https://www.gnu.org/licenses/>. * */ #include "../../inc/MarlinConfig.h" #if ENABLED(PIDTEMPBED) #include "../gcode.h" #include "../../module/temperature.h" /** * M304 - Set and/or Report the current Bed PID values * * P<pval> - Set the P value * I<ival> - Set the I value * D<dval> - Set the D value */ void GcodeSuite::M304() { if (!parser.seen("PID")) return M304_report(); if (parser.seenval('P')) thermalManager.temp_bed.pid.set_Kp(parser.value_float()); if (parser.seenval('I')) thermalManager.temp_bed.pid.set_Ki(parser.value_float()); if (parser.seenval('D')) thermalManager.temp_bed.pid.set_Kd(parser.value_float()); } void GcodeSuite::M304_report(const bool forReplay/*=true*/) { TERN_(MARLIN_SMALL_BUILD, return); report_heading_etc(forReplay, F(STR_BED_PID)); SERIAL_ECHOLNPGM(" M304" " P", thermalManager.temp_bed.pid.p() , " I", thermalManager.temp_bed.pid.i() , " D", thermalManager.temp_bed.pid.d() ); } #endif // PIDTEMPBED
2301_81045437/Marlin
Marlin/src/gcode/config/M304.cpp
C++
agpl-3.0
1,813
/** * Marlin 3D Printer Firmware * Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin] * * Based on Sprinter and grbl. * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <https://www.gnu.org/licenses/>. * */ #include "../../inc/MarlinConfig.h" #if HAS_USER_THERMISTORS #include "../gcode.h" #include "../../module/temperature.h" /** * M305: Set (or report) custom thermistor parameters * * P[index] Thermistor table index * R[ohms] Pullup resistor value * T[ohms] Resistance at 25C * B[beta] Thermistor "beta" value * C[coeff] Steinhart-Hart Coefficient 'C' * * Format: M305 P[tbl_index] R[pullup_resistor_val] T[therm_25C_resistance] B[therm_beta] C[Steinhart_Hart_C_coeff] * * Examples: M305 P0 R4700 T100000 B3950 C0.0 * M305 P0 R4700 * M305 P0 T100000 * M305 P0 B3950 * M305 P0 C0.0 */ void GcodeSuite::M305() { const int8_t t_index = parser.intval('P', -1); const bool do_set = parser.seen("BCRT"); // A valid P index is required if (t_index >= (USER_THERMISTORS) || (do_set && t_index < 0)) SERIAL_ECHO_MSG("!Invalid index. (0 <= P <= ", USER_THERMISTORS - 1, ")"); else if (do_set) { if (parser.seenval('R')) // Pullup resistor value if (!thermalManager.set_pull_up_res(t_index, parser.value_float())) SERIAL_ECHO_MSG("!Invalid series resistance. (0 < R < 1000000)"); if (parser.seenval('T')) // Resistance at 25C if (!thermalManager.set_res25(t_index, parser.value_float())) SERIAL_ECHO_MSG("!Invalid 25C resistance. (0 < T < 10000000)"); if (parser.seenval('B')) // Beta value if (!thermalManager.set_beta(t_index, parser.value_float())) SERIAL_ECHO_MSG("!Invalid beta. (0 < B < 1000000)"); if (parser.seenval('C')) // Steinhart-Hart C coefficient if (!thermalManager.set_sh_coeff(t_index, parser.value_float())) SERIAL_ECHO_MSG("!Invalid Steinhart-Hart C coeff. (-0.01 < C < +0.01)"); } // If not setting then report parameters else if (t_index < 0) { // ...all user thermistors for (uint8_t i = 0; i < USER_THERMISTORS; ++i) thermalManager.M305_report(i); } else // ...one user thermistor thermalManager.M305_report(t_index); } #endif // HAS_USER_THERMISTORS
2301_81045437/Marlin
Marlin/src/gcode/config/M305.cpp
C++
agpl-3.0
2,958
/** * Marlin 3D Printer Firmware * Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin] * * Based on Sprinter and grbl. * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <https://www.gnu.org/licenses/>. * */ #include "../../inc/MarlinConfig.h" #if ENABLED(PIDTEMPCHAMBER) #include "../gcode.h" #include "../../module/temperature.h" /** * M309 - Set and/or Report the current Chamber PID values * * P<pval> - Set the P value * I<ival> - Set the I value * D<dval> - Set the D value */ void GcodeSuite::M309() { if (!parser.seen("PID")) return M309_report(); if (parser.seenval('P')) thermalManager.temp_chamber.pid.set_Kp(parser.value_float()); if (parser.seenval('I')) thermalManager.temp_chamber.pid.set_Ki(parser.value_float()); if (parser.seenval('D')) thermalManager.temp_chamber.pid.set_Kd(parser.value_float()); } void GcodeSuite::M309_report(const bool forReplay/*=true*/) { TERN_(MARLIN_SMALL_BUILD, return); report_heading_etc(forReplay, F(STR_CHAMBER_PID)); SERIAL_ECHOLNPGM(" M309" " P", thermalManager.temp_chamber.pid.p() , " I", thermalManager.temp_chamber.pid.i() , " D", thermalManager.temp_chamber.pid.d() ); } #endif // PIDTEMPCHAMBER
2301_81045437/Marlin
Marlin/src/gcode/config/M309.cpp
C++
agpl-3.0
1,853
/** * Marlin 3D Printer Firmware * Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin] * * Based on Sprinter and grbl. * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <https://www.gnu.org/licenses/>. * */ #include "../../inc/MarlinConfig.h" #if ENABLED(PINS_DEBUGGING) #include "../gcode.h" #include "../../MarlinCore.h" // for pin_is_protected, wait_for_user #include "../../pins/pinsDebug.h" #include "../../module/endstops.h" #if HAS_Z_SERVO_PROBE #include "../../module/probe.h" #include "../../module/servo.h" #endif #if ENABLED(BLTOUCH) #include "../../feature/bltouch.h" #endif #if ENABLED(HOST_PROMPT_SUPPORT) #include "../../feature/host_actions.h" #endif #if ENABLED(EXTENSIBLE_UI) #include "../../lcd/extui/ui_api.h" #endif #if HAS_RESUME_CONTINUE #include "../../lcd/marlinui.h" #endif #ifndef GET_PIN_MAP_PIN_M43 #define GET_PIN_MAP_PIN_M43(Q) GET_PIN_MAP_PIN(Q) #endif inline void toggle_pins() { const bool ignore_protection = parser.boolval('I'); const int repeat = parser.intval('R', 1), start = PARSED_PIN_INDEX('S', 0), end = PARSED_PIN_INDEX('L', NUM_DIGITAL_PINS - 1), wait = parser.intval('W', 500); for (uint8_t i = start; i <= end; ++i) { pin_t pin = GET_PIN_MAP_PIN_M43(i); if (!VALID_PIN(pin)) continue; if (M43_NEVER_TOUCH(i) || (!ignore_protection && pin_is_protected(pin))) { report_pin_state_extended(pin, ignore_protection, true, F("Untouched ")); SERIAL_EOL(); } else { hal.watchdog_refresh(); report_pin_state_extended(pin, ignore_protection, true, F("Pulsing ")); #ifdef __STM32F1__ const auto prior_mode = _GET_MODE(i); #else const bool prior_mode = GET_PINMODE(pin); #endif #if AVR_AT90USB1286_FAMILY // Teensy IDEs don't know about these pins so must use FASTIO if (pin == TEENSY_E2) { SET_OUTPUT(TEENSY_E2); for (int16_t j = 0; j < repeat; j++) { WRITE(TEENSY_E2, LOW); safe_delay(wait); WRITE(TEENSY_E2, HIGH); safe_delay(wait); WRITE(TEENSY_E2, LOW); safe_delay(wait); } } else if (pin == TEENSY_E3) { SET_OUTPUT(TEENSY_E3); for (int16_t j = 0; j < repeat; j++) { WRITE(TEENSY_E3, LOW); safe_delay(wait); WRITE(TEENSY_E3, HIGH); safe_delay(wait); WRITE(TEENSY_E3, LOW); safe_delay(wait); } } else #endif { pinMode(pin, OUTPUT); for (int16_t j = 0; j < repeat; j++) { hal.watchdog_refresh(); extDigitalWrite(pin, 0); safe_delay(wait); hal.watchdog_refresh(); extDigitalWrite(pin, 1); safe_delay(wait); hal.watchdog_refresh(); extDigitalWrite(pin, 0); safe_delay(wait); hal.watchdog_refresh(); } } #ifdef __STM32F1__ _SET_MODE(i, prior_mode); #else pinMode(pin, prior_mode); #endif } SERIAL_EOL(); } SERIAL_ECHOLNPGM(STR_DONE); } // toggle_pins inline void servo_probe_test() { #if !HAS_SERVO_0 SERIAL_ERROR_MSG("SERVO not set up."); #elif !HAS_Z_SERVO_PROBE SERIAL_ERROR_MSG("Z_PROBE_SERVO_NR not set up."); #else // HAS_Z_SERVO_PROBE const uint8_t probe_index = parser.byteval('P', Z_PROBE_SERVO_NR); SERIAL_ECHOLNPGM("Servo probe test\n" ". using index: ", probe_index, ", deploy angle: ", servo_angles[probe_index][0], ", stow angle: ", servo_angles[probe_index][1] ); bool deploy_state = false, stow_state; #if ENABLED(Z_MIN_PROBE_USES_Z_MIN_ENDSTOP_PIN) #define PROBE_TEST_PIN Z_MIN_PIN #define _PROBE_PREF "Z_MIN" #else #define PROBE_TEST_PIN Z_MIN_PROBE_PIN #define _PROBE_PREF "Z_MIN_PROBE" #endif SERIAL_ECHOLNPGM(". Probe " _PROBE_PREF "_PIN: ", PROBE_TEST_PIN); serial_ternary(F(". " _PROBE_PREF "_ENDSTOP_HIT_STATE: "), PROBE_HIT_STATE, F("HIGH"), F("LOW")); SERIAL_EOL(); SET_INPUT_PULLUP(PROBE_TEST_PIN); // First, check for a probe that recognizes an advanced BLTouch sequence. // In addition to STOW and DEPLOY, it uses SW MODE (and RESET in the beginning) // to see if this is one of the following: BLTOUCH Classic 1.2, 1.3, or // BLTouch Smart 1.0, 2.0, 2.2, 3.0, 3.1. But only if the user has actually // configured a BLTouch as being present. If the user has not configured this, // the BLTouch will be detected in the last phase of these tests (see further on). bool blt = false; // This code will try to detect a BLTouch probe or clone #if ENABLED(BLTOUCH) SERIAL_ECHOLNPGM(". Check for BLTOUCH"); bltouch._reset(); bltouch._stow(); if (!PROBE_TRIGGERED()) { bltouch._set_SW_mode(); if (PROBE_TRIGGERED()) { bltouch._deploy(); if (!PROBE_TRIGGERED()) { bltouch._stow(); SERIAL_ECHOLNPGM("= BLTouch Classic 1.2, 1.3, Smart 1.0, 2.0, 2.2, 3.0, 3.1 detected."); // Check for a 3.1 by letting the user trigger it, later blt = true; } } } #endif // The following code is common to all kinds of servo probes. // Since it could be a real servo or a BLTouch (any kind) or a clone, // use only "common" functions - i.e. SERVO_MOVE. No bltouch.xxxx stuff. // If it is already recognised as a being a BLTouch, no need for this test if (!blt) { // DEPLOY and STOW 4 times and see if the signal follows // Then it is a mechanical switch SERIAL_ECHOLNPGM(". Deploy & stow 4 times"); for (uint8_t i = 0; i < 4; ++i) { servo[probe_index].move(servo_angles[Z_PROBE_SERVO_NR][0]); // Deploy safe_delay(500); deploy_state = READ(PROBE_TEST_PIN); servo[probe_index].move(servo_angles[Z_PROBE_SERVO_NR][1]); // Stow safe_delay(500); stow_state = READ(PROBE_TEST_PIN); } if (PROBE_HIT_STATE == deploy_state) SERIAL_ECHOLNPGM("WARNING: " _PROBE_PREF "_ENDSTOP_HIT_STATE is probably wrong."); if (deploy_state != stow_state) { SERIAL_ECHOLNPGM("= Mechanical Switch detected"); if (deploy_state) { SERIAL_ECHOLNPGM(". DEPLOYED state: HIGH (logic 1)\n" ". STOWED (triggered) state: LOW (logic 0)"); } else { SERIAL_ECHOLNPGM(". DEPLOYED state: LOW (logic 0)\n" ". STOWED (triggered) state: HIGH (logic 1)"); } #if ENABLED(BLTOUCH) SERIAL_ECHOLNPGM("FAIL: Can't enable BLTOUCH. Check your settings."); #endif return; } } // Ask the user for a trigger event and measure the pulse width. servo[probe_index].move(servo_angles[Z_PROBE_SERVO_NR][0]); // Deploy safe_delay(500); SERIAL_ECHOLNPGM("** Please trigger probe within 30 sec **"); uint16_t probe_counter = 0; // Wait 30 seconds for user to trigger probe for (uint16_t j = 0; j < 500 * 30 && probe_counter == 0 ; j++) { safe_delay(2); if (0 == j % (500 * 1)) gcode.reset_stepper_timeout(); // Keep steppers powered if (deploy_state != READ(PROBE_TEST_PIN)) { // probe triggered for (probe_counter = 0; probe_counter < 15 && deploy_state != READ(PROBE_TEST_PIN); ++probe_counter) safe_delay(2); SERIAL_ECHOPGM(". Pulse width"); if (probe_counter == 15) SERIAL_ECHOLNPGM(": 30ms or more"); else SERIAL_ECHOLNPGM(" (+/- 4ms): ", probe_counter * 2); if (probe_counter >= 4) { if (probe_counter == 15) { if (blt) SERIAL_ECHOPGM("= BLTouch V3.1"); else SERIAL_ECHOPGM("= Z Servo Probe"); } else SERIAL_ECHOPGM("= BLTouch pre V3.1 (or compatible)"); SERIAL_ECHOLNPGM(" detected."); } else SERIAL_ECHOLNPGM("FAIL: Noise detected - please re-run test"); servo[probe_index].move(servo_angles[Z_PROBE_SERVO_NR][1]); // Stow return; } } if (!probe_counter) SERIAL_ECHOLNPGM("FAIL: No trigger detected"); #endif // HAS_Z_SERVO_PROBE } // servo_probe_test /** * M43: Pin debug - report pin state, watch pins, toggle pins and servo probe test/report * * M43 - report name and state of pin(s) * P<pin> Pin to read or watch. If omitted, reads all pins. * I Flag to ignore Marlin's pin protection. * * M43 W - Watch pins -reporting changes- until reset, click, or M108. * P<pin> Pin to read or watch. If omitted, read/watch all pins. * I Flag to ignore Marlin's pin protection. * * M43 E<bool> - Enable / disable background endstop monitoring * - Machine continues to operate * - Reports changes to endstops * - Toggles LED_PIN when an endstop changes * - Cannot reliably catch the 5mS pulse from BLTouch type probes * * M43 T - Toggle pin(s) and report which pin is being toggled * S<pin> - Start Pin number. If not given, will default to 0 * L<pin> - End Pin number. If not given, will default to last pin defined for this board * I<bool> - Flag to ignore Marlin's pin protection. Use with caution!!!! * R - Repeat pulses on each pin this number of times before continuing to next pin * W - Wait time (in milliseconds) between pulses. If not given will default to 500 * * M43 S - Servo probe test * P<index> - Probe index (optional - defaults to 0 */ void GcodeSuite::M43() { // 'T' must be first. It uses 'S' and 'E' differently. if (parser.seen('T')) return toggle_pins(); // 'E' Enable or disable endstop monitoring and return if (parser.seen('E')) { endstops.monitor_flag = parser.value_bool(); SERIAL_ECHOLN(F("endstop monitor "), endstops.monitor_flag ? F("en") : F("dis"), F("abled")); return; } // 'S' Run servo probe test and return if (parser.seen('S')) return servo_probe_test(); // 'P' Get the range of pins to test or watch uint8_t first_pin = PARSED_PIN_INDEX('P', 0), last_pin = parser.seenval('L') ? PARSED_PIN_INDEX('L', 0) : (parser.seenval('P') ? first_pin : (NUMBER_PINS_TOTAL) - 1); NOMORE(first_pin, (NUMBER_PINS_TOTAL) - 1); NOMORE(last_pin, (NUMBER_PINS_TOTAL) - 1); if (first_pin > last_pin) { const uint8_t f = first_pin; first_pin = last_pin; last_pin = f; } // 'I' to ignore protected pins const bool ignore_protection = parser.boolval('I'); // 'W' Watch until click, M108, or reset if (parser.boolval('W')) { #ifdef ARDUINO_ARCH_SAM NOLESS(first_pin, 2); // Don't hijack the UART pins #endif const uint8_t pin_count = last_pin - first_pin + 1; uint8_t pin_state[pin_count]; bool can_watch = false; for (uint8_t i = first_pin; i <= last_pin; ++i) { pin_t pin = GET_PIN_MAP_PIN_M43(i); if (!VALID_PIN(pin)) continue; if (M43_NEVER_TOUCH(i) || (!ignore_protection && pin_is_protected(pin))) continue; can_watch = true; pinMode(pin, INPUT_PULLUP); delay(1); /* if (IS_ANALOG(pin)) pin_state[pin - first_pin] = analogRead(DIGITAL_PIN_TO_ANALOG_PIN(pin)); // int16_t pin_state[...] else //*/ pin_state[i - first_pin] = extDigitalRead(pin); } const bool multipin = (pin_count > 1); if (!can_watch) { SERIAL_ECHOPGM("Specified pin"); SERIAL_ECHOPGM_P(multipin ? PSTR("s are") : PSTR(" is")); SERIAL_ECHOLNPGM(" protected. Use 'I' to override."); return; } // "Watching pin(s) # - #" SERIAL_ECHOPGM("Watching pin"); if (multipin) SERIAL_CHAR('s'); SERIAL_CHAR(' '); SERIAL_ECHO(first_pin); if (multipin) SERIAL_ECHOPGM(" - ", last_pin); SERIAL_EOL(); #if HAS_RESUME_CONTINUE KEEPALIVE_STATE(PAUSED_FOR_USER); wait_for_user = true; TERN_(HOST_PROMPT_SUPPORT, hostui.continue_prompt(F("M43 Waiting..."))); #if ENABLED(EXTENSIBLE_UI) ExtUI::onUserConfirmRequired(F("M43 Waiting...")); #else LCD_MESSAGE(MSG_USERWAIT); #endif #endif for (;;) { for (uint8_t i = first_pin; i <= last_pin; ++i) { const pin_t pin = GET_PIN_MAP_PIN_M43(i); if (!VALID_PIN(pin)) continue; if (M43_NEVER_TOUCH(i) || (!ignore_protection && pin_is_protected(pin))) continue; const byte val = /* IS_ANALOG(pin) ? analogRead(DIGITAL_PIN_TO_ANALOG_PIN(pin)) : // int16_t val : //*/ extDigitalRead(pin); if (val != pin_state[i - first_pin]) { report_pin_state_extended(pin, ignore_protection, true); pin_state[i - first_pin] = val; } } #if HAS_RESUME_CONTINUE ui.update(); if (!wait_for_user) break; #endif safe_delay(200); } TERN_(HAS_RESUME_CONTINUE, ui.reset_status()); } else { // Report current state of selected pin(s) for (uint8_t i = first_pin; i <= last_pin; ++i) { const pin_t pin = GET_PIN_MAP_PIN_M43(i); if (VALID_PIN(pin)) report_pin_state_extended(pin, ignore_protection, true); } } } #endif // PINS_DEBUGGING
2301_81045437/Marlin
Marlin/src/gcode/config/M43.cpp
C++
agpl-3.0
14,119
/** * Marlin 3D Printer Firmware * Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin] * * Based on Sprinter and grbl. * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <https://www.gnu.org/licenses/>. * */ #include "../../inc/MarlinConfig.h" #if ENABLED(SD_ABORT_ON_ENDSTOP_HIT) #include "../gcode.h" #include "../../module/planner.h" /** * M540: Set whether SD card print should abort on endstop hit (M540 S<0|1>) */ void GcodeSuite::M540() { if (parser.seen('S')) planner.abort_on_endstop_hit = parser.value_bool(); } #endif // SD_ABORT_ON_ENDSTOP_HIT
2301_81045437/Marlin
Marlin/src/gcode/config/M540.cpp
C++
agpl-3.0
1,225
/** * Marlin 3D Printer Firmware * Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin] * * Based on Sprinter and grbl. * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <https://www.gnu.org/licenses/>. * */ #include "../../inc/MarlinConfig.h" #if ENABLED(BAUD_RATE_GCODE) #include "../gcode.h" /** * M575 - Change serial baud rate * * P<index> - Serial port index. Omit for all. * B<baudrate> - Baud rate (bits per second) */ void GcodeSuite::M575() { int32_t baud = parser.ulongval('B'); switch (baud) { case 24: case 96: case 192: case 384: case 576: case 1152: baud *= 100; break; case 250: case 500: baud *= 1000; break; case 19: baud = 19200; break; case 38: baud = 38400; break; case 57: baud = 57600; break; case 115: baud = 115200; break; } switch (baud) { case 2400: case 9600: case 19200: case 38400: case 57600: case 115200: case 250000: case 500000: case 1000000: { const int8_t port = parser.intval('P', -99); const bool set1 = (port == -99 || port == 0); if (set1) SERIAL_ECHO_MSG(" Serial ", AS_DIGIT(0), " baud rate set to ", baud); #if HAS_MULTI_SERIAL const bool set2 = (port == -99 || port == 1); if (set2) SERIAL_ECHO_MSG(" Serial ", AS_DIGIT(1), " baud rate set to ", baud); #ifdef SERIAL_PORT_3 const bool set3 = (port == -99 || port == 2); if (set3) SERIAL_ECHO_MSG(" Serial ", AS_DIGIT(2), " baud rate set to ", baud); #endif #endif SERIAL_FLUSH(); if (set1) { MYSERIAL1.end(); MYSERIAL1.begin(baud); } #if HAS_MULTI_SERIAL if (set2) { MYSERIAL2.end(); MYSERIAL2.begin(baud); } #ifdef SERIAL_PORT_3 if (set3) { MYSERIAL3.end(); MYSERIAL3.begin(baud); } #endif #endif } break; default: SERIAL_ECHO_MSG("?(B)aud rate implausible."); } } #endif // BAUD_RATE_GCODE
2301_81045437/Marlin
Marlin/src/gcode/config/M575.cpp
C++
agpl-3.0
2,590
/** * Marlin 3D Printer Firmware * Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin] * * Based on Sprinter and grbl. * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <https://www.gnu.org/licenses/>. * */ #include "../../inc/MarlinConfig.h" #if ENABLED(DUET_SMART_EFFECTOR) && PIN_EXISTS(SMART_EFFECTOR_MOD) #include "../gcode.h" #include "../../HAL/shared/Delay.h" #include "../parser.h" /** * The Marlin format for the M672 command is different than shown in the Duet Smart Effector * documentation https://duet3d.dozuki.com/Wiki/Smart_effector_and_carriage_adapters_for_delta_printer * * To set custom sensitivity: * Duet: M672 S105:aaa:bbb * Marlin: M672 Saaa * * (where aaa is the desired sensitivity and bbb is 255 - aaa). * * Revert sensitivity to factory settings: * Duet: M672 S105:131:131 * Marlin: M672 R */ #define M672_PROGBYTE 105 // magic byte to start programming custom sensitivity #define M672_ERASEBYTE 131 // magic byte to clear custom sensitivity // // Smart Effector byte send protocol: // // 0 0 1 0 ... always 0010 // b7 b6 b5 b4 ~b4 ... hi bits, NOT last bit // b3 b2 b1 b0 ~b0 ... lo bits, NOT last bit // void M672_send(uint8_t b) { // bit rate requirement: 1kHz +/- 30% for (uint8_t bits = 0; bits < 14; ++bits) { switch (bits) { default: { OUT_WRITE(SMART_EFFECTOR_MOD_PIN, !!(b & 0x80)); b <<= 1; break; } // send bit, shift next into place case 7: case 12: { OUT_WRITE(SMART_EFFECTOR_MOD_PIN, !!(b & 0x80)); break; } // send bit. no shift case 8: case 13: { OUT_WRITE(SMART_EFFECTOR_MOD_PIN, !(b & 0x80)); b <<= 1; break; } // send inverted previous bit case 0: case 1: // 00 case 3: { OUT_WRITE(SMART_EFFECTOR_MOD_PIN, LOW); break; } // 0010 case 2: { OUT_WRITE(SMART_EFFECTOR_MOD_PIN, HIGH); break; } // 001 } DELAY_US(1000); } } /** * M672 - Set/reset Duet Smart Effector sensitivity * * One of these is required: * S<sensitivity> - 0-255 * R - Flag to reset sensitivity to default */ void GcodeSuite::M672() { if (parser.seen('R')) { M672_send(M672_ERASEBYTE); M672_send(M672_ERASEBYTE); } else if (parser.seenval('S')) { const int8_t M672_sensitivity = parser.value_byte(); M672_send(M672_PROGBYTE); M672_send(M672_sensitivity); M672_send(255 - M672_sensitivity); } else { SERIAL_ECHO_MSG("!'S' or 'R' parameter required."); return; } OUT_WRITE(SMART_EFFECTOR_MOD_PIN, LOW); // Keep Smart Effector in NORMAL mode } #endif // DUET_SMART_EFFECTOR && SMART_EFFECTOR_MOD_PIN
2301_81045437/Marlin
Marlin/src/gcode/config/M672.cpp
C++
agpl-3.0
3,342
/** * Marlin 3D Printer Firmware * Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin] * * Based on Sprinter and grbl. * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <https://www.gnu.org/licenses/>. * */ #include "../../inc/MarlinConfigPre.h" #if ENABLED(EDITABLE_STEPS_PER_UNIT) #include "../gcode.h" #include "../../module/planner.h" /** * M92: Set axis steps-per-unit for one or more axes, X, Y, Z, [I, [J, [K, [U, [V, [W,]]]]]] and E. * (Follows the same syntax as G92) * * With multiple extruders use T to specify which one. * * If no argument is given print the current values. * * With MAGIC_NUMBERS_GCODE: * * Use 'H' and/or 'L' to get ideal layer-height information. * H<microsteps> - Specify micro-steps to use. Best guess if not supplied. * L<linear> - Desired layer height in current units. Nearest good heights are shown. */ void GcodeSuite::M92() { const int8_t target_extruder = get_target_extruder_from_command(); if (target_extruder < 0) return; // No arguments? Show M92 report. if (!parser.seen(STR_AXES_LOGICAL TERN_(MAGIC_NUMBERS_GCODE, "HL"))) return M92_report(true, target_extruder); LOOP_LOGICAL_AXES(i) { if (parser.seenval(AXIS_CHAR(i))) { if (TERN1(HAS_EXTRUDERS, i != E_AXIS)) planner.settings.axis_steps_per_mm[i] = parser.value_per_axis_units((AxisEnum)i); else { #if HAS_EXTRUDERS const float value = parser.value_per_axis_units((AxisEnum)(E_AXIS_N(target_extruder))); if (value < 20) { float factor = planner.settings.axis_steps_per_mm[E_AXIS_N(target_extruder)] / value; // increase e constants if M92 E14 is given for netfab. #if ALL(CLASSIC_JERK, HAS_CLASSIC_E_JERK) planner.max_jerk.e *= factor; #endif planner.settings.max_feedrate_mm_s[E_AXIS_N(target_extruder)] *= factor; planner.max_acceleration_steps_per_s2[E_AXIS_N(target_extruder)] *= factor; } planner.settings.axis_steps_per_mm[E_AXIS_N(target_extruder)] = value; #endif } } } planner.refresh_positioning(); #if ENABLED(MAGIC_NUMBERS_GCODE) #ifndef Z_MICROSTEPS #define Z_MICROSTEPS 16 #endif const float wanted = parser.linearval('L'); if (parser.seen('H') || wanted) { const uint16_t argH = parser.ushortval('H'), micro_steps = argH ?: Z_MICROSTEPS; const float z_full_step_mm = micro_steps * planner.mm_per_step[Z_AXIS]; SERIAL_ECHO_START(); SERIAL_ECHOPGM("{ micro_steps:", micro_steps, ", z_full_step_mm:", z_full_step_mm); if (wanted) { const float best = uint16_t(wanted / z_full_step_mm) * z_full_step_mm; SERIAL_ECHOPGM(", best:[", best); if (best != wanted) { SERIAL_ECHO(C(','), best + z_full_step_mm); } SERIAL_CHAR(']'); } SERIAL_ECHOLNPGM(" }"); } #endif } void GcodeSuite::M92_report(const bool forReplay/*=true*/, const int8_t e/*=-1*/) { TERN_(MARLIN_SMALL_BUILD, return); report_heading_etc(forReplay, F(STR_STEPS_PER_UNIT)); #if NUM_AXES #define PRINT_EOL SERIAL_ECHOPGM_P(LIST_N(DOUBLE(NUM_AXES), PSTR(" M92 X"), LINEAR_UNIT(planner.settings.axis_steps_per_mm[X_AXIS]), SP_Y_STR, LINEAR_UNIT(planner.settings.axis_steps_per_mm[Y_AXIS]), SP_Z_STR, LINEAR_UNIT(planner.settings.axis_steps_per_mm[Z_AXIS]), SP_I_STR, I_AXIS_UNIT(planner.settings.axis_steps_per_mm[I_AXIS]), SP_J_STR, J_AXIS_UNIT(planner.settings.axis_steps_per_mm[J_AXIS]), SP_K_STR, K_AXIS_UNIT(planner.settings.axis_steps_per_mm[K_AXIS]), SP_U_STR, U_AXIS_UNIT(planner.settings.axis_steps_per_mm[U_AXIS]), SP_V_STR, V_AXIS_UNIT(planner.settings.axis_steps_per_mm[V_AXIS]), SP_W_STR, W_AXIS_UNIT(planner.settings.axis_steps_per_mm[W_AXIS]) )); #endif #if HAS_EXTRUDERS && DISABLED(DISTINCT_E_FACTORS) #define PRINT_EOL SERIAL_ECHOPGM_P(SP_E_STR, VOLUMETRIC_UNIT(planner.settings.axis_steps_per_mm[E_AXIS])); #endif if (ENABLED(PRINT_EOL)) SERIAL_EOL(); #if ENABLED(DISTINCT_E_FACTORS) for (uint8_t i = 0; i < E_STEPPERS; ++i) { if (e >= 0 && i != e) continue; report_echo_start(forReplay); SERIAL_ECHOLNPGM_P( PSTR(" M92 T"), i, SP_E_STR, VOLUMETRIC_UNIT(planner.settings.axis_steps_per_mm[E_AXIS_N(i)]) ); } #else UNUSED(e); #endif } #endif // EDITABLE_STEPS_PER_UNIT
2301_81045437/Marlin
Marlin/src/gcode/config/M92.cpp
C++
agpl-3.0
5,118
/** * Marlin 3D Printer Firmware * Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin] * * Based on Sprinter and grbl. * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <https://www.gnu.org/licenses/>. * */ #include "../../inc/MarlinConfig.h" #if DISABLED(EMERGENCY_PARSER) #include "../gcode.h" #include "../../MarlinCore.h" // for wait_for_heatup, kill, M112_KILL_STR #include "../../module/motion.h" // for quickstop_stepper /** * M108: Stop the waiting for heaters in M109, M190, M303. Does not affect the target temperature. */ void GcodeSuite::M108() { TERN_(HAS_RESUME_CONTINUE, wait_for_user = false); wait_for_heatup = false; } /** * M112: Full Shutdown */ void GcodeSuite::M112() { kill(FPSTR(M112_KILL_STR), nullptr, true); } /** * M410: Quickstop - Abort all planned moves * * This will stop the carriages mid-move, so most likely they * will be out of sync with the stepper position after this. */ void GcodeSuite::M410() { quickstop_stepper(); } #endif // !EMERGENCY_PARSER
2301_81045437/Marlin
Marlin/src/gcode/control/M108_M112_M410.cpp
C++
agpl-3.0
1,667
/** * Marlin 3D Printer Firmware * Copyright (c) 2021 MarlinFirmware [https://github.com/MarlinFirmware/Marlin] * * Based on Sprinter and grbl. * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <https://www.gnu.org/licenses/>. * */ /** * gcode/control/M10_M11.cpp * Air Evacuation */ #include "../../inc/MarlinConfig.h" #if ENABLED(AIR_EVACUATION) #include "../gcode.h" #include "../../feature/spindle_laser.h" /** * M10: Vacuum or Blower On */ void GcodeSuite::M10() { cutter.air_evac_enable(); // Turn on Vacuum or Blower motor } /** * M11: Vacuum or Blower OFF */ void GcodeSuite::M11() { cutter.air_evac_disable(); // Turn off Vacuum or Blower motor } #endif // AIR_EVACUATION
2301_81045437/Marlin
Marlin/src/gcode/control/M10_M11.cpp
C++
agpl-3.0
1,332
/** * Marlin 3D Printer Firmware * Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin] * * Based on Sprinter and grbl. * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <https://www.gnu.org/licenses/>. * */ #include "../../inc/MarlinConfig.h" #include "../gcode.h" /** * M111: Set the debug level */ void GcodeSuite::M111() { if (parser.seenval('S')) marlin_debug_flags = parser.value_byte(); #if ENABLED(DEBUG_FLAGS_GCODE) static PGMSTR(str_debug_1, STR_DEBUG_ECHO); static PGMSTR(str_debug_2, STR_DEBUG_INFO); static PGMSTR(str_debug_4, STR_DEBUG_ERRORS); #endif static PGMSTR(str_debug_8, STR_DEBUG_DRYRUN); #if ENABLED(DEBUG_FLAGS_GCODE) static PGMSTR(str_debug_16, STR_DEBUG_COMMUNICATION); #endif #if ENABLED(DEBUG_LEVELING_FEATURE) static PGMSTR(str_debug_detail, STR_DEBUG_DETAIL); #endif static PGM_P const debug_strings[] PROGMEM = { TERN(DEBUG_FLAGS_GCODE, str_debug_1, nullptr), TERN(DEBUG_FLAGS_GCODE, str_debug_2, nullptr), TERN(DEBUG_FLAGS_GCODE, str_debug_4, nullptr), str_debug_8, TERN(DEBUG_FLAGS_GCODE, str_debug_16, nullptr), TERN_(DEBUG_LEVELING_FEATURE, str_debug_detail) }; SERIAL_ECHO_START(); SERIAL_ECHOPGM(STR_DEBUG_PREFIX); if (marlin_debug_flags) { uint8_t comma = 0; for (uint8_t i = 0; i < COUNT(debug_strings); ++i) { PGM_P const pstr = (PGM_P)pgm_read_ptr(&debug_strings[i]); if (pstr && TEST(marlin_debug_flags, i)) { if (comma++) SERIAL_CHAR(','); SERIAL_ECHOPGM_P(pstr); } } } else { SERIAL_ECHOPGM(STR_DEBUG_OFF); #if !(defined(__AVR__) && defined(USBCON)) #if ENABLED(SERIAL_STATS_RX_BUFFER_OVERRUNS) SERIAL_ECHOPGM("\nBuffer Overruns: ", MYSERIAL1.buffer_overruns()); #endif #if ENABLED(SERIAL_STATS_RX_FRAMING_ERRORS) SERIAL_ECHOPGM("\nFraming Errors: ", MYSERIAL1.framing_errors()); #endif #if ENABLED(SERIAL_STATS_DROPPED_RX) SERIAL_ECHOPGM("\nDropped bytes: ", MYSERIAL1.dropped()); #endif #if ENABLED(SERIAL_STATS_MAX_RX_QUEUED) SERIAL_ECHOPGM("\nMax RX Queue Size: ", MYSERIAL1.rxMaxEnqueued()); #endif #endif // !(__AVR__ && USBCON) } SERIAL_EOL(); }
2301_81045437/Marlin
Marlin/src/gcode/control/M111.cpp
C++
agpl-3.0
2,874
/** * Marlin 3D Printer Firmware * Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin] * * Based on Sprinter and grbl. * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <https://www.gnu.org/licenses/>. * */ #include "../gcode.h" #include "../../module/endstops.h" /** * M120: Enable endstops and set non-homing endstop state to "enabled" */ void GcodeSuite::M120() { endstops.enable_globally(true); } /** * M121: Disable endstops and set non-homing endstop state to "disabled" */ void GcodeSuite::M121() { endstops.enable_globally(false); }
2301_81045437/Marlin
Marlin/src/gcode/control/M120_M121.cpp
C++
agpl-3.0
1,203
/** * Marlin 3D Printer Firmware * Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin] * * Based on Sprinter and grbl. * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <https://www.gnu.org/licenses/>. * */ #include "../gcode.h" #include "../../MarlinCore.h" // for stepper_inactive_time, disable_e_steppers #include "../../lcd/marlinui.h" #include "../../module/motion.h" // for e_axis_mask #include "../../module/planner.h" #include "../../module/stepper.h" #if ENABLED(AUTO_BED_LEVELING_UBL) #include "../../feature/bedlevel/bedlevel.h" #endif #define DEBUG_OUT ENABLED(MARLIN_DEV_MODE) #include "../../core/debug_out.h" #include "../../libs/hex_print.h" inline stepper_flags_t selected_axis_bits() { stepper_flags_t selected{0}; #if HAS_EXTRUDERS if (parser.seen('E')) { if (E_TERN0(parser.has_value())) { const uint8_t e = parser.value_int(); if (e < EXTRUDERS) selected.bits = _BV(INDEX_OF_AXIS(E_AXIS, e)); } else selected.bits = e_axis_mask; } #endif #if NUM_AXES selected.bits |= NUM_AXIS_GANG( (parser.seen_test('X') << X_AXIS), | (parser.seen_test('Y') << Y_AXIS), | (parser.seen_test('Z') << Z_AXIS), | (parser.seen_test(AXIS4_NAME) << I_AXIS), | (parser.seen_test(AXIS5_NAME) << J_AXIS), | (parser.seen_test(AXIS6_NAME) << K_AXIS), | (parser.seen_test(AXIS7_NAME) << U_AXIS), | (parser.seen_test(AXIS8_NAME) << V_AXIS), | (parser.seen_test(AXIS9_NAME) << W_AXIS) ); #endif return selected; } // Enable specified axes and warn about other affected axes void do_enable(const stepper_flags_t to_enable) { const ena_mask_t was_enabled = stepper.axis_enabled.bits, shall_enable = to_enable.bits & ~was_enabled; DEBUG_ECHOLNPGM("Now Enabled: ", hex_word(stepper.axis_enabled.bits), " Enabling: ", hex_word(to_enable.bits), " | ", shall_enable); if (!shall_enable) return; // All specified axes already enabled? ena_mask_t also_enabled = 0; // Track steppers enabled due to overlap // Enable all flagged axes LOOP_NUM_AXES(a) { if (TEST(shall_enable, a)) { stepper.enable_axis(AxisEnum(a)); // Mark and enable the requested axis DEBUG_ECHOLNPGM("Enabled ", AXIS_CHAR(a), " (", a, ") with overlap ", hex_word(enable_overlap[a]), " ... Enabled: ", hex_word(stepper.axis_enabled.bits)); also_enabled |= enable_overlap[a]; } } #if HAS_EXTRUDERS EXTRUDER_LOOP() { const uint8_t a = INDEX_OF_AXIS(E_AXIS, e); if (TEST(shall_enable, a)) { stepper.ENABLE_EXTRUDER(e); DEBUG_ECHOLNPGM("Enabled E", AS_DIGIT(e), " (", a, ") with overlap ", hex_word(enable_overlap[a]), " ... ", hex_word(stepper.axis_enabled.bits)); also_enabled |= enable_overlap[a]; } } #endif if ((also_enabled &= ~(shall_enable | was_enabled))) { SERIAL_CHAR('('); LOOP_NUM_AXES(a) if (TEST(also_enabled, a)) SERIAL_CHAR(AXIS_CHAR(a), ' '); #if HAS_EXTRUDERS #define _EN_ALSO(N) if (TEST(also_enabled, INDEX_OF_AXIS(E_AXIS, N))) SERIAL_CHAR('E', '0' + N, ' '); REPEAT(EXTRUDERS, _EN_ALSO) #endif SERIAL_ECHOLNPGM("also enabled)"); } DEBUG_ECHOLNPGM("Enabled Now: ", hex_word(stepper.axis_enabled.bits)); } /** * M17: Enable stepper motor power for one or more axes. * Print warnings for axes that share an ENABLE_PIN. * * Examples: * * M17 XZ ; Enable X and Z axes * M17 E ; Enable all E steppers * M17 E1 ; Enable just the E1 stepper */ void GcodeSuite::M17() { if (parser.seen_axis()) { if (any_enable_overlap()) do_enable(selected_axis_bits()); else { #if HAS_EXTRUDERS if (parser.seen('E')) { if (parser.has_value()) { const uint8_t e = parser.value_int(); if (e < EXTRUDERS) stepper.ENABLE_EXTRUDER(e); } else stepper.enable_e_steppers(); } #endif LOOP_NUM_AXES(a) if (parser.seen_test(AXIS_CHAR(a))) stepper.enable_axis((AxisEnum)a); } } else { LCD_MESSAGE(MSG_NO_MOVE); stepper.enable_all_steppers(); } } void try_to_disable(const stepper_flags_t to_disable) { ena_mask_t still_enabled = to_disable.bits & stepper.axis_enabled.bits; DEBUG_ECHOLNPGM("Enabled: ", hex_word(stepper.axis_enabled.bits), " To Disable: ", hex_word(to_disable.bits), " | ", hex_word(still_enabled)); if (!still_enabled) return; // Attempt to disable all flagged axes LOOP_NUM_AXES(a) if (TEST(to_disable.bits, a)) { DEBUG_ECHOPGM("Try to disable ", AXIS_CHAR(a), " (", a, ") with overlap ", hex_word(enable_overlap[a]), " ... "); if (stepper.disable_axis(AxisEnum(a))) { // Mark the requested axis and request to disable DEBUG_ECHOPGM("OK"); still_enabled &= ~(_BV(a) | enable_overlap[a]); // If actually disabled, clear one or more tracked bits } else DEBUG_ECHOPGM("OVERLAP"); DEBUG_ECHOLNPGM(" ... still_enabled=", hex_word(still_enabled)); } #if HAS_EXTRUDERS EXTRUDER_LOOP() { const uint8_t a = INDEX_OF_AXIS(E_AXIS, e); if (TEST(to_disable.bits, a)) { DEBUG_ECHOPGM("Try to disable E", AS_DIGIT(e), " (", a, ") with overlap ", hex_word(enable_overlap[a]), " ... "); if (stepper.DISABLE_EXTRUDER(e)) { DEBUG_ECHOPGM("OK"); still_enabled &= ~(_BV(a) | enable_overlap[a]); } else DEBUG_ECHOPGM("OVERLAP"); DEBUG_ECHOLNPGM(" ... still_enabled=", hex_word(still_enabled)); } } #endif auto overlap_warning = [](const ena_mask_t axis_bits) { SERIAL_ECHOPGM(" not disabled. Shared with"); LOOP_NUM_AXES(a) if (TEST(axis_bits, a)) SERIAL_ECHOPGM_P((PGM_P)pgm_read_ptr(&SP_AXIS_STR[a])); #if HAS_EXTRUDERS #define _EN_STILLON(N) if (TEST(axis_bits, INDEX_OF_AXIS(E_AXIS, N))) SERIAL_CHAR(' ', 'E', '0' + N); REPEAT(EXTRUDERS, _EN_STILLON) #endif SERIAL_ECHOLNPGM("."); }; // If any of the requested axes are still enabled, give a warning LOOP_NUM_AXES(a) { if (TEST(still_enabled, a)) { SERIAL_CHAR(AXIS_CHAR(a)); overlap_warning(stepper.axis_enabled.bits & enable_overlap[a]); } } #if HAS_EXTRUDERS EXTRUDER_LOOP() { const uint8_t a = INDEX_OF_AXIS(E_AXIS, e); if (TEST(still_enabled, a)) { SERIAL_CHAR('E', '0' + e); overlap_warning(stepper.axis_enabled.bits & enable_overlap[a]); } } #endif DEBUG_ECHOLNPGM("Enabled Now: ", hex_word(stepper.axis_enabled.bits)); } /** * M18, M84: Disable stepper motor power for one or more axes. * Print warnings for axes that share an ENABLE_PIN. */ void GcodeSuite::M18_M84() { if (parser.seenval('S')) { reset_stepper_timeout(); #if HAS_DISABLE_IDLE_AXES const millis_t ms = parser.value_millis_from_seconds(); #if LASER_SAFETY_TIMEOUT_MS > 0 if (ms && ms <= LASER_SAFETY_TIMEOUT_MS) { SERIAL_ECHO_MSG("M18 timeout must be > ", MS_TO_SEC(LASER_SAFETY_TIMEOUT_MS + 999), " s for laser safety."); return; } #endif stepper_inactive_time = ms; #endif } else { if (parser.seen_axis()) { planner.synchronize(); if (any_enable_overlap()) try_to_disable(selected_axis_bits()); else { #if HAS_EXTRUDERS if (parser.seen('E')) { if (E_TERN0(parser.has_value())) stepper.DISABLE_EXTRUDER(parser.value_int()); else stepper.disable_e_steppers(); } #endif LOOP_NUM_AXES(a) if (parser.seen_test(AXIS_CHAR(a))) stepper.disable_axis((AxisEnum)a); } } else planner.finish_and_disable(); TERN_(AUTO_BED_LEVELING_UBL, bedlevel.steppers_were_disabled()); } }
2301_81045437/Marlin
Marlin/src/gcode/control/M17_M18_M84.cpp
C++
agpl-3.0
8,528
/** * Marlin 3D Printer Firmware * Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin] * * Based on Sprinter and grbl. * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <https://www.gnu.org/licenses/>. * */ #include "../../inc/MarlinConfigPre.h" #if HAS_SOFTWARE_ENDSTOPS #include "../gcode.h" #include "../../module/motion.h" /** * M211: Enable, Disable, and/or Report software endstops * * Usage: M211 S1 to enable, M211 S0 to disable, M211 alone for report */ void GcodeSuite::M211() { if (parser.seen('S')) soft_endstop._enabled = parser.value_bool(); else M211_report(); } void GcodeSuite::M211_report(const bool forReplay/*=true*/) { TERN_(MARLIN_SMALL_BUILD, return); report_heading_etc(forReplay, F(STR_SOFT_ENDSTOPS)); SERIAL_ECHOPGM(" M211 S", AS_DIGIT(soft_endstop._enabled), " ; "); serialprintln_onoff(soft_endstop._enabled); report_echo_start(forReplay); const xyz_pos_t l_soft_min = soft_endstop.min.asLogical(), l_soft_max = soft_endstop.max.asLogical(); print_xyz(l_soft_min, F(STR_SOFT_MIN), F(" ")); print_xyz(l_soft_max, F(STR_SOFT_MAX)); } #endif // HAS_SOFTWARE_ENDSTOPS
2301_81045437/Marlin
Marlin/src/gcode/control/M211.cpp
C++
agpl-3.0
1,807
/** * Marlin 3D Printer Firmware * Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin] * * Based on Sprinter and grbl. * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <https://www.gnu.org/licenses/>. * */ #include "../../inc/MarlinConfig.h" #if ENABLED(DIRECT_PIN_CONTROL) #include "../gcode.h" #include "../../MarlinCore.h" // for pin_is_protected and idle() #include "../../module/planner.h" void protected_pin_err(); /** * M226: Wait until the specified pin reaches the state required (M226 P<pin> S<state>) */ void GcodeSuite::M226() { if (parser.seen('P')) { const int pin_number = PARSED_PIN_INDEX('P', 0), pin_state = parser.intval('S', -1); // required pin state - default is inverted const pin_t pin = GET_PIN_MAP_PIN(pin_number); if (WITHIN(pin_state, -1, 1) && pin > -1) { if (pin_is_protected(pin)) protected_pin_err(); else { int target = LOW; planner.synchronize(); pinMode(pin, INPUT); switch (pin_state) { case 1: target = HIGH; break; case 0: target = LOW; break; case -1: target = !extDigitalRead(pin); break; } while (int(extDigitalRead(pin)) != target) idle(); } } // pin_state -1 0 1 && pin > -1 } // parser.seen('P') } #endif // DIRECT_PIN_CONTROL
2301_81045437/Marlin
Marlin/src/gcode/control/M226.cpp
C++
agpl-3.0
1,974
/** * Marlin 3D Printer Firmware * Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin] * * Based on Sprinter and grbl. * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <https://www.gnu.org/licenses/>. * */ #include "../../inc/MarlinConfig.h" #if HAS_SERVOS #include "../gcode.h" #include "../../module/servo.h" #include "../../module/planner.h" /** * M280: Get or set servo position. * P<index> - Servo index * S<angle> - Angle to set, omit to read current angle, or use -1 to detach * * With POLARGRAPH: * T<ms> - Duration of servo move */ void GcodeSuite::M280() { if (!parser.seenval('P')) return; TERN_(POLARGRAPH, planner.synchronize()); const int servo_index = parser.value_int(); if (WITHIN(servo_index, 0, NUM_SERVOS - 1)) { if (parser.seenval('S')) { const int anew = parser.value_int(); if (anew >= 0) { #if ENABLED(POLARGRAPH) if (parser.seenval('T')) { // (ms) Total duration of servo move const int16_t t = constrain(parser.value_int(), 0, 10000); const int aold = servo[servo_index].read(); millis_t now = millis(); const millis_t start = now, end = start + t; while (PENDING(now, end)) { safe_delay(50); now = _MIN(millis(), end); servo[servo_index].move(LROUND(aold + (anew - aold) * (float(now - start) / t))); } } #endif // POLARGRAPH servo[servo_index].move(anew); } else servo[servo_index].detach(); } else SERIAL_ECHO_MSG(" Servo ", servo_index, ": ", servo[servo_index].read()); } else SERIAL_ERROR_MSG("Servo ", servo_index, " out of range"); } #endif // HAS_SERVOS
2301_81045437/Marlin
Marlin/src/gcode/control/M280.cpp
C++
agpl-3.0
2,391
/** * Marlin 3D Printer Firmware * Copyright (c) 2021 MarlinFirmware [https://github.com/MarlinFirmware/Marlin] * * Based on Sprinter and grbl. * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <https://www.gnu.org/licenses/>. * */ #include "../../inc/MarlinConfig.h" #if ENABLED(SERVO_DETACH_GCODE) #include "../gcode.h" #include "../../module/servo.h" /** * M282: Detach Servo. P<index> */ void GcodeSuite::M282() { if (!parser.seenval('P')) return; const int servo_index = parser.value_int(); if (WITHIN(servo_index, 0, NUM_SERVOS - 1)) servo[servo_index].detach(); else SERIAL_ECHO_MSG("Servo ", servo_index, " out of range"); } #endif // SERVO_DETACH_GCODE
2301_81045437/Marlin
Marlin/src/gcode/control/M282.cpp
C++
agpl-3.0
1,318
/** * Marlin 3D Printer Firmware * Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin] * * Based on Sprinter and grbl. * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <https://www.gnu.org/licenses/>. * */ #include "../../inc/MarlinConfig.h" #if HAS_CUTTER #include "../gcode.h" #include "../../feature/spindle_laser.h" #include "../../module/planner.h" /** * Laser: * M3 - Laser ON/Power (Ramped power) * M4 - Laser ON/Power (Ramped power) * * M3I - Enable continuous inline power to be processed by the planner, with power * calculated and set in the planner blocks, processed inline during stepping. * In inline mode M3 S-Values will set the power for the next moves. * (e.g., G1 X10 Y10 powers on with the last S-Value.) * M3I must be set before using planner-synced M3 inline S-Values (LASER_POWER_SYNC). * * M4I - Set dynamic mode which calculates laser power OCR based on the current feedrate. * * Spindle: * M3 - Spindle ON (Clockwise) * M4 - Spindle ON (Counter-clockwise) * * Parameters: * S<power> - Set power. S0 will turn the spindle/laser off. * * If no PWM pin is defined then M3/M4 just turns it on or off. * * At least 12.8kHz (50Hz * 256) is needed for Spindle PWM. * Hardware PWM is required on AVR. ISRs are too slow. * * NOTE: WGM for timers 3, 4, and 5 must be either Mode 1 or Mode 5. * No other settings give a PWM signal that goes from 0 to 5 volts. * * The system automatically sets WGM to Mode 1, so no special * initialization is needed. * * WGM bits for timer 2 are automatically set by the system to * Mode 1. This produces an acceptable 0 to 5 volt signal. * No special initialization is needed. * * NOTE: A minimum PWM frequency of 50 Hz is needed. All prescaler * factors for timers 2, 3, 4, and 5 are acceptable. * * SPINDLE_LASER_ENA_PIN needs an external pullup or it may power on * the spindle/laser during power-up or when connecting to the host * (usually goes through a reset which sets all I/O pins to tri-state) * * PWM duty cycle goes from 0 (off) to 255 (always on). */ void GcodeSuite::M3_M4(const bool is_M4) { #if LASER_SAFETY_TIMEOUT_MS > 0 reset_stepper_timeout(); // Reset timeout to allow subsequent G-code to power the laser (imm.) #endif if (cutter.cutter_mode == CUTTER_MODE_STANDARD) planner.synchronize(); // Wait for previous movement commands (G0/G1/G2/G3) to complete before changing power #if ENABLED(LASER_FEATURE) if (parser.seen_test('I')) { cutter.cutter_mode = is_M4 ? CUTTER_MODE_DYNAMIC : CUTTER_MODE_CONTINUOUS; cutter.inline_power(0); cutter.set_enabled(true); } #endif auto get_s_power = [] { if (parser.seenval('S')) { const float v = parser.value_float(); cutter.menuPower = cutter.unitPower = TERN(LASER_POWER_TRAP, v, cutter.power_to_range(v)); } else if (cutter.cutter_mode == CUTTER_MODE_STANDARD) cutter.menuPower = cutter.unitPower = cutter.cpwr_to_upwr(SPEED_POWER_STARTUP); // PWM not implied, power converted to OCR from unit definition and on/off if not PWM. cutter.power = TERN(SPINDLE_LASER_USE_PWM, cutter.upower_to_ocr(cutter.unitPower), cutter.unitPower > 0 ? 255 : 0); }; if (cutter.cutter_mode == CUTTER_MODE_CONTINUOUS || cutter.cutter_mode == CUTTER_MODE_DYNAMIC) { // Laser power in inline mode #if ENABLED(LASER_FEATURE) planner.laser_inline.status.isPowered = true; // M3 or M4 is powered either way get_s_power(); // Update cutter.power if seen #if ENABLED(LASER_POWER_SYNC) // With power sync we only set power so it does not effect queued inline power sets planner.buffer_sync_block(BLOCK_BIT_LASER_PWR); // Send the flag, queueing inline power #else planner.synchronize(); cutter.inline_power(cutter.power); #endif #endif } else { cutter.set_enabled(true); get_s_power(); cutter.apply_power( #if ENABLED(SPINDLE_SERVO) cutter.unitPower #elif ENABLED(SPINDLE_LASER_USE_PWM) cutter.upower_to_ocr(cutter.unitPower) #else cutter.unitPower > 0 ? 255 : 0 #endif ); TERN_(SPINDLE_CHANGE_DIR, cutter.set_reverse(is_M4)); } } /** * M5 - Cutter OFF (when moves are complete) * * Laser: * M5 - Set power output to 0 (leaving inline mode unchanged). * M5I - Clear inline mode and set power to 0. * * Spindle: * M5 - Spindle OFF */ void GcodeSuite::M5() { planner.synchronize(); cutter.power = 0; cutter.apply_power(0); // M5 just kills power, leaving inline mode unchanged if (cutter.cutter_mode != CUTTER_MODE_STANDARD) { if (parser.seen_test('I')) { TERN_(LASER_FEATURE, cutter.inline_power(cutter.power)); cutter.set_enabled(false); // Needs to happen while we are in inline mode to clear inline power. cutter.cutter_mode = CUTTER_MODE_STANDARD; // Switch from inline to standard mode. } } cutter.set_enabled(false); // Disable enable output setting } #endif // HAS_CUTTER
2301_81045437/Marlin
Marlin/src/gcode/control/M3-M5.cpp
C++
agpl-3.0
5,976
/** * Marlin 3D Printer Firmware * Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin] * * Based on Sprinter and grbl. * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <https://www.gnu.org/licenses/>. * */ #include "../../inc/MarlinConfig.h" #if HAS_MICROSTEPS #include "../gcode.h" #include "../../module/stepper.h" #if NUM_AXES == XYZ && EXTRUDERS >= 1 #define HAS_M350_B_PARAM 1 // "5th axis" (after E0) for an original XYZEB setup. #endif /** * M350: Set axis microstepping modes. S sets mode for all drivers. * * Warning: Steps-per-unit remains unchanged. */ void GcodeSuite::M350() { if (parser.seen('S')) LOOP_DISTINCT_AXES(i) stepper.microstep_mode(i, parser.value_byte()); LOOP_LOGICAL_AXES(i) if (parser.seenval(AXIS_CHAR(i))) stepper.microstep_mode(i, parser.value_byte()); TERN_(HAS_M350_B_PARAM, if (parser.seenval('B')) stepper.microstep_mode(E_AXIS + 1, parser.value_byte())); stepper.microstep_readings(); } /** * M351: Toggle MS1 MS2 pins directly with axis codes X Y Z . . . E [B] * S# determines MS1, MS2 or MS3, X# sets the pin high/low. * * Parameter 'B' sets "5th axis" (after E0) only for an original XYZEB setup. */ void GcodeSuite::M351() { const int8_t bval = TERN(HAS_M350_B_PARAM, parser.byteval('B', -1), -1); UNUSED(bval); if (parser.seenval('S')) switch (parser.value_byte()) { case 1: LOOP_LOGICAL_AXES(i) if (parser.seenval(AXIS_CHAR(i))) stepper.microstep_ms(i, parser.value_byte(), -1, -1); TERN_(HAS_M350_B_PARAM, if (bval >= 0) stepper.microstep_ms(E_AXIS + 1, bval != 0, -1, -1)); break; case 2: LOOP_LOGICAL_AXES(i) if (parser.seenval(AXIS_CHAR(i))) stepper.microstep_ms(i, -1, parser.value_byte(), -1); TERN_(HAS_M350_B_PARAM, if (bval >= 0) stepper.microstep_ms(E_AXIS + 1, -1, bval != 0, -1)); break; case 3: LOOP_LOGICAL_AXES(i) if (parser.seenval(AXIS_CHAR(i))) stepper.microstep_ms(i, -1, -1, parser.value_byte()); TERN_(HAS_M350_B_PARAM, if (bval >= 0) stepper.microstep_ms(E_AXIS + 1, -1, -1, bval != 0)); break; } stepper.microstep_readings(); } #endif // HAS_MICROSTEPS
2301_81045437/Marlin
Marlin/src/gcode/control/M350_M351.cpp
C++
agpl-3.0
2,788
/** * Marlin 3D Printer Firmware * Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin] * * Based on Sprinter and grbl. * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <https://www.gnu.org/licenses/>. * */ #include "../../inc/MarlinConfig.h" #if ANY(EXT_SOLENOID, MANUAL_SOLENOID_CONTROL) #include "../gcode.h" #include "../../feature/solenoid.h" #include "../../module/motion.h" /** * M380: Enable solenoid on the active extruder * * S<index> to specify a solenoid (Requires MANUAL_SOLENOID_CONTROL) */ void GcodeSuite::M380() { #if ENABLED(MANUAL_SOLENOID_CONTROL) enable_solenoid(parser.intval('S', active_extruder)); #else enable_solenoid(active_extruder); #endif } /** * M381: Disable all solenoids if EXT_SOLENOID * Disable selected/active solenoid if MANUAL_SOLENOID_CONTROL */ void GcodeSuite::M381() { #if ENABLED(MANUAL_SOLENOID_CONTROL) disable_solenoid(parser.intval('S', active_extruder)); #else disable_all_solenoids(); #endif } #endif // EXT_SOLENOID || MANUAL_SOLENOID_CONTROL
2301_81045437/Marlin
Marlin/src/gcode/control/M380_M381.cpp
C++
agpl-3.0
1,698
/** * Marlin 3D Printer Firmware * Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin] * * Based on Sprinter and grbl. * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <https://www.gnu.org/licenses/>. * */ #include "../../inc/MarlinConfig.h" #if ENABLED(DIRECT_PIN_CONTROL) #include "../gcode.h" #if HAS_FAN #include "../../module/temperature.h" #endif #ifdef MAPLE_STM32F1 // these are enums on the F1... #define INPUT_PULLDOWN INPUT_PULLDOWN #define INPUT_ANALOG INPUT_ANALOG #define OUTPUT_OPEN_DRAIN OUTPUT_OPEN_DRAIN #endif bool pin_is_protected(const pin_t pin); void protected_pin_err() { SERIAL_ERROR_MSG(STR_ERR_PROTECTED_PIN); } /** * M42: Change pin status via G-Code * * P<pin> Pin number (LED if omitted) * For LPC1768 specify pin P1_02 as M42 P102, * P1_20 as M42 P120, etc. * * S<byte> Pin status from 0 - 255 * I Flag to ignore Marlin's pin protection * * T<mode> Pin mode: 0=INPUT 1=OUTPUT 2=INPUT_PULLUP 3=INPUT_PULLDOWN * 4=INPUT_ANALOG 5=OUTPUT_OPEN_DRAIN */ void GcodeSuite::M42() { const int pin_index = PARSED_PIN_INDEX('P', GET_PIN_MAP_INDEX(LED_PIN)); if (pin_index < 0) return; const pin_t pin = GET_PIN_MAP_PIN(pin_index); if (!parser.boolval('I') && pin_is_protected(pin)) return protected_pin_err(); bool avoidWrite = false; if (parser.seenval('T')) { switch (parser.value_byte()) { case 0: pinMode(pin, INPUT); avoidWrite = true; break; case 1: pinMode(pin, OUTPUT); break; case 2: pinMode(pin, INPUT_PULLUP); avoidWrite = true; break; #ifdef INPUT_PULLDOWN case 3: pinMode(pin, INPUT_PULLDOWN); avoidWrite = true; break; #endif #ifdef INPUT_ANALOG case 4: pinMode(pin, INPUT_ANALOG); avoidWrite = true; break; #endif #ifdef OUTPUT_OPEN_DRAIN case 5: pinMode(pin, OUTPUT_OPEN_DRAIN); break; #endif default: SERIAL_ECHOLNPGM(GCODE_ERR_MSG("Invalid Pin Mode")); return; } } if (!parser.seenval('S')) return; const byte pin_status = parser.value_byte(); #if HAS_FAN switch (pin) { #define _CASE(N) case FAN##N##_PIN: thermalManager.fan_speed[N] = pin_status; return; REPEAT(FAN_COUNT, _CASE) } #endif if (avoidWrite) { SERIAL_ECHOLNPGM(GCODE_ERR_MSG("Cannot write to INPUT")); return; } // An OUTPUT_OPEN_DRAIN should not be changed to normal OUTPUT (STM32) // Use M42 Px T1/5 S0/1 to set the output type and then set value #ifndef OUTPUT_OPEN_DRAIN pinMode(pin, OUTPUT); #endif extDigitalWrite(pin, pin_status); #ifdef ARDUINO_ARCH_STM32 // A simple I/O will be set to 0 by hal.set_pwm_duty() if (pin_status <= 1 && !PWM_PIN(pin)) return; #endif hal.set_pwm_duty(pin, pin_status); } #endif // DIRECT_PIN_CONTROL
2301_81045437/Marlin
Marlin/src/gcode/control/M42.cpp
C++
agpl-3.0
3,487
/** * Marlin 3D Printer Firmware * Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin] * * Based on Sprinter and grbl. * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <https://www.gnu.org/licenses/>. * */ #include "../../inc/MarlinConfig.h" #if HAS_DUPLICATION_MODE //#define DEBUG_DXC_MODE #include "../gcode.h" #include "../../module/motion.h" #include "../../module/tool_change.h" #include "../../module/planner.h" #define DEBUG_OUT ENABLED(DEBUG_DXC_MODE) #include "../../core/debug_out.h" #if ENABLED(DUAL_X_CARRIAGE) /** * M605: Set dual x-carriage movement mode * * M605 S0 : (FULL_CONTROL) The slicer has full control over both X-carriages and can achieve optimal travel * results as long as it supports dual X-carriages. * * M605 S1 : (AUTO_PARK) The firmware automatically parks and unparks the X-carriages on tool-change so that * additional slicer support is not required. * * M605 S2 X R : (DUPLICATION) The firmware moves the second X-carriage and extruder in synchronization with * the first X-carriage and extruder, to print 2 copies of the same object at the same time. * Set the constant X-offset and temperature differential with M605 S2 X[offs] R[deg] and * follow with "M605 S2" to initiate duplicated movement. For example, use "M605 S2 X100 R2" to * make a copy 100mm to the right with E1 2° hotter than E0. * * M605 S3 : (MIRRORED) Formbot/Vivedino-inspired mirrored mode in which the second extruder duplicates * the movement of the first except the second extruder is reversed in the X axis. * The temperature differential and initial X offset must be set with "M605 S2 X[offs] R[deg]", * then followed by "M605 S3" to initiate mirrored movement. * * M605 W : IDEX What? command. * * Note: the X axis should be homed after changing Dual X-carriage mode. */ void GcodeSuite::M605() { planner.synchronize(); if (parser.seenval('S')) { const DualXMode previous_mode = dual_x_carriage_mode; dual_x_carriage_mode = (DualXMode)parser.value_byte(); idex_set_mirrored_mode(false); switch (dual_x_carriage_mode) { case DXC_FULL_CONTROL_MODE: case DXC_AUTO_PARK_MODE: break; case DXC_DUPLICATION_MODE: // Set the X offset, but no less than the safety gap if (parser.seenval('X')) duplicate_extruder_x_offset = _MAX(parser.value_linear_units(), (X2_MIN_POS) - (X1_MIN_POS)); if (parser.seenval('R')) duplicate_extruder_temp_offset = parser.value_celsius_diff(); // Always switch back to tool 0 if (active_extruder != 0) tool_change(0); break; case DXC_MIRRORED_MODE: { if (previous_mode != DXC_DUPLICATION_MODE) { SERIAL_ECHOLNPGM("Printer must be in DXC_DUPLICATION_MODE prior to "); SERIAL_ECHOLNPGM("specifying DXC_MIRRORED_MODE."); dual_x_carriage_mode = DEFAULT_DUAL_X_CARRIAGE_MODE; return; } idex_set_mirrored_mode(true); // Do a small 'jog' motion in the X axis xyze_pos_t dest = current_position; dest.x -= 0.1f; for (uint8_t i = 2; --i;) { planner.buffer_line(dest, feedrate_mm_s, 0); dest.x += 0.1f; } } return; default: dual_x_carriage_mode = DEFAULT_DUAL_X_CARRIAGE_MODE; break; } idex_set_parked(false); set_duplication_enabled(false); #ifdef EVENT_GCODE_IDEX_AFTER_MODECHANGE process_subcommands_now(F(EVENT_GCODE_IDEX_AFTER_MODECHANGE)); #endif } else if (!parser.seen('W')) // if no S or W parameter, the DXC mode gets reset to the user's default dual_x_carriage_mode = DEFAULT_DUAL_X_CARRIAGE_MODE; #ifdef DEBUG_DXC_MODE if (parser.seen('W')) { DEBUG_ECHO_START(); DEBUG_ECHOPGM("Dual X Carriage Mode "); switch (dual_x_carriage_mode) { case DXC_FULL_CONTROL_MODE: DEBUG_ECHOPGM("FULL_CONTROL"); break; case DXC_AUTO_PARK_MODE: DEBUG_ECHOPGM("AUTO_PARK"); break; case DXC_DUPLICATION_MODE: DEBUG_ECHOPGM("DUPLICATION"); break; case DXC_MIRRORED_MODE: DEBUG_ECHOPGM("MIRRORED"); break; } DEBUG_ECHOPGM("\nActive Ext: ", active_extruder); if (!active_extruder_parked) DEBUG_ECHOPGM(" NOT ", F(" parked.")); DEBUG_ECHOLNPGM( "\nactive_extruder_x_pos: ", current_position.x, "\ninactive_extruder_x: ", inactive_extruder_x, "\nextruder_duplication_enabled: ", extruder_duplication_enabled, "\nduplicate_extruder_x_offset: ", duplicate_extruder_x_offset, "\nduplicate_extruder_temp_offset: ", duplicate_extruder_temp_offset, "\ndelayed_move_time: ", delayed_move_time, "\nX1 Home: ", x_home_pos(0), " X1_MIN_POS=", X1_MIN_POS, " X1_MAX_POS=", X1_MAX_POS, "\nX2 Home: ", x_home_pos(1), " X2_MIN_POS=", X2_MIN_POS, " X2_MAX_POS=", X2_MAX_POS, "\nDEFAULT_DUAL_X_CARRIAGE_MODE=", STRINGIFY(DEFAULT_DUAL_X_CARRIAGE_MODE), "\toolchange_settings.z_raise=", toolchange_settings.z_raise, "\nDEFAULT_DUPLICATION_X_OFFSET=", DEFAULT_DUPLICATION_X_OFFSET ); HOTEND_LOOP() { DEBUG_ECHOPGM_P(SP_T_STR, e); LOOP_NUM_AXES(a) DEBUG_ECHOPGM(" hotend_offset[", e, "].", C(AXIS_CHAR(a) | 0x20), "=", hotend_offset[e][a]); DEBUG_EOL(); } DEBUG_EOL(); } #endif // DEBUG_DXC_MODE } #elif ENABLED(MULTI_NOZZLE_DUPLICATION) /** * M605: Set multi-nozzle duplication mode * * S2 - Enable duplication mode * P[mask] - Bit-mask of nozzles to include in the duplication set. * A value of 0 disables duplication. * E[index] - Last nozzle index to include in the duplication set. * A value of 0 disables duplication. */ void GcodeSuite::M605() { bool ena = false; if (parser.seen("EPS")) { planner.synchronize(); if (parser.seenval('P')) duplication_e_mask = parser.value_int(); // Set the mask directly else if (parser.seenval('E')) duplication_e_mask = _BV(parser.value_int() + 1) - 1; // Set the mask by E index ena = (2 == parser.intval('S', extruder_duplication_enabled ? 2 : 0)); set_duplication_enabled(ena && (duplication_e_mask >= 3)); } SERIAL_ECHO_START(); SERIAL_ECHOPGM(STR_DUPLICATION_MODE); serialprint_onoff(extruder_duplication_enabled); if (ena) { SERIAL_ECHOPGM(" ( "); HOTEND_LOOP() if (TEST(duplication_e_mask, e)) { SERIAL_ECHO(e); SERIAL_CHAR(' '); } SERIAL_CHAR(')'); } SERIAL_EOL(); } #endif // MULTI_NOZZLE_DUPLICATION #endif // HAS_DUPICATION_MODE
2301_81045437/Marlin
Marlin/src/gcode/control/M605.cpp
C++
agpl-3.0
7,570
/** * Marlin 3D Printer Firmware * Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin] * * Based on Sprinter and grbl. * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <https://www.gnu.org/licenses/>. * */ #include "../../inc/MarlinConfigPre.h" #if ANY(COOLANT_MIST, COOLANT_FLOOD, AIR_ASSIST) #include "../gcode.h" #include "../../module/planner.h" #if ENABLED(COOLANT_MIST) /** * M7: Mist Coolant On */ void GcodeSuite::M7() { planner.synchronize(); // Wait for move to arrive WRITE(COOLANT_MIST_PIN, !(COOLANT_MIST_INVERT)); // Turn on Mist coolant } #endif #if ANY(COOLANT_FLOOD, AIR_ASSIST) #if ENABLED(AIR_ASSIST) #include "../../feature/spindle_laser.h" #endif /** * M8: Flood Coolant / Air Assist ON */ void GcodeSuite::M8() { planner.synchronize(); // Wait for move to arrive #if ENABLED(COOLANT_FLOOD) WRITE(COOLANT_FLOOD_PIN, !(COOLANT_FLOOD_INVERT)); // Turn on Flood coolant #endif #if ENABLED(AIR_ASSIST) cutter.air_assist_enable(); // Turn on Air Assist #endif } #endif /** * M9: Coolant / Air Assist OFF */ void GcodeSuite::M9() { planner.synchronize(); // Wait for move to arrive #if ENABLED(COOLANT_MIST) WRITE(COOLANT_MIST_PIN, COOLANT_MIST_INVERT); // Turn off Mist coolant #endif #if ENABLED(COOLANT_FLOOD) WRITE(COOLANT_FLOOD_PIN, COOLANT_FLOOD_INVERT); // Turn off Flood coolant #endif #if ENABLED(AIR_ASSIST) cutter.air_assist_disable(); // Turn off Air Assist #endif } #endif // COOLANT_MIST | COOLANT_FLOOD | AIR_ASSIST
2301_81045437/Marlin
Marlin/src/gcode/control/M7-M9.cpp
C++
agpl-3.0
2,343
/** * Marlin 3D Printer Firmware * Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin] * * Based on Sprinter and grbl. * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <https://www.gnu.org/licenses/>. * */ #include "../gcode.h" #include "../../module/temperature.h" #include "../../module/planner.h" // for planner.finish_and_disable #include "../../module/printcounter.h" // for print_job_timer.stop #include "../../lcd/marlinui.h" // for LCD_MESSAGE_F #include "../../inc/MarlinConfig.h" #if ENABLED(PSU_CONTROL) #include "../queue.h" #include "../../feature/power.h" #endif #if HAS_SUICIDE #include "../../MarlinCore.h" #endif #if ENABLED(PSU_CONTROL) /** * M80 : Turn on the Power Supply * M80 S : Report the current state and exit */ void GcodeSuite::M80() { // S: Report the current power supply state and exit if (parser.seen('S')) { SERIAL_ECHO(powerManager.psu_on ? F("PS:1\n") : F("PS:0\n")); return; } powerManager.power_on(); /** * If you have a switch on suicide pin, this is useful * if you want to start another print with suicide feature after * a print without suicide... */ #if HAS_SUICIDE OUT_WRITE(SUICIDE_PIN, !SUICIDE_PIN_STATE); #endif TERN_(HAS_MARLINUI_MENU, ui.reset_status()); } #endif // PSU_CONTROL /** * M81: Turn off Power, including Power Supply, if there is one. * * This code should ALWAYS be available for FULL SHUTDOWN! */ void GcodeSuite::M81() { planner.finish_and_disable(); thermalManager.cooldown(); print_job_timer.stop(); #if ALL(HAS_FAN, PROBING_FANS_OFF) thermalManager.fans_paused = false; ZERO(thermalManager.saved_fan_speed); #endif safe_delay(1000); // Wait 1 second before switching off LCD_MESSAGE_F(MACHINE_NAME " " STR_OFF "."); bool delayed_power_off = false; #if ENABLED(POWER_OFF_TIMER) if (parser.seenval('D')) { uint16_t delay = parser.value_ushort(); if (delay > 1) { // skip already observed 1s delay delayed_power_off = true; powerManager.setPowerOffTimer(SEC_TO_MS(delay - 1)); } } #endif #if ENABLED(POWER_OFF_WAIT_FOR_COOLDOWN) if (parser.boolval('S')) { delayed_power_off = true; powerManager.setPowerOffOnCooldown(true); } #endif if (delayed_power_off) { SERIAL_ECHOLNPGM(STR_DELAYED_POWEROFF); return; } #if HAS_SUICIDE suicide(); #elif ENABLED(PSU_CONTROL) powerManager.power_off_soon(); #endif }
2301_81045437/Marlin
Marlin/src/gcode/control/M80_M81.cpp
C++
agpl-3.0
3,180
/** * Marlin 3D Printer Firmware * Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin] * * Based on Sprinter and grbl. * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <https://www.gnu.org/licenses/>. * */ #include "../gcode.h" /** * M85: Set inactivity shutdown timer with parameter S<seconds>. To disable set zero (default) */ void GcodeSuite::M85() { if (parser.seen('S')) { reset_stepper_timeout(); const millis_t ms = parser.value_millis_from_seconds(); #if LASER_SAFETY_TIMEOUT_MS > 0 if (ms && ms <= LASER_SAFETY_TIMEOUT_MS) { SERIAL_ECHO_MSG(GCODE_ERR_MSG("M85 timeout must be > ", MS_TO_SEC(LASER_SAFETY_TIMEOUT_MS + 999), " s for laser safety.")); return; } #endif max_inactive_time = ms; } else { #if DISABLED(MARLIN_SMALL_BUILD) SERIAL_ECHOLNPGM("Inactivity timeout ", MS_TO_SEC(max_inactive_time), " s."); #endif } }
2301_81045437/Marlin
Marlin/src/gcode/control/M85.cpp
C++
agpl-3.0
1,562
/** * Marlin 3D Printer Firmware * Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin] * * Based on Sprinter and grbl. * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <https://www.gnu.org/licenses/>. * */ #include "../../inc/MarlinConfig.h" #if SPI_FLASH_BACKUP #include "../gcode.h" #include "../../sd/cardreader.h" #include "../../libs/W25Qxx.h" /** * M993: Backup SPI Flash to SD */ void GcodeSuite::M993() { if (!card.isMounted()) card.mount(); char fname[] = "spiflash.bin"; card.openFileWrite(fname); if (!card.isFileOpen()) { SERIAL_ECHOLNPGM("Failed to open ", fname, " to write."); return; } uint8_t buf[1024]; uint32_t addr = 0; W25QXX.init(SPI_QUARTER_SPEED); SERIAL_ECHOPGM("Save SPI Flash"); while (addr < SPI_FLASH_SIZE) { W25QXX.SPI_FLASH_BufferRead(buf, addr, COUNT(buf)); addr += COUNT(buf); card.write(buf, COUNT(buf)); if (addr % (COUNT(buf) * 10) == 0) SERIAL_CHAR('.'); } SERIAL_ECHOLNPGM(" done"); card.closefile(); } /** * M994: Load a backup from SD to SPI Flash */ void GcodeSuite::M994() { if (!card.isMounted()) card.mount(); char fname[] = "spiflash.bin"; card.openFileRead(fname); if (!card.isFileOpen()) { SERIAL_ECHOLNPGM("Failed to open ", fname, " to read."); return; } uint8_t buf[1024]; uint32_t addr = 0; W25QXX.init(SPI_QUARTER_SPEED); W25QXX.SPI_FLASH_BulkErase(); SERIAL_ECHOPGM("Load SPI Flash"); while (addr < SPI_FLASH_SIZE) { card.read(buf, COUNT(buf)); W25QXX.SPI_FLASH_BufferWrite(buf, addr, COUNT(buf)); addr += COUNT(buf); if (addr % (COUNT(buf) * 10) == 0) SERIAL_CHAR('.'); } SERIAL_ECHOLNPGM(" done"); card.closefile(); } #endif // SPI_FLASH_BACKUP
2301_81045437/Marlin
Marlin/src/gcode/control/M993_M994.cpp
C++
agpl-3.0
2,374
/** * Marlin 3D Printer Firmware * Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin] * * Based on Sprinter and grbl. * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <https://www.gnu.org/licenses/>. * */ #include "../gcode.h" #if ENABLED(PLATFORM_M997_SUPPORT) #if ENABLED(EXTENSIBLE_UI) #include "../../lcd/extui/ui_api.h" #endif /** * M997: Perform in-application firmware update */ void GcodeSuite::M997() { TERN_(EXTENSIBLE_UI, ExtUI::onFirmwareFlash()); flashFirmware(parser.intval('S')); } #endif
2301_81045437/Marlin
Marlin/src/gcode/control/M997.cpp
C++
agpl-3.0
1,177
/** * Marlin 3D Printer Firmware * Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin] * * Based on Sprinter and grbl. * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <https://www.gnu.org/licenses/>. * */ #include "../gcode.h" #include "../../lcd/marlinui.h" // for ui.reset_alert_level #include "../../MarlinCore.h" // for marlin_state #include "../queue.h" // for flush_and_request_resend /** * M999: Restart after being stopped * * Default behavior is to flush the serial buffer and request * a resend to the host starting on the last N line received. * * Sending "M999 S1" will resume printing without flushing the * existing command buffer. */ void GcodeSuite::M999() { marlin_state = MF_RUNNING; ui.reset_alert_level(); if (parser.boolval('S')) return; queue.flush_and_request_resend(queue.ring_buffer.command_port()); }
2301_81045437/Marlin
Marlin/src/gcode/control/M999.cpp
C++
agpl-3.0
1,517
/** * Marlin 3D Printer Firmware * Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin] * * Based on Sprinter and grbl. * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <https://www.gnu.org/licenses/>. * */ #include "../../inc/MarlinConfigPre.h" #if HAS_TOOLCHANGE #include "../gcode.h" #include "../../module/tool_change.h" #if ANY(HAS_MULTI_EXTRUDER, DEBUG_LEVELING_FEATURE) #include "../../module/motion.h" #endif #if HAS_PRUSA_MMU2 #include "../../feature/mmu/mmu2.h" #endif #define DEBUG_OUT ENABLED(DEBUG_LEVELING_FEATURE) #include "../../core/debug_out.h" /** * T0-T<n>: Switch tool, usually switching extruders * * F[units/min] Set the movement feedrate * S1 Don't move the tool in XY after change * * For PRUSA_MMU2(S) and EXTENDABLE_EMU_MMU2(S) * T[n] G-code to extrude at least 38.10 mm at feedrate 19.02 mm/s must follow immediately to load to extruder wheels. * T? G-code to extrude shouldn't have to follow. Load to extruder wheels is done automatically. * Tx Same as T?, but nozzle doesn't have to be preheated. Tc requires a preheated nozzle to finish filament load. * Tc Load to nozzle after filament was prepared by Tc and nozzle is already heated. */ void GcodeSuite::T(const int8_t tool_index) { #if HAS_MULTI_EXTRUDER // For 'T' with no parameter report the current tool. if (parser.string_arg && *parser.string_arg == '*') { SERIAL_ECHOLNPGM(STR_ACTIVE_EXTRUDER, active_extruder); return; } #endif DEBUG_SECTION(log_T, "T", DEBUGGING(LEVELING)); if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPGM("...(", tool_index, ")"); // Count this command as movement / activity reset_stepper_timeout(); #if HAS_PRUSA_MMU2 if (parser.string_arg) { mmu2.tool_change(parser.string_arg); // Special commands T?/Tx/Tc return; } #endif tool_change(tool_index #if HAS_MULTI_EXTRUDER , parser.boolval('S') || TERN(PARKING_EXTRUDER, false, tool_index == active_extruder) // For PARKING_EXTRUDER motion is decided in tool_change() #endif ); } #endif // HAS_TOOLCHANGE
2301_81045437/Marlin
Marlin/src/gcode/control/T.cpp
C++
agpl-3.0
2,759
/** * Marlin 3D Printer Firmware * Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin] * * Based on Sprinter and grbl. * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <https://www.gnu.org/licenses/>. * */ #include "../gcode.h" #include "../../module/settings.h" #include "../../core/serial.h" #include "../../inc/MarlinConfig.h" #if ENABLED(CONFIGURATION_EMBEDDING) #include "../../sd/cardreader.h" #include "../../mczip.h" #endif /** * M500: Store settings in EEPROM */ void GcodeSuite::M500() { (void)settings.save(); } /** * M501: Read settings from EEPROM */ void GcodeSuite::M501() { (void)settings.load(); } /** * M502: Revert to default settings */ void GcodeSuite::M502() { (void)settings.reset(); } #if DISABLED(DISABLE_M503) /** * M503: print settings currently in memory * * S<bool> : Include / exclude header comments in the output. (Default: S1) * * With CONFIGURATION_EMBEDDING: * C<flag> : Save the full Marlin configuration to SD Card as "mc.zip" */ void GcodeSuite::M503() { (void)settings.report(!parser.boolval('S', true)); #if ENABLED(CONFIGURATION_EMBEDDING) if (parser.seen_test('C')) { MediaFile file; // Need to create the config size on the SD card MediaFile root = card.getroot(); if (file.open(&root, "mc.zip", O_WRITE|O_CREAT)) { bool success = true; for (uint16_t i = 0; success && i < sizeof(mc_zip); ++i) { const uint8_t c = pgm_read_byte(&mc_zip[i]); success = (file.write(c) == 1); } success = file.close() && success; if (success) SERIAL_ECHO_MSG("Configuration saved as 'mc.zip'"); } } #endif } #endif // !DISABLE_M503 #if ENABLED(EEPROM_SETTINGS) #if ENABLED(MARLIN_DEV_MODE) #include "../../libs/hex_print.h" #endif /** * M504: Validate EEPROM Contents */ void GcodeSuite::M504() { #if ENABLED(MARLIN_DEV_MODE) const bool dowrite = parser.seenval('W'); if (dowrite || parser.seenval('R')) { uint8_t val = 0; int addr = parser.value_ushort(); if (dowrite) { val = parser.byteval('V'); persistentStore.write_data(addr, &val); SERIAL_ECHOLNPGM("Wrote address ", addr, " with ", val); } else { if (parser.seenval('T')) { const int endaddr = parser.value_ushort(); while (addr <= endaddr) { persistentStore.read_data(addr, &val); SERIAL_ECHOLNPGM("0x", hex_word(addr), ":", hex_byte(val)); addr++; safe_delay(10); } SERIAL_EOL(); } else { persistentStore.read_data(addr, &val); SERIAL_ECHOLNPGM("Read address ", addr, " and got ", val); } } return; } #endif if (settings.validate()) SERIAL_ECHO_MSG("EEPROM OK"); } #endif
2301_81045437/Marlin
Marlin/src/gcode/eeprom/M500-M504.cpp
C++
agpl-3.0
3,621
/** * Marlin 3D Printer Firmware * Copyright (c) 2021 MarlinFirmware [https://github.com/MarlinFirmware/Marlin] * * Based on Sprinter and grbl. * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <https://www.gnu.org/licenses/>. * */ #include "../../../inc/MarlinConfig.h" #if ENABLED(HAS_MCP3426_ADC) #include "../../gcode.h" #include "../../../feature/adc/adc_mcp3426.h" #define MCP3426_BASE_ADDR (0b1101 << 3) /** * M3426: Read 16 bit (signed) value from I2C MCP3426 ADC device * * M3426 C<byte-1 value in base 10> channel 1 or 2 * M3426 G<byte-1 value in base 10> gain 1, 2, 4 or 8 * M3426 I<byte-2 value in base 10> 0 or 1, invert reply */ void GcodeSuite::M3426() { uint8_t channel = parser.byteval('C', 1), // Channel 1 or 2 gain = parser.byteval('G', 1), // Gain 1, 2, 4, or 8 address = parser.byteval('A', 3); // Address 0-7 (or 104-111) const bool inverted = parser.boolval('I'); if (address <= 7) address += MCP3426_BASE_ADDR; if (WITHIN(channel, 1, 2) && (gain == 1 || gain == 2 || gain == 4 || gain == 8) && WITHIN(address, MCP3426_BASE_ADDR, MCP3426_BASE_ADDR + 7)) { int16_t result = mcp3426.ReadValue(channel, gain, address); if (mcp3426.Error == false) { if (inverted) { // Should we invert the reading (32767 - ADC value) ? // Caters to end devices that expect values to increase when in reality they decrease. // e.g., A pressure sensor in a vacuum when the end device expects a positive pressure. result = INT16_MAX - result; } //SERIAL_ECHOPGM(STR_OK); SERIAL_ECHOLNPGM("V:", result, " C:", channel, " G:", gain, " I:", inverted ? 1 : 0); } else SERIAL_ERROR_MSG("MCP342X i2c error"); } else SERIAL_ERROR_MSG("MCP342X Bad request"); } #endif // HAS_MCP3426_ADC
2301_81045437/Marlin
Marlin/src/gcode/feature/adc/M3426.cpp
C++
agpl-3.0
2,446
/** * Marlin 3D Printer Firmware * Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin] * * Based on Sprinter and grbl. * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <https://www.gnu.org/licenses/>. * */ #include "../../../inc/MarlinConfig.h" #if ENABLED(LIN_ADVANCE) #include "../../gcode.h" #include "../../../module/planner.h" #if ENABLED(ADVANCE_K_EXTRA) float other_extruder_advance_K[DISTINCT_E]; uint8_t lin_adv_slot = 0; #endif /** * M900: Get or Set Linear Advance K-factor * T<tool> Which tool to address * K<factor> Set current advance K factor (Slot 0). * L<factor> Set secondary advance K factor (Slot 1). Requires ADVANCE_K_EXTRA. * S<0/1> Activate slot 0 or 1. Requires ADVANCE_K_EXTRA. */ void GcodeSuite::M900() { auto echo_value_oor = [](const char ltr, const bool ten=true) { SERIAL_CHAR('?', ltr); SERIAL_ECHOPGM(" value out of range"); if (ten) SERIAL_ECHOPGM(" (0-10)"); SERIAL_ECHOLNPGM("."); }; #if EXTRUDERS < 2 constexpr uint8_t tool_index = 0; UNUSED(tool_index); #else const uint8_t tool_index = parser.intval('T', active_extruder); if (tool_index >= EXTRUDERS) { echo_value_oor('T', false); return; } #endif float &kref = planner.extruder_advance_K[E_INDEX_N(tool_index)], newK = kref; const float oldK = newK; #if ENABLED(ADVANCE_K_EXTRA) float &lref = other_extruder_advance_K[E_INDEX_N(tool_index)]; const bool old_slot = TEST(lin_adv_slot, tool_index), // The tool's current slot (0 or 1) new_slot = parser.boolval('S', old_slot); // The passed slot (default = current) // If a new slot is being selected swap the current and // saved K values. Do here so K/L will apply correctly. if (new_slot != old_slot) { // Not the same slot? SET_BIT_TO(lin_adv_slot, tool_index, new_slot); // Update the slot for the tool newK = lref; // Get new K value from backup lref = oldK; // Save K to backup } // Set the main K value. Apply if the main slot is active. if (parser.seenval('K')) { const float K = parser.value_float(); if (!WITHIN(K, 0, 10)) echo_value_oor('K'); else if (new_slot) lref = K; // S1 Knn else newK = K; // S0 Knn } // Set the extra K value. Apply if the extra slot is active. if (parser.seenval('L')) { const float L = parser.value_float(); if (!WITHIN(L, 0, 10)) echo_value_oor('L'); else if (!new_slot) lref = L; // S0 Lnn else newK = L; // S1 Lnn } #else if (parser.seenval('K')) { const float K = parser.value_float(); if (WITHIN(K, 0, 10)) newK = K; else echo_value_oor('K'); } #endif if (newK != oldK) { planner.synchronize(); kref = newK; } if (!parser.seen_any()) { #if ENABLED(ADVANCE_K_EXTRA) #if DISTINCT_E < 2 SERIAL_ECHOLNPGM("Advance S", new_slot, " K", kref, "(S", !new_slot, " K", lref, ")"); #else EXTRUDER_LOOP() { const bool slot = TEST(lin_adv_slot, e); SERIAL_ECHOLNPGM("Advance T", e, " S", slot, " K", planner.extruder_advance_K[e], "(S", !slot, " K", other_extruder_advance_K[e], ")"); } #endif #else SERIAL_ECHO_START(); #if DISTINCT_E < 2 SERIAL_ECHOLNPGM("Advance K=", planner.extruder_advance_K[0]); #else SERIAL_ECHOPGM("Advance K"); EXTRUDER_LOOP() SERIAL_ECHO(C(' '), C('0' + e), C(':'), planner.extruder_advance_K[e]); SERIAL_EOL(); #endif #endif } } void GcodeSuite::M900_report(const bool forReplay/*=true*/) { TERN_(MARLIN_SMALL_BUILD, return); report_heading(forReplay, F(STR_LINEAR_ADVANCE)); #if DISTINCT_E < 2 report_echo_start(forReplay); SERIAL_ECHOLNPGM(" M900 K", planner.extruder_advance_K[0]); #else EXTRUDER_LOOP() { report_echo_start(forReplay); SERIAL_ECHOLNPGM(" M900 T", e, " K", planner.extruder_advance_K[e]); } #endif } #endif // LIN_ADVANCE
2301_81045437/Marlin
Marlin/src/gcode/feature/advance/M900.cpp
C++
agpl-3.0
4,899
/** * Marlin 3D Printer Firmware * Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin] * * Based on Sprinter and grbl. * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <https://www.gnu.org/licenses/>. * */ #include "../../../inc/MarlinConfig.h" #if ENABLED(BARICUDA) #include "../../gcode.h" #include "../../../feature/baricuda.h" #if HAS_HEATER_1 /** * M126: Heater 1 valve open */ void GcodeSuite::M126() { baricuda_valve_pressure = parser.byteval('S', 255); } /** * M127: Heater 1 valve close */ void GcodeSuite::M127() { baricuda_valve_pressure = 0; } #endif // HAS_HEATER_1 #if HAS_HEATER_2 /** * M128: Heater 2 valve open */ void GcodeSuite::M128() { baricuda_e_to_p_pressure = parser.byteval('S', 255); } /** * M129: Heater 2 valve close */ void GcodeSuite::M129() { baricuda_e_to_p_pressure = 0; } #endif // HAS_HEATER_2 #endif // BARICUDA
2301_81045437/Marlin
Marlin/src/gcode/feature/baricuda/M126-M129.cpp
C++
agpl-3.0
1,556
/** * Marlin 3D Printer Firmware * Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin] * * Based on Sprinter and grbl. * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <https://www.gnu.org/licenses/>. * */ #include "../../../inc/MarlinConfig.h" #if ENABLED(PHOTO_GCODE) #include "../../gcode.h" #include "../../../module/motion.h" // for active_extruder and current_position #if PIN_EXISTS(CHDK) millis_t chdk_timeout; // = 0 #endif #if defined(PHOTO_POSITION) && PHOTO_DELAY_MS > 0 #include "../../../MarlinCore.h" // for idle() #endif #ifdef PHOTO_RETRACT_MM #define _PHOTO_RETRACT_MM (PHOTO_RETRACT_MM + 0) #include "../../../module/planner.h" #include "../../../module/temperature.h" #if ENABLED(ADVANCED_PAUSE_FEATURE) #include "../../../feature/pause.h" #endif #ifdef PHOTO_RETRACT_MM inline void e_move_m240(const float length, const_feedRate_t fr_mm_s) { if (length && thermalManager.hotEnoughToExtrude(active_extruder)) unscaled_e_move(length, fr_mm_s); } #endif #endif #if PIN_EXISTS(PHOTOGRAPH) FORCE_INLINE void set_photo_pin(const uint8_t state) { constexpr uint32_t pulse_length = ( #ifdef PHOTO_PULSES_US PHOTO_PULSE_DELAY_US #else 15 // 15.24 from _delay_ms(0.01524) #endif ); WRITE(PHOTOGRAPH_PIN, state); delayMicroseconds(pulse_length); } FORCE_INLINE void tweak_photo_pin() { set_photo_pin(HIGH); set_photo_pin(LOW); } #ifdef PHOTO_PULSES_US inline void pulse_photo_pin(const uint32_t duration, const uint8_t state) { if (state) { for (const uint32_t stop = micros() + duration; micros() < stop;) tweak_photo_pin(); } else delayMicroseconds(duration); } inline void spin_photo_pin() { static constexpr uint32_t sequence[] = PHOTO_PULSES_US; for (uint8_t i = 0; i < COUNT(sequence); ++i) pulse_photo_pin(sequence[i], !(i & 1)); } #else constexpr uint8_t NUM_PULSES = 16; inline void spin_photo_pin() { for (uint8_t i = NUM_PULSES; i--;) tweak_photo_pin(); } #endif #endif /** * M240: Trigger a camera by... * * - CHDK : Emulate a Canon RC-1 with a configurable ON duration. * https://captain-slow.dk/2014/03/09/3d-printing-timelapses/ * - PHOTOGRAPH_PIN : Pulse a digital pin 16 times. * See https://www.doc-diy.net/photo/rc-1_hacked/ * - PHOTO_SWITCH_POSITION : Bump a physical switch with the X-carriage using a * configured position, delay, and retract length. * * PHOTO_POSITION parameters: * A - X offset to the return position * B - Y offset to the return position * F - Override the XY movement feedrate * R - Retract/recover length (current units) * S - Retract/recover feedrate (mm/min) * X - Move to X before triggering the shutter * Y - Move to Y before triggering the shutter * Z - Raise Z by a distance before triggering the shutter * * PHOTO_SWITCH_POSITION parameters: * D - Duration (ms) to hold down switch (Requires PHOTO_SWITCH_MS) * P - Delay (ms) after triggering the shutter (Requires PHOTO_SWITCH_MS) * I - Switch trigger position override X * J - Switch trigger position override Y */ void GcodeSuite::M240() { #ifdef PHOTO_POSITION if (homing_needed_error()) return; const xyz_pos_t old_pos = NUM_AXIS_ARRAY( current_position.x + parser.linearval('A'), current_position.y + parser.linearval('B'), current_position.z, current_position.i, current_position.j, current_position.k, current_position.u, current_position.v, current_position.w ); #ifdef PHOTO_RETRACT_MM const float rval = parser.linearval('R', _PHOTO_RETRACT_MM); const feedRate_t sval = parser.feedrateval('S', TERN(ADVANCED_PAUSE_FEATURE, PAUSE_PARK_RETRACT_FEEDRATE, TERN(FWRETRACT, RETRACT_FEEDRATE, 45))); e_move_m240(-rval, sval); #endif feedRate_t fr_mm_s = parser.feedrateval('F'); if (fr_mm_s) NOLESS(fr_mm_s, 10.0f); constexpr xyz_pos_t photo_position = PHOTO_POSITION; xyz_pos_t raw = { parser.seenval('X') ? RAW_X_POSITION(parser.value_linear_units()) : photo_position.x, parser.seenval('Y') ? RAW_Y_POSITION(parser.value_linear_units()) : photo_position.y, (parser.seenval('Z') ? parser.value_linear_units() : photo_position.z) + current_position.z }; apply_motion_limits(raw); do_blocking_move_to(raw, fr_mm_s); #ifdef PHOTO_SWITCH_POSITION constexpr xy_pos_t photo_switch_position = PHOTO_SWITCH_POSITION; const xy_pos_t sraw = { parser.seenval('I') ? RAW_X_POSITION(parser.value_linear_units()) : photo_switch_position.x, parser.seenval('J') ? RAW_Y_POSITION(parser.value_linear_units()) : photo_switch_position.y }; do_blocking_move_to_xy(sraw, get_homing_bump_feedrate(X_AXIS)); #if PHOTO_SWITCH_MS > 0 safe_delay(parser.intval('D', PHOTO_SWITCH_MS)); #endif do_blocking_move_to(raw); #endif #endif #if PIN_EXISTS(CHDK) OUT_WRITE(CHDK_PIN, HIGH); chdk_timeout = millis() + parser.intval('D', PHOTO_SWITCH_MS); #elif HAS_PHOTOGRAPH spin_photo_pin(); delay(7.33); spin_photo_pin(); #endif #ifdef PHOTO_POSITION #if PHOTO_DELAY_MS > 0 const millis_t timeout = millis() + parser.intval('P', PHOTO_DELAY_MS); while (PENDING(millis(), timeout)) idle(); #endif do_blocking_move_to(old_pos, fr_mm_s); #ifdef PHOTO_RETRACT_MM e_move_m240(rval, sval); #endif #endif } #endif // PHOTO_GCODE
2301_81045437/Marlin
Marlin/src/gcode/feature/camera/M240.cpp
C++
agpl-3.0
6,340
/** * Marlin 3D Printer Firmware * Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin] * * Based on Sprinter and grbl. * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <https://www.gnu.org/licenses/>. * */ #include "../../../inc/MarlinConfig.h" #if ENABLED(CANCEL_OBJECTS) #include "../../gcode.h" #include "../../../feature/cancel_object.h" /** * M486: A simple interface to cancel objects * * T[count] : Reset objects and/or set the count * S<index> : Start an object with the given index * P<index> : Cancel the object with the given index * U<index> : Un-cancel object with the given index * C : Cancel the current object (the last index given by S<index>) * S-1 : Start a non-object like a brim or purge tower that should always print */ void GcodeSuite::M486() { if (parser.seen('T')) { cancelable.reset(); cancelable.object_count = parser.intval('T', 1); } if (parser.seenval('S')) cancelable.set_active_object(parser.value_int()); if (parser.seen('C')) cancelable.cancel_active_object(); if (parser.seenval('P')) cancelable.cancel_object(parser.value_int()); if (parser.seenval('U')) cancelable.uncancel_object(parser.value_int()); } #endif // CANCEL_OBJECTS
2301_81045437/Marlin
Marlin/src/gcode/feature/cancel/M486.cpp
C++
agpl-3.0
1,890
/** * Marlin 3D Printer Firmware * Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin] * * Based on Sprinter and grbl. * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <https://www.gnu.org/licenses/>. * */ #include "../../../inc/MarlinConfig.h" #if ENABLED(CASE_LIGHT_ENABLE) #include "../../../feature/caselight.h" #include "../../gcode.h" /** * M355: Turn case light on/off and set brightness * * P<byte> Set case light brightness (PWM pin required - ignored otherwise) * * S<bool> Set case light on/off * * When S turns on the light on a PWM pin then the current brightness level is used/restored * * M355 P200 S0 turns off the light & sets the brightness level * M355 S1 turns on the light with a brightness of 200 (assuming a PWM pin) */ void GcodeSuite::M355() { bool didset = false; #if CASELIGHT_USES_BRIGHTNESS if (parser.seenval('P')) { didset = true; caselight.brightness = parser.value_byte(); } #endif const bool sflag = parser.seenval('S'); if (sflag) { didset = true; caselight.on = parser.value_bool(); } if (didset) caselight.update(sflag); // Always report case light status SERIAL_ECHO_START(); SERIAL_ECHOPGM("Case light: "); if (!caselight.on) SERIAL_ECHOLNPGM(STR_OFF); else { #if CASELIGHT_USES_BRIGHTNESS if (TERN(CASE_LIGHT_USE_NEOPIXEL, true, TERN0(NEED_CASE_LIGHT_PIN, PWM_PIN(CASE_LIGHT_PIN)))) { SERIAL_ECHOLN(int(caselight.brightness)); return; } #endif SERIAL_ECHOLNPGM(STR_ON); } } #endif // CASE_LIGHT_ENABLE
2301_81045437/Marlin
Marlin/src/gcode/feature/caselight/M355.cpp
C++
agpl-3.0
2,225
/** * Marlin 3D Printer Firmware * Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin] * * Based on Sprinter and grbl. * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <https://www.gnu.org/licenses/>. * */ #include "../../../inc/MarlinConfig.h" #if ENABLED(NOZZLE_CLEAN_FEATURE) #include "../../../libs/nozzle.h" #include "../../gcode.h" #include "../../parser.h" #include "../../../module/motion.h" #if HAS_LEVELING #include "../../../module/planner.h" #include "../../../feature/bedlevel/bedlevel.h" #endif /** * G12: Clean the nozzle * * E<bool> : 0=Never or 1=Always apply the "software endstop" limits * P0 S<strokes> : Stroke cleaning with S strokes * P1 Sn T<objects> : Zigzag cleaning with S repeats and T zigzags * P2 Sn R<radius> : Circle cleaning with S repeats and R radius * X, Y, Z : Specify axes to move during cleaning. Default: ALL. */ void GcodeSuite::G12() { // Don't allow nozzle cleaning without homing first constexpr main_axes_bits_t clean_axis_mask = main_axes_mask & ~TERN0(NOZZLE_CLEAN_NO_Z, Z_AXIS) & ~TERN0(NOZZLE_CLEAN_NO_Y, Y_AXIS); if (homing_needed_error(clean_axis_mask)) return; #ifdef WIPE_SEQUENCE_COMMANDS if (!parser.seen_any()) { process_subcommands_now(F(WIPE_SEQUENCE_COMMANDS)); return; } #endif const uint8_t pattern = ( #if COUNT_ENABLED(NOZZLE_CLEAN_PATTERN_LINE, NOZZLE_CLEAN_PATTERN_ZIGZAG, NOZZLE_CLEAN_PATTERN_CIRCLE) > 1 parser.ushortval('P', NOZZLE_CLEAN_DEFAULT_PATTERN) #else NOZZLE_CLEAN_DEFAULT_PATTERN #endif ); const uint8_t strokes = parser.ushortval('S', NOZZLE_CLEAN_STROKES), objects = TERN0(NOZZLE_CLEAN_PATTERN_ZIGZAG, parser.ushortval('T', NOZZLE_CLEAN_TRIANGLES)); const float radius = TERN0(NOZZLE_CLEAN_PATTERN_CIRCLE, parser.linearval('R', NOZZLE_CLEAN_CIRCLE_RADIUS)); const bool seenxyz = parser.seen("XYZ"); const uint8_t cleans = (!seenxyz || parser.boolval('X') ? _BV(X_AXIS) : 0) | (!seenxyz || parser.boolval('Y') ? _BV(Y_AXIS) : 0) | TERN(NOZZLE_CLEAN_NO_Z, 0, (!seenxyz || parser.boolval('Z') ? _BV(Z_AXIS) : 0)) ; #if HAS_LEVELING // Disable bed leveling if cleaning Z TEMPORARY_BED_LEVELING_STATE(!TEST(cleans, Z_AXIS) && planner.leveling_active); #endif SET_SOFT_ENDSTOP_LOOSE(!parser.boolval('E')); nozzle.clean(pattern, strokes, radius, objects, cleans); SET_SOFT_ENDSTOP_LOOSE(false); } #endif // NOZZLE_CLEAN_FEATURE
2301_81045437/Marlin
Marlin/src/gcode/feature/clean/G12.cpp
C++
agpl-3.0
3,182
/** * Marlin 3D Printer Firmware * Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin] * * Based on Sprinter and grbl. * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <https://www.gnu.org/licenses/>. * */ #include "../../../inc/MarlinConfigPre.h" #if ENABLED(CONTROLLER_FAN_EDITABLE) #include "../../gcode.h" #include "../../../feature/controllerfan.h" /** * M710: Set controller fan settings * * R : Reset to defaults * S[0-255] : Fan speed when motors are active * I[0-255] : Fan speed when motors are idle * A[0|1] : Turn auto mode on or off * D : Set auto mode idle duration * * Examples: * M710 ; Report current Settings * M710 R ; Reset SIAD to defaults * M710 I64 ; Set controller fan Idle Speed to 25% * M710 S255 ; Set controller fan Active Speed to 100% * M710 S0 ; Set controller fan Active Speed to OFF * M710 I255 A0 ; Set controller fan Idle Speed to 100% with Auto Mode OFF * M710 I127 A1 S255 D160 ; Set controller fan idle speed 50%, AutoMode On, Fan speed 100%, duration to 160 Secs */ void GcodeSuite::M710() { const bool seenR = parser.seen('R'); if (seenR) controllerFan.reset(); const bool seenS = parser.seenval('S'); if (seenS) controllerFan.settings.active_speed = parser.value_byte(); const bool seenI = parser.seenval('I'); if (seenI) controllerFan.settings.idle_speed = parser.value_byte(); const bool seenA = parser.seenval('A'); if (seenA) controllerFan.settings.auto_mode = parser.value_bool(); const bool seenD = parser.seenval('D'); if (seenD) controllerFan.settings.duration = parser.value_ushort(); if (!(seenR || seenS || seenI || seenA || seenD)) M710_report(); } void GcodeSuite::M710_report(const bool forReplay/*=true*/) { TERN_(MARLIN_SMALL_BUILD, return); report_heading_etc(forReplay, F(STR_CONTROLLER_FAN)); SERIAL_ECHOLNPGM(" M710" " S", int(controllerFan.settings.active_speed), " I", int(controllerFan.settings.idle_speed), " A", int(controllerFan.settings.auto_mode), " D", controllerFan.settings.duration, " ; (", (int(controllerFan.settings.active_speed) * 100) / 255, "%" " ", (int(controllerFan.settings.idle_speed) * 100) / 255, "%)" ); } #endif // CONTROLLER_FAN_EDITABLE
2301_81045437/Marlin
Marlin/src/gcode/feature/controllerfan/M710.cpp
C++
agpl-3.0
2,998
/** * Marlin 3D Printer Firmware * Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin] * * Based on Sprinter and grbl. * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <https://www.gnu.org/licenses/>. * */ #include "../../../inc/MarlinConfig.h" #if HAS_MOTOR_CURRENT_SPI || HAS_MOTOR_CURRENT_PWM || HAS_MOTOR_CURRENT_I2C || HAS_MOTOR_CURRENT_DAC #include "../../gcode.h" #if HAS_MOTOR_CURRENT_SPI || HAS_MOTOR_CURRENT_PWM #include "../../../module/stepper.h" #endif #if HAS_MOTOR_CURRENT_I2C #include "../../../feature/digipot/digipot.h" #endif #if HAS_MOTOR_CURRENT_DAC #include "../../../feature/dac/stepper_dac.h" #endif /** * M907: Set digital trimpot motor current using axis codes X [Y] [Z] [I] [J] [K] [U] [V] [W] [E] * B<current> - Special case for E1 (Requires DIGIPOTSS_PIN or DIGIPOT_MCP4018 or DIGIPOT_MCP4451) * C<current> - Special case for E2 (Requires DIGIPOTSS_PIN or DIGIPOT_MCP4018 or DIGIPOT_MCP4451) * S<current> - Set current in mA for all axes (Requires DIGIPOTSS_PIN or DIGIPOT_MCP4018 or DIGIPOT_MCP4451), or * Set percentage of max current for all axes (Requires HAS_DIGIPOT_DAC) */ void GcodeSuite::M907() { #if HAS_MOTOR_CURRENT_SPI if (!parser.seen("BS" STR_AXES_LOGICAL)) return M907_report(); if (parser.seenval('S')) for (uint8_t i = 0; i < MOTOR_CURRENT_COUNT; ++i) stepper.set_digipot_current(i, parser.value_int()); LOOP_LOGICAL_AXES(i) if (parser.seenval(IAXIS_CHAR(i))) stepper.set_digipot_current(i, parser.value_int()); // X Y Z (I J K U V W) E (map to drivers according to DIGIPOT_CHANNELS. Default with NUM_AXES 3: map X Y Z E to X Y Z E0) // Additional extruders use B,C. // TODO: Change these parameters because 'E' is used and D should be reserved for debugging. B<index>? #if E_STEPPERS >= 2 if (parser.seenval('B')) stepper.set_digipot_current(E_AXIS + 1, parser.value_int()); #if E_STEPPERS >= 3 if (parser.seenval('C')) stepper.set_digipot_current(E_AXIS + 2, parser.value_int()); #endif #endif #elif HAS_MOTOR_CURRENT_PWM #if ANY_PIN(MOTOR_CURRENT_PWM_X, MOTOR_CURRENT_PWM_Y, MOTOR_CURRENT_PWM_XY, MOTOR_CURRENT_PWM_I, MOTOR_CURRENT_PWM_J, MOTOR_CURRENT_PWM_K, MOTOR_CURRENT_PWM_U, MOTOR_CURRENT_PWM_V, MOTOR_CURRENT_PWM_W) #define HAS_X_Y_XY_I_J_K_U_V_W 1 #endif #if HAS_X_Y_XY_I_J_K_U_V_W || ANY_PIN(MOTOR_CURRENT_PWM_E, MOTOR_CURRENT_PWM_Z) if (!parser.seen("S" #if HAS_X_Y_XY_I_J_K_U_V_W "XY" SECONDARY_AXIS_GANG("I", "J", "K", "U", "V", "W") #endif #if PIN_EXISTS(MOTOR_CURRENT_PWM_Z) "Z" #endif #if PIN_EXISTS(MOTOR_CURRENT_PWM_E) "E" #endif )) return M907_report(); if (parser.seenval('S')) for (uint8_t a = 0; a < MOTOR_CURRENT_COUNT; ++a) stepper.set_digipot_current(a, parser.value_int()); #if HAS_X_Y_XY_I_J_K_U_V_W if (NUM_AXIS_GANG( parser.seenval('X'), || parser.seenval('Y'), || false, || parser.seenval('I'), || parser.seenval('J'), || parser.seenval('K'), || parser.seenval('U'), || parser.seenval('V'), || parser.seenval('W') )) stepper.set_digipot_current(0, parser.value_int()); #endif #if PIN_EXISTS(MOTOR_CURRENT_PWM_Z) if (parser.seenval('Z')) stepper.set_digipot_current(1, parser.value_int()); #endif #if PIN_EXISTS(MOTOR_CURRENT_PWM_E) if (parser.seenval('E')) stepper.set_digipot_current(2, parser.value_int()); #endif #endif #endif // HAS_MOTOR_CURRENT_PWM #if HAS_MOTOR_CURRENT_I2C // this one uses actual amps in floating point if (parser.seenval('S')) for (uint8_t q = 0; q < DIGIPOT_I2C_NUM_CHANNELS; ++q) digipot_i2c.set_current(q, parser.value_float()); LOOP_LOGICAL_AXES(i) if (parser.seenval(IAXIS_CHAR(i))) digipot_i2c.set_current(i, parser.value_float()); // X Y Z (I J K U V W) E (map to drivers according to pots adresses. Default with NUM_AXES 3 X Y Z E: map to X Y Z E0) // Additional extruders use B,C,D. // TODO: Change these parameters because 'E' is used and because 'D' should be reserved for debugging. B<index>? #if E_STEPPERS >= 2 for (uint8_t i = E_AXIS + 1; i < _MAX(DIGIPOT_I2C_NUM_CHANNELS, (NUM_AXES + 3)); i++) if (parser.seenval('B' + i - (E_AXIS + 1))) digipot_i2c.set_current(i, parser.value_float()); #endif #endif #if HAS_MOTOR_CURRENT_DAC if (parser.seenval('S')) { const float dac_percent = parser.value_float(); LOOP_LOGICAL_AXES(i) stepper_dac.set_current_percent(i, dac_percent); } LOOP_LOGICAL_AXES(i) if (parser.seenval(IAXIS_CHAR(i))) stepper_dac.set_current_percent(i, parser.value_float()); // X Y Z (I J K U V W) E (map to drivers according to DAC_STEPPER_ORDER. Default with NUM_AXES 3: X Y Z E map to X Y Z E0) #endif } #if HAS_MOTOR_CURRENT_SPI || HAS_MOTOR_CURRENT_PWM void GcodeSuite::M907_report(const bool forReplay/*=true*/) { TERN_(MARLIN_SMALL_BUILD, return); report_heading_etc(forReplay, F(STR_STEPPER_MOTOR_CURRENTS)); #if HAS_MOTOR_CURRENT_PWM SERIAL_ECHOLNPGM_P( // PWM-based has 3 values: PSTR(" M907 X"), stepper.motor_current_setting[0] // X, Y, (I, J, K, U, V, W) , SP_Z_STR, stepper.motor_current_setting[1] // Z #if PIN_EXISTS(MOTOR_CURRENT_PWM_E) , SP_E_STR, stepper.motor_current_setting[2] // E #endif ); #elif HAS_MOTOR_CURRENT_SPI SERIAL_ECHOPGM(" M907"); // SPI-based has 5 values: LOOP_LOGICAL_AXES(q) { // X Y Z (I J K U V W) E (map to X Y Z (I J K U V W) E0 by default) SERIAL_CHAR(' ', IAXIS_CHAR(q)); SERIAL_ECHO(stepper.motor_current_setting[q]); } #if E_STEPPERS >= 2 SERIAL_ECHOPGM_P(PSTR(" B"), stepper.motor_current_setting[E_AXIS + 1] // B (maps to E1 with NUM_AXES 3 according to DIGIPOT_CHANNELS) #if E_STEPPERS >= 3 , PSTR(" C"), stepper.motor_current_setting[E_AXIS + 2] // C (mapping to E2 must be defined by DIGIPOT_CHANNELS) #endif ); #endif SERIAL_EOL(); #endif } #endif // HAS_MOTOR_CURRENT_SPI || HAS_MOTOR_CURRENT_PWM #if HAS_MOTOR_CURRENT_SPI || HAS_MOTOR_CURRENT_DAC /** * M908: Control digital trimpot directly (M908 P<pin> S<current>) */ void GcodeSuite::M908() { TERN_(HAS_MOTOR_CURRENT_SPI, stepper.set_digipot_value_spi(parser.intval('P'), parser.intval('S'))); TERN_(HAS_MOTOR_CURRENT_DAC, stepper_dac.set_current_value(parser.byteval('P', -1), parser.ushortval('S', 0))); } #if HAS_MOTOR_CURRENT_DAC void GcodeSuite::M909() { stepper_dac.print_values(); } void GcodeSuite::M910() { stepper_dac.commit_eeprom(); } #endif // HAS_MOTOR_CURRENT_DAC #endif // HAS_MOTOR_CURRENT_SPI || HAS_MOTOR_CURRENT_DAC #endif // HAS_MOTOR_CURRENT_SPI || HAS_MOTOR_CURRENT_PWM || HAS_MOTOR_CURRENT_I2C || HAS_MOTOR_CURRENT_DAC
2301_81045437/Marlin
Marlin/src/gcode/feature/digipot/M907-M910.cpp
C++
agpl-3.0
7,727
/** * Marlin 3D Printer Firmware * Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin] * * Based on Sprinter and grbl. * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <https://www.gnu.org/licenses/>. * */ #include "../../../inc/MarlinConfig.h" #if ENABLED(FILAMENT_WIDTH_SENSOR) #include "../../../feature/filwidth.h" #include "../../../module/planner.h" #include "../../../MarlinCore.h" #include "../../gcode.h" /** * M404: Display or set (in current units) the nominal filament width (3mm, 1.75mm ) W<3.0> */ void GcodeSuite::M404() { if (parser.seenval('W')) { filwidth.nominal_mm = parser.value_linear_units(); planner.volumetric_area_nominal = CIRCLE_AREA(filwidth.nominal_mm * 0.5); } else SERIAL_ECHOLNPGM("Filament dia (nominal mm):", filwidth.nominal_mm); } /** * M405: Turn on filament sensor for control */ void GcodeSuite::M405() { // This is technically a linear measurement, but since it's quantized to centimeters and is a different // unit than everything else, it uses parser.value_byte() instead of parser.value_linear_units(). if (parser.seenval('D')) filwidth.set_delay_cm(parser.value_byte()); filwidth.enable(true); } /** * M406: Turn off filament sensor for control */ void GcodeSuite::M406() { filwidth.enable(false); planner.calculate_volumetric_multipliers(); // Restore correct 'volumetric_multiplier' value } /** * M407: Get measured filament diameter on serial output */ void GcodeSuite::M407() { SERIAL_ECHOLNPGM("Filament dia (measured mm):", filwidth.measured_mm); } #endif // FILAMENT_WIDTH_SENSOR
2301_81045437/Marlin
Marlin/src/gcode/feature/filwidth/M404-M407.cpp
C++
agpl-3.0
2,243
/** * Marlin 3D Printer Firmware * Copyright (c) 2023 MarlinFirmware [https://github.com/MarlinFirmware/Marlin] * * Based on Sprinter and grbl. * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <https://www.gnu.org/licenses/>. * */ #include "../../../inc/MarlinConfig.h" #if ENABLED(FT_MOTION) #include "../../gcode.h" #include "../../../module/ft_motion.h" #include "../../../module/stepper.h" void say_shaping() { // FT Enabled SERIAL_ECHO_TERNARY(ftMotion.cfg.mode, "Fixed-Time Motion ", "en", "dis", "abled"); // FT Shaping #if HAS_X_AXIS if (ftMotion.cfg.mode > ftMotionMode_ENABLED) { SERIAL_ECHOPGM(" with "); switch (ftMotion.cfg.mode) { default: break; case ftMotionMode_ZV: SERIAL_ECHOPGM("ZV"); break; case ftMotionMode_ZVD: SERIAL_ECHOPGM("ZVD"); break; case ftMotionMode_ZVDD: SERIAL_ECHOPGM("ZVDD"); break; case ftMotionMode_ZVDDD: SERIAL_ECHOPGM("ZVDDD"); break; case ftMotionMode_EI: SERIAL_ECHOPGM("EI"); break; case ftMotionMode_2HEI: SERIAL_ECHOPGM("2 Hump EI"); break; case ftMotionMode_3HEI: SERIAL_ECHOPGM("3 Hump EI"); break; case ftMotionMode_MZV: SERIAL_ECHOPGM("MZV"); break; //case ftMotionMode_DISCTF: SERIAL_ECHOPGM("discrete transfer functions"); break; //case ftMotionMode_ULENDO_FBS: SERIAL_ECHOPGM("Ulendo FBS."); return; } SERIAL_ECHOPGM(" shaping"); } #endif SERIAL_ECHOLNPGM("."); const bool z_based = TERN0(HAS_DYNAMIC_FREQ_MM, ftMotion.cfg.dynFreqMode == dynFreqMode_Z_BASED), g_based = TERN0(HAS_DYNAMIC_FREQ_G, ftMotion.cfg.dynFreqMode == dynFreqMode_MASS_BASED), dynamic = z_based || g_based; // FT Dynamic Frequency Mode if (ftMotion.cfg.modeHasShaper()) { #if HAS_DYNAMIC_FREQ SERIAL_ECHOPGM("Dynamic Frequency Mode "); switch (ftMotion.cfg.dynFreqMode) { default: case dynFreqMode_DISABLED: SERIAL_ECHOPGM("disabled"); break; #if HAS_DYNAMIC_FREQ_MM case dynFreqMode_Z_BASED: SERIAL_ECHOPGM("Z-based"); break; #endif #if HAS_DYNAMIC_FREQ_G case dynFreqMode_MASS_BASED: SERIAL_ECHOPGM("Mass-based"); break; #endif } SERIAL_ECHOLNPGM("."); #endif #if HAS_X_AXIS SERIAL_ECHO_TERNARY(dynamic, "X/A ", "base dynamic", "static", " compensator frequency: "); SERIAL_ECHO(p_float_t(ftMotion.cfg.baseFreq[X_AXIS], 2), F("Hz")); #if HAS_DYNAMIC_FREQ if (dynamic) SERIAL_ECHO(F(" scaling: "), p_float_t(ftMotion.cfg.dynFreqK[X_AXIS], 2), F("Hz/"), z_based ? F("mm") : F("g")); #endif SERIAL_EOL(); #endif #if HAS_Y_AXIS SERIAL_ECHO_TERNARY(dynamic, "Y/B ", "base dynamic", "static", " compensator frequency: "); SERIAL_ECHO(p_float_t(ftMotion.cfg.baseFreq[Y_AXIS], 2), F(" Hz")); #if HAS_DYNAMIC_FREQ if (dynamic) SERIAL_ECHO(F(" scaling: "), p_float_t(ftMotion.cfg.dynFreqK[Y_AXIS], 2), F("Hz/"), z_based ? F("mm") : F("g")); #endif SERIAL_EOL(); #endif } #if HAS_EXTRUDERS SERIAL_ECHO_TERNARY(ftMotion.cfg.linearAdvEna, "Linear Advance ", "en", "dis", "abled"); if (ftMotion.cfg.linearAdvEna) SERIAL_ECHOLNPGM(". Gain: ", ftMotion.cfg.linearAdvK); else SERIAL_EOL(); #endif } void GcodeSuite::M493_report(const bool forReplay/*=true*/) { TERN_(MARLIN_SMALL_BUILD, return); report_heading_etc(forReplay, F(STR_FT_MOTION)); const ft_config_t &c = ftMotion.cfg; SERIAL_ECHOPGM(" M493 S", c.mode); #if HAS_X_AXIS SERIAL_ECHOPGM(" A", c.baseFreq[X_AXIS]); #if HAS_Y_AXIS SERIAL_ECHOPGM(" B", c.baseFreq[Y_AXIS]); #endif #endif #if HAS_DYNAMIC_FREQ SERIAL_ECHOPGM(" D", c.dynFreqMode); #if HAS_X_AXIS SERIAL_ECHOPGM(" F", c.dynFreqK[X_AXIS]); #if HAS_Y_AXIS SERIAL_ECHOPGM(" H", c.dynFreqK[Y_AXIS]); #endif #endif #endif #if HAS_EXTRUDERS SERIAL_ECHOPGM(" P", c.linearAdvEna, " K", c.linearAdvK); #endif SERIAL_EOL(); } /** * M493: Set Fixed-time Motion Control parameters * * S<mode> Set the motion / shaping mode. Shaping requires an X axis, at the minimum. * * 0: Standard Motion * 1: Fixed-Time Motion * 10: ZV : Zero Vibration * 11: ZVD : Zero Vibration and Derivative * 12: ZVDD : Zero Vibration, Derivative, and Double Derivative * 13: ZVDDD : Zero Vibration, Derivative, Double Derivative, and Triple Derivative * 14: EI : Extra-Intensive * 15: 2HEI : 2-Hump Extra-Intensive * 16: 3HEI : 3-Hump Extra-Intensive * 17: MZV : Mass-based Zero Vibration * * P<bool> Enable (1) or Disable (0) Linear Advance pressure control * * K<gain> Set Linear Advance gain * * D<mode> Set Dynamic Frequency mode * 0: DISABLED * 1: Z-based (Requires a Z axis) * 2: Mass-based (Requires X and E axes) * * A<Hz> Set static/base frequency for the X axis * F<Hz> Set frequency scaling for the X axis * I 0.0 Set damping ratio for the X axis * Q 0.00 Set the vibration tolerance for the X axis * * B<Hz> Set static/base frequency for the Y axis * H<Hz> Set frequency scaling for the Y axis * J 0.0 Set damping ratio for the Y axis * R 0.00 Set the vibration tolerance for the Y axis */ void GcodeSuite::M493() { struct { bool update_n:1, update_a:1, reset_ft:1, report_h:1; } flag = { false }; if (!parser.seen_any()) flag.report_h = true; // Parse 'S' mode parameter. if (parser.seenval('S')) { const ftMotionMode_t newmm = (ftMotionMode_t)parser.value_byte(); if (newmm != ftMotion.cfg.mode) { switch (newmm) { default: SERIAL_ECHOLNPGM("?Invalid control mode [S] value."); return; #if HAS_X_AXIS case ftMotionMode_ZV: case ftMotionMode_ZVD: case ftMotionMode_ZVDD: case ftMotionMode_ZVDDD: case ftMotionMode_EI: case ftMotionMode_2HEI: case ftMotionMode_3HEI: case ftMotionMode_MZV: //case ftMotionMode_ULENDO_FBS: //case ftMotionMode_DISCTF: flag.update_n = flag.update_a = true; #endif case ftMotionMode_DISABLED: flag.reset_ft = true; case ftMotionMode_ENABLED: ftMotion.cfg.mode = newmm; flag.report_h = true; break; } } } #if HAS_EXTRUDERS // Pressure control (linear advance) parameter. if (parser.seen('P')) { const bool val = parser.value_bool(); ftMotion.cfg.linearAdvEna = val; flag.report_h = true; SERIAL_ECHO_TERNARY(val, "Linear Advance ", "en", "dis", "abled.\n"); } // Pressure control (linear advance) gain parameter. if (parser.seenval('K')) { const float val = parser.value_float(); if (val >= 0.0f) { ftMotion.cfg.linearAdvK = val; flag.report_h = true; } else // Value out of range. SERIAL_ECHOLNPGM("Linear Advance gain out of range."); } #endif // HAS_EXTRUDERS #if HAS_DYNAMIC_FREQ // Dynamic frequency mode parameter. if (parser.seenval('D')) { if (ftMotion.cfg.modeHasShaper()) { const dynFreqMode_t val = dynFreqMode_t(parser.value_byte()); switch (val) { #if HAS_DYNAMIC_FREQ_MM case dynFreqMode_Z_BASED: #endif #if HAS_DYNAMIC_FREQ_G case dynFreqMode_MASS_BASED: #endif case dynFreqMode_DISABLED: ftMotion.cfg.dynFreqMode = val; flag.report_h = true; break; default: SERIAL_ECHOLNPGM("?Invalid Dynamic Frequency Mode [D] value."); break; } } else { SERIAL_ECHOLNPGM("?Wrong shaper for [D] Dynamic Frequency mode."); } } const bool modeUsesDynFreq = ( TERN0(HAS_DYNAMIC_FREQ_MM, ftMotion.cfg.dynFreqMode == dynFreqMode_Z_BASED) || TERN0(HAS_DYNAMIC_FREQ_G, ftMotion.cfg.dynFreqMode == dynFreqMode_MASS_BASED) ); #endif // HAS_DYNAMIC_FREQ #if HAS_X_AXIS // Parse frequency parameter (X axis). if (parser.seenval('A')) { if (ftMotion.cfg.modeHasShaper()) { const float val = parser.value_float(); // TODO: Frequency minimum is dependent on the shaper used; the above check isn't always correct. if (WITHIN(val, FTM_MIN_SHAPE_FREQ, (FTM_FS) / 2)) { ftMotion.cfg.baseFreq[X_AXIS] = val; flag.update_n = flag.reset_ft = flag.report_h = true; } else // Frequency out of range. SERIAL_ECHOLNPGM("Invalid [", C('A'), "] frequency value."); } else // Mode doesn't use frequency. SERIAL_ECHOLNPGM("Wrong mode for [", C('A'), "] frequency."); } #if HAS_DYNAMIC_FREQ // Parse frequency scaling parameter (X axis). if (parser.seenval('F')) { if (modeUsesDynFreq) { ftMotion.cfg.dynFreqK[X_AXIS] = parser.value_float(); flag.report_h = true; } else SERIAL_ECHOLNPGM("Wrong mode for [", C('F'), "] frequency scaling."); } #endif // Parse zeta parameter (X axis). if (parser.seenval('I')) { const float val = parser.value_float(); if (ftMotion.cfg.modeHasShaper()) { if (WITHIN(val, 0.01f, 1.0f)) { ftMotion.cfg.zeta[0] = val; flag.update_n = flag.update_a = true; } else SERIAL_ECHOLNPGM("Invalid X zeta [", C('I'), "] value."); // Zeta out of range. } else SERIAL_ECHOLNPGM("Wrong mode for zeta parameter."); } // Parse vtol parameter (X axis). if (parser.seenval('Q')) { const float val = parser.value_float(); if (ftMotion.cfg.modeHasShaper() && IS_EI_MODE(ftMotion.cfg.mode)) { if (WITHIN(val, 0.00f, 1.0f)) { ftMotion.cfg.vtol[0] = val; flag.update_a = true; } else SERIAL_ECHOLNPGM("Invalid X vtol [", C('Q'), "] value."); // VTol out of range. } else SERIAL_ECHOLNPGM("Wrong mode for vtol parameter."); } #endif // HAS_X_AXIS #if HAS_Y_AXIS // Parse frequency parameter (Y axis). if (parser.seenval('B')) { if (ftMotion.cfg.modeHasShaper()) { const float val = parser.value_float(); if (WITHIN(val, FTM_MIN_SHAPE_FREQ, (FTM_FS) / 2)) { ftMotion.cfg.baseFreq[Y_AXIS] = val; flag.update_n = flag.reset_ft = flag.report_h = true; } else // Frequency out of range. SERIAL_ECHOLNPGM("Invalid frequency [", C('B'), "] value."); } else // Mode doesn't use frequency. SERIAL_ECHOLNPGM("Wrong mode for [", C('B'), "] frequency."); } #if HAS_DYNAMIC_FREQ // Parse frequency scaling parameter (Y axis). if (parser.seenval('H')) { if (modeUsesDynFreq) { ftMotion.cfg.dynFreqK[Y_AXIS] = parser.value_float(); flag.report_h = true; } else SERIAL_ECHOLNPGM("Wrong mode for [", C('H'), "] frequency scaling."); } #endif // Parse zeta parameter (Y axis). if (parser.seenval('J')) { const float val = parser.value_float(); if (ftMotion.cfg.modeHasShaper()) { if (WITHIN(val, 0.01f, 1.0f)) { ftMotion.cfg.zeta[1] = val; flag.update_n = flag.update_a = true; } else SERIAL_ECHOLNPGM("Invalid Y zeta [", C('J'), "] value."); // Zeta Out of range } else SERIAL_ECHOLNPGM("Wrong mode for zeta parameter."); } // Parse vtol parameter (Y axis). if (parser.seenval('R')) { const float val = parser.value_float(); if (ftMotion.cfg.modeHasShaper() && IS_EI_MODE(ftMotion.cfg.mode)) { if (WITHIN(val, 0.00f, 1.0f)) { ftMotion.cfg.vtol[1] = val; flag.update_a = true; } else SERIAL_ECHOLNPGM("Invalid Y vtol [", C('R'), "] value."); // VTol out of range. } else SERIAL_ECHOLNPGM("Wrong mode for vtol parameter."); } #endif // HAS_Y_AXIS planner.synchronize(); if (flag.update_n) ftMotion.refreshShapingN(); if (flag.update_a) ftMotion.updateShapingA(); if (flag.reset_ft) { stepper.ftMotion_syncPosition(); ftMotion.reset(); } if (flag.report_h) say_shaping(); } #endif // FT_MOTION
2301_81045437/Marlin
Marlin/src/gcode/feature/ft_motion/M493.cpp
C++
agpl-3.0
13,091
/** * Marlin 3D Printer Firmware * Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin] * * Based on Sprinter and grbl. * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <https://www.gnu.org/licenses/>. * */ #include "../../../inc/MarlinConfig.h" #if ENABLED(FWRETRACT) #include "../../../feature/fwretract.h" #include "../../gcode.h" #include "../../../module/motion.h" /** * G10 - Retract filament according to settings of M207 * TODO: Handle 'G10 P' for tool settings and 'G10 L' for workspace settings */ void GcodeSuite::G10() { fwretract.retract(true E_OPTARG(parser.boolval('S'))); } /** * G11 - Recover filament according to settings of M208 */ void GcodeSuite::G11() { fwretract.retract(false); } #endif // FWRETRACT
2301_81045437/Marlin
Marlin/src/gcode/feature/fwretract/G10_G11.cpp
C++
agpl-3.0
1,397
/** * Marlin 3D Printer Firmware * Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin] * * Based on Sprinter and grbl. * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <https://www.gnu.org/licenses/>. * */ #include "../../../inc/MarlinConfig.h" #if ENABLED(FWRETRACT) #include "../../../feature/fwretract.h" #include "../../gcode.h" /** * M207: Set firmware retraction values * * S[+units] retract_length * W[+units] swap_retract_length (multi-extruder) * F[units/min] retract_feedrate_mm_s * Z[units] retract_zraise */ void GcodeSuite::M207() { fwretract.M207(); } void GcodeSuite::M207_report(const bool forReplay/*=true*/) { TERN_(MARLIN_SMALL_BUILD, return); report_heading_etc(forReplay, F(STR_RETRACT_S_F_Z)); fwretract.M207_report(); } /** * M208: Set firmware un-retraction values * * S[+units] retract_recover_extra (in addition to M207 S*) * W[+units] swap_retract_recover_extra (multi-extruder) * F[units/min] retract_recover_feedrate_mm_s * R[units/min] swap_retract_recover_feedrate_mm_s */ void GcodeSuite::M208() { fwretract.M208(); } void GcodeSuite::M208_report(const bool forReplay/*=true*/) { TERN_(MARLIN_SMALL_BUILD, return); report_heading_etc(forReplay, F(STR_RECOVER_S_F)); fwretract.M208_report(); } #if ENABLED(FWRETRACT_AUTORETRACT) /** * M209: Enable automatic retract (M209 S1) * * For slicers that don't support G10/11, reversed * extruder-only moves can be classified as retraction. */ void GcodeSuite::M209() { fwretract.M209(); } void GcodeSuite::M209_report(const bool forReplay/*=true*/) { TERN_(MARLIN_SMALL_BUILD, return); report_heading_etc(forReplay, F(STR_AUTO_RETRACT_S)); fwretract.M209_report(); } #endif #endif // FWRETRACT
2301_81045437/Marlin
Marlin/src/gcode/feature/fwretract/M207-M209.cpp
C++
agpl-3.0
2,436
/** * Marlin 3D Printer Firmware * Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin] * * Based on Sprinter and grbl. * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <https://www.gnu.org/licenses/>. * */ #include "../../../inc/MarlinConfig.h" #if ENABLED(EXPERIMENTAL_I2CBUS) #include "../../gcode.h" #include "../../../feature/twibus.h" /** * M260: Send data to a I2C slave device * * This is a PoC, the formatting and arguments for the GCODE will * change to be more compatible, the current proposal is: * * M260 A<slave device address base 10> ; Sets the I2C slave address the data will be sent to * * M260 B<byte-1 value in base 10> * M260 B<byte-2 value in base 10> * M260 B<byte-3 value in base 10> * * M260 S1 ; Send the buffered data and reset the buffer * M260 R1 ; Reset the buffer without sending data */ void GcodeSuite::M260() { // Set the target address if (parser.seenval('A')) i2c.address(parser.value_byte()); // Add a new byte to the buffer if (parser.seenval('B')) i2c.addbyte(parser.value_byte()); // Flush the buffer to the bus if (parser.seen('S')) i2c.send(); // Reset and rewind the buffer else if (parser.seen('R')) i2c.reset(); } /** * M261: Request X bytes from I2C slave device * * Usage: M261 A<slave device address base 10> B<number of bytes> S<style> */ void GcodeSuite::M261() { if (parser.seenval('A')) i2c.address(parser.value_byte()); const uint8_t bytes = parser.byteval('B', 1), // Bytes to request style = parser.byteval('S'); // Serial output style (ASCII, HEX etc) if (i2c.addr && bytes && bytes <= TWIBUS_BUFFER_SIZE) i2c.relay(bytes, style); else SERIAL_ERROR_MSG("Bad i2c request"); } #endif
2301_81045437/Marlin
Marlin/src/gcode/feature/i2c/M260_M261.cpp
C++
agpl-3.0
2,384
/** * Marlin 3D Printer Firmware * Copyright (c) 2022 MarlinFirmware [https://github.com/MarlinFirmware/Marlin] * * Based on Sprinter and grbl. * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <https://www.gnu.org/licenses/>. * */ #include "../../../inc/MarlinConfig.h" #if HAS_ZV_SHAPING #include "../../gcode.h" #include "../../../module/stepper.h" void GcodeSuite::M593_report(const bool forReplay/*=true*/) { TERN_(MARLIN_SMALL_BUILD, return); report_heading_etc(forReplay, F("Input Shaping")); #if ENABLED(INPUT_SHAPING_X) SERIAL_ECHOLNPGM(" M593 X" " F", stepper.get_shaping_frequency(X_AXIS), " D", stepper.get_shaping_damping_ratio(X_AXIS) ); #endif #if ENABLED(INPUT_SHAPING_Y) TERN_(INPUT_SHAPING_X, report_echo_start(forReplay)); SERIAL_ECHOLNPGM(" M593 Y" " F", stepper.get_shaping_frequency(Y_AXIS), " D", stepper.get_shaping_damping_ratio(Y_AXIS) ); #endif } /** * M593: Get or Set Input Shaping Parameters * D<factor> Set the zeta/damping factor. If axes (X, Y, etc.) are not specified, set for all axes. * F<frequency> Set the frequency. If axes (X, Y, etc.) are not specified, set for all axes. * T[map] Input Shaping type, 0:ZV, 1:EI, 2:2H EI (not implemented yet) * X Set the given parameters only for the X axis. * Y Set the given parameters only for the Y axis. */ void GcodeSuite::M593() { if (!parser.seen_any()) return M593_report(); const bool seen_X = TERN0(INPUT_SHAPING_X, parser.seen_test('X')), seen_Y = TERN0(INPUT_SHAPING_Y, parser.seen_test('Y')), for_X = seen_X || TERN0(INPUT_SHAPING_X, (!seen_X && !seen_Y)), for_Y = seen_Y || TERN0(INPUT_SHAPING_Y, (!seen_X && !seen_Y)); if (parser.seen('D')) { const float zeta = parser.value_float(); if (WITHIN(zeta, 0, 1)) { if (for_X) stepper.set_shaping_damping_ratio(X_AXIS, zeta); if (for_Y) stepper.set_shaping_damping_ratio(Y_AXIS, zeta); } else SERIAL_ECHO_MSG("?Zeta (D) value out of range (0-1)"); } if (parser.seen('F')) { const float freq = parser.value_float(); constexpr float min_freq = float(uint32_t(STEPPER_TIMER_RATE) / 2) / shaping_time_t(-2); if (freq == 0.0f || freq > min_freq) { if (for_X) stepper.set_shaping_frequency(X_AXIS, freq); if (for_Y) stepper.set_shaping_frequency(Y_AXIS, freq); } else SERIAL_ECHOLNPGM(GCODE_ERR_MSG("Frequency (F) must be greater than ", min_freq, " or 0 to disable")); } } #endif
2301_81045437/Marlin
Marlin/src/gcode/feature/input_shaping/M593.cpp
C++
agpl-3.0
3,174
/** * Marlin 3D Printer Firmware * Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin] * * Based on Sprinter and grbl. * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <https://www.gnu.org/licenses/>. * */ #include "../../../inc/MarlinConfig.h" #if HAS_COLOR_LEDS #include "../../gcode.h" #include "../../../feature/leds/leds.h" /** * M150: Set Status LED Color - Use R-U-B-W for R-G-B-W * and Brightness - Use P (for NEOPIXEL only) * * Always sets all 3 or 4 components unless the K flag is specified. * If a component is left out, set to 0. * If brightness is left out, no value changed. * * With NEOPIXEL_LED: * I<index> Set the NeoPixel index to affect. Default: All * K Keep all unspecified values unchanged instead of setting to 0. * * With NEOPIXEL2_SEPARATE: * S<index> The NeoPixel strip to set. Default: All. * * Examples: * * M150 R255 ; Turn LED red * M150 R255 U127 ; Turn LED orange (PWM only) * M150 ; Turn LED off * M150 R U B ; Turn LED white * M150 W ; Turn LED white using a white LED * M150 P127 ; Set LED 50% brightness * M150 P ; Set LED full brightness * M150 I1 R ; Set NEOPIXEL index 1 to red * M150 S1 I1 R ; Set SEPARATE index 1 to red * M150 K R127 ; Set LED red to 50% without changing blue or green */ void GcodeSuite::M150() { int32_t old_color = 0; #if ENABLED(NEOPIXEL_LED) const pixel_index_t index = parser.intval('I', -1); const bool seenK = parser.seen_test('K'); #if ENABLED(NEOPIXEL2_SEPARATE) #ifndef NEOPIXEL_M150_DEFAULT #define NEOPIXEL_M150_DEFAULT -1 #elif NEOPIXEL_M150_DEFAULT > 1 #error "NEOPIXEL_M150_DEFAULT must be -1, 0, or 1." #endif int8_t brightness = neo.brightness(), unit = parser.intval('S', NEOPIXEL_M150_DEFAULT); switch (unit) { case -1: neo2.neoindex = index; // fall-thru case 0: neo.neoindex = index; old_color = seenK ? neo.pixel_color(_MAX(index, 0)) : 0; break; case 1: neo2.neoindex = index; brightness = neo2.brightness(); old_color = seenK ? neo2.pixel_color(_MAX(index, 0)) : 0; break; } #else const uint8_t brightness = neo.brightness(); neo.neoindex = index; old_color = seenK ? neo.pixel_color(_MAX(index, 0)) : 0; #endif #endif const LEDColor color = LEDColor( parser.seen('R') ? (parser.has_value() ? parser.value_byte() : 255) : (old_color >> 16) & 0xFF, parser.seen('U') ? (parser.has_value() ? parser.value_byte() : 255) : (old_color >> 8) & 0xFF, parser.seen('B') ? (parser.has_value() ? parser.value_byte() : 255) : old_color & 0xFF OPTARG(HAS_WHITE_LED, parser.seen('W') ? (parser.has_value() ? parser.value_byte() : 255) : (old_color >> 24) & 0xFF) OPTARG(NEOPIXEL_LED, parser.seen('P') ? (parser.has_value() ? parser.value_byte() : 255) : brightness) ); #if ENABLED(NEOPIXEL2_SEPARATE) switch (unit) { case 0: leds.set_color(color); return; case 1: leds2.set_color(color); return; } #endif // If 'S' is not specified use both leds.set_color(color); TERN_(NEOPIXEL2_SEPARATE, leds2.set_color(color)); } #endif // HAS_COLOR_LEDS
2301_81045437/Marlin
Marlin/src/gcode/feature/leds/M150.cpp
C++
agpl-3.0
3,945
/** * Marlin 3D Printer Firmware * Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin] * * Based on Sprinter and grbl. * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <https://www.gnu.org/licenses/>. * */ #include "../../../inc/MarlinConfigPre.h" #if ENABLED(MAX7219_GCODE) #include "../../gcode.h" #include "../../../feature/max7219.h" /** * M7219: Control the Max7219 LED matrix * * I - Initialize (clear) the matrix * F - Fill the matrix (set all bits) * P - Dump the led_line[] array values * C<column> - Set a column to the bitmask given by 'V' (Units 0-3 in portrait layout) * R<row> - Set a row to the bitmask given by 'V' (Units 0-3 in landscape layout) * X<pos> - X index of an LED to set or toggle * Y<pos> - Y index of an LED to set or toggle * V<value> - LED on/off state or row/column bitmask (8, 16, 24, or 32-bits) * ('C' / 'R' can be used to update up to 4 units at once) * * Directly set a native matrix row to the 8-bit value 'V': * D<line> - Display line (0..7) * U<unit> - Unit index (0..MAX7219_NUMBER_UNITS-1) */ void GcodeSuite::M7219() { if (parser.seen('I')) { max7219.register_setup(); max7219.clear(); } if (parser.seen('F')) max7219.fill(); const uint32_t v = parser.ulongval('V'); if (parser.seenval('R')) { const uint8_t r = parser.value_byte(); max7219.set_row(r, v); } else if (parser.seenval('C')) { const uint8_t c = parser.value_byte(); max7219.set_column(c, v); } else if (parser.seenval('X') || parser.seenval('Y')) { const uint8_t x = parser.byteval('X'), y = parser.byteval('Y'); if (parser.seenval('V')) max7219.led_set(x, y, v > 0); else max7219.led_toggle(x, y); } else if (parser.seen('D')) { const uint8_t uline = parser.value_byte() & 0x7, line = uline + (parser.byteval('U') << 3); if (line < MAX7219_LINES) { max7219.led_line[line] = v; return max7219.refresh_line(line); } } if (parser.seen('P')) { for (uint8_t r = 0; r < MAX7219_LINES; ++r) { SERIAL_ECHOPGM("led_line["); if (r < 10) SERIAL_CHAR(' '); SERIAL_ECHO(r); SERIAL_ECHOPGM("]="); for (uint8_t b = 8; b--;) SERIAL_CHAR('0' + TEST(max7219.led_line[r], b)); SERIAL_EOL(); } } } #endif // MAX7219_GCODE
2301_81045437/Marlin
Marlin/src/gcode/feature/leds/M7219.cpp
C++
agpl-3.0
3,014
/** * Marlin 3D Printer Firmware * Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin] * * Based on Sprinter and grbl. * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <https://www.gnu.org/licenses/>. * */ #include "../../../inc/MarlinConfig.h" #if ENABLED(GCODE_MACROS) #include "../../gcode.h" #include "../../queue.h" #include "../../parser.h" char gcode_macros[GCODE_MACROS_SLOTS][GCODE_MACROS_SLOT_SIZE + 1] = {{ 0 }}; /** * M810_819: Set/execute a G-code macro. * * Usage: * M810 <command>|... Set Macro 0 to the given commands, separated by the pipe character * M810 Execute Macro 0 */ void GcodeSuite::M810_819() { const uint8_t index = parser.codenum - 810; if (index >= GCODE_MACROS_SLOTS) return; const size_t len = strlen(parser.string_arg); if (len) { // Set a macro if (len > GCODE_MACROS_SLOT_SIZE) SERIAL_ERROR_MSG("Macro too long."); else { char c, *s = parser.string_arg, *d = gcode_macros[index]; do { c = *s++; *d++ = c == '|' ? '\n' : c; } while (c); } } else { // Execute a macro char * const cmd = gcode_macros[index]; if (strlen(cmd)) process_subcommands_now(cmd); } } #endif // GCODE_MACROS
2301_81045437/Marlin
Marlin/src/gcode/feature/macro/M810-M819.cpp
C++
agpl-3.0
1,890
/** * Marlin 3D Printer Firmware * Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin] * * Based on Sprinter and grbl. * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <https://www.gnu.org/licenses/>. * */ #include "../../../inc/MarlinConfig.h" #if ENABLED(MIXING_EXTRUDER) #include "../../gcode.h" #include "../../../feature/mixing.h" /** * M163: Set a single mix factor for a mixing extruder * This is called "weight" by some systems. * Must be followed by M164 to normalize and commit them. * * S[index] The channel index to set * P[float] The mix value */ void GcodeSuite::M163() { const int mix_index = parser.intval('S'); if (mix_index < MIXING_STEPPERS) mixer.set_collector(mix_index, parser.floatval('P')); } /** * M164: Normalize and commit the mix. * * S[index] The virtual tool to store * If 'S' is omitted update the active virtual tool. */ void GcodeSuite::M164() { #if MIXING_VIRTUAL_TOOLS > 1 const int tool_index = parser.intval('S', -1); #else constexpr int tool_index = 0; #endif if (tool_index >= 0) { if (tool_index < MIXING_VIRTUAL_TOOLS) mixer.normalize(tool_index); } else mixer.normalize(); } #if ENABLED(DIRECT_MIXING_IN_G1) /** * M165: Set multiple mix factors for a mixing extruder. * Omitted factors will be set to 0. * The mix is normalized and stored in the current virtual tool. * * A[factor] Mix factor for extruder stepper 1 * B[factor] Mix factor for extruder stepper 2 * C[factor] Mix factor for extruder stepper 3 * D[factor] Mix factor for extruder stepper 4 * H[factor] Mix factor for extruder stepper 5 * I[factor] Mix factor for extruder stepper 6 */ void GcodeSuite::M165() { // Get mixing parameters from the G-Code // The total "must" be 1.0 (but it will be normalized) // If no mix factors are given, the old mix is preserved const char mixing_codes[] = { LIST_N(MIXING_STEPPERS, 'A', 'B', 'C', 'D', 'H', 'I') }; uint8_t mix_bits = 0; MIXER_STEPPER_LOOP(i) { if (parser.seenval(mixing_codes[i])) { SBI(mix_bits, i); mixer.set_collector(i, parser.value_float()); } } // If any mixing factors were included, clear the rest // If none were included, preserve the last mix if (mix_bits) { MIXER_STEPPER_LOOP(i) if (!TEST(mix_bits, i)) mixer.set_collector(i, 0.0f); mixer.normalize(); } } #endif // DIRECT_MIXING_IN_G1 #endif // MIXING_EXTRUDER
2301_81045437/Marlin
Marlin/src/gcode/feature/mixing/M163-M165.cpp
C++
agpl-3.0
3,195
/** * Marlin 3D Printer Firmware * Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin] * * Based on Sprinter and grbl. * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <https://www.gnu.org/licenses/>. * */ #include "../../../inc/MarlinConfig.h" #if ENABLED(GRADIENT_MIX) #include "../../gcode.h" #include "../../../module/motion.h" #include "../../../module/planner.h" #include "../../../feature/mixing.h" inline void echo_mix() { SERIAL_ECHOPGM(" (", mixer.mix[0], "%|", mixer.mix[1], "%)"); } inline void echo_zt(const int t, const_float_t z) { mixer.update_mix_from_vtool(t); SERIAL_ECHOPGM_P(SP_Z_STR, z, SP_T_STR, t); echo_mix(); } /** * M166: Set a simple gradient mix for a two-component mixer * based on the Geeetech A10M implementation by Jone Liu. * * S[bool] - Enable / disable gradients * A[float] - Starting Z for the gradient * Z[float] - Ending Z for the gradient. (Must be greater than the starting Z.) * I[index] - V-Tool to use as the starting mix. * J[index] - V-Tool to use as the ending mix. * * T[index] - A V-Tool index to use as an alias for the Gradient (Requires GRADIENT_VTOOL) * T with no index clears the setting. Note: This can match the I or J value. * * Example: M166 S1 A0 Z20 I0 J1 */ void GcodeSuite::M166() { if (parser.seenval('A')) mixer.gradient.start_z = parser.value_float(); if (parser.seenval('Z')) mixer.gradient.end_z = parser.value_float(); if (parser.seenval('I')) mixer.gradient.start_vtool = (uint8_t)constrain(parser.value_int(), 0, MIXING_VIRTUAL_TOOLS); if (parser.seenval('J')) mixer.gradient.end_vtool = (uint8_t)constrain(parser.value_int(), 0, MIXING_VIRTUAL_TOOLS); #if ENABLED(GRADIENT_VTOOL) if (parser.seen('T')) mixer.gradient.vtool_index = parser.byteval('T', -1); #endif if (parser.seen('S')) mixer.gradient.enabled = parser.value_bool(); mixer.refresh_gradient(); SERIAL_ECHOPGM("Gradient Mix "); serialprint_onoff(mixer.gradient.enabled); if (mixer.gradient.enabled) { #if ENABLED(GRADIENT_VTOOL) if (mixer.gradient.vtool_index >= 0) { SERIAL_ECHOPGM(" (T", mixer.gradient.vtool_index); SERIAL_CHAR(')'); } #endif SERIAL_ECHOPGM(" ; Start"); echo_zt(mixer.gradient.start_vtool, mixer.gradient.start_z); SERIAL_ECHOPGM(" ; End"); echo_zt(mixer.gradient.end_vtool, mixer.gradient.end_z); mixer.update_mix_from_gradient(); SERIAL_ECHOPGM(" ; Current Z"); #if ENABLED(DELTA) get_cartesian_from_steppers(); SERIAL_ECHO(cartes.z); #else SERIAL_ECHO(planner.get_axis_position_mm(Z_AXIS)); #endif echo_mix(); } SERIAL_EOL(); } #endif // GRADIENT_MIX
2301_81045437/Marlin
Marlin/src/gcode/feature/mixing/M166.cpp
C++
agpl-3.0
3,358
/** * Marlin 3D Printer Firmware * Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin] * * Based on Sprinter and grbl. * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <https://www.gnu.org/licenses/>. * */ #include "../../../inc/MarlinConfigPre.h" #if HAS_ETHERNET #include "../../../feature/ethernet.h" #include "../../../core/serial.h" #include "../../gcode.h" void say_ethernet() { SERIAL_ECHOPGM(" Ethernet "); } void ETH0_report() { say_ethernet(); SERIAL_ECHO_TERNARY(ethernet.hardware_enabled, "port ", "en", "dis", "abled.\n"); if (ethernet.hardware_enabled) { say_ethernet(); SERIAL_ECHO_TERNARY(ethernet.have_telnet_client, "client ", "en", "dis", "abled.\n"); } else SERIAL_ECHOLNPGM("Send 'M552 S1' to enable."); } void MAC_report() { uint8_t mac[6]; if (ethernet.hardware_enabled) { Ethernet.MACAddress(mac); SERIAL_ECHOPGM(" MAC: "); for (uint8_t i = 0; i < 6; ++i) { if (mac[i] < 16) SERIAL_CHAR('0'); SERIAL_PRINT(mac[i], PrintBase::Hex); if (i < 5) SERIAL_CHAR(':'); } } SERIAL_EOL(); } // Display current values when the link is active, // otherwise show the stored values void ip_report(const uint16_t cmd, FSTR_P const post, const IPAddress &ipo) { SERIAL_CHAR('M'); SERIAL_ECHO(cmd); SERIAL_CHAR(' '); for (uint8_t i = 0; i < 4; ++i) { SERIAL_ECHO(ipo[i]); if (i < 3) SERIAL_CHAR('.'); } SERIAL_ECHOLN(F(" ; "), post); } /** * M552: Set IP address, enable/disable network interface * * S0 : disable networking * S1 : enable networking * S-1 : reset network interface * * Pnnn : Set IP address, 0.0.0.0 means acquire an IP address using DHCP */ void GcodeSuite::M552() { const bool seenP = parser.seenval('P'); if (seenP) ethernet.ip.fromString(parser.value_string()); const bool seenS = parser.seenval('S'); if (seenS) { switch (parser.value_int()) { case -1: if (ethernet.telnetClient) ethernet.telnetClient.stop(); ethernet.init(); break; case 0: ethernet.hardware_enabled = false; break; case 1: ethernet.hardware_enabled = true; break; default: break; } } const bool nopar = !seenS && !seenP; if (nopar || seenS) ETH0_report(); if (nopar || seenP) M552_report(); } void GcodeSuite::M552_report() { TERN_(MARLIN_SMALL_BUILD, return); ip_report(552, F("ip address"), Ethernet.linkStatus() == LinkON ? Ethernet.localIP() : ethernet.ip); } /** * M553 Pnnn - Set netmask */ void GcodeSuite::M553() { if (parser.seenval('P')) ethernet.subnet.fromString(parser.value_string()); else M553_report(); } void GcodeSuite::M553_report() { TERN_(MARLIN_SMALL_BUILD, return); ip_report(553, F("subnet mask"), Ethernet.linkStatus() == LinkON ? Ethernet.subnetMask() : ethernet.subnet); } /** * M554 Pnnn - Set Gateway */ void GcodeSuite::M554() { if (parser.seenval('P')) ethernet.gateway.fromString(parser.value_string()); else M554_report(); } void GcodeSuite::M554_report() { TERN_(MARLIN_SMALL_BUILD, return); ip_report(554, F("gateway"), Ethernet.linkStatus() == LinkON ? Ethernet.gatewayIP() : ethernet.gateway); } #endif // HAS_ETHERNET
2301_81045437/Marlin
Marlin/src/gcode/feature/network/M552-M554.cpp
C++
agpl-3.0
3,835
/** * Marlin 3D Printer Firmware * Copyright (c) 2023 MarlinFirmware [https://github.com/MarlinFirmware/Marlin] * * Based on Sprinter and grbl. * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <https://www.gnu.org/licenses/>. * */ #include "../../../inc/MarlinConfig.h" #if ENABLED(NONLINEAR_EXTRUSION) #include "../../gcode.h" #include "../../../module/stepper.h" void GcodeSuite::M592_report(const bool forReplay/*=true*/) { TERN_(MARLIN_SMALL_BUILD, return); report_heading(forReplay, F(STR_NONLINEAR_EXTRUSION)); SERIAL_ECHOLNPGM(" M592 A", stepper.ne.A, " B", stepper.ne.B, " C", stepper.ne.C); } /** * M592: Get or set nonlinear extrusion parameters * A<factor> Linear coefficient (default 0.0) * B<factor> Quadratic coefficient (default 0.0) * C<factor> Constant coefficient (default 1.0) * * Adjusts the amount of extrusion based on the instantaneous velocity of extrusion, as a multiplier. * The amount of extrusion is multiplied by max(C, C + A*v + B*v^2) where v is extruder velocity in mm/s. * Only adjusts forward extrusions, since those are the ones affected by backpressure. */ void GcodeSuite::M592() { if (!parser.seen_any()) return M592_report(); if (parser.seenval('A')) stepper.ne.A = parser.value_float(); if (parser.seenval('B')) stepper.ne.B = parser.value_float(); if (parser.seenval('C')) stepper.ne.C = parser.value_float(); } #endif // NONLINEAR_EXTRUSION
2301_81045437/Marlin
Marlin/src/gcode/feature/nonlinear/M592.cpp
C++
agpl-3.0
2,054
/** * Marlin 3D Printer Firmware * Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin] * * Based on Sprinter and grbl. * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <https://www.gnu.org/licenses/>. * */ #include "../../../inc/MarlinConfigPre.h" #if ENABLED(PASSWORD_FEATURE) #include "../../../feature/password/password.h" #include "../../../core/serial.h" #include "../../gcode.h" // // M510: Lock Printer // void GcodeSuite::M510() { password.lock_machine(); } // // M511: Unlock Printer // #if ENABLED(PASSWORD_UNLOCK_GCODE) void GcodeSuite::M511() { if (password.is_locked) { password.value_entry = parser.ulongval('P'); password.authentication_check(); } } #endif // PASSWORD_UNLOCK_GCODE // // M512: Set/Change/Remove Password // #if ENABLED(PASSWORD_CHANGE_GCODE) void GcodeSuite::M512() { if (password.is_set && parser.ulongval('P') != password.value) { SERIAL_ECHOLNPGM(STR_WRONG_PASSWORD); return; } if (parser.seenval('S')) { password.value_entry = parser.ulongval('S'); if (password.value_entry < CAT(1e, PASSWORD_LENGTH)) { password.is_set = true; password.value = password.value_entry; SERIAL_ECHOLNPGM(STR_PASSWORD_SET, password.value); // TODO: Update password.string } else SERIAL_ECHOLNPGM(STR_PASSWORD_TOO_LONG); } else { password.is_set = false; SERIAL_ECHOLNPGM(STR_PASSWORD_REMOVED); } SERIAL_ECHOLNPGM(STR_REMINDER_SAVE_SETTINGS); } #endif // PASSWORD_CHANGE_GCODE #endif // PASSWORD_FEATURE
2301_81045437/Marlin
Marlin/src/gcode/feature/password/M510-M512.cpp
C++
agpl-3.0
2,225
/** * Marlin 3D Printer Firmware * Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin] * * Based on Sprinter and grbl. * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <https://www.gnu.org/licenses/>. * */ #include "../../../inc/MarlinConfig.h" #if ENABLED(NOZZLE_PARK_FEATURE) #include "../../gcode.h" #include "../../../libs/nozzle.h" #include "../../../module/motion.h" /** * G27: Park the nozzle according with the given style * * P<style> - Parking style: * 0 = (Default) Relative raise by NOZZLE_PARK_Z_RAISE_MIN (>= NOZZLE_PARK_POINT.z) before XY parking. * 1 = Absolute move to NOZZLE_PARK_POINT.z before XY parking. (USE WITH CAUTION!) * 2 = Relative raise by NOZZLE_PARK_POINT.z before XY parking. * 3 = Relative raise by NOZZLE_PARK_Z_RAISE_MIN, skip XY parking. * 4 = No Z raise. Just XY parking. */ void GcodeSuite::G27() { // Don't allow nozzle parking without homing first if (homing_needed_error()) return; nozzle.park(parser.ushortval('P')); } #endif // NOZZLE_PARK_FEATURE
2301_81045437/Marlin
Marlin/src/gcode/feature/pause/G27.cpp
C++
agpl-3.0
1,728
/** * Marlin 3D Printer Firmware * Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin] * * Based on Sprinter and grbl. * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <https://www.gnu.org/licenses/>. * */ #include "../../../inc/MarlinConfig.h" #if SAVED_POSITIONS #include "../../gcode.h" #include "../../../module/motion.h" #define DEBUG_OUT ENABLED(SAVED_POSITIONS_DEBUG) #include "../../../core/debug_out.h" /** * G60: Save current position * * S<slot> - Memory slot # (0-based) to save into (default 0) */ void GcodeSuite::G60() { const uint8_t slot = parser.byteval('S'); if (slot >= SAVED_POSITIONS) { SERIAL_ERROR_MSG(STR_INVALID_POS_SLOT STRINGIFY(SAVED_POSITIONS)); return; } stored_position[slot] = current_position; SBI(saved_slots[slot >> 3], slot & 0x07); #if ENABLED(SAVED_POSITIONS_DEBUG) { const xyze_pos_t &pos = stored_position[slot]; DEBUG_ECHOPGM(STR_SAVED_POS " S", slot, " :"); #if NUM_AXES DEBUG_ECHOPGM_P( LIST_N(DOUBLE(NUM_AXES), SP_X_LBL, pos.x, SP_Y_LBL, pos.y, SP_Z_LBL, pos.z, SP_I_LBL, pos.i, SP_J_LBL, pos.j, SP_K_LBL, pos.k, SP_U_LBL, pos.u, SP_V_LBL, pos.v, SP_W_LBL, pos.w ) ); #endif #if HAS_EXTRUDERS DEBUG_ECHOPGM_P(SP_E_LBL, pos.e); #endif DEBUG_EOL(); } #endif } #endif // SAVED_POSITIONS
2301_81045437/Marlin
Marlin/src/gcode/feature/pause/G60.cpp
C++
agpl-3.0
2,018
/** * Marlin 3D Printer Firmware * Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin] * * Based on Sprinter and grbl. * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <https://www.gnu.org/licenses/>. * */ #include "../../../inc/MarlinConfig.h" #if SAVED_POSITIONS #include "../../../module/planner.h" #include "../../gcode.h" #include "../../../module/motion.h" #include "../../../module/planner.h" #define DEBUG_OUT ENABLED(SAVED_POSITIONS_DEBUG) #include "../../../core/debug_out.h" /** * G61: Return to saved position * * F<rate> - Feedrate (optional) for the move back. * S<slot> - Slot # (0-based) to restore from (default 0). * X<offset> - Restore X axis, applying the given offset (default 0) * Y<offset> - Restore Y axis, applying the given offset (default 0) * Z<offset> - Restore Z axis, applying the given offset (default 0) * * If there is an Extruder: * E<offset> - Restore E axis, applying the given offset (default 0) * * With extra axes using default names: * A<offset> - Restore 4th axis, applying the given offset (default 0) * B<offset> - Restore 5th axis, applying the given offset (default 0) * C<offset> - Restore 6th axis, applying the given offset (default 0) * U<offset> - Restore 7th axis, applying the given offset (default 0) * V<offset> - Restore 8th axis, applying the given offset (default 0) * W<offset> - Restore 9th axis, applying the given offset (default 0) * * If no axes are specified then all axes are restored. */ void GcodeSuite::G61() { const uint8_t slot = parser.byteval('S'); #define SYNC_E(POINT) TERN_(HAS_EXTRUDERS, planner.set_e_position_mm((destination.e = current_position.e = (POINT)))) #if SAVED_POSITIONS < 256 if (slot >= SAVED_POSITIONS) { SERIAL_ERROR_MSG(STR_INVALID_POS_SLOT STRINGIFY(SAVED_POSITIONS)); return; } #endif // No saved position? No axes being restored? if (!TEST(saved_slots[slot >> 3], slot & 0x07)) return; // Apply any given feedrate over 0.0 REMEMBER(saved, feedrate_mm_s); const float fr = parser.linearval('F'); if (fr > 0.0) feedrate_mm_s = MMM_TO_MMS(fr); if (!parser.seen_axis()) { DEBUG_ECHOLNPGM("Default position restore"); do_blocking_move_to(stored_position[slot], feedrate_mm_s); SYNC_E(stored_position[slot].e); } else { if (parser.seen(STR_AXES_MAIN)) { DEBUG_ECHOPGM(STR_RESTORING_POS " S", slot); LOOP_NUM_AXES(i) { destination[i] = parser.seen(AXIS_CHAR(i)) ? stored_position[slot][i] + parser.value_axis_units((AxisEnum)i) : current_position[i]; DEBUG_ECHO(C(' '), C(AXIS_CHAR(i)), p_float_t(destination[i], 2)); } DEBUG_EOL(); // Move to the saved position prepare_line_to_destination(); } #if HAS_EXTRUDERS if (parser.seen_test('E')) { DEBUG_ECHOLNPGM(STR_RESTORING_POS " S", slot, " E", current_position.e, "=>", stored_position[slot].e); SYNC_E(stored_position[slot].e); } #endif } } #endif // SAVED_POSITIONS
2301_81045437/Marlin
Marlin/src/gcode/feature/pause/G61.cpp
C++
agpl-3.0
3,704
/** * Marlin 3D Printer Firmware * Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin] * * Based on Sprinter and grbl. * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <https://www.gnu.org/licenses/>. * */ #include "../../../inc/MarlinConfig.h" #if ENABLED(PARK_HEAD_ON_PAUSE) #include "../../gcode.h" #include "../../parser.h" #include "../../../feature/pause.h" #include "../../../lcd/marlinui.h" #include "../../../module/motion.h" #include "../../../module/printcounter.h" #include "../../../sd/cardreader.h" #if ENABLED(POWER_LOSS_RECOVERY) #include "../../../feature/powerloss.h" #endif /** * M125: Store current position and move to parking position. * Called on pause (by M25) to prevent material leaking onto the * object. On resume (M24) the head will be moved back and the * print will resume. * * When not actively SD printing, M125 simply moves to the park * position and waits, resuming with a button click or M108. * Without PARK_HEAD_ON_PAUSE the M125 command does nothing. * * L<linear> = Override retract Length * X<pos> = Override park position X * Y<pos> = Override park position Y * A<pos> = Override park position A (requires AXIS*_NAME 'A') * B<pos> = Override park position B (requires AXIS*_NAME 'B') * C<pos> = Override park position C (requires AXIS*_NAME 'C') * U<pos> = Override park position U (requires AXIS*_NAME 'U') * V<pos> = Override park position V (requires AXIS*_NAME 'V') * W<pos> = Override park position W (requires AXIS*_NAME 'W') * Z<linear> = Override Z raise * * With an LCD menu: * P<bool> = Always show a prompt and await a response */ void GcodeSuite::M125() { // Initial retract before move to filament change position const float retract = TERN0(HAS_EXTRUDERS, -ABS(parser.axisunitsval('L', E_AXIS, PAUSE_PARK_RETRACT_LENGTH))); xyz_pos_t park_point = NOZZLE_PARK_POINT; // Move to filament change position or given position NUM_AXIS_CODE( if (parser.seenval('X')) park_point.x = RAW_X_POSITION(parser.linearval('X')), if (parser.seenval('Y')) park_point.y = RAW_Y_POSITION(parser.linearval('Y')), NOOP, if (parser.seenval(AXIS4_NAME)) park_point.i = RAW_I_POSITION(parser.linearval(AXIS4_NAME)), if (parser.seenval(AXIS5_NAME)) park_point.j = RAW_J_POSITION(parser.linearval(AXIS5_NAME)), if (parser.seenval(AXIS6_NAME)) park_point.k = RAW_K_POSITION(parser.linearval(AXIS6_NAME)), if (parser.seenval(AXIS7_NAME)) park_point.u = RAW_U_POSITION(parser.linearval(AXIS7_NAME)), if (parser.seenval(AXIS8_NAME)) park_point.v = RAW_V_POSITION(parser.linearval(AXIS8_NAME)), if (parser.seenval(AXIS9_NAME)) park_point.w = RAW_W_POSITION(parser.linearval(AXIS9_NAME)) ); // Lift Z axis #if HAS_Z_AXIS if (parser.seenval('Z')) park_point.z = parser.linearval('Z'); #endif #if HAS_HOTEND_OFFSET && NONE(DUAL_X_CARRIAGE, DELTA) park_point += hotend_offset[active_extruder]; #endif const bool sd_printing = TERN0(HAS_MEDIA, IS_SD_PRINTING()); ui.pause_show_message(PAUSE_MESSAGE_PARKING, PAUSE_MODE_PAUSE_PRINT); // If possible, show an LCD prompt with the 'P' flag const bool show_lcd = TERN0(HAS_MARLINUI_MENU, parser.boolval('P')); if (pause_print(retract, park_point, show_lcd, 0)) { if (ENABLED(HAS_DISPLAY) || ALL(EMERGENCY_PARSER, HOST_PROMPT_SUPPORT) || !sd_printing || show_lcd) { wait_for_confirmation(false, 0); resume_print(0, 0, -retract, 0); } } } #endif // PARK_HEAD_ON_PAUSE
2301_81045437/Marlin
Marlin/src/gcode/feature/pause/M125.cpp
C++
agpl-3.0
4,220
/** * Marlin 3D Printer Firmware * Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin] * * Based on Sprinter and grbl. * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <https://www.gnu.org/licenses/>. * */ #include "../../../inc/MarlinConfig.h" #if ENABLED(ADVANCED_PAUSE_FEATURE) #include "../../gcode.h" #include "../../../feature/pause.h" #include "../../../module/motion.h" #include "../../../module/printcounter.h" #include "../../../lcd/marlinui.h" #if HAS_MULTI_EXTRUDER #include "../../../module/tool_change.h" #endif #if HAS_PRUSA_MMU2 #include "../../../feature/mmu/mmu2.h" #if ENABLED(MMU2_MENUS) #include "../../../lcd/menu/menu_mmu2.h" #endif #endif #if ENABLED(MIXING_EXTRUDER) #include "../../../feature/mixing.h" #endif #if HAS_FILAMENT_SENSOR #include "../../../feature/runout.h" #endif /** * M600: Pause for filament change * * E[distance] - Retract the filament this far * Z[distance] - Move the Z axis by this distance * X[position] - Move to this X position (instead of NOZZLE_PARK_POINT.x) * Y[position] - Move to this Y position (instead of NOZZLE_PARK_POINT.y) * I[position] - Move to this I position (instead of NOZZLE_PARK_POINT.i) * J[position] - Move to this J position (instead of NOZZLE_PARK_POINT.j) * K[position] - Move to this K position (instead of NOZZLE_PARK_POINT.k) * C[position] - Move to this U position (instead of NOZZLE_PARK_POINT.u) * H[position] - Move to this V position (instead of NOZZLE_PARK_POINT.v) * O[position] - Move to this W position (instead of NOZZLE_PARK_POINT.w) * U[distance] - Retract distance for removal (manual reload) * L[distance] - Extrude distance for insertion (manual reload) * B[count] - Number of times to beep, -1 for indefinite (if equipped with a buzzer) * T[toolhead] - Select extruder for filament change * R[temp] - Resume temperature (in current units) * * Default values are used for omitted arguments. */ void GcodeSuite::M600() { #if ENABLED(MIXING_EXTRUDER) const int8_t eindex = get_target_e_stepper_from_command(); if (eindex < 0) return; const uint8_t old_mixing_tool = mixer.get_current_vtool(); mixer.T(MIXER_DIRECT_SET_TOOL); MIXER_STEPPER_LOOP(i) mixer.set_collector(i, i == uint8_t(eindex) ? 1.0 : 0.0); mixer.normalize(); const int8_t target_extruder = active_extruder; #else const int8_t target_extruder = get_target_extruder_from_command(); if (target_extruder < 0) return; #endif #if ENABLED(DUAL_X_CARRIAGE) int8_t DXC_ext = target_extruder; if (!parser.seen_test('T')) { // If no tool index is specified, M600 was (probably) sent in response to filament runout. // In this case, for duplicating modes set DXC_ext to the extruder that ran out. #if MULTI_FILAMENT_SENSOR if (idex_is_duplicating()) DXC_ext = (READ(FIL_RUNOUT2_PIN) == FIL_RUNOUT2_STATE) ? 1 : 0; #else DXC_ext = active_extruder; #endif } #endif const bool standardM600 = TERN1(MMU2_MENUS, !mmu2.enabled()); // Show initial "wait for start" message if (standardM600) ui.pause_show_message(PAUSE_MESSAGE_CHANGING, PAUSE_MODE_PAUSE_PRINT, target_extruder); // If needed, home before parking for filament change TERN_(HOME_BEFORE_FILAMENT_CHANGE, home_if_needed(true)); #if HAS_MULTI_EXTRUDER // Change toolhead if specified const uint8_t active_extruder_before_filament_change = active_extruder; if (active_extruder != target_extruder && TERN1(DUAL_X_CARRIAGE, !idex_is_duplicating())) tool_change(target_extruder); #endif // Initial retract before move to filament change position const float retract = -ABS(parser.axisunitsval('E', E_AXIS, PAUSE_PARK_RETRACT_LENGTH)); xyz_pos_t park_point NOZZLE_PARK_POINT; // Move XY axes to filament change position or given position NUM_AXIS_CODE( if (parser.seenval('X')) park_point.x = parser.linearval('X'), if (parser.seenval('Y')) park_point.y = parser.linearval('Y'), if (parser.seenval('Z')) park_point.z = parser.linearval('Z'), // Lift Z axis if (parser.seenval('I')) park_point.i = parser.linearval('I'), if (parser.seenval('J')) park_point.j = parser.linearval('J'), if (parser.seenval('K')) park_point.k = parser.linearval('K'), if (parser.seenval('C')) park_point.u = parser.linearval('C'), // U axis if (parser.seenval('H')) park_point.v = parser.linearval('H'), // V axis if (parser.seenval('O')) park_point.w = parser.linearval('O') // W axis ); #if HAS_HOTEND_OFFSET && NONE(DUAL_X_CARRIAGE, DELTA) park_point += hotend_offset[active_extruder]; #endif // Unload filament // For MMU2, when enabled, reset retract value so it doesn't mess with MMU filament handling const float unload_length = standardM600 ? -ABS(parser.axisunitsval('U', E_AXIS, fc_settings[active_extruder].unload_length)) : 0.5f; const int beep_count = parser.intval('B', -1 #ifdef FILAMENT_CHANGE_ALERT_BEEPS + 1 + FILAMENT_CHANGE_ALERT_BEEPS #endif ); if (pause_print(retract, park_point, true, unload_length DXC_PASS)) { if (standardM600) { wait_for_confirmation(true, beep_count DXC_PASS); resume_print( FILAMENT_CHANGE_SLOW_LOAD_LENGTH, ABS(parser.axisunitsval('L', E_AXIS, fc_settings[active_extruder].load_length)), ADVANCED_PAUSE_PURGE_LENGTH, beep_count, parser.celsiusval('R') DXC_PASS ); } else { #if ENABLED(MMU2_MENUS) mmu2_M600(); resume_print(0, 0, 0, beep_count, 0 DXC_PASS); #endif } } #if HAS_MULTI_EXTRUDER // Restore toolhead if it was changed if (active_extruder_before_filament_change != active_extruder) tool_change(active_extruder_before_filament_change); #endif TERN_(MIXING_EXTRUDER, mixer.T(old_mixing_tool)); // Restore original mixing tool } #endif // ADVANCED_PAUSE_FEATURE
2301_81045437/Marlin
Marlin/src/gcode/feature/pause/M600.cpp
C++
agpl-3.0
6,631
/** * Marlin 3D Printer Firmware * Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin] * * Based on Sprinter and grbl. * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <https://www.gnu.org/licenses/>. * */ #include "../../../inc/MarlinConfigPre.h" #if ENABLED(CONFIGURE_FILAMENT_CHANGE) #include "../../gcode.h" #include "../../../feature/pause.h" #include "../../../module/motion.h" #include "../../../module/printcounter.h" /** * M603: Configure filament change * * T[toolhead] - Select extruder to configure, active extruder if not specified * U[distance] - Retract distance for removal, for the specified extruder * L[distance] - Extrude distance for insertion, for the specified extruder */ void GcodeSuite::M603() { if (!parser.seen("TUL")) return M603_report(); const int8_t target_extruder = get_target_extruder_from_command(); if (target_extruder < 0) return; // Unload length if (parser.seenval('U')) { fc_settings[target_extruder].unload_length = ABS(parser.value_axis_units(E_AXIS)); #if ENABLED(PREVENT_LENGTHY_EXTRUDE) NOMORE(fc_settings[target_extruder].unload_length, EXTRUDE_MAXLENGTH); #endif } // Load length if (parser.seenval('L')) { fc_settings[target_extruder].load_length = ABS(parser.value_axis_units(E_AXIS)); #if ENABLED(PREVENT_LENGTHY_EXTRUDE) NOMORE(fc_settings[target_extruder].load_length, EXTRUDE_MAXLENGTH); #endif } } void GcodeSuite::M603_report(const bool forReplay/*=true*/) { TERN_(MARLIN_SMALL_BUILD, return); report_heading(forReplay, F(STR_FILAMENT_LOAD_UNLOAD)); #if EXTRUDERS == 1 report_echo_start(forReplay); SERIAL_ECHOPGM(" M603 L", LINEAR_UNIT(fc_settings[0].load_length), " U", LINEAR_UNIT(fc_settings[0].unload_length), " ;"); say_units(); #else EXTRUDER_LOOP() { report_echo_start(forReplay); SERIAL_ECHOPGM(" M603 T", e, " L", LINEAR_UNIT(fc_settings[e].load_length), " U", LINEAR_UNIT(fc_settings[e].unload_length), " ;"); say_units(); } #endif } #endif // CONFIGURE_FILAMENT_CHANGE
2301_81045437/Marlin
Marlin/src/gcode/feature/pause/M603.cpp
C++
agpl-3.0
2,718
/** * Marlin 3D Printer Firmware * Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin] * * Based on Sprinter and grbl. * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <https://www.gnu.org/licenses/>. * */ #include "../../../inc/MarlinConfigPre.h" #if ENABLED(FILAMENT_LOAD_UNLOAD_GCODES) #include "../../gcode.h" #include "../../../MarlinCore.h" #include "../../../module/motion.h" #include "../../../module/temperature.h" #include "../../../feature/pause.h" #include "../../../lcd/marlinui.h" #if HAS_MULTI_EXTRUDER #include "../../../module/tool_change.h" #endif #if HAS_PRUSA_MMU2 #include "../../../feature/mmu/mmu2.h" #endif #if ENABLED(MIXING_EXTRUDER) #include "../../../feature/mixing.h" #endif /** * M701: Load filament * * T<extruder> - Extruder number. Required for mixing extruder. * For non-mixing, current extruder if omitted. * Z<distance> - Move the Z axis by this distance * L<distance> - Extrude distance for insertion (positive value) (manual reload) * * Default values are used for omitted arguments. */ void GcodeSuite::M701() { xyz_pos_t park_point = NOZZLE_PARK_POINT; // Don't raise Z if the machine isn't homed if (TERN0(NO_MOTION_BEFORE_HOMING, axes_should_home())) park_point.z = 0; #if ENABLED(MIXING_EXTRUDER) const int8_t eindex = get_target_e_stepper_from_command(); if (eindex < 0) return; const uint8_t old_mixing_tool = mixer.get_current_vtool(); mixer.T(MIXER_DIRECT_SET_TOOL); MIXER_STEPPER_LOOP(i) mixer.set_collector(i, i == uint8_t(eindex) ? 1.0 : 0.0); mixer.normalize(); const int8_t target_extruder = active_extruder; #else const int8_t target_extruder = get_target_extruder_from_command(); if (target_extruder < 0) return; #endif // Z axis lift if (parser.seenval('Z')) park_point.z = parser.linearval('Z'); // Show initial "wait for load" message ui.pause_show_message(PAUSE_MESSAGE_LOAD, PAUSE_MODE_LOAD_FILAMENT, target_extruder); #if HAS_MULTI_EXTRUDER && (HAS_PRUSA_MMU1 || !HAS_MMU) // Change toolhead if specified uint8_t active_extruder_before_filament_change = active_extruder; if (active_extruder != target_extruder) tool_change(target_extruder); #endif auto move_z_by = [](const_float_t zdist) { if (zdist) { destination = current_position; destination.z += zdist; prepare_internal_move_to_destination(NOZZLE_PARK_Z_FEEDRATE); } }; // Raise the Z axis (with max limit) const float park_raise = _MIN(park_point.z, (Z_MAX_POS) - current_position.z); move_z_by(park_raise); // Load filament #if HAS_PRUSA_MMU2 mmu2.load_to_nozzle(target_extruder); #else constexpr float purge_length = ADVANCED_PAUSE_PURGE_LENGTH, slow_load_length = FILAMENT_CHANGE_SLOW_LOAD_LENGTH; const float fast_load_length = ABS(parser.seenval('L') ? parser.value_axis_units(E_AXIS) : fc_settings[active_extruder].load_length); load_filament( slow_load_length, fast_load_length, purge_length, FILAMENT_CHANGE_ALERT_BEEPS, true, // show_lcd thermalManager.still_heating(target_extruder), // pause_for_user PAUSE_MODE_LOAD_FILAMENT // pause_mode OPTARG(DUAL_X_CARRIAGE, target_extruder) // Dual X target ); #endif // Restore Z axis move_z_by(-park_raise); #if HAS_MULTI_EXTRUDER && (HAS_PRUSA_MMU1 || !HAS_MMU) // Restore toolhead if it was changed if (active_extruder_before_filament_change != active_extruder) tool_change(active_extruder_before_filament_change); #endif TERN_(MIXING_EXTRUDER, mixer.T(old_mixing_tool)); // Restore original mixing tool // Show status screen ui.pause_show_message(PAUSE_MESSAGE_STATUS); } /** * M702: Unload filament * * T<extruder> - Extruder number. Required for mixing extruder. * For non-mixing, if omitted, current extruder * (or ALL extruders with FILAMENT_UNLOAD_ALL_EXTRUDERS). * Z<distance> - Move the Z axis by this distance * U<distance> - Retract distance for removal (manual reload) * * Default values are used for omitted arguments. */ void GcodeSuite::M702() { xyz_pos_t park_point = NOZZLE_PARK_POINT; // Don't raise Z if the machine isn't homed if (TERN0(NO_MOTION_BEFORE_HOMING, axes_should_home())) park_point.z = 0; #if ENABLED(MIXING_EXTRUDER) const uint8_t old_mixing_tool = mixer.get_current_vtool(); #if ENABLED(FILAMENT_UNLOAD_ALL_EXTRUDERS) float mix_multiplier = 1.0; const bool seenT = parser.seenval('T'); if (!seenT) { mixer.T(MIXER_AUTORETRACT_TOOL); mix_multiplier = MIXING_STEPPERS; } #else constexpr bool seenT = true; #endif if (seenT) { const int8_t eindex = get_target_e_stepper_from_command(); if (eindex < 0) return; mixer.T(MIXER_DIRECT_SET_TOOL); MIXER_STEPPER_LOOP(i) mixer.set_collector(i, i == uint8_t(eindex) ? 1.0 : 0.0); mixer.normalize(); } const int8_t target_extruder = active_extruder; #else const int8_t target_extruder = get_target_extruder_from_command(); if (target_extruder < 0) return; #endif // Z axis lift if (parser.seenval('Z')) park_point.z = parser.linearval('Z'); // Show initial "wait for unload" message ui.pause_show_message(PAUSE_MESSAGE_UNLOAD, PAUSE_MODE_UNLOAD_FILAMENT, target_extruder); #if HAS_MULTI_EXTRUDER && (HAS_PRUSA_MMU1 || !HAS_MMU) // Change toolhead if specified uint8_t active_extruder_before_filament_change = active_extruder; if (active_extruder != target_extruder) tool_change(target_extruder); #endif // Lift Z axis if (park_point.z > 0) do_blocking_move_to_z(_MIN(current_position.z + park_point.z, Z_MAX_POS), feedRate_t(NOZZLE_PARK_Z_FEEDRATE)); // Unload filament #if HAS_PRUSA_MMU2 mmu2.unload(); #else #if ALL(HAS_MULTI_EXTRUDER, FILAMENT_UNLOAD_ALL_EXTRUDERS) if (!parser.seenval('T')) { HOTEND_LOOP() { if (e != active_extruder) tool_change(e); unload_filament(-fc_settings[e].unload_length, true, PAUSE_MODE_UNLOAD_FILAMENT); } } else #endif { // Unload length const float unload_length = -ABS(parser.seen('U') ? parser.value_axis_units(E_AXIS) : fc_settings[target_extruder].unload_length); unload_filament(unload_length, true, PAUSE_MODE_UNLOAD_FILAMENT #if ALL(FILAMENT_UNLOAD_ALL_EXTRUDERS, MIXING_EXTRUDER) , mix_multiplier #endif ); } #endif // Restore Z axis if (park_point.z > 0) do_blocking_move_to_z(_MAX(current_position.z - park_point.z, 0), feedRate_t(NOZZLE_PARK_Z_FEEDRATE)); #if HAS_MULTI_EXTRUDER && (HAS_PRUSA_MMU1 || !HAS_MMU) // Restore toolhead if it was changed if (active_extruder_before_filament_change != active_extruder) tool_change(active_extruder_before_filament_change); #endif TERN_(MIXING_EXTRUDER, mixer.T(old_mixing_tool)); // Restore original mixing tool // Show status screen ui.pause_show_message(PAUSE_MESSAGE_STATUS); } #endif // ADVANCED_PAUSE_FEATURE
2301_81045437/Marlin
Marlin/src/gcode/feature/pause/M701_M702.cpp
C++
agpl-3.0
7,968
/** * Marlin 3D Printer Firmware * Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin] * * Based on Sprinter and grbl. * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <https://www.gnu.org/licenses/>. * */ #include "../../../inc/MarlinConfig.h" #if HAS_POWER_MONITOR #include "../../../feature/power_monitor.h" #include "../../../MarlinCore.h" #include "../../gcode.h" /** * M430: Enable/disable current LCD display * With no parameters report the system current draw (in Amps) * * I[bool] - Set Display of current on the LCD * V[bool] - Set Display of voltage on the LCD * W[bool] - Set Display of power on the LCD */ void GcodeSuite::M430() { bool do_report = true; #if HAS_WIRED_LCD #if ENABLED(POWER_MONITOR_CURRENT) if (parser.seen('I')) { power_monitor.set_current_display(parser.value_bool()); do_report = false; } #endif #if ENABLED(POWER_MONITOR_VOLTAGE) if (parser.seen('V')) { power_monitor.set_voltage_display(parser.value_bool()); do_report = false; } #endif #if HAS_POWER_MONITOR_WATTS if (parser.seen('W')) { power_monitor.set_power_display(parser.value_bool()); do_report = false; } #endif #endif if (do_report) { SERIAL_ECHOLNPGM( #if ENABLED(POWER_MONITOR_CURRENT) "Current: ", power_monitor.getAmps(), "A" TERN_(POWER_MONITOR_VOLTAGE, " ") #endif #if ENABLED(POWER_MONITOR_VOLTAGE) "Voltage: ", power_monitor.getVolts(), "V" #endif #if HAS_POWER_MONITOR_WATTS " Power: ", power_monitor.getPower(), "W" #endif ); } } #endif // HAS_POWER_MONITOR
2301_81045437/Marlin
Marlin/src/gcode/feature/power_monitor/M430.cpp
C++
agpl-3.0
2,270
/** * Marlin 3D Printer Firmware * Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin] * * Based on Sprinter and grbl. * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <https://www.gnu.org/licenses/>. * */ #include "../../../inc/MarlinConfig.h" #if ENABLED(POWER_LOSS_RECOVERY) #include "../../gcode.h" #include "../../../feature/powerloss.h" #include "../../../module/motion.h" #if HAS_PLR_BED_THRESHOLD #include "../../../module/temperature.h" // for degBed #endif #include "../../../lcd/marlinui.h" #if ENABLED(EXTENSIBLE_UI) #include "../../../lcd/extui/ui_api.h" #elif ENABLED(DWIN_CREALITY_LCD) #include "../../../lcd/e3v2/creality/dwin.h" #elif ENABLED(DWIN_CREALITY_LCD_JYERSUI) #include "../../../lcd/e3v2/jyersui/dwin.h" // Temporary fix until it can be better implemented #endif #define DEBUG_OUT ENABLED(DEBUG_POWER_LOSS_RECOVERY) #include "../../../core/debug_out.h" void menu_job_recovery(); inline void plr_error(FSTR_P const prefix) { #if ENABLED(DEBUG_POWER_LOSS_RECOVERY) DEBUG_ECHO_START(); DEBUG_ECHOLN(prefix, F(" Job Recovery Data")); #else UNUSED(prefix); #endif } #if HAS_MARLINUI_MENU void lcd_power_loss_recovery_cancel(); #endif /** * M1000: Resume from power-loss (undocumented) * - With 'S' go to the Resume/Cancel menu * ...unless the bed temperature is already above a configured minimum temperature. * - With 'C' execute a cancel selection * - With no parameters, run recovery commands */ void GcodeSuite::M1000() { if (recovery.valid()) { const bool force_resume = TERN0(HAS_PLR_BED_THRESHOLD, recovery.bed_temp_threshold && (thermalManager.degBed() >= recovery.bed_temp_threshold)); if (!force_resume && parser.seen_test('S')) { #if HAS_MARLINUI_MENU ui.goto_screen(menu_job_recovery); #elif ENABLED(EXTENSIBLE_UI) ExtUI::onPowerLossResume(); #elif HAS_PLR_UI_FLAG recovery.ui_flag_resume = true; #elif ENABLED(DWIN_CREALITY_LCD_JYERSUI) // Temporary fix until it can be better implemented jyersDWIN.popupHandler(Popup_Resume); #else SERIAL_ECHO_MSG("Resume requires LCD."); #endif } else if (parser.seen_test('C')) { #if HAS_MARLINUI_MENU lcd_power_loss_recovery_cancel(); #else recovery.cancel(); #endif TERN_(EXTENSIBLE_UI, ExtUI::onPrintTimerStopped()); } else recovery.resume(); } else plr_error(recovery.info.valid_head ? F("No") : F("Invalid")); } #endif // POWER_LOSS_RECOVERY
2301_81045437/Marlin
Marlin/src/gcode/feature/powerloss/M1000.cpp
C++
agpl-3.0
3,190
/** * Marlin 3D Printer Firmware * Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin] * * Based on Sprinter and grbl. * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <https://www.gnu.org/licenses/>. * */ #include "../../../inc/MarlinConfig.h" #if ENABLED(POWER_LOSS_RECOVERY) #include "../../gcode.h" #include "../../../feature/powerloss.h" #include "../../../module/motion.h" #include "../../../lcd/marlinui.h" /** * M413: Enable / Disable power-loss recovery * * Parameters * S[bool] - Flag to enable / disable. * If omitted, report current state. * * With PLR_BED_THRESHOLD: * B Bed Temperature above which recovery will proceed without asking permission. */ void GcodeSuite::M413() { if (parser.seen('S')) recovery.enable(parser.value_bool()); else M413_report(); #if HAS_PLR_BED_THRESHOLD if (parser.seenval('B')) recovery.bed_temp_threshold = parser.value_celsius(); #endif #if ENABLED(DEBUG_POWER_LOSS_RECOVERY) if (parser.seen("RL")) recovery.load(); if (parser.seen_test('W')) recovery.save(true); if (parser.seen_test('P')) recovery.purge(); if (parser.seen_test('D')) recovery.debug(F("M413")); if (parser.seen_test('O')) recovery._outage(true); if (parser.seen_test('C')) (void)recovery.check(); if (parser.seen_test('E')) SERIAL_ECHO(recovery.exists() ? F("PLR Exists\n") : F("No PLR\n")); if (parser.seen_test('V')) SERIAL_ECHO(recovery.valid() ? F("Valid\n") : F("Invalid\n")); #endif } void GcodeSuite::M413_report(const bool forReplay/*=true*/) { TERN_(MARLIN_SMALL_BUILD, return); report_heading_etc(forReplay, F(STR_POWER_LOSS_RECOVERY)); SERIAL_ECHOPGM(" M413 S", AS_DIGIT(recovery.enabled) #if HAS_PLR_BED_THRESHOLD , " B", recovery.bed_temp_threshold #endif ); SERIAL_ECHO(" ; "); serialprintln_onoff(recovery.enabled); } #endif // POWER_LOSS_RECOVERY
2301_81045437/Marlin
Marlin/src/gcode/feature/powerloss/M413.cpp
C++
agpl-3.0
2,564
/** * Marlin 3D Printer Firmware * Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin] * * Based on Sprinter and grbl. * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <https://www.gnu.org/licenses/>. * */ #include "../../../inc/MarlinConfigPre.h" #if HAS_PRUSA_MMU2 #include "../../gcode.h" #include "../../../feature/mmu/mmu2.h" /** * M403: Set filament type for MMU2 * * Valid filament type values: * * 0 Default * 1 Flexible * 2 PVA */ void GcodeSuite::M403() { int8_t index = parser.intval('E', -1), type = parser.intval('F', -1); if (WITHIN(index, 0, EXTRUDERS - 1) && WITHIN(type, 0, 2)) mmu2.set_filament_type(index, type); else SERIAL_ECHO_MSG("M403 - bad arguments."); } #endif // HAS_PRUSA_MMU2
2301_81045437/Marlin
Marlin/src/gcode/feature/prusa_MMU2/M403.cpp
C++
agpl-3.0
1,408
/** * Marlin 3D Printer Firmware * Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin] * * Based on Sprinter and grbl. * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <https://www.gnu.org/licenses/>. * */ #include "../../../inc/MarlinConfig.h" #if HAS_TRINAMIC_CONFIG #include "../../gcode.h" #include "../../../feature/tmc_util.h" #include "../../../module/stepper/indirection.h" // for restore_stepper_drivers /** * M122: Debug TMC drivers * * I - Flag to re-initialize stepper drivers with current settings. * X, Y, Z, E - Flags to only report the specified axes. * * With TMC_DEBUG: * V - Report raw register data. Refer to the datasheet to decipher the report. * S - Flag to enable/disable continuous debug reporting. * P<ms> - Interval between continuous debug reports, in milliseconds. */ void GcodeSuite::M122() { xyze_bool_t print_axis = ARRAY_N_1(LOGICAL_AXES, false); bool print_all = true; LOOP_LOGICAL_AXES(i) if (parser.seen_test(AXIS_CHAR(i))) { print_axis[i] = true; print_all = false; } if (print_all) LOOP_LOGICAL_AXES(i) print_axis[i] = true; if (parser.boolval('I')) restore_stepper_drivers(); #if ENABLED(TMC_DEBUG) #if ENABLED(MONITOR_DRIVER_STATUS) const bool sflag = parser.seen_test('S'), sval = sflag && parser.value_bool(); if (sflag && !sval) tmc_set_report_interval(0); else if (parser.seenval('P')) tmc_set_report_interval(_MAX(uint16_t(250), parser.value_ushort())); else if (sval) tmc_set_report_interval(MONITOR_DRIVER_STATUS_INTERVAL_MS); #endif if (parser.seen_test('V')) tmc_get_registers(LOGICAL_AXIS_ELEM(print_axis)); else tmc_report_all(LOGICAL_AXIS_ELEM(print_axis)); #endif test_tmc_connection(LOGICAL_AXIS_ELEM(print_axis)); } #endif // HAS_TRINAMIC_CONFIG
2301_81045437/Marlin
Marlin/src/gcode/feature/trinamic/M122.cpp
C++
agpl-3.0
2,497
/** * Marlin 3D Printer Firmware * Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin] * * Based on Sprinter and grbl. * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <https://www.gnu.org/licenses/>. * */ #include "../../../inc/MarlinConfig.h" #if HAS_STEALTHCHOP #if AXIS_COLLISION('I') #error "M569 parameter 'I' collision with axis name." #endif #include "../../gcode.h" #include "../../../feature/tmc_util.h" #include "../../../module/stepper/indirection.h" template<typename TMC> void tmc_say_stealth_status(TMC &st) { st.printLabel(); SERIAL_ECHOLN(F(" driver mode:\t"), st.get_stealthChop() ? F("stealthChop") : F("spreadCycle")); } template<typename TMC> void tmc_set_stealthChop(TMC &st, const bool enable) { st.stored.stealthChop_enabled = enable; st.refresh_stepping_mode(); } static void set_stealth_status(const bool enable, const int8_t eindex) { #define TMC_SET_STEALTH(Q) tmc_set_stealthChop(stepper##Q, enable) #if X2_HAS_STEALTHCHOP || Y2_HAS_STEALTHCHOP || Z2_HAS_STEALTHCHOP || Z3_HAS_STEALTHCHOP || Z4_HAS_STEALTHCHOP const int8_t index = parser.byteval('I', -1); #else constexpr int8_t index = -1; #endif UNUSED(index); LOOP_LOGICAL_AXES(i) if (parser.seen(AXIS_CHAR(i))) { switch (i) { #if HAS_X_AXIS case X_AXIS: TERN_(X_HAS_STEALTHCHOP, if (index < 0 || index == 0) TMC_SET_STEALTH(X)); TERN_(X2_HAS_STEALTHCHOP, if (index < 0 || index == 1) TMC_SET_STEALTH(X2)); break; #endif #if HAS_Y_AXIS case Y_AXIS: TERN_(Y_HAS_STEALTHCHOP, if (index < 0 || index == 0) TMC_SET_STEALTH(Y)); TERN_(Y2_HAS_STEALTHCHOP, if (index < 0 || index == 1) TMC_SET_STEALTH(Y2)); break; #endif #if HAS_Z_AXIS case Z_AXIS: TERN_(Z_HAS_STEALTHCHOP, if (index < 0 || index == 0) TMC_SET_STEALTH(Z)); TERN_(Z2_HAS_STEALTHCHOP, if (index < 0 || index == 1) TMC_SET_STEALTH(Z2)); TERN_(Z3_HAS_STEALTHCHOP, if (index < 0 || index == 2) TMC_SET_STEALTH(Z3)); TERN_(Z4_HAS_STEALTHCHOP, if (index < 0 || index == 3) TMC_SET_STEALTH(Z4)); break; #endif #if I_HAS_STEALTHCHOP case I_AXIS: TMC_SET_STEALTH(I); break; #endif #if J_HAS_STEALTHCHOP case J_AXIS: TMC_SET_STEALTH(J); break; #endif #if K_HAS_STEALTHCHOP case K_AXIS: TMC_SET_STEALTH(K); break; #endif #if U_HAS_STEALTHCHOP case U_AXIS: TMC_SET_STEALTH(U); break; #endif #if V_HAS_STEALTHCHOP case V_AXIS: TMC_SET_STEALTH(V); break; #endif #if W_HAS_STEALTHCHOP case W_AXIS: TMC_SET_STEALTH(W); break; #endif #if E_STEPPERS case E_AXIS: { TERN_(E0_HAS_STEALTHCHOP, if (eindex < 0 || eindex == 0) TMC_SET_STEALTH(E0)); TERN_(E1_HAS_STEALTHCHOP, if (eindex < 0 || eindex == 1) TMC_SET_STEALTH(E1)); TERN_(E2_HAS_STEALTHCHOP, if (eindex < 0 || eindex == 2) TMC_SET_STEALTH(E2)); TERN_(E3_HAS_STEALTHCHOP, if (eindex < 0 || eindex == 3) TMC_SET_STEALTH(E3)); TERN_(E4_HAS_STEALTHCHOP, if (eindex < 0 || eindex == 4) TMC_SET_STEALTH(E4)); TERN_(E5_HAS_STEALTHCHOP, if (eindex < 0 || eindex == 5) TMC_SET_STEALTH(E5)); TERN_(E6_HAS_STEALTHCHOP, if (eindex < 0 || eindex == 6) TMC_SET_STEALTH(E6)); TERN_(E7_HAS_STEALTHCHOP, if (eindex < 0 || eindex == 7) TMC_SET_STEALTH(E7)); } break; #endif } } } static void say_stealth_status() { #define TMC_SAY_STEALTH_STATUS(Q) tmc_say_stealth_status(stepper##Q) OPTCODE( X_HAS_STEALTHCHOP, TMC_SAY_STEALTH_STATUS(X)) OPTCODE(X2_HAS_STEALTHCHOP, TMC_SAY_STEALTH_STATUS(X2)) OPTCODE( Y_HAS_STEALTHCHOP, TMC_SAY_STEALTH_STATUS(Y)) OPTCODE(Y2_HAS_STEALTHCHOP, TMC_SAY_STEALTH_STATUS(Y2)) OPTCODE( Z_HAS_STEALTHCHOP, TMC_SAY_STEALTH_STATUS(Z)) OPTCODE(Z2_HAS_STEALTHCHOP, TMC_SAY_STEALTH_STATUS(Z2)) OPTCODE(Z3_HAS_STEALTHCHOP, TMC_SAY_STEALTH_STATUS(Z3)) OPTCODE(Z4_HAS_STEALTHCHOP, TMC_SAY_STEALTH_STATUS(Z4)) OPTCODE( I_HAS_STEALTHCHOP, TMC_SAY_STEALTH_STATUS(I)) OPTCODE( J_HAS_STEALTHCHOP, TMC_SAY_STEALTH_STATUS(J)) OPTCODE( K_HAS_STEALTHCHOP, TMC_SAY_STEALTH_STATUS(K)) OPTCODE( U_HAS_STEALTHCHOP, TMC_SAY_STEALTH_STATUS(U)) OPTCODE( V_HAS_STEALTHCHOP, TMC_SAY_STEALTH_STATUS(V)) OPTCODE( W_HAS_STEALTHCHOP, TMC_SAY_STEALTH_STATUS(W)) OPTCODE(E0_HAS_STEALTHCHOP, TMC_SAY_STEALTH_STATUS(E0)) OPTCODE(E1_HAS_STEALTHCHOP, TMC_SAY_STEALTH_STATUS(E1)) OPTCODE(E2_HAS_STEALTHCHOP, TMC_SAY_STEALTH_STATUS(E2)) OPTCODE(E3_HAS_STEALTHCHOP, TMC_SAY_STEALTH_STATUS(E3)) OPTCODE(E4_HAS_STEALTHCHOP, TMC_SAY_STEALTH_STATUS(E4)) OPTCODE(E5_HAS_STEALTHCHOP, TMC_SAY_STEALTH_STATUS(E5)) OPTCODE(E6_HAS_STEALTHCHOP, TMC_SAY_STEALTH_STATUS(E6)) OPTCODE(E7_HAS_STEALTHCHOP, TMC_SAY_STEALTH_STATUS(E7)) } /** * M569: Enable stealthChop on an axis * * S[1|0] to enable or disable * XYZE to target an axis * No arguments reports the stealthChop status of all capable drivers. */ void GcodeSuite::M569() { if (parser.seen('S')) set_stealth_status(parser.value_bool(), get_target_e_stepper_from_command(-2)); else say_stealth_status(); } void GcodeSuite::M569_report(const bool forReplay/*=true*/) { TERN_(MARLIN_SMALL_BUILD, return); report_heading(forReplay, F(STR_DRIVER_STEPPING_MODE)); auto say_M569 = [](const bool forReplay, FSTR_P const etc=nullptr, const bool eol=false) { if (!forReplay) SERIAL_ECHO_START(); SERIAL_ECHOPGM(" M569 S1"); if (etc) SERIAL_ECHO(C(' '), etc); if (eol) SERIAL_EOL(); }; const bool chop_x = TERN0(X_HAS_STEALTHCHOP, stepperX.get_stored_stealthChop()), chop_y = TERN0(Y_HAS_STEALTHCHOP, stepperY.get_stored_stealthChop()), chop_z = TERN0(Z_HAS_STEALTHCHOP, stepperZ.get_stored_stealthChop()), chop_i = TERN0(I_HAS_STEALTHCHOP, stepperI.get_stored_stealthChop()), chop_j = TERN0(J_HAS_STEALTHCHOP, stepperJ.get_stored_stealthChop()), chop_k = TERN0(K_HAS_STEALTHCHOP, stepperK.get_stored_stealthChop()), chop_u = TERN0(U_HAS_STEALTHCHOP, stepperU.get_stored_stealthChop()), chop_v = TERN0(V_HAS_STEALTHCHOP, stepperV.get_stored_stealthChop()), chop_w = TERN0(W_HAS_STEALTHCHOP, stepperW.get_stored_stealthChop()); if (chop_x || chop_y || chop_z || chop_i || chop_j || chop_k || chop_u || chop_v || chop_w) { say_M569(forReplay); NUM_AXIS_CODE( if (chop_x) SERIAL_ECHOPGM_P(SP_X_STR), if (chop_y) SERIAL_ECHOPGM_P(SP_Y_STR), if (chop_z) SERIAL_ECHOPGM_P(SP_Z_STR), if (chop_i) SERIAL_ECHOPGM_P(SP_I_STR), if (chop_j) SERIAL_ECHOPGM_P(SP_J_STR), if (chop_k) SERIAL_ECHOPGM_P(SP_K_STR), if (chop_u) SERIAL_ECHOPGM_P(SP_U_STR), if (chop_v) SERIAL_ECHOPGM_P(SP_V_STR), if (chop_w) SERIAL_ECHOPGM_P(SP_W_STR) ); SERIAL_EOL(); } const bool chop_x2 = TERN0(X2_HAS_STEALTHCHOP, stepperX2.get_stored_stealthChop()), chop_y2 = TERN0(Y2_HAS_STEALTHCHOP, stepperY2.get_stored_stealthChop()), chop_z2 = TERN0(Z2_HAS_STEALTHCHOP, stepperZ2.get_stored_stealthChop()); if (chop_x2 || chop_y2 || chop_z2) { say_M569(forReplay, F("I1")); NUM_AXIS_CODE( if (chop_x2) SERIAL_ECHOPGM_P(SP_X_STR), if (chop_y2) SERIAL_ECHOPGM_P(SP_Y_STR), if (chop_z2) SERIAL_ECHOPGM_P(SP_Z_STR), NOOP, NOOP, NOOP, NOOP, NOOP, NOOP ); SERIAL_EOL(); } if (TERN0(Z3_HAS_STEALTHCHOP, stepperZ3.get_stored_stealthChop())) { say_M569(forReplay, F("I2 Z"), true); } if (TERN0(Z4_HAS_STEALTHCHOP, stepperZ4.get_stored_stealthChop())) { say_M569(forReplay, F("I3 Z"), true); } #if HAS_I_AXIS if (TERN0(I_HAS_STEALTHCHOP, stepperI.get_stored_stealthChop())) { say_M569(forReplay, FPSTR(SP_I_STR), true); } #endif #if HAS_J_AXIS if (TERN0(J_HAS_STEALTHCHOP, stepperJ.get_stored_stealthChop())) { say_M569(forReplay, FPSTR(SP_J_STR), true); } #endif #if HAS_K_AXIS if (TERN0(K_HAS_STEALTHCHOP, stepperK.get_stored_stealthChop())) { say_M569(forReplay, FPSTR(SP_K_STR), true); } #endif #if HAS_U_AXIS if (TERN0(U_HAS_STEALTHCHOP, stepperU.get_stored_stealthChop())) { say_M569(forReplay, FPSTR(SP_U_STR), true); } #endif #if HAS_V_AXIS if (TERN0(V_HAS_STEALTHCHOP, stepperV.get_stored_stealthChop())) { say_M569(forReplay, FPSTR(SP_V_STR), true); } #endif #if HAS_W_AXIS if (TERN0(W_HAS_STEALTHCHOP, stepperW.get_stored_stealthChop())) { say_M569(forReplay, FPSTR(SP_W_STR), true); } #endif if (TERN0(E0_HAS_STEALTHCHOP, stepperE0.get_stored_stealthChop())) { say_M569(forReplay, F("T0 E"), true); } if (TERN0(E1_HAS_STEALTHCHOP, stepperE1.get_stored_stealthChop())) { say_M569(forReplay, F("T1 E"), true); } if (TERN0(E2_HAS_STEALTHCHOP, stepperE2.get_stored_stealthChop())) { say_M569(forReplay, F("T2 E"), true); } if (TERN0(E3_HAS_STEALTHCHOP, stepperE3.get_stored_stealthChop())) { say_M569(forReplay, F("T3 E"), true); } if (TERN0(E4_HAS_STEALTHCHOP, stepperE4.get_stored_stealthChop())) { say_M569(forReplay, F("T4 E"), true); } if (TERN0(E5_HAS_STEALTHCHOP, stepperE5.get_stored_stealthChop())) { say_M569(forReplay, F("T5 E"), true); } if (TERN0(E6_HAS_STEALTHCHOP, stepperE6.get_stored_stealthChop())) { say_M569(forReplay, F("T6 E"), true); } if (TERN0(E7_HAS_STEALTHCHOP, stepperE7.get_stored_stealthChop())) { say_M569(forReplay, F("T7 E"), true); } } #endif // HAS_STEALTHCHOP
2301_81045437/Marlin
Marlin/src/gcode/feature/trinamic/M569.cpp
C++
agpl-3.0
10,186
/** * Marlin 3D Printer Firmware * Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin] * * Based on Sprinter and grbl. * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <https://www.gnu.org/licenses/>. * */ #include "../../../inc/MarlinConfig.h" #if HAS_TRINAMIC_CONFIG #include "../../gcode.h" #include "../../../feature/tmc_util.h" #include "../../../module/stepper/indirection.h" template<typename TMC> static void tmc_print_current(TMC &st) { st.printLabel(); SERIAL_ECHOLNPGM(" driver current: ", st.getMilliamps()); } /** * M906: Set motor current in milliamps. * * Parameters: * X[current] - Set mA current for X driver(s) * Y[current] - Set mA current for Y driver(s) * Z[current] - Set mA current for Z driver(s) * A[current] - Set mA current for A driver(s) (Requires AXIS*_NAME 'A') * B[current] - Set mA current for B driver(s) (Requires AXIS*_NAME 'B') * C[current] - Set mA current for C driver(s) (Requires AXIS*_NAME 'C') * U[current] - Set mA current for U driver(s) (Requires AXIS*_NAME 'U') * V[current] - Set mA current for V driver(s) (Requires AXIS*_NAME 'V') * W[current] - Set mA current for W driver(s) (Requires AXIS*_NAME 'W') * E[current] - Set mA current for E driver(s) * * I[index] - Axis sub-index (Omit or 0 for X, Y, Z; 1 for X2, Y2, Z2; 2 for Z3; 3 for Z4.) * T[index] - Extruder index (Zero-based. Omit for E0 only.) * * With no parameters report driver currents. */ void GcodeSuite::M906() { #define TMC_SAY_CURRENT(Q) tmc_print_current(stepper##Q) #define TMC_SET_CURRENT(Q) stepper##Q.rms_current(value) bool report = true; #if AXIS_IS_TMC(X2) || AXIS_IS_TMC(Y2) || AXIS_IS_TMC(Z2) || AXIS_IS_TMC(Z3) || AXIS_IS_TMC(Z4) const int8_t index = parser.byteval('I', -1); #elif AXIS_IS_TMC(X) || AXIS_IS_TMC(Y) || AXIS_IS_TMC(Z) constexpr int8_t index = -1; #endif LOOP_LOGICAL_AXES(i) if (uint16_t value = parser.intval(AXIS_CHAR(i))) { report = false; switch (i) { #if AXIS_IS_TMC(X) || AXIS_IS_TMC(X2) case X_AXIS: #if AXIS_IS_TMC(X) if (index < 0 || index == 0) TMC_SET_CURRENT(X); #endif #if AXIS_IS_TMC(X2) if (index < 0 || index == 1) TMC_SET_CURRENT(X2); #endif break; #endif #if AXIS_IS_TMC(Y) || AXIS_IS_TMC(Y2) case Y_AXIS: #if AXIS_IS_TMC(Y) if (index < 0 || index == 0) TMC_SET_CURRENT(Y); #endif #if AXIS_IS_TMC(Y2) if (index < 0 || index == 1) TMC_SET_CURRENT(Y2); #endif break; #endif #if AXIS_IS_TMC(Z) || AXIS_IS_TMC(Z2) || AXIS_IS_TMC(Z3) || AXIS_IS_TMC(Z4) case Z_AXIS: #if AXIS_IS_TMC(Z) if (index < 0 || index == 0) TMC_SET_CURRENT(Z); #endif #if AXIS_IS_TMC(Z2) if (index < 0 || index == 1) TMC_SET_CURRENT(Z2); #endif #if AXIS_IS_TMC(Z3) if (index < 0 || index == 2) TMC_SET_CURRENT(Z3); #endif #if AXIS_IS_TMC(Z4) if (index < 0 || index == 3) TMC_SET_CURRENT(Z4); #endif break; #endif #if AXIS_IS_TMC(I) case I_AXIS: TMC_SET_CURRENT(I); break; #endif #if AXIS_IS_TMC(J) case J_AXIS: TMC_SET_CURRENT(J); break; #endif #if AXIS_IS_TMC(K) case K_AXIS: TMC_SET_CURRENT(K); break; #endif #if AXIS_IS_TMC(U) case U_AXIS: TMC_SET_CURRENT(U); break; #endif #if AXIS_IS_TMC(V) case V_AXIS: TMC_SET_CURRENT(V); break; #endif #if AXIS_IS_TMC(W) case W_AXIS: TMC_SET_CURRENT(W); break; #endif #if AXIS_IS_TMC(E0) || AXIS_IS_TMC(E1) || AXIS_IS_TMC(E2) || AXIS_IS_TMC(E3) || AXIS_IS_TMC(E4) || AXIS_IS_TMC(E5) || AXIS_IS_TMC(E6) || AXIS_IS_TMC(E7) case E_AXIS: { const int8_t eindex = get_target_e_stepper_from_command(-2); #if AXIS_IS_TMC(E0) if (eindex < 0 || eindex == 0) TMC_SET_CURRENT(E0); #endif #if AXIS_IS_TMC(E1) if (eindex < 0 || eindex == 1) TMC_SET_CURRENT(E1); #endif #if AXIS_IS_TMC(E2) if (eindex < 0 || eindex == 2) TMC_SET_CURRENT(E2); #endif #if AXIS_IS_TMC(E3) if (eindex < 0 || eindex == 3) TMC_SET_CURRENT(E3); #endif #if AXIS_IS_TMC(E4) if (eindex < 0 || eindex == 4) TMC_SET_CURRENT(E4); #endif #if AXIS_IS_TMC(E5) if (eindex < 0 || eindex == 5) TMC_SET_CURRENT(E5); #endif #if AXIS_IS_TMC(E6) if (eindex < 0 || eindex == 6) TMC_SET_CURRENT(E6); #endif #if AXIS_IS_TMC(E7) if (eindex < 0 || eindex == 7) TMC_SET_CURRENT(E7); #endif } break; #endif } } if (report) { #if AXIS_IS_TMC(X) TMC_SAY_CURRENT(X); #endif #if AXIS_IS_TMC(X2) TMC_SAY_CURRENT(X2); #endif #if AXIS_IS_TMC(Y) TMC_SAY_CURRENT(Y); #endif #if AXIS_IS_TMC(Y2) TMC_SAY_CURRENT(Y2); #endif #if AXIS_IS_TMC(Z) TMC_SAY_CURRENT(Z); #endif #if AXIS_IS_TMC(Z2) TMC_SAY_CURRENT(Z2); #endif #if AXIS_IS_TMC(Z3) TMC_SAY_CURRENT(Z3); #endif #if AXIS_IS_TMC(Z4) TMC_SAY_CURRENT(Z4); #endif #if AXIS_IS_TMC(I) TMC_SAY_CURRENT(I); #endif #if AXIS_IS_TMC(J) TMC_SAY_CURRENT(J); #endif #if AXIS_IS_TMC(K) TMC_SAY_CURRENT(K); #endif #if AXIS_IS_TMC(U) TMC_SAY_CURRENT(U); #endif #if AXIS_IS_TMC(V) TMC_SAY_CURRENT(V); #endif #if AXIS_IS_TMC(W) TMC_SAY_CURRENT(W); #endif #if AXIS_IS_TMC(E0) TMC_SAY_CURRENT(E0); #endif #if AXIS_IS_TMC(E1) TMC_SAY_CURRENT(E1); #endif #if AXIS_IS_TMC(E2) TMC_SAY_CURRENT(E2); #endif #if AXIS_IS_TMC(E3) TMC_SAY_CURRENT(E3); #endif #if AXIS_IS_TMC(E4) TMC_SAY_CURRENT(E4); #endif #if AXIS_IS_TMC(E5) TMC_SAY_CURRENT(E5); #endif #if AXIS_IS_TMC(E6) TMC_SAY_CURRENT(E6); #endif #if AXIS_IS_TMC(E7) TMC_SAY_CURRENT(E7); #endif } } void GcodeSuite::M906_report(const bool forReplay/*=true*/) { TERN_(MARLIN_SMALL_BUILD, return); report_heading(forReplay, F(STR_STEPPER_DRIVER_CURRENT)); auto say_M906 = [](const bool forReplay) { report_echo_start(forReplay); SERIAL_ECHOPGM(" M906"); }; #if AXIS_IS_TMC(X) || AXIS_IS_TMC(Y) || AXIS_IS_TMC(Z) \ || AXIS_IS_TMC(I) || AXIS_IS_TMC(J) || AXIS_IS_TMC(K) \ || AXIS_IS_TMC(U) || AXIS_IS_TMC(V) || AXIS_IS_TMC(W) say_M906(forReplay); #if AXIS_IS_TMC(X) SERIAL_ECHOPGM_P(SP_X_STR, stepperX.getMilliamps()); #endif #if AXIS_IS_TMC(Y) SERIAL_ECHOPGM_P(SP_Y_STR, stepperY.getMilliamps()); #endif #if AXIS_IS_TMC(Z) SERIAL_ECHOPGM_P(SP_Z_STR, stepperZ.getMilliamps()); #endif #if AXIS_IS_TMC(I) SERIAL_ECHOPGM_P(SP_I_STR, stepperI.getMilliamps()); #endif #if AXIS_IS_TMC(J) SERIAL_ECHOPGM_P(SP_J_STR, stepperJ.getMilliamps()); #endif #if AXIS_IS_TMC(K) SERIAL_ECHOPGM_P(SP_K_STR, stepperK.getMilliamps()); #endif #if AXIS_IS_TMC(U) SERIAL_ECHOPGM_P(SP_U_STR, stepperU.getMilliamps()); #endif #if AXIS_IS_TMC(V) SERIAL_ECHOPGM_P(SP_V_STR, stepperV.getMilliamps()); #endif #if AXIS_IS_TMC(W) SERIAL_ECHOPGM_P(SP_W_STR, stepperW.getMilliamps()); #endif SERIAL_EOL(); #endif #if AXIS_IS_TMC(X2) || AXIS_IS_TMC(Y2) || AXIS_IS_TMC(Z2) say_M906(forReplay); SERIAL_ECHOPGM(" I1"); #if AXIS_IS_TMC(X2) SERIAL_ECHOPGM_P(SP_X_STR, stepperX2.getMilliamps()); #endif #if AXIS_IS_TMC(Y2) SERIAL_ECHOPGM_P(SP_Y_STR, stepperY2.getMilliamps()); #endif #if AXIS_IS_TMC(Z2) SERIAL_ECHOPGM_P(SP_Z_STR, stepperZ2.getMilliamps()); #endif SERIAL_EOL(); #endif #if AXIS_IS_TMC(Z3) say_M906(forReplay); SERIAL_ECHOLNPGM(" I2 Z", stepperZ3.getMilliamps()); #endif #if AXIS_IS_TMC(Z4) say_M906(forReplay); SERIAL_ECHOLNPGM(" I3 Z", stepperZ4.getMilliamps()); #endif #if AXIS_IS_TMC(E0) say_M906(forReplay); SERIAL_ECHOLNPGM(" T0 E", stepperE0.getMilliamps()); #endif #if AXIS_IS_TMC(E1) say_M906(forReplay); SERIAL_ECHOLNPGM(" T1 E", stepperE1.getMilliamps()); #endif #if AXIS_IS_TMC(E2) say_M906(forReplay); SERIAL_ECHOLNPGM(" T2 E", stepperE2.getMilliamps()); #endif #if AXIS_IS_TMC(E3) say_M906(forReplay); SERIAL_ECHOLNPGM(" T3 E", stepperE3.getMilliamps()); #endif #if AXIS_IS_TMC(E4) say_M906(forReplay); SERIAL_ECHOLNPGM(" T4 E", stepperE4.getMilliamps()); #endif #if AXIS_IS_TMC(E5) say_M906(forReplay); SERIAL_ECHOLNPGM(" T5 E", stepperE5.getMilliamps()); #endif #if AXIS_IS_TMC(E6) say_M906(forReplay); SERIAL_ECHOLNPGM(" T6 E", stepperE6.getMilliamps()); #endif #if AXIS_IS_TMC(E7) say_M906(forReplay); SERIAL_ECHOLNPGM(" T7 E", stepperE7.getMilliamps()); #endif } #endif // HAS_TRINAMIC_CONFIG
2301_81045437/Marlin
Marlin/src/gcode/feature/trinamic/M906.cpp
C++
agpl-3.0
9,850
/** * Marlin 3D Printer Firmware * Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin] * * Based on Sprinter and grbl. * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <https://www.gnu.org/licenses/>. * */ #include "../../../inc/MarlinConfig.h" #if HAS_TRINAMIC_CONFIG #include "../../gcode.h" #include "../../../feature/tmc_util.h" #include "../../../module/stepper/indirection.h" #include "../../../module/planner.h" #include "../../queue.h" #if ENABLED(MONITOR_DRIVER_STATUS) #define M91x_USE(ST) (AXIS_DRIVER_TYPE(ST, TMC2130) || AXIS_DRIVER_TYPE(ST, TMC2160) || AXIS_DRIVER_TYPE(ST, TMC2208) || AXIS_DRIVER_TYPE(ST, TMC2209) || AXIS_DRIVER_TYPE(ST, TMC2660) || AXIS_DRIVER_TYPE(ST, TMC5130) || AXIS_DRIVER_TYPE(ST, TMC5160)) #define M91x_USE_E(N) (E_STEPPERS > N && M91x_USE(E##N)) #if HAS_X_AXIS && (M91x_USE(X) || M91x_USE(X2)) #define M91x_SOME_X 1 #endif #if HAS_Y_AXIS && (M91x_USE(Y) || M91x_USE(Y2)) #define M91x_SOME_Y 1 #endif #if HAS_Z_AXIS && (M91x_USE(Z) || M91x_USE(Z2) || M91x_USE(Z3) || M91x_USE(Z4)) #define M91x_SOME_Z 1 #endif #if HAS_I_AXIS && M91x_USE(I) #define M91x_USE_I 1 #endif #if HAS_J_AXIS && M91x_USE(J) #define M91x_USE_J 1 #endif #if HAS_K_AXIS && M91x_USE(K) #define M91x_USE_K 1 #endif #if HAS_U_AXIS && M91x_USE(U) #define M91x_USE_U 1 #endif #if HAS_V_AXIS && M91x_USE(V) #define M91x_USE_V 1 #endif #if HAS_W_AXIS && M91x_USE(W) #define M91x_USE_W 1 #endif #if M91x_USE_E(0) || M91x_USE_E(1) || M91x_USE_E(2) || M91x_USE_E(3) || M91x_USE_E(4) || M91x_USE_E(5) || M91x_USE_E(6) || M91x_USE_E(7) #define M91x_SOME_E 1 #endif #if !M91x_SOME_X && !M91x_SOME_Y && !M91x_SOME_Z && !M91x_USE_I && !M91x_USE_J && !M91x_USE_K && !M91x_USE_U && !M91x_USE_V && !M91x_USE_W && !M91x_SOME_E #error "MONITOR_DRIVER_STATUS requires at least one TMC2130, 2160, 2208, 2209, 2660, 5130, or 5160." #endif template<typename TMC> static void tmc_report_otpw(TMC &st) { st.printLabel(); SERIAL_ECHOPGM(" temperature prewarn triggered: "); serialprint_truefalse(st.getOTPW()); SERIAL_EOL(); } template<typename TMC> static void tmc_clear_otpw(TMC &st) { st.clear_otpw(); st.printLabel(); SERIAL_ECHOLNPGM(" prewarn flag cleared"); } /** * M911: Report TMC stepper driver overtemperature pre-warn flag * This flag is held by the library, persisting until cleared by M912 */ void GcodeSuite::M911() { #if M91x_USE(X) tmc_report_otpw(stepperX); #endif #if M91x_USE(X2) tmc_report_otpw(stepperX2); #endif #if M91x_USE(Y) tmc_report_otpw(stepperY); #endif #if M91x_USE(Y2) tmc_report_otpw(stepperY2); #endif #if M91x_USE(Z) tmc_report_otpw(stepperZ); #endif #if M91x_USE(Z2) tmc_report_otpw(stepperZ2); #endif #if M91x_USE(Z3) tmc_report_otpw(stepperZ3); #endif #if M91x_USE(Z4) tmc_report_otpw(stepperZ4); #endif TERN_(M91x_USE_I, tmc_report_otpw(stepperI)); TERN_(M91x_USE_J, tmc_report_otpw(stepperJ)); TERN_(M91x_USE_K, tmc_report_otpw(stepperK)); TERN_(M91x_USE_U, tmc_report_otpw(stepperU)); TERN_(M91x_USE_V, tmc_report_otpw(stepperV)); TERN_(M91x_USE_W, tmc_report_otpw(stepperW)); #if M91x_USE_E(0) tmc_report_otpw(stepperE0); #endif #if M91x_USE_E(1) tmc_report_otpw(stepperE1); #endif #if M91x_USE_E(2) tmc_report_otpw(stepperE2); #endif #if M91x_USE_E(3) tmc_report_otpw(stepperE3); #endif #if M91x_USE_E(4) tmc_report_otpw(stepperE4); #endif #if M91x_USE_E(5) tmc_report_otpw(stepperE5); #endif #if M91x_USE_E(6) tmc_report_otpw(stepperE6); #endif #if M91x_USE_E(7) tmc_report_otpw(stepperE7); #endif } /** * M912: Clear TMC stepper driver overtemperature pre-warn flag held by the library * Specify one or more axes with X, Y, Z, X1, Y1, Z1, X2, Y2, Z2, Z3, Z4, A, B, C, U, V, W, and E[index]. * If no axes are given, clear all. * * Examples: * M912 X ; clear X and X2 * M912 X1 ; clear X1 only * M912 X2 ; clear X2 only * M912 X E ; clear X, X2, and all E * M912 E1 ; clear E1 only */ void GcodeSuite::M912() { const bool hasX = TERN0(M91x_SOME_X, parser.seen(axis_codes.x)), hasY = TERN0(M91x_SOME_Y, parser.seen(axis_codes.y)), hasZ = TERN0(M91x_SOME_Z, parser.seen(axis_codes.z)), hasI = TERN0(M91x_USE_I, parser.seen(axis_codes.i)), hasJ = TERN0(M91x_USE_J, parser.seen(axis_codes.j)), hasK = TERN0(M91x_USE_K, parser.seen(axis_codes.k)), hasU = TERN0(M91x_USE_U, parser.seen(axis_codes.u)), hasV = TERN0(M91x_USE_V, parser.seen(axis_codes.v)), hasW = TERN0(M91x_USE_W, parser.seen(axis_codes.w)), hasE = TERN0(M91x_SOME_E, parser.seen(axis_codes.e)); const bool hasNone = !hasE && !hasX && !hasY && !hasZ && !hasI && !hasJ && !hasK && !hasU && !hasV && !hasW; #if M91x_SOME_X const int8_t xval = int8_t(parser.byteval(axis_codes.x, 0xFF)); #if M91x_USE(X) if (hasNone || xval == 1 || (hasX && xval < 0)) tmc_clear_otpw(stepperX); #endif #if M91x_USE(X2) if (hasNone || xval == 2 || (hasX && xval < 0)) tmc_clear_otpw(stepperX2); #endif #endif #if M91x_SOME_Y const int8_t yval = int8_t(parser.byteval(axis_codes.y, 0xFF)); #if M91x_USE(Y) if (hasNone || yval == 1 || (hasY && yval < 0)) tmc_clear_otpw(stepperY); #endif #if M91x_USE(Y2) if (hasNone || yval == 2 || (hasY && yval < 0)) tmc_clear_otpw(stepperY2); #endif #endif #if M91x_SOME_Z const int8_t zval = int8_t(parser.byteval(axis_codes.z, 0xFF)); #if M91x_USE(Z) if (hasNone || zval == 1 || (hasZ && zval < 0)) tmc_clear_otpw(stepperZ); #endif #if M91x_USE(Z2) if (hasNone || zval == 2 || (hasZ && zval < 0)) tmc_clear_otpw(stepperZ2); #endif #if M91x_USE(Z3) if (hasNone || zval == 3 || (hasZ && zval < 0)) tmc_clear_otpw(stepperZ3); #endif #if M91x_USE(Z4) if (hasNone || zval == 4 || (hasZ && zval < 0)) tmc_clear_otpw(stepperZ4); #endif #endif #if M91x_USE_I const int8_t ival = int8_t(parser.byteval(axis_codes.i, 0xFF)); if (hasNone || ival == 1 || (hasI && ival < 0)) tmc_clear_otpw(stepperI); #endif #if M91x_USE_J const int8_t jval = int8_t(parser.byteval(axis_codes.j, 0xFF)); if (hasNone || jval == 1 || (hasJ && jval < 0)) tmc_clear_otpw(stepperJ); #endif #if M91x_USE_K const int8_t kval = int8_t(parser.byteval(axis_codes.k, 0xFF)); if (hasNone || kval == 1 || (hasK && kval < 0)) tmc_clear_otpw(stepperK); #endif #if M91x_USE_U const int8_t uval = int8_t(parser.byteval(axis_codes.u, 0xFF)); if (hasNone || uval == 1 || (hasU && uval < 0)) tmc_clear_otpw(stepperU); #endif #if M91x_USE_V const int8_t vval = int8_t(parser.byteval(axis_codes.v, 0xFF)); if (hasNone || vval == 1 || (hasV && vval < 0)) tmc_clear_otpw(stepperV); #endif #if M91x_USE_W const int8_t wval = int8_t(parser.byteval(axis_codes.w, 0xFF)); if (hasNone || wval == 1 || (hasW && wval < 0)) tmc_clear_otpw(stepperW); #endif #if M91x_SOME_E const int8_t eval = int8_t(parser.byteval(axis_codes.e, 0xFF)); #if M91x_USE_E(0) if (hasNone || eval == 0 || (hasE && eval < 0)) tmc_clear_otpw(stepperE0); #endif #if M91x_USE_E(1) if (hasNone || eval == 1 || (hasE && eval < 0)) tmc_clear_otpw(stepperE1); #endif #if M91x_USE_E(2) if (hasNone || eval == 2 || (hasE && eval < 0)) tmc_clear_otpw(stepperE2); #endif #if M91x_USE_E(3) if (hasNone || eval == 3 || (hasE && eval < 0)) tmc_clear_otpw(stepperE3); #endif #if M91x_USE_E(4) if (hasNone || eval == 4 || (hasE && eval < 0)) tmc_clear_otpw(stepperE4); #endif #if M91x_USE_E(5) if (hasNone || eval == 5 || (hasE && eval < 0)) tmc_clear_otpw(stepperE5); #endif #if M91x_USE_E(6) if (hasNone || eval == 6 || (hasE && eval < 0)) tmc_clear_otpw(stepperE6); #endif #if M91x_USE_E(7) if (hasNone || eval == 7 || (hasE && eval < 0)) tmc_clear_otpw(stepperE7); #endif #endif } #endif // MONITOR_DRIVER_STATUS #if ENABLED(HYBRID_THRESHOLD) template<typename TMC> static void tmc_print_pwmthrs(TMC &st) { st.printLabel(); SERIAL_ECHOLNPGM(" stealthChop max speed: ", st.get_pwm_thrs()); } /** * M913: Set HYBRID_THRESHOLD speed. */ void GcodeSuite::M913() { #define TMC_SAY_PWMTHRS(A,Q) tmc_print_pwmthrs(stepper##Q) #define TMC_SET_PWMTHRS(A,Q) stepper##Q.set_pwm_thrs(value) #define TMC_SAY_PWMTHRS_E(E) tmc_print_pwmthrs(stepperE##E) #define TMC_SET_PWMTHRS_E(E) stepperE##E.set_pwm_thrs(value) bool report = true; #if AXIS_IS_TMC(X2) || AXIS_IS_TMC(Y2) || AXIS_IS_TMC(Z2) || AXIS_IS_TMC(Z3) || AXIS_IS_TMC(Z4) const uint8_t index = parser.byteval('I'); #elif AXIS_IS_TMC(X) || AXIS_IS_TMC(Y) || AXIS_IS_TMC(Z) constexpr uint8_t index = 0; #endif LOOP_LOGICAL_AXES(i) if (int32_t value = parser.longval(AXIS_CHAR(i))) { report = false; switch (i) { #if X_HAS_STEALTHCHOP || X2_HAS_STEALTHCHOP case X_AXIS: TERN_(X_HAS_STEALTHCHOP, if (index < 2) TMC_SET_PWMTHRS(X,X)); TERN_(X2_HAS_STEALTHCHOP, if (!index || index == 2) TMC_SET_PWMTHRS(X,X2)); break; #endif #if Y_HAS_STEALTHCHOP || Y2_HAS_STEALTHCHOP case Y_AXIS: TERN_(Y_HAS_STEALTHCHOP, if (index < 2) TMC_SET_PWMTHRS(Y,Y)); TERN_(Y2_HAS_STEALTHCHOP, if (!index || index == 2) TMC_SET_PWMTHRS(Y,Y2)); break; #endif #if Z_HAS_STEALTHCHOP || Z2_HAS_STEALTHCHOP || Z3_HAS_STEALTHCHOP || Z4_HAS_STEALTHCHOP case Z_AXIS: TERN_(Z_HAS_STEALTHCHOP, if (index < 2) TMC_SET_PWMTHRS(Z,Z)); TERN_(Z2_HAS_STEALTHCHOP, if (!index || index == 2) TMC_SET_PWMTHRS(Z,Z2)); TERN_(Z3_HAS_STEALTHCHOP, if (!index || index == 3) TMC_SET_PWMTHRS(Z,Z3)); TERN_(Z4_HAS_STEALTHCHOP, if (!index || index == 4) TMC_SET_PWMTHRS(Z,Z4)); break; #endif #if I_HAS_STEALTHCHOP case I_AXIS: TMC_SET_PWMTHRS(I,I); break; #endif #if J_HAS_STEALTHCHOP case J_AXIS: TMC_SET_PWMTHRS(J,J); break; #endif #if K_HAS_STEALTHCHOP case K_AXIS: TMC_SET_PWMTHRS(K,K); break; #endif #if U_HAS_STEALTHCHOP case U_AXIS: TMC_SET_PWMTHRS(U,U); break; #endif #if V_HAS_STEALTHCHOP case V_AXIS: TMC_SET_PWMTHRS(V,V); break; #endif #if W_HAS_STEALTHCHOP case W_AXIS: TMC_SET_PWMTHRS(W,W); break; #endif #if E0_HAS_STEALTHCHOP || E1_HAS_STEALTHCHOP || E2_HAS_STEALTHCHOP || E3_HAS_STEALTHCHOP || E4_HAS_STEALTHCHOP || E5_HAS_STEALTHCHOP || E6_HAS_STEALTHCHOP || E7_HAS_STEALTHCHOP case E_AXIS: { const int8_t eindex = get_target_e_stepper_from_command(-2); TERN_(E0_HAS_STEALTHCHOP, if (eindex < 0 || eindex == 0) TMC_SET_PWMTHRS_E(0)); TERN_(E1_HAS_STEALTHCHOP, if (eindex < 0 || eindex == 1) TMC_SET_PWMTHRS_E(1)); TERN_(E2_HAS_STEALTHCHOP, if (eindex < 0 || eindex == 2) TMC_SET_PWMTHRS_E(2)); TERN_(E3_HAS_STEALTHCHOP, if (eindex < 0 || eindex == 3) TMC_SET_PWMTHRS_E(3)); TERN_(E4_HAS_STEALTHCHOP, if (eindex < 0 || eindex == 4) TMC_SET_PWMTHRS_E(4)); TERN_(E5_HAS_STEALTHCHOP, if (eindex < 0 || eindex == 5) TMC_SET_PWMTHRS_E(5)); TERN_(E6_HAS_STEALTHCHOP, if (eindex < 0 || eindex == 6) TMC_SET_PWMTHRS_E(6)); TERN_(E7_HAS_STEALTHCHOP, if (eindex < 0 || eindex == 7) TMC_SET_PWMTHRS_E(7)); } break; #endif // E_STEPPERS } } if (report) { TERN_( X_HAS_STEALTHCHOP, TMC_SAY_PWMTHRS(X,X)); TERN_(X2_HAS_STEALTHCHOP, TMC_SAY_PWMTHRS(X,X2)); TERN_( Y_HAS_STEALTHCHOP, TMC_SAY_PWMTHRS(Y,Y)); TERN_(Y2_HAS_STEALTHCHOP, TMC_SAY_PWMTHRS(Y,Y2)); TERN_( Z_HAS_STEALTHCHOP, TMC_SAY_PWMTHRS(Z,Z)); TERN_(Z2_HAS_STEALTHCHOP, TMC_SAY_PWMTHRS(Z,Z2)); TERN_(Z3_HAS_STEALTHCHOP, TMC_SAY_PWMTHRS(Z,Z3)); TERN_(Z4_HAS_STEALTHCHOP, TMC_SAY_PWMTHRS(Z,Z4)); TERN_( I_HAS_STEALTHCHOP, TMC_SAY_PWMTHRS(I,I)); TERN_( J_HAS_STEALTHCHOP, TMC_SAY_PWMTHRS(J,J)); TERN_( K_HAS_STEALTHCHOP, TMC_SAY_PWMTHRS(K,K)); TERN_( U_HAS_STEALTHCHOP, TMC_SAY_PWMTHRS(U,U)); TERN_( V_HAS_STEALTHCHOP, TMC_SAY_PWMTHRS(V,V)); TERN_( W_HAS_STEALTHCHOP, TMC_SAY_PWMTHRS(W,W)); TERN_(E0_HAS_STEALTHCHOP, TMC_SAY_PWMTHRS_E(0)); TERN_(E1_HAS_STEALTHCHOP, TMC_SAY_PWMTHRS_E(1)); TERN_(E2_HAS_STEALTHCHOP, TMC_SAY_PWMTHRS_E(2)); TERN_(E3_HAS_STEALTHCHOP, TMC_SAY_PWMTHRS_E(3)); TERN_(E4_HAS_STEALTHCHOP, TMC_SAY_PWMTHRS_E(4)); TERN_(E5_HAS_STEALTHCHOP, TMC_SAY_PWMTHRS_E(5)); TERN_(E6_HAS_STEALTHCHOP, TMC_SAY_PWMTHRS_E(6)); TERN_(E7_HAS_STEALTHCHOP, TMC_SAY_PWMTHRS_E(7)); } } void GcodeSuite::M913_report(const bool forReplay/*=true*/) { TERN_(MARLIN_SMALL_BUILD, return); report_heading(forReplay, F(STR_HYBRID_THRESHOLD)); auto say_M913 = [](const bool forReplay) { report_echo_start(forReplay); SERIAL_ECHOPGM(" M913"); }; #if X_HAS_STEALTHCHOP || Y_HAS_STEALTHCHOP || Z_HAS_STEALTHCHOP say_M913(forReplay); #if X_HAS_STEALTHCHOP SERIAL_ECHOPGM_P(SP_X_STR, stepperX.get_pwm_thrs()); #endif #if Y_HAS_STEALTHCHOP SERIAL_ECHOPGM_P(SP_Y_STR, stepperY.get_pwm_thrs()); #endif #if Z_HAS_STEALTHCHOP SERIAL_ECHOPGM_P(SP_Z_STR, stepperZ.get_pwm_thrs()); #endif SERIAL_EOL(); #endif #if X2_HAS_STEALTHCHOP || Y2_HAS_STEALTHCHOP || Z2_HAS_STEALTHCHOP say_M913(forReplay); SERIAL_ECHOPGM(" I2"); #if X2_HAS_STEALTHCHOP SERIAL_ECHOPGM_P(SP_X_STR, stepperX2.get_pwm_thrs()); #endif #if Y2_HAS_STEALTHCHOP SERIAL_ECHOPGM_P(SP_Y_STR, stepperY2.get_pwm_thrs()); #endif #if Z2_HAS_STEALTHCHOP SERIAL_ECHOPGM_P(SP_Z_STR, stepperZ2.get_pwm_thrs()); #endif SERIAL_EOL(); #endif #if Z3_HAS_STEALTHCHOP say_M913(forReplay); SERIAL_ECHOLNPGM(" I3 Z", stepperZ3.get_pwm_thrs()); #endif #if Z4_HAS_STEALTHCHOP say_M913(forReplay); SERIAL_ECHOLNPGM(" I4 Z", stepperZ4.get_pwm_thrs()); #endif #if I_HAS_STEALTHCHOP say_M913(forReplay); SERIAL_ECHOLNPGM_P(SP_I_STR, stepperI.get_pwm_thrs()); #endif #if J_HAS_STEALTHCHOP say_M913(forReplay); SERIAL_ECHOLNPGM_P(SP_J_STR, stepperJ.get_pwm_thrs()); #endif #if K_HAS_STEALTHCHOP say_M913(forReplay); SERIAL_ECHOLNPGM_P(SP_K_STR, stepperK.get_pwm_thrs()); #endif #if U_HAS_STEALTHCHOP say_M913(forReplay); SERIAL_ECHOLNPGM_P(SP_U_STR, stepperU.get_pwm_thrs()); #endif #if V_HAS_STEALTHCHOP say_M913(forReplay); SERIAL_ECHOLNPGM_P(SP_V_STR, stepperV.get_pwm_thrs()); #endif #if W_HAS_STEALTHCHOP say_M913(forReplay); SERIAL_ECHOLNPGM_P(SP_W_STR, stepperW.get_pwm_thrs()); #endif #if E0_HAS_STEALTHCHOP say_M913(forReplay); SERIAL_ECHOLNPGM(" T0 E", stepperE0.get_pwm_thrs()); #endif #if E1_HAS_STEALTHCHOP say_M913(forReplay); SERIAL_ECHOLNPGM(" T1 E", stepperE1.get_pwm_thrs()); #endif #if E2_HAS_STEALTHCHOP say_M913(forReplay); SERIAL_ECHOLNPGM(" T2 E", stepperE2.get_pwm_thrs()); #endif #if E3_HAS_STEALTHCHOP say_M913(forReplay); SERIAL_ECHOLNPGM(" T3 E", stepperE3.get_pwm_thrs()); #endif #if E4_HAS_STEALTHCHOP say_M913(forReplay); SERIAL_ECHOLNPGM(" T4 E", stepperE4.get_pwm_thrs()); #endif #if E5_HAS_STEALTHCHOP say_M913(forReplay); SERIAL_ECHOLNPGM(" T5 E", stepperE5.get_pwm_thrs()); #endif #if E6_HAS_STEALTHCHOP say_M913(forReplay); SERIAL_ECHOLNPGM(" T6 E", stepperE6.get_pwm_thrs()); #endif #if E7_HAS_STEALTHCHOP say_M913(forReplay); SERIAL_ECHOLNPGM(" T7 E", stepperE7.get_pwm_thrs()); #endif SERIAL_EOL(); } #endif // HYBRID_THRESHOLD #if USE_SENSORLESS template<typename TMC> static void tmc_print_sgt(TMC &st) { st.printLabel(); SERIAL_ECHOPGM(" homing sensitivity: "); SERIAL_PRINTLN(st.homing_threshold(), PrintBase::Dec); } /** * M914: Set StallGuard sensitivity. */ void GcodeSuite::M914() { bool report = true; const uint8_t index = parser.byteval('I'); LOOP_NUM_AXES(i) if (parser.seen(AXIS_CHAR(i))) { const int16_t value = parser.value_int(); report = false; switch (i) { #if X_SENSORLESS case X_AXIS: if (index < 2) stepperX.homing_threshold(value); TERN_(X2_SENSORLESS, if (!index || index == 2) stepperX2.homing_threshold(value)); break; #endif #if Y_SENSORLESS case Y_AXIS: if (index < 2) stepperY.homing_threshold(value); TERN_(Y2_SENSORLESS, if (!index || index == 2) stepperY2.homing_threshold(value)); break; #endif #if Z_SENSORLESS case Z_AXIS: if (index < 2) stepperZ.homing_threshold(value); TERN_(Z2_SENSORLESS, if (!index || index == 2) stepperZ2.homing_threshold(value)); TERN_(Z3_SENSORLESS, if (!index || index == 3) stepperZ3.homing_threshold(value)); TERN_(Z4_SENSORLESS, if (!index || index == 4) stepperZ4.homing_threshold(value)); break; #endif #if I_SENSORLESS case I_AXIS: stepperI.homing_threshold(value); break; #endif #if J_SENSORLESS case J_AXIS: stepperJ.homing_threshold(value); break; #endif #if K_SENSORLESS case K_AXIS: stepperK.homing_threshold(value); break; #endif #if U_SENSORLESS && AXIS_HAS_STALLGUARD(U) case U_AXIS: stepperU.homing_threshold(value); break; #endif #if V_SENSORLESS && AXIS_HAS_STALLGUARD(V) case V_AXIS: stepperV.homing_threshold(value); break; #endif #if W_SENSORLESS && AXIS_HAS_STALLGUARD(W) case W_AXIS: stepperW.homing_threshold(value); break; #endif } } if (report) { TERN_(X_SENSORLESS, tmc_print_sgt(stepperX)); TERN_(X2_SENSORLESS, tmc_print_sgt(stepperX2)); TERN_(Y_SENSORLESS, tmc_print_sgt(stepperY)); TERN_(Y2_SENSORLESS, tmc_print_sgt(stepperY2)); TERN_(Z_SENSORLESS, tmc_print_sgt(stepperZ)); TERN_(Z2_SENSORLESS, tmc_print_sgt(stepperZ2)); TERN_(Z3_SENSORLESS, tmc_print_sgt(stepperZ3)); TERN_(Z4_SENSORLESS, tmc_print_sgt(stepperZ4)); TERN_(I_SENSORLESS, tmc_print_sgt(stepperI)); TERN_(J_SENSORLESS, tmc_print_sgt(stepperJ)); TERN_(K_SENSORLESS, tmc_print_sgt(stepperK)); TERN_(U_SENSORLESS, tmc_print_sgt(stepperU)); TERN_(V_SENSORLESS, tmc_print_sgt(stepperV)); TERN_(W_SENSORLESS, tmc_print_sgt(stepperW)); } } void GcodeSuite::M914_report(const bool forReplay/*=true*/) { TERN_(MARLIN_SMALL_BUILD, return); report_heading(forReplay, F(STR_STALLGUARD_THRESHOLD)); auto say_M914 = [](const bool forReplay) { report_echo_start(forReplay); SERIAL_ECHOPGM(" M914"); }; #if X_SENSORLESS || Y_SENSORLESS || Z_SENSORLESS say_M914(forReplay); #if X_SENSORLESS SERIAL_ECHOPGM_P(SP_X_STR, stepperX.homing_threshold()); #endif #if Y_SENSORLESS SERIAL_ECHOPGM_P(SP_Y_STR, stepperY.homing_threshold()); #endif #if Z_SENSORLESS SERIAL_ECHOPGM_P(SP_Z_STR, stepperZ.homing_threshold()); #endif SERIAL_EOL(); #endif #if X2_SENSORLESS || Y2_SENSORLESS || Z2_SENSORLESS say_M914(forReplay); SERIAL_ECHOPGM(" I2"); #if X2_SENSORLESS SERIAL_ECHOPGM_P(SP_X_STR, stepperX2.homing_threshold()); #endif #if Y2_SENSORLESS SERIAL_ECHOPGM_P(SP_Y_STR, stepperY2.homing_threshold()); #endif #if Z2_SENSORLESS SERIAL_ECHOPGM_P(SP_Z_STR, stepperZ2.homing_threshold()); #endif SERIAL_EOL(); #endif #if Z3_SENSORLESS say_M914(forReplay); SERIAL_ECHOLNPGM(" I3 Z", stepperZ3.homing_threshold()); #endif #if Z4_SENSORLESS say_M914(forReplay); SERIAL_ECHOLNPGM(" I4 Z", stepperZ4.homing_threshold()); #endif #if I_SENSORLESS say_M914(forReplay); SERIAL_ECHOLNPGM_P(SP_I_STR, stepperI.homing_threshold()); #endif #if J_SENSORLESS say_M914(forReplay); SERIAL_ECHOLNPGM_P(SP_J_STR, stepperJ.homing_threshold()); #endif #if K_SENSORLESS say_M914(forReplay); SERIAL_ECHOLNPGM_P(SP_K_STR, stepperK.homing_threshold()); #endif #if U_SENSORLESS say_M914(forReplay); SERIAL_ECHOLNPGM_P(SP_U_STR, stepperU.homing_threshold()); #endif #if V_SENSORLESS say_M914(forReplay); SERIAL_ECHOLNPGM_P(SP_V_STR, stepperV.homing_threshold()); #endif #if W_SENSORLESS say_M914(forReplay); SERIAL_ECHOLNPGM_P(SP_W_STR, stepperW.homing_threshold()); #endif } #endif // USE_SENSORLESS #endif // HAS_TRINAMIC_CONFIG
2301_81045437/Marlin
Marlin/src/gcode/feature/trinamic/M911-M914.cpp
C++
agpl-3.0
22,446
/** * Marlin 3D Printer Firmware * Copyright (c) 2021 MarlinFirmware [https://github.com/MarlinFirmware/Marlin] * * Based on Sprinter and grbl. * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <https://www.gnu.org/licenses/>. * */ #include "../../../inc/MarlinConfig.h" #if HAS_TRINAMIC_CONFIG #if AXIS_COLLISION('I') #error "M919 parameter 'I' collision with axis name." #endif #include "../../gcode.h" #include "../../../feature/tmc_util.h" #include "../../../module/stepper/indirection.h" #define DEBUG_OUT ENABLED(MARLIN_DEV_MODE) #include "../../../core/debug_out.h" template<typename TMC> static void tmc_print_chopper_time(TMC &st) { st.printLabel(); SERIAL_ECHOLNPGM(" chopper .toff: ", st.toff(), " .hend: ", st.hysteresis_end(), " .hstrt: ", st.hysteresis_start()); } /** * M919: Set TMC stepper driver chopper times * * Parameters: * XYZ...E - Selected axes * I[index] - Axis sub-index (Omit for all XYZ steppers, 1 for X2, Y2, Z2; 2 for Z3; 3 for Z4) * T[index] - Extruder index (Zero-based. Omit for all extruders.) * O - time-off [ 1..15] * P - hysteresis_end [-3..12] * S - hysteresis_start [ 1...8] * * With no parameters report chopper times for all axes */ void GcodeSuite::M919() { bool err = false; int8_t toff = int8_t(parser.intval('O', -127)); if (toff != -127) { if (WITHIN(toff, 1, 15)) DEBUG_ECHOLNPGM(".toff: ", toff); else { SERIAL_ECHOLNPGM(GCODE_ERR_MSG("O out of range (1..15)")); err = true; } } int8_t hend = int8_t(parser.intval('P', -127)); if (hend != -127) { if (WITHIN(hend, -3, 12)) DEBUG_ECHOLNPGM(".hend: ", hend); else { SERIAL_ECHOLNPGM(GCODE_ERR_MSG("P out of range (-3..12)")); err = true; } } int8_t hstrt = int8_t(parser.intval('S', -127)); if (hstrt != -127) { if (WITHIN(hstrt, 1, 8)) DEBUG_ECHOLNPGM(".hstrt: ", hstrt); else { SERIAL_ECHOLNPGM(GCODE_ERR_MSG("S out of range (1..8)")); err = true; } } if (err) return; #if AXIS_IS_TMC(X2) || AXIS_IS_TMC(Y2) || AXIS_IS_TMC(Z2) || AXIS_IS_TMC(Z3) || AXIS_IS_TMC(Z4) const int8_t index = parser.byteval('I'); #elif AXIS_IS_TMC(X) || AXIS_IS_TMC(Y) || AXIS_IS_TMC(Z) constexpr int8_t index = -1; #endif auto make_chopper_timing = [](chopper_timing_t bct, const int8_t toff, const int8_t hend, const int8_t hstrt) { chopper_timing_t uct = bct; if (toff != -127) uct.toff = toff; if (hend != -127) uct.hend = hend; if (hstrt != -127) uct.hstrt = hstrt; return uct; }; #define TMC_SET_CHOPPER_TIME(Q) stepper##Q.set_chopper_times(make_chopper_timing(CHOPPER_TIMING_##Q, toff, hend, hstrt)) #if AXIS_IS_TMC(E0) || AXIS_IS_TMC(E1) || AXIS_IS_TMC(E2) || AXIS_IS_TMC(E3) || AXIS_IS_TMC(E4) || AXIS_IS_TMC(E5) || AXIS_IS_TMC(E6) || AXIS_IS_TMC(E7) #define HAS_E_CHOPPER 1 int8_t eindex = -1; #endif bool report = true; LOOP_LOGICAL_AXES(i) if (parser.seen_test(AXIS_CHAR(i))) { report = false; // Get the chopper timing for the specified axis and index switch (i) { default: // A specified axis isn't Trinamic SERIAL_ECHOLNPGM(GCODE_ERR_MSG("Axis ", C(AXIS_CHAR(i)), " has no TMC drivers.")); break; #if AXIS_IS_TMC(X) || AXIS_IS_TMC(X2) case X_AXIS: #if AXIS_IS_TMC(X) if (index <= 0) TMC_SET_CHOPPER_TIME(X); #endif #if AXIS_IS_TMC(X2) if (index < 0 || index == 1) TMC_SET_CHOPPER_TIME(X2); #endif break; #endif #if AXIS_IS_TMC(Y) || AXIS_IS_TMC(Y2) case Y_AXIS: #if AXIS_IS_TMC(Y) if (index <= 0) TMC_SET_CHOPPER_TIME(Y); #endif #if AXIS_IS_TMC(Y2) if (index < 0 || index == 1) TMC_SET_CHOPPER_TIME(Y2); #endif break; #endif #if AXIS_IS_TMC(Z) || AXIS_IS_TMC(Z2) || AXIS_IS_TMC(Z3) || AXIS_IS_TMC(Z4) case Z_AXIS: #if AXIS_IS_TMC(Z) if (index <= 0) TMC_SET_CHOPPER_TIME(Z); #endif #if AXIS_IS_TMC(Z2) if (index < 0 || index == 1) TMC_SET_CHOPPER_TIME(Z2); #endif #if AXIS_IS_TMC(Z3) if (index < 0 || index == 2) TMC_SET_CHOPPER_TIME(Z3); #endif #if AXIS_IS_TMC(Z4) if (index < 0 || index == 3) TMC_SET_CHOPPER_TIME(Z4); #endif break; #endif #if AXIS_IS_TMC(I) case I_AXIS: TMC_SET_CHOPPER_TIME(I); break; #endif #if AXIS_IS_TMC(J) case J_AXIS: TMC_SET_CHOPPER_TIME(J); break; #endif #if AXIS_IS_TMC(K) case K_AXIS: TMC_SET_CHOPPER_TIME(K); break; #endif #if AXIS_IS_TMC(U) case U_AXIS: TMC_SET_CHOPPER_TIME(U); break; #endif #if AXIS_IS_TMC(V) case V_AXIS: TMC_SET_CHOPPER_TIME(V); break; #endif #if AXIS_IS_TMC(W) case W_AXIS: TMC_SET_CHOPPER_TIME(W); break; #endif #if HAS_E_CHOPPER case E_AXIS: { #if AXIS_IS_TMC(E0) if (eindex <= 0) TMC_SET_CHOPPER_TIME(E0); #endif #if AXIS_IS_TMC(E1) if (eindex < 0 || eindex == 1) TMC_SET_CHOPPER_TIME(E1); #endif #if AXIS_IS_TMC(E2) if (eindex < 0 || eindex == 2) TMC_SET_CHOPPER_TIME(E2); #endif #if AXIS_IS_TMC(E3) if (eindex < 0 || eindex == 3) TMC_SET_CHOPPER_TIME(E3); #endif #if AXIS_IS_TMC(E4) if (eindex < 0 || eindex == 4) TMC_SET_CHOPPER_TIME(E4); #endif #if AXIS_IS_TMC(E5) if (eindex < 0 || eindex == 5) TMC_SET_CHOPPER_TIME(E5); #endif #if AXIS_IS_TMC(E6) if (eindex < 0 || eindex == 6) TMC_SET_CHOPPER_TIME(E6); #endif #if AXIS_IS_TMC(E7) if (eindex < 0 || eindex == 7) TMC_SET_CHOPPER_TIME(E7); #endif } break; #endif } } if (report) { #define TMC_SAY_CHOPPER_TIME(Q) tmc_print_chopper_time(stepper##Q) #if AXIS_IS_TMC(X) TMC_SAY_CHOPPER_TIME(X); #endif #if AXIS_IS_TMC(X2) TMC_SAY_CHOPPER_TIME(X2); #endif #if AXIS_IS_TMC(Y) TMC_SAY_CHOPPER_TIME(Y); #endif #if AXIS_IS_TMC(Y2) TMC_SAY_CHOPPER_TIME(Y2); #endif #if AXIS_IS_TMC(Z) TMC_SAY_CHOPPER_TIME(Z); #endif #if AXIS_IS_TMC(Z2) TMC_SAY_CHOPPER_TIME(Z2); #endif #if AXIS_IS_TMC(Z3) TMC_SAY_CHOPPER_TIME(Z3); #endif #if AXIS_IS_TMC(Z4) TMC_SAY_CHOPPER_TIME(Z4); #endif #if AXIS_IS_TMC(I) TMC_SAY_CHOPPER_TIME(I); #endif #if AXIS_IS_TMC(J) TMC_SAY_CHOPPER_TIME(J); #endif #if AXIS_IS_TMC(K) TMC_SAY_CHOPPER_TIME(K); #endif #if AXIS_IS_TMC(U) TMC_SAY_CHOPPER_TIME(U); #endif #if AXIS_IS_TMC(V) TMC_SAY_CHOPPER_TIME(V); #endif #if AXIS_IS_TMC(W) TMC_SAY_CHOPPER_TIME(W); #endif #if AXIS_IS_TMC(E0) TMC_SAY_CHOPPER_TIME(E0); #endif #if AXIS_IS_TMC(E1) TMC_SAY_CHOPPER_TIME(E1); #endif #if AXIS_IS_TMC(E2) TMC_SAY_CHOPPER_TIME(E2); #endif #if AXIS_IS_TMC(E3) TMC_SAY_CHOPPER_TIME(E3); #endif #if AXIS_IS_TMC(E4) TMC_SAY_CHOPPER_TIME(E4); #endif #if AXIS_IS_TMC(E5) TMC_SAY_CHOPPER_TIME(E5); #endif #if AXIS_IS_TMC(E6) TMC_SAY_CHOPPER_TIME(E6); #endif #if AXIS_IS_TMC(E7) TMC_SAY_CHOPPER_TIME(E7); #endif } } #endif // HAS_TRINAMIC_CONFIG
2301_81045437/Marlin
Marlin/src/gcode/feature/trinamic/M919.cpp
C++
agpl-3.0
8,282
/** * Marlin 3D Printer Firmware * Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin] * * Based on Sprinter and grbl. * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <https://www.gnu.org/licenses/>. * */ /** * gcode.cpp - Temporary container for all G-code handlers * Most will migrate to classes, by feature. */ #include "gcode.h" GcodeSuite gcode; #if ENABLED(WIFI_CUSTOM_COMMAND) extern bool wifi_custom_command(char * const command_ptr); #endif #include "parser.h" #include "queue.h" #include "../module/motion.h" #if ENABLED(PRINTCOUNTER) #include "../module/printcounter.h" #endif #if ENABLED(HOST_ACTION_COMMANDS) #include "../feature/host_actions.h" #endif #if ENABLED(POWER_LOSS_RECOVERY) #include "../sd/cardreader.h" #include "../feature/powerloss.h" #endif #if ENABLED(CANCEL_OBJECTS) #include "../feature/cancel_object.h" #endif #if ENABLED(LASER_FEATURE) #include "../feature/spindle_laser.h" #endif #if ENABLED(FLOWMETER_SAFETY) #include "../feature/cooler.h" #endif #if ENABLED(PASSWORD_FEATURE) #include "../feature/password/password.h" #endif #if HAS_FANCHECK #include "../feature/fancheck.h" #endif #include "../MarlinCore.h" // for idle, kill // Inactivity shutdown millis_t GcodeSuite::previous_move_ms = 0, GcodeSuite::max_inactive_time = 0; #if HAS_DISABLE_IDLE_AXES millis_t GcodeSuite::stepper_inactive_time = SEC_TO_MS(DEFAULT_STEPPER_TIMEOUT_SEC); #endif // Relative motion mode for each logical axis relative_t GcodeSuite::axis_relative; // Init in constructor #if ANY(HAS_AUTO_REPORTING, HOST_KEEPALIVE_FEATURE) bool GcodeSuite::autoreport_paused; // = false #endif #if ENABLED(HOST_KEEPALIVE_FEATURE) GcodeSuite::MarlinBusyState GcodeSuite::busy_state = NOT_BUSY; uint8_t GcodeSuite::host_keepalive_interval = DEFAULT_KEEPALIVE_INTERVAL; #endif #if ENABLED(CNC_WORKSPACE_PLANES) GcodeSuite::WorkspacePlane GcodeSuite::workspace_plane = PLANE_XY; #endif #if ENABLED(CNC_COORDINATE_SYSTEMS) int8_t GcodeSuite::active_coordinate_system = -1; // machine space xyz_pos_t GcodeSuite::coordinate_system[MAX_COORDINATE_SYSTEMS]; #endif void GcodeSuite::report_echo_start(const bool forReplay) { if (!forReplay) SERIAL_ECHO_START(); } void GcodeSuite::report_heading(const bool forReplay, FSTR_P const fstr, const bool eol/*=true*/) { if (forReplay) return; if (fstr) { SERIAL_ECHO_START(); SERIAL_ECHO(F("; "), fstr); } if (eol) { SERIAL_CHAR(':'); SERIAL_EOL(); } } void GcodeSuite::say_units() { SERIAL_ECHOLNPGM_P( TERN_(INCH_MODE_SUPPORT, parser.linear_unit_factor != 1.0 ? PSTR(" (in)") :) PSTR(" (mm)") ); } /** * Get the target extruder from the T parameter or the active_extruder * Return -1 if the T parameter is out of range */ int8_t GcodeSuite::get_target_extruder_from_command() { #if HAS_TOOLCHANGE if (parser.seenval('T')) { const int8_t e = parser.value_byte(); if (e < EXTRUDERS) return e; SERIAL_ECHO_START(); SERIAL_CHAR('M'); SERIAL_ECHO(parser.codenum); SERIAL_ECHOLNPGM(" " STR_INVALID_EXTRUDER " ", e); return -1; } #endif return active_extruder; } /** * Get the target E stepper from the 'T' parameter. * If there is no 'T' parameter then dval will be substituted. * Returns -1 if the resulting E stepper index is out of range. */ int8_t GcodeSuite::get_target_e_stepper_from_command(const int8_t dval/*=-1*/) { const int8_t e = parser.intval('T', dval); if (WITHIN(e, 0, E_STEPPERS - 1)) return e; if (dval == -2) return dval; SERIAL_ECHO_START(); SERIAL_CHAR('M'); SERIAL_ECHO(parser.codenum); if (e == -1) SERIAL_ECHOLNPGM(" " STR_E_STEPPER_NOT_SPECIFIED); else SERIAL_ECHOLNPGM(" " STR_INVALID_E_STEPPER " ", e); return -1; } /** * Set XYZ...E destination and feedrate from the current G-Code command * * - Set destination from included axis codes * - Set to current for missing axis codes * - Set the feedrate, if included */ void GcodeSuite::get_destination_from_command() { xyze_bool_t seen{false}; #if ENABLED(CANCEL_OBJECTS) const bool &skip_move = cancelable.skipping; #else constexpr bool skip_move = false; #endif // Get new XYZ position, whether absolute or relative LOOP_NUM_AXES(i) { if ( (seen[i] = parser.seenval(AXIS_CHAR(i))) ) { const float v = parser.value_axis_units((AxisEnum)i); if (skip_move) destination[i] = current_position[i]; else destination[i] = axis_is_relative(AxisEnum(i)) ? current_position[i] + v : LOGICAL_TO_NATIVE(v, i); } else destination[i] = current_position[i]; } #if HAS_EXTRUDERS // Get new E position, whether absolute or relative if ( (seen.e = parser.seenval('E')) ) { const float v = parser.value_axis_units(E_AXIS); destination.e = axis_is_relative(E_AXIS) ? current_position.e + v : v; } else destination.e = current_position.e; #endif #if ENABLED(POWER_LOSS_RECOVERY) && !PIN_EXISTS(POWER_LOSS) // Only update power loss recovery on moves with E if (recovery.enabled && IS_SD_PRINTING() && seen.e && (seen.x || seen.y)) recovery.save(); #endif if (parser.floatval('F') > 0) { feedrate_mm_s = parser.value_feedrate(); // Update the cutter feed rate for use by M4 I set inline moves. TERN_(LASER_FEATURE, cutter.feedrate_mm_m = MMS_TO_MMM(feedrate_mm_s)); } #if ALL(PRINTCOUNTER, HAS_EXTRUDERS) if (!DEBUGGING(DRYRUN) && !skip_move) print_job_timer.incFilamentUsed(destination.e - current_position.e); #endif // Get ABCDHI mixing factors #if ALL(MIXING_EXTRUDER, DIRECT_MIXING_IN_G1) M165(); #endif #if ENABLED(LASER_FEATURE) if (cutter.cutter_mode == CUTTER_MODE_CONTINUOUS || cutter.cutter_mode == CUTTER_MODE_DYNAMIC) { // Set the cutter power in the planner to configure this move cutter.last_feedrate_mm_m = 0; if (WITHIN(parser.codenum, 1, TERN(ARC_SUPPORT, 3, 1)) || TERN0(BEZIER_CURVE_SUPPORT, parser.codenum == 5)) { planner.laser_inline.status.isPowered = true; if (parser.seen('I')) cutter.set_enabled(true); // This is set for backward LightBurn compatibility. if (parser.seenval('S')) { const float v = parser.value_float(), u = TERN(LASER_POWER_TRAP, v, cutter.power_to_range(v)); cutter.menuPower = cutter.unitPower = u; cutter.inline_power(TERN(SPINDLE_LASER_USE_PWM, cutter.upower_to_ocr(u), u > 0 ? 255 : 0)); } } else if (parser.codenum == 0) { // For dynamic mode we need to flag isPowered off, dynamic power is calculated in the stepper based on feedrate. if (cutter.cutter_mode == CUTTER_MODE_DYNAMIC) planner.laser_inline.status.isPowered = false; cutter.inline_power(0); // This is planner-based so only set power and do not disable inline control flags. } } else if (parser.codenum == 0) cutter.apply_power(0); #endif // LASER_FEATURE } /** * Dwell waits immediately. It does not synchronize. Use M400 instead of G4 */ void GcodeSuite::dwell(millis_t time) { time += millis(); while (PENDING(millis(), time)) idle(); } /** * When G29_RETRY_AND_RECOVER is enabled, call G29() in * a loop with recovery and retry handling. */ #if ENABLED(G29_RETRY_AND_RECOVER) void GcodeSuite::event_probe_recover() { TERN_(HOST_PROMPT_SUPPORT, hostui.prompt_do(PROMPT_INFO, F("G29 Retrying"), FPSTR(DISMISS_STR))); #ifdef ACTION_ON_G29_RECOVER hostui.g29_recover(); #endif #ifdef G29_RECOVER_COMMANDS process_subcommands_now(F(G29_RECOVER_COMMANDS)); #endif } #if ENABLED(G29_HALT_ON_FAILURE) #include "../lcd/marlinui.h" #endif void GcodeSuite::event_probe_failure() { #ifdef ACTION_ON_G29_FAILURE hostui.g29_failure(); #endif #ifdef G29_FAILURE_COMMANDS process_subcommands_now(F(G29_FAILURE_COMMANDS)); #endif #if ENABLED(G29_HALT_ON_FAILURE) #ifdef ACTION_ON_CANCEL hostui.cancel(); #endif kill(GET_TEXT_F(MSG_LCD_PROBING_FAILED)); #endif } #ifndef G29_MAX_RETRIES #define G29_MAX_RETRIES 0 #endif void GcodeSuite::G29_with_retry() { uint8_t retries = G29_MAX_RETRIES; while (G29()) { // G29 should return true for failed probes ONLY if (retries) { event_probe_recover(); --retries; } else { event_probe_failure(); return; } } TERN_(HOST_PROMPT_SUPPORT, hostui.prompt_end()); #ifdef G29_SUCCESS_COMMANDS process_subcommands_now(F(G29_SUCCESS_COMMANDS)); #endif } #endif // G29_RETRY_AND_RECOVER /** * Process the parsed command and dispatch it to its handler */ void GcodeSuite::process_parsed_command(const bool no_ok/*=false*/) { TERN_(HAS_FANCHECK, fan_check.check_deferred_error()); KEEPALIVE_STATE(IN_HANDLER); /** * Block all Gcodes except M511 Unlock Printer, if printer is locked * Will still block Gcodes if M511 is disabled, in which case the printer should be unlocked via LCD Menu */ #if ENABLED(PASSWORD_FEATURE) if (password.is_locked && !parser.is_command('M', 511)) { SERIAL_ECHO_MSG(STR_PRINTER_LOCKED); if (!no_ok) queue.ok_to_send(); return; } #endif #if ENABLED(FLOWMETER_SAFETY) if (cooler.flowfault) { SERIAL_ECHO_MSG(STR_FLOWMETER_FAULT); return; } #endif // Handle a known command or reply "unknown command" switch (parser.command_letter) { case 'G': switch (parser.codenum) { case 0: case 1: // G0: Fast Move, G1: Linear Move G0_G1(TERN_(HAS_FAST_MOVES, parser.codenum == 0)); break; #if ENABLED(ARC_SUPPORT) && DISABLED(SCARA) case 2: case 3: G2_G3(parser.codenum == 2); break; // G2: CW ARC, G3: CCW ARC #endif case 4: G4(); break; // G4: Dwell #if ENABLED(BEZIER_CURVE_SUPPORT) case 5: G5(); break; // G5: Cubic B_spline #endif #if ENABLED(DIRECT_STEPPING) case 6: G6(); break; // G6: Direct Stepper Move #endif #if ENABLED(FWRETRACT) case 10: G10(); break; // G10: Retract / Swap Retract case 11: G11(); break; // G11: Recover / Swap Recover #endif #if ENABLED(NOZZLE_CLEAN_FEATURE) case 12: G12(); break; // G12: Nozzle Clean #endif #if ENABLED(CNC_WORKSPACE_PLANES) case 17: G17(); break; // G17: Select Plane XY case 18: G18(); break; // G18: Select Plane ZX case 19: G19(); break; // G19: Select Plane YZ #endif #if ENABLED(INCH_MODE_SUPPORT) case 20: G20(); break; // G20: Inch Mode case 21: G21(); break; // G21: MM Mode #else case 21: NOOP; break; // No error on unknown G21 #endif #if ENABLED(G26_MESH_VALIDATION) case 26: G26(); break; // G26: Mesh Validation Pattern generation #endif #if ENABLED(NOZZLE_PARK_FEATURE) case 27: G27(); break; // G27: Nozzle Park #endif case 28: G28(); break; // G28: Home one or more axes #if HAS_LEVELING case 29: // G29: Bed leveling calibration TERN(G29_RETRY_AND_RECOVER, G29_with_retry, G29)(); break; #endif #if HAS_BED_PROBE case 30: G30(); break; // G30: Single Z probe #if ENABLED(Z_PROBE_SLED) case 31: G31(); break; // G31: dock the sled case 32: G32(); break; // G32: undock the sled #endif #endif #if ENABLED(DELTA_AUTO_CALIBRATION) case 33: G33(); break; // G33: Delta Auto-Calibration #endif #if ANY(Z_MULTI_ENDSTOPS, Z_STEPPER_AUTO_ALIGN, MECHANICAL_GANTRY_CALIBRATION) case 34: G34(); break; // G34: Z Stepper automatic alignment using probe #endif #if ENABLED(ASSISTED_TRAMMING) case 35: G35(); break; // G35: Read four bed corners to help adjust bed screws #endif #if ENABLED(G38_PROBE_TARGET) case 38: // G38.2, G38.3: Probe towards target if (WITHIN(parser.subcode, 2, TERN(G38_PROBE_AWAY, 5, 3))) G38(parser.subcode); // G38.4, G38.5: Probe away from target break; #endif #if HAS_MESH case 42: G42(); break; // G42: Coordinated move to a mesh point #endif #if ENABLED(CNC_COORDINATE_SYSTEMS) case 53: G53(); break; // G53: (prefix) Apply native workspace case 54: G54(); break; // G54: Switch to Workspace 1 case 55: G55(); break; // G55: Switch to Workspace 2 case 56: G56(); break; // G56: Switch to Workspace 3 case 57: G57(); break; // G57: Switch to Workspace 4 case 58: G58(); break; // G58: Switch to Workspace 5 case 59: G59(); break; // G59.0 - G59.3: Switch to Workspace 6-9 #endif #if SAVED_POSITIONS case 60: G60(); break; // G60: save current position case 61: G61(); break; // G61: Apply/restore saved coordinates. #endif #if ALL(PTC_PROBE, PTC_BED) case 76: G76(); break; // G76: Calibrate first layer compensation values #endif #if ENABLED(GCODE_MOTION_MODES) case 80: G80(); break; // G80: Reset the current motion mode #endif case 90: set_relative_mode(false); break; // G90: Absolute Mode case 91: set_relative_mode(true); break; // G91: Relative Mode case 92: G92(); break; // G92: Set current axis position(s) #if ENABLED(CALIBRATION_GCODE) case 425: G425(); break; // G425: Perform calibration with calibration cube #endif #if ENABLED(DEBUG_GCODE_PARSER) case 800: parser.debug(); break; // G800: G-Code Parser Test for G #endif default: parser.unknown_command_warning(); break; } break; case 'M': switch (parser.codenum) { #if HAS_RESUME_CONTINUE case 0: // M0: Unconditional stop - Wait for user button press on LCD case 1: M0_M1(); break; // M1: Conditional stop - Wait for user button press on LCD #endif #if HAS_CUTTER case 3: M3_M4(false); break; // M3: Turn ON Laser | Spindle (clockwise), set Power | Speed case 4: M3_M4(true ); break; // M4: Turn ON Laser | Spindle (counter-clockwise), set Power | Speed case 5: M5(); break; // M5: Turn OFF Laser | Spindle #endif #if ENABLED(COOLANT_MIST) case 7: M7(); break; // M7: Coolant Mist ON #endif #if ANY(AIR_ASSIST, COOLANT_FLOOD) case 8: M8(); break; // M8: Air Assist / Coolant Flood ON #endif #if ANY(AIR_ASSIST, COOLANT_CONTROL) case 9: M9(); break; // M9: Air Assist / Coolant OFF #endif #if ENABLED(AIR_EVACUATION) case 10: M10(); break; // M10: Vacuum or Blower motor ON case 11: M11(); break; // M11: Vacuum or Blower motor OFF #endif #if ENABLED(EXTERNAL_CLOSED_LOOP_CONTROLLER) case 12: M12(); break; // M12: Synchronize and optionally force a CLC set #endif #if ENABLED(EXPECTED_PRINTER_CHECK) case 16: M16(); break; // M16: Expected printer check #endif case 17: M17(); break; // M17: Enable all stepper motors #if HAS_MEDIA case 20: M20(); break; // M20: List SD card case 21: M21(); break; // M21: Init SD card case 22: M22(); break; // M22: Release SD card case 23: M23(); break; // M23: Select file case 24: M24(); break; // M24: Start SD print case 25: M25(); break; // M25: Pause SD print case 26: M26(); break; // M26: Set SD index case 27: M27(); break; // M27: Get SD status case 28: M28(); break; // M28: Start SD write case 29: M29(); break; // M29: Stop SD write case 30: M30(); break; // M30 <filename> Delete File #if HAS_MEDIA_SUBCALLS case 32: M32(); break; // M32: Select file and start SD print #endif #if ENABLED(LONG_FILENAME_HOST_SUPPORT) case 33: M33(); break; // M33: Get the long full path to a file or folder #endif #if ALL(SDCARD_SORT_ALPHA, SDSORT_GCODE) case 34: M34(); break; // M34: Set SD card sorting options #endif case 928: M928(); break; // M928: Start SD write #endif // HAS_MEDIA case 31: M31(); break; // M31: Report time since the start of SD print or last M109 #if ENABLED(DIRECT_PIN_CONTROL) case 42: M42(); break; // M42: Change pin state #endif #if ENABLED(PINS_DEBUGGING) case 43: M43(); break; // M43: Read pin state #endif #if ENABLED(Z_MIN_PROBE_REPEATABILITY_TEST) case 48: M48(); break; // M48: Z probe repeatability test #endif #if ENABLED(SET_PROGRESS_MANUALLY) case 73: M73(); break; // M73: Set progress percentage #endif case 75: M75(); break; // M75: Start print timer case 76: M76(); break; // M76: Pause print timer case 77: M77(); break; // M77: Stop print timer #if ENABLED(PRINTCOUNTER) case 78: M78(); break; // M78: Show print statistics #endif #if ENABLED(M100_FREE_MEMORY_WATCHER) case 100: M100(); break; // M100: Free Memory Report #endif #if ENABLED(BD_SENSOR) case 102: M102(); break; // M102: Configure Bed Distance Sensor #endif #if HAS_HOTEND case 104: M104(); break; // M104: Set hot end temperature case 109: M109(); break; // M109: Wait for hotend temperature to reach target #endif case 105: M105(); return; // M105: Report Temperatures (and say "ok") #if HAS_FAN case 106: M106(); break; // M106: Fan On case 107: M107(); break; // M107: Fan Off #endif case 110: M110(); break; // M110: Set Current Line Number case 111: M111(); break; // M111: Set debug level #if DISABLED(EMERGENCY_PARSER) case 108: M108(); break; // M108: Cancel Waiting case 112: M112(); break; // M112: Full Shutdown case 410: M410(); break; // M410: Quickstop - Abort all the planned moves. #if ENABLED(HOST_PROMPT_SUPPORT) case 876: M876(); break; // M876: Handle Host prompt responses #endif #else case 108: case 112: case 410: TERN_(HOST_PROMPT_SUPPORT, case 876:) break; #endif #if ENABLED(HOST_KEEPALIVE_FEATURE) case 113: M113(); break; // M113: Set Host Keepalive interval #endif #if HAS_FANCHECK case 123: M123(); break; // M123: Report fan states or set fans auto-report interval #endif #if HAS_HEATED_BED case 140: M140(); break; // M140: Set bed temperature case 190: M190(); break; // M190: Wait for bed temperature to reach target #endif #if HAS_HEATED_CHAMBER case 141: M141(); break; // M141: Set chamber temperature case 191: M191(); break; // M191: Wait for chamber temperature to reach target #endif #if HAS_TEMP_PROBE case 192: M192(); break; // M192: Wait for probe temp #endif #if HAS_COOLER case 143: M143(); break; // M143: Set cooler temperature case 193: M193(); break; // M193: Wait for cooler temperature to reach target #endif #if ENABLED(AUTO_REPORT_POSITION) case 154: M154(); break; // M154: Set position auto-report interval #endif #if ALL(AUTO_REPORT_TEMPERATURES, HAS_TEMP_SENSOR) case 155: M155(); break; // M155: Set temperature auto-report interval #endif #if ENABLED(PARK_HEAD_ON_PAUSE) case 125: M125(); break; // M125: Store current position and move to filament change position #endif #if ENABLED(BARICUDA) // PWM for HEATER_1_PIN #if HAS_HEATER_1 case 126: M126(); break; // M126: valve open case 127: M127(); break; // M127: valve closed #endif // PWM for HEATER_2_PIN #if HAS_HEATER_2 case 128: M128(); break; // M128: valve open case 129: M129(); break; // M129: valve closed #endif #endif // BARICUDA #if ENABLED(PSU_CONTROL) case 80: M80(); break; // M80: Turn on Power Supply #endif case 81: M81(); break; // M81: Turn off Power, including Power Supply, if possible #if HAS_EXTRUDERS case 82: M82(); break; // M82: Set E axis normal mode (same as other axes) case 83: M83(); break; // M83: Set E axis relative mode #endif case 18: case 84: M18_M84(); break; // M18/M84: Disable Steppers / Set Timeout case 85: M85(); break; // M85: Set inactivity stepper shutdown timeout #if ENABLED(HOTEND_IDLE_TIMEOUT) case 86: M86(); break; // M86: Set Hotend Idle Timeout case 87: M87(); break; // M87: Cancel Hotend Idle Timeout #endif #if ENABLED(EDITABLE_STEPS_PER_UNIT) case 92: M92(); break; // M92: Set the steps-per-unit for one or more axes #endif case 114: M114(); break; // M114: Report current position #if ENABLED(CAPABILITIES_REPORT) case 115: M115(); break; // M115: Report capabilities #endif case 117: TERN_(HAS_STATUS_MESSAGE, M117()); break; // M117: Set LCD message text, if possible case 118: M118(); break; // M118: Display a message in the host console case 119: M119(); break; // M119: Report endstop states case 120: M120(); break; // M120: Enable endstops case 121: M121(); break; // M121: Disable endstops #if HAS_PREHEAT case 145: M145(); break; // M145: Set material heatup parameters #endif #if ENABLED(TEMPERATURE_UNITS_SUPPORT) case 149: M149(); break; // M149: Set temperature units #endif #if HAS_COLOR_LEDS case 150: M150(); break; // M150: Set Status LED Color #endif #if ENABLED(MIXING_EXTRUDER) case 163: M163(); break; // M163: Set a component weight for mixing extruder case 164: M164(); break; // M164: Save current mix as a virtual extruder #if ENABLED(DIRECT_MIXING_IN_G1) case 165: M165(); break; // M165: Set multiple mix weights #endif #if ENABLED(GRADIENT_MIX) case 166: M166(); break; // M166: Set Gradient Mix #endif #endif #if DISABLED(NO_VOLUMETRICS) case 200: M200(); break; // M200: Set filament diameter, E to cubic units #endif case 201: M201(); break; // M201: Set max acceleration for print moves (units/s^2) #if 0 case 202: M202(); break; // M202: Not used for Sprinter/grbl gen6 #endif case 203: M203(); break; // M203: Set max feedrate (units/sec) case 204: M204(); break; // M204: Set acceleration case 205: M205(); break; // M205: Set advanced settings #if HAS_HOME_OFFSET case 206: M206(); break; // M206: Set home offsets #endif #if ENABLED(FWRETRACT) case 207: M207(); break; // M207: Set Retract Length, Feedrate, and Z lift case 208: M208(); break; // M208: Set Recover (unretract) Additional Length and Feedrate #if ENABLED(FWRETRACT_AUTORETRACT) case 209: if (MIN_AUTORETRACT <= MAX_AUTORETRACT) M209(); // M209: Turn Automatic Retract Detection on/off break; #endif #endif #if HAS_SOFTWARE_ENDSTOPS case 211: M211(); break; // M211: Enable, Disable, and/or Report software endstops #endif #if HAS_MULTI_EXTRUDER case 217: M217(); break; // M217: Set filament swap parameters #endif #if HAS_HOTEND_OFFSET case 218: M218(); break; // M218: Set a tool offset #endif case 220: M220(); break; // M220: Set Feedrate Percentage: S<percent> ("FR" on your LCD) #if HAS_EXTRUDERS case 221: M221(); break; // M221: Set Flow Percentage #endif #if ENABLED(DIRECT_PIN_CONTROL) case 226: M226(); break; // M226: Wait until a pin reaches a state #endif #if HAS_SERVOS case 280: M280(); break; // M280: Set servo position absolute #if ENABLED(EDITABLE_SERVO_ANGLES) case 281: M281(); break; // M281: Set servo angles #endif #if ENABLED(SERVO_DETACH_GCODE) case 282: M282(); break; // M282: Detach servo #endif #endif #if ENABLED(BABYSTEPPING) case 290: M290(); break; // M290: Babystepping #if ENABLED(EP_BABYSTEPPING) case 293: IF_DISABLED(EMERGENCY_PARSER, M293()); break; // M293: Babystep up case 294: IF_DISABLED(EMERGENCY_PARSER, M294()); break; // M294: Babystep down #endif #endif #if HAS_SOUND case 300: M300(); break; // M300: Play beep tone #endif #if ENABLED(PIDTEMP) case 301: M301(); break; // M301: Set hotend PID parameters #endif #if ENABLED(PIDTEMPBED) case 304: M304(); break; // M304: Set bed PID parameters #endif #if ENABLED(PIDTEMPCHAMBER) case 309: M309(); break; // M309: Set chamber PID parameters #endif #if ENABLED(PHOTO_GCODE) case 240: M240(); break; // M240: Trigger a camera #endif #if HAS_LCD_CONTRAST case 250: M250(); break; // M250: Set LCD contrast #endif #if ENABLED(EDITABLE_DISPLAY_TIMEOUT) case 255: M255(); break; // M255: Set LCD Sleep/Backlight Timeout (Minutes) #endif #if HAS_LCD_BRIGHTNESS case 256: M256(); break; // M256: Set LCD brightness #endif #if ENABLED(EXPERIMENTAL_I2CBUS) case 260: M260(); break; // M260: Send data to an i2c slave case 261: M261(); break; // M261: Request data from an i2c slave #endif #if ENABLED(PREVENT_COLD_EXTRUSION) case 302: M302(); break; // M302: Allow cold extrudes (set the minimum extrude temperature) #endif #if HAS_PID_HEATING case 303: M303(); break; // M303: PID autotune #endif #if HAS_USER_THERMISTORS case 305: M305(); break; // M305: Set user thermistor parameters #endif #if ENABLED(MPCTEMP) case 306: M306(); break; // M306: MPC autotune #endif #if ENABLED(REPETIER_GCODE_M360) case 360: M360(); break; // M360: Firmware settings #endif #if ENABLED(MORGAN_SCARA) case 360: if (M360()) return; break; // M360: SCARA Theta pos1 case 361: if (M361()) return; break; // M361: SCARA Theta pos2 case 362: if (M362()) return; break; // M362: SCARA Psi pos1 case 363: if (M363()) return; break; // M363: SCARA Psi pos2 case 364: if (M364()) return; break; // M364: SCARA Psi pos3 (90 deg to Theta) #endif #if ANY(EXT_SOLENOID, MANUAL_SOLENOID_CONTROL) case 380: M380(); break; // M380: Activate solenoid on active (or specified) extruder case 381: M381(); break; // M381: Disable all solenoids or, if MANUAL_SOLENOID_CONTROL, active (or specified) solenoid #endif case 400: M400(); break; // M400: Finish all moves #if HAS_BED_PROBE case 401: M401(); break; // M401: Deploy probe case 402: M402(); break; // M402: Stow probe #endif #if HAS_PRUSA_MMU2 case 403: M403(); break; #endif #if ENABLED(FILAMENT_WIDTH_SENSOR) case 404: M404(); break; // M404: Enter the nominal filament width (3mm, 1.75mm ) N<3.0> or display nominal filament width case 405: M405(); break; // M405: Turn on filament sensor for control case 406: M406(); break; // M406: Turn off filament sensor for control case 407: M407(); break; // M407: Display measured filament diameter #endif #if HAS_FILAMENT_SENSOR case 412: M412(); break; // M412: Enable/Disable filament runout detection #endif #if HAS_MULTI_LANGUAGE case 414: M414(); break; // M414: Select multi language menu #endif #if HAS_LEVELING case 420: M420(); break; // M420: Enable/Disable Bed Leveling #endif #if HAS_MESH case 421: M421(); break; // M421: Set a Mesh Bed Leveling Z coordinate #endif #if ENABLED(X_AXIS_TWIST_COMPENSATION) case 423: M423(); break; // M423: Reset, modify, or report X-Twist Compensation data #endif #if ENABLED(BACKLASH_GCODE) case 425: M425(); break; // M425: Tune backlash compensation #endif #if HAS_HOME_OFFSET case 428: M428(); break; // M428: Apply current_position to home_offset #endif #if HAS_POWER_MONITOR case 430: M430(); break; // M430: Read the system current (A), voltage (V), and power (W) #endif #if ENABLED(CANCEL_OBJECTS) case 486: M486(); break; // M486: Identify and cancel objects #endif #if ENABLED(FT_MOTION) case 493: M493(); break; // M493: Fixed-Time Motion control #endif case 500: M500(); break; // M500: Store settings in EEPROM case 501: M501(); break; // M501: Read settings from EEPROM case 502: M502(); break; // M502: Revert to default settings #if DISABLED(DISABLE_M503) case 503: M503(); break; // M503: print settings currently in memory #endif #if ENABLED(EEPROM_SETTINGS) case 504: M504(); break; // M504: Validate EEPROM contents #endif #if ENABLED(PASSWORD_FEATURE) case 510: M510(); break; // M510: Lock Printer #if ENABLED(PASSWORD_UNLOCK_GCODE) case 511: M511(); break; // M511: Unlock Printer #endif #if ENABLED(PASSWORD_CHANGE_GCODE) case 512: M512(); break; // M512: Set/Change/Remove Password #endif #endif #if HAS_MEDIA case 524: M524(); break; // M524: Abort the current SD print job #endif #if ENABLED(SD_ABORT_ON_ENDSTOP_HIT) case 540: M540(); break; // M540: Set abort on endstop hit for SD printing #endif #if HAS_ETHERNET case 552: M552(); break; // M552: Set IP address case 553: M553(); break; // M553: Set gateway case 554: M554(); break; // M554: Set netmask #endif #if ENABLED(BAUD_RATE_GCODE) case 575: M575(); break; // M575: Set serial baudrate #endif #if ENABLED(NONLINEAR_EXTRUSION) case 592: M592(); break; // M592: Nonlinear Extrusion control #endif #if HAS_ZV_SHAPING case 593: M593(); break; // M593: Input Shaping control #endif #if ENABLED(ADVANCED_PAUSE_FEATURE) case 600: M600(); break; // M600: Pause for Filament Change #if ENABLED(CONFIGURE_FILAMENT_CHANGE) case 603: M603(); break; // M603: Configure Filament Change #endif #endif #if HAS_DUPLICATION_MODE case 605: M605(); break; // M605: Set Dual X Carriage movement mode #endif #if IS_KINEMATIC case 665: M665(); break; // M665: Set Kinematics parameters #endif #if ANY(DELTA, HAS_EXTRA_ENDSTOPS) case 666: M666(); break; // M666: Set delta or multiple endstop adjustment #endif #if ENABLED(DUET_SMART_EFFECTOR) && PIN_EXISTS(SMART_EFFECTOR_MOD) case 672: M672(); break; // M672: Set/clear Duet Smart Effector sensitivity #endif #if ENABLED(FILAMENT_LOAD_UNLOAD_GCODES) case 701: M701(); break; // M701: Load Filament case 702: M702(); break; // M702: Unload Filament #endif #if ENABLED(CONTROLLER_FAN_EDITABLE) case 710: M710(); break; // M710: Set Controller Fan settings #endif #if ENABLED(GCODE_MACROS) case 810: case 811: case 812: case 813: case 814: case 815: case 816: case 817: case 818: case 819: M810_819(); break; // M810-M819: Define/execute G-code macro #endif #if HAS_BED_PROBE case 851: M851(); break; // M851: Set Z Probe Z Offset #endif #if ENABLED(SKEW_CORRECTION_GCODE) case 852: M852(); break; // M852: Set Skew factors #endif #if HAS_PTC case 871: M871(); break; // M871: Print/reset/clear first layer temperature offset values #endif #if ENABLED(LIN_ADVANCE) case 900: M900(); break; // M900: Set advance K factor. #endif #if ANY(HAS_MOTOR_CURRENT_SPI, HAS_MOTOR_CURRENT_PWM, HAS_MOTOR_CURRENT_I2C, HAS_MOTOR_CURRENT_DAC) case 907: M907(); break; // M907: Set digital trimpot motor current using axis codes. #if ANY(HAS_MOTOR_CURRENT_SPI, HAS_MOTOR_CURRENT_DAC) case 908: M908(); break; // M908: Control digital trimpot directly. #if HAS_MOTOR_CURRENT_DAC case 909: M909(); break; // M909: Print digipot/DAC current value case 910: M910(); break; // M910: Commit digipot/DAC value to external EEPROM #endif #endif #endif #if HAS_TRINAMIC_CONFIG case 122: M122(); break; // M122: Report driver configuration and status case 906: M906(); break; // M906: Set motor current in milliamps using axis codes X, Y, Z, E #if HAS_STEALTHCHOP case 569: M569(); break; // M569: Enable stealthChop on an axis. #endif #if ENABLED(MONITOR_DRIVER_STATUS) case 911: M911(); break; // M911: Report TMC2130 prewarn triggered flags case 912: M912(); break; // M912: Clear TMC2130 prewarn triggered flags #endif #if ENABLED(HYBRID_THRESHOLD) case 913: M913(); break; // M913: Set HYBRID_THRESHOLD speed. #endif #if USE_SENSORLESS case 914: M914(); break; // M914: Set StallGuard sensitivity. #endif case 919: M919(); break; // M919: Set stepper Chopper Times #endif #if HAS_MICROSTEPS case 350: M350(); break; // M350: Set microstepping mode. Warning: Steps per unit remains unchanged. S code sets stepping mode for all drivers. case 351: M351(); break; // M351: Toggle MS1 MS2 pins directly, S# determines MS1 or MS2, X# sets the pin high/low. #endif #if ENABLED(CASE_LIGHT_ENABLE) case 355: M355(); break; // M355: Set case light brightness #endif #if ENABLED(DEBUG_GCODE_PARSER) case 800: parser.debug(); break; // M800: G-Code Parser Test for M #endif #if ENABLED(GCODE_REPEAT_MARKERS) case 808: M808(); break; // M808: Set / Goto repeat markers #endif #if ENABLED(I2C_POSITION_ENCODERS) case 860: M860(); break; // M860: Report encoder module position case 861: M861(); break; // M861: Report encoder module status case 862: M862(); break; // M862: Perform axis test case 863: M863(); break; // M863: Calibrate steps/mm case 864: M864(); break; // M864: Change module address case 865: M865(); break; // M865: Check module firmware version case 866: M866(); break; // M866: Report axis error count case 867: M867(); break; // M867: Toggle error correction case 868: M868(); break; // M868: Set error correction threshold case 869: M869(); break; // M869: Report axis error #endif #if ENABLED(MAGNETIC_PARKING_EXTRUDER) case 951: M951(); break; // M951: Set Magnetic Parking Extruder parameters #endif #if ENABLED(Z_STEPPER_AUTO_ALIGN) case 422: M422(); break; // M422: Set Z Stepper automatic alignment position using probe #endif #if ENABLED(OTA_FIRMWARE_UPDATE) case 936: M936(); break; // M936: OTA update firmware. #endif #if SPI_FLASH_BACKUP case 993: M993(); break; // M993: Backup SPI Flash to SD case 994: M994(); break; // M994: Load a Backup from SD to SPI Flash #endif #if ENABLED(TOUCH_SCREEN_CALIBRATION) case 995: M995(); break; // M995: Touch screen calibration for TFT display #endif #if ENABLED(PLATFORM_M997_SUPPORT) case 997: M997(); break; // M997: Perform in-application firmware update #endif case 999: M999(); break; // M999: Restart after being Stopped #if ENABLED(POWER_LOSS_RECOVERY) case 413: M413(); break; // M413: Enable/disable/query Power-Loss Recovery case 1000: M1000(); break; // M1000: [INTERNAL] Resume from power-loss #endif #if HAS_MEDIA case 1001: M1001(); break; // M1001: [INTERNAL] Handle SD completion #endif #if DGUS_LCD_UI_MKS case 1002: M1002(); break; // M1002: [INTERNAL] Tool-change and Relative E Move #endif #if ENABLED(UBL_MESH_WIZARD) case 1004: M1004(); break; // M1004: UBL Mesh Wizard #endif #if ENABLED(MAX7219_GCODE) case 7219: M7219(); break; // M7219: Set LEDs, columns, and rows #endif #if ENABLED(HAS_MCP3426_ADC) case 3426: M3426(); break; // M3426: Read MCP3426 ADC (over i2c) #endif default: parser.unknown_command_warning(); break; } break; case 'T': T(parser.codenum); break; // Tn: Tool Change #if ENABLED(MARLIN_DEV_MODE) case 'D': D(parser.codenum); break; // Dn: Debug codes #endif #if ENABLED(REALTIME_REPORTING_COMMANDS) case 'S': case 'P': case 'R': break; // Invalid S, P, R commands already filtered #endif default: #if ENABLED(WIFI_CUSTOM_COMMAND) if (wifi_custom_command(parser.command_ptr)) break; #endif parser.unknown_command_warning(); } if (!no_ok) queue.ok_to_send(); SERIAL_IMPL.msgDone(); // Call the msgDone serial hook to signal command processing done } #if ENABLED(M100_FREE_MEMORY_DUMPER) void M100_dump_routine(FSTR_P const title, const char * const start, const uintptr_t size); #endif /** * Process a single command and dispatch it to its handler * This is called from the main loop() */ void GcodeSuite::process_next_command() { GCodeQueue::CommandLine &command = queue.ring_buffer.peek_next_command(); PORT_REDIRECT(SERIAL_PORTMASK(command.port)); TERN_(POWER_LOSS_RECOVERY, recovery.queue_index_r = queue.ring_buffer.index_r); if (DEBUGGING(ECHO)) { SERIAL_ECHO_START(); SERIAL_ECHOLN(command.buffer); #if ENABLED(M100_FREE_MEMORY_DUMPER) SERIAL_ECHOPGM("slot:", queue.ring_buffer.index_r); M100_dump_routine(F(" Command Queue:"), (const char*)&queue.ring_buffer, sizeof(queue.ring_buffer)); #endif } // Parse the next command in the queue parser.parse(command.buffer); process_parsed_command(); } #pragma GCC diagnostic push #if GCC_VERSION >= 80000 #pragma GCC diagnostic ignored "-Wstringop-truncation" #endif /** * Run a series of commands, bypassing the command queue to allow * G-code "macros" to be called from within other G-code handlers. */ void GcodeSuite::process_subcommands_now(FSTR_P fgcode) { PGM_P pgcode = FTOP(fgcode); char * const saved_cmd = parser.command_ptr; // Save the parser state for (;;) { PGM_P const delim = strchr_P(pgcode, '\n'); // Get address of next newline const size_t len = delim ? delim - pgcode : strlen_P(pgcode); // Get the command length parser.parse(MString<MAX_CMD_SIZE>().setn_P(pgcode, len)); // Parse the command process_parsed_command(true); // Process it (no "ok") if (!delim) break; // Last command? pgcode = delim + 1; // Get the next command } parser.parse(saved_cmd); // Restore the parser state } #pragma GCC diagnostic pop void GcodeSuite::process_subcommands_now(char * gcode) { char * const saved_cmd = parser.command_ptr; // Save the parser state for (;;) { char * const delim = strchr(gcode, '\n'); // Get address of next newline if (delim) *delim = '\0'; // Replace with nul parser.parse(gcode); // Parse the current command process_parsed_command(true); // Process it (no "ok") if (!delim) break; // Last command? *delim = '\n'; // Put back the newline gcode = delim + 1; // Get the next command } parser.parse(saved_cmd); // Restore the parser state } #if ENABLED(HOST_KEEPALIVE_FEATURE) /** * Output a "busy" message at regular intervals * while the machine is not accepting commands. */ void GcodeSuite::host_keepalive() { const millis_t ms = millis(); static millis_t next_busy_signal_ms = 0; if (!autoreport_paused && host_keepalive_interval && busy_state != NOT_BUSY) { if (PENDING(ms, next_busy_signal_ms)) return; PORT_REDIRECT(SerialMask::All); switch (busy_state) { case IN_HANDLER: case IN_PROCESS: SERIAL_ECHO_MSG(STR_BUSY_PROCESSING); TERN_(FULL_REPORT_TO_HOST_FEATURE, report_current_position_moving()); break; case PAUSED_FOR_USER: SERIAL_ECHO_MSG(STR_BUSY_PAUSED_FOR_USER); TERN_(FULL_REPORT_TO_HOST_FEATURE, set_and_report_grblstate(M_HOLD)); break; case PAUSED_FOR_INPUT: SERIAL_ECHO_MSG(STR_BUSY_PAUSED_FOR_INPUT); TERN_(FULL_REPORT_TO_HOST_FEATURE, set_and_report_grblstate(M_HOLD)); break; default: break; } } next_busy_signal_ms = ms + SEC_TO_MS(host_keepalive_interval); } #endif // HOST_KEEPALIVE_FEATURE
2301_81045437/Marlin
Marlin/src/gcode/gcode.cpp
C++
agpl-3.0
50,951
/** * Marlin 3D Printer Firmware * Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin] * * Based on Sprinter and grbl. * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <https://www.gnu.org/licenses/>. * */ #pragma once /** * ----------------- * G-Codes in Marlin * ----------------- * * Helpful G-code references: * - https://marlinfw.org/meta/gcode * - https://reprap.org/wiki/G-code * - https://linuxcnc.org/docs/html/gcode.html * * Help to document Marlin's G-codes online: * - https://github.com/MarlinFirmware/MarlinDocumentation * * ----------------- * * "G" Codes * * G0 -> G1 * G1 - Coordinated Movement X Y Z E * G2 - CW ARC * G3 - CCW ARC * G4 - Dwell S<seconds> or P<milliseconds> * G5 - Cubic B-spline with XYZE destination and IJPQ offsets * G10 - Retract filament according to settings of M207 (Requires FWRETRACT) * G11 - Retract recover filament according to settings of M208 (Requires FWRETRACT) * G12 - Clean tool (Requires NOZZLE_CLEAN_FEATURE) * G17 - Select Plane XY (Requires CNC_WORKSPACE_PLANES) * G18 - Select Plane ZX (Requires CNC_WORKSPACE_PLANES) * G19 - Select Plane YZ (Requires CNC_WORKSPACE_PLANES) * G20 - Set input units to inches (Requires INCH_MODE_SUPPORT) * G21 - Set input units to millimeters (Requires INCH_MODE_SUPPORT) * G26 - Mesh Validation Pattern (Requires G26_MESH_VALIDATION) * G27 - Park Nozzle (Requires NOZZLE_PARK_FEATURE) * G28 - Home one or more axes * G29 - Start or continue the bed leveling probe procedure (Requires bed leveling) * G30 - Single Z probe, probes bed at X Y location (defaults to current XY location) * G31 - Dock sled (Z_PROBE_SLED only) * G32 - Undock sled (Z_PROBE_SLED only) * G33 - Delta Auto-Calibration (Requires DELTA_AUTO_CALIBRATION) * G34 - Z Stepper automatic alignment using probe: I<iterations> T<accuracy> A<amplification> (Requires Z_STEPPER_AUTO_ALIGN) * G35 - Read bed corners to help adjust bed screws: T<screw_thread> (Requires ASSISTED_TRAMMING) * G38 - Probe in any direction using the Z_MIN_PROBE (Requires G38_PROBE_TARGET) * G42 - Coordinated move to a mesh point (Requires MESH_BED_LEVELING, AUTO_BED_LEVELING_BLINEAR, or AUTO_BED_LEVELING_UBL) * G60 - Save current position. (Requires SAVED_POSITIONS) * G61 - Apply/restore saved coordinates. (Requires SAVED_POSITIONS) * G76 - Calibrate first layer temperature offsets. (Requires PTC_PROBE and PTC_BED) * G80 - Cancel current motion mode (Requires GCODE_MOTION_MODES) * G90 - Use Absolute Coordinates * G91 - Use Relative Coordinates * G92 - Set current position to coordinates given * * "M" Codes * * M0 - Unconditional stop - Wait for user to press a button on the LCD (Only if ULTRA_LCD is enabled) * M1 -> M0 * M3 - Turn ON Laser | Spindle (clockwise), set Power | Speed. (Requires SPINDLE_FEATURE or LASER_FEATURE) * M4 - Turn ON Laser | Spindle (counter-clockwise), set Power | Speed. (Requires SPINDLE_FEATURE or LASER_FEATURE) * M5 - Turn OFF Laser | Spindle. (Requires SPINDLE_FEATURE or LASER_FEATURE) * M7 - Turn mist coolant ON. (Requires COOLANT_CONTROL) * M8 - Turn flood coolant ON. (Requires COOLANT_CONTROL) * M9 - Turn coolant OFF. (Requires COOLANT_CONTROL) * M10 - Turn Vacuum or Blower motor ON (Requires AIR_EVACUATION) * M11 - Turn Vacuum or Blower motor OFF (Requires AIR_EVACUATION) * M12 - Set up closed loop control system. (Requires EXTERNAL_CLOSED_LOOP_CONTROLLER) * M16 - Expected printer check. (Requires EXPECTED_PRINTER_CHECK) * M17 - Enable/Power all stepper motors * M18 - Disable all stepper motors; same as M84 * *** Print from Media (SDSUPPORT) *** * M20 - List SD card. (Requires SDSUPPORT) * M21 - Init SD card. (Requires SDSUPPORT) With MULTI_VOLUME select a drive with `M21 Pn` / 'M21 S' / 'M21 U'. * M22 - Release SD card. (Requires SDSUPPORT) * M23 - Select SD file: "M23 /path/file.gco". (Requires SDSUPPORT) * M24 - Start/resume SD print. (Requires SDSUPPORT) * M25 - Pause SD print. (Requires SDSUPPORT) * M26 - Set SD position in bytes: "M26 S12345". (Requires SDSUPPORT) * M27 - Report SD print status. (Requires SDSUPPORT) * OR, with 'S<seconds>' set the SD status auto-report interval. (Requires AUTO_REPORT_SD_STATUS) * OR, with 'C' get the current filename. * M28 - Start SD write: "M28 /path/file.gco". (Requires SDSUPPORT) * M29 - Stop SD write. (Requires SDSUPPORT) * M30 - Delete file from SD: "M30 /path/file.gco" (Requires SDSUPPORT) * M31 - Report time since last M109 or SD card start to serial. * M32 - Select file and start SD print: "M32 [S<bytepos>] !/path/file.gco#". (Requires SDSUPPORT) * Use P to run other files as sub-programs: "M32 P !filename#" * The '#' is necessary when calling from within sd files, as it stops buffer prereading * M33 - Get the longname version of a path. (Requires LONG_FILENAME_HOST_SUPPORT) * M34 - Set SD Card sorting options. (Requires SDCARD_SORT_ALPHA) * * M42 - Change pin status via G-code: M42 P<pin> S<value>. LED pin assumed if P is omitted. (Requires DIRECT_PIN_CONTROL) * M43 - Display pin status, watch pins for changes, watch endstops & toggle LED, Z servo probe test, toggle pins (Requires PINS_DEBUGGING) * M48 - Measure Z Probe repeatability: M48 P<points> X<pos> Y<pos> V<level> E<engage> L<legs> S<chizoid>. (Requires Z_MIN_PROBE_REPEATABILITY_TEST) * * M73 - Set the progress percentage. (Requires SET_PROGRESS_MANUALLY) * M75 - Start the print job timer. * M76 - Pause the print job timer. * M77 - Stop the print job timer. * M78 - Show statistical information about the print jobs. (Requires PRINTCOUNTER) * * M80 - Turn on Power Supply. (Requires PSU_CONTROL) * M81 - Turn off Power Supply. (Requires PSU_CONTROL) * * M82 - Set E codes absolute (default). * M83 - Set E codes relative while in Absolute (G90) mode. * M84 - Disable steppers until next move, or use S<seconds> to specify an idle * duration after which steppers should turn off. S0 disables the timeout. * M85 - Set inactivity shutdown timer with parameter S<seconds>. To disable set zero (default) * M92 - Set planner.settings.axis_steps_per_mm for one or more axes. (Requires EDITABLE_STEPS_PER_UNIT) * * M100 - Watch Free Memory (for debugging) (Requires M100_FREE_MEMORY_WATCHER) * * M102 - Configure Bed Distance Sensor. (Requires BD_SENSOR) * * M104 - Set extruder target temp. * M105 - Report current temperatures. * M106 - Set print fan speed. * M107 - Print fan off. * M108 - Break out of heating loops (M109, M190, M303). With no controller, breaks out of M0/M1. (Requires EMERGENCY_PARSER) * M109 - S<temp> Wait for extruder current temp to reach target temp. ** Wait only when heating! ** * R<temp> Wait for extruder current temp to reach target temp. ** Wait for heating or cooling. ** * If AUTOTEMP is enabled, S<mintemp> B<maxtemp> F<factor>. Exit autotemp by any M109 without F * * M110 - Set the current line number. (Used by host printing) * M111 - Set debug flags: "M111 S<flagbits>". See flag bits defined in enum.h. * M112 - Full Shutdown. * * M113 - Get or set the timeout interval for Host Keepalive "busy" messages. (Requires HOST_KEEPALIVE_FEATURE) * M114 - Report current position. * M115 - Report capabilities. (Requires CAPABILITIES_REPORT) * M117 - Display a message on the controller screen. (Requires an LCD) * M118 - Display a message in the host console. * * M119 - Report endstops status. * M120 - Enable endstops detection. * M121 - Disable endstops detection. * * M122 - Debug stepper (Requires at least one _DRIVER_TYPE defined as TMC2130/2160/5130/5160/2208/2209/2660) * M123 - Report fan tachometers. (Requires En_FAN_TACHO_PIN) Optionally set auto-report interval. (Requires AUTO_REPORT_FANS) * M125 - Save current position and move to filament change position. (Requires PARK_HEAD_ON_PAUSE) * * M126 - Solenoid Air Valve Open. (Requires BARICUDA) * M127 - Solenoid Air Valve Closed. (Requires BARICUDA) * M128 - EtoP Open. (Requires BARICUDA) * M129 - EtoP Closed. (Requires BARICUDA) * * M140 - Set bed target temp. S<temp> * M141 - Set heated chamber target temp. S<temp> (Requires a chamber heater) * M143 - Set cooler target temp. S<temp> (Requires a laser cooling device) * M145 - Set heatup values for materials on the LCD. H<hotend> B<bed> F<fan speed> for S<material> (0=PLA, 1=ABS) * M149 - Set temperature units. (Requires TEMPERATURE_UNITS_SUPPORT) * M150 - Set Status LED Color as R<red> U<green> B<blue> W<white> P<bright>. Values 0-255. (Requires BLINKM, RGB_LED, RGBW_LED, NEOPIXEL_LED, PCA9533, or PCA9632). * M154 - Auto-report position with interval of S<seconds>. (Requires AUTO_REPORT_POSITION) * M155 - Auto-report temperatures with interval of S<seconds>. (Requires AUTO_REPORT_TEMPERATURES) * M163 - Set a single proportion for a mixing extruder. (Requires MIXING_EXTRUDER) * M164 - Commit the mix and save to a virtual tool (current, or as specified by 'S'). (Requires MIXING_EXTRUDER) * M165 - Set the mix for the mixing extruder (and current virtual tool) with parameters ABCDHI. (Requires MIXING_EXTRUDER and DIRECT_MIXING_IN_G1) * M166 - Set the Gradient Mix for the mixing extruder. (Requires GRADIENT_MIX) * M190 - Set bed target temperature and wait. R<temp> Set target temperature and wait. S<temp> Set, but only wait when heating. (Requires TEMP_SENSOR_BED) * M192 - Wait for probe to reach target temperature. (Requires TEMP_SENSOR_PROBE) * M193 - R<temp> Wait for cooler to reach target temp. ** Wait for cooling. ** * M200 - Set filament diameter, D<diameter>, setting E axis units to cubic. (Use S0 to revert to linear units.) * M201 - Set max acceleration in units/s^2 for print moves: "M201 X<accel> Y<accel> Z<accel> E<accel>" * M202 - Set max acceleration in units/s^2 for travel moves: "M202 X<accel> Y<accel> Z<accel> E<accel>" ** UNUSED IN MARLIN! ** * M203 - Set maximum feedrate: "M203 X<fr> Y<fr> Z<fr> E<fr>" in units/sec. * M204 - Set default acceleration in units/sec^2: P<printing> R<extruder_only> T<travel> * M205 - Set advanced settings. Current units apply: S<print> T<travel> minimum speeds B<minimum segment time> X<max X jerk>, Y<max Y jerk>, Z<max Z jerk>, E<max E jerk> * M206 - Set additional homing offset. (Disabled by NO_WORKSPACE_OFFSETS or DELTA) * M207 - Set Retract Length: S<length>, Feedrate: F<units/min>, and Z lift: Z<distance>. (Requires FWRETRACT) * M208 - Set Recover (unretract) Additional (!) Length: S<length> and Feedrate: F<units/min>. (Requires FWRETRACT) * M209 - Turn Automatic Retract Detection on/off: S<0|1> (For slicers that don't support G10/11). (Requires FWRETRACT_AUTORETRACT) Every normal extrude-only move will be classified as retract depending on the direction. * M211 - Enable, Disable, and/or Report software endstops: S<0|1> (Requires MIN_SOFTWARE_ENDSTOPS or MAX_SOFTWARE_ENDSTOPS) * M217 - Set filament swap parameters: "M217 S<length> P<feedrate> R<feedrate>". (Requires SINGLENOZZLE) * M218 - Set/get a tool offset: "M218 T<index> X<offset> Y<offset>". (Requires 2 or more extruders) * M220 - Set Feedrate Percentage: "M220 S<percent>" (i.e., "FR" on the LCD) * Use "M220 B" to back up the Feedrate Percentage and "M220 R" to restore it. (Requires an MMU_MODEL version 2 or 2S) * M221 - Set Flow Percentage: "M221 S<percent>" (Requires an extruder) * M226 - Wait until a pin is in a given state: "M226 P<pin> S<state>" (Requires DIRECT_PIN_CONTROL) * M240 - Trigger a camera to take a photograph. (Requires PHOTO_GCODE) * M250 - Set LCD contrast: "M250 C<contrast>" (0-63). (Requires LCD support) * M255 - Set LCD sleep time: "M255 S<minutes>" (0-99). (Requires an LCD with brightness or sleep/wake) * M256 - Set LCD brightness: "M256 B<brightness>" (0-255). (Requires an LCD with brightness control) * M260 - i2c Send Data (Requires EXPERIMENTAL_I2CBUS) * M261 - i2c Request Data (Requires EXPERIMENTAL_I2CBUS) * M280 - Set servo position absolute: "M280 P<index> S<angle|µs>". (Requires servos) * M281 - Set servo min|max position: "M281 P<index> L<min> U<max>". (Requires EDITABLE_SERVO_ANGLES) * M282 - Detach servo: "M282 P<index>". (Requires SERVO_DETACH_GCODE) * M290 - Babystepping (Requires BABYSTEPPING) * M300 - Play beep sound S<frequency Hz> P<duration ms> * M301 - Set PID parameters P I and D. (Requires PIDTEMP) * M302 - Allow cold extrudes, or set the minimum extrude S<temperature>. (Requires PREVENT_COLD_EXTRUSION) * M303 - PID relay autotune S<temperature> sets the target temperature. Default 150C. (Requires PIDTEMP) * M304 - Set bed PID parameters P I and D. (Requires PIDTEMPBED) * M305 - Set user thermistor parameters R T and P. (Requires TEMP_SENSOR_x 1000) * M306 - MPC autotune. (Requires MPCTEMP) * M309 - Set chamber PID parameters P I and D. (Requires PIDTEMPCHAMBER) * M350 - Set microstepping mode. (Requires digital microstepping pins.) * M351 - Toggle MS1 MS2 pins directly. (Requires digital microstepping pins.) * M355 - Set Case Light on/off and set brightness. (Requires CASE_LIGHT_PIN) * M380 - Activate solenoid on active tool (Requires EXT_SOLENOID) or the tool specified by 'S' (Requires MANUAL_SOLENOID_CONTROL). * M381 - Disable solenoids on all tools (Requires EXT_SOLENOID) or the tool specified by 'S' (Requires MANUAL_SOLENOID_CONTROL). * M400 - Finish all moves. * M401 - Deploy and activate Z probe. (Requires a probe) * M402 - Deactivate and stow Z probe. (Requires a probe) * M403 - Set filament type for PRUSA MMU2 * M404 - Display or set the Nominal Filament Width: "W<diameter>". (Requires FILAMENT_WIDTH_SENSOR) * M405 - Enable Filament Sensor flow control. "M405 D<delay_cm>". (Requires FILAMENT_WIDTH_SENSOR) * M406 - Disable Filament Sensor flow control. (Requires FILAMENT_WIDTH_SENSOR) * M407 - Display measured filament diameter in millimeters. (Requires FILAMENT_WIDTH_SENSOR) * M410 - Quickstop. Abort all planned moves. * M412 - Enable / Disable Filament Runout Detection. (Requires FILAMENT_RUNOUT_SENSOR) * M413 - Enable / Disable Power-Loss Recovery. (Requires POWER_LOSS_RECOVERY) * M414 - Set language by index. (Requires LCD_LANGUAGE_2...) * M420 - Enable/Disable Leveling (with current values) S1=enable S0=disable (Requires MESH_BED_LEVELING or ABL) * M421 - Set a single Z coordinate in the Mesh Leveling grid. X<units> Y<units> Z<units> (Requires MESH_BED_LEVELING, AUTO_BED_LEVELING_BILINEAR, or AUTO_BED_LEVELING_UBL) * M422 - Set Z Stepper automatic alignment position using probe. X<units> Y<units> A<axis> (Requires Z_STEPPER_AUTO_ALIGN) * M425 - Enable/Disable and tune backlash correction. (Requires BACKLASH_COMPENSATION and BACKLASH_GCODE) * M428 - Set the home_offset based on the current_position. Nearest edge applies. (Disabled by NO_WORKSPACE_OFFSETS or DELTA) * M430 - Read the system current, voltage, and power (Requires POWER_MONITOR_CURRENT, POWER_MONITOR_VOLTAGE, or POWER_MONITOR_FIXED_VOLTAGE) * M486 - Identify and cancel objects. (Requires CANCEL_OBJECTS) * M500 - Store parameters in EEPROM. (Requires EEPROM_SETTINGS) * M501 - Restore parameters from EEPROM. (Requires EEPROM_SETTINGS) * M502 - Revert to the default "factory settings". ** Does not write them to EEPROM! ** * M503 - Print the current settings (in memory): "M503 S<verbose>". S0 specifies compact output. * M504 - Validate EEPROM contents. (Requires EEPROM_SETTINGS) * M510 - Lock Printer (Requires PASSWORD_FEATURE) * M511 - Unlock Printer (Requires PASSWORD_UNLOCK_GCODE) * M512 - Set/Change/Remove Password (Requires PASSWORD_CHANGE_GCODE) * M524 - Abort the current SD print job started with M24. (Requires SDSUPPORT) * M540 - Enable/disable SD card abort on endstop hit: "M540 S<state>". (Requires SD_ABORT_ON_ENDSTOP_HIT) * M552 - Get or set IP address. Enable/disable network interface. (Requires enabled Ethernet port) * M553 - Get or set IP netmask. (Requires enabled Ethernet port) * M554 - Get or set IP gateway. (Requires enabled Ethernet port) * M569 - Enable stealthChop on an axis. (Requires at least one _DRIVER_TYPE to be TMC2130/2160/2208/2209/5130/5160) * M575 - Change the serial baud rate. (Requires BAUD_RATE_GCODE) * M592 - Get or set nonlinear extrusion parameters. (Requires NONLINEAR_EXTRUSION) * M593 - Get or set input shaping parameters. (Requires INPUT_SHAPING_[XY]) * M600 - Pause for filament change: "M600 X<pos> Y<pos> Z<raise> E<first_retract> L<later_retract>". (Requires ADVANCED_PAUSE_FEATURE) * M603 - Configure filament change: "M603 T<tool> U<unload_length> L<load_length>". (Requires ADVANCED_PAUSE_FEATURE) * M605 - Set Dual X-Carriage movement mode: "M605 S<mode> [X<x_offset>] [R<temp_offset>]". (Requires DUAL_X_CARRIAGE) * M665 - Set delta configurations: "M665 H<delta height> L<diagonal rod> R<delta radius> S<segments/s> B<calibration radius> X<Alpha angle trim> Y<Beta angle trim> Z<Gamma angle trim> (Requires DELTA) * Set SCARA configurations: "M665 S<segments-per-second> P<theta-psi-offset> T<theta-offset> Z<z-offset> (Requires MORGAN_SCARA or MP_SCARA) * Set Polargraph draw area and belt length: "M665 S<segments-per-second> L<draw-area-left> R<draw-area-right> T<draw-area-top> B<draw-area-bottom> H<max-belt-length>" * M666 - Set/get offsets for delta (Requires DELTA) or dual endstops. (Requires [XYZ]_DUAL_ENDSTOPS) * M672 - Set/Reset Duet Smart Effector's sensitivity. (Requires DUET_SMART_EFFECTOR and SMART_EFFECTOR_MOD_PIN) * M701 - Load filament (Requires FILAMENT_LOAD_UNLOAD_GCODES) * M702 - Unload filament (Requires FILAMENT_LOAD_UNLOAD_GCODES) * M808 - Set or Goto a Repeat Marker (Requires GCODE_REPEAT_MARKERS) * M810-M819 - Define/execute a G-code macro (Requires GCODE_MACROS) * M851 - Set Z probe's XYZ offsets in current units. (Negative values: X=left, Y=front, Z=below) * M852 - Set skew factors: "M852 [I<xy>] [J<xz>] [K<yz>]". (Requires SKEW_CORRECTION_GCODE, plus SKEW_CORRECTION_FOR_Z for IJ) * *** I2C_POSITION_ENCODERS *** * M860 - Report the position of position encoder modules. * M861 - Report the status of position encoder modules. * M862 - Perform an axis continuity test for position encoder modules. * M863 - Perform steps-per-mm calibration for position encoder modules. * M864 - Change position encoder module I2C address. * M865 - Check position encoder module firmware version. * M866 - Report or reset position encoder module error count. * M867 - Enable/disable or toggle error correction for position encoder modules. * M868 - Report or set position encoder module error correction threshold. * M869 - Report position encoder module error. * * M871 - Print/reset/clear first layer temperature offset values. (Requires PTC_PROBE, PTC_BED, or PTC_HOTEND) * M876 - Handle Prompt Response. (Requires HOST_PROMPT_SUPPORT and not EMERGENCY_PARSER) * M900 - Get or Set Linear Advance K-factor. (Requires LIN_ADVANCE) * M906 - Set or get motor current in milliamps using axis codes XYZE, etc. Report values if no axis codes given. (Requires at least one _DRIVER_TYPE defined as TMC2130/2160/5130/5160/2208/2209/2660) * M907 - Set digital trimpot motor current using axis codes. (Requires a board with digital trimpots) * M908 - Control digital trimpot directly. (Requires HAS_MOTOR_CURRENT_DAC or DIGIPOTSS_PIN) * M909 - Print digipot/DAC current value. (Requires HAS_MOTOR_CURRENT_DAC) * M910 - Commit digipot/DAC value to external EEPROM via I2C. (Requires HAS_MOTOR_CURRENT_DAC) * M911 - Report stepper driver overtemperature pre-warn condition. (Requires at least one _DRIVER_TYPE defined as TMC2130/2160/5130/5160/2208/2209/2660) * M912 - Clear stepper driver overtemperature pre-warn condition flag. (Requires at least one _DRIVER_TYPE defined as TMC2130/2160/5130/5160/2208/2209/2660) * M913 - Set HYBRID_THRESHOLD speed. (Requires HYBRID_THRESHOLD) * M914 - Set StallGuard sensitivity. (Requires SENSORLESS_HOMING or SENSORLESS_PROBING) * M919 - Get or Set motor Chopper Times (time_off, hysteresis_end, hysteresis_start) using axis codes XYZE, etc. If no parameters are given, report. (Requires at least one _DRIVER_TYPE defined as TMC2130/2160/5130/5160/2208/2209/2660) * M936 - OTA update firmware. (Requires OTA_FIRMWARE_UPDATE) * M951 - Set Magnetic Parking Extruder parameters. (Requires MAGNETIC_PARKING_EXTRUDER) * M3426 - Read MCP3426 ADC over I2C. (Requires HAS_MCP3426_ADC) * M7219 - Control Max7219 Matrix LEDs. (Requires MAX7219_GCODE) * *** SCARA *** * M360 - SCARA calibration: Move to cal-position ThetaA (0 deg calibration) * M361 - SCARA calibration: Move to cal-position ThetaB (90 deg calibration - steps per degree) * M362 - SCARA calibration: Move to cal-position PsiA (0 deg calibration) * M363 - SCARA calibration: Move to cal-position PsiB (90 deg calibration - steps per degree) * M364 - SCARA calibration: Move to cal-position PSIC (90 deg to Theta calibration position) * *** Custom codes (can be changed to suit future G-code standards) *** * G425 - Calibrate using a conductive object. (Requires CALIBRATION_GCODE) * M928 - Start SD logging: "M928 filename.gco". Stop with M29. (Requires SDSUPPORT) * M993 - Backup SPI Flash to SD * M994 - Load a Backup from SD to SPI Flash * M995 - Touch screen calibration for TFT display * M997 - Perform in-application firmware update * M999 - Restart after being stopped by error * * D... - Custom Development G-code. Add hooks to 'gcode_D.cpp' for developers to test features. (Requires MARLIN_DEV_MODE) * D576 - Set buffer monitoring options. (Requires BUFFER_MONITORING) * *** "T" Codes *** * * T0-T3 - Select an extruder (tool) by index: "T<n> F<units/min>" */ #include "../inc/MarlinConfig.h" #include "parser.h" #if ENABLED(I2C_POSITION_ENCODERS) #include "../feature/encoder_i2c.h" #endif #if ANY(IS_SCARA, POLAR) || defined(G0_FEEDRATE) #define HAS_FAST_MOVES 1 #endif #if ENABLED(MARLIN_SMALL_BUILD) #define GCODE_ERR_MSG(V...) "?" #else #define GCODE_ERR_MSG(V...) "?" V #endif enum AxisRelative : uint8_t { LOGICAL_AXIS_LIST(REL_E, REL_X, REL_Y, REL_Z, REL_I, REL_J, REL_K, REL_U, REL_V, REL_W) #if HAS_EXTRUDERS , E_MODE_ABS, E_MODE_REL #endif , NUM_REL_MODES }; typedef bits_t(NUM_REL_MODES) relative_t; extern const char G28_STR[]; class GcodeSuite { public: static relative_t axis_relative; GcodeSuite() { // Relative motion mode for each logical axis axis_relative = AxisBits(AXIS_RELATIVE_MODES).bits; } static bool axis_is_relative(const AxisEnum a) { #if HAS_EXTRUDERS if (a == E_AXIS) { if (TEST(axis_relative, E_MODE_REL)) return true; if (TEST(axis_relative, E_MODE_ABS)) return false; } #endif return TEST(axis_relative, a); } static void set_relative_mode(const bool rel) { axis_relative = rel ? (0 LOGICAL_AXIS_GANG( | _BV(REL_E), | _BV(REL_X), | _BV(REL_Y), | _BV(REL_Z), | _BV(REL_I), | _BV(REL_J), | _BV(REL_K), | _BV(REL_U), | _BV(REL_V), | _BV(REL_W) )) : 0; } #if HAS_EXTRUDERS static void set_e_relative() { CBI(axis_relative, E_MODE_ABS); SBI(axis_relative, E_MODE_REL); } static void set_e_absolute() { CBI(axis_relative, E_MODE_REL); SBI(axis_relative, E_MODE_ABS); } #endif #if ENABLED(CNC_WORKSPACE_PLANES) /** * Workspace planes only apply to G2/G3 moves * (and "canned cycles" - not a current feature) */ enum WorkspacePlane : char { PLANE_XY, PLANE_ZX, PLANE_YZ }; static WorkspacePlane workspace_plane; #endif #define MAX_COORDINATE_SYSTEMS 9 #if ENABLED(CNC_COORDINATE_SYSTEMS) static int8_t active_coordinate_system; static xyz_pos_t coordinate_system[MAX_COORDINATE_SYSTEMS]; static bool select_coordinate_system(const int8_t _new); #endif static millis_t previous_move_ms, max_inactive_time; FORCE_INLINE static bool stepper_max_timed_out(const millis_t ms=millis()) { return max_inactive_time && ELAPSED(ms, previous_move_ms + max_inactive_time); } FORCE_INLINE static void reset_stepper_timeout(const millis_t ms=millis()) { previous_move_ms = ms; } #if HAS_DISABLE_IDLE_AXES static millis_t stepper_inactive_time; FORCE_INLINE static bool stepper_inactive_timeout(const millis_t ms=millis()) { return ELAPSED(ms, previous_move_ms + stepper_inactive_time); } #else static bool stepper_inactive_timeout(const millis_t) { return false; } #endif static void report_echo_start(const bool forReplay); static void report_heading(const bool forReplay, FSTR_P const fstr, const bool eol=true); static void report_heading_etc(const bool forReplay, FSTR_P const fstr, const bool eol=true) { report_heading(forReplay, fstr, eol); report_echo_start(forReplay); } static void say_units(); static int8_t get_target_extruder_from_command(); static int8_t get_target_e_stepper_from_command(const int8_t dval=-1); static void get_destination_from_command(); static void process_parsed_command(const bool no_ok=false); static void process_next_command(); // Execute G-code in-place, preserving current G-code parameters static void process_subcommands_now(FSTR_P fgcode); static void process_subcommands_now(char * gcode); static void home_all_axes(const bool keep_leveling=false) { process_subcommands_now(keep_leveling ? FPSTR(G28_STR) : TERN(CAN_SET_LEVELING_AFTER_G28, F("G28L0"), FPSTR(G28_STR))); } #if ANY(HAS_AUTO_REPORTING, HOST_KEEPALIVE_FEATURE) static bool autoreport_paused; static bool set_autoreport_paused(const bool p) { const bool was = autoreport_paused; autoreport_paused = p; return was; } #else static constexpr bool autoreport_paused = false; static bool set_autoreport_paused(const bool) { return false; } #endif #if ENABLED(HOST_KEEPALIVE_FEATURE) /** * States for managing Marlin and host communication * Marlin sends messages if blocked or busy */ enum MarlinBusyState : char { NOT_BUSY, // Not in a handler IN_HANDLER, // Processing a G-Code IN_PROCESS, // Known to be blocking command input (as in G29) PAUSED_FOR_USER, // Blocking pending any input PAUSED_FOR_INPUT // Blocking pending text input (concept) }; static MarlinBusyState busy_state; static uint8_t host_keepalive_interval; static void host_keepalive(); static bool host_keepalive_is_paused() { return busy_state >= PAUSED_FOR_USER; } #define KEEPALIVE_STATE(N) REMEMBER(_KA_, gcode.busy_state, gcode.N) #else #define KEEPALIVE_STATE(N) NOOP #endif static void dwell(millis_t time); private: friend class MarlinSettings; #if ENABLED(ARC_SUPPORT) friend void plan_arc(const xyze_pos_t&, const ab_float_t&, const bool, const uint8_t); #endif #if ENABLED(MARLIN_DEV_MODE) static void D(const int16_t dcode); #endif static void G0_G1(TERN_(HAS_FAST_MOVES, const bool fast_move=false)); #if ENABLED(ARC_SUPPORT) static void G2_G3(const bool clockwise); #endif static void G4(); #if ENABLED(BEZIER_CURVE_SUPPORT) static void G5(); #endif #if ENABLED(DIRECT_STEPPING) static void G6(); #endif #if ENABLED(FWRETRACT) static void G10(); static void G11(); #endif #if ENABLED(NOZZLE_CLEAN_FEATURE) static void G12(); #endif #if ENABLED(CNC_WORKSPACE_PLANES) static void G17(); static void G18(); static void G19(); #endif #if ENABLED(INCH_MODE_SUPPORT) static void G20(); static void G21(); #endif #if ENABLED(G26_MESH_VALIDATION) static void G26(); #endif #if ENABLED(NOZZLE_PARK_FEATURE) static void G27(); #endif static void G28(); #if HAS_LEVELING #if ENABLED(G29_RETRY_AND_RECOVER) static void event_probe_failure(); static void event_probe_recover(); static void G29_with_retry(); #define G29_TYPE bool #else #define G29_TYPE void #endif static G29_TYPE G29(); #endif #if HAS_BED_PROBE static void G30(); #if ENABLED(Z_PROBE_SLED) static void G31(); static void G32(); #endif #endif #if ENABLED(DELTA_AUTO_CALIBRATION) static void G33(); #endif #if ANY(Z_MULTI_ENDSTOPS, Z_STEPPER_AUTO_ALIGN, MECHANICAL_GANTRY_CALIBRATION) static void G34(); #endif #if ENABLED(Z_STEPPER_AUTO_ALIGN) static void M422(); static void M422_report(const bool forReplay=true); #endif #if ENABLED(ASSISTED_TRAMMING) static void G35(); #endif #if ENABLED(G38_PROBE_TARGET) static void G38(const int8_t subcode); #endif #if HAS_MESH static void G42(); #endif #if ENABLED(CNC_COORDINATE_SYSTEMS) static void G53(); static void G54(); static void G55(); static void G56(); static void G57(); static void G58(); static void G59(); #endif #if ALL(PTC_PROBE, PTC_BED) static void G76(); #endif #if SAVED_POSITIONS static void G60(); static void G61(); #endif #if ENABLED(GCODE_MOTION_MODES) static void G80(); #endif static void G92(); #if ENABLED(CALIBRATION_GCODE) static void G425(); #endif #if HAS_RESUME_CONTINUE static void M0_M1(); #endif #if HAS_CUTTER static void M3_M4(const bool is_M4); static void M5(); #endif #if ENABLED(COOLANT_MIST) static void M7(); #endif #if ANY(AIR_ASSIST, COOLANT_FLOOD) static void M8(); #endif #if ANY(AIR_ASSIST, COOLANT_CONTROL) static void M9(); #endif #if ENABLED(AIR_EVACUATION) static void M10(); static void M11(); #endif #if ENABLED(EXTERNAL_CLOSED_LOOP_CONTROLLER) static void M12(); #endif #if ENABLED(EXPECTED_PRINTER_CHECK) static void M16(); #endif static void M17(); static void M18_M84(); #if HAS_MEDIA static void M20(); static void M21(); static void M22(); static void M23(); static void M24(); static void M25(); static void M26(); static void M27(); static void M28(); static void M29(); static void M30(); #endif static void M31(); #if HAS_MEDIA #if HAS_MEDIA_SUBCALLS static void M32(); #endif #if ENABLED(LONG_FILENAME_HOST_SUPPORT) static void M33(); #endif #if ALL(SDCARD_SORT_ALPHA, SDSORT_GCODE) static void M34(); #endif #endif #if ENABLED(DIRECT_PIN_CONTROL) static void M42(); #endif #if ENABLED(PINS_DEBUGGING) static void M43(); #endif #if ENABLED(Z_MIN_PROBE_REPEATABILITY_TEST) static void M48(); #endif #if ENABLED(SET_PROGRESS_MANUALLY) static void M73(); #endif static void M75(); static void M76(); static void M77(); #if ENABLED(PRINTCOUNTER) static void M78(); #endif #if ENABLED(PSU_CONTROL) static void M80(); #endif static void M81(); #if HAS_EXTRUDERS static void M82(); static void M83(); #endif static void M85(); #if ENABLED(HOTEND_IDLE_TIMEOUT) static void M86(); static void M86_report(const bool forReplay=true); static void M87(); #endif #if ENABLED(EDITABLE_STEPS_PER_UNIT) static void M92(); static void M92_report(const bool forReplay=true, const int8_t e=-1); #endif #if ENABLED(M100_FREE_MEMORY_WATCHER) static void M100(); #endif #if ENABLED(BD_SENSOR) static void M102(); #endif #if HAS_HOTEND static void M104_M109(const bool isM109); FORCE_INLINE static void M104() { M104_M109(false); } FORCE_INLINE static void M109() { M104_M109(true); } #endif static void M105(); #if HAS_FAN static void M106(); static void M107(); #endif #if DISABLED(EMERGENCY_PARSER) static void M108(); static void M112(); static void M410(); #if ENABLED(HOST_PROMPT_SUPPORT) static void M876(); #endif #endif static void M110(); static void M111(); #if ENABLED(HOST_KEEPALIVE_FEATURE) static void M113(); #endif static void M114(); #if ENABLED(CAPABILITIES_REPORT) static void M115(); #endif #if HAS_STATUS_MESSAGE static void M117(); #endif static void M118(); static void M119(); static void M120(); static void M121(); #if HAS_FANCHECK static void M123(); #endif #if ENABLED(PARK_HEAD_ON_PAUSE) static void M125(); #endif #if ENABLED(BARICUDA) #if HAS_HEATER_1 static void M126(); static void M127(); #endif #if HAS_HEATER_2 static void M128(); static void M129(); #endif #endif #if HAS_HEATED_BED static void M140_M190(const bool isM190); FORCE_INLINE static void M140() { M140_M190(false); } FORCE_INLINE static void M190() { M140_M190(true); } #endif #if HAS_HEATED_CHAMBER static void M141(); static void M191(); #endif #if HAS_TEMP_PROBE static void M192(); #endif #if HAS_COOLER static void M143(); static void M193(); #endif #if HAS_PREHEAT static void M145(); static void M145_report(const bool forReplay=true); #endif #if ENABLED(TEMPERATURE_UNITS_SUPPORT) static void M149(); static void M149_report(const bool forReplay=true); #endif #if HAS_COLOR_LEDS static void M150(); #endif #if ENABLED(AUTO_REPORT_POSITION) static void M154(); #endif #if ALL(AUTO_REPORT_TEMPERATURES, HAS_TEMP_SENSOR) static void M155(); #endif #if ENABLED(MIXING_EXTRUDER) static void M163(); static void M164(); #if ENABLED(DIRECT_MIXING_IN_G1) static void M165(); #endif #if ENABLED(GRADIENT_MIX) static void M166(); #endif #endif #if DISABLED(NO_VOLUMETRICS) static void M200(); static void M200_report(const bool forReplay=true); #endif static void M201(); static void M201_report(const bool forReplay=true); #if 0 static void M202(); // Not used for Sprinter/grbl gen6 #endif static void M203(); static void M203_report(const bool forReplay=true); static void M204(); static void M204_report(const bool forReplay=true); static void M205(); static void M205_report(const bool forReplay=true); #if HAS_HOME_OFFSET static void M206(); static void M206_report(const bool forReplay=true); #endif #if ENABLED(FWRETRACT) static void M207(); static void M207_report(const bool forReplay=true); static void M208(); static void M208_report(const bool forReplay=true); #if ENABLED(FWRETRACT_AUTORETRACT) static void M209(); static void M209_report(const bool forReplay=true); #endif #endif static void M211(); static void M211_report(const bool forReplay=true); #if HAS_MULTI_EXTRUDER static void M217(); static void M217_report(const bool forReplay=true); #endif #if HAS_HOTEND_OFFSET static void M218(); static void M218_report(const bool forReplay=true); #endif static void M220(); #if HAS_EXTRUDERS static void M221(); #endif #if ENABLED(DIRECT_PIN_CONTROL) static void M226(); #endif #if ENABLED(PHOTO_GCODE) static void M240(); #endif #if HAS_LCD_CONTRAST static void M250(); static void M250_report(const bool forReplay=true); #endif #if ENABLED(EDITABLE_DISPLAY_TIMEOUT) static void M255(); static void M255_report(const bool forReplay=true); #endif #if HAS_LCD_BRIGHTNESS static void M256(); static void M256_report(const bool forReplay=true); #endif #if ENABLED(EXPERIMENTAL_I2CBUS) static void M260(); static void M261(); #endif #if HAS_SERVOS static void M280(); #if ENABLED(EDITABLE_SERVO_ANGLES) static void M281(); static void M281_report(const bool forReplay=true); #endif #if ENABLED(SERVO_DETACH_GCODE) static void M282(); #endif #endif #if ENABLED(BABYSTEPPING) static void M290(); #if ENABLED(EP_BABYSTEPPING) static void M293(); static void M294(); #endif #endif #if HAS_SOUND static void M300(); #endif #if ENABLED(PIDTEMP) static void M301(); static void M301_report(const bool forReplay=true E_OPTARG(const int8_t eindex=-1)); #endif #if ENABLED(PREVENT_COLD_EXTRUSION) static void M302(); #endif #if HAS_PID_HEATING static void M303(); #endif #if ENABLED(PIDTEMPBED) static void M304(); static void M304_report(const bool forReplay=true); #endif #if HAS_USER_THERMISTORS static void M305(); #endif #if ENABLED(MPCTEMP) static void M306(); static void M306_report(const bool forReplay=true); #endif #if ENABLED(PIDTEMPCHAMBER) static void M309(); static void M309_report(const bool forReplay=true); #endif #if HAS_MICROSTEPS static void M350(); static void M351(); #endif #if ENABLED(CASE_LIGHT_ENABLE) static void M355(); #endif #if ENABLED(REPETIER_GCODE_M360) static void M360(); #endif #if ENABLED(MORGAN_SCARA) static bool M360(); static bool M361(); static bool M362(); static bool M363(); static bool M364(); #endif #if ANY(EXT_SOLENOID, MANUAL_SOLENOID_CONTROL) static void M380(); static void M381(); #endif static void M400(); #if HAS_BED_PROBE static void M401(); static void M402(); #endif #if HAS_PRUSA_MMU2 static void M403(); #endif #if ENABLED(FILAMENT_WIDTH_SENSOR) static void M404(); static void M405(); static void M406(); static void M407(); #endif #if HAS_FILAMENT_SENSOR static void M412(); static void M412_report(const bool forReplay=true); #endif #if HAS_MULTI_LANGUAGE static void M414(); static void M414_report(const bool forReplay=true); #endif #if HAS_LEVELING static void M420(); static void M420_report(const bool forReplay=true); static void M421(); #endif #if ENABLED(BACKLASH_GCODE) static void M425(); static void M425_report(const bool forReplay=true); #endif #if HAS_HOME_OFFSET static void M428(); #endif #if HAS_POWER_MONITOR static void M430(); #endif #if ENABLED(CANCEL_OBJECTS) static void M486(); #endif #if ENABLED(FT_MOTION) static void M493(); static void M493_report(const bool forReplay=true); #endif static void M500(); static void M501(); static void M502(); #if DISABLED(DISABLE_M503) static void M503(); #endif #if ENABLED(EEPROM_SETTINGS) static void M504(); #endif #if ENABLED(PASSWORD_FEATURE) static void M510(); #if ENABLED(PASSWORD_UNLOCK_GCODE) static void M511(); #endif #if ENABLED(PASSWORD_CHANGE_GCODE) static void M512(); #endif #endif #if HAS_MEDIA static void M524(); #endif #if ENABLED(SD_ABORT_ON_ENDSTOP_HIT) static void M540(); #endif #if HAS_ETHERNET static void M552(); static void M552_report(); static void M553(); static void M553_report(); static void M554(); static void M554_report(); #endif #if HAS_STEALTHCHOP static void M569(); static void M569_report(const bool forReplay=true); #endif #if ENABLED(BAUD_RATE_GCODE) static void M575(); #endif #if ENABLED(NONLINEAR_EXTRUSION) static void M592(); static void M592_report(const bool forReplay=true); #endif #if HAS_ZV_SHAPING static void M593(); static void M593_report(const bool forReplay=true); #endif #if ENABLED(ADVANCED_PAUSE_FEATURE) static void M600(); static void M603(); static void M603_report(const bool forReplay=true); #endif #if HAS_DUPLICATION_MODE static void M605(); #endif #if IS_KINEMATIC static void M665(); static void M665_report(const bool forReplay=true); #endif #if ANY(DELTA, HAS_EXTRA_ENDSTOPS) static void M666(); static void M666_report(const bool forReplay=true); #endif #if ENABLED(DUET_SMART_EFFECTOR) && PIN_EXISTS(SMART_EFFECTOR_MOD) static void M672(); #endif #if ENABLED(FILAMENT_LOAD_UNLOAD_GCODES) static void M701(); static void M702(); #endif #if ENABLED(GCODE_REPEAT_MARKERS) static void M808(); #endif #if ENABLED(GCODE_MACROS) static void M810_819(); #endif #if HAS_BED_PROBE static void M851(); static void M851_report(const bool forReplay=true); #endif #if ENABLED(SKEW_CORRECTION_GCODE) static void M852(); static void M852_report(const bool forReplay=true); #endif #if ENABLED(I2C_POSITION_ENCODERS) FORCE_INLINE static void M860() { I2CPEM.M860(); } FORCE_INLINE static void M861() { I2CPEM.M861(); } FORCE_INLINE static void M862() { I2CPEM.M862(); } FORCE_INLINE static void M863() { I2CPEM.M863(); } FORCE_INLINE static void M864() { I2CPEM.M864(); } FORCE_INLINE static void M865() { I2CPEM.M865(); } FORCE_INLINE static void M866() { I2CPEM.M866(); } FORCE_INLINE static void M867() { I2CPEM.M867(); } FORCE_INLINE static void M868() { I2CPEM.M868(); } FORCE_INLINE static void M869() { I2CPEM.M869(); } #endif #if HAS_PTC static void M871(); #endif #if ENABLED(LIN_ADVANCE) static void M900(); static void M900_report(const bool forReplay=true); #endif #if HAS_TRINAMIC_CONFIG static void M122(); static void M906(); static void M906_report(const bool forReplay=true); #if ENABLED(MONITOR_DRIVER_STATUS) static void M911(); static void M912(); #endif #if ENABLED(HYBRID_THRESHOLD) static void M913(); static void M913_report(const bool forReplay=true); #endif #if USE_SENSORLESS static void M914(); static void M914_report(const bool forReplay=true); #endif static void M919(); #endif #if HAS_MOTOR_CURRENT_SPI || HAS_MOTOR_CURRENT_PWM || HAS_MOTOR_CURRENT_I2C || HAS_MOTOR_CURRENT_DAC static void M907(); #if HAS_MOTOR_CURRENT_SPI || HAS_MOTOR_CURRENT_PWM static void M907_report(const bool forReplay=true); #endif #endif #if HAS_MOTOR_CURRENT_SPI || HAS_MOTOR_CURRENT_DAC static void M908(); #endif #if HAS_MOTOR_CURRENT_DAC static void M909(); static void M910(); #endif #if HAS_MEDIA static void M928(); #endif #if ENABLED(OTA_FIRMWARE_UPDATE) static void M936(); #endif #if ENABLED(MAGNETIC_PARKING_EXTRUDER) static void M951(); #endif #if ENABLED(TOUCH_SCREEN_CALIBRATION) static void M995(); #endif #if SPI_FLASH_BACKUP static void M993(); static void M994(); #endif #if ENABLED(PLATFORM_M997_SUPPORT) static void M997(); #endif static void M999(); #if ENABLED(POWER_LOSS_RECOVERY) static void M413(); static void M413_report(const bool forReplay=true); static void M1000(); #endif #if ENABLED(X_AXIS_TWIST_COMPENSATION) static void M423(); static void M423_report(const bool forReplay=true); #endif #if HAS_MEDIA static void M1001(); #endif #if DGUS_LCD_UI_MKS static void M1002(); #endif #if ENABLED(UBL_MESH_WIZARD) static void M1004(); #endif #if ENABLED(HAS_MCP3426_ADC) static void M3426(); #endif #if ENABLED(MAX7219_GCODE) static void M7219(); #endif #if ENABLED(CONTROLLER_FAN_EDITABLE) static void M710(); static void M710_report(const bool forReplay=true); #endif static void T(const int8_t tool_index) IF_DISABLED(HAS_TOOLCHANGE, { UNUSED(tool_index); }); }; extern GcodeSuite gcode;
2301_81045437/Marlin
Marlin/src/gcode/gcode.h
C++
agpl-3.0
44,197
/** * Marlin 3D Printer Firmware * Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin] * * Based on Sprinter and grbl. * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <https://www.gnu.org/licenses/>. * */ #include "../inc/MarlinConfigPre.h" #if ENABLED(MARLIN_DEV_MODE) #include "gcode.h" #if ENABLED(BUFFER_MONITORING) #include "queue.h" #endif #include "../module/settings.h" #include "../module/temperature.h" #include "../libs/hex_print.h" #include "../HAL/shared/eeprom_if.h" #include "../HAL/shared/Delay.h" #include "../sd/cardreader.h" #include "../MarlinCore.h" // for kill void dump_delay_accuracy_check(); /** * Dn: G-code for development and testing * * See https://reprap.org/wiki/G-code#D:_Debug_codes * * Put whatever else you need here to test ongoing development. */ void GcodeSuite::D(const int16_t dcode) { switch (dcode) { case -1: for (;;) { /* loop forever (watchdog reset) */ } case 0: hal.reboot(); break; case 10: kill(F("D10"), F("KILL TEST"), parser.seen_test('P')); break; case 1: { // Zero or pattern-fill the EEPROM data #if ENABLED(EEPROM_SETTINGS) persistentStore.access_start(); size_t total = persistentStore.capacity(); int pos = 0; const uint8_t value = 0x0; while (total--) persistentStore.write_data(pos, &value, 1); persistentStore.access_finish(); #else settings.reset(); settings.save(); #endif hal.reboot(); } break; case 2: { // D2 Read / Write SRAM #define SRAM_SIZE 8192 uint8_t *pointer = parser.hex_adr_val('A'); uint16_t len = parser.ushortval('C', 1); uintptr_t addr = (uintptr_t)pointer; NOMORE(addr, size_t(SRAM_SIZE - 1)); NOMORE(len, SRAM_SIZE - addr); if (parser.seenval('X')) { // Write the hex bytes after the X uint16_t val = parser.hex_val('X'); while (len--) { *pointer = val; pointer++; } } else { while (len--) print_hex_byte(*(pointer++)); SERIAL_EOL(); } } break; #if ENABLED(EEPROM_SETTINGS) case 3: { // D3 Read / Write EEPROM uint8_t *pointer = parser.hex_adr_val('A'); uint16_t len = parser.ushortval('C', 1); uintptr_t addr = (uintptr_t)pointer; NOMORE(addr, size_t(persistentStore.capacity() - 1)); NOMORE(len, persistentStore.capacity() - addr); if (parser.seenval('X')) { uint16_t val = parser.hex_val('X'); #if ENABLED(EEPROM_SETTINGS) persistentStore.access_start(); while (len--) { int pos = 0; persistentStore.write_data(pos, (uint8_t *)&val, sizeof(val)); } SERIAL_EOL(); persistentStore.access_finish(); #else SERIAL_ECHOLNPGM("NO EEPROM"); #endif } else { // Read bytes from EEPROM #if ENABLED(EEPROM_SETTINGS) persistentStore.access_start(); int pos = 0; uint8_t val; while (len--) if (!persistentStore.read_data(pos, &val, 1)) print_hex_byte(val); SERIAL_EOL(); persistentStore.access_finish(); #else SERIAL_ECHOLNPGM("NO EEPROM"); len = 0; #endif SERIAL_EOL(); } } break; #endif case 4: { // D4 Read / Write PIN //const bool is_out = parser.boolval('F'); //const uint8_t pin = parser.byteval('P'), // val = parser.byteval('V', LOW); if (parser.seenval('X')) { // TODO: Write the hex bytes after the X //while (len--) { //} } else { //while (len--) { //// TODO: Read bytes from EEPROM // print_hex_byte(eeprom_read_byte(adr++)); //} SERIAL_EOL(); } } break; case 5: { // D5 Read / Write onboard Flash // This will overwrite program and data, so don't use it. #define ONBOARD_FLASH_SIZE 1024 // 0x400 uint8_t *pointer = parser.hex_adr_val('A'); uint16_t len = parser.ushortval('C', 1); uintptr_t addr = (uintptr_t)pointer; NOMORE(addr, size_t(ONBOARD_FLASH_SIZE - 1)); NOMORE(len, ONBOARD_FLASH_SIZE - addr); if (parser.seenval('X')) { // TODO: Write the hex bytes after the X //while (len--) {} } else { //while (len--) { //// TODO: Read bytes from FLASH // print_hex_byte(flash_read_byte(adr++)); //} SERIAL_EOL(); } } break; case 6: // D6 Check delay loop accuracy dump_delay_accuracy_check(); break; case 7: // D7 dump the current serial port type (hence configuration) SERIAL_ECHOLNPGM("Current serial configuration RX_BS:", RX_BUFFER_SIZE, ", TX_BS:", TX_BUFFER_SIZE); SERIAL_ECHOLN(gtn(&SERIAL_IMPL)); break; case 100: { // D100 Disable heaters and attempt a hard hang (Watchdog Test) SERIAL_ECHOLNPGM("Disabling heaters and attempting to trigger Watchdog"); SERIAL_ECHOLNPGM("(USE_WATCHDOG " TERN(USE_WATCHDOG, "ENABLED", "DISABLED") ")"); thermalManager.disable_all_heaters(); delay(1000); // Allow time to print hal.isr_off(); // Use a low-level delay that does not rely on interrupts to function // Do not spin forever, to avoid thermal risks if heaters are enabled and // watchdog does not work. for (int i = 10000; i--;) DELAY_US(1000UL); hal.isr_on(); SERIAL_ECHOLNPGM("FAILURE: Watchdog did not trigger board reset."); } break; #if HAS_MEDIA case 101: { // D101 Test SD Write card.openFileWrite("test.gco"); if (!card.isFileOpen()) { SERIAL_ECHOLNPGM("Failed to open test.gco to write."); return; } __attribute__((aligned(sizeof(size_t)))) uint8_t buf[512]; uint16_t c; for (c = 0; c < COUNT(buf); c++) buf[c] = 'A' + (c % ('Z' - 'A')); c = 1024 * 4; while (c--) { hal.watchdog_refresh(); card.write(buf, COUNT(buf)); } SERIAL_ECHOLNPGM(" done"); card.closefile(); } break; case 102: { // D102 Test SD Read char testfile[] = "test.gco"; card.openFileRead(testfile); if (!card.isFileOpen()) { SERIAL_ECHOLNPGM("Failed to open test.gco to read."); return; } __attribute__((aligned(sizeof(size_t)))) uint8_t buf[512]; uint16_t c = 1024 * 4; while (c--) { hal.watchdog_refresh(); card.read(buf, COUNT(buf)); bool error = false; for (uint16_t i = 0; i < COUNT(buf); i++) { if (buf[i] != ('A' + (i % ('Z' - 'A')))) { error = true; break; } } if (error) { SERIAL_ECHOLNPGM(" Read error!"); break; } } SERIAL_ECHOLNPGM(" done"); card.closefile(); } break; #endif // HAS_MEDIA #if ENABLED(POSTMORTEM_DEBUGGING) case 451: { // Trigger all kind of faults to test exception catcher SERIAL_ECHOLNPGM("Disabling heaters"); thermalManager.disable_all_heaters(); delay(1000); // Allow time to print volatile uint8_t type[5] = { parser.byteval('T', 1) }; // The code below is obviously wrong and it's full of quirks to fool the compiler from optimizing away the code switch (type[0]) { case 1: default: *(int*)0 = 451; break; // Write at bad address case 2: { volatile int a = 0; volatile int b = 452 / a; *(int*)&a = b; } break; // Divide by zero (some CPUs accept this, like ARM) case 3: { *(uint32_t*)&type[1] = 453; volatile int a = *(int*)&type[1]; type[0] = a / 255; } break; // Unaligned access (some CPUs accept this) case 4: { volatile void (*func)() = (volatile void (*)()) 0xE0000000; func(); } break; // Invalid instruction } break; } #endif #if ENABLED(BUFFER_MONITORING) /** * D576: Return buffer stats or set the auto-report interval. * Usage: D576 [S<seconds>] * * With no parameters emits the following output: * "D576 P<nn> B<nn> PU<nn> PD<nn> BU<nn> BD<nn>" * Where: * P : Planner buffers free * B : Command buffers free * PU: Planner buffer underruns (since the last report) * PD: Longest duration (ms) the planner buffer was empty (since the last report) * BU: Command buffer underruns (since the last report) * BD: Longest duration (ms) command buffer was empty (since the last report) */ case 576: { if (parser.seenval('S')) queue.set_auto_report_interval((uint8_t)parser.value_byte()); else queue.report_buffer_statistics(); break; } #endif // BUFFER_MONITORING } } #endif // MARLIN_DEV_MODE
2301_81045437/Marlin
Marlin/src/gcode/gcode_d.cpp
C++
agpl-3.0
9,744
/** * Marlin 3D Printer Firmware * Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin] * * Based on Sprinter and grbl. * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <https://www.gnu.org/licenses/>. * */ #include "../../inc/MarlinConfig.h" #if ENABLED(CNC_WORKSPACE_PLANES) #include "../gcode.h" inline void report_workspace_plane() { SERIAL_ECHO_START(); SERIAL_ECHOPGM("Workspace Plane "); SERIAL_ECHO( gcode.workspace_plane == GcodeSuite::PLANE_YZ ? F("YZ\n") : gcode.workspace_plane == GcodeSuite::PLANE_ZX ? F("ZX\n") : F("XY\n") ); } inline void set_workspace_plane(const GcodeSuite::WorkspacePlane plane) { gcode.workspace_plane = plane; if (DEBUGGING(INFO)) report_workspace_plane(); } /** * G17: Select Plane XY * G18: Select Plane ZX * G19: Select Plane YZ */ void GcodeSuite::G17() { set_workspace_plane(PLANE_XY); } void GcodeSuite::G18() { set_workspace_plane(PLANE_ZX); } void GcodeSuite::G19() { set_workspace_plane(PLANE_YZ); } #endif // CNC_WORKSPACE_PLANES
2301_81045437/Marlin
Marlin/src/gcode/geometry/G17-G19.cpp
C++
agpl-3.0
1,718
/** * Marlin 3D Printer Firmware * Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin] * * Based on Sprinter and grbl. * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <https://www.gnu.org/licenses/>. * */ #include "../gcode.h" #include "../../module/motion.h" #if ENABLED(CNC_COORDINATE_SYSTEMS) //#define DEBUG_M53 /** * Select a coordinate system and update the workspace offset. * System index -1 is used to specify machine-native. */ bool GcodeSuite::select_coordinate_system(const int8_t _new) { if (active_coordinate_system == _new) return false; active_coordinate_system = _new; xyz_float_t new_offset{0}; if (WITHIN(_new, 0, MAX_COORDINATE_SYSTEMS - 1)) new_offset = coordinate_system[_new]; workspace_offset = new_offset; return true; } /** * G53: Apply native workspace to the current move * * In CNC G-code G53 is a modifier. * It precedes a movement command (or other modifiers) on the same line. * This is the first command to use parser.chain() to make this possible. * * Marlin also uses G53 on a line by itself to go back to native space. */ void GcodeSuite::G53() { const int8_t old_system = active_coordinate_system; select_coordinate_system(-1); // Always remove workspace offsets #ifdef DEBUG_M53 SERIAL_ECHOLNPGM("Go to native space"); report_current_position(); #endif if (parser.chain()) { // Command to chain? process_parsed_command(); // ...process the chained command select_coordinate_system(old_system); #ifdef DEBUG_M53 SERIAL_ECHOLNPGM("Go back to workspace ", old_system); report_current_position(); #endif } } /** * G54-G59.3: Select a new workspace * * A workspace is an XYZ offset to the machine native space. * All workspaces default to 0,0,0 at start, or with EEPROM * support they may be restored from a previous session. * * G92 is used to set the current workspace's offset. */ void G54_59(uint8_t subcode=0) { const int8_t _space = parser.codenum - 54 + subcode; if (gcode.select_coordinate_system(_space)) { SERIAL_ECHOLNPGM("Select workspace ", _space); report_current_position(); } } void GcodeSuite::G54() { G54_59(); } void GcodeSuite::G55() { G54_59(); } void GcodeSuite::G56() { G54_59(); } void GcodeSuite::G57() { G54_59(); } void GcodeSuite::G58() { G54_59(); } void GcodeSuite::G59() { G54_59(parser.subcode); } #endif // CNC_COORDINATE_SYSTEMS
2301_81045437/Marlin
Marlin/src/gcode/geometry/G53-G59.cpp
C++
agpl-3.0
3,066
/** * Marlin 3D Printer Firmware * Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin] * * Based on Sprinter and grbl. * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <https://www.gnu.org/licenses/>. * */ #include "../gcode.h" #include "../../module/motion.h" #if ENABLED(I2C_POSITION_ENCODERS) #include "../../feature/encoder_i2c.h" #endif /** * G92: Set the Current Position to the given X [Y [Z [A [B [C [U [V [W ]]]]]]]] [E] values. * * Behind the scenes the G92 command may modify the Current Position * or the Position Shift depending on settings and sub-commands. * * Since E has no Workspace Offset, it is always set directly. * * Without Workspace Offsets (e.g., with NO_WORKSPACE_OFFSETS): * G92 : Set NATIVE Current Position to the given X [Y [Z [A [B [C [U [V [W ]]]]]]]] [E]. * * Using Workspace Offsets (default Marlin behavior): * G92 : Modify Workspace Offsets so the reported position shows the given X [Y [Z [A [B [C [U [V [W ]]]]]]]] [E]. * G92.1 : Zero XYZ Workspace Offsets (so the reported position = the native position). * * With POWER_LOSS_RECOVERY or with AXISn_ROTATES: * G92.9 : Set NATIVE Current Position to the given X [Y [Z [A [B [C [U [V [W ]]]]]]]] [E]. */ void GcodeSuite::G92() { #if HAS_EXTRUDERS bool sync_E = false; #endif bool sync_XYZE = false; #if USE_GCODE_SUBCODES const uint8_t subcode_G92 = parser.subcode; #else constexpr uint8_t subcode_G92 = 0; #endif switch (subcode_G92) { default: return; // Ignore unknown G92.x #if ENABLED(CNC_COORDINATE_SYSTEMS) && !IS_SCARA case 1: // G92.1 - Zero the Workspace Offset workspace_offset.reset(); break; #endif #if ANY(POWER_LOSS_RECOVERY, HAS_ROTATIONAL_AXES) case 9: // G92.9 - Set Current Position directly (like Marlin 1.0) LOOP_LOGICAL_AXES(i) { if (parser.seenval(AXIS_CHAR(i))) { if (TERN1(HAS_EXTRUDERS, i != E_AXIS)) sync_XYZE = true; else { TERN_(HAS_EXTRUDERS, sync_E = true); } current_position[i] = parser.value_axis_units((AxisEnum)i); } } break; #endif case 0: LOOP_LOGICAL_AXES(i) { if (parser.seenval(AXIS_CHAR(i))) { const float l = parser.value_axis_units((AxisEnum)i), // Given axis coordinate value, converted to millimeters v = TERN0(HAS_EXTRUDERS, i == E_AXIS) ? l : LOGICAL_TO_NATIVE(l, i), // Axis position in NATIVE space (applying the existing offset) d = v - current_position[i]; // How much is the current axis position altered by? if (!NEAR_ZERO(d)) { #if HAS_WORKSPACE_OFFSET && NONE(IS_SCARA, POLARGRAPH) // When using workspaces... if (TERN1(HAS_EXTRUDERS, i != E_AXIS)) { workspace_offset[i] += d; // ...most axes offset the workspace... } else { #if HAS_EXTRUDERS sync_E = true; current_position.e = v; // ...but E is set directly #endif } #else // Without workspaces... if (TERN1(HAS_EXTRUDERS, i != E_AXIS)) sync_XYZE = true; else { TERN_(HAS_EXTRUDERS, sync_E = true); } current_position[i] = v; // ...set Current Position directly (like Marlin 1.0) #endif } } } break; } #if ENABLED(CNC_COORDINATE_SYSTEMS) // Apply Workspace Offset to the active coordinate system if (WITHIN(active_coordinate_system, 0, MAX_COORDINATE_SYSTEMS - 1)) coordinate_system[active_coordinate_system] = workspace_offset; #endif if (sync_XYZE) sync_plan_position(); #if HAS_EXTRUDERS else if (sync_E) sync_plan_position_e(); #endif IF_DISABLED(DIRECT_STEPPING, report_current_position()); }
2301_81045437/Marlin
Marlin/src/gcode/geometry/G92.cpp
C++
agpl-3.0
4,899