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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  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. LOOP_NUM_AXES(a)
  39. if (parser.seenval(AXIS_CHAR(a))) set_home_offset((AxisEnum)a, parser.value_axis_units((AxisEnum)a));
  40. #if ENABLED(MORGAN_SCARA)
  41. if (parser.seenval('T')) set_home_offset(A_AXIS, parser.value_float()); // Theta
  42. if (parser.seenval('P')) set_home_offset(B_AXIS, parser.value_float()); // Psi
  43. #endif
  44. report_current_position();
  45. }
  46. void GcodeSuite::M206_report(const bool forReplay/*=true*/) {
  47. report_heading_etc(forReplay, F(STR_HOME_OFFSET));
  48. SERIAL_ECHOLNPGM_P(
  49. #if IS_CARTESIAN
  50. LIST_N(DOUBLE(NUM_AXES),
  51. PSTR(" M206 X"), LINEAR_UNIT(home_offset.x),
  52. SP_Y_STR, LINEAR_UNIT(home_offset.y),
  53. SP_Z_STR, LINEAR_UNIT(home_offset.z),
  54. SP_I_STR, I_AXIS_UNIT(home_offset.i),
  55. SP_J_STR, J_AXIS_UNIT(home_offset.j),
  56. SP_K_STR, K_AXIS_UNIT(home_offset.k),
  57. SP_U_STR, U_AXIS_UNIT(home_offset.u),
  58. SP_V_STR, V_AXIS_UNIT(home_offset.v),
  59. SP_W_STR, W_AXIS_UNIT(home_offset.w)
  60. )
  61. #else
  62. PSTR(" M206 Z"), LINEAR_UNIT(home_offset.z)
  63. #endif
  64. );
  65. }
  66. /**
  67. * M428: Set home_offset based on the distance between the
  68. * current_position and the nearest "reference point."
  69. * If an axis is past center its endstop position
  70. * is the reference-point. Otherwise it uses 0. This allows
  71. * the Z offset to be set near the bed when using a max endstop.
  72. *
  73. * M428 can't be used more than 2cm away from 0 or an endstop.
  74. *
  75. * Use M206 to set these values directly.
  76. */
  77. void GcodeSuite::M428() {
  78. if (homing_needed_error()) return;
  79. xyz_float_t diff;
  80. LOOP_NUM_AXES(i) {
  81. diff[i] = base_home_pos((AxisEnum)i) - current_position[i];
  82. if (!WITHIN(diff[i], -20, 20) && home_dir((AxisEnum)i) > 0)
  83. diff[i] = -current_position[i];
  84. if (!WITHIN(diff[i], -20, 20)) {
  85. SERIAL_ERROR_MSG(STR_ERR_M428_TOO_FAR);
  86. LCD_ALERTMESSAGE_F("Err: Too far!");
  87. ERR_BUZZ();
  88. return;
  89. }
  90. }
  91. LOOP_NUM_AXES(i) set_home_offset((AxisEnum)i, diff[i]);
  92. report_current_position();
  93. LCD_MESSAGE(MSG_HOME_OFFSETS_APPLIED);
  94. OKAY_BUZZ();
  95. }
  96. #endif // HAS_M206_COMMAND