22
22
23
23
24
24
/* ***************************************************************************
25
- * Written By Florin Muntean 2019 *
25
+ * Written By Florin Muntean (C) 2019 *
26
26
* *
27
27
* This program is free software: you can redistribute it and/or modify *
28
28
* it under the terms of the GNU General Public License as published by *
40
40
41
41
42
42
/*
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)
81
46
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
+ */
83
69
84
70
85
71
86
72
#include " ../../inc/MarlinConfigPre.h"
87
73
88
74
#if HAS_LCD_MENU && ENABLED(CNC)
89
75
76
+ #include " ../../core/macros.h"
90
77
#include " menu.h"
91
78
#include " ../../module/motion.h"
92
79
#include " ../../module/stepper.h"
93
80
#include " ../../gcode/queue.h"
94
81
#include " ../../gcode/gcode.h"
95
82
#include " ../../gcode/parser.h"
96
83
#include " ../../sd/cardreader.h"
84
+ #include " ../../module/printcounter.h"
85
+ #include " ../../module/endstops.h"
97
86
98
87
#if ENABLED(DELTA)
99
88
#include " ../../module/delta.h"
@@ -105,40 +94,16 @@ MAIN
105
94
#include " ../../feature/bedlevel/bedlevel.h"
106
95
#endif
107
96
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
128
102
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
- */
137
103
138
104
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
142
107
143
108
// enable all steppers to make sure they keep their position
144
109
enable_all_steppers ();
@@ -184,6 +149,8 @@ static float millingZ = DEFAULT_CNC_MILLING_Z;
184
149
static float toolDiameter = DEFAULT_CNC_TOOL_DIAMETER;
185
150
static float millSpeed = DEFAULT_CNC_MILLING_SPEED;
186
151
static uint8_t millOverlap = DEFAULT_CNC_MILLING_OVERLAP;
152
+ static float zProbeOffset = 0 ;
153
+
187
154
188
155
static float scan[4 ]; // used to keep the min max for x and Y during scanning
189
156
#define MINX scan[0 ]
@@ -233,6 +200,8 @@ G56 ; Select workspace 2 (this will be the milling workspace)
233
200
G92 X0 Y0 Z0 ;after we manually moved to the desired starting position for milling
234
201
;at this point we can start milling
235
202
*/
203
+
204
+ #ifdef USE_PROBE_BLOCK
236
205
void cnc_tool_workspace (){
237
206
char cmd[50 ],str_1[16 ];// ,str_2[16];
238
207
@@ -304,6 +273,10 @@ void cnc_tool_workspace(){
304
273
// sprintf_P(cmd, PSTR("G0 X0 Y0 Z0"),str_1);
305
274
// cnc_process_command(cmd);
306
275
}
276
+ #else
277
+ void cnc_tool_workspace (){};
278
+ #endif
279
+
307
280
308
281
309
282
@@ -605,71 +578,41 @@ void cnc_start_drilling(){
605
578
606
579
607
580
void set_workpiece_origin (){
608
- cnc_process_command_P (PSTR (" G56\n G92 X0 Y0 Z0 \n M300" ));
581
+ cnc_process_command_P (PSTR (" G56\n G92 X0 Y0\n M300" )); // we keep the same Z as before
609
582
ui.return_to_status ();
610
583
}
611
584
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\n G91\n G38.2 Z-10\n G90\n G92 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\n G90\n G92 X0 Y0 Z0" ));
594
+ cnc_process_command_P (PSTR (" M810 G55|G0 Z0|G0 X0 Y0\n G56" ));
595
+
596
+ ui.return_to_status ();
644
597
}
645
- // else
646
- // MENU_ITEM(gcode, MSG_AUTO_HOME, PSTR("G28"));
647
-
648
- END_MENU ();
649
598
}
650
599
600
+ #define busy (IS_SD_PRINTING() || print_job_timer.isRunning() || print_job_timer.isPaused())
601
+
651
602
// CNC -> PROBING submenu
652
603
void menu_cnc_probing () {
653
604
START_MENU ();
654
605
MENU_BACK (MSG_CNC);
655
606
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 \n G91 \n G38.2 Z-10 \n G90 \n G92 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 );
658
609
659
610
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) " \n M810" ));
666
611
667
- MENU_ITEM (function, MSG_CNC_SET_WORKPIECE_ORIGIN, set_workpiece_origin);
668
-
669
- MENU_ITEM (gcode, MSG_CNC_MOVE_WORKPIECE, PSTR (" G56\n G0 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
+ }
673
616
674
617
// MENU_ITEM(gcode, MSG_CNC_PROBE_X_RIGHT, PSTR("G91\nG38.2 X20\nG90\nG92 Z0"));
675
618
// 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;
888
831
if (parser.seen_axis ()){
889
832
if (parser.seen (' X' )){
890
833
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);
893
836
// SERIAL_ECHOPAIR_F("X=",x,2);
894
837
}
895
838
896
839
if (parser.seen (' Y' )){
897
840
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);
900
843
// SERIAL_ECHOLNPAIR_F(" Y=",y,2);
901
844
}
902
845
@@ -1117,8 +1060,11 @@ void menu_cnc() {
1117
1060
//
1118
1061
MENU_BACK (MSG_MAIN);
1119
1062
1063
+
1064
+
1120
1065
// 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);
1122
1068
1123
1069
1124
1070
@@ -1128,15 +1074,35 @@ void menu_cnc() {
1128
1074
#if ENABLED(DELTA)
1129
1075
if (all_axes_homed ())
1130
1076
#endif
1131
- // MENU_ITEM(submenu, MSG_MOVE_AXIS, menu_cnc_move);
1077
+
1132
1078
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);
1133
1085
1086
+ // establish the cnc tool workspace
1087
+ if (!busy)
1088
+ MENU_ITEM (function, MSG_CNC_TOOL_WORKSPACE,cnc_tool_workspace);
1134
1089
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);
1139
1097
1098
+ MENU_ITEM (gcode, MSG_CNC_MOVE_WORKPIECE, PSTR (" G56\n G0 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
+ }
1140
1106
// settings
1141
1107
MENU_ITEM (submenu, MSG_CONFIGURATION,menu_cnc_config);
1142
1108
0 commit comments