Skip to content

Commit ad22ce1

Browse files
committed
updates to CNC menu.
some features disabled while in pause printing.
1 parent 85f790d commit ad22ce1

File tree

3 files changed

+104
-141
lines changed

3 files changed

+104
-141
lines changed

Marlin/Configuration.h

+5-7
Original file line numberDiff line numberDiff line change
@@ -150,19 +150,14 @@
150150
#define CNC_MAX_MILLING_SPEED 1000 //mm/minute
151151
#define CNC_MAX_DRILLING_SPEED 300 //mm/minute
152152

153-
#define USE_PROBE_BLOCK
153+
//#define USE_PROBE_BLOCK
154154
#ifdef USE_PROBE_BLOCK
155155
//we need the block dimensions in mm
156156
#define PROBE_BLOCK_X 35
157157
#define PROBE_BLOCK_Y 60
158158
#define PROBE_BLOCK_Z 10
159159
#endif
160160

161-
//tool changing position from the PROBE BLOCK
162-
#define TOOL_CHANGE_X 300
163-
#define TOOL_CHANGE_Y 200
164-
#define TOOL_CHANGE_Z 100
165-
166161
#endif //CNC
167162

168163

@@ -340,8 +335,9 @@
340335
*
341336
* :{ 0:'No power switch', 1:'ATX', 2:'X-Box 360' }
342337
*/
343-
#define POWER_SUPPLY 0
338+
//#define POWER_SUPPLY 0
344339

340+
/*
345341
#if POWER_SUPPLY > 0
346342
// Enable this option to leave the PSU off at startup.
347343
// Power to steppers and heaters will need to be turned on with M80.
@@ -356,6 +352,8 @@
356352
#endif
357353
358354
#endif
355+
*/
356+
359357

360358
// @section temperature
361359

Marlin/Configuration_adv.h

+1-2
Original file line numberDiff line numberDiff line change
@@ -1196,7 +1196,7 @@
11961196

11971197
// The ASCII buffer for serial input
11981198
#define MAX_CMD_SIZE 96
1199-
#define BUFSIZE 8 //MFD: was 4
1199+
#define BUFSIZE 4
12001200

12011201
// Transmission to Host Buffer Size
12021202
// To save 386 bytes of PROGMEM (and TX_BUFFER_SIZE+3 bytes of RAM) set to 0.
@@ -1232,7 +1232,6 @@
12321232
// Enable an emergency-command parser to intercept certain commands as they
12331233
// enter the serial receive buffer, so they cannot be blocked.
12341234
// Currently handles M108, M112, M410
1235-
//MFD: added M25 for pausing when printing from SD
12361235
// Does not work on boards using AT90USB (USBCON) processors!
12371236
#define EMERGENCY_PARSER
12381237

Marlin/src/lcd/menu/menu_cnc.cpp

+98-132
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222

2323

2424
/****************************************************************************
25-
* Written By Florin Muntean 2019 *
25+
* Written By Florin Muntean (C)2019 *
2626
* *
2727
* This program is free software: you can redistribute it and/or modify *
2828
* it under the terms of the GNU General Public License as published by *
@@ -40,60 +40,49 @@
4040

4141

4242
/*
43-
CNC Menu
44-
--------
45-
MAIN
46-
CNC
47-
RESET ALL AXES
48-
PROBING
49-
PROBE Z DOWN
50-
PROBE X RIGHT
51-
PROBE X LEFT
52-
PROBE Y RIGHT
53-
PROBE Y LEFT
54-
MILLING
55-
MILL TOP
56-
SET TOOL DIAMETER
57-
SET PATH OVERLAP %
58-
SET BOARD SIZE X
59-
SET BOARD SIZE Y
60-
SET MILL DEPTH
61-
SET MILL SPEED
62-
SET MILL DIRECTION
63-
Execute MILL TOP
64-
MILL X SIDE
65-
SET MILL SIZE
66-
SET MILL DEPTH
67-
SET MILL SPEED
68-
Execute MILL X SIDE
69-
MILL Y SIDE
70-
SET MILL SIZE
71-
SET MILL DEPTH
72-
SET MILL SPEED
73-
Execute MILL Y SIDE
74-
DRILL
75-
SET MILL DEPTH
76-
SET MILL SPEED
77-
Execute DRILL
78-
RESET X AZIS
79-
RESET Y AZIS
80-
RESET Z AXIS
43+
G54 ; Select workspace 0 (this is the machine physical workspace)
44+
G55 ; Select workspace 1 (this will be the tool change workspace)
45+
G56 ; Select workspace 2 (this will be the workpiece milling workspace)
8146
82-
*/
47+
48+
49+
Main process:
50+
1. if not using home switches and homing select CNC -> Reset all Axes
51+
2. Move to tool change position aka where the z probing is done using MOVE Axis menu
52+
3. Set or change the Z probing offset if necessary CNC -> XYZ Probing -> Z probe offset
53+
3. CNC -> XYZ Probing -> Z probe down
54+
4. Move to work piece origin using MOVE Axis menu
55+
5. CNC -> Set Workpiece Origin
56+
6. Start the printing
57+
58+
For Change Tool script use:
59+
M25 ; pause
60+
M801 ; use M801 macro to move to the position
61+
# ; wait here for pause to take effect
62+
; change tool
63+
; using CNC -> XYZ Probing -> Z probe down will reset the tool Z
64+
; use CNC -> Move to Workpiece origin
65+
; resume will continue priting with the new tool now
66+
67+
68+
*/
8369

