first_lay_cal.cpp 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  1. //! @file
  2. //! @date Jun 10, 2019
  3. //! @author Marek Bel
  4. //! @brief First layer (Z offset) calibration
  5. #include "first_lay_cal.h"
  6. #include "Configuration_prusa.h"
  7. #include "language.h"
  8. #include "Marlin.h"
  9. #include "mmu.h"
  10. #include <avr/pgmspace.h>
  11. //! @brief Preheat
  12. void lay1cal_preheat()
  13. {
  14. static const char cmd_preheat_0[] PROGMEM = "M107";
  15. static const char cmd_preheat_1[] PROGMEM = "M104 S" STRINGIFY(PLA_PREHEAT_HOTEND_TEMP);
  16. static const char cmd_preheat_2[] PROGMEM = "M140 S" STRINGIFY(PLA_PREHEAT_HPB_TEMP);
  17. static const char cmd_preheat_3[] PROGMEM = "M190 S" STRINGIFY(PLA_PREHEAT_HPB_TEMP);
  18. static const char cmd_preheat_4[] PROGMEM = "M109 S" STRINGIFY(PLA_PREHEAT_HOTEND_TEMP);
  19. static const char cmd_preheat_5[] PROGMEM = "G28";
  20. static const char cmd_preheat_6[] PROGMEM = "G92 E0.0";
  21. static const char * const preheat_cmd[] PROGMEM =
  22. {
  23. cmd_preheat_0,
  24. cmd_preheat_1,
  25. cmd_preheat_2,
  26. cmd_preheat_3,
  27. cmd_preheat_4,
  28. cmd_preheat_5, //call MSG_M117_V2_CALIBRATION before
  29. cmd_preheat_6,
  30. };
  31. for (uint8_t i = 0; i < (sizeof(preheat_cmd)/sizeof(preheat_cmd[0])); ++i)
  32. {
  33. if (5 == i) enquecommand_P(_T(MSG_M117_V2_CALIBRATION));
  34. enquecommand_P(static_cast<char*>(pgm_read_ptr(&preheat_cmd[i])));
  35. }
  36. }
  37. //! @brief Load filament
  38. //! @param cmd_buffer character buffer needed to format gcodes
  39. //! @param filament filament to use (applies for MMU only)
  40. void lay1cal_load_filament(char *cmd_buffer, uint8_t filament)
  41. {
  42. if (mmu_enabled)
  43. {
  44. enquecommand_P(PSTR("M83"));
  45. enquecommand_P(PSTR("G1 Y-3.0 F1000.0"));
  46. enquecommand_P(PSTR("G1 Z0.4 F1000.0"));
  47. sprintf_P(cmd_buffer, PSTR("T%d"), filament);
  48. enquecommand(cmd_buffer);
  49. }
  50. }
  51. //! @brief Print intro line
  52. void lay1cal_intro_line()
  53. {
  54. static const char cmd_intro_mmu_3[] PROGMEM = "G1 X55.0 E32.0 F1073.0";
  55. static const char cmd_intro_mmu_4[] PROGMEM = "G1 X5.0 E32.0 F1800.0";
  56. static const char cmd_intro_mmu_5[] PROGMEM = "G1 X55.0 E8.0 F2000.0";
  57. static const char cmd_intro_mmu_6[] PROGMEM = "G1 Z0.3 F1000.0";
  58. static const char cmd_intro_mmu_7[] PROGMEM = "G92 E0.0";
  59. static const char cmd_intro_mmu_8[] PROGMEM = "G1 X240.0 E25.0 F2200.0";
  60. static const char cmd_intro_mmu_9[] PROGMEM = "G1 Y-2.0 F1000.0";
  61. static const char cmd_intro_mmu_10[] PROGMEM = "G1 X55.0 E25 F1400.0";
  62. static const char cmd_intro_mmu_11[] PROGMEM = "G1 Z0.20 F1000.0";
  63. static const char cmd_intro_mmu_12[] PROGMEM = "G1 X5.0 E4.0 F1000.0";
  64. static const char * const intro_mmu_cmd[] PROGMEM =
  65. {
  66. cmd_intro_mmu_3,
  67. cmd_intro_mmu_4,
  68. cmd_intro_mmu_5,
  69. cmd_intro_mmu_6,
  70. cmd_intro_mmu_7,
  71. cmd_intro_mmu_8,
  72. cmd_intro_mmu_9,
  73. cmd_intro_mmu_10,
  74. cmd_intro_mmu_11,
  75. cmd_intro_mmu_12,
  76. };
  77. if (mmu_enabled)
  78. {
  79. for (uint8_t i = 0; i < (sizeof(intro_mmu_cmd)/sizeof(intro_mmu_cmd[0])); ++i)
  80. {
  81. enquecommand_P(static_cast<char*>(pgm_read_ptr(&intro_mmu_cmd[i])));
  82. }
  83. }
  84. else
  85. {
  86. enquecommand_P(PSTR("G1 X60.0 E9.0 F1000.0"));
  87. enquecommand_P(PSTR("G1 X100.0 E12.5 F1000.0"));
  88. }
  89. }
  90. //! @brief Setup for printing meander
  91. void lay1cal_before_meander()
  92. {
  93. static const char cmd_pre_meander_0[] PROGMEM = "G92 E0.0";
  94. static const char cmd_pre_meander_1[] PROGMEM = "G21"; //set units to millimeters TODO unsupported command
  95. static const char cmd_pre_meander_2[] PROGMEM = "G90"; //use absolute coordinates
  96. static const char cmd_pre_meander_3[] PROGMEM = "M83"; //use relative distances for extrusion TODO: duplicate
  97. static const char cmd_pre_meander_4[] PROGMEM = "G1 E-1.50000 F2100.00000";
  98. static const char cmd_pre_meander_5[] PROGMEM = "G1 Z5 F7200.000";
  99. static const char cmd_pre_meander_6[] PROGMEM = "M204 S1000"; //set acceleration
  100. static const char cmd_pre_meander_7[] PROGMEM = "G1 F4000";
  101. static const char * const cmd_pre_meander[] PROGMEM =
  102. {
  103. cmd_pre_meander_0,
  104. cmd_pre_meander_1,
  105. cmd_pre_meander_2,
  106. cmd_pre_meander_3,
  107. cmd_pre_meander_4,
  108. cmd_pre_meander_5,
  109. cmd_pre_meander_6,
  110. cmd_pre_meander_7,
  111. };
  112. for (uint8_t i = 0; i < (sizeof(cmd_pre_meander)/sizeof(cmd_pre_meander[0])); ++i)
  113. {
  114. enquecommand_P(static_cast<char*>(pgm_read_ptr(&cmd_pre_meander[i])));
  115. }
  116. }
  117. //! @brief Count extrude length
  118. //!
  119. //! @param layer_height layer height in mm
  120. //! @param extrusion_width extrusion width in mm
  121. //! @param extrusion_length extrusion length in mm
  122. //! @return filament length in mm which needs to be extruded to form line
  123. static constexpr float count_e(float layer_height, float extrusion_width, float extrusion_length)
  124. {
  125. return (extrusion_length * layer_height * extrusion_width / (M_PI * pow(1.75, 2) / 4));
  126. }
  127. static const float width = 0.4; //!< line width
  128. static const float length = 20 - width; //!< line length
  129. static const float height = 0.2; //!< layer height TODO This is wrong, as current Z height is 0.15 mm
  130. static const float extr = count_e(height, width, length); //!< E axis movement needed to print line
  131. //! @brief Print meander
  132. //! @param cmd_buffer character buffer needed to format gcodes
  133. void lay1cal_meander(char *cmd_buffer)
  134. {
  135. static const char cmd_meander_0[] PROGMEM = "G1 X50 Y155";
  136. static const char cmd_meander_1[] PROGMEM = "G1 Z0.150 F7200.000";
  137. static const char cmd_meander_2[] PROGMEM = "G1 F1080";
  138. static const char cmd_meander_3[] PROGMEM = "G1 X75 Y155 E2.5";
  139. static const char cmd_meander_4[] PROGMEM = "G1 X100 Y155 E2";
  140. static const char cmd_meander_5[] PROGMEM = "G1 X200 Y155 E2.62773";
  141. static const char cmd_meander_6[] PROGMEM = "G1 X200 Y135 E0.66174";
  142. static const char cmd_meander_7[] PROGMEM = "G1 X50 Y135 E3.62773";
  143. static const char cmd_meander_8[] PROGMEM = "G1 X50 Y115 E0.49386";
  144. static const char cmd_meander_9[] PROGMEM = "G1 X200 Y115 E3.62773";
  145. static const char cmd_meander_10[] PROGMEM = "G1 X200 Y95 E0.49386";
  146. static const char cmd_meander_11[] PROGMEM = "G1 X50 Y95 E3.62773";
  147. static const char cmd_meander_12[] PROGMEM = "G1 X50 Y75 E0.49386";
  148. static const char cmd_meander_13[] PROGMEM = "G1 X200 Y75 E3.62773";
  149. static const char cmd_meander_14[] PROGMEM = "G1 X200 Y55 E0.49386";
  150. static const char cmd_meander_15[] PROGMEM = "G1 X50 Y55 E3.62773";
  151. static const char * const cmd_meander[] PROGMEM =
  152. {
  153. cmd_meander_0,
  154. cmd_meander_1,
  155. cmd_meander_2,
  156. cmd_meander_3,
  157. cmd_meander_4,
  158. cmd_meander_5,
  159. cmd_meander_6,
  160. cmd_meander_7,
  161. cmd_meander_8,
  162. cmd_meander_9,
  163. cmd_meander_10,
  164. cmd_meander_11,
  165. cmd_meander_12,
  166. cmd_meander_13,
  167. cmd_meander_14,
  168. cmd_meander_15,
  169. };
  170. for (uint8_t i = 0; i < (sizeof(cmd_meander)/sizeof(cmd_meander[0])); ++i)
  171. {
  172. enquecommand_P(static_cast<char*>(pgm_read_ptr(&cmd_meander[i])));
  173. }
  174. sprintf_P(cmd_buffer, PSTR("G1 X50 Y35 E%-.3f"), extr);
  175. enquecommand(cmd_buffer);
  176. }
  177. //! @brief Print square
  178. //!
  179. //! This function needs to be called 16 times for i from 0 to 15.
  180. //!
  181. //! @param cmd_buffer character buffer needed to format gcodes
  182. //! @param i iteration
  183. void lay1cal_square(char *cmd_buffer, uint8_t i)
  184. {
  185. const float extr_short_segment = count_e(height, width, width);
  186. static const char fmt1[] PROGMEM = "G1 X%d Y%-.2f E%-.3f";
  187. static const char fmt2[] PROGMEM = "G1 Y%-.2f E%-.3f";
  188. sprintf_P(cmd_buffer, fmt1, 70, (35 - i*width * 2), extr);
  189. enquecommand(cmd_buffer);
  190. sprintf_P(cmd_buffer, fmt2, (35 - (2 * i + 1)*width), extr_short_segment);
  191. enquecommand(cmd_buffer);
  192. sprintf_P(cmd_buffer, fmt1, 50, (35 - (2 * i + 1)*width), extr);
  193. enquecommand(cmd_buffer);
  194. sprintf_P(cmd_buffer, fmt2, (35 - (i + 1)*width * 2), extr_short_segment);
  195. enquecommand(cmd_buffer);
  196. }