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.

M114.cpp 6.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  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. #include "../gcode.h"
  24. #include "../../module/motion.h"
  25. #include "../../module/stepper.h"
  26. #if ENABLED(M114_DETAIL)
  27. #if HAS_L64XX
  28. #include "../../libs/L64XX/L64XX_Marlin.h"
  29. #define DEBUG_OUT ENABLED(L6470_CHITCHAT)
  30. #include "../../core/debug_out.h"
  31. #endif
  32. void report_xyze(const xyze_pos_t &pos, const uint8_t n=XYZE, const uint8_t precision=3) {
  33. char str[12];
  34. LOOP_L_N(a, n) {
  35. SERIAL_CHAR(' ', axis_codes[a], ':');
  36. if (pos[a] >= 0) SERIAL_CHAR(' ');
  37. SERIAL_ECHO(dtostrf(pos[a], 1, precision, str));
  38. }
  39. SERIAL_EOL();
  40. }
  41. inline void report_xyz(const xyze_pos_t &pos) { report_xyze(pos, XYZ); }
  42. void report_xyz(const xyz_pos_t &pos, const uint8_t precision=3) {
  43. char str[12];
  44. LOOP_XYZ(a) {
  45. SERIAL_CHAR(' ', XYZ_CHAR(a), ':');
  46. SERIAL_ECHO(dtostrf(pos[a], 1, precision, str));
  47. }
  48. SERIAL_EOL();
  49. }
  50. void report_current_position_detail() {
  51. // Position as sent by G-code
  52. SERIAL_ECHOPGM("\nLogical:");
  53. report_xyz(current_position.asLogical());
  54. // Cartesian position in native machine space
  55. SERIAL_ECHOPGM("Raw: ");
  56. report_xyz(current_position);
  57. xyze_pos_t leveled = current_position;
  58. #if HAS_LEVELING
  59. // Current position with leveling applied
  60. SERIAL_ECHOPGM("Leveled:");
  61. planner.apply_leveling(leveled);
  62. report_xyz(leveled);
  63. // Test planner un-leveling. This should match the Raw result.
  64. SERIAL_ECHOPGM("UnLevel:");
  65. xyze_pos_t unleveled = leveled;
  66. planner.unapply_leveling(unleveled);
  67. report_xyz(unleveled);
  68. #endif
  69. #if IS_KINEMATIC
  70. // Kinematics applied to the leveled position
  71. #if IS_SCARA
  72. SERIAL_ECHOPGM("ScaraK: ");
  73. #else
  74. SERIAL_ECHOPGM("DeltaK: ");
  75. #endif
  76. inverse_kinematics(leveled); // writes delta[]
  77. report_xyz(delta);
  78. #endif
  79. planner.synchronize();
  80. #if HAS_L64XX
  81. char temp_buf[80];
  82. int32_t temp;
  83. //#define ABS_POS_SIGN_MASK 0b1111 1111 1110 0000 0000 0000 0000 0000
  84. #define ABS_POS_SIGN_MASK 0b11111111111000000000000000000000
  85. #define REPORT_ABSOLUTE_POS(Q) do{ \
  86. L64xxManager.say_axis(Q, false); \
  87. temp = L6470_GETPARAM(L6470_ABS_POS,Q); \
  88. if (temp & ABS_POS_SIGN_MASK) temp |= ABS_POS_SIGN_MASK; \
  89. sprintf_P(temp_buf, PSTR(":%8ld "), temp); \
  90. DEBUG_ECHO(temp_buf); \
  91. }while(0)
  92. DEBUG_ECHOPGM("\nL6470:");
  93. #if AXIS_IS_L64XX(X)
  94. REPORT_ABSOLUTE_POS(X);
  95. #endif
  96. #if AXIS_IS_L64XX(X2)
  97. REPORT_ABSOLUTE_POS(X2);
  98. #endif
  99. #if AXIS_IS_L64XX(Y)
  100. REPORT_ABSOLUTE_POS(Y);
  101. #endif
  102. #if AXIS_IS_L64XX(Y2)
  103. REPORT_ABSOLUTE_POS(Y2);
  104. #endif
  105. #if AXIS_IS_L64XX(Z)
  106. REPORT_ABSOLUTE_POS(Z);
  107. #endif
  108. #if AXIS_IS_L64XX(Z2)
  109. REPORT_ABSOLUTE_POS(Z2);
  110. #endif
  111. #if AXIS_IS_L64XX(Z3)
  112. REPORT_ABSOLUTE_POS(Z3);
  113. #endif
  114. #if AXIS_IS_L64XX(Z4)
  115. REPORT_ABSOLUTE_POS(Z4);
  116. #endif
  117. #if AXIS_IS_L64XX(E0)
  118. REPORT_ABSOLUTE_POS(E0);
  119. #endif
  120. #if AXIS_IS_L64XX(E1)
  121. REPORT_ABSOLUTE_POS(E1);
  122. #endif
  123. #if AXIS_IS_L64XX(E2)
  124. REPORT_ABSOLUTE_POS(E2);
  125. #endif
  126. #if AXIS_IS_L64XX(E3)
  127. REPORT_ABSOLUTE_POS(E3);
  128. #endif
  129. #if AXIS_IS_L64XX(E4)
  130. REPORT_ABSOLUTE_POS(E4);
  131. #endif
  132. #if AXIS_IS_L64XX(E5)
  133. REPORT_ABSOLUTE_POS(E5);
  134. #endif
  135. #if AXIS_IS_L64XX(E6)
  136. REPORT_ABSOLUTE_POS(E6);
  137. #endif
  138. #if AXIS_IS_L64XX(E7)
  139. REPORT_ABSOLUTE_POS(E7);
  140. #endif
  141. SERIAL_EOL();
  142. #endif // HAS_L64XX
  143. SERIAL_ECHOPGM("Stepper:");
  144. LOOP_XYZE(i) {
  145. SERIAL_CHAR(' ', axis_codes[i], ':');
  146. SERIAL_ECHO(stepper.position((AxisEnum)i));
  147. }
  148. SERIAL_EOL();
  149. #if IS_SCARA
  150. const xy_float_t deg = {
  151. planner.get_axis_position_degrees(A_AXIS),
  152. planner.get_axis_position_degrees(B_AXIS)
  153. };
  154. SERIAL_ECHOPGM("Degrees:");
  155. report_xyze(deg, 2);
  156. #endif
  157. SERIAL_ECHOPGM("FromStp:");
  158. get_cartesian_from_steppers(); // writes 'cartes' (with forward kinematics)
  159. xyze_pos_t from_steppers = { cartes.x, cartes.y, cartes.z, planner.get_axis_position_mm(E_AXIS) };
  160. report_xyze(from_steppers);
  161. const xyze_float_t diff = from_steppers - leveled;
  162. SERIAL_ECHOPGM("Diff: ");
  163. report_xyze(diff);
  164. }
  165. #endif // M114_DETAIL
  166. /**
  167. * M114: Report the current position to host.
  168. * Since steppers are moving, the count positions are
  169. * projected by using planner calculations.
  170. * D - Report more detail. This syncs the planner. (Requires M114_DETAIL)
  171. * E - Report E stepper position (Requires M114_DETAIL)
  172. * R - Report the realtime position instead of projected.
  173. */
  174. void GcodeSuite::M114() {
  175. #if ENABLED(M114_DETAIL)
  176. if (parser.seen('D')) {
  177. #if DISABLED(M114_LEGACY)
  178. planner.synchronize();
  179. #endif
  180. report_current_position();
  181. report_current_position_detail();
  182. return;
  183. }
  184. if (parser.seen('E')) {
  185. SERIAL_ECHOLNPAIR("Count E:", stepper.position(E_AXIS));
  186. return;
  187. }
  188. #endif
  189. #if ENABLED(M114_REALTIME)
  190. if (parser.seen('R')) { report_real_position(); return; }
  191. #endif
  192. TERN_(M114_LEGACY, planner.synchronize());
  193. report_current_position_projected();
  194. }