My Marlin configs for Fabrikator Mini and CTC i3 Pro B
Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329
  1. /**
  2. * Marlin 3D Printer Firmware
  3. * Copyright (C) 2016 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. #ifndef __MARLIN_H__
  23. #define __MARLIN_H__
  24. #include <math.h>
  25. #include <stdio.h>
  26. #include <stdlib.h>
  27. #include "inc/MarlinConfig.h"
  28. #ifdef DEBUG_GCODE_PARSER
  29. #include "gcode/parser.h"
  30. #endif
  31. #if ENABLED(PRINTCOUNTER)
  32. #include "module/printcounter.h"
  33. #else
  34. #include "libs/stopwatch.h"
  35. #endif
  36. void stop();
  37. void idle(
  38. #if ENABLED(ADVANCED_PAUSE_FEATURE)
  39. bool no_stepper_sleep = false // pass true to keep steppers from disabling on timeout
  40. #endif
  41. );
  42. void manage_inactivity(bool ignore_stepper_queue = false);
  43. #if ENABLED(DUAL_X_CARRIAGE) || ENABLED(DUAL_NOZZLE_DUPLICATION_MODE)
  44. extern bool extruder_duplication_enabled;
  45. #endif
  46. #if HAS_X2_ENABLE
  47. #define enable_X() do{ X_ENABLE_WRITE( X_ENABLE_ON); X2_ENABLE_WRITE( X_ENABLE_ON); }while(0)
  48. #define disable_X() do{ X_ENABLE_WRITE(!X_ENABLE_ON); X2_ENABLE_WRITE(!X_ENABLE_ON); axis_known_position[X_AXIS] = false; }while(0)
  49. #elif HAS_X_ENABLE
  50. #define enable_X() X_ENABLE_WRITE( X_ENABLE_ON)
  51. #define disable_X() do{ X_ENABLE_WRITE(!X_ENABLE_ON); axis_known_position[X_AXIS] = false; }while(0)
  52. #else
  53. #define enable_X() NOOP
  54. #define disable_X() NOOP
  55. #endif
  56. #if HAS_Y2_ENABLE
  57. #define enable_Y() do{ Y_ENABLE_WRITE( Y_ENABLE_ON); Y2_ENABLE_WRITE(Y_ENABLE_ON); }while(0)
  58. #define disable_Y() do{ Y_ENABLE_WRITE(!Y_ENABLE_ON); Y2_ENABLE_WRITE(!Y_ENABLE_ON); axis_known_position[Y_AXIS] = false; }while(0)
  59. #elif HAS_Y_ENABLE
  60. #define enable_Y() Y_ENABLE_WRITE( Y_ENABLE_ON)
  61. #define disable_Y() do{ Y_ENABLE_WRITE(!Y_ENABLE_ON); axis_known_position[Y_AXIS] = false; }while(0)
  62. #else
  63. #define enable_Y() NOOP
  64. #define disable_Y() NOOP
  65. #endif
  66. #if HAS_Z2_ENABLE
  67. #define enable_Z() do{ Z_ENABLE_WRITE( Z_ENABLE_ON); Z2_ENABLE_WRITE(Z_ENABLE_ON); }while(0)
  68. #define disable_Z() do{ Z_ENABLE_WRITE(!Z_ENABLE_ON); Z2_ENABLE_WRITE(!Z_ENABLE_ON); axis_known_position[Z_AXIS] = false; }while(0)
  69. #elif HAS_Z_ENABLE
  70. #define enable_Z() Z_ENABLE_WRITE( Z_ENABLE_ON)
  71. #define disable_Z() do{ Z_ENABLE_WRITE(!Z_ENABLE_ON); axis_known_position[Z_AXIS] = false; }while(0)
  72. #else
  73. #define enable_Z() NOOP
  74. #define disable_Z() NOOP
  75. #endif
  76. #if ENABLED(MIXING_EXTRUDER)
  77. /**
  78. * Mixing steppers synchronize their enable (and direction) together
  79. */
  80. #if MIXING_STEPPERS > 3
  81. #define enable_E0() { E0_ENABLE_WRITE( E_ENABLE_ON); E1_ENABLE_WRITE( E_ENABLE_ON); E2_ENABLE_WRITE( E_ENABLE_ON); E3_ENABLE_WRITE( E_ENABLE_ON); }
  82. #define disable_E0() { E0_ENABLE_WRITE(!E_ENABLE_ON); E1_ENABLE_WRITE(!E_ENABLE_ON); E2_ENABLE_WRITE(!E_ENABLE_ON); E3_ENABLE_WRITE(!E_ENABLE_ON); }
  83. #elif MIXING_STEPPERS > 2
  84. #define enable_E0() { E0_ENABLE_WRITE( E_ENABLE_ON); E1_ENABLE_WRITE( E_ENABLE_ON); E2_ENABLE_WRITE( E_ENABLE_ON); }
  85. #define disable_E0() { E0_ENABLE_WRITE(!E_ENABLE_ON); E1_ENABLE_WRITE(!E_ENABLE_ON); E2_ENABLE_WRITE(!E_ENABLE_ON); }
  86. #else
  87. #define enable_E0() { E0_ENABLE_WRITE( E_ENABLE_ON); E1_ENABLE_WRITE( E_ENABLE_ON); }
  88. #define disable_E0() { E0_ENABLE_WRITE(!E_ENABLE_ON); E1_ENABLE_WRITE(!E_ENABLE_ON); }
  89. #endif
  90. #define enable_E1() NOOP
  91. #define disable_E1() NOOP
  92. #define enable_E2() NOOP
  93. #define disable_E2() NOOP
  94. #define enable_E3() NOOP
  95. #define disable_E3() NOOP
  96. #define enable_E4() NOOP
  97. #define disable_E4() NOOP
  98. #else // !MIXING_EXTRUDER
  99. #if HAS_E0_ENABLE
  100. #define enable_E0() E0_ENABLE_WRITE( E_ENABLE_ON)
  101. #define disable_E0() E0_ENABLE_WRITE(!E_ENABLE_ON)
  102. #else
  103. #define enable_E0() NOOP
  104. #define disable_E0() NOOP
  105. #endif
  106. #if E_STEPPERS > 1 && HAS_E1_ENABLE
  107. #define enable_E1() E1_ENABLE_WRITE( E_ENABLE_ON)
  108. #define disable_E1() E1_ENABLE_WRITE(!E_ENABLE_ON)
  109. #else
  110. #define enable_E1() NOOP
  111. #define disable_E1() NOOP
  112. #endif
  113. #if E_STEPPERS > 2 && HAS_E2_ENABLE
  114. #define enable_E2() E2_ENABLE_WRITE( E_ENABLE_ON)
  115. #define disable_E2() E2_ENABLE_WRITE(!E_ENABLE_ON)
  116. #else
  117. #define enable_E2() NOOP
  118. #define disable_E2() NOOP
  119. #endif
  120. #if E_STEPPERS > 3 && HAS_E3_ENABLE
  121. #define enable_E3() E3_ENABLE_WRITE( E_ENABLE_ON)
  122. #define disable_E3() E3_ENABLE_WRITE(!E_ENABLE_ON)
  123. #else
  124. #define enable_E3() NOOP
  125. #define disable_E3() NOOP
  126. #endif
  127. #if E_STEPPERS > 4 && HAS_E4_ENABLE
  128. #define enable_E4() E4_ENABLE_WRITE( E_ENABLE_ON)
  129. #define disable_E4() E4_ENABLE_WRITE(!E_ENABLE_ON)
  130. #else
  131. #define enable_E4() NOOP
  132. #define disable_E4() NOOP
  133. #endif
  134. #endif // !MIXING_EXTRUDER
  135. #if ENABLED(G38_PROBE_TARGET)
  136. extern bool G38_move, // flag to tell the interrupt handler that a G38 command is being run
  137. G38_endstop_hit; // flag from the interrupt handler to indicate if the endstop went active
  138. #endif
  139. /**
  140. * The axis order in all axis related arrays is X, Y, Z, E
  141. */
  142. #define _AXIS(AXIS) AXIS ##_AXIS
  143. void enable_all_steppers();
  144. void disable_e_steppers();
  145. void disable_all_steppers();
  146. void kill(const char*);
  147. void quickstop_stepper();
  148. #if ENABLED(FILAMENT_RUNOUT_SENSOR)
  149. void handle_filament_runout();
  150. #endif
  151. extern bool Running;
  152. inline bool IsRunning() { return Running; }
  153. inline bool IsStopped() { return !Running; }
  154. /**
  155. * Feedrate scaling and conversion
  156. */
  157. extern int16_t feedrate_percentage;
  158. #define MMS_SCALED(MM_S) ((MM_S)*feedrate_percentage*0.01)
  159. extern bool volumetric_enabled;
  160. extern float filament_size[EXTRUDERS]; // cross-sectional area of filament (in millimeters), typically around 1.75 or 2.85, 0 disables the volumetric calculations for the extruder.
  161. extern float volumetric_multiplier[EXTRUDERS]; // reciprocal of cross-sectional area of filament (in square millimeters), stored this way to reduce computational burden in planner
  162. extern bool axis_known_position[XYZ];
  163. extern bool axis_homed[XYZ];
  164. extern volatile bool wait_for_heatup;
  165. #if HAS_RESUME_CONTINUE
  166. extern volatile bool wait_for_user;
  167. #endif
  168. // Hotend Offsets
  169. #if HOTENDS > 1
  170. extern float hotend_offset[XYZ][HOTENDS];
  171. #endif
  172. // Software Endstops
  173. extern float soft_endstop_min[XYZ], soft_endstop_max[XYZ];
  174. #if HAS_WORKSPACE_OFFSET || ENABLED(DUAL_X_CARRIAGE)
  175. void update_software_endstops(const AxisEnum axis);
  176. #endif
  177. #if IS_KINEMATIC
  178. extern float delta[ABC];
  179. void inverse_kinematics(const float logical[XYZ]);
  180. #endif
  181. #if ENABLED(DELTA)
  182. extern float endstop_adj[ABC],
  183. delta_radius,
  184. delta_diagonal_rod,
  185. delta_calibration_radius,
  186. delta_segments_per_second,
  187. delta_tower_angle_trim[2],
  188. delta_clip_start_height;
  189. void recalc_delta_settings(float radius, float diagonal_rod);
  190. #elif IS_SCARA
  191. void forward_kinematics_SCARA(const float &a, const float &b);
  192. #endif
  193. #if ENABLED(AUTO_BED_LEVELING_BILINEAR)
  194. extern int bilinear_grid_spacing[2], bilinear_start[2];
  195. extern float bilinear_grid_factor[2],
  196. z_values[GRID_MAX_POINTS_X][GRID_MAX_POINTS_Y];
  197. float bilinear_z_offset(const float logical[XYZ]);
  198. #endif
  199. #if ENABLED(AUTO_BED_LEVELING_UBL)
  200. typedef struct { double A, B, D; } linear_fit;
  201. linear_fit* lsf_linear_fit(double x[], double y[], double z[], const int);
  202. #endif
  203. #if HAS_LEVELING
  204. bool leveling_is_valid();
  205. bool leveling_is_active();
  206. void set_bed_leveling_enabled(const bool enable=true);
  207. void reset_bed_level();
  208. #endif
  209. #if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
  210. void set_z_fade_height(const float zfh);
  211. #endif
  212. #if ENABLED(Z_DUAL_ENDSTOPS)
  213. extern float z_endstop_adj;
  214. #endif
  215. #if HAS_BED_PROBE
  216. extern float zprobe_zoffset;
  217. void refresh_zprobe_zoffset(const bool no_babystep=false);
  218. #define DEPLOY_PROBE() set_probe_deployed(true)
  219. #define STOW_PROBE() set_probe_deployed(false)
  220. #else
  221. #define DEPLOY_PROBE()
  222. #define STOW_PROBE()
  223. #endif
  224. #if FAN_COUNT > 0
  225. extern int16_t fanSpeeds[FAN_COUNT];
  226. #if ENABLED(PROBING_FANS_OFF)
  227. extern bool fans_paused;
  228. extern int16_t paused_fanSpeeds[FAN_COUNT];
  229. #endif
  230. #endif
  231. #if ENABLED(BARICUDA)
  232. extern uint8_t baricuda_valve_pressure, baricuda_e_to_p_pressure;
  233. #endif
  234. #if ENABLED(FILAMENT_WIDTH_SENSOR)
  235. extern bool filament_sensor; // Flag that filament sensor readings should control extrusion
  236. extern float filament_width_nominal, // Theoretical filament diameter i.e., 3.00 or 1.75
  237. filament_width_meas; // Measured filament diameter
  238. extern uint8_t meas_delay_cm, // Delay distance
  239. measurement_delay[]; // Ring buffer to delay measurement
  240. extern int8_t filwidth_delay_index[2]; // Ring buffer indexes. Used by planner, temperature, and main code
  241. #endif
  242. #if ENABLED(ADVANCED_PAUSE_FEATURE)
  243. extern AdvancedPauseMenuResponse advanced_pause_menu_response;
  244. #endif
  245. #if ENABLED(PID_EXTRUSION_SCALING)
  246. extern int lpq_len;
  247. #endif
  248. // Print job timer
  249. #if ENABLED(PRINTCOUNTER)
  250. extern PrintCounter print_job_timer;
  251. #else
  252. extern Stopwatch print_job_timer;
  253. #endif
  254. #if HAS_TEMP_HOTEND || HAS_TEMP_BED
  255. void print_heaterstates();
  256. #endif
  257. #if ENABLED(MIXING_EXTRUDER)
  258. extern float mixing_factor[MIXING_STEPPERS];
  259. #if MIXING_VIRTUAL_TOOLS > 1
  260. extern float mixing_virtual_tool_mix[MIXING_VIRTUAL_TOOLS][MIXING_STEPPERS];
  261. #endif
  262. #endif
  263. void calculate_volumetric_multipliers();
  264. /**
  265. * Blocking movement and shorthand functions
  266. */
  267. void do_blocking_move_to(const float &x, const float &y, const float &z, const float &fr_mm_s=0.0);
  268. void do_blocking_move_to_x(const float &x, const float &fr_mm_s=0.0);
  269. void do_blocking_move_to_z(const float &z, const float &fr_mm_s=0.0);
  270. void do_blocking_move_to_xy(const float &x, const float &y, const float &fr_mm_s=0.0);
  271. #if ENABLED(Z_PROBE_ALLEN_KEY) || ENABLED(Z_PROBE_SLED) || HAS_PROBING_PROCEDURE || HOTENDS > 1 || ENABLED(NOZZLE_CLEAN_FEATURE) || ENABLED(NOZZLE_PARK_FEATURE)
  272. bool axis_unhomed_error(const bool x=true, const bool y=true, const bool z=true);
  273. #endif
  274. #endif // __MARLIN_H__