8470

8571

8672
#include "../../inc/MarlinConfigPre.h"
8773

8874
#if HAS_LCD_MENU && ENABLED(CNC)
8975

76+
#include "../../core/macros.h"
9077
#include "menu.h"
9178
#include "../../module/motion.h"
9279
#include "../../module/stepper.h"
9380
#include "../../gcode/queue.h"
9481
#include "../../gcode/gcode.h"
9582
#include "../../gcode/parser.h"
9683
#include "../../sd/cardreader.h"
84+
#include "../../module/printcounter.h"
85+
#include "../../module/endstops.h"
9786

9887
#if ENABLED(DELTA)
9988
#include "../../module/delta.h"
@@ -105,40 +94,16 @@ MAIN
10594
#include "../../feature/bedlevel/bedlevel.h"
10695
#endif
10796

108-
extern millis_t manual_move_start_time;
109-
extern int8_t manual_move_axis;
110-
#if IS_KINEMATIC
111-
extern float manual_move_offset;
112-
#endif
113-
114-
//
115-
// "Motion" > "Move Axis" submenu
116-
// most of it used directly from menu_motion.cpp
117-
//
118-
119-
//these are defined by menu motion
120-
extern void lcd_move_x();
121-
extern void lcd_move_y();
122-
extern void lcd_move_z();
123-
124-
//defined under the lcd move menu
125-
extern void lcd_move_get_x_amount();
126-
extern void lcd_move_get_y_amount();
127-
extern void lcd_move_get_z_amount();
97+
//extern millis_t manual_move_start_time;
98+
//extern int8_t manual_move_axis;
99+
//#if IS_KINEMATIC
100+
// extern float manual_move_offset;
101+
//#endif
128102

129-
/*
130-
#if ENABLED(DELTA)
131-
void lcd_lower_z_to_clip_height() {
132-
line_to_z(delta_clip_start_height);
133-
ui.synchronize();
134-
}
135-
#endif
136-
*/
137103

