My Marlin configs for Fabrikator Mini and CTC i3 Pro B
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

motion.h 13KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386
  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. #pragma once
  23. /**
  24. * motion.h
  25. *
  26. * High-level motion commands to feed the planner
  27. * Some of these methods may migrate to the planner class.
  28. */
  29. #include "../inc/MarlinConfig.h"
  30. #if IS_SCARA
  31. #include "scara.h"
  32. #endif
  33. // Axis homed and known-position states
  34. extern uint8_t axis_homed, axis_known_position;
  35. constexpr uint8_t xyz_bits = _BV(X_AXIS) | _BV(Y_AXIS) | _BV(Z_AXIS);
  36. FORCE_INLINE bool no_axes_homed() { return !axis_homed; }
  37. FORCE_INLINE bool all_axes_homed() { return (axis_homed & xyz_bits) == xyz_bits; }
  38. FORCE_INLINE bool all_axes_known() { return (axis_known_position & xyz_bits) == xyz_bits; }
  39. FORCE_INLINE void set_all_unhomed() { axis_homed = 0; }
  40. FORCE_INLINE void set_all_unknown() { axis_known_position = 0; }
  41. FORCE_INLINE bool homing_needed() {
  42. return !(
  43. #if ENABLED(HOME_AFTER_DEACTIVATE)
  44. all_axes_known()
  45. #else
  46. all_axes_homed()
  47. #endif
  48. );
  49. }
  50. // Error margin to work around float imprecision
  51. constexpr float fslop = 0.0001;
  52. extern bool relative_mode;
  53. extern xyze_pos_t current_position, // High-level current tool position
  54. destination; // Destination for a move
  55. // G60/G61 Position Save and Return
  56. #if SAVED_POSITIONS
  57. extern uint8_t saved_slots[(SAVED_POSITIONS + 7) >> 3];
  58. extern xyz_pos_t stored_position[SAVED_POSITIONS];
  59. #endif
  60. // Scratch space for a cartesian result
  61. extern xyz_pos_t cartes;
  62. // Until kinematics.cpp is created, declare this here
  63. #if IS_KINEMATIC
  64. extern abc_pos_t delta;
  65. #endif
  66. #if HAS_ABL_NOT_UBL
  67. extern float xy_probe_feedrate_mm_s;
  68. #define XY_PROBE_FEEDRATE_MM_S xy_probe_feedrate_mm_s
  69. #elif defined(XY_PROBE_SPEED)
  70. #define XY_PROBE_FEEDRATE_MM_S MMM_TO_MMS(XY_PROBE_SPEED)
  71. #else
  72. #define XY_PROBE_FEEDRATE_MM_S PLANNER_XY_FEEDRATE()
  73. #endif
  74. #if ENABLED(Z_SAFE_HOMING)
  75. constexpr xy_float_t safe_homing_xy = { Z_SAFE_HOMING_X_POINT, Z_SAFE_HOMING_Y_POINT };
  76. #endif
  77. /**
  78. * Feed rates are often configured with mm/m
  79. * but the planner and stepper like mm/s units.
  80. */
  81. extern const feedRate_t homing_feedrate_mm_s[XYZ];
  82. FORCE_INLINE feedRate_t homing_feedrate(const AxisEnum a) { return pgm_read_float(&homing_feedrate_mm_s[a]); }
  83. feedRate_t get_homing_bump_feedrate(const AxisEnum axis);
  84. extern feedRate_t feedrate_mm_s;
  85. /**
  86. * Feedrate scaling
  87. */
  88. extern int16_t feedrate_percentage;
  89. // The active extruder (tool). Set with T<extruder> command.
  90. #if EXTRUDERS > 1
  91. extern uint8_t active_extruder;
  92. #else
  93. constexpr uint8_t active_extruder = 0;
  94. #endif
  95. #if ENABLED(LCD_SHOW_E_TOTAL)
  96. extern float e_move_accumulator;
  97. #endif
  98. FORCE_INLINE float pgm_read_any(const float *p) { return pgm_read_float(p); }
  99. FORCE_INLINE signed char pgm_read_any(const signed char *p) { return pgm_read_byte(p); }
  100. #define XYZ_DEFS(T, NAME, OPT) \
  101. extern const XYZval<T> NAME##_P; \
  102. FORCE_INLINE T NAME(AxisEnum axis) { return pgm_read_any(&NAME##_P[axis]); }
  103. XYZ_DEFS(float, base_min_pos, MIN_POS);
  104. XYZ_DEFS(float, base_max_pos, MAX_POS);
  105. XYZ_DEFS(float, base_home_pos, HOME_POS);
  106. XYZ_DEFS(float, max_length, MAX_LENGTH);
  107. XYZ_DEFS(float, home_bump_mm, HOME_BUMP_MM);
  108. XYZ_DEFS(signed char, home_dir, HOME_DIR);
  109. #if HAS_WORKSPACE_OFFSET
  110. void update_workspace_offset(const AxisEnum axis);
  111. #else
  112. #define update_workspace_offset(x) NOOP
  113. #endif
  114. #if HAS_HOTEND_OFFSET
  115. extern xyz_pos_t hotend_offset[HOTENDS];
  116. void reset_hotend_offsets();
  117. #elif HOTENDS
  118. constexpr xyz_pos_t hotend_offset[HOTENDS] = { { 0 } };
  119. #else
  120. constexpr xyz_pos_t hotend_offset[1] = { { 0 } };
  121. #endif
  122. typedef struct { xyz_pos_t min, max; } axis_limits_t;
  123. #if HAS_SOFTWARE_ENDSTOPS
  124. extern bool soft_endstops_enabled;
  125. extern axis_limits_t soft_endstop;
  126. void apply_motion_limits(xyz_pos_t &target);
  127. void update_software_endstops(const AxisEnum axis
  128. #if HAS_HOTEND_OFFSET
  129. , const uint8_t old_tool_index=0, const uint8_t new_tool_index=0
  130. #endif
  131. );
  132. #else
  133. constexpr bool soft_endstops_enabled = false;
  134. //constexpr axis_limits_t soft_endstop = {
  135. // { X_MIN_POS, Y_MIN_POS, Z_MIN_POS },
  136. // { X_MAX_POS, Y_MAX_POS, Z_MAX_POS } };
  137. #define apply_motion_limits(V) NOOP
  138. #define update_software_endstops(...) NOOP
  139. #endif
  140. void report_current_position();
  141. void get_cartesian_from_steppers();
  142. void set_current_from_steppers_for_axis(const AxisEnum axis);
  143. /**
  144. * sync_plan_position
  145. *
  146. * Set the planner/stepper positions directly from current_position with
  147. * no kinematic translation. Used for homing axes and cartesian/core syncing.
  148. */
  149. void sync_plan_position();
  150. void sync_plan_position_e();
  151. /**
  152. * Move the planner to the current position from wherever it last moved
  153. * (or from wherever it has been told it is located).
  154. */
  155. void line_to_current_position(const feedRate_t &fr_mm_s=feedrate_mm_s);
  156. void prepare_move_to_destination();
  157. void _internal_move_to_destination(const feedRate_t &fr_mm_s=0.0f
  158. #if IS_KINEMATIC
  159. , const bool is_fast=false
  160. #endif
  161. );
  162. inline void prepare_internal_move_to_destination(const feedRate_t &fr_mm_s=0.0f) {
  163. _internal_move_to_destination(fr_mm_s);
  164. }
  165. #if IS_KINEMATIC
  166. void prepare_fast_move_to_destination(const feedRate_t &scaled_fr_mm_s=MMS_SCALED(feedrate_mm_s));
  167. inline void prepare_internal_fast_move_to_destination(const feedRate_t &fr_mm_s=0.0f) {
  168. _internal_move_to_destination(fr_mm_s, true);
  169. }
  170. #endif
  171. /**
  172. * Blocking movement and shorthand functions
  173. */
  174. void do_blocking_move_to(const float rx, const float ry, const float rz, const feedRate_t &fr_mm_s=0.0f);
  175. void do_blocking_move_to(const xy_pos_t &raw, const feedRate_t &fr_mm_s=0.0f);
  176. void do_blocking_move_to(const xyz_pos_t &raw, const feedRate_t &fr_mm_s=0.0f);
  177. void do_blocking_move_to(const xyze_pos_t &raw, const feedRate_t &fr_mm_s=0.0f);
  178. void do_blocking_move_to_x(const float &rx, const feedRate_t &fr_mm_s=0.0f);
  179. void do_blocking_move_to_y(const float &ry, const feedRate_t &fr_mm_s=0.0f);
  180. void do_blocking_move_to_z(const float &rz, const feedRate_t &fr_mm_s=0.0f);
  181. void do_blocking_move_to_xy(const float &rx, const float &ry, const feedRate_t &fr_mm_s=0.0f);
  182. void do_blocking_move_to_xy(const xy_pos_t &raw, const feedRate_t &fr_mm_s=0.0f);
  183. FORCE_INLINE void do_blocking_move_to_xy(const xyz_pos_t &raw, const feedRate_t &fr_mm_s=0.0f) { do_blocking_move_to_xy(xy_pos_t(raw), fr_mm_s); }
  184. FORCE_INLINE void do_blocking_move_to_xy(const xyze_pos_t &raw, const feedRate_t &fr_mm_s=0.0f) { do_blocking_move_to_xy(xy_pos_t(raw), fr_mm_s); }
  185. void do_blocking_move_to_xy_z(const xy_pos_t &raw, const float &z, const feedRate_t &fr_mm_s=0.0f);
  186. FORCE_INLINE void do_blocking_move_to_xy_z(const xyz_pos_t &raw, const float &z, const feedRate_t &fr_mm_s=0.0f) { do_blocking_move_to_xy_z(xy_pos_t(raw), z, fr_mm_s); }
  187. FORCE_INLINE void do_blocking_move_to_xy_z(const xyze_pos_t &raw, const float &z, const feedRate_t &fr_mm_s=0.0f) { do_blocking_move_to_xy_z(xy_pos_t(raw), z, fr_mm_s); }
  188. void remember_feedrate_and_scaling();
  189. void remember_feedrate_scaling_off();
  190. void restore_feedrate_and_scaling();
  191. //
  192. // Homing
  193. //
  194. uint8_t axes_need_homing(uint8_t axis_bits=0x07);
  195. bool axis_unhomed_error(uint8_t axis_bits=0x07);
  196. #if ENABLED(NO_MOTION_BEFORE_HOMING)
  197. #define MOTION_CONDITIONS (IsRunning() && !axis_unhomed_error())
  198. #else
  199. #define MOTION_CONDITIONS IsRunning()
  200. #endif
  201. void set_axis_is_at_home(const AxisEnum axis);
  202. void set_axis_is_not_at_home(const AxisEnum axis);
  203. void homeaxis(const AxisEnum axis);
  204. /**
  205. * Workspace offsets
  206. */
  207. #if HAS_HOME_OFFSET || HAS_POSITION_SHIFT
  208. #if HAS_HOME_OFFSET
  209. extern xyz_pos_t home_offset;
  210. #endif
  211. #if HAS_POSITION_SHIFT
  212. extern xyz_pos_t position_shift;
  213. #endif
  214. #if HAS_HOME_OFFSET && HAS_POSITION_SHIFT
  215. extern xyz_pos_t workspace_offset;
  216. #define _WS workspace_offset
  217. #elif HAS_HOME_OFFSET
  218. #define _WS home_offset
  219. #else
  220. #define _WS position_shift
  221. #endif
  222. #define NATIVE_TO_LOGICAL(POS, AXIS) ((POS) + _WS[AXIS])
  223. #define LOGICAL_TO_NATIVE(POS, AXIS) ((POS) - _WS[AXIS])
  224. FORCE_INLINE void toLogical(xy_pos_t &raw) { raw += _WS; }
  225. FORCE_INLINE void toLogical(xyz_pos_t &raw) { raw += _WS; }
  226. FORCE_INLINE void toLogical(xyze_pos_t &raw) { raw += _WS; }
  227. FORCE_INLINE void toNative(xy_pos_t &raw) { raw -= _WS; }
  228. FORCE_INLINE void toNative(xyz_pos_t &raw) { raw -= _WS; }
  229. FORCE_INLINE void toNative(xyze_pos_t &raw) { raw -= _WS; }
  230. #else
  231. #define NATIVE_TO_LOGICAL(POS, AXIS) (POS)
  232. #define LOGICAL_TO_NATIVE(POS, AXIS) (POS)
  233. FORCE_INLINE void toLogical(xy_pos_t&) {}
  234. FORCE_INLINE void toLogical(xyz_pos_t&) {}
  235. FORCE_INLINE void toLogical(xyze_pos_t&) {}
  236. FORCE_INLINE void toNative(xy_pos_t&) {}
  237. FORCE_INLINE void toNative(xyz_pos_t&) {}
  238. FORCE_INLINE void toNative(xyze_pos_t&) {}
  239. #endif
  240. #define LOGICAL_X_POSITION(POS) NATIVE_TO_LOGICAL(POS, X_AXIS)
  241. #define LOGICAL_Y_POSITION(POS) NATIVE_TO_LOGICAL(POS, Y_AXIS)
  242. #define LOGICAL_Z_POSITION(POS) NATIVE_TO_LOGICAL(POS, Z_AXIS)
  243. #define RAW_X_POSITION(POS) LOGICAL_TO_NATIVE(POS, X_AXIS)
  244. #define RAW_Y_POSITION(POS) LOGICAL_TO_NATIVE(POS, Y_AXIS)
  245. #define RAW_Z_POSITION(POS) LOGICAL_TO_NATIVE(POS, Z_AXIS)
  246. /**
  247. * position_is_reachable family of functions
  248. */
  249. #if IS_KINEMATIC // (DELTA or SCARA)
  250. #if HAS_SCARA_OFFSET
  251. extern abc_pos_t scara_home_offset; // A and B angular offsets, Z mm offset
  252. #endif
  253. // Return true if the given point is within the printable area
  254. inline bool position_is_reachable(const float &rx, const float &ry, const float inset=0) {
  255. #if ENABLED(DELTA)
  256. return HYPOT2(rx, ry) <= sq(DELTA_PRINTABLE_RADIUS - inset + fslop);
  257. #elif IS_SCARA
  258. const float R2 = HYPOT2(rx - SCARA_OFFSET_X, ry - SCARA_OFFSET_Y);
  259. return (
  260. R2 <= sq(L1 + L2) - inset
  261. #if MIDDLE_DEAD_ZONE_R > 0
  262. && R2 >= sq(float(MIDDLE_DEAD_ZONE_R))
  263. #endif
  264. );
  265. #endif
  266. }
  267. inline bool position_is_reachable(const xy_pos_t &pos, const float inset=0) {
  268. return position_is_reachable(pos.x, pos.y, inset);
  269. }
  270. #else // CARTESIAN
  271. // Return true if the given position is within the machine bounds.
  272. inline bool position_is_reachable(const float &rx, const float &ry) {
  273. if (!WITHIN(ry, Y_MIN_POS - fslop, Y_MAX_POS + fslop)) return false;
  274. #if ENABLED(DUAL_X_CARRIAGE)
  275. if (active_extruder)
  276. return WITHIN(rx, X2_MIN_POS - fslop, X2_MAX_POS + fslop);
  277. else
  278. return WITHIN(rx, X1_MIN_POS - fslop, X1_MAX_POS + fslop);
  279. #else
  280. return WITHIN(rx, X_MIN_POS - fslop, X_MAX_POS + fslop);
  281. #endif
  282. }
  283. inline bool position_is_reachable(const xy_pos_t &pos) { return position_is_reachable(pos.x, pos.y); }
  284. #endif // CARTESIAN
  285. /**
  286. * Duplication mode
  287. */
  288. #if HAS_DUPLICATION_MODE
  289. extern bool extruder_duplication_enabled, // Used in Dual X mode 2
  290. mirrored_duplication_mode; // Used in Dual X mode 3
  291. #if ENABLED(MULTI_NOZZLE_DUPLICATION)
  292. extern uint8_t duplication_e_mask;
  293. #endif
  294. #endif
  295. /**
  296. * Dual X Carriage
  297. */
  298. #if ENABLED(DUAL_X_CARRIAGE)
  299. enum DualXMode : char {
  300. DXC_FULL_CONTROL_MODE,
  301. DXC_AUTO_PARK_MODE,
  302. DXC_DUPLICATION_MODE,
  303. DXC_MIRRORED_MODE
  304. };
  305. extern DualXMode dual_x_carriage_mode;
  306. extern float inactive_extruder_x_pos, // Used in mode 0 & 1
  307. duplicate_extruder_x_offset; // Used in mode 2 & 3
  308. extern xyz_pos_t raised_parked_position; // Used in mode 1
  309. extern bool active_extruder_parked; // Used in mode 1, 2 & 3
  310. extern millis_t delayed_move_time; // Used in mode 1
  311. extern int16_t duplicate_extruder_temp_offset; // Used in mode 2 & 3
  312. FORCE_INLINE bool dxc_is_duplicating() { return dual_x_carriage_mode >= DXC_DUPLICATION_MODE; }
  313. float x_home_pos(const int extruder);
  314. FORCE_INLINE int x_home_dir(const uint8_t extruder) { return extruder ? X2_HOME_DIR : X_HOME_DIR; }
  315. #elif ENABLED(MULTI_NOZZLE_DUPLICATION)
  316. enum DualXMode : char {
  317. DXC_DUPLICATION_MODE = 2
  318. };
  319. #endif
  320. #if HAS_M206_COMMAND
  321. void set_home_offset(const AxisEnum axis, const float v);
  322. #endif