My Marlin configs for Fabrikator Mini and CTC i3 Pro B
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

motion.h 12KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368
  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. /**
  23. * motion.h
  24. *
  25. * High-level motion commands to feed the planner
  26. * Some of these methods may migrate to the planner class.
  27. */
  28. #ifndef MOTION_H
  29. #define MOTION_H
  30. #include "../inc/MarlinConfig.h"
  31. #if IS_SCARA
  32. #include "../module/scara.h"
  33. #endif
  34. // Error margin to work around float imprecision
  35. constexpr float slop = 0.0001;
  36. extern bool relative_mode;
  37. extern float current_position[XYZE], // High-level current tool position
  38. destination[XYZE]; // Destination for a move
  39. // Scratch space for a cartesian result
  40. extern float cartes[XYZ];
  41. // Until kinematics.cpp is created, declare this here
  42. #if IS_KINEMATIC
  43. extern float delta[ABC];
  44. #endif
  45. #if OLDSCHOOL_ABL
  46. extern float xy_probe_feedrate_mm_s;
  47. #define XY_PROBE_FEEDRATE_MM_S xy_probe_feedrate_mm_s
  48. #elif defined(XY_PROBE_SPEED)
  49. #define XY_PROBE_FEEDRATE_MM_S MMM_TO_MMS(XY_PROBE_SPEED)
  50. #else
  51. #define XY_PROBE_FEEDRATE_MM_S PLANNER_XY_FEEDRATE()
  52. #endif
  53. /**
  54. * Feed rates are often configured with mm/m
  55. * but the planner and stepper like mm/s units.
  56. */
  57. extern const float homing_feedrate_mm_s[4];
  58. FORCE_INLINE float homing_feedrate(const AxisEnum a) { return pgm_read_float(&homing_feedrate_mm_s[a]); }
  59. extern float feedrate_mm_s;
  60. /**
  61. * Feedrate scaling and conversion
  62. */
  63. extern int16_t feedrate_percentage;
  64. #define MMS_SCALED(MM_S) ((MM_S)*feedrate_percentage*0.01f)
  65. extern uint8_t active_extruder;
  66. #if HAS_HOTEND_OFFSET
  67. extern float hotend_offset[XYZ][HOTENDS];
  68. #endif
  69. extern float soft_endstop_min[XYZ], soft_endstop_max[XYZ];
  70. FORCE_INLINE float pgm_read_any(const float *p) { return pgm_read_float_near(p); }
  71. FORCE_INLINE signed char pgm_read_any(const signed char *p) { return pgm_read_byte_near(p); }
  72. #define XYZ_DEFS(type, array, CONFIG) \
  73. extern const type array##_P[XYZ]; \
  74. FORCE_INLINE type array(AxisEnum axis) { return pgm_read_any(&array##_P[axis]); } \
  75. typedef void __void_##CONFIG##__
  76. XYZ_DEFS(float, base_min_pos, MIN_POS);
  77. XYZ_DEFS(float, base_max_pos, MAX_POS);
  78. XYZ_DEFS(float, base_home_pos, HOME_POS);
  79. XYZ_DEFS(float, max_length, MAX_LENGTH);
  80. XYZ_DEFS(float, home_bump_mm, HOME_BUMP_MM);
  81. XYZ_DEFS(signed char, home_dir, HOME_DIR);
  82. #if HAS_SOFTWARE_ENDSTOPS
  83. extern bool soft_endstops_enabled;
  84. void clamp_to_software_endstops(float target[XYZ]);
  85. #else
  86. #define soft_endstops_enabled false
  87. #define clamp_to_software_endstops(x) NOOP
  88. #endif
  89. void report_current_position();
  90. inline void set_current_from_destination() { COPY(current_position, destination); }
  91. inline void set_destination_from_current() { COPY(destination, current_position); }
  92. void get_cartesian_from_steppers();
  93. void set_current_from_steppers_for_axis(const AxisEnum axis);
  94. /**
  95. * sync_plan_position
  96. *
  97. * Set the planner/stepper positions directly from current_position with
  98. * no kinematic translation. Used for homing axes and cartesian/core syncing.
  99. */
  100. void sync_plan_position();
  101. void sync_plan_position_e();
  102. #if IS_KINEMATIC
  103. void sync_plan_position_kinematic();
  104. #define SYNC_PLAN_POSITION_KINEMATIC() sync_plan_position_kinematic()
  105. #else
  106. #define SYNC_PLAN_POSITION_KINEMATIC() sync_plan_position()
  107. #endif
  108. /**
  109. * Move the planner to the current position from wherever it last moved
  110. * (or from wherever it has been told it is located).
  111. */
  112. void line_to_current_position();
  113. /**
  114. * Move the planner to the position stored in the destination array, which is
  115. * used by G0/G1/G2/G3/G5 and many other functions to set a destination.
  116. */
  117. void buffer_line_to_destination(const float fr_mm_s);
  118. #if IS_KINEMATIC
  119. void prepare_uninterpolated_move_to_destination(const float fr_mm_s=0);
  120. #endif
  121. void prepare_move_to_destination();
  122. /**
  123. * Blocking movement and shorthand functions
  124. */
  125. void do_blocking_move_to(const float rx, const float ry, const float rz, const float &fr_mm_s=0);
  126. void do_blocking_move_to_x(const float &rx, const float &fr_mm_s=0);
  127. void do_blocking_move_to_z(const float &rz, const float &fr_mm_s=0);
  128. void do_blocking_move_to_xy(const float &rx, const float &ry, const float &fr_mm_s=0);
  129. void setup_for_endstop_or_probe_move();
  130. void clean_up_after_endstop_or_probe_move();
  131. void bracket_probe_move(const bool before);
  132. void setup_for_endstop_or_probe_move();
  133. void clean_up_after_endstop_or_probe_move();
  134. //
  135. // Homing
  136. //
  137. #define HAS_AXIS_UNHOMED_ERR ( \
  138. ENABLED(Z_PROBE_ALLEN_KEY) \
  139. || ENABLED(Z_PROBE_SLED) \
  140. || HAS_PROBING_PROCEDURE \
  141. || HOTENDS > 1 \
  142. || ENABLED(NOZZLE_CLEAN_FEATURE) \
  143. || ENABLED(NOZZLE_PARK_FEATURE) \
  144. || (ENABLED(ADVANCED_PAUSE_FEATURE) && ENABLED(HOME_BEFORE_FILAMENT_CHANGE)) \
  145. || HAS_M206_COMMAND \
  146. ) || ENABLED(NO_MOTION_BEFORE_HOMING)
  147. #if HAS_AXIS_UNHOMED_ERR
  148. bool axis_unhomed_error(const bool x=true, const bool y=true, const bool z=true);
  149. #endif
  150. #if ENABLED(NO_MOTION_BEFORE_HOMING)
  151. #define MOTION_CONDITIONS (IsRunning() && !axis_unhomed_error())
  152. #else
  153. #define MOTION_CONDITIONS IsRunning()
  154. #endif
  155. void set_axis_is_at_home(const AxisEnum axis);
  156. void homeaxis(const AxisEnum axis);
  157. #if ENABLED(SENSORLESS_HOMING)
  158. void sensorless_homing_per_axis(const AxisEnum axis, const bool enable=true);
  159. #endif
  160. //
  161. // Macros
  162. //
  163. /**
  164. * Workspace offsets
  165. */
  166. #if HAS_WORKSPACE_OFFSET
  167. #if HAS_HOME_OFFSET
  168. extern float home_offset[XYZ];
  169. #endif
  170. #if HAS_POSITION_SHIFT
  171. extern float position_shift[XYZ];
  172. #endif
  173. #if HAS_HOME_OFFSET && HAS_POSITION_SHIFT
  174. extern float workspace_offset[XYZ];
  175. #define WORKSPACE_OFFSET(AXIS) workspace_offset[AXIS]
  176. #elif HAS_HOME_OFFSET
  177. #define WORKSPACE_OFFSET(AXIS) home_offset[AXIS]
  178. #elif HAS_POSITION_SHIFT
  179. #define WORKSPACE_OFFSET(AXIS) position_shift[AXIS]
  180. #endif
  181. #define NATIVE_TO_LOGICAL(POS, AXIS) ((POS) + WORKSPACE_OFFSET(AXIS))
  182. #define LOGICAL_TO_NATIVE(POS, AXIS) ((POS) - WORKSPACE_OFFSET(AXIS))
  183. #else
  184. #define NATIVE_TO_LOGICAL(POS, AXIS) (POS)
  185. #define LOGICAL_TO_NATIVE(POS, AXIS) (POS)
  186. #endif
  187. #define LOGICAL_X_POSITION(POS) NATIVE_TO_LOGICAL(POS, X_AXIS)
  188. #define LOGICAL_Y_POSITION(POS) NATIVE_TO_LOGICAL(POS, Y_AXIS)
  189. #define LOGICAL_Z_POSITION(POS) NATIVE_TO_LOGICAL(POS, Z_AXIS)
  190. #define RAW_X_POSITION(POS) LOGICAL_TO_NATIVE(POS, X_AXIS)
  191. #define RAW_Y_POSITION(POS) LOGICAL_TO_NATIVE(POS, Y_AXIS)
  192. #define RAW_Z_POSITION(POS) LOGICAL_TO_NATIVE(POS, Z_AXIS)
  193. /**
  194. * position_is_reachable family of functions
  195. */
  196. #if IS_KINEMATIC // (DELTA or SCARA)
  197. #if IS_SCARA
  198. extern const float L1, L2;
  199. #endif
  200. // Return true if the given point is within the printable area
  201. inline bool position_is_reachable(const float &rx, const float &ry, const float inset=0) {
  202. #if ENABLED(DELTA)
  203. return HYPOT2(rx, ry) <= sq(DELTA_PRINTABLE_RADIUS - inset);
  204. #elif IS_SCARA
  205. const float R2 = HYPOT2(rx - SCARA_OFFSET_X, ry - SCARA_OFFSET_Y);
  206. return (
  207. R2 <= sq(L1 + L2) - inset
  208. #if MIDDLE_DEAD_ZONE_R > 0
  209. && R2 >= sq(float(MIDDLE_DEAD_ZONE_R))
  210. #endif
  211. );
  212. #endif
  213. }
  214. #if HAS_BED_PROBE
  215. // Return true if the both nozzle and the probe can reach the given point.
  216. // Note: This won't work on SCARA since the probe offset rotates with the arm.
  217. inline bool position_is_reachable_by_probe(const float &rx, const float &ry) {
  218. return position_is_reachable(rx - (X_PROBE_OFFSET_FROM_EXTRUDER), ry - (Y_PROBE_OFFSET_FROM_EXTRUDER))
  219. && position_is_reachable(rx, ry, ABS(MIN_PROBE_EDGE));
  220. }
  221. #endif
  222. #else // CARTESIAN
  223. // Return true if the given position is within the machine bounds.
  224. inline bool position_is_reachable(const float &rx, const float &ry) {
  225. if (!WITHIN(ry, Y_MIN_POS - slop, Y_MAX_POS + slop)) return false;
  226. #if ENABLED(DUAL_X_CARRIAGE)
  227. if (active_extruder)
  228. return WITHIN(rx, X2_MIN_POS - slop, X2_MAX_POS + slop);
  229. else
  230. return WITHIN(rx, X1_MIN_POS - slop, X1_MAX_POS + slop);
  231. #else
  232. return WITHIN(rx, X_MIN_POS - slop, X_MAX_POS + slop);
  233. #endif
  234. }
  235. #if HAS_BED_PROBE
  236. /**
  237. * Return whether the given position is within the bed, and whether the nozzle
  238. * can reach the position required to put the probe at the given position.
  239. *
  240. * Example: For a probe offset of -10,+10, then for the probe to reach 0,0 the
  241. * nozzle must be be able to reach +10,-10.
  242. */
  243. inline bool position_is_reachable_by_probe(const float &rx, const float &ry) {
  244. return position_is_reachable(rx - (X_PROBE_OFFSET_FROM_EXTRUDER), ry - (Y_PROBE_OFFSET_FROM_EXTRUDER))
  245. && WITHIN(rx, MIN_PROBE_X - slop, MAX_PROBE_X + slop)
  246. && WITHIN(ry, MIN_PROBE_Y - slop, MAX_PROBE_Y + slop);
  247. }
  248. #endif
  249. #endif // CARTESIAN
  250. #if !HAS_BED_PROBE
  251. FORCE_INLINE bool position_is_reachable_by_probe(const float &rx, const float &ry) { return position_is_reachable(rx, ry); }
  252. #endif
  253. /**
  254. * Dual X Carriage / Dual Nozzle
  255. */
  256. #if ENABLED(DUAL_X_CARRIAGE) || ENABLED(DUAL_NOZZLE_DUPLICATION_MODE)
  257. extern bool extruder_duplication_enabled; // Used in Dual X mode 2
  258. extern bool symmetric_duplication_mode; // Used in Dual X mode 2
  259. #endif
  260. /**
  261. * Dual X Carriage
  262. */
  263. #if ENABLED(DUAL_X_CARRIAGE)
  264. enum DualXMode : char {
  265. DXC_FULL_CONTROL_MODE, // DUAL_X_CARRIAGE only
  266. DXC_AUTO_PARK_MODE, // DUAL_X_CARRIAGE only
  267. DXC_DUPLICATION_MODE,
  268. };
  269. extern DualXMode dual_x_carriage_mode;
  270. extern float inactive_extruder_x_pos, // used in mode 0 & 1
  271. raised_parked_position[XYZE], // used in mode 1
  272. duplicate_extruder_x_offset; // used in mode 2 & 3
  273. extern bool active_extruder_parked; // used in mode 1, 2 & 3
  274. extern millis_t delayed_move_time; // used in mode 1
  275. extern int16_t duplicate_extruder_temp_offset; // used in mode 2 & 3
  276. float x_home_pos(const int extruder);
  277. FORCE_INLINE int x_home_dir(const uint8_t extruder) { return extruder ? X2_HOME_DIR : X_HOME_DIR; }
  278. #elif ENABLED(DUAL_NOZZLE_DUPLICATION_MODE)
  279. enum DualXMode : char {
  280. DXC_DUPLICATION_MODE = 2
  281. };
  282. #endif
  283. #if HAS_WORKSPACE_OFFSET || ENABLED(DUAL_X_CARRIAGE) || ENABLED(DELTA)
  284. void update_software_endstops(const AxisEnum axis);
  285. #endif
  286. #if HAS_M206_COMMAND
  287. void set_home_offset(const AxisEnum axis, const float v);
  288. #endif
  289. #if ENABLED(AUTO_BED_LEVELING_BILINEAR)
  290. #if ENABLED(DELTA)
  291. #define ADJUST_DELTA(V) \
  292. if (planner.leveling_active) { \
  293. const float zadj = bilinear_z_offset(V); \
  294. delta[A_AXIS] += zadj; \
  295. delta[B_AXIS] += zadj; \
  296. delta[C_AXIS] += zadj; \
  297. }
  298. #else
  299. #define ADJUST_DELTA(V) if (planner.leveling_active) { delta[Z_AXIS] += bilinear_z_offset(V); }
  300. #endif
  301. #else
  302. #define ADJUST_DELTA(V) NOOP
  303. #endif
  304. #endif // MOTION_H