Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
P
Printrun
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
machinery
Printrun
Commits
bd09e6f4
Commit
bd09e6f4
authored
May 18, 2013
by
Guillaume Seguin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Cleanup gcoder.py a little bit
parent
6826dad6
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
19 additions
and
19 deletions
+19
-19
gcoder.py
printrun/gcoder.py
+19
-19
No files found.
printrun/gcoder.py
View file @
bd09e6f4
...
@@ -21,6 +21,7 @@ import datetime
...
@@ -21,6 +21,7 @@ import datetime
gcode_parsed_args
=
[
"x"
,
"y"
,
"e"
,
"f"
,
"z"
,
"p"
,
"i"
,
"j"
]
gcode_parsed_args
=
[
"x"
,
"y"
,
"e"
,
"f"
,
"z"
,
"p"
,
"i"
,
"j"
]
gcode_exp
=
re
.
compile
(
"
\
([^
\
(
\
)]*
\
)|[/
\
*].*
\n
|
\n
|[a-z][-+]?[0-9]*
\
.?[0-9]*"
)
gcode_exp
=
re
.
compile
(
"
\
([^
\
(
\
)]*
\
)|[/
\
*].*
\n
|
\n
|[a-z][-+]?[0-9]*
\
.?[0-9]*"
)
move_gcodes
=
[
"G0"
,
"G1"
,
"G2"
,
"G3"
]
class
Line
(
object
):
class
Line
(
object
):
...
@@ -49,7 +50,7 @@ class Line(object):
...
@@ -49,7 +50,7 @@ class Line(object):
self
.
raw
=
self
.
raw
.
split
(
";"
)[
0
]
.
rstrip
()
self
.
raw
=
self
.
raw
.
split
(
";"
)[
0
]
.
rstrip
()
self
.
split_raw
=
gcode_exp
.
findall
(
self
.
raw
)
self
.
split_raw
=
gcode_exp
.
findall
(
self
.
raw
)
self
.
command
=
self
.
split_raw
[
0
]
.
upper
()
if
not
self
.
split_raw
[
0
]
.
startswith
(
"n"
)
else
self
.
split_raw
[
1
]
self
.
command
=
self
.
split_raw
[
0
]
.
upper
()
if
not
self
.
split_raw
[
0
]
.
startswith
(
"n"
)
else
self
.
split_raw
[
1
]
self
.
is_move
=
self
.
command
in
[
"G0"
,
"G1"
]
self
.
is_move
=
self
.
command
in
move_gcodes
def
parse_coordinates
(
self
,
imperial
):
def
parse_coordinates
(
self
,
imperial
):
# Not a G-line, we don't want to parse its arguments
# Not a G-line, we don't want to parse its arguments
...
@@ -92,11 +93,6 @@ class Layer(object):
...
@@ -92,11 +93,6 @@ class Layer(object):
current_z
=
0
current_z
=
0
for
line
in
self
.
lines
:
for
line
in
self
.
lines
:
if
line
.
command
==
"G92"
:
current_x
=
line
.
x
or
current_x
current_y
=
line
.
y
or
current_y
current_z
=
line
.
z
or
current_z
if
line
.
is_move
:
if
line
.
is_move
:
x
=
line
.
x
x
=
line
.
x
y
=
line
.
y
y
=
line
.
y
...
@@ -122,6 +118,11 @@ class Layer(object):
...
@@ -122,6 +118,11 @@ class Layer(object):
current_y
=
y
or
current_y
current_y
=
y
or
current_y
current_z
=
z
or
current_z
current_z
=
z
or
current_z
elif
line
.
command
==
"G92"
:
current_x
=
line
.
x
or
current_x
current_y
=
line
.
y
or
current_y
current_z
=
line
.
z
or
current_z
return
(
xmin
,
xmax
),
(
ymin
,
ymax
),
(
zmin
,
zmax
)
return
(
xmin
,
xmax
),
(
ymin
,
ymax
),
(
zmin
,
zmax
)
class
GCode
(
object
):
class
GCode
(
object
):
...
@@ -142,7 +143,10 @@ class GCode(object):
...
@@ -142,7 +143,10 @@ class GCode(object):
relative
=
False
relative
=
False
relative_e
=
False
relative_e
=
False
for
line
in
self
.
lines
:
for
line
in
self
.
lines
:
if
line
.
command
==
"G20"
:
if
line
.
is_move
:
line
.
relative
=
relative
line
.
relative_e
=
relative_e
elif
line
.
command
==
"G20"
:
imperial
=
True
imperial
=
True
elif
line
.
command
==
"G21"
:
elif
line
.
command
==
"G21"
:
imperial
=
False
imperial
=
False
...
@@ -156,9 +160,7 @@ class GCode(object):
...
@@ -156,9 +160,7 @@ class GCode(object):
relative_e
=
False
relative_e
=
False
elif
line
.
command
==
"M83"
:
elif
line
.
command
==
"M83"
:
relative_e
=
True
relative_e
=
True
elif
line
.
is_move
:
if
line
.
command
[
0
]
==
"G"
:
line
.
relative
=
relative
line
.
relative_e
=
relative_e
line
.
parse_coordinates
(
imperial
)
line
.
parse_coordinates
(
imperial
)
# FIXME : looks like this needs to be tested with list Z on move
# FIXME : looks like this needs to be tested with list Z on move
...
@@ -243,15 +245,15 @@ class GCode(object):
...
@@ -243,15 +245,15 @@ class GCode(object):
for
line
in
self
.
lines
:
for
line
in
self
.
lines
:
if
line
.
e
==
None
:
if
line
.
e
==
None
:
continue
continue
if
line
.
command
==
"G92"
:
if
line
.
is_move
:
cur_e
=
line
.
e
elif
line
.
is_move
:
if
line
.
relative_e
:
if
line
.
relative_e
:
total_e
+=
line
.
e
total_e
+=
line
.
e
else
:
else
:
total_e
+=
line
.
e
-
cur_e
total_e
+=
line
.
e
-
cur_e
cur_e
=
line
.
e
cur_e
=
line
.
e
max_e
=
max
(
max_e
,
total_e
)
max_e
=
max
(
max_e
,
total_e
)
elif
line
.
command
==
"G92"
:
cur_e
=
line
.
e
return
max_e
return
max_e
...
@@ -274,7 +276,7 @@ class GCode(object):
...
@@ -274,7 +276,7 @@ class GCode(object):
for
z
in
zs
:
for
z
in
zs
:
layer
=
self
.
layers
[
z
]
layer
=
self
.
layers
[
z
]
for
line
in
layer
.
lines
:
for
line
in
layer
.
lines
:
if
line
.
command
not
in
[
"G
4"
,
"G1
"
]:
if
line
.
command
not
in
[
"G
1"
,
"G0"
,
"G4
"
]:
continue
continue
if
line
.
command
==
"G4"
:
if
line
.
command
==
"G4"
:
moveduration
=
line
.
p
moveduration
=
line
.
p
...
@@ -282,7 +284,7 @@ class GCode(object):
...
@@ -282,7 +284,7 @@ class GCode(object):
continue
continue
else
:
else
:
moveduration
/=
1000.0
moveduration
/=
1000.0
el
if
line
.
command
==
"G1"
:
el
se
:
x
=
line
.
x
if
line
.
x
!=
None
else
lastx
x
=
line
.
x
if
line
.
x
!=
None
else
lastx
y
=
line
.
y
if
line
.
y
!=
None
else
lasty
y
=
line
.
y
if
line
.
y
!=
None
else
lasty
e
=
line
.
e
if
line
.
e
!=
None
else
laste
e
=
line
.
e
if
line
.
e
!=
None
else
laste
...
@@ -322,8 +324,6 @@ def main():
...
@@ -322,8 +324,6 @@ def main():
print
"usage:
%
s filename.gcode"
%
sys
.
argv
[
0
]
print
"usage:
%
s filename.gcode"
%
sys
.
argv
[
0
]
return
return
# d = [i.replace("\n","") for i in open(sys.argv[1])]
# gcode = GCode(d)
gcode
=
GCode
(
open
(
sys
.
argv
[
1
]))
gcode
=
GCode
(
open
(
sys
.
argv
[
1
]))
gcode
.
measure
()
gcode
.
measure
()
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment