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
f299ea66
Commit
f299ea66
authored
Feb 11, 2017
by
Franco (nextime) Lanza
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add new gcode exporter
parent
3e54cec8
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
125 additions
and
2 deletions
+125
-2
MK4duo.py
pymkcam/Exporters/GCode/MK4duo.py
+123
-0
ToolpathExport.py
pymkcam/Plugins/ToolpathExport.py
+2
-2
No files found.
pymkcam/Exporters/GCode/MK4duo.py
0 → 100644
View file @
f299ea66
# -*- coding: utf-8 -*-
"""
Copyright 2012 Lars Kruse <devel@sumpfralle.de>
This file is part of pyMKcam.
pyMKcam is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
pyMKcam is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with pyMKcam. If not, see <http://www.gnu.org/licenses/>.
"""
import
os
import
pymkcam.Exporters.GCode
from
pymkcam.Toolpath
import
CORNER_STYLE_EXACT_PATH
,
CORNER_STYLE_EXACT_STOP
,
\
CORNER_STYLE_OPTIMIZE_SPEED
,
CORNER_STYLE_OPTIMIZE_TOLERANCE
DEFAULT_HEADER
=
((
"G40"
,
"disable tool radius compensation"
),
(
"G49"
,
"disable tool length compensation"
),
(
"G80"
,
"cancel modal motion"
),
(
"G54"
,
"select coordinate system 1"
),
(
"G90"
,
"disable incremental moves"
))
DEFAULT_DIGITS
=
6
def
_render_number
(
number
):
if
int
(
number
)
==
number
:
return
"
%
d"
%
number
else
:
return
(
"
%%
.
%
df"
%
DEFAULT_DIGITS
)
%
number
class
MK4duo
(
pymkcam
.
Exporters
.
GCode
.
BaseGenerator
):
def
add_header
(
self
):
for
command
,
comment
in
DEFAULT_HEADER
:
self
.
add_command
(
command
,
comment
=
comment
)
# TODO: use a "unit" filter
if
True
:
self
.
add_command
(
"G21"
,
"metric"
)
else
:
self
.
add_command
(
"G20"
,
"imperial"
)
def
add_footer
(
self
):
self
.
add_command
(
"M2"
,
"end program"
)
def
add_comment
(
self
,
comment
):
self
.
add_command
(
";
%
s"
%
comment
)
def
add_command
(
self
,
command
,
comment
=
None
):
self
.
destination
.
write
(
command
)
if
comment
:
self
.
destination
.
write
(
"
\t
"
)
self
.
add_comment
(
comment
)
else
:
self
.
destination
.
write
(
os
.
linesep
)
def
add_move
(
self
,
coordinates
,
is_rapid
=
False
):
components
=
[]
# the cached value may be:
# True: the last move was G0
# False: the last move was G1
# None: some non-move happened before
if
self
.
_get_cache
(
"rapid_move"
,
None
)
!=
is_rapid
:
components
.
append
(
"G0"
if
is_rapid
else
"G1"
)
else
:
# improve gcode style
components
.
append
(
" "
)
axes
=
[
axis
for
axis
in
"XYZABCUVW"
]
previous
=
self
.
_get_cache
(
"position"
,
[
None
]
*
len
(
coordinates
))
for
(
axis
,
value
,
last
)
in
zip
(
axes
,
coordinates
,
previous
):
if
(
last
is
None
)
or
(
last
!=
value
):
components
.
append
(
"
%
s
%.6
f"
%
(
axis
,
value
))
command
=
" "
.
join
(
components
)
if
command
.
strip
():
self
.
add_command
(
command
)
def
command_feedrate
(
self
,
feedrate
):
self
.
add_command
(
"F
%
s"
%
_render_number
(
feedrate
),
"set feedrate"
)
def
command_select_tool
(
self
,
tool_id
):
self
.
add_command
(
"T
%
d M6"
%
tool_id
,
"select tool"
)
def
command_spindle_speed
(
self
,
speed
):
self
.
add_command
(
"S
%
s"
%
_render_number
(
speed
),
"set spindle speed"
)
def
command_spindle_enabled
(
self
,
state
):
if
state
:
self
.
add_command
(
"M3"
,
"start spindle"
)
else
:
self
.
add_command
(
"M5"
,
"stop spindle"
)
def
command_delay
(
self
,
seconds
):
self
.
add_command
(
"G04 P
%
d"
%
seconds
,
"wait for
%
d seconds"
%
seconds
)
def
command_corner_style
(
self
,
(
path_mode
,
motion_tolerance
,
naive_tolerance
)):
if
path_mode
==
CORNER_STYLE_EXACT_PATH
:
self
.
add_command
(
"G61"
,
"exact path mode"
)
elif
path_mode
==
CORNER_STYLE_EXACT_STOP
:
self
.
add_command
(
"G61.1"
,
"exact stop mode"
)
elif
path_mode
==
CORNER_STYLE_OPTIMIZE_SPEED
:
self
.
add_command
(
"G64"
,
"continuous mode with maximum speed"
)
else
:
if
not
naive_tolerance
:
self
.
add_command
(
"G64 P
%
f"
%
motion_tolerance
,
"continuous mode with tolerance"
)
else
:
self
.
add_command
(
"G64 P
%
f Q
%
f"
%
\
(
motion_tolerance
,
naive_tolerance
),
"continuous mode with tolerance and cleanup"
)
pymkcam/Plugins/ToolpathExport.py
View file @
f299ea66
...
@@ -24,7 +24,7 @@ import os
...
@@ -24,7 +24,7 @@ import os
import
pymkcam.Plugins
import
pymkcam.Plugins
from
pymkcam.Geometry.PointUtils
import
*
from
pymkcam.Geometry.PointUtils
import
*
import
pymkcam.Exporters.GCode.
LinuxCNC
import
pymkcam.Exporters.GCode.
MK4duo
FILTER_GCODE
=
((
"GCode files"
,
(
"*.ngc"
,
"*.nc"
,
"*.gc"
,
"*.gcode"
)),)
FILTER_GCODE
=
((
"GCode files"
,
(
"*.ngc"
,
"*.nc"
,
"*.gc"
,
"*.gcode"
)),)
...
@@ -121,7 +121,7 @@ class ToolpathExport(pymkcam.Plugins.PluginBase):
...
@@ -121,7 +121,7 @@ class ToolpathExport(pymkcam.Plugins.PluginBase):
machine_time
+=
toolpath
.
get_machine_time
()
machine_time
+=
toolpath
.
get_machine_time
()
all_info
=
meta_data
+
os
.
linesep
\
all_info
=
meta_data
+
os
.
linesep
\
+
"Estimated machine time:
%.0
f minutes"
%
machine_time
+
"Estimated machine time:
%.0
f minutes"
%
machine_time
generator
=
pymkcam
.
Exporters
.
GCode
.
LinuxCNC
.
LinuxCNC
(
destination
)
generator
=
pymkcam
.
Exporters
.
GCode
.
MK4duo
.
MK4duo
(
destination
)
generator
.
add_filters
(
settings_filters
)
generator
.
add_filters
(
settings_filters
)
generator
.
add_filters
(
common_filters
)
generator
.
add_filters
(
common_filters
)
"""
"""
...
...
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