Fri, 17 Nov 2017 10:13:31 +0100
proper configuration, homing and planner optimization
0 | 1 | /* |
2 | Reprap firmware based on Sprinter and grbl. | |
3 | Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm | |
4 | ||
5 | This program is free software: you can redistribute it and/or modify | |
6 | it under the terms of the GNU General Public License as published by | |
7 | the Free Software Foundation, either version 3 of the License, or | |
8 | (at your option) any later version. | |
9 | ||
10 | This program is distributed in the hope that it will be useful, | |
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
13 | GNU General Public License for more details. | |
14 | ||
15 | You should have received a copy of the GNU General Public License | |
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | |
17 | */ | |
18 | ||
19 | /* | |
20 | This firmware is a mashup between Sprinter and grbl. | |
21 | (https://github.com/kliment/Sprinter) | |
22 | (https://github.com/simen/grbl/tree) | |
23 | ||
24 | It has preliminary support for Matthew Roberts advance algorithm | |
25 | http://reprap.org/pipermail/reprap-dev/2011-May/003323.html | |
26 | */ | |
27 | ||
28 | /* | |
29 | RepRapPro ammendations, deletions and additions | |
30 | ||
31 | G10, M0, M1, M112 and T commands added/modified by AB 18/7/12 | |
32 | Much conditional-compiled code for old/unused hardware removed - AB 29/7/12 | |
33 | ||
34 | */ | |
35 | ||
36 | /* | |
37 | NeoSoft modifications: | |
38 | ||
39 | Implement: | |
40 | - M571 to enable PWM on extruder Movement (laser modulation support), second E parameter to disable real E drive | |
41 | - MXXX to enable Emergency Stop button (if disabled the button can be used to programmatically pause the lasercut for user interaction. For example: | |
42 | move to bottom left of print rectangle, ask user to align workpiece (wait for button press), then move to bottom right and ask user to align the other workpiece end, wait for button press to start engraving... | |
43 | ||
44 | EXT PINS: | |
45 | 30, 29,28 = EXT1-3, 27=EXT4=LED | |
46 | ||
47 | M571 pin default to EXT3 (PIN 28) in pins.h | |
48 | ||
49 | Emergency Stop (PAUSE) button on EXT2 (PIN 29): | |
50 | If not stopped: call stop() | |
51 | If stopped: execute code from M999 Command (do not inject M999, execute the code!) | |
52 | // bool x_min_endstop=(READ(X_MIN_PIN) != X_ENDSTOPS_INVERTING); | |
53 | //pinMode(inPin, INPUT); | |
54 | ||
55 | alternative approach (better?): | |
56 | make copy of "void enquecommand(const char *cmd)" with following behaviour: | |
57 | - pause serial receiver enqueueing (the irq should respond like "buffer full") | |
58 | - call alternative of stop() which memorizes the last PROCESSED line? | |
59 | */ | |
60 | ||
61 | #include "Marlin.h" | |
62 | ||
63 | #include "ultralcd.h" | |
64 | #include "led.h" | |
65 | #include "z_probe.h" | |
66 | #include "FPUTransform.h" | |
67 | #include "planner.h" | |
68 | #include "stepper.h" | |
69 | #include "temperature.h" | |
70 | #include "motion_control.h" | |
71 | #include "cardreader.h" | |
72 | #include "EEPROMwrite.h" | |
73 | #include "language.h" | |
74 | #include "pins_arduino.h" | |
75 | #include "slave_comms.h" | |
76 | ||
3 | 77 | #define VERSION_STRING "1.0.2 RRP/NeoSoft\nModified for ERFH - Engraving Robot From Hell" |
0 | 78 | |
79 | // look here for descriptions of gcodes: http://linuxcnc.org/handbook/gcode/g-code.html | |
80 | // http://objects.reprap.org/wiki/Mendel_User_Manual:_RepRapGCodes | |
81 | ||
82 | //Implemented Codes | |
83 | //------------------- | |
84 | // G0 -> G1 | |
85 | // G1 - Coordinated Movement X Y Z E | |
86 | // G2 - CW ARC | |
87 | // G3 - CCW ARC | |
88 | // G4 - Dwell S<seconds> or P<milliseconds> | |
89 | // G10 - set head offset and temps | |
90 | // G28 - Home all Axis | |
91 | // G29 - Detailed Z-Probe (3 location test) | |
92 | // G30 - Single Z Probe (probe current location) | |
93 | // G31 - Report Curent Probe status | |
94 | // G32 - Probe Z and calibrate with FPU | |
95 | // G90 - Use Absolute Coordinates | |
96 | // G91 - Use Relative Coordinates | |
97 | // G92 - Set current position to cordinates given | |
98 | ||
99 | //RepRap M Codes | |
100 | // M104 - Set extruder target temp (deprecated) | |
101 | // M105 - Read current temp | |
102 | // M106 - Fan on | |
103 | // M107 - Fan off | |
104 | // M109 - Wait for extruder current temp to reach target temp. (deprecated) | |
105 | // M114 - Display current position | |
106 | ||
107 | //Custom M Codes | |
108 | // M17 - Enable/Power all stepper motors | |
109 | // M18 - Disable all stepper motors; same as M84 | |
110 | // M20 - List SD card | |
111 | // M21 - Init SD card | |
112 | // M22 - Release SD card | |
113 | // M23 - Select SD file (M23 filename.g) | |
114 | // M24 - Start/resume SD print | |
115 | // M25 - Pause SD print | |
116 | // M26 - Set SD position in bytes (M26 S12345) | |
117 | // M27 - Report SD print status | |
118 | // M28 - Start SD write (M28 filename.g) | |
119 | // M29 - Stop SD write | |
120 | // M30 - Fast SD transfer | |
121 | // M31 - high speed xfer capabilities | |
122 | // M35 - Output time since last M109 or SD card start to serial | |
123 | ||
124 | // M42 - Change pin status via gcode | |
125 | // M82 - Set E codes absolute (default) | |
126 | // M83 - Set E codes relative while in Absolute Coordinates (G90) mode | |
127 | // M84 - Disable steppers until next move, | |
128 | // or use S<seconds> to specify an inactivity timeout, after which the steppers will be disabled. S0 to disable the timeout. | |
129 | // M85 - Set inactivity shutdown timer with parameter S<seconds>. To disable set zero (default) | |
130 | // M92 - Set axis_steps_per_unit - same syntax as G92 | |
131 | // M114 - Output current position to serial port | |
132 | // M115 - Capabilities string | |
133 | // M117 - display message | |
134 | // M119 - Output Endstop status to serial port | |
135 | // M140 - Set bed target temp | |
136 | // M190 - Wait for bed current temp to reach target temp. | |
137 | // M200 - Set filament diameter | |
138 | // M201 - Set max acceleration in units/s^2 for print moves (M201 X1000 Y1000) | |
139 | // M202 - Set max acceleration in units/s^2 for travel moves (M202 X1000 Y1000) Unused in Marlin!! | |
140 | // M203 - Set maximum feedrate that your machine can sustain (M203 X200 Y200 Z300 E10000) in mm/sec | |
141 | // M204 - Set default acceleration: S normal moves T filament only moves (M204 S3000 T7000) im mm/sec^2 also sets minimum segment time in ms (B20000) to prevent buffer underruns and M20 minimum feedrate | |
142 | // M205 - advanced settings: minimum travel speed S=while printing T=travel only, B=minimum segment time X= maximum xy jerk, Z=maximum Z jerk, E=maximum E jerk | |
143 | // M206 - set additional homeing offset | |
144 | // M208 - set axis max length | |
145 | // M220 S<factor in percent>- set speed factor override percentage | |
146 | // M221 S<factor in percent>- set extrude factor override percentage | |
147 | // M240 - Trigger a camera to take a photograph | |
148 | // M301 - Set PID parameters P I D and W | |
149 | // M302 - S1 Allow cold extrudes, S0 cold extrues not allowed (default) | |
150 | // M303 - PID relay autotune S<temperature> sets the target temperature. (default target temperature = 150C) | |
151 | // M304 - Set thermistor parameters | |
152 | // M400 - Finish all moves | |
153 | // M500 - stores paramters in EEPROM | |
154 | // M501 - reads parameters from EEPROM (if you need reset them after you changed them temporarily). | |
155 | // M502 - reverts to the default "factory settings". You still need to store them in EEPROM afterwards if you want to. | |
156 | // M503 - print the current settings (from memory not from eeprom) | |
157 | // M510 - FPU Enable | |
158 | // M511 - FPU Reset | |
159 | // M512 - FPU Disable | |
160 | // M999 - Restart after being stopped by error | |
161 | ||
162 | // M555 - Temporary: master/slave comms test | |
163 | ||
164 | // TN - Select extruder N | |
165 | ||
166 | //Stepper Movement Variables | |
167 | ||
168 | //=========================================================================== | |
169 | //=============================imported variables============================ | |
170 | //=========================================================================== | |
171 | ||
172 | ||
173 | //=========================================================================== | |
174 | //=============================public variables============================= | |
175 | //=========================================================================== | |
176 | #ifdef SDSUPPORT | |
177 | CardReader card; | |
178 | #endif | |
179 | float homing_feedrate[] = HOMING_FEEDRATE; | |
180 | float fast_home_feedrate[] = FAST_HOME_FEEDRATE; | |
181 | bool axis_relative_modes[] = AXIS_RELATIVE_MODES; | |
182 | volatile int feedmultiply=100; //100->1 200->2 | |
183 | int saved_feedmultiply; | |
184 | volatile bool feedmultiplychanged=false; | |
185 | volatile int extrudemultiply=100; //100->1 200->2 | |
186 | float current_position[NUM_AXIS] = { 0.0, 0.0, 0.0, 0.0 }; | |
187 | float add_homeing[3]={0,0,0}; | |
188 | float max_length[] = AXES_MAX_LENGTHS; | |
189 | #ifdef ADVANCE | |
190 | float advance_k = EXTRUDER_ADVANCE_K; | |
191 | #endif | |
192 | uint8_t active_extruder = 0; | |
193 | float extruder_x_off[EXTRUDERS]; | |
194 | float extruder_y_off[EXTRUDERS]; | |
195 | float extruder_z_off[EXTRUDERS]; | |
196 | float extruder_standby[EXTRUDERS]; | |
197 | float extruder_temperature[EXTRUDERS]; | |
198 | float x_off_d; | |
199 | float y_off_d; | |
200 | float z_off_d; | |
201 | float temp_position[NUM_AXIS] = { 0.0, 0.0, 0.0, 0.0 }; | |
202 | bool extruder_selected=false; | |
203 | ||
204 | ||
205 | unsigned char FanSpeed=0; | |
206 | bool m571_enabled = 0; | |
207 | bool n571_enabled = 0; | |
208 | ||
209 | float destination[NUM_AXIS] = { 0.0, 0.0, 0.0, 0.0}; | |
210 | float offset[3] = {0.0, 0.0, 0.0}; | |
211 | float feedrate = 1500.0, next_feedrate, saved_feedrate; | |
212 | ||
213 | // used by FPU transform code | |
214 | float modified_destination[NUM_AXIS] = { 0.0, 0.0, 0.0, 0.0}; | |
215 | ||
216 | //=========================================================================== | |
217 | //=============================private variables============================= | |
218 | //=========================================================================== | |
219 | const char axis_codes[NUM_AXIS] = {'X', 'Y', 'Z', 'E'}; | |
220 | static bool home_all_axis = true; | |
221 | static long gcode_N, gcode_LastN, Stopped_gcode_LastN = 0; | |
222 | ||
223 | static bool relative_mode = false; //Determines Absolute or Relative Coordinates | |
224 | static bool relative_mode_e = false; //Determines Absolute or Relative E Codes while in Absolute Coordinates mode. E is always relative in Relative Coordinates mode. | |
225 | ||
226 | static char cmdbuffer[BUFSIZE][MAX_CMD_SIZE]; | |
227 | static bool fromsd[BUFSIZE]; | |
228 | static int bufindr = 0; | |
229 | static int bufindw = 0; | |
230 | static int buflen = 0; | |
231 | //static int i = 0; | |
232 | static char serial_char; | |
233 | static int serial_count = 0; | |
234 | static boolean comment_mode = false; | |
235 | static char *strchr_pointer; // just a pointer to find chars in the cmd string like X, Y, Z, E, etc | |
236 | ||
237 | const int sensitive_pins[] = SENSITIVE_PINS; // Sensitive pin list for M42 | |
238 | ||
239 | //static float tt = 0; | |
240 | //static float bt = 0; | |
241 | ||
242 | //Inactivity shutdown variables | |
243 | static unsigned long previous_millis_cmd = 0; | |
244 | static unsigned long max_inactive_time = 0; | |
245 | static unsigned long stepper_inactive_time = DEFAULT_STEPPER_DEACTIVE_TIME*1000l; | |
246 | ||
247 | static unsigned long starttime=0; | |
248 | static unsigned long stoptime=0; | |
249 | ||
250 | static uint8_t tmp_extruder; | |
251 | ||
252 | ||
253 | bool Stopped=false; | |
254 | ||
255 | //=========================================================================== | |
256 | //=============================ROUTINES============================= | |
257 | //=========================================================================== | |
258 | ||
259 | void get_arc_coordinates(); | |
260 | ||
261 | extern "C"{ | |
262 | extern unsigned int __bss_end; | |
263 | extern unsigned int __heap_start; | |
264 | extern void *__brkval; | |
265 | ||
266 | int freeMemory() { | |
267 | int free_memory; | |
268 | ||
269 | if((int)__brkval == 0) | |
270 | free_memory = ((int)&free_memory) - ((int)&__bss_end); | |
271 | else | |
272 | free_memory = ((int)&free_memory) - ((int)__brkval); | |
273 | ||
274 | return free_memory; | |
275 | } | |
276 | } | |
277 | ||
278 | //adds an command to the main command buffer | |
279 | //thats really done in a non-safe way. | |
280 | //needs overworking someday | |
281 | void enquecommand(const char *cmd) | |
282 | { | |
283 | if(buflen < BUFSIZE) | |
284 | { | |
285 | //this is dangerous if a mixing of serial and this happsens | |
286 | strcpy(&(cmdbuffer[bufindw][0]),cmd); | |
287 | SERIAL_ECHO_START; | |
288 | SERIAL_ECHOPGM("enqueing \""); | |
289 | SERIAL_ECHO(cmdbuffer[bufindw]); | |
290 | SERIAL_ECHOLNPGM("\""); | |
291 | bufindw= (bufindw + 1)%BUFSIZE; | |
292 | buflen += 1; | |
293 | } | |
294 | } | |
295 | ||
296 | void setup_photpin() | |
297 | { | |
298 | #ifdef PHOTOGRAPH_PIN | |
299 | #if (PHOTOGRAPH_PIN > -1) | |
300 | SET_OUTPUT(PHOTOGRAPH_PIN); | |
301 | WRITE(PHOTOGRAPH_PIN, LOW); | |
302 | #endif | |
303 | #endif | |
304 | } | |
305 | ||
306 | void setup_powerhold() | |
307 | { | |
308 | #ifdef SUICIDE_PIN | |
309 | #if (SUICIDE_PIN> -1) | |
310 | SET_OUTPUT(SUICIDE_PIN); | |
311 | WRITE(SUICIDE_PIN, HIGH); | |
312 | #endif | |
313 | #endif | |
314 | } | |
315 | ||
316 | void suicide() | |
317 | { | |
318 | #ifdef SUICIDE_PIN | |
319 | #if (SUICIDE_PIN> -1) | |
320 | SET_OUTPUT(SUICIDE_PIN); | |
321 | WRITE(SUICIDE_PIN, LOW); | |
322 | #endif | |
323 | #endif | |
324 | } | |
325 | ||
326 | void setup() | |
327 | { | |
328 | setup_powerhold(); | |
329 | MYSERIAL.begin(BAUDRATE); | |
330 | SERIAL_PROTOCOLLNPGM("start"); | |
331 | SERIAL_ECHO_START; | |
332 | ||
333 | for(int8_t i = 0; i < EXTRUDERS; i++) | |
334 | { | |
335 | extruder_x_off[i] = X_EXTRUDER_OFFSET; | |
336 | extruder_y_off[i] = Y_EXTRUDER_OFFSET; | |
337 | extruder_z_off[i] = Z_EXTRUDER_OFFSET; | |
338 | extruder_standby[i] = STANDBY_TEMP; | |
339 | extruder_temperature[i] = DEFAULT_TEMP; | |
340 | } | |
341 | ||
342 | ||
343 | // Check startup - does nothing if bootloader sets MCUSR to 0 | |
344 | byte mcu = MCUSR; | |
345 | if(mcu & 1) SERIAL_ECHOLNPGM(MSG_POWERUP); | |
346 | if(mcu & 2) SERIAL_ECHOLNPGM(MSG_EXTERNAL_RESET); | |
347 | if(mcu & 4) SERIAL_ECHOLNPGM(MSG_BROWNOUT_RESET); | |
348 | if(mcu & 8) SERIAL_ECHOLNPGM(MSG_WATCHDOG_RESET); | |
349 | if(mcu & 32) SERIAL_ECHOLNPGM(MSG_SOFTWARE_RESET); | |
350 | MCUSR=0; | |
351 | ||
352 | SERIAL_ECHOPGM(MSG_MARLIN); | |
353 | SERIAL_ECHOLNPGM(VERSION_STRING); | |
354 | #ifdef STRING_VERSION_CONFIG_H | |
355 | #ifdef STRING_CONFIG_H_AUTHOR | |
356 | SERIAL_ECHO_START; | |
357 | SERIAL_ECHOPGM(MSG_CONFIGURATION_VER); | |
358 | SERIAL_ECHOPGM(STRING_VERSION_CONFIG_H); | |
359 | SERIAL_ECHOPGM(MSG_AUTHOR); | |
360 | SERIAL_ECHOLNPGM(STRING_CONFIG_H_AUTHOR); | |
361 | #endif | |
362 | #endif | |
363 | SERIAL_ECHO_START; | |
364 | SERIAL_ECHOPGM(MSG_FREE_MEMORY); | |
365 | SERIAL_ECHO(freeMemory()); | |
366 | SERIAL_ECHOPGM(MSG_PLANNER_BUFFER_BYTES); | |
367 | SERIAL_ECHOLN((int)sizeof(block_t)*BLOCK_BUFFER_SIZE); | |
368 | for(int8_t i = 0; i < BUFSIZE; i++) | |
369 | { | |
370 | fromsd[i] = false; | |
371 | } | |
372 | ||
373 | EEPROM_RetrieveSettings(); // loads data from EEPROM if available | |
374 | ||
375 | for(int8_t i=0; i < NUM_AXIS; i++) | |
376 | { | |
377 | axis_steps_per_sqr_second[i] = max_acceleration_units_per_sq_second[i] * axis_steps_per_unit[i]; | |
378 | } | |
379 | ||
380 | ||
381 | tp_init(); // Initialize temperature loop | |
382 | plan_init(); // Initialize planner; | |
383 | st_init(); // Initialize stepper; | |
384 | #if (LED_PIN > -1) | |
385 | led_init(); | |
386 | #endif | |
387 | probe_init(); //Initializes probe if PROBE_PIN is defined | |
388 | FPUTransform_init(); //Initializes FPU when UMFPUSUPPORT defined | |
389 | setup_photpin(); | |
390 | ||
391 | #ifdef REPRAPPRO_MULTIMATERIALS | |
392 | setup_slave(); | |
393 | #endif | |
394 | ||
395 | } | |
396 | ||
397 | ||
398 | void loop() | |
399 | { | |
400 | if(buflen < (BUFSIZE-1)) | |
401 | get_command(); | |
402 | #ifdef SDSUPPORT | |
403 | card.checkautostart(false); | |
404 | #endif | |
405 | if(buflen) | |
406 | { | |
407 | #ifdef SDSUPPORT | |
408 | if(card.saving) | |
409 | { | |
410 | if(strstr(cmdbuffer[bufindr],"M29") == NULL) | |
411 | { | |
412 | card.write_command(cmdbuffer[bufindr]); | |
413 | SERIAL_PROTOCOLLNPGM(MSG_OK); | |
414 | } | |
415 | else | |
416 | { | |
417 | card.closefile(); | |
418 | SERIAL_PROTOCOLLNPGM(MSG_FILE_SAVED); | |
419 | } | |
420 | } | |
421 | else | |
422 | { | |
423 | process_commands(); | |
424 | } | |
425 | #else | |
426 | process_commands(); | |
427 | #endif //SDSUPPORT | |
428 | buflen = (buflen-1); | |
429 | bufindr = (bufindr + 1)%BUFSIZE; | |
430 | } | |
431 | //check heater every n milliseconds | |
432 | manage_heater(); | |
433 | manage_inactivity(1); | |
434 | checkHitEndstops(); | |
435 | LCD_STATUS; | |
436 | LED_STATUS; | |
437 | } | |
438 | ||
439 | void get_command() | |
440 | { | |
441 | while( MYSERIAL.available() > 0 && buflen < BUFSIZE) { | |
442 | serial_char = MYSERIAL.read(); | |
443 | if(serial_char == '\n' || | |
444 | serial_char == '\r' || | |
445 | (serial_char == ':' && comment_mode == false) || | |
446 | serial_count >= (MAX_CMD_SIZE - 1) ) | |
447 | { | |
448 | if(!serial_count) { //if empty line | |
449 | comment_mode = false; //for new command | |
450 | return; | |
451 | } | |
452 | cmdbuffer[bufindw][serial_count] = 0; //terminate string | |
453 | if(!comment_mode){ | |
454 | comment_mode = false; //for new command | |
455 | fromsd[bufindw] = false; | |
456 | if(strstr(cmdbuffer[bufindw], "N") != NULL) | |
457 | { | |
458 | strchr_pointer = strchr(cmdbuffer[bufindw], 'N'); | |
459 | gcode_N = (strtol(&cmdbuffer[bufindw][strchr_pointer - cmdbuffer[bufindw] + 1], NULL, 10)); | |
460 | if(gcode_N != gcode_LastN+1 && (strstr(cmdbuffer[bufindw], "M110") == NULL) ) { | |
461 | SERIAL_ERROR_START; | |
462 | SERIAL_ERRORPGM(MSG_ERR_LINE_NO); | |
463 | SERIAL_ERRORLN(gcode_LastN); | |
464 | //Serial.println(gcode_N); | |
465 | FlushSerialRequestResend(); | |
466 | serial_count = 0; | |
467 | return; | |
468 | } | |
469 | ||
470 | if(strstr(cmdbuffer[bufindw], "*") != NULL) | |
471 | { | |
472 | byte checksum = 0; | |
473 | byte count = 0; | |
474 | while(cmdbuffer[bufindw][count] != '*') checksum = checksum^cmdbuffer[bufindw][count++]; | |
475 | strchr_pointer = strchr(cmdbuffer[bufindw], '*'); | |
476 | ||
477 | if( (int)(strtod(&cmdbuffer[bufindw][strchr_pointer - cmdbuffer[bufindw] + 1], NULL)) != checksum) { | |
478 | SERIAL_ERROR_START; | |
479 | SERIAL_ERRORPGM(MSG_ERR_CHECKSUM_MISMATCH); | |
480 | SERIAL_ERRORLN(gcode_LastN); | |
481 | FlushSerialRequestResend(); | |
482 | serial_count = 0; | |
483 | return; | |
484 | } | |
485 | //if no errors, continue parsing | |
486 | } | |
487 | else | |
488 | { | |
489 | SERIAL_ERROR_START; | |
490 | SERIAL_ERRORPGM(MSG_ERR_NO_CHECKSUM); | |
491 | SERIAL_ERRORLN(gcode_LastN); | |
492 | FlushSerialRequestResend(); | |
493 | serial_count = 0; | |
494 | return; | |
495 | } | |
496 | ||
497 | gcode_LastN = gcode_N; | |
498 | //if no errors, continue parsing | |
499 | } | |
500 | else // if we don't receive 'N' but still see '*' | |
501 | { | |
502 | if((strstr(cmdbuffer[bufindw], "*") != NULL)) | |
503 | { | |
504 | SERIAL_ERROR_START; | |
505 | SERIAL_ERRORPGM(MSG_ERR_NO_LINENUMBER_WITH_CHECKSUM); | |
506 | SERIAL_ERRORLN(gcode_LastN); | |
507 | serial_count = 0; | |
508 | return; | |
509 | } | |
510 | } | |
511 | if((strstr(cmdbuffer[bufindw], "G") != NULL)){ | |
512 | strchr_pointer = strchr(cmdbuffer[bufindw], 'G'); | |
513 | switch((int)((strtod(&cmdbuffer[bufindw][strchr_pointer - cmdbuffer[bufindw] + 1], NULL)))){ | |
514 | case 0: | |
515 | case 1: | |
516 | case 2: | |
517 | case 3: | |
518 | if(Stopped == false) { // If printer is stopped by an error the G[0-3] codes are ignored. | |
519 | #ifdef SDSUPPORT | |
520 | if(card.saving) | |
521 | break; | |
522 | #endif //SDSUPPORT | |
523 | SERIAL_PROTOCOLLNPGM(MSG_OK); | |
524 | } | |
525 | else { | |
526 | SERIAL_ERRORLNPGM(MSG_ERR_STOPPED); | |
527 | LCD_MESSAGEPGM(MSG_STOPPED); | |
528 | } | |
529 | break; | |
530 | default: | |
531 | break; | |
532 | } | |
533 | ||
534 | } | |
535 | bufindw = (bufindw + 1)%BUFSIZE; | |
536 | buflen += 1; | |
537 | } | |
538 | serial_count = 0; //clear buffer | |
539 | } | |
540 | else | |
541 | { | |
542 | if(serial_char == ';') comment_mode = true; | |
543 | if(!comment_mode) cmdbuffer[bufindw][serial_count++] = serial_char; | |
544 | } | |
545 | } | |
546 | #ifdef SDSUPPORT | |
547 | if(!card.sdprinting || serial_count!=0){ | |
548 | return; | |
549 | } | |
550 | while( !card.eof() && buflen < BUFSIZE) { | |
551 | int16_t n=card.get(); | |
552 | serial_char = (char)n; | |
553 | if(serial_char == '\n' || | |
554 | serial_char == '\r' || | |
555 | (serial_char == ':' && comment_mode == false) || | |
556 | serial_count >= (MAX_CMD_SIZE - 1)||n==-1) | |
557 | { | |
558 | if(card.eof()){ | |
559 | SERIAL_PROTOCOLLNPGM(MSG_FILE_PRINTED); | |
560 | stoptime=millis(); | |
561 | char time[30]; | |
562 | unsigned long t=(stoptime-starttime)/1000; | |
563 | int sec,min; | |
564 | min=t/60; | |
565 | sec=t%60; | |
566 | sprintf(time,"%i min, %i sec",min,sec); | |
567 | SERIAL_ECHO_START; | |
568 | SERIAL_ECHOLN(time); | |
569 | LCD_MESSAGE(time); | |
570 | card.printingHasFinished(); | |
571 | card.checkautostart(true); | |
572 | ||
573 | } | |
574 | if(!serial_count) | |
575 | { | |
576 | comment_mode = false; //for new command | |
577 | return; //if empty line | |
578 | } | |
579 | cmdbuffer[bufindw][serial_count] = 0; //terminate string | |
580 | // if(!comment_mode){ | |
581 | fromsd[bufindw] = true; | |
582 | buflen += 1; | |
583 | bufindw = (bufindw + 1)%BUFSIZE; | |
584 | // } | |
585 | comment_mode = false; //for new command | |
586 | serial_count = 0; //clear buffer | |
587 | } | |
588 | else | |
589 | { | |
590 | if(serial_char == ';') comment_mode = true; | |
591 | if(!comment_mode) cmdbuffer[bufindw][serial_count++] = serial_char; | |
592 | } | |
593 | } | |
594 | ||
595 | #endif //SDSUPPORT | |
596 | ||
597 | } | |
598 | ||
599 | ||
600 | float code_value() | |
601 | { | |
602 | return (strtod(&cmdbuffer[bufindr][strchr_pointer - cmdbuffer[bufindr] + 1], NULL)); | |
603 | } | |
604 | ||
605 | long code_value_long() | |
606 | { | |
607 | return (strtol(&cmdbuffer[bufindr][strchr_pointer - cmdbuffer[bufindr] + 1], NULL, 10)); | |
608 | } | |
609 | ||
610 | bool code_seen(char code_string[]) //Return True if the string was found | |
611 | { | |
612 | return (strstr(cmdbuffer[bufindr], code_string) != NULL); | |
613 | } | |
614 | ||
615 | bool code_seen(char code) | |
616 | { | |
617 | strchr_pointer = strchr(cmdbuffer[bufindr], code); | |
618 | return (strchr_pointer != NULL); //Return True if a character was found | |
619 | } | |
620 | ||
621 | #define HOMEAXIS(LETTER) \ | |
622 | if ((LETTER##_MIN_PIN > -1 && LETTER##_HOME_DIR==-1) || (LETTER##_MAX_PIN > -1 && LETTER##_HOME_DIR==1))\ | |
623 | { \ | |
624 | current_position[LETTER##_AXIS] = 0; \ | |
625 | plan_set_position(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS]); \ | |
626 | destination[LETTER##_AXIS] = 1.1 * max_length[LETTER##_AXIS] * LETTER##_HOME_DIR; \ | |
627 | feedrate = fast_home_feedrate[LETTER##_AXIS]; \ | |
1
b584642d4f58
several modifications to support laser enable - still needs cleanup
mbayer
parents:
0
diff
changeset
|
628 | plan_buffer_line(destination[X_AXIS], destination[Y_AXIS], destination[Z_AXIS], destination[E_AXIS], feedrate/60, active_extruder, false); \ |
0 | 629 | st_synchronize();\ |
630 | \ | |
631 | current_position[LETTER##_AXIS] = 0;\ | |
632 | plan_set_position(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS]);\ | |
633 | destination[LETTER##_AXIS] = -LETTER##_HOME_RETRACT_MM * LETTER##_HOME_DIR;\ | |
1
b584642d4f58
several modifications to support laser enable - still needs cleanup
mbayer
parents:
0
diff
changeset
|
634 | plan_buffer_line(destination[X_AXIS], destination[Y_AXIS], destination[Z_AXIS], destination[E_AXIS], feedrate/60, active_extruder, false); \ |
0 | 635 | st_synchronize();\ |
636 | \ | |
637 | destination[LETTER##_AXIS] = 2*LETTER##_HOME_RETRACT_MM * LETTER##_HOME_DIR;\ | |
638 | feedrate = homing_feedrate[LETTER##_AXIS] ; \ | |
1
b584642d4f58
several modifications to support laser enable - still needs cleanup
mbayer
parents:
0
diff
changeset
|
639 | plan_buffer_line(destination[X_AXIS], destination[Y_AXIS], destination[Z_AXIS], destination[E_AXIS], feedrate/60, active_extruder, false); \ |
0 | 640 | st_synchronize();\ |
641 | \ | |
642 | current_position[LETTER##_AXIS] = LETTER##_HOME_POS;\ | |
643 | destination[LETTER##_AXIS] = current_position[LETTER##_AXIS];\ | |
644 | feedrate = 0.0;\ | |
645 | endstops_hit_on_purpose();\ | |
646 | } | |
647 | ||
648 | void wait_for_temp(uint8_t& t_ext, unsigned long& codenum) | |
649 | { | |
650 | /* See if we are heating up or cooling down */ | |
651 | bool target_direction = isHeatingHotend(t_ext); // true if heating, false if cooling | |
652 | ||
653 | #ifdef TEMP_RESIDENCY_TIME | |
654 | long residencyStart; | |
655 | residencyStart = -1; | |
656 | /* continue to loop until we have reached the target temp | |
657 | _and_ until TEMP_RESIDENCY_TIME hasn't passed since we reached it */ | |
658 | while((residencyStart == -1) || | |
659 | (residencyStart >= 0 && (((unsigned int) (millis() - residencyStart)) < (TEMP_RESIDENCY_TIME * 1000UL))) ) | |
660 | { | |
661 | #else | |
662 | while ( target_direction ? (isHeatingHotend(t_ext)) : (isCoolingHotend(tmp_extruder)&&(CooldownNoWait==false)) ) | |
663 | { | |
664 | #endif //TEMP_RESIDENCY_TIME | |
665 | if( (millis() - codenum) > 1000UL ) | |
666 | { //Print Temp Reading and remaining time every 1 second while heating up/cooling down | |
667 | SERIAL_PROTOCOLPGM("T:"); | |
668 | SERIAL_PROTOCOL_F(degHotend(t_ext),1); | |
669 | SERIAL_PROTOCOLPGM(" E:"); | |
670 | SERIAL_PROTOCOL( (int)t_ext ); | |
671 | #ifdef TEMP_RESIDENCY_TIME | |
672 | SERIAL_PROTOCOLPGM(" W:"); | |
673 | if(residencyStart > -1) | |
674 | { | |
675 | codenum = ((TEMP_RESIDENCY_TIME * 1000UL) - (millis() - residencyStart)) / 1000UL; | |
676 | SERIAL_PROTOCOLLN( codenum ); | |
677 | } else | |
678 | { | |
679 | SERIAL_PROTOCOLLN( "?" ); | |
680 | } | |
681 | #else | |
682 | SERIAL_PROTOCOLLN(""); | |
683 | #endif | |
684 | codenum = millis(); | |
685 | } | |
686 | manage_heater(); | |
687 | manage_inactivity(1); | |
688 | lcd_status(); | |
689 | led_status(); | |
690 | #ifdef TEMP_RESIDENCY_TIME | |
691 | /* start/restart the TEMP_RESIDENCY_TIME timer whenever we reach target temp for the first time | |
692 | or when current temp falls outside the hysteresis after target temp was reached */ | |
693 | if ((residencyStart == -1 && target_direction && (degHotend(t_ext) >= (degTargetHotend(t_ext)-TEMP_WINDOW))) || | |
694 | (residencyStart == -1 && !target_direction && (degHotend(t_ext) <= (degTargetHotend(t_ext)+TEMP_WINDOW))) || | |
695 | (residencyStart > -1 && labs(degHotend(t_ext) - degTargetHotend(t_ext)) > TEMP_HYSTERESIS) ) | |
696 | { | |
697 | residencyStart = millis(); | |
698 | } | |
699 | #endif //TEMP_RESIDENCY_TIME | |
700 | } | |
701 | LCD_MESSAGEPGM(MSG_HEATING_COMPLETE); | |
702 | starttime=millis(); | |
703 | previous_millis_cmd = millis(); | |
704 | } | |
705 | ||
706 | ||
707 | void process_commands() | |
708 | { | |
709 | unsigned long codenum; //throw away variable | |
710 | char *starpos = NULL; | |
711 | ||
712 | if(code_seen('G')) | |
713 | { | |
714 | switch((int)code_value()) | |
715 | { | |
716 | case 0: // G0 -> G1 | |
1
b584642d4f58
several modifications to support laser enable - still needs cleanup
mbayer
parents:
0
diff
changeset
|
717 | if(Stopped == false) { |
b584642d4f58
several modifications to support laser enable - still needs cleanup
mbayer
parents:
0
diff
changeset
|
718 | get_coordinates(); // For X Y Z E F |
b584642d4f58
several modifications to support laser enable - still needs cleanup
mbayer
parents:
0
diff
changeset
|
719 | prepare_move(false); |
b584642d4f58
several modifications to support laser enable - still needs cleanup
mbayer
parents:
0
diff
changeset
|
720 | //ClearToSend(); |
b584642d4f58
several modifications to support laser enable - still needs cleanup
mbayer
parents:
0
diff
changeset
|
721 | return; |
b584642d4f58
several modifications to support laser enable - still needs cleanup
mbayer
parents:
0
diff
changeset
|
722 | } |
0 | 723 | case 1: // G1 |
724 | if(Stopped == false) { | |
725 | get_coordinates(); // For X Y Z E F | |
1
b584642d4f58
several modifications to support laser enable - still needs cleanup
mbayer
parents:
0
diff
changeset
|
726 | prepare_move(true); |
0 | 727 | //ClearToSend(); |
728 | return; | |
729 | } | |
730 | //break; | |
731 | case 2: // G2 - CW ARC | |
732 | if(Stopped == false) { | |
733 | get_arc_coordinates(); | |
734 | prepare_arc_move(true); | |
735 | return; | |
736 | } | |
737 | case 3: // G3 - CCW ARC | |
738 | if(Stopped == false) { | |
739 | get_arc_coordinates(); | |
740 | prepare_arc_move(false); | |
741 | return; | |
742 | } | |
743 | case 4: // G4 dwell | |
744 | LCD_MESSAGEPGM(MSG_DWELL); | |
745 | codenum = 0; | |
746 | if(code_seen('P')) codenum = code_value(); // milliseconds to wait | |
747 | if(code_seen('S')) codenum = code_value() * 1000; // seconds to wait | |
748 | ||
749 | st_synchronize(); | |
750 | codenum += millis(); // keep track of when we started waiting | |
751 | previous_millis_cmd = millis(); | |
752 | while(millis() < codenum ){ | |
753 | manage_heater(); | |
754 | manage_inactivity(1); | |
755 | } | |
756 | break; | |
757 | ||
758 | case 10: // Set offsets | |
759 | if(code_seen('P')) | |
760 | { | |
761 | tmp_extruder = code_value(); | |
762 | get_coordinates(); | |
763 | extruder_x_off[tmp_extruder] = destination[0]; // X | |
764 | extruder_y_off[tmp_extruder] = destination[1]; // Y | |
765 | extruder_z_off[tmp_extruder] = destination[2]; // Z | |
766 | if(code_seen('R')) | |
767 | extruder_standby[tmp_extruder] = code_value(); | |
768 | if(code_seen('S')) | |
769 | extruder_temperature[tmp_extruder] = code_value(); | |
770 | } | |
771 | break; | |
772 | ||
773 | case 28: //G28 Home all Axis one at a time | |
774 | saved_feedrate = feedrate; | |
775 | saved_feedmultiply = feedmultiply; | |
776 | feedmultiply = 100; | |
777 | previous_millis_cmd = millis(); | |
778 | ||
779 | enable_endstops(true); | |
780 | ||
781 | for(int8_t i=0; i < NUM_AXIS; i++) { | |
782 | destination[i] = current_position[i]; | |
783 | } | |
784 | feedrate = 0.0; | |
785 | home_all_axis = !((code_seen(axis_codes[0])) || (code_seen(axis_codes[1])) || (code_seen(axis_codes[2]))); | |
786 | ||
787 | if((home_all_axis) || (code_seen(axis_codes[X_AXIS]))) | |
788 | { | |
789 | HOMEAXIS(X); | |
790 | } | |
791 | ||
792 | if((home_all_axis) || (code_seen(axis_codes[Y_AXIS]))) { | |
793 | HOMEAXIS(Y); | |
794 | } | |
795 | ||
796 | if((home_all_axis) || (code_seen(axis_codes[Z_AXIS]))) { | |
797 | HOMEAXIS(Z); | |
798 | } | |
799 | ||
800 | if((home_all_axis) || code_seen(axis_codes[X_AXIS])) | |
801 | { | |
802 | if(code_value_long() != 0) { | |
803 | current_position[X_AXIS]=code_value(); | |
804 | } | |
805 | current_position[X_AXIS]+=add_homeing[0]; | |
806 | } | |
807 | ||
808 | if((home_all_axis) || code_seen(axis_codes[Y_AXIS])) { | |
809 | if(code_value_long() != 0) { | |
810 | current_position[Y_AXIS]=code_value(); | |
811 | } | |
812 | current_position[Y_AXIS]+=add_homeing[1]; | |
813 | } | |
814 | ||
815 | if((home_all_axis) || code_seen(axis_codes[Z_AXIS])) { | |
816 | if(code_value_long() != 0) { | |
817 | current_position[Z_AXIS]=code_value(); | |
818 | } | |
819 | current_position[Z_AXIS]+=add_homeing[2]; | |
820 | } | |
821 | plan_set_position(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS]); | |
822 | ||
823 | #ifdef ENDSTOPS_ONLY_FOR_HOMING | |
824 | enable_endstops(false); | |
825 | #endif | |
826 | ||
827 | feedrate = saved_feedrate; | |
828 | feedmultiply = saved_feedmultiply; | |
829 | previous_millis_cmd = millis(); | |
830 | endstops_hit_on_purpose(); | |
831 | break; | |
832 | case 29: | |
833 | probe_3points(); | |
834 | break; | |
835 | case 30: | |
836 | probe_1point(); | |
837 | break; | |
838 | case 31: | |
839 | probe_status(); | |
840 | break; | |
841 | case 32: | |
842 | FPUTransform_determineBedOrientation(); | |
843 | break; | |
844 | case 90: // G90 | |
845 | relative_mode = false; | |
846 | break; | |
847 | case 91: // G91 | |
848 | relative_mode = true; | |
849 | break; | |
850 | case 92: // G92 | |
851 | if(!code_seen(axis_codes[E_AXIS])) | |
852 | st_synchronize(); | |
853 | for(int8_t i=0; i < NUM_AXIS; i++) { | |
854 | if(code_seen(axis_codes[i])) { | |
855 | current_position[i] = code_value()+add_homeing[i]; | |
856 | if(i == E_AXIS) { | |
857 | current_position[i] = code_value(); | |
858 | plan_set_e_position(current_position[E_AXIS]); | |
859 | } | |
860 | else { | |
861 | current_position[i] = code_value()+add_homeing[i]; | |
862 | plan_set_position(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS]); | |
863 | } | |
864 | } | |
865 | } | |
866 | break; | |
867 | } | |
868 | } | |
869 | ||
870 | else if(code_seen('M')) | |
871 | { | |
872 | switch( (int)code_value() ) | |
873 | { | |
874 | case 0: // Stops - add me... | |
875 | case 1: | |
876 | case 112: | |
877 | break; | |
878 | ||
879 | case 17: | |
880 | LCD_MESSAGEPGM(MSG_NO_MOVE); | |
881 | enable_x(); | |
882 | enable_y(); | |
883 | enable_z(); | |
884 | // N571 disables real E drive! (ie. on laser operations) | |
885 | if (!n571_enabled) { | |
886 | enable_e0(); | |
887 | enable_e1(); | |
888 | enable_e2(); | |
889 | } | |
890 | break; | |
891 | ||
892 | #ifdef SDSUPPORT | |
893 | case 20: // M20 - list SD card | |
894 | SERIAL_PROTOCOLLNPGM(MSG_BEGIN_FILE_LIST); | |
895 | card.ls(); | |
896 | SERIAL_PROTOCOLLNPGM(MSG_END_FILE_LIST); | |
897 | break; | |
898 | case 21: // M21 - init SD card | |
899 | ||
900 | card.initsd(); | |
901 | ||
902 | break; | |
903 | case 22: //M22 - release SD card | |
904 | card.release(); | |
905 | ||
906 | break; | |
907 | case 23: //M23 - Select file | |
908 | starpos = (strchr(strchr_pointer + 4,'*')); | |
909 | if(starpos!=NULL) | |
910 | *(starpos-1)='\0'; | |
911 | card.openFile(strchr_pointer + 4,true); | |
912 | break; | |
913 | case 24: //M24 - Start SD print | |
914 | card.startFileprint(); | |
915 | starttime=millis(); | |
916 | break; | |
917 | case 25: //M25 - Pause SD print | |
918 | card.pauseSDPrint(); | |
919 | break; | |
920 | case 26: //M26 - Set SD index | |
921 | if(card.cardOK && code_seen('S')) { | |
922 | card.setIndex(code_value_long()); | |
923 | } | |
924 | break; | |
925 | case 27: //M27 - Get SD status | |
926 | card.getStatus(); | |
927 | break; | |
928 | case 28: //M28 - Start SD write | |
929 | starpos = (strchr(strchr_pointer + 4,'*')); | |
930 | if(starpos != NULL){ | |
931 | char* npos = strchr(cmdbuffer[bufindr], 'N'); | |
932 | strchr_pointer = strchr(npos,' ') + 1; | |
933 | *(starpos-1) = '\0'; | |
934 | } | |
935 | card.openFile(strchr_pointer+4,false); | |
936 | break; | |
937 | case 29: //M29 - Stop SD write | |
938 | //processed in write to file routine above | |
939 | //card,saving = false; | |
940 | break; | |
941 | case 30: //M30 <filename> Delete File | |
942 | if (card.cardOK){ | |
943 | card.closefile(); | |
944 | starpos = (strchr(strchr_pointer + 4,'*')); | |
945 | if(starpos != NULL){ | |
946 | char* npos = strchr(cmdbuffer[bufindr], 'N'); | |
947 | strchr_pointer = strchr(npos,' ') + 1; | |
948 | *(starpos-1) = '\0'; | |
949 | } | |
950 | card.removeFile(strchr_pointer + 4); | |
951 | } | |
952 | break; | |
953 | ||
954 | case 32: //M32 - fast SD transfer | |
955 | card.fast_xfer(strchr_pointer+4); | |
956 | break; | |
957 | case 33: //M31 - high speed xfer capabilities | |
958 | SERIAL_ECHOPGM("RAW:"); | |
959 | SERIAL_ECHOLN(SD_FAST_XFER_CHUNK_SIZE); | |
960 | break; | |
961 | #endif //SDSUPPORT | |
962 | ||
963 | case 35: //M35 take time since the start of the SD print or an M109 command | |
964 | { | |
965 | stoptime=millis(); | |
966 | char time[30]; | |
967 | unsigned long t=(stoptime-starttime)/1000; | |
968 | int sec,min; | |
969 | min=t/60; | |
970 | sec=t%60; | |
971 | sprintf(time,"%i min, %i sec",min,sec); | |
972 | SERIAL_ECHO_START; | |
973 | SERIAL_ECHOLN(time); | |
974 | LCD_MESSAGE(time); | |
975 | } | |
976 | break; | |
977 | case 42: //M42 -Change pin status via gcode | |
978 | if (code_seen('S')) | |
979 | { | |
980 | int pin_status = code_value(); | |
981 | if (code_seen('P') && pin_status >= 0 && pin_status <= 255) | |
982 | { | |
983 | int pin_number = code_value(); | |
984 | for(int8_t i = 0; i < (int8_t)sizeof(sensitive_pins); i++) | |
985 | { | |
986 | if (sensitive_pins[i] == pin_number) | |
987 | { | |
988 | pin_number = -1; | |
989 | break; | |
990 | } | |
991 | } | |
992 | ||
993 | if (pin_number > -1) | |
994 | { | |
995 | pinMode(pin_number, OUTPUT); | |
996 | digitalWrite(pin_number, pin_status); | |
997 | analogWrite(pin_number, pin_status); | |
998 | } | |
999 | } | |
1000 | } | |
1001 | break; | |
1002 | case 104: // M104 | |
1003 | tmp_extruder = active_extruder; | |
1004 | if(code_seen('T')) { // Why is this T and not S? - AB | |
1005 | tmp_extruder = code_value(); | |
1006 | if(tmp_extruder >= EXTRUDERS) { | |
1007 | SERIAL_ECHO_START; | |
1008 | SERIAL_ECHO(MSG_M104_INVALID_EXTRUDER); | |
1009 | SERIAL_ECHOLN(tmp_extruder); | |
1010 | break; | |
1011 | } | |
1012 | } | |
1013 | if (code_seen('S')) | |
1014 | { | |
1015 | extruder_temperature[tmp_extruder] = code_value(); | |
1016 | setTargetHotend(code_value(), tmp_extruder); | |
1017 | } | |
1018 | ||
1019 | break; | |
1020 | case 140: // M140 set bed temp | |
1021 | if (code_seen('S')) setTargetBed(code_value()); | |
1022 | break; | |
1023 | case 1105: | |
1024 | #if (TEMP_0_PIN > -1) | |
1025 | SERIAL_PROTOCOLPGM("ok T0 raw:"); | |
1026 | SERIAL_PROTOCOL(rawHotend(tmp_extruder)); | |
1027 | SERIAL_PROTOCOLPGM(", min:"); | |
1028 | SERIAL_PROTOCOL(minHotend(tmp_extruder)); | |
1029 | SERIAL_PROTOCOLPGM(", max:"); | |
1030 | SERIAL_PROTOCOL(maxHotend(tmp_extruder)); | |
1031 | #endif | |
1032 | break; | |
1033 | case 105 : // M105 | |
1034 | tmp_extruder = active_extruder; | |
1035 | if(code_seen('T')) { | |
1036 | tmp_extruder = code_value(); | |
1037 | if(tmp_extruder >= EXTRUDERS) { | |
1038 | SERIAL_ECHO_START; | |
1039 | SERIAL_ECHO(MSG_M105_INVALID_EXTRUDER); | |
1040 | SERIAL_ECHOLN(tmp_extruder); | |
1041 | break; | |
1042 | } | |
1043 | } | |
1044 | #if (TEMP_0_PIN > -1) | |
1045 | SERIAL_PROTOCOLPGM("ok T:"); | |
1046 | SERIAL_PROTOCOL_F(degHotend(tmp_extruder),1); | |
1047 | SERIAL_PROTOCOLPGM(" /"); | |
1048 | SERIAL_PROTOCOL_F(degTargetHotend(tmp_extruder),1); | |
1049 | #if TEMP_BED_PIN > -1 | |
1050 | SERIAL_PROTOCOLPGM(" B:"); | |
1051 | SERIAL_PROTOCOL_F(degBed(),1); | |
1052 | SERIAL_PROTOCOLPGM(" /"); | |
1053 | SERIAL_PROTOCOL_F(degTargetBed(),1); | |
1054 | #endif //TEMP_BED_PIN | |
1055 | #else | |
1056 | SERIAL_ERROR_START; | |
1057 | SERIAL_ERRORLNPGM(MSG_ERR_NO_THERMISTORS); | |
1058 | #endif | |
1059 | #ifdef PIDTEMP | |
1060 | SERIAL_PROTOCOLPGM(" @:"); | |
1061 | SERIAL_PROTOCOL(getHeaterPower(tmp_extruder)); | |
1062 | #endif | |
1063 | SERIAL_PROTOCOLLN(""); | |
1064 | return; | |
1065 | break; | |
1066 | case 109: | |
1067 | // M109 - Wait for extruder heater to reach target. | |
1068 | tmp_extruder = active_extruder; | |
1069 | if(code_seen('T')) { // Why is this T and not S? - AB | |
1070 | tmp_extruder = code_value(); | |
1071 | if(tmp_extruder >= EXTRUDERS) { | |
1072 | SERIAL_ECHO_START; | |
1073 | SERIAL_ECHO(MSG_M109_INVALID_EXTRUDER); | |
1074 | SERIAL_ECHOLN(tmp_extruder); | |
1075 | break; | |
1076 | } | |
1077 | } | |
1078 | LCD_MESSAGEPGM(MSG_HEATING); | |
1079 | ||
1080 | if (code_seen('S')) | |
1081 | { | |
1082 | extruder_temperature[tmp_extruder] = code_value(); | |
1083 | setTargetHotend(code_value(), tmp_extruder); | |
1084 | } | |
1085 | ||
1086 | ||
1087 | codenum = millis(); | |
1088 | wait_for_temp(tmp_extruder, codenum); | |
1089 | break; | |
1090 | case 190: // M190 - Wait for bed heater to reach target. | |
1091 | #if TEMP_BED_PIN > -1 | |
1092 | LCD_MESSAGEPGM(MSG_BED_HEATING); | |
1093 | if (code_seen('S')) setTargetBed(code_value()); | |
1094 | codenum = millis(); | |
1095 | while(isHeatingBed()) | |
1096 | { | |
1097 | if(( millis() - codenum) > 1000 ) //Print Temp Reading every 1 second while heating up. | |
1098 | { | |
1099 | float tt=degHotend(active_extruder); | |
1100 | SERIAL_PROTOCOLPGM("T:"); | |
1101 | SERIAL_PROTOCOL(tt); | |
1102 | SERIAL_PROTOCOLPGM(" E:"); | |
1103 | SERIAL_PROTOCOL((int)active_extruder); | |
1104 | SERIAL_PROTOCOLPGM(" B:"); | |
1105 | SERIAL_PROTOCOL_F(degBed(),1); | |
1106 | SERIAL_PROTOCOLLN(""); | |
1107 | codenum = millis(); | |
1108 | } | |
1109 | manage_heater(); | |
1110 | manage_inactivity(1); | |
1111 | LCD_STATUS; | |
1112 | } | |
1113 | LCD_MESSAGEPGM(MSG_BED_DONE); | |
1114 | previous_millis_cmd = millis(); | |
1115 | #endif | |
1116 | break; | |
1117 | ||
1118 | #if FAN_PIN > -1 | |
1119 | case 106: //M106 Fan On | |
1120 | if (code_seen('S')){ | |
1121 | FanSpeed=constrain(code_value(),0,255); | |
1122 | } | |
1123 | else { | |
1124 | FanSpeed=255; | |
1125 | } | |
1126 | break; | |
1127 | case 107: //M107 Fan Off | |
1128 | FanSpeed = 0; | |
1129 | break; | |
1130 | #endif //FAN_PIN | |
1131 | ||
1132 | ||
1133 | case 82: | |
1134 | axis_relative_modes[3] = false; | |
1135 | break; | |
1136 | case 83: | |
1137 | axis_relative_modes[3] = true; | |
1138 | break; | |
1139 | case 18: //compatibility | |
1140 | case 84: // M84 | |
1141 | if(code_seen('S')){ | |
1142 | stepper_inactive_time = code_value() * 1000; | |
1143 | } | |
1144 | else | |
1145 | { | |
1146 | bool all_axis = !((code_seen(axis_codes[0])) || (code_seen(axis_codes[1])) || (code_seen(axis_codes[2]))|| (code_seen(axis_codes[3]))); | |
1147 | if(all_axis) | |
1148 | { | |
1149 | st_synchronize(); | |
1150 | disable_e0(); | |
1151 | disable_e1(); | |
1152 | disable_e2(); | |
1153 | finishAndDisableSteppers(); | |
1154 | ||
1155 | if (m571_enabled) WRITE(M571_PIN, LOW);// M571 disable | |
1156 | } | |
1157 | else | |
1158 | { | |
1159 | st_synchronize(); | |
1160 | if(code_seen('X')) disable_x(); | |
1161 | if(code_seen('Y')) disable_y(); | |
1162 | if(code_seen('Z')) disable_z(); | |
1163 | #if ((E0_ENABLE_PIN != X_ENABLE_PIN) && (E1_ENABLE_PIN != Y_ENABLE_PIN)) // Only enable on boards that have seperate ENABLE_PINS | |
1164 | if(code_seen('E')) { | |
1165 | disable_e0(); | |
1166 | disable_e1(); | |
1167 | disable_e2(); | |
1168 | if (m571_enabled) WRITE(M571_PIN, LOW);// M571 disable | |
1169 | } | |
1170 | #endif | |
1171 | LCD_MESSAGEPGM(MSG_PART_RELEASE); | |
1172 | } | |
1173 | } | |
1174 | break; | |
1175 | case 85: // M85 | |
1176 | code_seen('S'); | |
1177 | max_inactive_time = code_value() * 1000; | |
1178 | break; | |
1179 | case 92: // M92 | |
1180 | for(int8_t i=0; i < NUM_AXIS; i++) | |
1181 | { | |
1182 | if(code_seen(axis_codes[i])) | |
1183 | axis_steps_per_unit[i] = code_value(); | |
1184 | } | |
1185 | break; | |
1186 | case 115: // M115 | |
1187 | SerialprintPGM(MSG_M115_REPORT); | |
1188 | break; | |
1189 | case 117: // M117 display message | |
1190 | LCD_MESSAGE(cmdbuffer[bufindr]+5); | |
1191 | break; | |
1192 | case 114: // M114 | |
1193 | SERIAL_PROTOCOLPGM("X:"); | |
1194 | SERIAL_PROTOCOL(current_position[X_AXIS]); | |
1195 | SERIAL_PROTOCOLPGM("Y:"); | |
1196 | SERIAL_PROTOCOL(current_position[Y_AXIS]); | |
1197 | SERIAL_PROTOCOLPGM("Z:"); | |
1198 | SERIAL_PROTOCOL(current_position[Z_AXIS]); | |
1199 | SERIAL_PROTOCOLPGM("E:"); | |
1200 | SERIAL_PROTOCOL(current_position[E_AXIS]); | |
1201 | ||
1202 | SERIAL_PROTOCOLPGM(MSG_COUNT_X); | |
1203 | SERIAL_PROTOCOL(float(st_get_position(X_AXIS))/axis_steps_per_unit[X_AXIS]); | |
1204 | SERIAL_PROTOCOLPGM("Y:"); | |
1205 | SERIAL_PROTOCOL(float(st_get_position(Y_AXIS))/axis_steps_per_unit[Y_AXIS]); | |
1206 | SERIAL_PROTOCOLPGM("Z:"); | |
1207 | SERIAL_PROTOCOL(float(st_get_position(Z_AXIS))/axis_steps_per_unit[Z_AXIS]); | |
1208 | ||
1209 | SERIAL_PROTOCOLLN(""); | |
1210 | break; | |
1211 | case 120: // M120 | |
1212 | enable_endstops(false) ; | |
1213 | break; | |
1214 | case 121: // M121 | |
1215 | enable_endstops(true) ; | |
1216 | break; | |
1217 | case 119: // M119 | |
1218 | #if (X_MIN_PIN > -1) | |
1219 | SERIAL_PROTOCOLPGM(MSG_X_MIN); | |
1220 | SERIAL_PROTOCOL(((READ(X_MIN_PIN)^X_ENDSTOPS_INVERTING)?"H ":"L ")); | |
1221 | #endif | |
1222 | #if (X_MAX_PIN > -1) | |
1223 | SERIAL_PROTOCOLPGM(MSG_X_MAX); | |
1224 | SERIAL_PROTOCOL(((READ(X_MAX_PIN)^X_ENDSTOPS_INVERTING)?"H ":"L ")); | |
1225 | #endif | |
1226 | #if (Y_MIN_PIN > -1) | |
1227 | SERIAL_PROTOCOLPGM(MSG_Y_MIN); | |
1228 | SERIAL_PROTOCOL(((READ(Y_MIN_PIN)^Y_ENDSTOPS_INVERTING)?"H ":"L ")); | |
1229 | #endif | |
1230 | #if (Y_MAX_PIN > -1) | |
1231 | SERIAL_PROTOCOLPGM(MSG_Y_MAX); | |
1232 | SERIAL_PROTOCOL(((READ(Y_MAX_PIN)^Y_ENDSTOPS_INVERTING)?"H ":"L ")); | |
1233 | #endif | |
1234 | #if (Z_MIN_PIN > -1) | |
1235 | SERIAL_PROTOCOLPGM(MSG_Z_MIN); | |
1236 | SERIAL_PROTOCOL(((READ(Z_MIN_PIN)^Z_ENDSTOPS_INVERTING)?"H ":"L ")); | |
1237 | #endif | |
1238 | #if (Z_MAX_PIN > -1) | |
1239 | SERIAL_PROTOCOLPGM(MSG_Z_MAX); | |
1240 | SERIAL_PROTOCOL(((READ(Z_MAX_PIN)^Z_ENDSTOPS_INVERTING)?"H ":"L ")); | |
1241 | #endif | |
1242 | SERIAL_PROTOCOLLN(""); | |
1243 | break; | |
1244 | case 201: // M201 | |
1245 | for(int8_t i=0; i < NUM_AXIS; i++) | |
1246 | { | |
1247 | if(code_seen(axis_codes[i])) | |
1248 | { | |
1249 | max_acceleration_units_per_sq_second[i] = code_value(); | |
1250 | axis_steps_per_sqr_second[i] = code_value() * axis_steps_per_unit[i]; | |
1251 | } | |
1252 | } | |
1253 | break; | |
1254 | #if 0 // Not used for Sprinter/grbl gen6 | |
1255 | case 202: // M202 | |
1256 | for(int8_t i=0; i < NUM_AXIS; i++) { | |
1257 | if(code_seen(axis_codes[i])) axis_travel_steps_per_sqr_second[i] = code_value() * axis_steps_per_unit[i]; | |
1258 | } | |
1259 | break; | |
1260 | #endif | |
1261 | case 203: // M203 max feedrate mm/sec | |
1262 | for(int8_t i=0; i < NUM_AXIS; i++) { | |
1263 | if(code_seen(axis_codes[i])) max_feedrate[i] = code_value(); | |
1264 | } | |
1265 | break; | |
1266 | case 204: // M204 acclereration S normal moves T filmanent only moves | |
1267 | { | |
1268 | if(code_seen('S')) acceleration = code_value() ; | |
1269 | if(code_seen('T')) retract_acceleration = code_value() ; | |
1270 | } | |
1271 | break; | |
1272 | case 205: //M205 advanced settings: minimum travel speed S=while printing T=travel only, B=minimum segment time X= maximum xy jerk, Z=maximum Z jerk | |
1273 | { | |
1274 | if(code_seen('S')) minimumfeedrate = code_value(); | |
1275 | if(code_seen('T')) mintravelfeedrate = code_value(); | |
1276 | if(code_seen('B')) minsegmenttime = code_value() ; | |
1277 | if(code_seen('X')) max_xy_jerk = code_value() ; | |
1278 | if(code_seen('Z')) max_z_jerk = code_value() ; | |
1279 | if(code_seen('E')) max_e_jerk = code_value() ; | |
1280 | #ifdef ADVANCE | |
1281 | if(code_seen('K')) advance_k = code_value() ; | |
1282 | #endif | |
1283 | } | |
1284 | break; | |
1285 | case 206: // M206 additional homeing offset | |
1286 | for(int8_t i=0; i < 3; i++) | |
1287 | { | |
1288 | if(code_seen(axis_codes[i])) add_homeing[i] = code_value(); | |
1289 | } | |
1290 | break; | |
1291 | case 208: // M208 set axis max length | |
1292 | for(int8_t i=0; i < 3; i++) | |
1293 | { | |
1294 | if(code_seen(axis_codes[i])) { | |
1295 | max_length[i] = code_value(); | |
1296 | SERIAL_PROTOCOL(axis_codes[i]); | |
1297 | SERIAL_PROTOCOL(" Axis max length: "); | |
1298 | SERIAL_PROTOCOL(max_length[i]); | |
1299 | } | |
1300 | } | |
1301 | break; | |
1302 | case 220: // M220 S<factor in percent>- set speed factor override percentage | |
1303 | { | |
1304 | if(code_seen('S')) | |
1305 | { | |
1306 | feedmultiply = code_value() ; | |
1307 | feedmultiplychanged=true; | |
1308 | } | |
1309 | } | |
1310 | break; | |
1311 | case 221: // M221 S<factor in percent>- set extrude factor override percentage | |
1312 | { | |
1313 | if(code_seen('S')) | |
1314 | { | |
1315 | extrudemultiply = code_value() ; | |
1316 | } | |
1317 | } | |
1318 | break; | |
1319 | ||
1320 | #ifdef PIDTEMP | |
1321 | case 301: // M301 | |
1322 | { | |
1323 | if(code_seen('P')) Kp = code_value(); | |
1324 | if(code_seen('I')) Ki = code_value()*PID_dT; | |
1325 | if(code_seen('D')) Kd = code_value()/PID_dT; | |
1326 | if(code_seen('W')) Ki_Max = constrain(code_value(),0,255); | |
1327 | ||
1328 | updatePID(); | |
1329 | SERIAL_PROTOCOL(MSG_OK); | |
1330 | SERIAL_PROTOCOL(" p:"); | |
1331 | SERIAL_PROTOCOL(Kp); | |
1332 | SERIAL_PROTOCOL(" i:"); | |
1333 | SERIAL_PROTOCOL(Ki/PID_dT); | |
1334 | SERIAL_PROTOCOL(" d:"); | |
1335 | SERIAL_PROTOCOL(Kd*PID_dT); | |
1336 | SERIAL_PROTOCOL(" w:"); | |
1337 | SERIAL_PROTOCOL(Ki_Max); | |
1338 | ||
1339 | SERIAL_PROTOCOLLN(""); | |
1340 | } | |
1341 | break; | |
1342 | #endif //PIDTEMP | |
1343 | case 240: // M240 Triggers a camera by emulating a Canon RC-1 : http://www.doc-diy.net/photo/rc-1_hacked/ | |
1344 | { | |
1345 | #ifdef PHOTOGRAPH_PIN | |
1346 | #if (PHOTOGRAPH_PIN > -1) | |
1347 | const uint8_t NUM_PULSES=16; | |
1348 | const float PULSE_LENGTH=0.01524; | |
1349 | for(int i=0; i < NUM_PULSES; i++) { | |
1350 | WRITE(PHOTOGRAPH_PIN, HIGH); | |
1351 | _delay_ms(PULSE_LENGTH); | |
1352 | WRITE(PHOTOGRAPH_PIN, LOW); | |
1353 | _delay_ms(PULSE_LENGTH); | |
1354 | } | |
1355 | delay(7.33); | |
1356 | for(int i=0; i < NUM_PULSES; i++) { | |
1357 | WRITE(PHOTOGRAPH_PIN, HIGH); | |
1358 | _delay_ms(PULSE_LENGTH); | |
1359 | WRITE(PHOTOGRAPH_PIN, LOW); | |
1360 | _delay_ms(PULSE_LENGTH); | |
1361 | } | |
1362 | #endif | |
1363 | #endif | |
1364 | } | |
1365 | break; | |
1366 | ||
1367 | case 302: // allow cold extrudes | |
1368 | { | |
1369 | if (code_seen('S')) | |
1370 | { | |
1371 | allow_cold_extrudes(code_value()); | |
1372 | }else{ | |
1373 | allow_cold_extrudes(true); | |
1374 | } | |
1375 | } | |
1376 | break; | |
1377 | case 303: // M303 PID autotune | |
1378 | { | |
1379 | float temp = 150.0; | |
1380 | if (code_seen('S')) temp=code_value(); | |
1381 | PID_autotune(temp); | |
1382 | } | |
1383 | break; | |
1384 | case 304: // Set thermistor parameters | |
1385 | { | |
1386 | // M304 H0 B3960 R4700 | |
1387 | // M304 H1 Bb Rr | |
1388 | if (code_seen('H')) | |
1389 | { | |
1390 | if(!code_value()){ | |
1391 | //set BED thermistor | |
1392 | if(code_seen('B')) b_beta = code_value(); | |
1393 | if(code_seen('R')) b_resistor = code_value(); | |
1394 | if(code_seen('T')) b_thermistor = code_value(); | |
1395 | b_inf = ( b_thermistor*exp(-b_beta/298.15) ); | |
1396 | SERIAL_PROTOCOL(MSG_OK); | |
1397 | SERIAL_PROTOCOL(" M304 H0 B"); | |
1398 | SERIAL_PROTOCOL(b_beta); | |
1399 | SERIAL_PROTOCOL(" R"); | |
1400 | SERIAL_PROTOCOL(b_resistor); | |
1401 | SERIAL_PROTOCOL(" T"); | |
1402 | SERIAL_PROTOCOL(b_thermistor); | |
1403 | SERIAL_PROTOCOLLN(""); | |
1404 | }else{ | |
1405 | //set active Nozzle thermistor | |
1406 | if(code_seen('B')) n_beta = code_value(); | |
1407 | if(code_seen('R')) n_resistor = code_value(); | |
1408 | if(code_seen('T')) n_thermistor = code_value(); | |
1409 | n_inf = ( n_thermistor*exp(-n_beta/298.15) ); | |
1410 | SERIAL_PROTOCOL(MSG_OK); | |
1411 | SERIAL_PROTOCOL(" M304 H1 B"); | |
1412 | SERIAL_PROTOCOL(n_beta); | |
1413 | SERIAL_PROTOCOL(" R"); | |
1414 | SERIAL_PROTOCOL(n_resistor); | |
1415 | SERIAL_PROTOCOL(" T"); | |
1416 | SERIAL_PROTOCOL(n_thermistor); | |
1417 | SERIAL_PROTOCOLLN(""); | |
1418 | } | |
1419 | } | |
1420 | } | |
1421 | break; | |
1422 | case 400: // M400 finish all moves | |
1423 | { | |
1424 | st_synchronize(); | |
1425 | } | |
1426 | break; | |
1427 | case 500: // Store settings in EEPROM | |
1428 | { | |
1429 | EEPROM_StoreSettings(); | |
1430 | } | |
1431 | break; | |
1432 | case 501: // Read settings from EEPROM | |
1433 | { | |
1434 | EEPROM_RetrieveSettings(); | |
1435 | } | |
1436 | break; | |
1437 | case 502: // Revert to default settings | |
1438 | { | |
1439 | EEPROM_RetrieveSettings(true); | |
1440 | } | |
1441 | break; | |
1442 | case 503: // print settings currently in memory | |
1443 | { | |
1444 | EEPROM_printSettings(); | |
1445 | } | |
1446 | break; | |
1447 | case 504: // print free memory | |
1448 | { | |
1449 | SERIAL_ECHO_START; | |
1450 | SERIAL_ECHOPGM("Free Memory:"); | |
1451 | SERIAL_ECHO(freeMemory()); | |
1452 | } | |
1453 | break; | |
1454 | case 999: // Restart after being stopped | |
1455 | Stopped = false; | |
1456 | gcode_LastN = Stopped_gcode_LastN; | |
1457 | FlushSerialRequestResend(); | |
1458 | break; | |
1459 | case 510: // FPU Enable | |
1460 | { | |
1461 | FPUEnable(); | |
1462 | } | |
1463 | break; | |
1464 | case 511: // FPU Reset | |
1465 | { | |
1466 | FPUReset(); | |
1467 | } | |
1468 | break; | |
1469 | case 512: // FPU Disable | |
1470 | { | |
1471 | FPUDisable(); | |
1472 | } | |
1473 | break; | |
1474 | #ifdef REPRAPPRO_MULTIMATERIALS | |
1475 | case 555: // Slave comms test | |
1476 | talkToSlave("t 0"); | |
1477 | SERIAL_ECHO_START; | |
1478 | SERIAL_ECHOPGM("Slave response:"); | |
1479 | SERIAL_ECHO(listenToSlave()); | |
1480 | break; | |
1481 | case 556: // Set temp | |
1482 | talkToSlave("T 0 100"); | |
1483 | break; | |
1484 | case 557: // Call stepper test | |
1485 | talkToSlave("A"); | |
1486 | break; | |
1487 | case 558: // Send interrupt | |
1488 | for(int ii=0; ii < 1000; ii++) | |
1489 | { | |
1490 | toggleSlaveClock(); | |
1491 | delay(1); | |
1492 | } | |
1493 | break; | |
1494 | #endif | |
1495 | ||
1496 | case 571: // enable extruder active pin | |
1497 | if (code_seen('S')) | |
1498 | { | |
1499 | m571_enabled = (int)code_value(); | |
1500 | } | |
1501 | ||
1502 | if (code_seen('E')) | |
1503 | { | |
1504 | n571_enabled = (int)code_value(); | |
1505 | } | |
1506 | ||
1507 | WRITE(M571_PIN, LOW);// M571 disable in any case! | |
1508 | ||
3 | 1509 | if (!(code_seen('S') || code_seen('E'))) { |
1510 | // only output to console when calles without parameters | |
0 | 1511 | SERIAL_ECHO_START; |
1512 | SERIAL_ECHO("Parameters: S<0|1> enable extruder active pin, E<0|1> if enabled prevent real drive movement"); | |
1513 | ||
1514 | SERIAL_ECHO_START; | |
1515 | SERIAL_ECHO("Extruder active pin: "); | |
1516 | if (m571_enabled) { | |
1517 | SERIAL_ECHOLN("enabled"); | |
1518 | } else { | |
1519 | SERIAL_ECHOLN("disabled"); | |
1520 | } | |
1521 | ||
1522 | SERIAL_ECHO_START; | |
1523 | SERIAL_ECHO("Extruder motor move: "); | |
1524 | if (!n571_enabled) { | |
1525 | SERIAL_ECHOLN("enabled"); | |
1526 | } else { | |
1527 | SERIAL_ECHOLN("disabled"); | |
1528 | } | |
3 | 1529 | } |
0 | 1530 | break; |
1531 | ||
1532 | ||
1533 | ||
1534 | } | |
1535 | } | |
1536 | ||
1537 | else if(code_seen('T')) | |
1538 | { | |
1539 | tmp_extruder = code_value(); | |
1540 | if(tmp_extruder >= EXTRUDERS) | |
1541 | { | |
1542 | SERIAL_ECHO_START; | |
1543 | SERIAL_ECHO(MSG_STANDBY_TEMP); | |
1544 | SERIAL_ECHO(active_extruder); | |
1545 | setTargetHotend(extruder_standby[active_extruder], active_extruder); | |
1546 | } | |
1547 | else | |
1548 | { | |
1549 | if((tmp_extruder != active_extruder) || !extruder_selected) | |
1550 | { | |
1551 | setTargetHotend(extruder_standby[active_extruder], active_extruder); | |
1552 | extruder_selected = true; | |
1553 | ||
1554 | // Deal with offsets here: record current pos as temp_position; | |
1555 | // move to temp_position + tmp_extruder - active_extruder; | |
1556 | // Set current pos to be temp_position | |
1557 | // TOTHINKABOUT: What about cumulative errors with a LOT of extruder changes? | |
1558 | ||
1559 | for(int8_t i=0; i < NUM_AXIS; i++) | |
1560 | { | |
1561 | temp_position[i] = current_position[i]; | |
1562 | destination[i] = current_position[i]; | |
1563 | } | |
1564 | next_feedrate = feedrate; | |
1565 | x_off_d = extruder_x_off[tmp_extruder] - extruder_x_off[active_extruder]; | |
1566 | y_off_d = extruder_y_off[tmp_extruder] - extruder_y_off[active_extruder]; | |
1567 | z_off_d = extruder_z_off[tmp_extruder] - extruder_z_off[active_extruder]; | |
1568 | ||
1569 | if(z_off_d > 0) | |
1570 | { | |
1571 | destination[Z_AXIS] += z_off_d; | |
1572 | feedrate = fast_home_feedrate[Z_AXIS]; | |
1
b584642d4f58
several modifications to support laser enable - still needs cleanup
mbayer
parents:
0
diff
changeset
|
1573 | prepare_move(false); |
0 | 1574 | destination[X_AXIS] = temp_position[X_AXIS] + x_off_d; |
1575 | destination[Y_AXIS] = temp_position[Y_AXIS] + y_off_d; | |
1576 | feedrate = fast_home_feedrate[X_AXIS]; | |
1
b584642d4f58
several modifications to support laser enable - still needs cleanup
mbayer
parents:
0
diff
changeset
|
1577 | prepare_move(false); |
0 | 1578 | } else |
1579 | { | |
1580 | destination[X_AXIS] += x_off_d; | |
1581 | destination[Y_AXIS] += y_off_d; | |
1582 | feedrate = fast_home_feedrate[X_AXIS]; | |
1
b584642d4f58
several modifications to support laser enable - still needs cleanup
mbayer
parents:
0
diff
changeset
|
1583 | prepare_move(false); |
0 | 1584 | destination[Z_AXIS] = temp_position[Z_AXIS] + z_off_d; |
1585 | feedrate = fast_home_feedrate[Z_AXIS]; | |
1
b584642d4f58
several modifications to support laser enable - still needs cleanup
mbayer
parents:
0
diff
changeset
|
1586 | prepare_move(false); |
0 | 1587 | } |
1588 | ||
1589 | for(int8_t i=0; i < NUM_AXIS; i++) | |
1590 | current_position[i] = temp_position[i]; | |
1591 | feedrate = next_feedrate; | |
1592 | active_extruder = tmp_extruder; | |
1593 | ||
1594 | SERIAL_ECHO_START; | |
1595 | SERIAL_ECHO(MSG_ACTIVE_EXTRUDER); | |
1596 | SERIAL_PROTOCOLLN((int)active_extruder); | |
1597 | ||
1598 | setTargetHotend(extruder_temperature[active_extruder], active_extruder); | |
1599 | ||
1600 | ||
1601 | codenum = millis(); | |
1602 | wait_for_temp(active_extruder, codenum); | |
1603 | } | |
1604 | } | |
1605 | } | |
1606 | ||
1607 | ||
1608 | else | |
1609 | { | |
1610 | SERIAL_ECHO_START; | |
1611 | SERIAL_ECHOPGM(MSG_UNKNOWN_COMMAND); | |
1612 | SERIAL_ECHO(cmdbuffer[bufindr]); | |
1613 | SERIAL_ECHOLNPGM("\""); | |
1614 | } | |
1615 | ||
1616 | ClearToSend(); | |
1617 | } | |
1618 | ||
1619 | void FlushSerialRequestResend() | |
1620 | { | |
1621 | //char cmdbuffer[bufindr][100]="Resend:"; | |
1622 | MYSERIAL.flush(); | |
1623 | SERIAL_PROTOCOLPGM(MSG_RESEND); | |
1624 | SERIAL_PROTOCOLLN(gcode_LastN + 1); | |
1625 | ClearToSend(); | |
1626 | } | |
1627 | ||
1628 | void ClearToSend() | |
1629 | { | |
1630 | previous_millis_cmd = millis(); | |
1631 | #ifdef SDSUPPORT | |
1632 | if(fromsd[bufindr]) | |
1633 | return; | |
1634 | #endif //SDSUPPORT | |
1635 | SERIAL_PROTOCOLLNPGM(MSG_OK); | |
1636 | } | |
1637 | ||
1638 | void get_coordinates() | |
1639 | { | |
1640 | for(int8_t i=0; i < NUM_AXIS; i++) { | |
1641 | if(code_seen(axis_codes[i])) destination[i] = (float)code_value() + (axis_relative_modes[i] || relative_mode)*current_position[i]; | |
1642 | else destination[i] = current_position[i]; //Are these else lines really needed? | |
1643 | } | |
1644 | if(code_seen('F')) { | |
1645 | next_feedrate = code_value(); | |
1646 | if(next_feedrate > 0.0) feedrate = next_feedrate; | |
1647 | } | |
1648 | } | |
1649 | ||
1650 | void get_arc_coordinates() | |
1651 | { | |
1652 | get_coordinates(); | |
1653 | if(code_seen('I')) { | |
1654 | offset[0] = code_value(); | |
1655 | } | |
1656 | else { | |
1657 | offset[0] = 0.0; | |
1658 | } | |
1659 | if(code_seen('J')) { | |
1660 | offset[1] = code_value(); | |
1661 | } | |
1662 | else { | |
1663 | offset[1] = 0.0; | |
1664 | } | |
1665 | } | |
1666 | ||
1
b584642d4f58
several modifications to support laser enable - still needs cleanup
mbayer
parents:
0
diff
changeset
|
1667 | void prepare_move(bool laser_on) |
0 | 1668 | { |
1669 | ||
1670 | // transform destination ********************************************* | |
1671 | ||
1672 | FPUTransform_transformDestination(); | |
1673 | ||
1674 | if (min_software_endstops) { | |
1675 | if (modified_destination[X_AXIS] < X_HOME_POS) modified_destination[X_AXIS] = X_HOME_POS; | |
1676 | if (modified_destination[Y_AXIS] < Y_HOME_POS) modified_destination[Y_AXIS] = Y_HOME_POS; | |
1677 | if (modified_destination[Z_AXIS] < Z_HOME_POS) modified_destination[Z_AXIS] = Z_HOME_POS; | |
1678 | } | |
1679 | ||
1680 | if (max_software_endstops) { | |
1681 | if (modified_destination[X_AXIS] > max_length[X_AXIS]) modified_destination[X_AXIS] = max_length[X_AXIS]; | |
1682 | if (modified_destination[Y_AXIS] > max_length[Y_AXIS]) modified_destination[Y_AXIS] = max_length[Y_AXIS]; | |
1683 | if (modified_destination[Z_AXIS] > max_length[Z_AXIS]) modified_destination[Z_AXIS] = max_length[Z_AXIS]; | |
1684 | } | |
1685 | previous_millis_cmd = millis(); | |
1
b584642d4f58
several modifications to support laser enable - still needs cleanup
mbayer
parents:
0
diff
changeset
|
1686 | plan_buffer_line(modified_destination[X_AXIS], modified_destination[Y_AXIS], modified_destination[Z_AXIS], destination[E_AXIS], feedrate*feedmultiply/60/100.0, active_extruder, laser_on); |
0 | 1687 | for(int8_t i=0; i < NUM_AXIS; i++) { |
1688 | current_position[i] = destination[i]; | |
1689 | } | |
1690 | } | |
1691 | ||
1692 | void prepare_arc_move(char isclockwise) { | |
1693 | float r = hypot(offset[X_AXIS], offset[Y_AXIS]); // Compute arc radius for mc_arc | |
1694 | ||
1695 | // transform destination ********************************************* | |
1696 | FPUTransform_transformDestination(); | |
1697 | ||
1698 | // Trace the arc | |
1699 | mc_arc(current_position, modified_destination, offset, X_AXIS, Y_AXIS, Z_AXIS, feedrate*feedmultiply/60/100.0, r, isclockwise, active_extruder); | |
1700 | ||
1701 | // As far as the parser is concerned, the position is now == target. In reality the | |
1702 | // motion control system might still be processing the action and the real tool position | |
1703 | // in any intermediate location. | |
1704 | for(int8_t i=0; i < NUM_AXIS; i++) { | |
1705 | current_position[i] = destination[i]; | |
1706 | } | |
1707 | previous_millis_cmd = millis(); | |
1708 | } | |
1709 | ||
1710 | #ifdef CONTROLLERFAN_PIN | |
1711 | unsigned long lastMotor = 0; //Save the time for when a motor was turned on last | |
1712 | unsigned long lastMotorCheck = 0; | |
1713 | ||
1714 | void controllerFan() | |
1715 | { | |
1716 | if ((millis() - lastMotorCheck) >= 2500) //Not a time critical function, so we only check every 2500ms | |
1717 | { | |
1718 | lastMotorCheck = millis(); | |
1719 | ||
1720 | if(!READ(X_ENABLE_PIN) || !READ(Y_ENABLE_PIN) || !READ(Z_ENABLE_PIN) | |
1721 | #if EXTRUDERS > 2 | |
1722 | || !READ(E2_ENABLE_PIN) | |
1723 | #endif | |
1724 | #if EXTRUDER > 1 | |
1725 | || !READ(E2_ENABLE_PIN) | |
1726 | #endif | |
1727 | || !READ(E0_ENABLE_PIN)) //If any of the drivers are enabled... | |
1728 | { | |
1729 | lastMotor = millis(); //... set time to NOW so the fan will turn on | |
1730 | } | |
1731 | ||
1732 | if ((millis() - lastMotor) >= (CONTROLLERFAN_SEC*1000UL) || lastMotor == 0) //If the last time any driver was enabled, is longer since than CONTROLLERSEC... | |
1733 | { | |
1734 | WRITE(CONTROLLERFAN_PIN, LOW); //... turn the fan off | |
1735 | } | |
1736 | else | |
1737 | { | |
1738 | WRITE(CONTROLLERFAN_PIN, HIGH); //... turn the fan on | |
1739 | } | |
1740 | } | |
1741 | } | |
1742 | #endif | |
1743 | ||
1744 | void manage_inactivity(byte debug) | |
1745 | { | |
1746 | if( (millis() - previous_millis_cmd) > max_inactive_time ) | |
1747 | if(max_inactive_time) | |
1748 | kill(); | |
1749 | if(stepper_inactive_time) { | |
1750 | if( (millis() - previous_millis_cmd) > stepper_inactive_time ) | |
1751 | { | |
1752 | if(blocks_queued() == false) { | |
1753 | disable_x(); | |
1754 | disable_y(); | |
1755 | disable_z(); | |
1756 | disable_e0(); | |
1757 | disable_e1(); | |
1758 | disable_e2(); | |
1759 | if (m571_enabled) WRITE(M571_PIN, LOW);// M571 disable | |
1760 | } | |
1761 | } | |
1762 | } | |
1763 | #ifdef CONTROLLERFAN_PIN | |
1764 | controllerFan(); //Check if fan should be turned on to cool stepper drivers down | |
1765 | #endif | |
1766 | check_axes_activity(); | |
1767 | } | |
1768 | ||
1769 | void kill() | |
1770 | { | |
1771 | cli(); // Stop interrupts | |
1772 | disable_heater(); | |
1773 | ||
1774 | disable_x(); | |
1775 | disable_y(); | |
1776 | disable_z(); | |
1777 | disable_e0(); | |
1778 | disable_e1(); | |
1779 | disable_e2(); | |
1780 | if (m571_enabled) WRITE(M571_PIN, LOW);// M571 disable | |
1781 | ||
1782 | SERIAL_ERROR_START; | |
1783 | SERIAL_ERRORLNPGM(MSG_ERR_KILLED); | |
1784 | LCD_MESSAGEPGM(MSG_KILLED); | |
1785 | suicide(); | |
1786 | while(1); // Wait for reset | |
1787 | } | |
1788 | ||
1789 | void Stop() | |
1790 | { | |
1791 | disable_heater(); | |
1792 | if(Stopped == false) { | |
1793 | Stopped = true; | |
1794 | Stopped_gcode_LastN = gcode_LastN; // Save last g_code for restart | |
1795 | if (m571_enabled) WRITE(M571_PIN, LOW);// M571 disable | |
1796 | SERIAL_ERROR_START; | |
1797 | SERIAL_ERRORLNPGM(MSG_ERR_STOPPED); | |
1798 | LCD_MESSAGEPGM(MSG_STOPPED); | |
1799 | } | |
1800 | } | |
1801 | ||
1802 | bool IsStopped() { return Stopped; }; | |
1803 | ||
1804 |