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 5.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  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. #include "../../module/stepper.h"
  25. #if ENABLED(I2C_POSITION_ENCODERS)
  26. #include "../../feature/encoder_i2c.h"
  27. #endif
  28. /**
  29. * G92: Set the Current Position to the given X [Y [Z [A [B [C [U [V [W ]]]]]]]] [E] values.
  30. *
  31. * Behind the scenes the G92 command may modify the Current Position
  32. * or the Position Shift depending on settings and sub-commands.
  33. *
  34. * Since E has no Workspace Offset, it is always set directly.
  35. *
  36. * Without Workspace Offsets (e.g., with NO_WORKSPACE_OFFSETS):
  37. * G92 : Set NATIVE Current Position to the given X [Y [Z [A [B [C [U [V [W ]]]]]]]] [E].
  38. *
  39. * Using Workspace Offsets (default Marlin behavior):
  40. * G92 : Modify Workspace Offsets so the reported position shows the given X [Y [Z [A [B [C [U [V [W ]]]]]]]] [E].
  41. * G92.1 : Zero XYZ Workspace Offsets (so the reported position = the native position).
  42. *
  43. * With POWER_LOSS_RECOVERY:
  44. * G92.9 : Set NATIVE Current Position to the given X [Y [Z [A [B [C [U [V [W ]]]]]]]] [E].
  45. */
  46. void GcodeSuite::G92() {
  47. #if HAS_EXTRUDERS
  48. bool sync_E = false;
  49. #endif
  50. bool sync_XYZE = false;
  51. #if USE_GCODE_SUBCODES
  52. const uint8_t subcode_G92 = parser.subcode;
  53. #else
  54. constexpr uint8_t subcode_G92 = 0;
  55. #endif
  56. switch (subcode_G92) {
  57. default: return; // Ignore unknown G92.x
  58. #if ENABLED(CNC_COORDINATE_SYSTEMS) && !IS_SCARA
  59. case 1: // G92.1 - Zero the Workspace Offset
  60. LOOP_NUM_AXES(i) if (position_shift[i]) {
  61. position_shift[i] = 0;
  62. update_workspace_offset((AxisEnum)i);
  63. }
  64. break;
  65. #endif
  66. #if ENABLED(POWER_LOSS_RECOVERY)
  67. case 9: // G92.9 - Set Current Position directly (like Marlin 1.0)
  68. LOOP_LOGICAL_AXES(i) {
  69. if (parser.seenval(axis_codes[i])) {
  70. if (TERN1(HAS_EXTRUDERS, i != E_AXIS))
  71. sync_XYZE = true;
  72. else {
  73. TERN_(HAS_EXTRUDERS, sync_E = true);
  74. }
  75. current_position[i] = parser.value_axis_units((AxisEnum)i);
  76. }
  77. }
  78. break;
  79. #endif
  80. case 0:
  81. LOOP_LOGICAL_AXES(i) {
  82. if (parser.seenval(axis_codes[i])) {
  83. const float l = parser.value_axis_units((AxisEnum)i), // Given axis coordinate value, converted to millimeters
  84. v = TERN0(HAS_EXTRUDERS, i == E_AXIS) ? l : LOGICAL_TO_NATIVE(l, i), // Axis position in NATIVE space (applying the existing offset)
  85. d = v - current_position[i]; // How much is the current axis position altered by?
  86. if (!NEAR_ZERO(d)) {
  87. #if HAS_POSITION_SHIFT && !IS_SCARA // When using workspaces...
  88. if (TERN1(HAS_EXTRUDERS, i != E_AXIS)) {
  89. position_shift[i] += d; // ...most axes offset the workspace...
  90. update_workspace_offset((AxisEnum)i);
  91. }
  92. else {
  93. #if HAS_EXTRUDERS
  94. sync_E = true;
  95. current_position.e = v; // ...but E is set directly
  96. #endif
  97. }
  98. #else // Without workspaces...
  99. if (TERN1(HAS_EXTRUDERS, i != E_AXIS))
  100. sync_XYZE = true;
  101. else {
  102. TERN_(HAS_EXTRUDERS, sync_E = true);
  103. }
  104. current_position[i] = v; // ...set Current Position directly (like Marlin 1.0)
  105. #endif
  106. }
  107. }
  108. }
  109. break;
  110. }
  111. #if ENABLED(CNC_COORDINATE_SYSTEMS)
  112. // Apply Workspace Offset to the active coordinate system
  113. if (WITHIN(active_coordinate_system, 0, MAX_COORDINATE_SYSTEMS - 1))
  114. coordinate_system[active_coordinate_system] = position_shift;
  115. #endif
  116. if (sync_XYZE) sync_plan_position();
  117. #if HAS_EXTRUDERS
  118. else if (sync_E) sync_plan_position_e();
  119. #endif
  120. IF_DISABLED(DIRECT_STEPPING, report_current_position());
  121. }