1 |
ron |
1 |
/**
|
|
|
2 |
* Marlin 3D Printer Firmware
|
|
|
3 |
* Copyright (C) 2016 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
|
|
|
4 |
*
|
|
|
5 |
* Based on Sprinter and grbl.
|
|
|
6 |
* Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
|
|
|
7 |
*
|
|
|
8 |
* This program is free software: you can redistribute it and/or modify
|
|
|
9 |
* it under the terms of the GNU General Public License as published by
|
|
|
10 |
* the Free Software Foundation, either version 3 of the License, or
|
|
|
11 |
* (at your option) any later version.
|
|
|
12 |
*
|
|
|
13 |
* This program is distributed in the hope that it will be useful,
|
|
|
14 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
15 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
16 |
* GNU General Public License for more details.
|
|
|
17 |
*
|
|
|
18 |
* You should have received a copy of the GNU General Public License
|
|
|
19 |
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
20 |
*
|
|
|
21 |
*/
|
|
|
22 |
#ifndef MARLIN_H
|
|
|
23 |
#define MARLIN_H
|
|
|
24 |
|
|
|
25 |
#include <math.h>
|
|
|
26 |
#include <stdio.h>
|
|
|
27 |
#include <stdlib.h>
|
|
|
28 |
#include <string.h>
|
|
|
29 |
#include <inttypes.h>
|
|
|
30 |
|
|
|
31 |
#include <util/delay.h>
|
|
|
32 |
#include <avr/eeprom.h>
|
|
|
33 |
#include <avr/interrupt.h>
|
|
|
34 |
|
|
|
35 |
#include "MarlinConfig.h"
|
|
|
36 |
|
|
|
37 |
#ifdef DEBUG_GCODE_PARSER
|
|
|
38 |
#include "parser.h"
|
|
|
39 |
#endif
|
|
|
40 |
|
|
|
41 |
#include "enum.h"
|
|
|
42 |
#include "types.h"
|
|
|
43 |
#include "fastio.h"
|
|
|
44 |
#include "utility.h"
|
|
|
45 |
#include "serial.h"
|
|
|
46 |
|
|
|
47 |
void idle(
|
|
|
48 |
#if ENABLED(ADVANCED_PAUSE_FEATURE)
|
|
|
49 |
bool no_stepper_sleep = false // pass true to keep steppers from disabling on timeout
|
|
|
50 |
#endif
|
|
|
51 |
);
|
|
|
52 |
|
|
|
53 |
void manage_inactivity(const bool ignore_stepper_queue=false);
|
|
|
54 |
|
|
|
55 |
extern const char axis_codes[XYZE];
|
|
|
56 |
|
|
|
57 |
#if ENABLED(DUAL_X_CARRIAGE) || ENABLED(DUAL_NOZZLE_DUPLICATION_MODE)
|
|
|
58 |
extern bool extruder_duplication_enabled;
|
|
|
59 |
#endif
|
|
|
60 |
|
|
|
61 |
#if HAS_X2_ENABLE
|
|
|
62 |
#define enable_X() do{ X_ENABLE_WRITE( X_ENABLE_ON); X2_ENABLE_WRITE( X_ENABLE_ON); }while(0)
|
|
|
63 |
#define disable_X() do{ X_ENABLE_WRITE(!X_ENABLE_ON); X2_ENABLE_WRITE(!X_ENABLE_ON); CBI(axis_known_position, X_AXIS); }while(0)
|
|
|
64 |
#elif HAS_X_ENABLE
|
|
|
65 |
#define enable_X() X_ENABLE_WRITE( X_ENABLE_ON)
|
|
|
66 |
#define disable_X() do{ X_ENABLE_WRITE(!X_ENABLE_ON); CBI(axis_known_position, X_AXIS); }while(0)
|
|
|
67 |
#else
|
|
|
68 |
#define enable_X() NOOP
|
|
|
69 |
#define disable_X() NOOP
|
|
|
70 |
#endif
|
|
|
71 |
|
|
|
72 |
#if HAS_Y2_ENABLE
|
|
|
73 |
#define enable_Y() do{ Y_ENABLE_WRITE( Y_ENABLE_ON); Y2_ENABLE_WRITE(Y_ENABLE_ON); }while(0)
|
|
|
74 |
#define disable_Y() do{ Y_ENABLE_WRITE(!Y_ENABLE_ON); Y2_ENABLE_WRITE(!Y_ENABLE_ON); CBI(axis_known_position, Y_AXIS); }while(0)
|
|
|
75 |
#elif HAS_Y_ENABLE
|
|
|
76 |
#define enable_Y() Y_ENABLE_WRITE( Y_ENABLE_ON)
|
|
|
77 |
#define disable_Y() do{ Y_ENABLE_WRITE(!Y_ENABLE_ON); CBI(axis_known_position, Y_AXIS); }while(0)
|
|
|
78 |
#else
|
|
|
79 |
#define enable_Y() NOOP
|
|
|
80 |
#define disable_Y() NOOP
|
|
|
81 |
#endif
|
|
|
82 |
|
|
|
83 |
#if HAS_Z2_ENABLE
|
|
|
84 |
#define enable_Z() do{ Z_ENABLE_WRITE( Z_ENABLE_ON); Z2_ENABLE_WRITE(Z_ENABLE_ON); }while(0)
|
|
|
85 |
#define disable_Z() do{ Z_ENABLE_WRITE(!Z_ENABLE_ON); Z2_ENABLE_WRITE(!Z_ENABLE_ON); CBI(axis_known_position, Z_AXIS); }while(0)
|
|
|
86 |
#elif HAS_Z_ENABLE
|
|
|
87 |
#define enable_Z() Z_ENABLE_WRITE( Z_ENABLE_ON)
|
|
|
88 |
#define disable_Z() do{ Z_ENABLE_WRITE(!Z_ENABLE_ON); CBI(axis_known_position, Z_AXIS); }while(0)
|
|
|
89 |
#else
|
|
|
90 |
#define enable_Z() NOOP
|
|
|
91 |
#define disable_Z() NOOP
|
|
|
92 |
#endif
|
|
|
93 |
|
|
|
94 |
#if ENABLED(MIXING_EXTRUDER)
|
|
|
95 |
|
|
|
96 |
/**
|
|
|
97 |
* Mixing steppers synchronize their enable (and direction) together
|
|
|
98 |
*/
|
|
|
99 |
#if MIXING_STEPPERS > 4
|
|
|
100 |
#define enable_E0() { E0_ENABLE_WRITE( E_ENABLE_ON); E1_ENABLE_WRITE( E_ENABLE_ON); E2_ENABLE_WRITE( E_ENABLE_ON); E3_ENABLE_WRITE( E_ENABLE_ON); E4_ENABLE_WRITE( E_ENABLE_ON); }
|
|
|
101 |
#define disable_E0() { E0_ENABLE_WRITE(!E_ENABLE_ON); E1_ENABLE_WRITE(!E_ENABLE_ON); E2_ENABLE_WRITE(!E_ENABLE_ON); E3_ENABLE_WRITE(!E_ENABLE_ON); E4_ENABLE_WRITE(!E_ENABLE_ON); }
|
|
|
102 |
#elif MIXING_STEPPERS > 3
|
|
|
103 |
#define enable_E0() { E0_ENABLE_WRITE( E_ENABLE_ON); E1_ENABLE_WRITE( E_ENABLE_ON); E2_ENABLE_WRITE( E_ENABLE_ON); E3_ENABLE_WRITE( E_ENABLE_ON); }
|
|
|
104 |
#define disable_E0() { E0_ENABLE_WRITE(!E_ENABLE_ON); E1_ENABLE_WRITE(!E_ENABLE_ON); E2_ENABLE_WRITE(!E_ENABLE_ON); E3_ENABLE_WRITE(!E_ENABLE_ON); }
|
|
|
105 |
#elif MIXING_STEPPERS > 2
|
|
|
106 |
#define enable_E0() { E0_ENABLE_WRITE( E_ENABLE_ON); E1_ENABLE_WRITE( E_ENABLE_ON); E2_ENABLE_WRITE( E_ENABLE_ON); }
|
|
|
107 |
#define disable_E0() { E0_ENABLE_WRITE(!E_ENABLE_ON); E1_ENABLE_WRITE(!E_ENABLE_ON); E2_ENABLE_WRITE(!E_ENABLE_ON); }
|
|
|
108 |
#else
|
|
|
109 |
#define enable_E0() { E0_ENABLE_WRITE( E_ENABLE_ON); E1_ENABLE_WRITE( E_ENABLE_ON); }
|
|
|
110 |
#define disable_E0() { E0_ENABLE_WRITE(!E_ENABLE_ON); E1_ENABLE_WRITE(!E_ENABLE_ON); }
|
|
|
111 |
#endif
|
|
|
112 |
#define enable_E1() NOOP
|
|
|
113 |
#define disable_E1() NOOP
|
|
|
114 |
#define enable_E2() NOOP
|
|
|
115 |
#define disable_E2() NOOP
|
|
|
116 |
#define enable_E3() NOOP
|
|
|
117 |
#define disable_E3() NOOP
|
|
|
118 |
#define enable_E4() NOOP
|
|
|
119 |
#define disable_E4() NOOP
|
|
|
120 |
|
|
|
121 |
#else // !MIXING_EXTRUDER
|
|
|
122 |
|
|
|
123 |
#if HAS_E0_ENABLE
|
|
|
124 |
#define enable_E0() E0_ENABLE_WRITE( E_ENABLE_ON)
|
|
|
125 |
#define disable_E0() E0_ENABLE_WRITE(!E_ENABLE_ON)
|
|
|
126 |
#else
|
|
|
127 |
#define enable_E0() NOOP
|
|
|
128 |
#define disable_E0() NOOP
|
|
|
129 |
#endif
|
|
|
130 |
|
|
|
131 |
#if E_STEPPERS > 1 && HAS_E1_ENABLE
|
|
|
132 |
#define enable_E1() E1_ENABLE_WRITE( E_ENABLE_ON)
|
|
|
133 |
#define disable_E1() E1_ENABLE_WRITE(!E_ENABLE_ON)
|
|
|
134 |
#else
|
|
|
135 |
#define enable_E1() NOOP
|
|
|
136 |
#define disable_E1() NOOP
|
|
|
137 |
#endif
|
|
|
138 |
|
|
|
139 |
#if E_STEPPERS > 2 && HAS_E2_ENABLE
|
|
|
140 |
#define enable_E2() E2_ENABLE_WRITE( E_ENABLE_ON)
|
|
|
141 |
#define disable_E2() E2_ENABLE_WRITE(!E_ENABLE_ON)
|
|
|
142 |
#else
|
|
|
143 |
#define enable_E2() NOOP
|
|
|
144 |
#define disable_E2() NOOP
|
|
|
145 |
#endif
|
|
|
146 |
|
|
|
147 |
#if E_STEPPERS > 3 && HAS_E3_ENABLE
|
|
|
148 |
#define enable_E3() E3_ENABLE_WRITE( E_ENABLE_ON)
|
|
|
149 |
#define disable_E3() E3_ENABLE_WRITE(!E_ENABLE_ON)
|
|
|
150 |
#else
|
|
|
151 |
#define enable_E3() NOOP
|
|
|
152 |
#define disable_E3() NOOP
|
|
|
153 |
#endif
|
|
|
154 |
|
|
|
155 |
#if E_STEPPERS > 4 && HAS_E4_ENABLE
|
|
|
156 |
#define enable_E4() E4_ENABLE_WRITE( E_ENABLE_ON)
|
|
|
157 |
#define disable_E4() E4_ENABLE_WRITE(!E_ENABLE_ON)
|
|
|
158 |
#else
|
|
|
159 |
#define enable_E4() NOOP
|
|
|
160 |
#define disable_E4() NOOP
|
|
|
161 |
#endif
|
|
|
162 |
|
|
|
163 |
#endif // !MIXING_EXTRUDER
|
|
|
164 |
|
|
|
165 |
#if ENABLED(HANGPRINTER)
|
|
|
166 |
|
|
|
167 |
#define enable_A() enable_X()
|
|
|
168 |
#define enable_B() enable_Y()
|
|
|
169 |
#define enable_C() enable_Z()
|
|
|
170 |
#define __D_ENABLE(p) E##p##_ENABLE_WRITE(E_ENABLE_ON)
|
|
|
171 |
#define _D_ENABLE(p) __D_ENABLE(p)
|
|
|
172 |
#define enable_D() _D_ENABLE(EXTRUDERS)
|
|
|
173 |
|
|
|
174 |
// Don't allow any axes to be disabled
|
|
|
175 |
#undef disable_X
|
|
|
176 |
#undef disable_Y
|
|
|
177 |
#undef disable_Z
|
|
|
178 |
#define disable_X() NOOP
|
|
|
179 |
#define disable_Y() NOOP
|
|
|
180 |
#define disable_Z() NOOP
|
|
|
181 |
|
|
|
182 |
#if EXTRUDERS >= 1
|
|
|
183 |
#undef disable_E1
|
|
|
184 |
#define disable_E1() NOOP
|
|
|
185 |
#if EXTRUDERS >= 2
|
|
|
186 |
#undef disable_E2
|
|
|
187 |
#define disable_E2() NOOP
|
|
|
188 |
#if EXTRUDERS >= 3
|
|
|
189 |
#undef disable_E3
|
|
|
190 |
#define disable_E3() NOOP
|
|
|
191 |
#if EXTRUDERS >= 4
|
|
|
192 |
#undef disable_E4
|
|
|
193 |
#define disable_E4() NOOP
|
|
|
194 |
#endif // EXTRUDERS >= 4
|
|
|
195 |
#endif // EXTRUDERS >= 3
|
|
|
196 |
#endif // EXTRUDERS >= 2
|
|
|
197 |
#endif // EXTRUDERS >= 1
|
|
|
198 |
|
|
|
199 |
#endif // HANGPRINTER
|
|
|
200 |
|
|
|
201 |
#if ENABLED(G38_PROBE_TARGET)
|
|
|
202 |
extern bool G38_move, // flag to tell the interrupt handler that a G38 command is being run
|
|
|
203 |
G38_endstop_hit; // flag from the interrupt handler to indicate if the endstop went active
|
|
|
204 |
#endif
|
|
|
205 |
|
|
|
206 |
void enable_all_steppers();
|
|
|
207 |
void disable_e_stepper(const uint8_t e);
|
|
|
208 |
void disable_e_steppers();
|
|
|
209 |
void disable_all_steppers();
|
|
|
210 |
|
|
|
211 |
void sync_plan_position();
|
|
|
212 |
void sync_plan_position_e();
|
|
|
213 |
|
|
|
214 |
#if IS_KINEMATIC
|
|
|
215 |
void sync_plan_position_kinematic();
|
|
|
216 |
#define SYNC_PLAN_POSITION_KINEMATIC() sync_plan_position_kinematic()
|
|
|
217 |
#else
|
|
|
218 |
#define SYNC_PLAN_POSITION_KINEMATIC() sync_plan_position()
|
|
|
219 |
#endif
|
|
|
220 |
|
|
|
221 |
void flush_and_request_resend();
|
|
|
222 |
void ok_to_send();
|
|
|
223 |
|
|
|
224 |
void kill(const char*);
|
|
|
225 |
|
|
|
226 |
void quickstop_stepper();
|
|
|
227 |
|
|
|
228 |
extern uint8_t marlin_debug_flags;
|
|
|
229 |
#define DEBUGGING(F) (marlin_debug_flags & (DEBUG_## F))
|
|
|
230 |
|
|
|
231 |
extern bool Running;
|
|
|
232 |
inline bool IsRunning() { return Running; }
|
|
|
233 |
inline bool IsStopped() { return !Running; }
|
|
|
234 |
|
|
|
235 |
bool enqueue_and_echo_command(const char* cmd); // Add a single command to the end of the buffer. Return false on failure.
|
|
|
236 |
void enqueue_and_echo_commands_P(const char * const cmd); // Set one or more commands to be prioritized over the next Serial/SD command.
|
|
|
237 |
void clear_command_queue();
|
|
|
238 |
|
|
|
239 |
#if ENABLED(M100_FREE_MEMORY_WATCHER) || ENABLED(POWER_LOSS_RECOVERY)
|
|
|
240 |
extern char command_queue[BUFSIZE][MAX_CMD_SIZE];
|
|
|
241 |
#endif
|
|
|
242 |
|
|
|
243 |
#define HAS_LCD_QUEUE_NOW (ENABLED(MALYAN_LCD) || (ENABLED(ULTIPANEL) && (ENABLED(AUTO_BED_LEVELING_UBL) || ENABLED(PID_AUTOTUNE_MENU) || ENABLED(ADVANCED_PAUSE_FEATURE))))
|
|
|
244 |
#define HAS_QUEUE_NOW (ENABLED(SDSUPPORT) || HAS_LCD_QUEUE_NOW)
|
|
|
245 |
#if HAS_QUEUE_NOW
|
|
|
246 |
// Return only when commands are actually enqueued
|
|
|
247 |
void enqueue_and_echo_command_now(const char* cmd);
|
|
|
248 |
#if HAS_LCD_QUEUE_NOW
|
|
|
249 |
void enqueue_and_echo_commands_now_P(const char * const cmd);
|
|
|
250 |
#endif
|
|
|
251 |
#endif
|
|
|
252 |
|
|
|
253 |
extern millis_t previous_move_ms;
|
|
|
254 |
inline void reset_stepper_timeout() { previous_move_ms = millis(); }
|
|
|
255 |
|
|
|
256 |
/**
|
|
|
257 |
* Feedrate scaling and conversion
|
|
|
258 |
*/
|
|
|
259 |
extern float feedrate_mm_s;
|
|
|
260 |
extern int16_t feedrate_percentage;
|
|
|
261 |
|
|
|
262 |
#define MMS_SCALED(MM_S) ((MM_S)*feedrate_percentage*0.01f)
|
|
|
263 |
|
|
|
264 |
extern bool axis_relative_modes[XYZE];
|
|
|
265 |
|
|
|
266 |
extern uint8_t axis_homed, axis_known_position;
|
|
|
267 |
|
|
|
268 |
constexpr uint8_t xyz_bits = _BV(X_AXIS) | _BV(Y_AXIS) | _BV(Z_AXIS);
|
|
|
269 |
FORCE_INLINE bool all_axes_homed() { return (axis_homed & xyz_bits) == xyz_bits; }
|
|
|
270 |
FORCE_INLINE bool all_axes_known() { return (axis_known_position & xyz_bits) == xyz_bits; }
|
|
|
271 |
|
|
|
272 |
extern volatile bool wait_for_heatup;
|
|
|
273 |
|
|
|
274 |
#if HAS_RESUME_CONTINUE
|
|
|
275 |
extern volatile bool wait_for_user;
|
|
|
276 |
#endif
|
|
|
277 |
|
|
|
278 |
#if HAS_AUTO_REPORTING || ENABLED(HOST_KEEPALIVE_FEATURE)
|
|
|
279 |
extern bool suspend_auto_report;
|
|
|
280 |
#endif
|
|
|
281 |
|
|
|
282 |
extern float current_position[XYZE], destination[XYZE];
|
|
|
283 |
|
|
|
284 |
/**
|
|
|
285 |
* Workspace offsets
|
|
|
286 |
*/
|
|
|
287 |
#if HAS_WORKSPACE_OFFSET
|
|
|
288 |
#if HAS_HOME_OFFSET
|
|
|
289 |
extern float home_offset[XYZ];
|
|
|
290 |
#endif
|
|
|
291 |
#if HAS_POSITION_SHIFT
|
|
|
292 |
extern float position_shift[XYZ];
|
|
|
293 |
#endif
|
|
|
294 |
#if HAS_HOME_OFFSET && HAS_POSITION_SHIFT
|
|
|
295 |
extern float workspace_offset[XYZ];
|
|
|
296 |
#define WORKSPACE_OFFSET(AXIS) workspace_offset[AXIS]
|
|
|
297 |
#elif HAS_HOME_OFFSET
|
|
|
298 |
#define WORKSPACE_OFFSET(AXIS) home_offset[AXIS]
|
|
|
299 |
#elif HAS_POSITION_SHIFT
|
|
|
300 |
#define WORKSPACE_OFFSET(AXIS) position_shift[AXIS]
|
|
|
301 |
#endif
|
|
|
302 |
#define NATIVE_TO_LOGICAL(POS, AXIS) ((POS) + WORKSPACE_OFFSET(AXIS))
|
|
|
303 |
#define LOGICAL_TO_NATIVE(POS, AXIS) ((POS) - WORKSPACE_OFFSET(AXIS))
|
|
|
304 |
#else
|
|
|
305 |
#define NATIVE_TO_LOGICAL(POS, AXIS) (POS)
|
|
|
306 |
#define LOGICAL_TO_NATIVE(POS, AXIS) (POS)
|
|
|
307 |
#endif
|
|
|
308 |
#define LOGICAL_X_POSITION(POS) NATIVE_TO_LOGICAL(POS, X_AXIS)
|
|
|
309 |
#define LOGICAL_Y_POSITION(POS) NATIVE_TO_LOGICAL(POS, Y_AXIS)
|
|
|
310 |
#define LOGICAL_Z_POSITION(POS) NATIVE_TO_LOGICAL(POS, Z_AXIS)
|
|
|
311 |
#define RAW_X_POSITION(POS) LOGICAL_TO_NATIVE(POS, X_AXIS)
|
|
|
312 |
#define RAW_Y_POSITION(POS) LOGICAL_TO_NATIVE(POS, Y_AXIS)
|
|
|
313 |
#define RAW_Z_POSITION(POS) LOGICAL_TO_NATIVE(POS, Z_AXIS)
|
|
|
314 |
|
|
|
315 |
// Hotend Offsets
|
|
|
316 |
#if HOTENDS > 1
|
|
|
317 |
extern float hotend_offset[XYZ][HOTENDS];
|
|
|
318 |
#endif
|
|
|
319 |
|
|
|
320 |
// Software Endstops
|
|
|
321 |
extern float soft_endstop_min[XYZ], soft_endstop_max[XYZ];
|
|
|
322 |
|
|
|
323 |
#if HAS_SOFTWARE_ENDSTOPS
|
|
|
324 |
extern bool soft_endstops_enabled;
|
|
|
325 |
void clamp_to_software_endstops(float target[XYZ]);
|
|
|
326 |
#else
|
|
|
327 |
#define soft_endstops_enabled false
|
|
|
328 |
#define clamp_to_software_endstops(x) NOOP
|
|
|
329 |
#endif
|
|
|
330 |
|
|
|
331 |
#if HAS_WORKSPACE_OFFSET || ENABLED(DUAL_X_CARRIAGE)
|
|
|
332 |
void update_software_endstops(const AxisEnum axis);
|
|
|
333 |
#endif
|
|
|
334 |
|
|
|
335 |
#define MAX_COORDINATE_SYSTEMS 9
|
|
|
336 |
#if ENABLED(CNC_COORDINATE_SYSTEMS)
|
|
|
337 |
extern float coordinate_system[MAX_COORDINATE_SYSTEMS][XYZ];
|
|
|
338 |
bool select_coordinate_system(const int8_t _new);
|
|
|
339 |
#endif
|
|
|
340 |
|
|
|
341 |
void tool_change(const uint8_t tmp_extruder, const float fr_mm_s=0.0, bool no_move=false);
|
|
|
342 |
|
|
|
343 |
void home_all_axes();
|
|
|
344 |
|
|
|
345 |
void report_current_position();
|
|
|
346 |
|
|
|
347 |
#if IS_KINEMATIC
|
|
|
348 |
#if ENABLED(HANGPRINTER)
|
|
|
349 |
extern float line_lengths[ABCD];
|
|
|
350 |
#else
|
|
|
351 |
extern float delta[ABC];
|
|
|
352 |
#endif
|
|
|
353 |
void inverse_kinematics(const float raw[XYZ]);
|
|
|
354 |
#endif
|
|
|
355 |
|
|
|
356 |
#if ENABLED(DELTA)
|
|
|
357 |
extern float delta_height,
|
|
|
358 |
delta_endstop_adj[ABC],
|
|
|
359 |
delta_radius,
|
|
|
360 |
delta_tower_angle_trim[ABC],
|
|
|
361 |
delta_tower[ABC][2],
|
|
|
362 |
delta_diagonal_rod,
|
|
|
363 |
delta_calibration_radius,
|
|
|
364 |
delta_diagonal_rod_2_tower[ABC],
|
|
|
365 |
delta_segments_per_second,
|
|
|
366 |
delta_clip_start_height;
|
|
|
367 |
|
|
|
368 |
void recalc_delta_settings();
|
|
|
369 |
float delta_safe_distance_from_top();
|
|
|
370 |
|
|
|
371 |
// Macro to obtain the Z position of an individual tower
|
|
|
372 |
#define DELTA_Z(V,T) V[Z_AXIS] + SQRT( \
|
|
|
373 |
delta_diagonal_rod_2_tower[T] - HYPOT2( \
|
|
|
374 |
delta_tower[T][X_AXIS] - V[X_AXIS], \
|
|
|
375 |
delta_tower[T][Y_AXIS] - V[Y_AXIS] \
|
|
|
376 |
) \
|
|
|
377 |
)
|
|
|
378 |
|
|
|
379 |
#define DELTA_IK(V) do { \
|
|
|
380 |
delta[A_AXIS] = DELTA_Z(V, A_AXIS); \
|
|
|
381 |
delta[B_AXIS] = DELTA_Z(V, B_AXIS); \
|
|
|
382 |
delta[C_AXIS] = DELTA_Z(V, C_AXIS); \
|
|
|
383 |
}while(0)
|
|
|
384 |
|
|
|
385 |
#elif ENABLED(HANGPRINTER)
|
|
|
386 |
|
|
|
387 |
// Don't collect anchor positions in array because there are no A_x, D_x or D_y
|
|
|
388 |
extern float anchor_A_y,
|
|
|
389 |
anchor_A_z,
|
|
|
390 |
anchor_B_x,
|
|
|
391 |
anchor_B_y,
|
|
|
392 |
anchor_B_z,
|
|
|
393 |
anchor_C_x,
|
|
|
394 |
anchor_C_y,
|
|
|
395 |
anchor_C_z,
|
|
|
396 |
anchor_D_z,
|
|
|
397 |
delta_segments_per_second,
|
|
|
398 |
line_lengths_origin[ABCD];
|
|
|
399 |
|
|
|
400 |
void recalc_hangprinter_settings();
|
|
|
401 |
|
|
|
402 |
#define HANGPRINTER_IK(V) do { \
|
|
|
403 |
line_lengths[A_AXIS] = SQRT(sq(anchor_A_z - V[Z_AXIS]) \
|
|
|
404 |
+ sq(anchor_A_y - V[Y_AXIS]) \
|
|
|
405 |
+ sq( V[X_AXIS])); \
|
|
|
406 |
line_lengths[B_AXIS] = SQRT(sq(anchor_B_z - V[Z_AXIS]) \
|
|
|
407 |
+ sq(anchor_B_y - V[Y_AXIS]) \
|
|
|
408 |
+ sq(anchor_B_x - V[X_AXIS])); \
|
|
|
409 |
line_lengths[C_AXIS] = SQRT(sq(anchor_C_z - V[Z_AXIS]) \
|
|
|
410 |
+ sq(anchor_C_y - V[Y_AXIS]) \
|
|
|
411 |
+ sq(anchor_C_x - V[X_AXIS])); \
|
|
|
412 |
line_lengths[D_AXIS] = SQRT(sq( V[X_AXIS]) \
|
|
|
413 |
+ sq( V[Y_AXIS]) \
|
|
|
414 |
+ sq(anchor_D_z - V[Z_AXIS])); \
|
|
|
415 |
}while(0)
|
|
|
416 |
|
|
|
417 |
// Inverse kinematics at origin
|
|
|
418 |
#define HANGPRINTER_IK_ORIGIN(LL) do { \
|
|
|
419 |
LL[A_AXIS] = SQRT(sq(anchor_A_z) \
|
|
|
420 |
+ sq(anchor_A_y)); \
|
|
|
421 |
LL[B_AXIS] = SQRT(sq(anchor_B_z) \
|
|
|
422 |
+ sq(anchor_B_y) \
|
|
|
423 |
+ sq(anchor_B_x)); \
|
|
|
424 |
LL[C_AXIS] = SQRT(sq(anchor_C_z) \
|
|
|
425 |
+ sq(anchor_C_y) \
|
|
|
426 |
+ sq(anchor_C_x)); \
|
|
|
427 |
LL[D_AXIS] = anchor_D_z; \
|
|
|
428 |
}while(0)
|
|
|
429 |
|
|
|
430 |
#elif IS_SCARA
|
|
|
431 |
void forward_kinematics_SCARA(const float &a, const float &b);
|
|
|
432 |
#endif
|
|
|
433 |
|
|
|
434 |
#if ENABLED(G26_MESH_VALIDATION)
|
|
|
435 |
extern bool g26_debug_flag;
|
|
|
436 |
#elif ENABLED(AUTO_BED_LEVELING_UBL)
|
|
|
437 |
constexpr bool g26_debug_flag = false;
|
|
|
438 |
#endif
|
|
|
439 |
|
|
|
440 |
#if ENABLED(AUTO_BED_LEVELING_BILINEAR)
|
|
|
441 |
#define _GET_MESH_X(I) (bilinear_start[X_AXIS] + (I) * bilinear_grid_spacing[X_AXIS])
|
|
|
442 |
#define _GET_MESH_Y(J) (bilinear_start[Y_AXIS] + (J) * bilinear_grid_spacing[Y_AXIS])
|
|
|
443 |
#elif ENABLED(AUTO_BED_LEVELING_UBL)
|
|
|
444 |
#define _GET_MESH_X(I) ubl.mesh_index_to_xpos(I)
|
|
|
445 |
#define _GET_MESH_Y(J) ubl.mesh_index_to_ypos(J)
|
|
|
446 |
#elif ENABLED(MESH_BED_LEVELING)
|
|
|
447 |
#define _GET_MESH_X(I) mbl.index_to_xpos[I]
|
|
|
448 |
#define _GET_MESH_Y(J) mbl.index_to_ypos[J]
|
|
|
449 |
#endif
|
|
|
450 |
|
|
|
451 |
#if ENABLED(AUTO_BED_LEVELING_BILINEAR)
|
|
|
452 |
extern int bilinear_grid_spacing[2], bilinear_start[2];
|
|
|
453 |
extern float bilinear_grid_factor[2],
|
|
|
454 |
z_values[GRID_MAX_POINTS_X][GRID_MAX_POINTS_Y];
|
|
|
455 |
float bilinear_z_offset(const float raw[XYZ]);
|
|
|
456 |
#endif
|
|
|
457 |
|
|
|
458 |
#if ENABLED(AUTO_BED_LEVELING_BILINEAR) || ENABLED(MESH_BED_LEVELING)
|
|
|
459 |
typedef float (*element_2d_fn)(const uint8_t, const uint8_t);
|
|
|
460 |
void print_2d_array(const uint8_t sx, const uint8_t sy, const uint8_t precision, const element_2d_fn fn);
|
|
|
461 |
#endif
|
|
|
462 |
|
|
|
463 |
#if HAS_LEVELING
|
|
|
464 |
bool leveling_is_valid();
|
|
|
465 |
void set_bed_leveling_enabled(const bool enable=true);
|
|
|
466 |
void reset_bed_level();
|
|
|
467 |
#endif
|
|
|
468 |
|
|
|
469 |
#if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
|
|
|
470 |
void set_z_fade_height(const float zfh, const bool do_report=true);
|
|
|
471 |
#endif
|
|
|
472 |
|
|
|
473 |
#if HAS_BED_PROBE
|
|
|
474 |
extern float zprobe_zoffset;
|
|
|
475 |
bool set_probe_deployed(const bool deploy);
|
|
|
476 |
#ifdef Z_AFTER_PROBING
|
|
|
477 |
void move_z_after_probing();
|
|
|
478 |
#endif
|
|
|
479 |
enum ProbePtRaise : unsigned char {
|
|
|
480 |
PROBE_PT_NONE, // No raise or stow after run_z_probe
|
|
|
481 |
PROBE_PT_STOW, // Do a complete stow after run_z_probe
|
|
|
482 |
PROBE_PT_RAISE, // Raise to "between" clearance after run_z_probe
|
|
|
483 |
PROBE_PT_BIG_RAISE // Raise to big clearance after run_z_probe
|
|
|
484 |
};
|
|
|
485 |
float probe_pt(const float &rx, const float &ry, const ProbePtRaise raise_after=PROBE_PT_NONE, const uint8_t verbose_level=0, const bool probe_relative=true);
|
|
|
486 |
#define DEPLOY_PROBE() set_probe_deployed(true)
|
|
|
487 |
#define STOW_PROBE() set_probe_deployed(false)
|
|
|
488 |
#else
|
|
|
489 |
#define DEPLOY_PROBE()
|
|
|
490 |
#define STOW_PROBE()
|
|
|
491 |
#endif
|
|
|
492 |
|
|
|
493 |
#if ENABLED(HOST_KEEPALIVE_FEATURE)
|
|
|
494 |
extern MarlinBusyState busy_state;
|
|
|
495 |
#define KEEPALIVE_STATE(n) do{ busy_state = n; }while(0)
|
|
|
496 |
#else
|
|
|
497 |
#define KEEPALIVE_STATE(n) NOOP
|
|
|
498 |
#endif
|
|
|
499 |
|
|
|
500 |
#if FAN_COUNT > 0
|
|
|
501 |
extern int16_t fanSpeeds[FAN_COUNT];
|
|
|
502 |
#if ENABLED(EXTRA_FAN_SPEED)
|
|
|
503 |
extern int16_t old_fanSpeeds[FAN_COUNT],
|
|
|
504 |
new_fanSpeeds[FAN_COUNT];
|
|
|
505 |
#endif
|
|
|
506 |
#if ENABLED(PROBING_FANS_OFF)
|
|
|
507 |
extern bool fans_paused;
|
|
|
508 |
extern int16_t paused_fanSpeeds[FAN_COUNT];
|
|
|
509 |
#endif
|
|
|
510 |
#endif
|
|
|
511 |
|
|
|
512 |
#if ENABLED(USE_CONTROLLER_FAN)
|
|
|
513 |
extern int controllerFanSpeed;
|
|
|
514 |
#endif
|
|
|
515 |
|
|
|
516 |
#if ENABLED(BARICUDA)
|
|
|
517 |
extern uint8_t baricuda_valve_pressure, baricuda_e_to_p_pressure;
|
|
|
518 |
#endif
|
|
|
519 |
|
|
|
520 |
#if ENABLED(FILAMENT_WIDTH_SENSOR)
|
|
|
521 |
extern bool filament_sensor; // Flag that filament sensor readings should control extrusion
|
|
|
522 |
extern float filament_width_nominal, // Theoretical filament diameter i.e., 3.00 or 1.75
|
|
|
523 |
filament_width_meas; // Measured filament diameter
|
|
|
524 |
extern uint8_t meas_delay_cm; // Delay distance
|
|
|
525 |
extern int8_t measurement_delay[MAX_MEASUREMENT_DELAY + 1], // Ring buffer to delay measurement
|
|
|
526 |
filwidth_delay_index[2]; // Ring buffer indexes. Used by planner, temperature, and main code
|
|
|
527 |
#endif
|
|
|
528 |
|
|
|
529 |
#if ENABLED(ADVANCED_PAUSE_FEATURE)
|
|
|
530 |
extern int8_t did_pause_print;
|
|
|
531 |
extern AdvancedPauseMenuResponse advanced_pause_menu_response;
|
|
|
532 |
extern float filament_change_unload_length[EXTRUDERS],
|
|
|
533 |
filament_change_load_length[EXTRUDERS];
|
|
|
534 |
#endif
|
|
|
535 |
|
|
|
536 |
#if HAS_POWER_SWITCH
|
|
|
537 |
extern bool powersupply_on;
|
|
|
538 |
#define PSU_PIN_ON() do{ OUT_WRITE(PS_ON_PIN, PS_ON_AWAKE); powersupply_on = true; }while(0)
|
|
|
539 |
#define PSU_PIN_OFF() do{ OUT_WRITE(PS_ON_PIN, PS_ON_ASLEEP); powersupply_on = false; }while(0)
|
|
|
540 |
#endif
|
|
|
541 |
|
|
|
542 |
// Handling multiple extruders pins
|
|
|
543 |
extern uint8_t active_extruder;
|
|
|
544 |
|
|
|
545 |
#if ENABLED(MIXING_EXTRUDER)
|
|
|
546 |
extern float mixing_factor[MIXING_STEPPERS];
|
|
|
547 |
#endif
|
|
|
548 |
|
|
|
549 |
inline void set_current_from_destination() { COPY(current_position, destination); }
|
|
|
550 |
inline void set_destination_from_current() { COPY(destination, current_position); }
|
|
|
551 |
void prepare_move_to_destination();
|
|
|
552 |
|
|
|
553 |
/**
|
|
|
554 |
* Blocking movement and shorthand functions
|
|
|
555 |
*/
|
|
|
556 |
void do_blocking_move_to(const float rx, const float ry, const float rz, const float &fr_mm_s=0);
|
|
|
557 |
void do_blocking_move_to_x(const float &rx, const float &fr_mm_s=0);
|
|
|
558 |
void do_blocking_move_to_z(const float &rz, const float &fr_mm_s=0);
|
|
|
559 |
void do_blocking_move_to_xy(const float &rx, const float &ry, const float &fr_mm_s=0);
|
|
|
560 |
|
|
|
561 |
#if ENABLED(ARC_SUPPORT)
|
|
|
562 |
void plan_arc(const float(&cart)[XYZE], const float(&offset)[2], const bool clockwise);
|
|
|
563 |
#endif
|
|
|
564 |
|
|
|
565 |
#define HAS_AXIS_UNHOMED_ERR ( \
|
|
|
566 |
ENABLED(Z_PROBE_ALLEN_KEY) \
|
|
|
567 |
|| ENABLED(Z_PROBE_SLED) \
|
|
|
568 |
|| HAS_PROBING_PROCEDURE \
|
|
|
569 |
|| HOTENDS > 1 \
|
|
|
570 |
|| ENABLED(NOZZLE_CLEAN_FEATURE) \
|
|
|
571 |
|| ENABLED(NOZZLE_PARK_FEATURE) \
|
|
|
572 |
|| (ENABLED(ADVANCED_PAUSE_FEATURE) && ENABLED(HOME_BEFORE_FILAMENT_CHANGE)) \
|
|
|
573 |
|| HAS_M206_COMMAND \
|
|
|
574 |
) || ENABLED(NO_MOTION_BEFORE_HOMING)
|
|
|
575 |
|
|
|
576 |
#if HAS_AXIS_UNHOMED_ERR
|
|
|
577 |
bool axis_unhomed_error(const bool x=true, const bool y=true, const bool z=true);
|
|
|
578 |
#endif
|
|
|
579 |
|
|
|
580 |
/**
|
|
|
581 |
* position_is_reachable family of functions
|
|
|
582 |
*/
|
|
|
583 |
|
|
|
584 |
#if IS_KINEMATIC // (DELTA or SCARA)
|
|
|
585 |
|
|
|
586 |
#if IS_SCARA
|
|
|
587 |
extern const float L1, L2;
|
|
|
588 |
#endif
|
|
|
589 |
|
|
|
590 |
// Return true if the given point is within the printable area
|
|
|
591 |
inline bool position_is_reachable(const float &rx, const float &ry, const float inset=0) {
|
|
|
592 |
#if ENABLED(DELTA)
|
|
|
593 |
return HYPOT2(rx, ry) <= sq(DELTA_PRINTABLE_RADIUS - inset);
|
|
|
594 |
#elif ENABLED(HANGPRINTER)
|
|
|
595 |
// TODO: This is over simplified. Hangprinter's build volume is _not_ cylindrical.
|
|
|
596 |
return HYPOT2(rx, ry) <= sq(HANGPRINTER_PRINTABLE_RADIUS - inset);
|
|
|
597 |
#elif IS_SCARA
|
|
|
598 |
const float R2 = HYPOT2(rx - SCARA_OFFSET_X, ry - SCARA_OFFSET_Y);
|
|
|
599 |
return (
|
|
|
600 |
R2 <= sq(L1 + L2) - inset
|
|
|
601 |
#if MIDDLE_DEAD_ZONE_R > 0
|
|
|
602 |
&& R2 >= sq(float(MIDDLE_DEAD_ZONE_R))
|
|
|
603 |
#endif
|
|
|
604 |
);
|
|
|
605 |
#endif
|
|
|
606 |
}
|
|
|
607 |
|
|
|
608 |
#if HAS_BED_PROBE
|
|
|
609 |
// Return true if the both nozzle and the probe can reach the given point.
|
|
|
610 |
// Note: This won't work on SCARA since the probe offset rotates with the arm.
|
|
|
611 |
inline bool position_is_reachable_by_probe(const float &rx, const float &ry) {
|
|
|
612 |
return position_is_reachable(rx - (X_PROBE_OFFSET_FROM_EXTRUDER), ry - (Y_PROBE_OFFSET_FROM_EXTRUDER))
|
|
|
613 |
&& position_is_reachable(rx, ry, ABS(MIN_PROBE_EDGE));
|
|
|
614 |
}
|
|
|
615 |
#endif
|
|
|
616 |
|
|
|
617 |
#else // CARTESIAN
|
|
|
618 |
|
|
|
619 |
// Return true if the given position is within the machine bounds.
|
|
|
620 |
inline bool position_is_reachable(const float &rx, const float &ry) {
|
|
|
621 |
// Add 0.001 margin to deal with float imprecision
|
|
|
622 |
return WITHIN(rx, X_MIN_POS - 0.001f, X_MAX_POS + 0.001f)
|
|
|
623 |
&& WITHIN(ry, Y_MIN_POS - 0.001f, Y_MAX_POS + 0.001f);
|
|
|
624 |
}
|
|
|
625 |
|
|
|
626 |
#if HAS_BED_PROBE
|
|
|
627 |
/**
|
|
|
628 |
* Return whether the given position is within the bed, and whether the nozzle
|
|
|
629 |
* can reach the position required to put the probe at the given position.
|
|
|
630 |
*
|
|
|
631 |
* Example: For a probe offset of -10,+10, then for the probe to reach 0,0 the
|
|
|
632 |
* nozzle must be be able to reach +10,-10.
|
|
|
633 |
*/
|
|
|
634 |
inline bool position_is_reachable_by_probe(const float &rx, const float &ry) {
|
|
|
635 |
return position_is_reachable(rx - (X_PROBE_OFFSET_FROM_EXTRUDER), ry - (Y_PROBE_OFFSET_FROM_EXTRUDER))
|
|
|
636 |
&& WITHIN(rx, MIN_PROBE_X - 0.001f, MAX_PROBE_X + 0.001f)
|
|
|
637 |
&& WITHIN(ry, MIN_PROBE_Y - 0.001f, MAX_PROBE_Y + 0.001f);
|
|
|
638 |
}
|
|
|
639 |
#endif
|
|
|
640 |
|
|
|
641 |
#endif // CARTESIAN
|
|
|
642 |
|
|
|
643 |
#if !HAS_BED_PROBE
|
|
|
644 |
FORCE_INLINE bool position_is_reachable_by_probe(const float &rx, const float &ry) { return position_is_reachable(rx, ry); }
|
|
|
645 |
#endif
|
|
|
646 |
|
|
|
647 |
#endif // MARLIN_H
|