138104
void reset_all_axes(){
139-
//run the G92 X0 Y0 Z0
140-
//enqueue_and_echo_commands_now_P(PSTR("G92 X0 Y0 Z0"));
141-
//G92 applies offsets only so we can't use it here
105+
//Setting machine physical origin helps especially if not using home switches
106+
//G92 applies offsets only so we can't use it here
142107

143108
//enable all steppers to make sure they keep their position
144109
enable_all_steppers();
@@ -184,6 +149,8 @@ static float millingZ = DEFAULT_CNC_MILLING_Z;
184149
static float toolDiameter = DEFAULT_CNC_TOOL_DIAMETER;
185150
static float millSpeed = DEFAULT_CNC_MILLING_SPEED;
186151
static uint8_t millOverlap = DEFAULT_CNC_MILLING_OVERLAP;
152+
static float zProbeOffset = 0;
153+
187154

188155
static float scan[4]; //used to keep the min max for x and Y during scanning
189156
#define MINX scan[0]
@@ -233,6 +200,8 @@ G56 ; Select workspace 2 (this will be the milling workspace)
233200
G92 X0 Y0 Z0 ;after we manually moved to the desired starting position for milling
234201
;at this point we can start milling
235202
*/
203+
204+
#ifdef USE_PROBE_BLOCK
236205
void cnc_tool_workspace(){
237206
char cmd[50],str_1[16];//,str_2[16];
238207

@@ -304,6 +273,10 @@ void cnc_tool_workspace(){
304273
//sprintf_P(cmd, PSTR("G0 X0 Y0 Z0"),str_1);
305274
//cnc_process_command(cmd);
306275
}
276+
#else
277+
void cnc_tool_workspace(){};
278+
#endif
279+
307280

308281

309282

@@ -605,71 +578,41 @@ void cnc_start_drilling(){
605578

606579

607580
void set_workpiece_origin(){
608-
cnc_process_command_P(PSTR("G56\nG92 X0 Y0 Z0\nM300"));
581+
cnc_process_command_P(PSTR("G56\nG92 X0 Y0\nM300")); //we keep the same Z as before
609582
ui.return_to_status();
610583
}
611584

612-
//CNC -> MOVE AXIS submenu
613-
void menu_cnc_move() {
614-
START_MENU();
615-
MENU_BACK(MSG_CNC);
616-
617-
#if HAS_SOFTWARE_ENDSTOPS && ENABLED(SOFT_ENDSTOPS_MENU_ITEM)
618-
MENU_ITEM_EDIT(bool, MSG_LCD_SOFT_ENDSTOPS, &soft_endstops_enabled);
619-
#endif
620-
621-
if (
622-
#if IS_KINEMATIC || ENABLED(NO_MOTION_BEFORE_HOMING)
623-
all_axes_homed()
624-
#else
625-
true
626-
#endif
627-
) {
628-
if (
629-
#if ENABLED(DELTA)
630-
current_position[Z_AXIS] <= delta_clip_start_height
631-
#else
632-
true
633-
#endif
634-
) {
635-
MENU_ITEM(submenu, MSG_MOVE_X, lcd_move_get_x_amount);
636-
MENU_ITEM(submenu, MSG_MOVE_Y, lcd_move_get_y_amount);
637-
}
638-
#if ENABLED(DELTA)
639-
else
640-
MENU_ITEM(function, MSG_FREE_XY, lcd_lower_z_to_clip_height);
641-
#endif
642-
643-
MENU_ITEM(submenu, MSG_MOVE_Z, lcd_move_get_z_amount);
585+
void probing_z_down(){
586+
char cmd[50],str_1[10];
587+
dtostrf(zProbeOffset, 1, 3, str_1);
588+
sprintf_P(cmd, PSTR("G56\nG91\nG38.2 Z-10\nG90\nG92 Z%s"),str_1);
589+
cnc_process_command(cmd);
590+
if (READ(Z_MIN_PROBE_PIN) != Z_MIN_PROBE_ENDSTOP_INVERTING) //probe endstop hit
591+
{
592+
cnc_process_command_P(PSTR("G1 Z10"));
593+
cnc_process_command_P(PSTR("G55\nG90\nG92 X0 Y0 Z0"));
594+
cnc_process_command_P(PSTR("M810 G55|G0 Z0|G0 X0 Y0\nG56"));
595+
596+
ui.return_to_status();
644597
}
645-
//else
646-
// MENU_ITEM(gcode, MSG_AUTO_HOME, PSTR("G28"));
647-
648-
END_MENU();
649598
}
650599

600+
#define busy (IS_SD_PRINTING() || print_job_timer.isRunning() || print_job_timer.isPaused())
601+
651602
//CNC -> PROBING submenu
652603
void menu_cnc_probing() {
653604
START_MENU();
654605
MENU_BACK(MSG_CNC);
655606

656-
//the most used command here is to set the Z axis when chaning tools
657-
MENU_ITEM(gcode, MSG_CNC_PROBE_Z, PSTR("G56\nG91\nG38.2 Z-10\nG90\nG92 Z0"));
607+
//the most used command here is to set the Z axis when changing tools so we put it first
608+
MENU_ITEM(function, MSG_CNC_PROBE_Z, probing_z_down);
658609

659610

660-
//establish the cnc tool workspace
661-
MENU_ITEM(function, MSG_CNC_TOOL_WORKSPACE,cnc_tool_workspace);
662-
663-
//this creates and executes a macro to move to specific location and can be used during the tool change procedure
664-
// so M810 is set to move to the Tool Change position
665-
MENU_ITEM(gcode, MSG_CNC_MOVE_TOOL_CHANGE, PSTR("M810 G55|G0 Z" STRINGIFY(TOOL_CHANGE_Z) "|G0 X" STRINGIFY(TOOL_CHANGE_X) " Y" STRINGIFY(TOOL_CHANGE_Y) "\nM810" ));
666611

667-
MENU_ITEM(function, MSG_CNC_SET_WORKPIECE_ORIGIN, set_workpiece_origin);
668-
669-
MENU_ITEM(gcode, MSG_CNC_MOVE_WORKPIECE, PSTR("G56\nG0 X0 Y0 Z0"));
670-
671-
MENU_ITEM_EDIT(float3, MSG_CNC_MILLING_TOOL, &toolDiameter, 0,CNC_MAX_TOOL_DIAMETER);
672-
612+
if (!busy){
613+
MENU_ITEM_EDIT(float3, MSG_ZPROBE_ZOFFSET, &zProbeOffset , -50,50);
614+
MENU_ITEM_EDIT(float3, MSG_CNC_MILLING_TOOL, &toolDiameter, 0,CNC_MAX_TOOL_DIAMETER);
615+
}
673616

674617
//MENU_ITEM(gcode, MSG_CNC_PROBE_X_RIGHT, PSTR("G91\nG38.2 X20\nG90\nG92 Z0"));
675618
//MENU_ITEM(gcode, MSG_CNC_PROBE_X_LEFT, PSTR("G91\nG38.2 X-20\nG90\nG92 Z0"));
@@ -888,15 +831,15 @@ extern int8_t sd_top_line, sd_items;
888831
if (parser.seen_axis()){
889832
if (parser.seen('X')){
890833
float x = parser.value_per_axis_units(X_AXIS);
891-
MINX = MIN(MINX, x);
892-
MAXX = MAX(MAXX, x);
834+
MINX = _MIN(MINX, x);
835+
MAXX = _MAX(MAXX, x);
893836
//SERIAL_ECHOPAIR_F("X=",x,2);
894837
}
895838

896839
if (parser.seen('Y')){
897840
float y = parser.value_per_axis_units(Y_AXIS);
898-
MINY = MIN(MINY, y);
899-
MAXY = MAX(MAXY, y);
841+
MINY = _MIN(MINY, y);
842+
MAXY = _MAX(MAXY, y);
900843
//SERIAL_ECHOLNPAIR_F(" Y=",y,2);
901844
}
902845

@@ -1117,8 +1060,11 @@ void menu_cnc() {
11171060
//
11181061
MENU_BACK(MSG_MAIN);
11191062

1063+
1064+
11201065
//Resetting coordinates
1121-
MENU_ITEM(function, MSG_CNC_RESET_ALL, reset_all_axes);
1066+
if (!busy)
1067+
MENU_ITEM(function, MSG_CNC_RESET_ALL, reset_all_axes);
11221068

11231069

11241070

@@ -1128,15 +1074,35 @@ void menu_cnc() {
11281074
#if ENABLED(DELTA)
11291075
if (all_axes_homed())
11301076
#endif
1131-
// MENU_ITEM(submenu, MSG_MOVE_AXIS, menu_cnc_move);
1077+
11321078

1079+
if (busy)
1080+
{
1081+
//the most used command here is to set the Z axis when changing tools so we put it first
1082+
MENU_ITEM(function,MSG_CNC_PROBE " " MSG_CNC_PROBE_Z, probing_z_down);
1083+
}else
1084+
MENU_ITEM(submenu, MSG_CNC_PROBE, menu_cnc_probing);
11331085

1086+
//establish the cnc tool workspace
1087+
if (!busy)
1088+
MENU_ITEM(function, MSG_CNC_TOOL_WORKSPACE,cnc_tool_workspace);
11341089

1135-
MENU_ITEM(submenu, MSG_CNC_PROBE, menu_cnc_probing);
1136-
MENU_ITEM(submenu, MSG_CNC_MILLING, menu_cnc_milling);
1137-
1138-
MENU_ITEM(submenu, MSG_CNC_SCAN,menu_cnc_scan);
1090+
//this creates and executes a macro to move to specific location and can be used during the tool change procedure
1091+
// so M810 is set to move to the Tool Change position
1092+
//MENU_ITEM(gcode, MSG_CNC_MOVE_TOOL_CHANGE, PSTR("M810 G55|G0 Z" STRINGIFY(TOOL_CHANGE_Z) "|G0 X" STRINGIFY(TOOL_CHANGE_X) " Y" STRINGIFY(TOOL_CHANGE_Y) "\nM810" ));
1093+
MENU_ITEM(gcode, MSG_CNC_MOVE_TOOL_CHANGE, PSTR("M810" ));
1094+
1095+
if (!busy)
1096+
MENU_ITEM(function, MSG_CNC_SET_WORKPIECE_ORIGIN, set_workpiece_origin);
11391097

1098+
MENU_ITEM(gcode, MSG_CNC_MOVE_WORKPIECE, PSTR("G56\nG0 X0 Y0"));
1099+
1100+
1101+
if (!busy)
1102+
{
1103+
MENU_ITEM(submenu, MSG_CNC_MILLING, menu_cnc_milling);
1104+
MENU_ITEM(submenu, MSG_CNC_SCAN,menu_cnc_scan);
1105+
}
11401106
//settings
11411107
MENU_ITEM(submenu, MSG_CONFIGURATION,menu_cnc_config);
11421108

0 commit comments

Comments
 (0)