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

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