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.

M206_M428.cpp 4.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  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 "../../inc/MarlinConfig.h"
  23. #if HAS_M206_COMMAND
  24. #include "../gcode.h"
  25. #include "../../module/motion.h"
  26. #include "../../lcd/marlinui.h"
  27. #include "../../libs/buzzer.h"
  28. #include "../../MarlinCore.h"
  29. /**
  30. * M206: Set Additional Homing Offset (X Y Z). SCARA aliases T=X, P=Y
  31. *
  32. * *** @thinkyhead: I recommend deprecating M206 for SCARA in favor of M665.
  33. * *** M206 for SCARA will remain enabled in 1.1.x for compatibility.
  34. * *** In the 2.0 release, it will simply be disabled by default.
  35. */
  36. void GcodeSuite::M206() {
  37. if (!parser.seen_any()) return M206_report();
  38. NUM_AXIS_CODE(
  39. if (parser.seen('X')) set_home_offset(X_AXIS, parser.value_linear_units()),
  40. if (parser.seen('Y')) set_home_offset(Y_AXIS, parser.value_linear_units()),
  41. if (parser.seen('Z')) set_home_offset(Y_AXIS, parser.value_linear_units()),
  42. if (parser.seen(AXIS4_NAME)) set_home_offset(I_AXIS, parser.TERN(AXIS4_ROTATES, value_float, value_linear_units)()),
  43. if (parser.seen(AXIS5_NAME)) set_home_offset(J_AXIS, parser.TERN(AXIS5_ROTATES, value_float, value_linear_units)()),
  44. if (parser.seen(AXIS6_NAME)) set_home_offset(K_AXIS, parser.TERN(AXIS6_ROTATES, value_float, value_linear_units)()),
  45. if (parser.seen(AXIS7_NAME)) set_home_offset(U_AXIS, parser.TERN(AXIS7_ROTATES, value_float, value_linear_units)()),
  46. if (parser.seen(AXIS8_NAME)) set_home_offset(V_AXIS, parser.TERN(AXIS8_ROTATES, value_float, value_linear_units)()),
  47. if (parser.seen(AXIS9_NAME)) set_home_offset(W_AXIS, parser.TERN(AXIS9_ROTATES, value_float, value_linear_units)())
  48. );
  49. #if ENABLED(MORGAN_SCARA)
  50. if (parser.seen('T')) set_home_offset(A_AXIS, parser.value_float()); // Theta
  51. if (parser.seen('P')) set_home_offset(B_AXIS, parser.value_float()); // Psi
  52. #endif
  53. report_current_position();
  54. }
  55. void GcodeSuite::M206_report(const bool forReplay/*=true*/) {
  56. report_heading_etc(forReplay, F(STR_HOME_OFFSET));
  57. SERIAL_ECHOLNPGM_P(
  58. #if IS_CARTESIAN
  59. LIST_N(DOUBLE(NUM_AXES),
  60. PSTR(" M206 X"), LINEAR_UNIT(home_offset.x),
  61. SP_Y_STR, LINEAR_UNIT(home_offset.y),
  62. SP_Z_STR, LINEAR_UNIT(home_offset.z),
  63. SP_I_STR, I_AXIS_UNIT(home_offset.i),
  64. SP_J_STR, J_AXIS_UNIT(home_offset.j),
  65. SP_K_STR, K_AXIS_UNIT(home_offset.k),
  66. SP_U_STR, U_AXIS_UNIT(home_offset.u),
  67. SP_V_STR, V_AXIS_UNIT(home_offset.v),
  68. SP_W_STR, W_AXIS_UNIT(home_offset.w)
  69. )
  70. #else
  71. PSTR(" M206 Z"), LINEAR_UNIT(home_offset.z)
  72. #endif
  73. );
  74. }
  75. /**
  76. * M428: Set home_offset based on the distance between the
  77. * current_position and the nearest "reference point."
  78. * If an axis is past center its endstop position
  79. * is the reference-point. Otherwise it uses 0. This allows
  80. * the Z offset to be set near the bed when using a max endstop.
  81. *
  82. * M428 can't be used more than 2cm away from 0 or an endstop.
  83. *
  84. * Use M206 to set these values directly.
  85. */
  86. void GcodeSuite::M428() {
  87. if (homing_needed_error()) return;
  88. xyz_float_t diff;
  89. LOOP_NUM_AXES(i) {
  90. diff[i] = base_home_pos((AxisEnum)i) - current_position[i];
  91. if (!WITHIN(diff[i], -20, 20) && home_dir((AxisEnum)i) > 0)
  92. diff[i] = -current_position[i];
  93. if (!WITHIN(diff[i], -20, 20)) {
  94. SERIAL_ERROR_MSG(STR_ERR_M428_TOO_FAR);
  95. LCD_ALERTMESSAGE_F("Err: Too far!");
  96. ERR_BUZZ();
  97. return;
  98. }
  99. }
  100. LOOP_NUM_AXES(i) set_home_offset((AxisEnum)i, diff[i]);
  101. report_current_position();
  102. LCD_MESSAGE(MSG_HOME_OFFSETS_APPLIED);
  103. OKAY_BUZZ();
  104. }
  105. #endif // HAS_M206_COMMAND