Skip to content

Commit 921e5a9

Browse files
committed
Clean up and new streaming script check-mode feature.
[new] The stream.py streaming script now has a check-mode option, where it will place Grbl in $C check mode automatically and then stream the g-code program. It's a very fast way to check if the g-code program has any errors. [fix] The debug variable was not initialized if the debug option was enabled in config.h [fix] Updated error_codes CSV file to the same format as the others.
1 parent 790c666 commit 921e5a9

File tree

5 files changed

+113
-52
lines changed

5 files changed

+113
-52
lines changed

doc/csv/error_codes_en_US.csv

+37-37
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,37 @@
1-
Error Code in v1.1+ ,Error Message in v1.0-, Error Description
2-
1,Expected command letter,G-code words consist of a letter and a value. Letter was not found.
3-
2,Bad number format,Missing the expected G-code word value or numeric value format is not valid.
4-
3,Invalid statement,Grbl '$' system command was not recognized or supported.
5-
4,Value < 0,Negative value received for an expected positive value.
6-
5,Setting disabled,Homing cycle failure. Homing is not enabled via settings.
7-
6,Value < 3 usec,Minimum step pulse time must be greater than 3usec.
8-
7,EEPROM read fail. Using defaults,An EEPROM read failed. Auto-restoring affected EEPROM to default values.
9-
8,Not idle,Grbl '$' command cannot be used unless Grbl is IDLE. Ensures smooth operation during a job.
10-
9,G-code lock,G-code commands are locked out during alarm or jog state.
11-
10,Homing not enabled,Soft limits cannot be enabled without homing also enabled.
12-
11,Line overflow,Max characters per line exceeded. Received command line was not executed.
13-
12,Step rate > 30kHz,Grbl '$' setting value cause the step rate to exceed the maximum supported.
14-
13,Check Door,Safety door detected as opened and door state initiated.
15-
14,Line length exceeded,Build info or startup line exceeded EEPROM line length limit. Line not stored.
16-
15,Travel exceeded,Jog target exceeds machine travel. Jog command has been ignored.
17-
16,Invalid jog command,Jog command has no '=' or contains prohibited g-code.
18-
17,Setting disabled,Laser mode requires PWM output.
19-
20,Unsupported command,Unsupported or invalid g-code command found in block.
20-
21,Modal group violation,More than one g-code command from same modal group found in block.
21-
22,Undefined feed rate,Feed rate has not yet been set or is undefined.
22-
23,Invalid gcode ID:23,G-code command in block requires an integer value.
23-
24,Invalid gcode ID:24,More than one g-code command that requires axis words found in block.
24-
25,Invalid gcode ID:25,Repeated g-code word found in block.
25-
26,Invalid gcode ID:26,No axis words found in block for g-code command or current modal state which requires them.
26-
27,Invalid gcode ID:27,Line number value is invalid.
27-
28,Invalid gcode ID:28,G-code command is missing a required value word.
28-
29,Invalid gcode ID:29,G59.x work coordinate systems are not supported.
29-
30,Invalid gcode ID:30,G53 only allowed with G0 and G1 motion modes.
30-
31,Invalid gcode ID:31,Axis words found in block when no command or current modal state uses them.
31-
32,Invalid gcode ID:32,G2 and G3 arcs require at least one in-plane axis word.
32-
33,Invalid gcode ID:33,Motion command target is invalid.
33-
34,Invalid gcode ID:34,Arc radius value is invalid.
34-
35,Invalid gcode ID:35,G2 and G3 arcs require at least one in-plane offset word.
35-
36,Invalid gcode ID:36,Unused value words found in block.
36-
37,Invalid gcode ID:37,G43.1 dynamic tool length offset is not assigned to configured tool length axis.
37-
38,Invalid gcode ID:38,Tool number greater than max supported value.
1+
"Error Code in v1.1+","Error Message in v1.0-","Error Description"
2+
"1","Expected command letter","G-code words consist of a letter and a value. Letter was not found."
3+
"2","Bad number format","Missing the expected G-code word value or numeric value format is not valid."
4+
"3","Invalid statement","Grbl '$' system command was not recognized or supported."
5+
"4","Value < 0","Negative value received for an expected positive value."
6+
"5","Setting disabled","Homing cycle failure. Homing is not enabled via settings."
7+
"6","Value < 3 usec","Minimum step pulse time must be greater than 3usec."
8+
"7","EEPROM read fail. Using defaults","An EEPROM read failed. Auto-restoring affected EEPROM to default values."
9+
"8","Not idle","Grbl '$' command cannot be used unless Grbl is IDLE. Ensures smooth operation during a job."
10+
"9","G-code lock","G-code commands are locked out during alarm or jog state."
11+
"10","Homing not enabled","Soft limits cannot be enabled without homing also enabled."
12+
"11","Line overflow","Max characters per line exceeded. Received command line was not executed."
13+
"12","Step rate > 30kHz","Grbl '$' setting value cause the step rate to exceed the maximum supported."
14+
"13","Check Door","Safety door detected as opened and door state initiated."
15+
"14","Line length exceeded","Build info or startup line exceeded EEPROM line length limit. Line not stored."
16+
"15","Travel exceeded","Jog target exceeds machine travel. Jog command has been ignored."
17+
"16","Invalid jog command","Jog command has no '=' or contains prohibited g-code."
18+
"17","Setting disabled","Laser mode requires PWM output."
19+
"20","Unsupported command","Unsupported or invalid g-code command found in block."
20+
"21","Modal group violation","More than one g-code command from same modal group found in block."
21+
"22","Undefined feed rate","Feed rate has not yet been set or is undefined."
22+
"23","Invalid gcode ID:23","G-code command in block requires an integer value."
23+
"24","Invalid gcode ID:24","More than one g-code command that requires axis words found in block."
24+
"25","Invalid gcode ID:25","Repeated g-code word found in block."
25+
"26","Invalid gcode ID:26","No axis words found in block for g-code command or current modal state which requires them."
26+
"27","Invalid gcode ID:27","Line number value is invalid."
27+
"28","Invalid gcode ID:28","G-code command is missing a required value word."
28+
"29","Invalid gcode ID:29","G59.x work coordinate systems are not supported."
29+
"30","Invalid gcode ID:30","G53 only allowed with G0 and G1 motion modes."
30+
"31","Invalid gcode ID:31","Axis words found in block when no command or current modal state uses them."
31+
"32","Invalid gcode ID:32","G2 and G3 arcs require at least one in-plane axis word."
32+
"33","Invalid gcode ID:33","Motion command target is invalid."
33+
"34","Invalid gcode ID:34","Arc radius value is invalid."
34+
"35","Invalid gcode ID:35","G2 and G3 arcs require at least one in-plane offset word."
35+
"36","Invalid gcode ID:36","Unused value words found in block."
36+
"37","Invalid gcode ID:37","G43.1 dynamic tool length offset is not assigned to configured tool length axis."
37+
"38","Invalid gcode ID:38","Tool number greater than max supported value."

