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.

M852.cpp 3.0KB

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 ENABLED(SKEW_CORRECTION_GCODE)
  24. #include "../gcode.h"
  25. #include "../../module/planner.h"
  26. /**
  27. * M852: Get or set the machine skew factors. Reports current values with no arguments.
  28. *
  29. * S[xy_factor] - Alias for 'I'
  30. * I[xy_factor] - New XY skew factor
  31. * J[xz_factor] - New XZ skew factor
  32. * K[yz_factor] - New YZ skew factor
  33. */
  34. void GcodeSuite::M852() {
  35. if (!parser.seen("SIJK")) return M852_report();
  36. uint8_t badval = 0, setval = 0;
  37. if (parser.seenval('I') || parser.seenval('S')) {
  38. const float value = parser.value_linear_units();
  39. if (WITHIN(value, SKEW_FACTOR_MIN, SKEW_FACTOR_MAX)) {
  40. if (planner.skew_factor.xy != value) {
  41. planner.skew_factor.xy = value;
  42. ++setval;
  43. }
  44. }
  45. else
  46. ++badval;
  47. }
  48. #if ENABLED(SKEW_CORRECTION_FOR_Z)
  49. if (parser.seenval('J')) {
  50. const float value = parser.value_linear_units();
  51. if (WITHIN(value, SKEW_FACTOR_MIN, SKEW_FACTOR_MAX)) {
  52. if (planner.skew_factor.xz != value) {
  53. planner.skew_factor.xz = value;
  54. ++setval;
  55. }
  56. }
  57. else
  58. ++badval;
  59. }
  60. if (parser.seenval('K')) {
  61. const float value = parser.value_linear_units();
  62. if (WITHIN(value, SKEW_FACTOR_MIN, SKEW_FACTOR_MAX)) {
  63. if (planner.skew_factor.yz != value) {
  64. planner.skew_factor.yz = value;
  65. ++setval;
  66. }
  67. }
  68. else
  69. ++badval;
  70. }
  71. #endif
  72. if (badval)
  73. SERIAL_ECHOLNPGM(STR_SKEW_MIN " " STRINGIFY(SKEW_FACTOR_MIN) " " STR_SKEW_MAX " " STRINGIFY(SKEW_FACTOR_MAX));
  74. // When skew is changed the current position changes
  75. if (setval) {
  76. set_current_from_steppers_for_axis(ALL_AXES_ENUM);
  77. sync_plan_position();
  78. report_current_position();
  79. }
  80. }
  81. void GcodeSuite::M852_report(const bool forReplay/*=true*/) {
  82. report_heading_etc(forReplay, F(STR_SKEW_FACTOR));
  83. SERIAL_ECHOPAIR_F(" M852 I", planner.skew_factor.xy, 6);
  84. #if ENABLED(SKEW_CORRECTION_FOR_Z)
  85. SERIAL_ECHOPAIR_F(" J", planner.skew_factor.xz, 6);
  86. SERIAL_ECHOPAIR_F(" K", planner.skew_factor.yz, 6);
  87. SERIAL_ECHOLNPGM(" ; XY, XZ, YZ");
  88. #else
  89. SERIAL_ECHOLNPGM(" ; XY");
  90. #endif
  91. }
  92. #endif // SKEW_CORRECTION_GCODE