My Marlin configs for Fabrikator Mini and CTC i3 Pro B
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

G92.cpp 4.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. /**
  2. * Marlin 3D Printer Firmware
  3. * Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
  4. *
  5. * Based on Sprinter and grbl.
  6. * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
  7. *
  8. * This program is free software: you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation, either version 3 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  20. *
  21. */
  22. #include "../gcode.h"
  23. #include "../../module/motion.h"
  24. #if ENABLED(I2C_POSITION_ENCODERS)
  25. #include "../../feature/encoder_i2c.h"
  26. #endif
  27. /**
  28. * G92: Set the Current Position to the given X [Y [Z [A [B [C [U [V [W ]]]]]]]] [E] values.
  29. *
  30. * Behind the scenes the G92 command may modify the Current Position
  31. * or the Position Shift depending on settings and sub-commands.
  32. *
  33. * Since E has no Workspace Offset, it is always set directly.
  34. *
  35. * Without Workspace Offsets (e.g., with NO_WORKSPACE_OFFSETS):
  36. * G92 : Set NATIVE Current Position to the given X [Y [Z [A [B [C [U [V [W ]]]]]]]] [E].
  37. *
  38. * Using Workspace Offsets (default Marlin behavior):
  39. * G92 : Modify Workspace Offsets so the reported position shows the given X [Y [Z [A [B [C [U [V [W ]]]]]]]] [E].
  40. * G92.1 : Zero XYZ Workspace Offsets (so the reported position = the native position).
  41. *
  42. * With POWER_LOSS_RECOVERY:
  43. * G92.9 : Set NATIVE Current Position to the given X [Y [Z [A [B [C [U [V [W ]]]]]]]] [E].
  44. */
  45. void GcodeSuite::G92() {
  46. #if HAS_EXTRUDERS
  47. bool sync_E = false;
  48. #endif
  49. bool sync_XYZE = false;
  50. #if USE_GCODE_SUBCODES
  51. const uint8_t subcode_G92 = parser.subcode;
  52. #else
  53. constexpr uint8_t subcode_G92 = 0;
  54. #endif
  55. switch (subcode_G92) {
  56. default: return; // Ignore unknown G92.x
  57. #if ENABLED(CNC_COORDINATE_SYSTEMS) && !IS_SCARA
  58. case 1: // G92.1 - Zero the Workspace Offset
  59. LOOP_NUM_AXES(i) if (position_shift[i]) {
  60. position_shift[i] = 0;
  61. update_workspace_offset((AxisEnum)i);
  62. }
  63. break;
  64. #endif
  65. #if ENABLED(POWER_LOSS_RECOVERY)
  66. case 9: // G92.9 - Set Current Position directly (like Marlin 1.0)
  67. LOOP_LOGICAL_AXES(i) {
  68. if (parser.seenval(AXIS_CHAR(i))) {
  69. if (TERN1(HAS_EXTRUDERS, i != E_AXIS))
  70. sync_XYZE = true;
  71. else {
  72. TERN_(HAS_EXTRUDERS, sync_E = true);
  73. }
  74. current_position[i] = parser.value_axis_units((AxisEnum)i);
  75. }
  76. }
  77. break;
  78. #endif
  79. case 0:
  80. LOOP_LOGICAL_AXES(i) {
  81. if (parser.seenval(AXIS_CHAR(i))) {
  82. const float l = parser.value_axis_units((AxisEnum)i), // Given axis coordinate value, converted to millimeters
  83. v = TERN0(HAS_EXTRUDERS, i == E_AXIS) ? l : LOGICAL_TO_NATIVE(l, i), // Axis position in NATIVE space (applying the existing offset)
  84. d = v - current_position[i]; // How much is the current axis position altered by?
  85. if (!NEAR_ZERO(d)) {
  86. #if HAS_POSITION_SHIFT && NONE(IS_SCARA, POLARGRAPH) // When using workspaces...
  87. if (TERN1(HAS_EXTRUDERS, i != E_AXIS)) {
  88. position_shift[i] += d; // ...most axes offset the workspace...
  89. update_workspace_offset((AxisEnum)i);
  90. }
  91. else {
  92. #if HAS_EXTRUDERS
  93. sync_E = true;
  94. current_position.e = v; // ...but E is set directly
  95. #endif
  96. }
  97. #else // Without workspaces...
  98. if (TERN1(HAS_EXTRUDERS, i != E_AXIS))
  99. sync_XYZE = true;
  100. else {
  101. TERN_(HAS_EXTRUDERS, sync_E = true);
  102. }
  103. current_position[i] = v; // ...set Current Position directly (like Marlin 1.0)
  104. #endif
  105. }
  106. }
  107. }
  108. break;
  109. }
  110. #if ENABLED(CNC_COORDINATE_SYSTEMS)
  111. // Apply Workspace Offset to the active coordinate system
  112. if (WITHIN(active_coordinate_system, 0, MAX_COORDINATE_SYSTEMS - 1))
  113. coordinate_system[active_coordinate_system] = position_shift;
  114. #endif
  115. if (sync_XYZE) sync_plan_position();
  116. #if HAS_EXTRUDERS
  117. else if (sync_E) sync_plan_position_e();
  118. #endif
  119. IF_DISABLED(DIRECT_STEPPING, report_current_position());
  120. }