M206_M428.cpp 3.3 KB

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