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.

M851.cpp 2.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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_BED_PROBE
  24. #include "../gcode.h"
  25. #include "../../feature/bedlevel/bedlevel.h"
  26. #include "../../module/probe.h"
  27. /**
  28. * M851: Set the nozzle-to-probe offsets in current units
  29. */
  30. void GcodeSuite::M851() {
  31. // No parameters? Show current state.
  32. if (!parser.seen("XYZ")) return M851_report();
  33. // Start with current offsets and modify
  34. xyz_pos_t offs = probe.offset;
  35. // Assume no errors
  36. bool ok = true;
  37. if (parser.seenval('X')) {
  38. const float x = parser.value_float();
  39. #if HAS_PROBE_XY_OFFSET
  40. if (WITHIN(x, -(X_BED_SIZE), X_BED_SIZE))
  41. offs.x = x;
  42. else {
  43. SERIAL_ECHOLNPGM("?X out of range (-", X_BED_SIZE, " to ", X_BED_SIZE, ")");
  44. ok = false;
  45. }
  46. #else
  47. if (x) SERIAL_ECHOLNPGM("?X must be 0 (NOZZLE_AS_PROBE)."); // ...but let 'ok' stay true
  48. #endif
  49. }
  50. if (parser.seenval('Y')) {
  51. const float y = parser.value_float();
  52. #if HAS_PROBE_XY_OFFSET
  53. if (WITHIN(y, -(Y_BED_SIZE), Y_BED_SIZE))
  54. offs.y = y;
  55. else {
  56. SERIAL_ECHOLNPGM("?Y out of range (-", Y_BED_SIZE, " to ", Y_BED_SIZE, ")");
  57. ok = false;
  58. }
  59. #else
  60. if (y) SERIAL_ECHOLNPGM("?Y must be 0 (NOZZLE_AS_PROBE)."); // ...but let 'ok' stay true
  61. #endif
  62. }
  63. if (parser.seenval('Z')) {
  64. const float z = parser.value_float();
  65. if (WITHIN(z, Z_PROBE_OFFSET_RANGE_MIN, Z_PROBE_OFFSET_RANGE_MAX))
  66. offs.z = z;
  67. else {
  68. SERIAL_ECHOLNPGM("?Z out of range (", Z_PROBE_OFFSET_RANGE_MIN, " to ", Z_PROBE_OFFSET_RANGE_MAX, ")");
  69. ok = false;
  70. }
  71. }
  72. // Save the new offsets
  73. if (ok) probe.offset = offs;
  74. }
  75. void GcodeSuite::M851_report(const bool forReplay/*=true*/) {
  76. report_heading_etc(forReplay, F(STR_Z_PROBE_OFFSET));
  77. SERIAL_ECHOPGM_P(
  78. #if HAS_PROBE_XY_OFFSET
  79. PSTR(" M851 X"), LINEAR_UNIT(probe.offset_xy.x),
  80. SP_Y_STR, LINEAR_UNIT(probe.offset_xy.y),
  81. SP_Z_STR
  82. #else
  83. PSTR(" M851 X0 Y0 Z")
  84. #endif
  85. , LINEAR_UNIT(probe.offset.z)
  86. , PSTR(" ;")
  87. );
  88. say_units();
  89. }
  90. #endif // HAS_BED_PROBE