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
4165b31c
Commit
4165b31c
authored
May 20, 2013
by
Guillaume Seguin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Start merging gcoder and GCodeAnalyzer by reusing gcoder parsing
parent
ce51f36e
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
38 additions
and
49 deletions
+38
-49
GCodeAnalyzer.py
printrun/GCodeAnalyzer.py
+38
-49
No files found.
printrun/GCodeAnalyzer.py
View file @
4165b31c
...
@@ -31,6 +31,7 @@
...
@@ -31,6 +31,7 @@
# limitations under the License.
# limitations under the License.
import
re
import
re
import
gcoder
class
GCodeAnalyzer
():
class
GCodeAnalyzer
():
def
__init__
(
self
):
def
__init__
(
self
):
...
@@ -65,66 +66,54 @@ class GCodeAnalyzer():
...
@@ -65,66 +66,54 @@ class GCodeAnalyzer():
self
.
hasHomeY
=
False
self
.
hasHomeY
=
False
self
.
hasHomeZ
=
False
self
.
hasHomeZ
=
False
# find a code in a gstring line
def
findCode
(
self
,
gcode
,
codeStr
):
pattern
=
re
.
compile
(
codeStr
+
"
\\
s*(-?[
\
d.]*)"
,
re
.
I
)
m
=
re
.
search
(
pattern
,
gcode
)
if
m
==
None
:
return
None
else
:
return
m
.
group
(
1
)
def
Analyze
(
self
,
gcode
):
def
Analyze
(
self
,
gcode
):
gcode
=
gcode
[:
gcode
.
find
(
";"
)]
.
lstrip
()
# remove comments
gcode
=
gcode
[:
gcode
.
find
(
";"
)]
.
lstrip
()
# remove comments
if
gcode
.
startswith
(
"@"
):
return
# code is a host command
gline
=
gcoder
.
Line
(
gcode
)
code_g
=
self
.
findCode
(
gcode
,
"G"
)
if
gline
.
command
.
startswith
(
";@"
):
return
# code is a host command
code_m
=
self
.
findCode
(
gcode
,
"M"
)
if
gline
.
command
.
startswith
(
"G"
):
# we have a g_code
code_g
=
int
(
gline
.
command
[
1
:])
if
code_g
!=
None
:
if
gline
.
command
.
startswith
(
"M"
)
:
code_g
=
int
(
code_g
)
code_m
=
int
(
gline
.
command
[
1
:]
)
#get movement codes
#get movement codes
if
code_g
==
0
or
code_g
==
1
or
code_g
==
2
or
code_g
==
3
:
if
gline
.
is_move
:
self
.
lastX
=
self
.
x
self
.
lastX
=
self
.
x
self
.
lastY
=
self
.
y
self
.
lastY
=
self
.
y
self
.
lastZ
=
self
.
z
self
.
lastZ
=
self
.
z
self
.
lastE
=
self
.
e
self
.
lastE
=
self
.
e
eChanged
=
False
;
eChanged
=
False
;
code_f
=
self
.
findCode
(
gcode
,
"F"
)
code_f
=
gline
.
f
if
code_f
!=
None
:
if
code_f
!=
None
:
self
.
f
=
float
(
code_f
)
self
.
f
=
code_f
code_x
=
self
.
findCode
(
gcode
,
"X"
)
code_x
=
gline
.
x
code_y
=
self
.
findCode
(
gcode
,
"Y"
)
code_y
=
gline
.
y
code_z
=
self
.
findCode
(
gcode
,
"Z"
)
code_z
=
gline
.
z
code_e
=
self
.
findCode
(
gcode
,
"E"
)
code_e
=
gline
.
e
if
self
.
relative
:
if
self
.
relative
:
if
code_x
!=
None
:
self
.
x
+=
float
(
code_x
)
if
code_x
!=
None
:
self
.
x
+=
code_x
if
code_y
!=
None
:
self
.
y
+=
float
(
code_y
)
if
code_y
!=
None
:
self
.
y
+=
code_y
if
code_z
!=
None
:
self
.
z
+=
float
(
code_z
)
if
code_z
!=
None
:
self
.
z
+=
code_z
if
code_e
!=
None
:
if
code_e
!=
None
:
e
=
float
(
code_e
)
if
code_e
!=
0
:
if
e
!=
0
:
eChanged
=
True
eChanged
=
True
self
.
e
+=
e
self
.
e
+=
code_
e
else
:
else
:
#absolute coordinates
#absolute coordinates
if
code_x
!=
None
:
self
.
x
=
self
.
xOffset
+
float
(
code_x
)
if
code_x
!=
None
:
self
.
x
=
self
.
xOffset
+
code_x
if
code_y
!=
None
:
self
.
y
=
self
.
yOffset
+
float
(
code_y
)
if
code_y
!=
None
:
self
.
y
=
self
.
yOffset
+
code_y
if
code_z
!=
None
:
self
.
z
=
self
.
zOffset
+
float
(
code_z
)
if
code_z
!=
None
:
self
.
z
=
self
.
zOffset
+
code_z
if
code_e
!=
None
:
if
code_e
!=
None
:
e
=
float
(
code_e
)
if
self
.
eRelative
:
if
self
.
eRelative
:
if
e
!=
0
:
if
code_
e
!=
0
:
eChanged
=
True
eChanged
=
True
self
.
e
+=
e
self
.
e
+=
code_
e
else
:
else
:
# e is absolute. Is it changed?
# e is absolute. Is it changed?
if
self
.
e
!=
self
.
eOffset
+
e
:
if
self
.
e
!=
self
.
eOffset
+
code_
e
:
eChanged
=
True
eChanged
=
True
self
.
e
=
self
.
eOffset
+
e
self
.
e
=
self
.
eOffset
+
code_
e
#limit checking
#limit checking
if
self
.
x
<
self
.
minX
:
self
.
x
=
self
.
minX
if
self
.
x
<
self
.
minX
:
self
.
x
=
self
.
minX
if
self
.
y
<
self
.
minY
:
self
.
y
=
self
.
minY
if
self
.
y
<
self
.
minY
:
self
.
y
=
self
.
minY
...
@@ -139,10 +128,10 @@ class GCodeAnalyzer():
...
@@ -139,10 +128,10 @@ class GCodeAnalyzer():
self
.
lastY
=
self
.
y
self
.
lastY
=
self
.
y
self
.
lastZ
=
self
.
z
self
.
lastZ
=
self
.
z
self
.
lastE
=
self
.
e
self
.
lastE
=
self
.
e
code_x
=
self
.
findCode
(
gcode
,
"X"
)
code_x
=
gline
.
x
code_y
=
self
.
findCode
(
gcode
,
"Y"
)
code_y
=
gline
.
y
code_z
=
self
.
findCode
(
gcode
,
"Z"
)
code_z
=
gline
.
z
code_e
=
self
.
findCode
(
gcode
,
"E"
)
code_e
=
gline
.
e
homeAll
=
False
homeAll
=
False
if
code_x
==
None
and
code_y
==
None
and
code_z
==
None
:
homeAll
=
True
if
code_x
==
None
and
code_y
==
None
and
code_z
==
None
:
homeAll
=
True
if
code_x
!=
None
or
homeAll
:
if
code_x
!=
None
or
homeAll
:
...
@@ -165,9 +154,9 @@ class GCodeAnalyzer():
...
@@ -165,9 +154,9 @@ class GCodeAnalyzer():
self
.
lastY
=
self
.
y
self
.
lastY
=
self
.
y
self
.
lastZ
=
self
.
z
self
.
lastZ
=
self
.
z
self
.
lastE
=
self
.
e
self
.
lastE
=
self
.
e
code_x
=
self
.
findCode
(
gcode
,
"X"
)
code_x
=
gline
.
x
code_y
=
self
.
findCode
(
gcode
,
"Y"
)
code_y
=
gline
.
y
code_z
=
self
.
findCode
(
gcode
,
"Z"
)
code_z
=
gline
.
z
homeAll
=
False
homeAll
=
False
if
code_x
==
None
and
code_y
==
None
and
code_z
==
None
:
homeAll
=
True
if
code_x
==
None
and
code_y
==
None
and
code_z
==
None
:
homeAll
=
True
if
code_x
!=
None
or
homeAll
:
if
code_x
!=
None
or
homeAll
:
...
@@ -185,10 +174,10 @@ class GCodeAnalyzer():
...
@@ -185,10 +174,10 @@ class GCodeAnalyzer():
elif
code_g
==
90
:
self
.
relative
=
False
elif
code_g
==
90
:
self
.
relative
=
False
elif
code_g
==
91
:
self
.
relative
=
True
elif
code_g
==
91
:
self
.
relative
=
True
elif
code_g
==
92
:
elif
code_g
==
92
:
code_x
=
self
.
findCode
(
gcode
,
"X"
)
code_x
=
gline
.
x
code_y
=
self
.
findCode
(
gcode
,
"Y"
)
code_y
=
gline
.
y
code_z
=
self
.
findCode
(
gcode
,
"Z"
)
code_z
=
gline
.
z
code_e
=
self
.
findCode
(
gcode
,
"E"
)
code_e
=
gline
.
e
if
code_x
!=
None
:
if
code_x
!=
None
:
self
.
xOffset
=
self
.
x
-
float
(
code_x
)
self
.
xOffset
=
self
.
x
-
float
(
code_x
)
self
.
x
=
self
.
xOffset
self
.
x
=
self
.
xOffset
...
@@ -210,4 +199,4 @@ class GCodeAnalyzer():
...
@@ -210,4 +199,4 @@ class GCodeAnalyzer():
def
print_status
(
self
):
def
print_status
(
self
):
attrs
=
vars
(
self
)
attrs
=
vars
(
self
)
print
'
\n
'
.
join
(
"
%
s:
%
s"
%
item
for
item
in
attrs
.
items
())
print
'
\n
'
.
join
(
"
%
s:
%
s"
%
item
for
item
in
attrs
.
items
())
\ No newline at end of file
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