doc/log/commit_log_v1.1.txt

+19
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,22 @@
1+
----------------
2+
Date: 2017-05-31
3+
Author: chamnit
4+
Subject: New nonlinear spindle speed PWM output model and solution. Updated scripts.
5+
6+
[new] A nonlinear spindle speed/PWM output option via a piecewise
7+
linear fit model. Enabled through config.h and solved by a Python
8+
script in /doc/script
9+
10+
[new] fit_nonlinear_spindle.py. A solver script that can be run on
11+
http://repl.it for free. No Python install necessary. All instructions
12+
are available in the script file comments.
13+
14+
[new] stream.py has been updated to include status reports feedback at
15+
1 second interval.
16+
17+
[fix] stream.py bug fix with verbose mode disabled.
18+
19+
120
----------------
221
Date: 2017-03-24
322
Author: Sonny Jeon

doc/script/stream.py

+53-14
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
write mode via simple streaming method. MIT-licensed.
1919
2020
TODO:
21-
- Add runtime command capabilities
21+
- Add realtime control commands during streaming.
2222
2323
---------------------
2424
The MIT License (MIT)
@@ -69,6 +69,8 @@
6969
help='suppress output text')
7070
parser.add_argument('-s','--settings',action='store_true', default=False,
7171
help='settings write mode')
72+
parser.add_argument('-c','--check',action='store_true', default=False,
73+
help='stream in check mode')
7274
args = parser.parse_args()
7375

7476
# Periodic timer to query for status reports
@@ -89,14 +91,30 @@ def periodic_timer() :
8991
if args.quiet : verbose = False
9092
settings_mode = False
9193
if args.settings : settings_mode = True
94+
check_mode = False
95+
if args.check : check_mode = True
9296

9397
# Wake up grbl
94-
print "Initializing grbl..."
98+
print "Initializing Grbl..."
9599
s.write("\r\n\r\n")
96100

97101
# Wait for grbl to initialize and flush startup text in serial input
98102
time.sleep(2)
99103
s.flushInput()
104+
105+
if check_mode :
106+
print "Enabling Grbl Check-Mode: SND: [$C]",
107+
s.write("$C\n")
108+
while 1:
109+
grbl_out = s.readline().strip() # Wait for grbl response with carriage return
110+
if grbl_out.find('error') >= 0 :
111+
print "REC:",grbl_out
112+
print " Failed to set Grbl check-mode. Aborting..."
113+
quit()
114+
elif grbl_out.find('ok') >= 0 :
115+
if verbose: print 'REC:',grbl_out
116+
break
117+
100118
start_time = time.time();
101119

102120
# Start status report periodic timer
@@ -107,6 +125,7 @@ def periodic_timer() :
107125

