fix feedrate update
Fix machinestate to handle drill moves and tests move feed and rapid declarations to PathGeom
This commit is contained in:
@@ -25,6 +25,7 @@ import PathScripts.PathLog as PathLog
|
||||
import PathMachineState
|
||||
import PathScripts.PathGeom as PathGeom
|
||||
import Part
|
||||
from PathScripts.PathGeom import CmdMoveRapid, CmdMoveAll
|
||||
|
||||
__title__ = "Feed Rate Helper Utility"
|
||||
__author__ = "sliptonic (Brad Collette)"
|
||||
@@ -43,6 +44,12 @@ else:
|
||||
|
||||
|
||||
def setFeedRate(commandlist, ToolController):
|
||||
"""Set the appropriate feed rate for a list of Path commands using the information from a Tool Controler
|
||||
|
||||
Every motion command in the list will have a feed rate parameter added or overwritten based
|
||||
on the information stored in the tool controller. If a motion is a plunge (vertical) motion, the
|
||||
VertFeed value will be used, otherwise the HorizFeed value will be used instead."""
|
||||
|
||||
def _isVertical(currentposition, command):
|
||||
x = (
|
||||
command.Parameters["X"]
|
||||
@@ -64,25 +71,22 @@ def setFeedRate(commandlist, ToolController):
|
||||
return True
|
||||
return PathGeom.isVertical(Part.makeLine(currentposition, endpoint))
|
||||
|
||||
feedcommands = ["G01", "G1", "G2", "G3", "G02", "G03", "G81", "G82", "G83"]
|
||||
rapidcommands = ["G0", "G00"]
|
||||
|
||||
machine = PathMachineState.MachineState()
|
||||
|
||||
for command in commandlist:
|
||||
if command.Name not in feedcommands + rapidcommands:
|
||||
if command.Name not in CmdMoveAll:
|
||||
continue
|
||||
|
||||
if _isVertical(FreeCAD.Vector(machine.X, machine.Y, machine.Z), command):
|
||||
if _isVertical(machine.getPosition(), command):
|
||||
rate = (
|
||||
ToolController.VertRapid.Value
|
||||
if command.Name in rapidcommands
|
||||
if command.Name in CmdMoveRapid
|
||||
else ToolController.VertFeed.Value
|
||||
)
|
||||
else:
|
||||
rate = (
|
||||
ToolController.HorizRapid.Value
|
||||
if command.Name in rapidcommands
|
||||
if command.Name in CmdMoveRapid
|
||||
else ToolController.HorizFeed.Value
|
||||
)
|
||||
|
||||
|
||||
@@ -29,6 +29,7 @@ __contributors__ = ""
|
||||
import PathScripts.PathLog as PathLog
|
||||
import FreeCAD
|
||||
from dataclasses import dataclass, field
|
||||
from PathScripts.PathGeom import CmdMoveRapid, CmdMoveAll, CmdMoveDrill
|
||||
|
||||
if True:
|
||||
PathLog.setLevel(PathLog.Level.DEBUG, PathLog.thisModule())
|
||||
@@ -92,6 +93,13 @@ class MachineState:
|
||||
self.WCS = command.Name
|
||||
return not oldstate == self.getState()
|
||||
|
||||
if command.Name in CmdMoveDrill:
|
||||
oldZ = self.Z
|
||||
for p in command.Parameters:
|
||||
self.__setattr__(p, command.Parameters[p])
|
||||
self.__setattr__("Z", oldZ)
|
||||
return not oldstate == self.getState()
|
||||
|
||||
for p in command.Parameters:
|
||||
self.__setattr__(p, command.Parameters[p])
|
||||
|
||||
@@ -116,3 +124,12 @@ class MachineState:
|
||||
state['T'] = self.T
|
||||
|
||||
return state
|
||||
|
||||
def getPosition(self):
|
||||
"""
|
||||
Returns a vector of the current machine position
|
||||
"""
|
||||
|
||||
# This is technical debt. The actual position may include a rotation
|
||||
# component as well. We should probably be returning a placement
|
||||
return FreeCAD.Vector(self.X, self.Y, self.Z)
|
||||
|
||||
@@ -87,8 +87,9 @@ CmdMoveRapid = ["G0", "G00"]
|
||||
CmdMoveStraight = ["G1", "G01"]
|
||||
CmdMoveCW = ["G2", "G02"]
|
||||
CmdMoveCCW = ["G3", "G03"]
|
||||
CmdMoveDrill = ["G81", "G82", "G83"]
|
||||
CmdMoveArc = CmdMoveCW + CmdMoveCCW
|
||||
CmdMove = CmdMoveStraight + CmdMoveArc
|
||||
CmdMove = CmdMoveStraight + CmdMoveArc + CmdMoveDrill
|
||||
CmdMoveAll = CmdMove + CmdMoveRapid
|
||||
|
||||
|
||||
|
||||
@@ -53,6 +53,7 @@ class TestPathHelpers(PathTestBase):
|
||||
tc.HorizFeed = 20
|
||||
|
||||
resultlist = PathFeedRate.setFeedRate(self.commandlist, tc)
|
||||
print(resultlist)
|
||||
|
||||
self.assertTrue(resultlist[0].Parameters["F"] == 5)
|
||||
self.assertTrue(resultlist[1].Parameters["F"] == 10)
|
||||
@@ -101,3 +102,10 @@ class TestPathHelpers(PathTestBase):
|
||||
result = machine.addCommand(Path.Command("G0 X30"))
|
||||
self.assertTrue(result)
|
||||
|
||||
# Test that Drilling moves are handled correctly
|
||||
result = machine.addCommand(Path.Command("G81 X50 Y50 Z0"))
|
||||
state = machine.getState()
|
||||
self.assertTrue(state['X'] == 50 )
|
||||
self.assertTrue(state['Y'] == 50 )
|
||||
self.assertTrue(state['Z'] == 5 )
|
||||
|
||||
|
||||
Reference in New Issue
Block a user