Manage tool change in single gcode exports

parent 76a6b0a9
...@@ -31,8 +31,8 @@ DEFAULT_HEADER = ( ...@@ -31,8 +31,8 @@ DEFAULT_HEADER = (
DEFAULT_FOOTER = ( DEFAULT_FOOTER = (
("G0 Z5.00000 F200", "safe Z position"), #("G0 Z5.00000 F200", "safe Z position"),
("M5", "stop spindle"), #("M5", "stop spindle"),
("M18", "unlock all steppers"), ("M18", "unlock all steppers"),
("M2", "program ends") ("M2", "program ends")
) )
...@@ -51,7 +51,7 @@ class MK4duo(pymkcam.Exporters.GCode.BaseGenerator): ...@@ -51,7 +51,7 @@ class MK4duo(pymkcam.Exporters.GCode.BaseGenerator):
sspeed = "10000" sspeed = "10000"
feed = "300" feed = "300"
fast = "3000" fast = "3000"
tool_id = 0
def add_header(self): def add_header(self):
for command, comment in DEFAULT_HEADER: for command, comment in DEFAULT_HEADER:
...@@ -97,7 +97,9 @@ class MK4duo(pymkcam.Exporters.GCode.BaseGenerator): ...@@ -97,7 +97,9 @@ class MK4duo(pymkcam.Exporters.GCode.BaseGenerator):
self.feed = _render_number(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" % tool_id, "select tool") if self.tool_id > 0 and self.tool_id != tool_id:
self.add_command("T%d" % tool_id, "select tool")
self.tool_id = tool_id
def command_spindle_speed(self, speed): def command_spindle_speed(self, speed):
self.sspeed = _render_number(speed) self.sspeed = _render_number(speed)
......
...@@ -79,6 +79,7 @@ class BaseGenerator(object): ...@@ -79,6 +79,7 @@ class BaseGenerator(object):
all_filters.extend(filters) all_filters.extend(filters)
filtered_moves = pymkcam.Toolpath.Filters.get_filtered_moves(moves, filtered_moves = pymkcam.Toolpath.Filters.get_filtered_moves(moves,
all_filters) all_filters)
_log.info(filtered_moves)
for move_type, args in filtered_moves: for move_type, args in filtered_moves:
if move_type in (MOVE_STRAIGHT, MOVE_STRAIGHT_RAPID): if move_type in (MOVE_STRAIGHT, MOVE_STRAIGHT_RAPID):
is_rapid = move_type == MOVE_STRAIGHT_RAPID is_rapid = move_type == MOVE_STRAIGHT_RAPID
......
...@@ -22,6 +22,7 @@ along with pyMKcam. If not, see <http://www.gnu.org/licenses/>. ...@@ -22,6 +22,7 @@ along with pyMKcam. If not, see <http://www.gnu.org/licenses/>.
import pymkcam.Plugins import pymkcam.Plugins
import pymkcam.Toolpath.Filters as Filters
class TaskTypeMilling(pymkcam.Plugins.PluginBase): class TaskTypeMilling(pymkcam.Plugins.PluginBase):
...@@ -62,6 +63,12 @@ class TaskTypeMilling(pymkcam.Plugins.PluginBase): ...@@ -62,6 +63,12 @@ class TaskTypeMilling(pymkcam.Plugins.PluginBase):
funcs[key] = self.core.get("get_parameter_sets")(key)\ funcs[key] = self.core.get("get_parameter_sets")(key)\
[environment[key][set_name]]["func"] [environment[key][set_name]]["func"]
tool, tool_filters = funcs["tool"](environment["tool"]["parameters"]) tool, tool_filters = funcs["tool"](environment["tool"]["parameters"])
selecttool = False
for tool_filter in tool_filters:
if isinstance(tool_filter, Filters.SelectTool):
selecttool = True
if not selecttool:
tool_filters.insert(0, Filters.SelectTool(task["parameters"]["tool"]["id"]))
low, high = environment["bounds"].get_absolute_limits( low, high = environment["bounds"].get_absolute_limits(
tool_radius=tool.radius, models=environment["collision_models"]) tool_radius=tool.radius, models=environment["collision_models"])
path_generator, motion_grid = funcs["process"](environment["process"], path_generator, motion_grid = funcs["process"](environment["process"],
......
...@@ -232,7 +232,7 @@ class SelectTool(BaseFilter): ...@@ -232,7 +232,7 @@ class SelectTool(BaseFilter):
index = 0 index = 0
# skip all non-moves # skip all non-moves
while (index < len(toolpath)) and \ while (index < len(toolpath)) and \
(not toolpath[0][0] in MOVES_LIST): ((not toolpath[index][0] in MOVES_LIST) or (not not toolpath[index][1][0] == "spindle_enabled")):
index += 1 index += 1
toolpath.insert(index, (MACHINE_SETTING, toolpath.insert(index, (MACHINE_SETTING,
("select_tool", self.settings["tool_id"]))) ("select_tool", self.settings["tool_id"])))
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment