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.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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_LINEAR_AXES(i)
  39. if (parser.seen(AXIS_CHAR(i)))
  40. set_home_offset((AxisEnum)i, parser.value_linear_units());
  41. #if ENABLED(MORGAN_SCARA)
  42. if (parser.seen('T')) set_home_offset(A_AXIS, parser.value_float()); // Theta
  43. if (parser.seen('P')) set_home_offset(B_AXIS, parser.value_float()); // Psi
  44. #endif
  45. report_current_position();
  46. }
  47. void GcodeSuite::M206_report(const bool forReplay/*=true*/) {
  48. report_heading_etc(forReplay, PSTR(STR_HOME_OFFSET));
  49. SERIAL_ECHOLNPGM_P(
  50. #if IS_CARTESIAN
  51. LIST_N(DOUBLE(LINEAR_AXES),
  52. PSTR(" M206 X"), LINEAR_UNIT(home_offset.x),
  53. SP_Y_STR, LINEAR_UNIT(home_offset.y),
  54. SP_Z_STR, LINEAR_UNIT(home_offset.z),
  55. SP_I_STR, LINEAR_UNIT(home_offset.i),
  56. SP_J_STR, LINEAR_UNIT(home_offset.j),
  57. SP_K_STR, LINEAR_UNIT(home_offset.k)
  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_LINEAR_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_ALERTMESSAGEPGM_P(PSTR("Err: Too far!"));
  85. BUZZ(200, 40);
  86. return;
  87. }
  88. }
  89. LOOP_LINEAR_AXES(i) set_home_offset((AxisEnum)i, diff[i]);
  90. report_current_position();
  91. LCD_MESSAGEPGM(MSG_HOME_OFFSETS_APPLIED);
  92. BUZZ(100, 659);
  93. BUZZ(100, 698);
  94. }
  95. #endif // HAS_M206_COMMAND