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

planner.cpp 54KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513
  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. * planner.cpp
  24. *
  25. * Buffer movement commands and manage the acceleration profile plan
  26. *
  27. * Derived from Grbl
  28. * Copyright (c) 2009-2011 Simen Svale Skogsrud
  29. *
  30. * The ring buffer implementation gleaned from the wiring_serial library by David A. Mellis.
  31. *
  32. *
  33. * Reasoning behind the mathematics in this module (in the key of 'Mathematica'):
  34. *
  35. * s == speed, a == acceleration, t == time, d == distance
  36. *
  37. * Basic definitions:
  38. * Speed[s_, a_, t_] := s + (a*t)
  39. * Travel[s_, a_, t_] := Integrate[Speed[s, a, t], t]
  40. *
  41. * Distance to reach a specific speed with a constant acceleration:
  42. * Solve[{Speed[s, a, t] == m, Travel[s, a, t] == d}, d, t]
  43. * d -> (m^2 - s^2)/(2 a) --> estimate_acceleration_distance()
  44. *
  45. * Speed after a given distance of travel with constant acceleration:
  46. * Solve[{Speed[s, a, t] == m, Travel[s, a, t] == d}, m, t]
  47. * m -> Sqrt[2 a d + s^2]
  48. *
  49. * DestinationSpeed[s_, a_, d_] := Sqrt[2 a d + s^2]
  50. *
  51. * When to start braking (di) to reach a specified destination speed (s2) after accelerating
  52. * from initial speed s1 without ever stopping at a plateau:
  53. * Solve[{DestinationSpeed[s1, a, di] == DestinationSpeed[s2, a, d - di]}, di]
  54. * di -> (2 a d - s1^2 + s2^2)/(4 a) --> intersection_distance()
  55. *
  56. * IntersectionDistance[s1_, s2_, a_, d_] := (2 a d - s1^2 + s2^2)/(4 a)
  57. *
  58. */
  59. #include "planner.h"
  60. #include "stepper.h"
  61. #include "temperature.h"
  62. #include "ultralcd.h"
  63. #include "language.h"
  64. #include "Marlin.h"
  65. #if ENABLED(MESH_BED_LEVELING)
  66. #include "mesh_bed_leveling.h"
  67. #endif
  68. Planner planner;
  69. // public:
  70. /**
  71. * A ring buffer of moves described in steps
  72. */
  73. block_t Planner::block_buffer[BLOCK_BUFFER_SIZE];
  74. volatile uint8_t Planner::block_buffer_head = 0, // Index of the next block to be pushed
  75. Planner::block_buffer_tail = 0;
  76. float Planner::max_feedrate_mm_s[XYZE_N], // Max speeds in mm per second
  77. Planner::axis_steps_per_mm[XYZE_N],
  78. Planner::steps_to_mm[XYZE_N];
  79. #if ENABLED(DISTINCT_E_FACTORS)
  80. uint8_t Planner::last_extruder = 0; // Respond to extruder change
  81. #endif
  82. uint32_t Planner::max_acceleration_steps_per_s2[XYZE_N],
  83. Planner::max_acceleration_mm_per_s2[XYZE_N]; // Use M201 to override by software
  84. millis_t Planner::min_segment_time;
  85. float Planner::min_feedrate_mm_s,
  86. Planner::acceleration, // Normal acceleration mm/s^2 DEFAULT ACCELERATION for all printing moves. M204 SXXXX
  87. Planner::retract_acceleration, // Retract acceleration mm/s^2 filament pull-back and push-forward while standing still in the other axes M204 TXXXX
  88. Planner::travel_acceleration, // Travel acceleration mm/s^2 DEFAULT ACCELERATION for all NON printing moves. M204 MXXXX
  89. Planner::max_jerk[XYZE], // The largest speed change requiring no acceleration
  90. Planner::min_travel_feedrate_mm_s;
  91. #if HAS_ABL
  92. bool Planner::abl_enabled = false; // Flag that auto bed leveling is enabled
  93. #endif
  94. #if ABL_PLANAR
  95. matrix_3x3 Planner::bed_level_matrix; // Transform to compensate for bed level
  96. #endif
  97. #if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
  98. float Planner::z_fade_height,
  99. Planner::inverse_z_fade_height;
  100. #endif
  101. #if ENABLED(AUTOTEMP)
  102. float Planner::autotemp_max = 250,
  103. Planner::autotemp_min = 210,
  104. Planner::autotemp_factor = 0.1;
  105. bool Planner::autotemp_enabled = false;
  106. #endif
  107. // private:
  108. long Planner::position[NUM_AXIS] = { 0 };
  109. uint32_t Planner::cutoff_long;
  110. float Planner::previous_speed[NUM_AXIS],
  111. Planner::previous_nominal_speed;
  112. #if ENABLED(DISABLE_INACTIVE_EXTRUDER)
  113. uint8_t Planner::g_uc_extruder_last_move[EXTRUDERS] = { 0 };
  114. #endif
  115. #ifdef XY_FREQUENCY_LIMIT
  116. // Old direction bits. Used for speed calculations
  117. unsigned char Planner::old_direction_bits = 0;
  118. // Segment times (in µs). Used for speed calculations
  119. long Planner::axis_segment_time[2][3] = { {MAX_FREQ_TIME + 1, 0, 0}, {MAX_FREQ_TIME + 1, 0, 0} };
  120. #endif
  121. #if ENABLED(LIN_ADVANCE)
  122. float Planner::extruder_advance_k = LIN_ADVANCE_K,
  123. Planner::advance_ed_ratio = LIN_ADVANCE_E_D_RATIO,
  124. Planner::position_float[NUM_AXIS] = { 0 };
  125. #endif
  126. #if ENABLED(ULTRA_LCD)
  127. volatile uint32_t Planner::block_buffer_runtime_us = 0;
  128. #endif
  129. /**
  130. * Class and Instance Methods
  131. */
  132. Planner::Planner() { init(); }
  133. void Planner::init() {
  134. block_buffer_head = block_buffer_tail = 0;
  135. ZERO(position);
  136. #if ENABLED(LIN_ADVANCE)
  137. ZERO(position_float);
  138. #endif
  139. ZERO(previous_speed);
  140. previous_nominal_speed = 0.0;
  141. #if ABL_PLANAR
  142. bed_level_matrix.set_to_identity();
  143. #endif
  144. }
  145. #define MINIMAL_STEP_RATE 120
  146. /**
  147. * Calculate trapezoid parameters, multiplying the entry- and exit-speeds
  148. * by the provided factors.
  149. */
  150. void Planner::calculate_trapezoid_for_block(block_t* const block, const float &entry_factor, const float &exit_factor) {
  151. uint32_t initial_rate = ceil(block->nominal_rate * entry_factor),
  152. final_rate = ceil(block->nominal_rate * exit_factor); // (steps per second)
  153. // Limit minimal step rate (Otherwise the timer will overflow.)
  154. NOLESS(initial_rate, MINIMAL_STEP_RATE);
  155. NOLESS(final_rate, MINIMAL_STEP_RATE);
  156. int32_t accel = block->acceleration_steps_per_s2,
  157. accelerate_steps = ceil(estimate_acceleration_distance(initial_rate, block->nominal_rate, accel)),
  158. decelerate_steps = floor(estimate_acceleration_distance(block->nominal_rate, final_rate, -accel)),
  159. plateau_steps = block->step_event_count - accelerate_steps - decelerate_steps;
  160. // Is the Plateau of Nominal Rate smaller than nothing? That means no cruising, and we will
  161. // have to use intersection_distance() to calculate when to abort accel and start braking
  162. // in order to reach the final_rate exactly at the end of this block.
  163. if (plateau_steps < 0) {
  164. accelerate_steps = ceil(intersection_distance(initial_rate, final_rate, accel, block->step_event_count));
  165. NOLESS(accelerate_steps, 0); // Check limits due to numerical round-off
  166. accelerate_steps = min((uint32_t)accelerate_steps, block->step_event_count);//(We can cast here to unsigned, because the above line ensures that we are above zero)
  167. plateau_steps = 0;
  168. }
  169. // block->accelerate_until = accelerate_steps;
  170. // block->decelerate_after = accelerate_steps+plateau_steps;
  171. CRITICAL_SECTION_START; // Fill variables used by the stepper in a critical section
  172. if (!TEST(block->flag, BLOCK_BIT_BUSY)) { // Don't update variables if block is busy.
  173. block->accelerate_until = accelerate_steps;
  174. block->decelerate_after = accelerate_steps + plateau_steps;
  175. block->initial_rate = initial_rate;
  176. block->final_rate = final_rate;
  177. #if ENABLED(ADVANCE)
  178. block->initial_advance = block->advance * sq(entry_factor);
  179. block->final_advance = block->advance * sq(exit_factor);
  180. #endif
  181. }
  182. CRITICAL_SECTION_END;
  183. }
  184. // "Junction jerk" in this context is the immediate change in speed at the junction of two blocks.
  185. // This method will calculate the junction jerk as the euclidean distance between the nominal
  186. // velocities of the respective blocks.
  187. //inline float junction_jerk(block_t *before, block_t *after) {
  188. // return sqrt(
  189. // pow((before->speed_x-after->speed_x), 2)+pow((before->speed_y-after->speed_y), 2));
  190. //}
  191. // The kernel called by recalculate() when scanning the plan from last to first entry.
  192. void Planner::reverse_pass_kernel(block_t* const current, const block_t *next) {
  193. if (!current || !next) return;
  194. // If entry speed is already at the maximum entry speed, no need to recheck. Block is cruising.
  195. // If not, block in state of acceleration or deceleration. Reset entry speed to maximum and
  196. // check for maximum allowable speed reductions to ensure maximum possible planned speed.
  197. float max_entry_speed = current->max_entry_speed;
  198. if (current->entry_speed != max_entry_speed) {
  199. // If nominal length true, max junction speed is guaranteed to be reached. Only compute
  200. // for max allowable speed if block is decelerating and nominal length is false.
  201. current->entry_speed = (TEST(current->flag, BLOCK_BIT_NOMINAL_LENGTH) || max_entry_speed <= next->entry_speed)
  202. ? max_entry_speed
  203. : min(max_entry_speed, max_allowable_speed(-current->acceleration, next->entry_speed, current->millimeters));
  204. SBI(current->flag, BLOCK_BIT_RECALCULATE);
  205. }
  206. }
  207. /**
  208. * recalculate() needs to go over the current plan twice.
  209. * Once in reverse and once forward. This implements the reverse pass.
  210. */
  211. void Planner::reverse_pass() {
  212. if (movesplanned() > 3) {
  213. block_t* block[3] = { NULL, NULL, NULL };
  214. // Make a local copy of block_buffer_tail, because the interrupt can alter it
  215. // Is a critical section REALLY needed for a single byte change?
  216. //CRITICAL_SECTION_START;
  217. uint8_t tail = block_buffer_tail;
  218. //CRITICAL_SECTION_END
  219. uint8_t b = BLOCK_MOD(block_buffer_head - 3);
  220. while (b != tail) {
  221. if (block[0] && TEST(block[0]->flag, BLOCK_BIT_START_FROM_FULL_HALT)) break;
  222. b = prev_block_index(b);
  223. block[2] = block[1];
  224. block[1] = block[0];
  225. block[0] = &block_buffer[b];
  226. reverse_pass_kernel(block[1], block[2]);
  227. }
  228. }
  229. }
  230. // The kernel called by recalculate() when scanning the plan from first to last entry.
  231. void Planner::forward_pass_kernel(const block_t* previous, block_t* const current) {
  232. if (!previous) return;
  233. // If the previous block is an acceleration block, but it is not long enough to complete the
  234. // full speed change within the block, we need to adjust the entry speed accordingly. Entry
  235. // speeds have already been reset, maximized, and reverse planned by reverse planner.
  236. // If nominal length is true, max junction speed is guaranteed to be reached. No need to recheck.
  237. if (!TEST(previous->flag, BLOCK_BIT_NOMINAL_LENGTH)) {
  238. if (previous->entry_speed < current->entry_speed) {
  239. float entry_speed = min(current->entry_speed,
  240. max_allowable_speed(-previous->acceleration, previous->entry_speed, previous->millimeters));
  241. // Check for junction speed change
  242. if (current->entry_speed != entry_speed) {
  243. current->entry_speed = entry_speed;
  244. SBI(current->flag, BLOCK_BIT_RECALCULATE);
  245. }
  246. }
  247. }
  248. }
  249. /**
  250. * recalculate() needs to go over the current plan twice.
  251. * Once in reverse and once forward. This implements the forward pass.
  252. */
  253. void Planner::forward_pass() {
  254. block_t* block[3] = { NULL, NULL, NULL };
  255. for (uint8_t b = block_buffer_tail; b != block_buffer_head; b = next_block_index(b)) {
  256. block[0] = block[1];
  257. block[1] = block[2];
  258. block[2] = &block_buffer[b];
  259. forward_pass_kernel(block[0], block[1]);
  260. }
  261. forward_pass_kernel(block[1], block[2]);
  262. }
  263. /**
  264. * Recalculate the trapezoid speed profiles for all blocks in the plan
  265. * according to the entry_factor for each junction. Must be called by
  266. * recalculate() after updating the blocks.
  267. */
  268. void Planner::recalculate_trapezoids() {
  269. int8_t block_index = block_buffer_tail;
  270. block_t *current, *next = NULL;
  271. while (block_index != block_buffer_head) {
  272. current = next;
  273. next = &block_buffer[block_index];
  274. if (current) {
  275. // Recalculate if current block entry or exit junction speed has changed.
  276. if (TEST(current->flag, BLOCK_BIT_RECALCULATE) || TEST(next->flag, BLOCK_BIT_RECALCULATE)) {
  277. // NOTE: Entry and exit factors always > 0 by all previous logic operations.
  278. float nom = current->nominal_speed;
  279. calculate_trapezoid_for_block(current, current->entry_speed / nom, next->entry_speed / nom);
  280. CBI(current->flag, BLOCK_BIT_RECALCULATE); // Reset current only to ensure next trapezoid is computed
  281. }
  282. }
  283. block_index = next_block_index(block_index);
  284. }
  285. // Last/newest block in buffer. Exit speed is set with MINIMUM_PLANNER_SPEED. Always recalculated.
  286. if (next) {
  287. float nom = next->nominal_speed;
  288. calculate_trapezoid_for_block(next, next->entry_speed / nom, (MINIMUM_PLANNER_SPEED) / nom);
  289. CBI(next->flag, BLOCK_BIT_RECALCULATE);
  290. }
  291. }
  292. /*
  293. * Recalculate the motion plan according to the following algorithm:
  294. *
  295. * 1. Go over every block in reverse order...
  296. *
  297. * Calculate a junction speed reduction (block_t.entry_factor) so:
  298. *
  299. * a. The junction jerk is within the set limit, and
  300. *
  301. * b. No speed reduction within one block requires faster
  302. * deceleration than the one, true constant acceleration.
  303. *
  304. * 2. Go over every block in chronological order...
  305. *
  306. * Dial down junction speed reduction values if:
  307. * a. The speed increase within one block would require faster
  308. * acceleration than the one, true constant acceleration.
  309. *
  310. * After that, all blocks will have an entry_factor allowing all speed changes to
  311. * be performed using only the one, true constant acceleration, and where no junction
  312. * jerk is jerkier than the set limit, Jerky. Finally it will:
  313. *
  314. * 3. Recalculate "trapezoids" for all blocks.
  315. */
  316. void Planner::recalculate() {
  317. reverse_pass();
  318. forward_pass();
  319. recalculate_trapezoids();
  320. }
  321. #if ENABLED(AUTOTEMP)
  322. void Planner::getHighESpeed() {
  323. static float oldt = 0;
  324. if (!autotemp_enabled) return;
  325. if (thermalManager.degTargetHotend(0) + 2 < autotemp_min) return; // probably temperature set to zero.
  326. float high = 0.0;
  327. for (uint8_t b = block_buffer_tail; b != block_buffer_head; b = next_block_index(b)) {
  328. block_t* block = &block_buffer[b];
  329. if (block->steps[X_AXIS] || block->steps[Y_AXIS] || block->steps[Z_AXIS]) {
  330. float se = (float)block->steps[E_AXIS] / block->step_event_count * block->nominal_speed; // mm/sec;
  331. NOLESS(high, se);
  332. }
  333. }
  334. float t = autotemp_min + high * autotemp_factor;
  335. t = constrain(t, autotemp_min, autotemp_max);
  336. if (t < oldt) t = t * (1 - (AUTOTEMP_OLDWEIGHT)) + oldt * (AUTOTEMP_OLDWEIGHT);
  337. oldt = t;
  338. thermalManager.setTargetHotend(t, 0);
  339. }
  340. #endif //AUTOTEMP
  341. /**
  342. * Maintain fans, paste extruder pressure,
  343. */
  344. void Planner::check_axes_activity() {
  345. unsigned char axis_active[NUM_AXIS] = { 0 },
  346. tail_fan_speed[FAN_COUNT];
  347. #if FAN_COUNT > 0
  348. for (uint8_t i = 0; i < FAN_COUNT; i++) tail_fan_speed[i] = fanSpeeds[i];
  349. #endif
  350. #if ENABLED(BARICUDA)
  351. #if HAS_HEATER_1
  352. unsigned char tail_valve_pressure = baricuda_valve_pressure;
  353. #endif
  354. #if HAS_HEATER_2
  355. unsigned char tail_e_to_p_pressure = baricuda_e_to_p_pressure;
  356. #endif
  357. #endif
  358. if (blocks_queued()) {
  359. #if FAN_COUNT > 0
  360. for (uint8_t i = 0; i < FAN_COUNT; i++) tail_fan_speed[i] = block_buffer[block_buffer_tail].fan_speed[i];
  361. #endif
  362. block_t* block;
  363. #if ENABLED(BARICUDA)
  364. block = &block_buffer[block_buffer_tail];
  365. #if HAS_HEATER_1
  366. tail_valve_pressure = block->valve_pressure;
  367. #endif
  368. #if HAS_HEATER_2
  369. tail_e_to_p_pressure = block->e_to_p_pressure;
  370. #endif
  371. #endif
  372. for (uint8_t b = block_buffer_tail; b != block_buffer_head; b = next_block_index(b)) {
  373. block = &block_buffer[b];
  374. LOOP_XYZE(i) if (block->steps[i]) axis_active[i]++;
  375. }
  376. }
  377. #if ENABLED(DISABLE_X)
  378. if (!axis_active[X_AXIS]) disable_X();
  379. #endif
  380. #if ENABLED(DISABLE_Y)
  381. if (!axis_active[Y_AXIS]) disable_Y();
  382. #endif
  383. #if ENABLED(DISABLE_Z)
  384. if (!axis_active[Z_AXIS]) disable_Z();
  385. #endif
  386. #if ENABLED(DISABLE_E)
  387. if (!axis_active[E_AXIS]) disable_e_steppers();
  388. #endif
  389. #if FAN_COUNT > 0
  390. #ifdef FAN_MIN_PWM
  391. #define CALC_FAN_SPEED(f) (tail_fan_speed[f] ? ( FAN_MIN_PWM + (tail_fan_speed[f] * (255 - FAN_MIN_PWM)) / 255 ) : 0)
  392. #else
  393. #define CALC_FAN_SPEED(f) tail_fan_speed[f]
  394. #endif
  395. #ifdef FAN_KICKSTART_TIME
  396. static millis_t fan_kick_end[FAN_COUNT] = { 0 };
  397. #define KICKSTART_FAN(f) \
  398. if (tail_fan_speed[f]) { \
  399. millis_t ms = millis(); \
  400. if (fan_kick_end[f] == 0) { \
  401. fan_kick_end[f] = ms + FAN_KICKSTART_TIME; \
  402. tail_fan_speed[f] = 255; \
  403. } else { \
  404. if (PENDING(ms, fan_kick_end[f])) { \
  405. tail_fan_speed[f] = 255; \
  406. } \
  407. } \
  408. } else { \
  409. fan_kick_end[f] = 0; \
  410. }
  411. #if HAS_FAN0
  412. KICKSTART_FAN(0);
  413. #endif
  414. #if HAS_FAN1
  415. KICKSTART_FAN(1);
  416. #endif
  417. #if HAS_FAN2
  418. KICKSTART_FAN(2);
  419. #endif
  420. #endif //FAN_KICKSTART_TIME
  421. #if ENABLED(FAN_SOFT_PWM)
  422. #if HAS_FAN0
  423. thermalManager.fanSpeedSoftPwm[0] = CALC_FAN_SPEED(0);
  424. #endif
  425. #if HAS_FAN1
  426. thermalManager.fanSpeedSoftPwm[1] = CALC_FAN_SPEED(1);
  427. #endif
  428. #if HAS_FAN2
  429. thermalManager.fanSpeedSoftPwm[2] = CALC_FAN_SPEED(2);
  430. #endif
  431. #else
  432. #if HAS_FAN0
  433. analogWrite(FAN_PIN, CALC_FAN_SPEED(0));
  434. #endif
  435. #if HAS_FAN1
  436. analogWrite(FAN1_PIN, CALC_FAN_SPEED(1));
  437. #endif
  438. #if HAS_FAN2
  439. analogWrite(FAN2_PIN, CALC_FAN_SPEED(2));
  440. #endif
  441. #endif
  442. #endif // FAN_COUNT > 0
  443. #if ENABLED(AUTOTEMP)
  444. getHighESpeed();
  445. #endif
  446. #if ENABLED(BARICUDA)
  447. #if HAS_HEATER_1
  448. analogWrite(HEATER_1_PIN, tail_valve_pressure);
  449. #endif
  450. #if HAS_HEATER_2
  451. analogWrite(HEATER_2_PIN, tail_e_to_p_pressure);
  452. #endif
  453. #endif
  454. }
  455. #if PLANNER_LEVELING
  456. /**
  457. * lx, ly, lz - logical (cartesian, not delta) positions in mm
  458. */
  459. void Planner::apply_leveling(float &lx, float &ly, float &lz) {
  460. #if HAS_ABL
  461. if (!abl_enabled) return;
  462. #endif
  463. #if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
  464. static float z_fade_factor = 1.0, last_raw_lz = -999.0;
  465. if (z_fade_height) {
  466. const float raw_lz = RAW_Z_POSITION(lz);
  467. if (raw_lz >= z_fade_height) return;
  468. if (last_raw_lz != raw_lz) {
  469. last_raw_lz = raw_lz;
  470. z_fade_factor = 1.0 - raw_lz * inverse_z_fade_height;
  471. }
  472. }
  473. else
  474. z_fade_factor = 1.0;
  475. #endif
  476. #if ENABLED(MESH_BED_LEVELING)
  477. if (mbl.active())
  478. lz += mbl.get_z(RAW_X_POSITION(lx), RAW_Y_POSITION(ly)
  479. #if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
  480. , z_fade_factor
  481. #endif
  482. );
  483. #elif ABL_PLANAR
  484. float dx = RAW_X_POSITION(lx) - (X_TILT_FULCRUM),
  485. dy = RAW_Y_POSITION(ly) - (Y_TILT_FULCRUM),
  486. dz = RAW_Z_POSITION(lz);
  487. apply_rotation_xyz(bed_level_matrix, dx, dy, dz);
  488. lx = LOGICAL_X_POSITION(dx + X_TILT_FULCRUM);
  489. ly = LOGICAL_Y_POSITION(dy + Y_TILT_FULCRUM);
  490. lz = LOGICAL_Z_POSITION(dz);
  491. #elif ENABLED(AUTO_BED_LEVELING_BILINEAR)
  492. float tmp[XYZ] = { lx, ly, 0 };
  493. lz += bilinear_z_offset(tmp)
  494. #if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
  495. * z_fade_factor
  496. #endif
  497. ;
  498. #endif
  499. }
  500. void Planner::unapply_leveling(float logical[XYZ]) {
  501. #if HAS_ABL
  502. if (!abl_enabled) return;
  503. #endif
  504. #if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
  505. if (z_fade_height && RAW_Z_POSITION(logical[Z_AXIS]) >= z_fade_height) return;
  506. #endif
  507. #if ENABLED(MESH_BED_LEVELING)
  508. if (mbl.active()) {
  509. #if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
  510. const float c = mbl.get_z(RAW_X_POSITION(logical[X_AXIS]), RAW_Y_POSITION(logical[Y_AXIS]), 1.0);
  511. logical[Z_AXIS] = (z_fade_height * (RAW_Z_POSITION(logical[Z_AXIS]) - c)) / (z_fade_height - c);
  512. #else
  513. logical[Z_AXIS] -= mbl.get_z(RAW_X_POSITION(logical[X_AXIS]), RAW_Y_POSITION(logical[Y_AXIS]));
  514. #endif
  515. }
  516. #elif ABL_PLANAR
  517. matrix_3x3 inverse = matrix_3x3::transpose(bed_level_matrix);
  518. float dx = RAW_X_POSITION(logical[X_AXIS]) - (X_TILT_FULCRUM),
  519. dy = RAW_Y_POSITION(logical[Y_AXIS]) - (Y_TILT_FULCRUM),
  520. dz = RAW_Z_POSITION(logical[Z_AXIS]);
  521. apply_rotation_xyz(inverse, dx, dy, dz);
  522. logical[X_AXIS] = LOGICAL_X_POSITION(dx + X_TILT_FULCRUM);
  523. logical[Y_AXIS] = LOGICAL_Y_POSITION(dy + Y_TILT_FULCRUM);
  524. logical[Z_AXIS] = LOGICAL_Z_POSITION(dz);
  525. #elif ENABLED(AUTO_BED_LEVELING_BILINEAR)
  526. #if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
  527. const float c = bilinear_z_offset(logical);
  528. logical[Z_AXIS] = (z_fade_height * (RAW_Z_POSITION(logical[Z_AXIS]) - c)) / (z_fade_height - c);
  529. #else
  530. logical[Z_AXIS] -= bilinear_z_offset(logical);
  531. #endif
  532. #endif
  533. }
  534. #endif // PLANNER_LEVELING
  535. /**
  536. * Planner::_buffer_line
  537. *
  538. * Add a new linear movement to the buffer.
  539. *
  540. * Leveling and kinematics should be applied ahead of calling this.
  541. *
  542. * a,b,c,e - target positions in mm or degrees
  543. * fr_mm_s - (target) speed of the move
  544. * extruder - target extruder
  545. */
  546. void Planner::_buffer_line(const float &a, const float &b, const float &c, const float &e, float fr_mm_s, const uint8_t extruder) {
  547. // The target position of the tool in absolute steps
  548. // Calculate target position in absolute steps
  549. //this should be done after the wait, because otherwise a M92 code within the gcode disrupts this calculation somehow
  550. const long target[XYZE] = {
  551. lround(a * axis_steps_per_mm[X_AXIS]),
  552. lround(b * axis_steps_per_mm[Y_AXIS]),
  553. lround(c * axis_steps_per_mm[Z_AXIS]),
  554. lround(e * axis_steps_per_mm[E_AXIS_N])
  555. };
  556. // When changing extruders recalculate steps corresponding to the E position
  557. #if ENABLED(DISTINCT_E_FACTORS)
  558. if (last_extruder != extruder && axis_steps_per_mm[E_AXIS_N] != axis_steps_per_mm[E_AXIS + last_extruder]) {
  559. position[E_AXIS] = lround(position[E_AXIS] * axis_steps_per_mm[E_AXIS_N] * steps_to_mm[E_AXIS + last_extruder]);
  560. last_extruder = extruder;
  561. }
  562. #endif
  563. #if ENABLED(LIN_ADVANCE)
  564. const float mm_D_float = sqrt(sq(a - position_float[X_AXIS]) + sq(b - position_float[Y_AXIS]));
  565. #endif
  566. const long da = target[X_AXIS] - position[X_AXIS],
  567. db = target[Y_AXIS] - position[Y_AXIS],
  568. dc = target[Z_AXIS] - position[Z_AXIS];
  569. /*
  570. SERIAL_ECHOPAIR(" Planner FR:", fr_mm_s);
  571. SERIAL_CHAR(' ');
  572. #if IS_KINEMATIC
  573. SERIAL_ECHOPAIR("A:", a);
  574. SERIAL_ECHOPAIR(" (", da);
  575. SERIAL_ECHOPAIR(") B:", b);
  576. #else
  577. SERIAL_ECHOPAIR("X:", a);
  578. SERIAL_ECHOPAIR(" (", da);
  579. SERIAL_ECHOPAIR(") Y:", b);
  580. #endif
  581. SERIAL_ECHOPAIR(" (", db);
  582. #if ENABLED(DELTA)
  583. SERIAL_ECHOPAIR(") C:", c);
  584. #else
  585. SERIAL_ECHOPAIR(") Z:", c);
  586. #endif
  587. SERIAL_ECHOPAIR(" (", dc);
  588. SERIAL_CHAR(')');
  589. SERIAL_EOL;
  590. //*/
  591. // DRYRUN ignores all temperature constraints and assures that the extruder is instantly satisfied
  592. if (DEBUGGING(DRYRUN)) {
  593. position[E_AXIS] = target[E_AXIS];
  594. #if ENABLED(LIN_ADVANCE)
  595. position_float[E_AXIS] = e;
  596. #endif
  597. }
  598. long de = target[E_AXIS] - position[E_AXIS];
  599. #if ENABLED(LIN_ADVANCE)
  600. float de_float = e - position_float[E_AXIS];
  601. #endif
  602. #if ENABLED(PREVENT_COLD_EXTRUSION)
  603. if (de) {
  604. if (thermalManager.tooColdToExtrude(extruder)) {
  605. position[E_AXIS] = target[E_AXIS]; // Behave as if the move really took place, but ignore E part
  606. de = 0; // no difference
  607. #if ENABLED(LIN_ADVANCE)
  608. position_float[E_AXIS] = e;
  609. de_float = 0;
  610. #endif
  611. SERIAL_ECHO_START;
  612. SERIAL_ECHOLNPGM(MSG_ERR_COLD_EXTRUDE_STOP);
  613. }
  614. #if ENABLED(PREVENT_LENGTHY_EXTRUDE)
  615. if (labs(de) > (int32_t)axis_steps_per_mm[E_AXIS_N] * (EXTRUDE_MAXLENGTH)) { // It's not important to get max. extrusion length in a precision < 1mm, so save some cycles and cast to int
  616. position[E_AXIS] = target[E_AXIS]; // Behave as if the move really took place, but ignore E part
  617. de = 0; // no difference
  618. #if ENABLED(LIN_ADVANCE)
  619. position_float[E_AXIS] = e;
  620. de_float = 0;
  621. #endif
  622. SERIAL_ECHO_START;
  623. SERIAL_ECHOLNPGM(MSG_ERR_LONG_EXTRUDE_STOP);
  624. }
  625. #endif
  626. }
  627. #endif
  628. // Compute direction bit-mask for this block
  629. uint8_t dm = 0;
  630. #if CORE_IS_XY
  631. if (da < 0) SBI(dm, X_HEAD); // Save the real Extruder (head) direction in X Axis
  632. if (db < 0) SBI(dm, Y_HEAD); // ...and Y
  633. if (dc < 0) SBI(dm, Z_AXIS);
  634. if (da + db < 0) SBI(dm, A_AXIS); // Motor A direction
  635. if (CORESIGN(da - db) < 0) SBI(dm, B_AXIS); // Motor B direction
  636. #elif CORE_IS_XZ
  637. if (da < 0) SBI(dm, X_HEAD); // Save the real Extruder (head) direction in X Axis
  638. if (db < 0) SBI(dm, Y_AXIS);
  639. if (dc < 0) SBI(dm, Z_HEAD); // ...and Z
  640. if (da + dc < 0) SBI(dm, A_AXIS); // Motor A direction
  641. if (CORESIGN(da - dc) < 0) SBI(dm, C_AXIS); // Motor C direction
  642. #elif CORE_IS_YZ
  643. if (da < 0) SBI(dm, X_AXIS);
  644. if (db < 0) SBI(dm, Y_HEAD); // Save the real Extruder (head) direction in Y Axis
  645. if (dc < 0) SBI(dm, Z_HEAD); // ...and Z
  646. if (db + dc < 0) SBI(dm, B_AXIS); // Motor B direction
  647. if (CORESIGN(db - dc) < 0) SBI(dm, C_AXIS); // Motor C direction
  648. #else
  649. if (da < 0) SBI(dm, X_AXIS);
  650. if (db < 0) SBI(dm, Y_AXIS);
  651. if (dc < 0) SBI(dm, Z_AXIS);
  652. #endif
  653. if (de < 0) SBI(dm, E_AXIS);
  654. const float esteps_float = de * volumetric_multiplier[extruder] * flow_percentage[extruder] * 0.01;
  655. const int32_t esteps = abs(esteps_float) + 0.5;
  656. // Calculate the buffer head after we push this byte
  657. const uint8_t next_buffer_head = next_block_index(block_buffer_head);
  658. // If the buffer is full: good! That means we are well ahead of the robot.
  659. // Rest here until there is room in the buffer.
  660. while (block_buffer_tail == next_buffer_head) idle();
  661. // Prepare to set up new block
  662. block_t* block = &block_buffer[block_buffer_head];
  663. // Clear all flags, including the "busy" bit
  664. block->flag = 0;
  665. // Set direction bits
  666. block->direction_bits = dm;
  667. // Number of steps for each axis
  668. // See http://www.corexy.com/theory.html
  669. #if CORE_IS_XY
  670. block->steps[A_AXIS] = labs(da + db);
  671. block->steps[B_AXIS] = labs(da - db);
  672. block->steps[Z_AXIS] = labs(dc);
  673. #elif CORE_IS_XZ
  674. block->steps[A_AXIS] = labs(da + dc);
  675. block->steps[Y_AXIS] = labs(db);
  676. block->steps[C_AXIS] = labs(da - dc);
  677. #elif CORE_IS_YZ
  678. block->steps[X_AXIS] = labs(da);
  679. block->steps[B_AXIS] = labs(db + dc);
  680. block->steps[C_AXIS] = labs(db - dc);
  681. #else
  682. // default non-h-bot planning
  683. block->steps[X_AXIS] = labs(da);
  684. block->steps[Y_AXIS] = labs(db);
  685. block->steps[Z_AXIS] = labs(dc);
  686. #endif
  687. block->steps[E_AXIS] = esteps;
  688. block->step_event_count = MAX4(block->steps[X_AXIS], block->steps[Y_AXIS], block->steps[Z_AXIS], esteps);
  689. // Bail if this is a zero-length block
  690. if (block->step_event_count < MIN_STEPS_PER_SEGMENT) return;
  691. // For a mixing extruder, get a magnified step_event_count for each
  692. #if ENABLED(MIXING_EXTRUDER)
  693. for (uint8_t i = 0; i < MIXING_STEPPERS; i++)
  694. block->mix_event_count[i] = mixing_factor[i] * block->step_event_count;
  695. #endif
  696. #if FAN_COUNT > 0
  697. for (uint8_t i = 0; i < FAN_COUNT; i++) block->fan_speed[i] = fanSpeeds[i];
  698. #endif
  699. #if ENABLED(BARICUDA)
  700. block->valve_pressure = baricuda_valve_pressure;
  701. block->e_to_p_pressure = baricuda_e_to_p_pressure;
  702. #endif
  703. block->active_extruder = extruder;
  704. //enable active axes
  705. #if CORE_IS_XY
  706. if (block->steps[A_AXIS] || block->steps[B_AXIS]) {
  707. enable_X();
  708. enable_Y();
  709. }
  710. #if DISABLED(Z_LATE_ENABLE)
  711. if (block->steps[Z_AXIS]) enable_Z();
  712. #endif
  713. #elif CORE_IS_XZ
  714. if (block->steps[A_AXIS] || block->steps[C_AXIS]) {
  715. enable_X();
  716. enable_Z();
  717. }
  718. if (block->steps[Y_AXIS]) enable_Y();
  719. #elif CORE_IS_YZ
  720. if (block->steps[B_AXIS] || block->steps[C_AXIS]) {
  721. enable_Y();
  722. enable_Z();
  723. }
  724. if (block->steps[X_AXIS]) enable_X();
  725. #else
  726. if (block->steps[X_AXIS]) enable_X();
  727. if (block->steps[Y_AXIS]) enable_Y();
  728. #if DISABLED(Z_LATE_ENABLE)
  729. if (block->steps[Z_AXIS]) enable_Z();
  730. #endif
  731. #endif
  732. // Enable extruder(s)
  733. if (esteps) {
  734. #if ENABLED(DISABLE_INACTIVE_EXTRUDER) // Enable only the selected extruder
  735. #define DISABLE_IDLE_E(N) if (!g_uc_extruder_last_move[N]) disable_E##N();
  736. for (uint8_t i = 0; i < EXTRUDERS; i++)
  737. if (g_uc_extruder_last_move[i] > 0) g_uc_extruder_last_move[i]--;
  738. switch(extruder) {
  739. case 0:
  740. enable_E0();
  741. g_uc_extruder_last_move[0] = (BLOCK_BUFFER_SIZE) * 2;
  742. #if ENABLED(DUAL_X_CARRIAGE) || ENABLED(DUAL_NOZZLE_DUPLICATION_MODE)
  743. if (extruder_duplication_enabled) {
  744. enable_E1();
  745. g_uc_extruder_last_move[1] = (BLOCK_BUFFER_SIZE) * 2;
  746. }
  747. #endif
  748. #if EXTRUDERS > 1
  749. DISABLE_IDLE_E(1);
  750. #if EXTRUDERS > 2
  751. DISABLE_IDLE_E(2);
  752. #if EXTRUDERS > 3
  753. DISABLE_IDLE_E(3);
  754. #if EXTRUDERS > 4
  755. DISABLE_IDLE_E(4);
  756. #endif // EXTRUDERS > 4
  757. #endif // EXTRUDERS > 3
  758. #endif // EXTRUDERS > 2
  759. #endif // EXTRUDERS > 1
  760. break;
  761. #if EXTRUDERS > 1
  762. case 1:
  763. enable_E1();
  764. g_uc_extruder_last_move[1] = (BLOCK_BUFFER_SIZE) * 2;
  765. DISABLE_IDLE_E(0);
  766. #if EXTRUDERS > 2
  767. DISABLE_IDLE_E(2);
  768. #if EXTRUDERS > 3
  769. DISABLE_IDLE_E(3);
  770. #if EXTRUDERS > 4
  771. DISABLE_IDLE_E(4);
  772. #endif // EXTRUDERS > 4
  773. #endif // EXTRUDERS > 3
  774. #endif // EXTRUDERS > 2
  775. break;
  776. #if EXTRUDERS > 2
  777. case 2:
  778. enable_E2();
  779. g_uc_extruder_last_move[2] = (BLOCK_BUFFER_SIZE) * 2;
  780. DISABLE_IDLE_E(0);
  781. DISABLE_IDLE_E(1);
  782. #if EXTRUDERS > 3
  783. DISABLE_IDLE_E(3);
  784. #if EXTRUDERS > 4
  785. DISABLE_IDLE_E(4);
  786. #endif
  787. #endif
  788. break;
  789. #if EXTRUDERS > 3
  790. case 3:
  791. enable_E3();
  792. g_uc_extruder_last_move[3] = (BLOCK_BUFFER_SIZE) * 2;
  793. DISABLE_IDLE_E(0);
  794. DISABLE_IDLE_E(1);
  795. DISABLE_IDLE_E(2);
  796. #if EXTRUDERS > 4
  797. DISABLE_IDLE_E(4);
  798. #endif
  799. break;
  800. #if EXTRUDERS > 4
  801. case 4:
  802. enable_E4();
  803. g_uc_extruder_last_move[4] = (BLOCK_BUFFER_SIZE) * 2;
  804. DISABLE_IDLE_E(0);
  805. DISABLE_IDLE_E(1);
  806. DISABLE_IDLE_E(2);
  807. DISABLE_IDLE_E(3);
  808. break;
  809. #endif // EXTRUDERS > 4
  810. #endif // EXTRUDERS > 3
  811. #endif // EXTRUDERS > 2
  812. #endif // EXTRUDERS > 1
  813. }
  814. #else
  815. enable_E0();
  816. enable_E1();
  817. enable_E2();
  818. enable_E3();
  819. enable_E4();
  820. #endif
  821. }
  822. if (esteps)
  823. NOLESS(fr_mm_s, min_feedrate_mm_s);
  824. else
  825. NOLESS(fr_mm_s, min_travel_feedrate_mm_s);
  826. /**
  827. * This part of the code calculates the total length of the movement.
  828. * For cartesian bots, the X_AXIS is the real X movement and same for Y_AXIS.
  829. * But for corexy bots, that is not true. The "X_AXIS" and "Y_AXIS" motors (that should be named to A_AXIS
  830. * and B_AXIS) cannot be used for X and Y length, because A=X+Y and B=X-Y.
  831. * So we need to create other 2 "AXIS", named X_HEAD and Y_HEAD, meaning the real displacement of the Head.
  832. * Having the real displacement of the head, we can calculate the total movement length and apply the desired speed.
  833. */
  834. #if IS_CORE
  835. float delta_mm[Z_HEAD + 1];
  836. #if CORE_IS_XY
  837. delta_mm[X_HEAD] = da * steps_to_mm[A_AXIS];
  838. delta_mm[Y_HEAD] = db * steps_to_mm[B_AXIS];
  839. delta_mm[Z_AXIS] = dc * steps_to_mm[Z_AXIS];
  840. delta_mm[A_AXIS] = (da + db) * steps_to_mm[A_AXIS];
  841. delta_mm[B_AXIS] = CORESIGN(da - db) * steps_to_mm[B_AXIS];
  842. #elif CORE_IS_XZ
  843. delta_mm[X_HEAD] = da * steps_to_mm[A_AXIS];
  844. delta_mm[Y_AXIS] = db * steps_to_mm[Y_AXIS];
  845. delta_mm[Z_HEAD] = dc * steps_to_mm[C_AXIS];
  846. delta_mm[A_AXIS] = (da + dc) * steps_to_mm[A_AXIS];
  847. delta_mm[C_AXIS] = CORESIGN(da - dc) * steps_to_mm[C_AXIS];
  848. #elif CORE_IS_YZ
  849. delta_mm[X_AXIS] = da * steps_to_mm[X_AXIS];
  850. delta_mm[Y_HEAD] = db * steps_to_mm[B_AXIS];
  851. delta_mm[Z_HEAD] = dc * steps_to_mm[C_AXIS];
  852. delta_mm[B_AXIS] = (db + dc) * steps_to_mm[B_AXIS];
  853. delta_mm[C_AXIS] = CORESIGN(db - dc) * steps_to_mm[C_AXIS];
  854. #endif
  855. #else
  856. float delta_mm[XYZE];
  857. delta_mm[X_AXIS] = da * steps_to_mm[X_AXIS];
  858. delta_mm[Y_AXIS] = db * steps_to_mm[Y_AXIS];
  859. delta_mm[Z_AXIS] = dc * steps_to_mm[Z_AXIS];
  860. #endif
  861. delta_mm[E_AXIS] = esteps_float * steps_to_mm[E_AXIS_N];
  862. if (block->steps[X_AXIS] < MIN_STEPS_PER_SEGMENT && block->steps[Y_AXIS] < MIN_STEPS_PER_SEGMENT && block->steps[Z_AXIS] < MIN_STEPS_PER_SEGMENT) {
  863. block->millimeters = fabs(delta_mm[E_AXIS]);
  864. }
  865. else {
  866. block->millimeters = sqrt(
  867. #if CORE_IS_XY
  868. sq(delta_mm[X_HEAD]) + sq(delta_mm[Y_HEAD]) + sq(delta_mm[Z_AXIS])
  869. #elif CORE_IS_XZ
  870. sq(delta_mm[X_HEAD]) + sq(delta_mm[Y_AXIS]) + sq(delta_mm[Z_HEAD])
  871. #elif CORE_IS_YZ
  872. sq(delta_mm[X_AXIS]) + sq(delta_mm[Y_HEAD]) + sq(delta_mm[Z_HEAD])
  873. #else
  874. sq(delta_mm[X_AXIS]) + sq(delta_mm[Y_AXIS]) + sq(delta_mm[Z_AXIS])
  875. #endif
  876. );
  877. }
  878. float inverse_millimeters = 1.0 / block->millimeters; // Inverse millimeters to remove multiple divides
  879. // Calculate moves/second for this move. No divide by zero due to previous checks.
  880. float inverse_mm_s = fr_mm_s * inverse_millimeters;
  881. const uint8_t moves_queued = movesplanned();
  882. // Slow down when the buffer starts to empty, rather than wait at the corner for a buffer refill
  883. #if ENABLED(SLOWDOWN) || ENABLED(ULTRA_LCD) || defined(XY_FREQUENCY_LIMIT)
  884. // Segment time im micro seconds
  885. unsigned long segment_time = lround(1000000.0 / inverse_mm_s);
  886. #endif
  887. #if ENABLED(SLOWDOWN)
  888. if (WITHIN(moves_queued, 2, (BLOCK_BUFFER_SIZE) / 2 - 1)) {
  889. if (segment_time < min_segment_time) {
  890. // buffer is draining, add extra time. The amount of time added increases if the buffer is still emptied more.
  891. inverse_mm_s = 1000000.0 / (segment_time + lround(2 * (min_segment_time - segment_time) / moves_queued));
  892. #if defined(XY_FREQUENCY_LIMIT) || ENABLED(ULTRA_LCD)
  893. segment_time = lround(1000000.0 / inverse_mm_s);
  894. #endif
  895. }
  896. }
  897. #endif
  898. #if ENABLED(ULTRA_LCD)
  899. CRITICAL_SECTION_START
  900. block_buffer_runtime_us += segment_time;
  901. CRITICAL_SECTION_END
  902. #endif
  903. block->nominal_speed = block->millimeters * inverse_mm_s; // (mm/sec) Always > 0
  904. block->nominal_rate = ceil(block->step_event_count * inverse_mm_s); // (step/sec) Always > 0
  905. #if ENABLED(FILAMENT_WIDTH_SENSOR)
  906. static float filwidth_e_count = 0, filwidth_delay_dist = 0;
  907. //FMM update ring buffer used for delay with filament measurements
  908. if (extruder == FILAMENT_SENSOR_EXTRUDER_NUM && filwidth_delay_index[1] >= 0) { //only for extruder with filament sensor and if ring buffer is initialized
  909. const int MMD_CM = MAX_MEASUREMENT_DELAY + 1, MMD_MM = MMD_CM * 10;
  910. // increment counters with next move in e axis
  911. filwidth_e_count += delta_mm[E_AXIS];
  912. filwidth_delay_dist += delta_mm[E_AXIS];
  913. // Only get new measurements on forward E movement
  914. if (filwidth_e_count > 0.0001) {
  915. // Loop the delay distance counter (modulus by the mm length)
  916. while (filwidth_delay_dist >= MMD_MM) filwidth_delay_dist -= MMD_MM;
  917. // Convert into an index into the measurement array
  918. filwidth_delay_index[0] = (int)(filwidth_delay_dist * 0.1 + 0.0001);
  919. // If the index has changed (must have gone forward)...
  920. if (filwidth_delay_index[0] != filwidth_delay_index[1]) {
  921. filwidth_e_count = 0; // Reset the E movement counter
  922. const int8_t meas_sample = thermalManager.widthFil_to_size_ratio() - 100; // Subtract 100 to reduce magnitude - to store in a signed char
  923. do {
  924. filwidth_delay_index[1] = (filwidth_delay_index[1] + 1) % MMD_CM; // The next unused slot
  925. measurement_delay[filwidth_delay_index[1]] = meas_sample; // Store the measurement
  926. } while (filwidth_delay_index[0] != filwidth_delay_index[1]); // More slots to fill?
  927. }
  928. }
  929. }
  930. #endif
  931. // Calculate and limit speed in mm/sec for each axis
  932. float current_speed[NUM_AXIS], speed_factor = 1.0; // factor <1 decreases speed
  933. LOOP_XYZE(i) {
  934. const float cs = fabs(current_speed[i] = delta_mm[i] * inverse_mm_s);
  935. #if ENABLED(DISTINCT_E_FACTORS)
  936. if (i == E_AXIS) i += extruder;
  937. #endif
  938. if (cs > max_feedrate_mm_s[i]) NOMORE(speed_factor, max_feedrate_mm_s[i] / cs);
  939. }
  940. // Max segment time in µs.
  941. #ifdef XY_FREQUENCY_LIMIT
  942. // Check and limit the xy direction change frequency
  943. const unsigned char direction_change = block->direction_bits ^ old_direction_bits;
  944. old_direction_bits = block->direction_bits;
  945. segment_time = lround((float)segment_time / speed_factor);
  946. long xs0 = axis_segment_time[X_AXIS][0],
  947. xs1 = axis_segment_time[X_AXIS][1],
  948. xs2 = axis_segment_time[X_AXIS][2],
  949. ys0 = axis_segment_time[Y_AXIS][0],
  950. ys1 = axis_segment_time[Y_AXIS][1],
  951. ys2 = axis_segment_time[Y_AXIS][2];
  952. if (TEST(direction_change, X_AXIS)) {
  953. xs2 = axis_segment_time[X_AXIS][2] = xs1;
  954. xs1 = axis_segment_time[X_AXIS][1] = xs0;
  955. xs0 = 0;
  956. }
  957. xs0 = axis_segment_time[X_AXIS][0] = xs0 + segment_time;
  958. if (TEST(direction_change, Y_AXIS)) {
  959. ys2 = axis_segment_time[Y_AXIS][2] = axis_segment_time[Y_AXIS][1];
  960. ys1 = axis_segment_time[Y_AXIS][1] = axis_segment_time[Y_AXIS][0];
  961. ys0 = 0;
  962. }
  963. ys0 = axis_segment_time[Y_AXIS][0] = ys0 + segment_time;
  964. const long max_x_segment_time = MAX3(xs0, xs1, xs2),
  965. max_y_segment_time = MAX3(ys0, ys1, ys2),
  966. min_xy_segment_time = min(max_x_segment_time, max_y_segment_time);
  967. if (min_xy_segment_time < MAX_FREQ_TIME) {
  968. const float low_sf = speed_factor * min_xy_segment_time / (MAX_FREQ_TIME);
  969. NOMORE(speed_factor, low_sf);
  970. }
  971. #endif // XY_FREQUENCY_LIMIT
  972. // Correct the speed
  973. if (speed_factor < 1.0) {
  974. LOOP_XYZE(i) current_speed[i] *= speed_factor;
  975. block->nominal_speed *= speed_factor;
  976. block->nominal_rate *= speed_factor;
  977. }
  978. // Compute and limit the acceleration rate for the trapezoid generator.
  979. const float steps_per_mm = block->step_event_count * inverse_millimeters;
  980. uint32_t accel;
  981. if (!block->steps[X_AXIS] && !block->steps[Y_AXIS] && !block->steps[Z_AXIS]) {
  982. // convert to: acceleration steps/sec^2
  983. accel = ceil(retract_acceleration * steps_per_mm);
  984. }
  985. else {
  986. #define LIMIT_ACCEL_LONG(AXIS,INDX) do{ \
  987. if (block->steps[AXIS] && max_acceleration_steps_per_s2[AXIS+INDX] < accel) { \
  988. const uint32_t comp = max_acceleration_steps_per_s2[AXIS+INDX] * block->step_event_count; \
  989. if (accel * block->steps[AXIS] > comp) accel = comp / block->steps[AXIS]; \
  990. } \
  991. }while(0)
  992. #define LIMIT_ACCEL_FLOAT(AXIS,INDX) do{ \
  993. if (block->steps[AXIS] && max_acceleration_steps_per_s2[AXIS+INDX] < accel) { \
  994. const float comp = (float)max_acceleration_steps_per_s2[AXIS+INDX] * (float)block->step_event_count; \
  995. if ((float)accel * (float)block->steps[AXIS] > comp) accel = comp / (float)block->steps[AXIS]; \
  996. } \
  997. }while(0)
  998. // Start with print or travel acceleration
  999. accel = ceil((esteps ? acceleration : travel_acceleration) * steps_per_mm);
  1000. #if ENABLED(DISTINCT_E_FACTORS)
  1001. #define ACCEL_IDX extruder
  1002. #else
  1003. #define ACCEL_IDX 0
  1004. #endif
  1005. // Limit acceleration per axis
  1006. if (block->step_event_count <= cutoff_long) {
  1007. LIMIT_ACCEL_LONG(X_AXIS, 0);
  1008. LIMIT_ACCEL_LONG(Y_AXIS, 0);
  1009. LIMIT_ACCEL_LONG(Z_AXIS, 0);
  1010. LIMIT_ACCEL_LONG(E_AXIS, ACCEL_IDX);
  1011. }
  1012. else {
  1013. LIMIT_ACCEL_FLOAT(X_AXIS, 0);
  1014. LIMIT_ACCEL_FLOAT(Y_AXIS, 0);
  1015. LIMIT_ACCEL_FLOAT(Z_AXIS, 0);
  1016. LIMIT_ACCEL_FLOAT(E_AXIS, ACCEL_IDX);
  1017. }
  1018. }
  1019. block->acceleration_steps_per_s2 = accel;
  1020. block->acceleration = accel / steps_per_mm;
  1021. block->acceleration_rate = (long)(accel * 16777216.0 / ((F_CPU) * 0.125)); // * 8.388608
  1022. // Initial limit on the segment entry velocity
  1023. float vmax_junction;
  1024. #if 0 // Use old jerk for now
  1025. float junction_deviation = 0.1;
  1026. // Compute path unit vector
  1027. double unit_vec[XYZ] = {
  1028. delta_mm[X_AXIS] * inverse_millimeters,
  1029. delta_mm[Y_AXIS] * inverse_millimeters,
  1030. delta_mm[Z_AXIS] * inverse_millimeters
  1031. };
  1032. /*
  1033. Compute maximum allowable entry speed at junction by centripetal acceleration approximation.
  1034. Let a circle be tangent to both previous and current path line segments, where the junction
  1035. deviation is defined as the distance from the junction to the closest edge of the circle,
  1036. collinear with the circle center.
  1037. The circular segment joining the two paths represents the path of centripetal acceleration.
  1038. Solve for max velocity based on max acceleration about the radius of the circle, defined
  1039. indirectly by junction deviation.
  1040. This may be also viewed as path width or max_jerk in the previous grbl version. This approach
  1041. does not actually deviate from path, but used as a robust way to compute cornering speeds, as
  1042. it takes into account the nonlinearities of both the junction angle and junction velocity.
  1043. */
  1044. vmax_junction = MINIMUM_PLANNER_SPEED; // Set default max junction speed
  1045. // Skip first block or when previous_nominal_speed is used as a flag for homing and offset cycles.
  1046. if (block_buffer_head != block_buffer_tail && previous_nominal_speed > 0.0) {
  1047. // Compute cosine of angle between previous and current path. (prev_unit_vec is negative)
  1048. // NOTE: Max junction velocity is computed without sin() or acos() by trig half angle identity.
  1049. float cos_theta = - previous_unit_vec[X_AXIS] * unit_vec[X_AXIS]
  1050. - previous_unit_vec[Y_AXIS] * unit_vec[Y_AXIS]
  1051. - previous_unit_vec[Z_AXIS] * unit_vec[Z_AXIS] ;
  1052. // Skip and use default max junction speed for 0 degree acute junction.
  1053. if (cos_theta < 0.95) {
  1054. vmax_junction = min(previous_nominal_speed, block->nominal_speed);
  1055. // Skip and avoid divide by zero for straight junctions at 180 degrees. Limit to min() of nominal speeds.
  1056. if (cos_theta > -0.95) {
  1057. // Compute maximum junction velocity based on maximum acceleration and junction deviation
  1058. float sin_theta_d2 = sqrt(0.5 * (1.0 - cos_theta)); // Trig half angle identity. Always positive.
  1059. NOMORE(vmax_junction, sqrt(block->acceleration * junction_deviation * sin_theta_d2 / (1.0 - sin_theta_d2)));
  1060. }
  1061. }
  1062. }
  1063. #endif
  1064. /**
  1065. * Adapted from Prusa MKS firmware
  1066. *
  1067. * Start with a safe speed (from which the machine may halt to stop immediately).
  1068. */
  1069. // Exit speed limited by a jerk to full halt of a previous last segment
  1070. static float previous_safe_speed;
  1071. float safe_speed = block->nominal_speed;
  1072. uint8_t limited = 0;
  1073. LOOP_XYZE(i) {
  1074. const float jerk = fabs(current_speed[i]), maxj = max_jerk[i];
  1075. if (jerk > maxj) {
  1076. if (limited) {
  1077. const float mjerk = maxj * block->nominal_speed;
  1078. if (jerk * safe_speed > mjerk) safe_speed = mjerk / jerk;
  1079. }
  1080. else {
  1081. ++limited;
  1082. safe_speed = maxj;
  1083. }
  1084. }
  1085. }
  1086. if (moves_queued > 1 && previous_nominal_speed > 0.0001) {
  1087. // Estimate a maximum velocity allowed at a joint of two successive segments.
  1088. // If this maximum velocity allowed is lower than the minimum of the entry / exit safe velocities,
  1089. // then the machine is not coasting anymore and the safe entry / exit velocities shall be used.
  1090. // The junction velocity will be shared between successive segments. Limit the junction velocity to their minimum.
  1091. bool prev_speed_larger = previous_nominal_speed > block->nominal_speed;
  1092. float smaller_speed_factor = prev_speed_larger ? (block->nominal_speed / previous_nominal_speed) : (previous_nominal_speed / block->nominal_speed);
  1093. // Pick the smaller of the nominal speeds. Higher speed shall not be achieved at the junction during coasting.
  1094. vmax_junction = prev_speed_larger ? block->nominal_speed : previous_nominal_speed;
  1095. // Factor to multiply the previous / current nominal velocities to get componentwise limited velocities.
  1096. float v_factor = 1.f;
  1097. limited = 0;
  1098. // Now limit the jerk in all axes.
  1099. LOOP_XYZE(axis) {
  1100. // Limit an axis. We have to differentiate: coasting, reversal of an axis, full stop.
  1101. float v_exit = previous_speed[axis], v_entry = current_speed[axis];
  1102. if (prev_speed_larger) v_exit *= smaller_speed_factor;
  1103. if (limited) {
  1104. v_exit *= v_factor;
  1105. v_entry *= v_factor;
  1106. }
  1107. // Calculate jerk depending on whether the axis is coasting in the same direction or reversing.
  1108. const float jerk = (v_exit > v_entry)
  1109. ? // coasting axis reversal
  1110. ( (v_entry > 0.f || v_exit < 0.f) ? (v_exit - v_entry) : max(v_exit, -v_entry) )
  1111. : // v_exit <= v_entry coasting axis reversal
  1112. ( (v_entry < 0.f || v_exit > 0.f) ? (v_entry - v_exit) : max(-v_exit, v_entry) );
  1113. if (jerk > max_jerk[axis]) {
  1114. v_factor *= max_jerk[axis] / jerk;
  1115. ++limited;
  1116. }
  1117. }
  1118. if (limited) vmax_junction *= v_factor;
  1119. // Now the transition velocity is known, which maximizes the shared exit / entry velocity while
  1120. // respecting the jerk factors, it may be possible, that applying separate safe exit / entry velocities will achieve faster prints.
  1121. const float vmax_junction_threshold = vmax_junction * 0.99f;
  1122. if (previous_safe_speed > vmax_junction_threshold && safe_speed > vmax_junction_threshold) {
  1123. // Not coasting. The machine will stop and start the movements anyway,
  1124. // better to start the segment from start.
  1125. SBI(block->flag, BLOCK_BIT_START_FROM_FULL_HALT);
  1126. vmax_junction = safe_speed;
  1127. }
  1128. }
  1129. else {
  1130. SBI(block->flag, BLOCK_BIT_START_FROM_FULL_HALT);
  1131. vmax_junction = safe_speed;
  1132. }
  1133. // Max entry speed of this block equals the max exit speed of the previous block.
  1134. block->max_entry_speed = vmax_junction;
  1135. // Initialize block entry speed. Compute based on deceleration to user-defined MINIMUM_PLANNER_SPEED.
  1136. const float v_allowable = max_allowable_speed(-block->acceleration, MINIMUM_PLANNER_SPEED, block->millimeters);
  1137. block->entry_speed = min(vmax_junction, v_allowable);
  1138. // Initialize planner efficiency flags
  1139. // Set flag if block will always reach maximum junction speed regardless of entry/exit speeds.
  1140. // If a block can de/ac-celerate from nominal speed to zero within the length of the block, then
  1141. // the current block and next block junction speeds are guaranteed to always be at their maximum
  1142. // junction speeds in deceleration and acceleration, respectively. This is due to how the current
  1143. // block nominal speed limits both the current and next maximum junction speeds. Hence, in both
  1144. // the reverse and forward planners, the corresponding block junction speed will always be at the
  1145. // the maximum junction speed and may always be ignored for any speed reduction checks.
  1146. block->flag |= BLOCK_FLAG_RECALCULATE | (block->nominal_speed <= v_allowable ? BLOCK_FLAG_NOMINAL_LENGTH : 0);
  1147. // Update previous path unit_vector and nominal speed
  1148. COPY(previous_speed, current_speed);
  1149. previous_nominal_speed = block->nominal_speed;
  1150. previous_safe_speed = safe_speed;
  1151. #if ENABLED(LIN_ADVANCE)
  1152. //
  1153. // Use LIN_ADVANCE for blocks if all these are true:
  1154. //
  1155. // esteps : We have E steps todo (a printing move)
  1156. //
  1157. // block->steps[X_AXIS] || block->steps[Y_AXIS] : We have a movement in XY direction (i.e., not retract / prime).
  1158. //
  1159. // extruder_advance_k : There is an advance factor set.
  1160. //
  1161. // block->steps[E_AXIS] != block->step_event_count : A problem occurs if the move before a retract is too small.
  1162. // In that case, the retract and move will be executed together.
  1163. // This leads to too many advance steps due to a huge e_acceleration.
  1164. // The math is good, but we must avoid retract moves with advance!
  1165. // de_float > 0.0 : Extruder is running forward (e.g., for "Wipe while retracting" (Slic3r) or "Combing" (Cura) moves)
  1166. //
  1167. block->use_advance_lead = esteps
  1168. && (block->steps[X_AXIS] || block->steps[Y_AXIS])
  1169. && extruder_advance_k
  1170. && (uint32_t)esteps != block->step_event_count
  1171. && de_float > 0.0;
  1172. if (block->use_advance_lead)
  1173. block->abs_adv_steps_multiplier8 = lround(
  1174. extruder_advance_k
  1175. * (UNEAR_ZERO(advance_ed_ratio) ? de_float / mm_D_float : advance_ed_ratio) // Use the fixed ratio, if set
  1176. * (block->nominal_speed / (float)block->nominal_rate)
  1177. * axis_steps_per_mm[E_AXIS_N] * 256.0
  1178. );
  1179. #elif ENABLED(ADVANCE)
  1180. // Calculate advance rate
  1181. if (esteps && (block->steps[X_AXIS] || block->steps[Y_AXIS] || block->steps[Z_AXIS])) {
  1182. const long acc_dist = estimate_acceleration_distance(0, block->nominal_rate, block->acceleration_steps_per_s2);
  1183. const float advance = ((STEPS_PER_CUBIC_MM_E) * (EXTRUDER_ADVANCE_K)) * HYPOT(current_speed[E_AXIS], EXTRUSION_AREA) * 256;
  1184. block->advance = advance;
  1185. block->advance_rate = acc_dist ? advance / (float)acc_dist : 0;
  1186. }
  1187. else
  1188. block->advance_rate = block->advance = 0;
  1189. /**
  1190. SERIAL_ECHO_START;
  1191. SERIAL_ECHOPGM("advance :");
  1192. SERIAL_ECHO(block->advance/256.0);
  1193. SERIAL_ECHOPGM("advance rate :");
  1194. SERIAL_ECHOLN(block->advance_rate/256.0);
  1195. */
  1196. #endif // ADVANCE or LIN_ADVANCE
  1197. calculate_trapezoid_for_block(block, block->entry_speed / block->nominal_speed, safe_speed / block->nominal_speed);
  1198. // Move buffer head
  1199. block_buffer_head = next_buffer_head;
  1200. // Update the position (only when a move was queued)
  1201. COPY(position, target);
  1202. #if ENABLED(LIN_ADVANCE)
  1203. position_float[X_AXIS] = a;
  1204. position_float[Y_AXIS] = b;
  1205. position_float[Z_AXIS] = c;
  1206. position_float[E_AXIS] = e;
  1207. #endif
  1208. recalculate();
  1209. stepper.wake_up();
  1210. } // buffer_line()
  1211. /**
  1212. * Directly set the planner XYZ position (and stepper positions)
  1213. * converting mm (or angles for SCARA) into steps.
  1214. *
  1215. * On CORE machines stepper ABC will be translated from the given XYZ.
  1216. */
  1217. void Planner::_set_position_mm(const float &a, const float &b, const float &c, const float &e) {
  1218. #if ENABLED(DISTINCT_E_FACTORS)
  1219. #define _EINDEX (E_AXIS + active_extruder)
  1220. last_extruder = active_extruder;
  1221. #else
  1222. #define _EINDEX E_AXIS
  1223. #endif
  1224. long na = position[X_AXIS] = lround(a * axis_steps_per_mm[X_AXIS]),
  1225. nb = position[Y_AXIS] = lround(b * axis_steps_per_mm[Y_AXIS]),
  1226. nc = position[Z_AXIS] = lround(c * axis_steps_per_mm[Z_AXIS]),
  1227. ne = position[E_AXIS] = lround(e * axis_steps_per_mm[_EINDEX]);
  1228. #if ENABLED(LIN_ADVANCE)
  1229. position_float[X_AXIS] = a;
  1230. position_float[Y_AXIS] = b;
  1231. position_float[Z_AXIS] = c;
  1232. position_float[E_AXIS] = e;
  1233. #endif
  1234. stepper.set_position(na, nb, nc, ne);
  1235. previous_nominal_speed = 0.0; // Resets planner junction speeds. Assumes start from rest.
  1236. ZERO(previous_speed);
  1237. }
  1238. void Planner::set_position_mm_kinematic(const float position[NUM_AXIS]) {
  1239. #if PLANNER_LEVELING
  1240. float lpos[XYZ] = { position[X_AXIS], position[Y_AXIS], position[Z_AXIS] };
  1241. apply_leveling(lpos);
  1242. #else
  1243. const float * const lpos = position;
  1244. #endif
  1245. #if IS_KINEMATIC
  1246. inverse_kinematics(lpos);
  1247. _set_position_mm(delta[A_AXIS], delta[B_AXIS], delta[C_AXIS], position[E_AXIS]);
  1248. #else
  1249. _set_position_mm(lpos[X_AXIS], lpos[Y_AXIS], lpos[Z_AXIS], position[E_AXIS]);
  1250. #endif
  1251. }
  1252. /**
  1253. * Sync from the stepper positions. (e.g., after an interrupted move)
  1254. */
  1255. void Planner::sync_from_steppers() {
  1256. LOOP_XYZE(i) {
  1257. position[i] = stepper.position((AxisEnum)i);
  1258. #if ENABLED(LIN_ADVANCE)
  1259. position_float[i] = position[i] * steps_to_mm[i
  1260. #if ENABLED(DISTINCT_E_FACTORS)
  1261. + (i == E_AXIS ? active_extruder : 0)
  1262. #endif
  1263. ];
  1264. #endif
  1265. }
  1266. }
  1267. /**
  1268. * Setters for planner position (also setting stepper position).
  1269. */
  1270. void Planner::set_position_mm(const AxisEnum axis, const float& v) {
  1271. #if ENABLED(DISTINCT_E_FACTORS)
  1272. const uint8_t axis_index = axis + (axis == E_AXIS ? active_extruder : 0);
  1273. last_extruder = active_extruder;
  1274. #else
  1275. const uint8_t axis_index = axis;
  1276. #endif
  1277. position[axis] = lround(v * axis_steps_per_mm[axis_index]);
  1278. #if ENABLED(LIN_ADVANCE)
  1279. position_float[axis] = v;
  1280. #endif
  1281. stepper.set_position(axis, v);
  1282. previous_speed[axis] = 0.0;
  1283. }
  1284. // Recalculate the steps/s^2 acceleration rates, based on the mm/s^2
  1285. void Planner::reset_acceleration_rates() {
  1286. #if ENABLED(DISTINCT_E_FACTORS)
  1287. #define HIGHEST_CONDITION (i < E_AXIS || i == E_AXIS + active_extruder)
  1288. #else
  1289. #define HIGHEST_CONDITION true
  1290. #endif
  1291. uint32_t highest_rate = 1;
  1292. LOOP_XYZE_N(i) {
  1293. max_acceleration_steps_per_s2[i] = max_acceleration_mm_per_s2[i] * axis_steps_per_mm[i];
  1294. if (HIGHEST_CONDITION) NOLESS(highest_rate, max_acceleration_steps_per_s2[i]);
  1295. }
  1296. cutoff_long = 4294967295UL / highest_rate;
  1297. }
  1298. // Recalculate position, steps_to_mm if axis_steps_per_mm changes!
  1299. void Planner::refresh_positioning() {
  1300. LOOP_XYZE_N(i) steps_to_mm[i] = 1.0 / axis_steps_per_mm[i];
  1301. set_position_mm_kinematic(current_position);
  1302. reset_acceleration_rates();
  1303. }
  1304. #if ENABLED(AUTOTEMP)
  1305. void Planner::autotemp_M104_M109() {
  1306. autotemp_enabled = code_seen('F');
  1307. if (autotemp_enabled) autotemp_factor = code_value_temp_diff();
  1308. if (code_seen('S')) autotemp_min = code_value_temp_abs();
  1309. if (code_seen('B')) autotemp_max = code_value_temp_abs();
  1310. }
  1311. #endif