108126
# Stream g-code to grbl
109127
l_count = 0
128+
error_count = 0
110129
if settings_mode:
111130
# Send settings file via simple call-response streaming method. Settings must be streamed
112131
# in this manner since the EEPROM accessing cycles shut-off the serial interrupt.
@@ -115,15 +134,19 @@ def periodic_timer() :
115134
l_count += 1 # Iterate line counter
116135
# l_block = re.sub('\s|\(.*?\)','',line).upper() # Strip comments/spaces/new line and capitalize
117136
l_block = line.strip() # Strip all EOL characters for consistency
118-
if verbose: print 'SND: ' + str(l_count) + ':' + l_block,
137+
if verbose: print "SND>"+str(l_count)+": \"" + l_block + "\""
119138
s.write(l_block + '\n') # Send g-code block to grbl
120139
while 1:
121140
grbl_out = s.readline().strip() # Wait for grbl response with carriage return
122-
if grbl_out.find('ok') < 0 and grbl_out.find('error') < 0 :
123-
print "\n Debug: ",grbl_out,
124-
else :
125-
if verbose: print 'REC:',grbl_out
141+
if grbl_out.find('ok') >= 0 :
142+
if verbose: print " REC<"+str(l_count)+": \""+grbl_out+"\""
143+
break
144+
elif grbl_out.find('error') >= 0 :
145+
if verbose: print " REC<"+str(l_count)+": \""+grbl_out+"\""
146+
error_count += 1
126147
break
148+
else:
149+
print " MSG: \""+grbl_out+"\""
127150
else:
128151
# Send g-code program via a more agressive streaming protocol that forces characters into
129152
# Grbl's serial read buffer to ensure Grbl has immediate access to the next g-code command
@@ -141,22 +164,38 @@ def periodic_timer() :
141164
while sum(c_line) >= RX_BUFFER_SIZE-1 | s.inWaiting() :
142165
out_temp = s.readline().strip() # Wait for grbl response
143166
if out_temp.find('ok') < 0 and out_temp.find('error') < 0 :
144-
print " Debug: ",out_temp # Debug response
167+
print " MSG: \""+out_temp+"\"" # Debug response
145168
else :
146-
grbl_out += out_temp;
169+
if out_temp.find('error') >= 0 : error_count += 1
147170
g_count += 1 # Iterate g-code counter
148-
grbl_out += str(g_count); # Add line finished indicator
171+
if verbose: print " REC<"+str(g_count)+": \""+out_temp+"\""
149172
del c_line[0] # Delete the block character count corresponding to the last 'ok'
150173
s.write(l_block + '\n') # Send g-code block to grbl
151-
if verbose: print "BUF: " + str(sum(c_line)) + " SND: " + str(l_count) + " [" + l_block + "] REC: " + grbl_out
174+
if verbose: print "SND>"+str(l_count)+": \"" + l_block + "\""
175+
# Wait until all responses have been received.
176+
while l_count > g_count :
177+
out_temp = s.readline().strip() # Wait for grbl response
178+
if out_temp.find('ok') < 0 and out_temp.find('error') < 0 :
179+
print " MSG: \""+out_temp+"\"" # Debug response
180+
else :
181+
if out_temp.find('error') >= 0 : error_count += 1
182+
g_count += 1 # Iterate g-code counter
183+
del c_line[0] # Delete the block character count corresponding to the last 'ok'
184+
if verbose: print " REC<"+str(g_count)+": \""+out_temp + "\""
152185

153186
# Wait for user input after streaming is completed
154-
print "G-code streaming finished!"
187+
print "\nG-code streaming finished!"
155188
end_time = time.time();
156189
is_run = False;
157190
print " Time elapsed: ",end_time-start_time,"\n"
158-
print "WARNING: Wait until grbl completes buffered g-code blocks before exiting."
159-
raw_input(" Press <Enter> to exit and disable grbl.")
191+
if check_mode :
192+
if error_count > 0 :
193+
print "CHECK FAILED:",error_count,"errors found! See output for details.\n"
194+
else :
195+
print "CHECK PASSED: No errors found in g-code program.\n"
196+
else :
197+
print "WARNING: Wait until Grbl completes buffered g-code blocks before exiting."
198+
raw_input(" Press <Enter> to exit and disable Grbl.")
160199

161200
# Close file and serial port
162201
f.close()

grbl/grbl.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323

2424
// Grbl versioning system
2525
#define GRBL_VERSION "1.1f"
26-
#define GRBL_VERSION_BUILD "20170531"
26+
#define GRBL_VERSION_BUILD "20170717"
2727

2828
// Define standard libraries used by Grbl.
2929
#include <avr/io.h>

grbl/main.c

+3
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@ volatile uint8_t sys_rt_exec_state; // Global realtime executor bitflag variab
3131
volatile uint8_t sys_rt_exec_alarm; // Global realtime executor bitflag variable for setting various alarms.
3232
volatile uint8_t sys_rt_exec_motion_override; // Global realtime executor bitflag variable for motion-based overrides.
3333
volatile uint8_t sys_rt_exec_accessory_override; // Global realtime executor bitflag variable for spindle/coolant overrides.
34+
#ifdef DEBUG
35+
volatile uint8_t sys_rt_exec_debug;
36+
#endif
3437

3538

3639
int main(void)

0 commit comments

Comments
 (0)