Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
P
pyMKcam
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
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
machinery
pyMKcam
Commits
76a6b0a9
Commit
76a6b0a9
authored
Feb 12, 2017
by
Franco (nextime) Lanza
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
MK4duo Gcode support
parent
f299ea66
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
37 additions
and
32 deletions
+37
-32
MK4duo.py
pymkcam/Exporters/GCode/MK4duo.py
+37
-32
No files found.
pymkcam/Exporters/GCode/MK4duo.py
View file @
76a6b0a9
...
@@ -25,11 +25,17 @@ from pymkcam.Toolpath import CORNER_STYLE_EXACT_PATH, CORNER_STYLE_EXACT_STOP, \
...
@@ -25,11 +25,17 @@ from pymkcam.Toolpath import CORNER_STYLE_EXACT_PATH, CORNER_STYLE_EXACT_STOP, \
CORNER_STYLE_OPTIMIZE_SPEED
,
CORNER_STYLE_OPTIMIZE_TOLERANCE
CORNER_STYLE_OPTIMIZE_SPEED
,
CORNER_STYLE_OPTIMIZE_TOLERANCE
DEFAULT_HEADER
=
((
"G40"
,
"disable tool radius compensation"
),
DEFAULT_HEADER
=
(
(
"G49"
,
"disable tool length compensation"
),
(
"M82"
,
"select absolute coordinate system"
),
(
"G80"
,
"cancel modal motion"
),
)
(
"G54"
,
"select coordinate system 1"
),
(
"G90"
,
"disable incremental moves"
))
DEFAULT_FOOTER
=
(
(
"G0 Z5.00000 F200"
,
"safe Z position"
),
(
"M5"
,
"stop spindle"
),
(
"M18"
,
"unlock all steppers"
),
(
"M2"
,
"program ends"
)
)
DEFAULT_DIGITS
=
6
DEFAULT_DIGITS
=
6
...
@@ -42,28 +48,30 @@ def _render_number(number):
...
@@ -42,28 +48,30 @@ def _render_number(number):
class
MK4duo
(
pymkcam
.
Exporters
.
GCode
.
BaseGenerator
):
class
MK4duo
(
pymkcam
.
Exporters
.
GCode
.
BaseGenerator
):
sspeed
=
"10000"
feed
=
"300"
fast
=
"3000"
def
add_header
(
self
):
def
add_header
(
self
):
for
command
,
comment
in
DEFAULT_HEADER
:
for
command
,
comment
in
DEFAULT_HEADER
:
self
.
add_command
(
command
,
comment
=
comment
)
self
.
add_command
(
command
,
comment
=
comment
)
# TODO: use a "unit" filter
if
True
:
if
True
:
self
.
add_command
(
"G21"
,
"metric"
)
self
.
add_command
(
"G21"
,
"metric"
)
else
:
else
:
self
.
add_command
(
"G20"
,
"imperial"
)
self
.
add_command
(
"G20"
,
"imperial"
)
def
add_footer
(
self
):
def
add_footer
(
self
):
self
.
add_command
(
"M2"
,
"end program"
)
for
command
,
comment
in
DEFAULT_FOOTER
:
self
.
add_command
(
command
,
comment
=
comment
)
def
add_comment
(
self
,
comment
):
def
add_comment
(
self
,
comment
):
self
.
add_command
(
";
%
s"
%
comment
)
self
.
add_command
(
";
%
s"
%
comment
)
def
add_command
(
self
,
command
,
comment
=
None
):
def
add_command
(
self
,
command
,
comment
=
None
):
self
.
destination
.
write
(
command
)
if
comment
:
if
comment
:
self
.
destination
.
write
(
"
\t
"
)
self
.
add_comment
(
comment
)
self
.
add_comment
(
comment
)
else
:
self
.
destination
.
write
(
command
)
self
.
destination
.
write
(
os
.
linesep
)
self
.
destination
.
write
(
os
.
linesep
)
def
add_move
(
self
,
coordinates
,
is_rapid
=
False
):
def
add_move
(
self
,
coordinates
,
is_rapid
=
False
):
...
@@ -72,52 +80,49 @@ class MK4duo(pymkcam.Exporters.GCode.BaseGenerator):
...
@@ -72,52 +80,49 @@ class MK4duo(pymkcam.Exporters.GCode.BaseGenerator):
# True: the last move was G0
# True: the last move was G0
# False: the last move was G1
# False: the last move was G1
# None: some non-move happened before
# None: some non-move happened before
if
self
.
_get_cache
(
"rapid_move"
,
None
)
!=
is_rapid
:
components
.
append
(
"G0"
if
is_rapid
else
"G1"
)
components
.
append
(
"G0"
if
is_rapid
else
"G1"
)
else
:
# improve gcode style
components
.
append
(
" "
)
axes
=
[
axis
for
axis
in
"XYZABCUVW"
]
axes
=
[
axis
for
axis
in
"XYZABCUVW"
]
previous
=
self
.
_get_cache
(
"position"
,
[
None
]
*
len
(
coordinates
))
previous
=
self
.
_get_cache
(
"position"
,
[
None
]
*
len
(
coordinates
))
for
(
axis
,
value
,
last
)
in
zip
(
axes
,
coordinates
,
previous
):
for
(
axis
,
value
,
last
)
in
zip
(
axes
,
coordinates
,
previous
):
if
(
last
is
None
)
or
(
last
!=
value
):
if
(
last
is
None
)
or
(
last
!=
value
):
components
.
append
(
"
%
s
%.6
f"
%
(
axis
,
value
))
components
.
append
(
"
%
s
%.6
f"
%
(
axis
,
value
))
if
len
(
components
)
>
1
:
if
self
.
_get_cache
(
"rapid_move"
,
None
)
!=
is_rapid
:
components
.
append
(
"F
%
s"
%
(
self
.
fast
if
is_rapid
else
self
.
feed
))
command
=
" "
.
join
(
components
)
command
=
" "
.
join
(
components
)
if
command
.
strip
():
if
command
.
strip
():
self
.
add_command
(
command
)
self
.
add_command
(
command
)
def
command_feedrate
(
self
,
feedrate
):
def
command_feedrate
(
self
,
feedrate
):
self
.
add_command
(
"F
%
s"
%
_render_number
(
feedrate
),
"set feedrate"
)
self
.
feed
=
_render_number
(
feedrate
)
def
command_select_tool
(
self
,
tool_id
):
def
command_select_tool
(
self
,
tool_id
):
self
.
add_command
(
"T
%
d
M6
"
%
tool_id
,
"select tool"
)
self
.
add_command
(
"T
%
d"
%
tool_id
,
"select tool"
)
def
command_spindle_speed
(
self
,
speed
):
def
command_spindle_speed
(
self
,
speed
):
self
.
add_command
(
"S
%
s"
%
_render_number
(
speed
),
"set spindle speed"
)
self
.
sspeed
=
_render_number
(
speed
)
def
command_spindle_enabled
(
self
,
state
):
def
command_spindle_enabled
(
self
,
state
):
if
state
:
if
state
:
self
.
add_command
(
"M3
"
,
"start spindle"
)
self
.
add_command
(
"M3
S
%
s"
%
self
.
sspeed
,
"start spindle"
)
else
:
else
:
self
.
add_command
(
"M5"
,
"stop spindle"
)
self
.
add_command
(
"M5"
,
"stop spindle"
)
def
command_delay
(
self
,
seconds
):
def
command_delay
(
self
,
seconds
):
self
.
add_command
(
"G04
P
%
d"
%
seconds
,
"wait for
%
d seconds"
%
seconds
)
self
.
add_command
(
"G04
S
%
d"
%
seconds
,
"wait for
%
d seconds"
%
seconds
)
def
command_corner_style
(
self
,
def
command_corner_style
(
self
,
(
path_mode
,
motion_tolerance
,
naive_tolerance
)):
(
path_mode
,
motion_tolerance
,
naive_tolerance
)):
if
path_mode
==
CORNER_STYLE_EXACT_PATH
:
if
path_mode
==
CORNER_STYLE_EXACT_PATH
:
self
.
add_comm
and
(
"G61"
,
"exact path mode
"
)
self
.
add_comm
ent
(
"G61 exact path mode was requested but not implemented
"
)
elif
path_mode
==
CORNER_STYLE_EXACT_STOP
:
elif
path_mode
==
CORNER_STYLE_EXACT_STOP
:
self
.
add_comm
and
(
"G61.1"
,
"exact stop mode
"
)
self
.
add_comm
ent
(
"G61.1 exact stop mode was requested but not implemented
"
)
elif
path_mode
==
CORNER_STYLE_OPTIMIZE_SPEED
:
elif
path_mode
==
CORNER_STYLE_OPTIMIZE_SPEED
:
self
.
add_comm
and
(
"G64"
,
"continuous mode with maximum spe
ed"
)
self
.
add_comm
ent
(
"G64 continuous mode with maximum speed was requested but not implement
ed"
)
else
:
else
:
if
not
naive_tolerance
:
if
not
naive_tolerance
:
self
.
add_command
(
"G64 P
%
f"
%
motion_tolerance
,
self
.
add_comment
(
"G64 P
%
f continuous mode with tolerance was requested but not implemented"
%
motion_tolerance
)
"continuous mode with tolerance"
)
else
:
else
:
self
.
add_command
(
"G64 P
%
f Q
%
f"
%
\
self
.
add_command
(
"G64 P
%
f Q
%
f continuous mode with tolerance and cleanup was requested but not implemented"
%
\
(
motion_tolerance
,
naive_tolerance
),
(
motion_tolerance
,
naive_tolerance
))
"continuous mode with tolerance and cleanup"
)
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