mirror of
https://github.com/sinseman44/PyCNC.git
synced 2026-05-06 21:28:12 +00:00
fix issue with g0 velocity and g92 command
This commit is contained in:
+15
-8
@@ -313,7 +313,8 @@ class GMachine(object):
|
|||||||
c = 'G1'
|
c = 'G1'
|
||||||
# read parameters
|
# read parameters
|
||||||
if self._absoluteCoordinates:
|
if self._absoluteCoordinates:
|
||||||
coord = gcode.coordinates(self._position, self._convertCoordinates)
|
coord = gcode.coordinates(self._position - self._local,
|
||||||
|
self._convertCoordinates)
|
||||||
coord = coord + self._local
|
coord = coord + self._local
|
||||||
delta = coord - self._position
|
delta = coord - self._position
|
||||||
else:
|
else:
|
||||||
@@ -336,19 +337,19 @@ class GMachine(object):
|
|||||||
if l > 0:
|
if l > 0:
|
||||||
proportion = abs(delta) / l
|
proportion = abs(delta) / l
|
||||||
if proportion.x > 0:
|
if proportion.x > 0:
|
||||||
v = MAX_VELOCITY_MM_PER_MIN_X / proportion.x
|
v = int(MAX_VELOCITY_MM_PER_MIN_X / proportion.x)
|
||||||
if v < vl:
|
if v < vl:
|
||||||
vl = v
|
vl = v
|
||||||
if proportion.y > 0:
|
if proportion.y > 0:
|
||||||
v = MAX_VELOCITY_MM_PER_MIN_Y / proportion.y
|
v = int(MAX_VELOCITY_MM_PER_MIN_Y / proportion.y)
|
||||||
if v < vl:
|
if v < vl:
|
||||||
vl = v
|
vl = v
|
||||||
if proportion.z > 0:
|
if proportion.z > 0:
|
||||||
v = MAX_VELOCITY_MM_PER_MIN_Z / proportion.z
|
v = int(MAX_VELOCITY_MM_PER_MIN_Z / proportion.z)
|
||||||
if v < vl:
|
if v < vl:
|
||||||
vl = v
|
vl = v
|
||||||
if proportion.e > 0:
|
if proportion.e > 0:
|
||||||
v = MAX_VELOCITY_MM_PER_MIN_E / proportion.e
|
v = int(MAX_VELOCITY_MM_PER_MIN_E / proportion.e)
|
||||||
if v < vl:
|
if v < vl:
|
||||||
vl = v
|
vl = v
|
||||||
self._move_linear(delta, vl)
|
self._move_linear(delta, vl)
|
||||||
@@ -391,9 +392,15 @@ class GMachine(object):
|
|||||||
elif c == 'G91': # switch to relative coords
|
elif c == 'G91': # switch to relative coords
|
||||||
self._absoluteCoordinates = False
|
self._absoluteCoordinates = False
|
||||||
elif c == 'G92': # switch to local coords
|
elif c == 'G92': # switch to local coords
|
||||||
self._local = self._position - \
|
if gcode.has_coordinates():
|
||||||
gcode.coordinates(Coordinates(0.0, 0.0, 0.0, 0.0),
|
self._local = self._position - gcode.coordinates(
|
||||||
self._convertCoordinates)
|
Coordinates(self._position.x - self._local.x,
|
||||||
|
self._position.y - self._local.y,
|
||||||
|
self._position.z - self._local.z,
|
||||||
|
self._position.e - self._local.e),
|
||||||
|
self._convertCoordinates)
|
||||||
|
else:
|
||||||
|
self._local = self._position
|
||||||
elif c == 'M3': # spindle on
|
elif c == 'M3': # spindle on
|
||||||
spindle_rpm = gcode.get('S', self._spindle_rpm)
|
spindle_rpm = gcode.get('S', self._spindle_rpm)
|
||||||
if spindle_rpm < 0 or spindle_rpm > SPINDLE_MAX_RPM:
|
if spindle_rpm < 0 or spindle_rpm > SPINDLE_MAX_RPM:
|
||||||
|
|||||||
+8
-4
@@ -165,10 +165,14 @@ def move(generator):
|
|||||||
assert f.count(f[0]) == len(f), "fast forwarded pulse detected"
|
assert f.count(f[0]) == len(f), "fast forwarded pulse detected"
|
||||||
pt = time.time()
|
pt = time.time()
|
||||||
assert direction_found, "direction not found"
|
assert direction_found, "direction not found"
|
||||||
assert ix / STEPPER_PULSES_PER_MM_X == delta.x, "x wrong number of pulses"
|
assert round(ix / STEPPER_PULSES_PER_MM_X, 10) == delta.x,\
|
||||||
assert iy / STEPPER_PULSES_PER_MM_Y == delta.y, "y wrong number of pulses"
|
"x wrong number of pulses"
|
||||||
assert iz / STEPPER_PULSES_PER_MM_Z == delta.z, "z wrong number of pulses"
|
assert round(iy / STEPPER_PULSES_PER_MM_Y, 10) == delta.y,\
|
||||||
assert ie / STEPPER_PULSES_PER_MM_E == delta.e, "e wrong number of pulses"
|
"y wrong number of pulses"
|
||||||
|
assert round(iz / STEPPER_PULSES_PER_MM_Z, 10) == delta.z, \
|
||||||
|
"z wrong number of pulses"
|
||||||
|
assert round(ie / STEPPER_PULSES_PER_MM_E, 10) == delta.e, \
|
||||||
|
"e wrong number of pulses"
|
||||||
assert max(mx, my, mz, me) <= generator.total_time_s(), \
|
assert max(mx, my, mz, me) <= generator.total_time_s(), \
|
||||||
"interpolation time or pulses wrong"
|
"interpolation time or pulses wrong"
|
||||||
logging.debug("Moved {}, {}, {}, {} iterations".format(ix, iy, iz, ie))
|
logging.debug("Moved {}, {}, {}, {} iterations".format(ix, iy, iz, ie))
|
||||||
|
|||||||
+12
-2
@@ -56,6 +56,8 @@ class TestGMachine(unittest.TestCase):
|
|||||||
# Test gcode commands.
|
# Test gcode commands.
|
||||||
def test_g0_g1(self):
|
def test_g0_g1(self):
|
||||||
m = GMachine()
|
m = GMachine()
|
||||||
|
m.do_command(GCode.parse_line("G0X10Y10Z11"))
|
||||||
|
self.assertEqual(m.position(), Coordinates(10, 10, 11, 0))
|
||||||
m.do_command(GCode.parse_line("G0X3Y2Z1E-2"))
|
m.do_command(GCode.parse_line("G0X3Y2Z1E-2"))
|
||||||
self.assertEqual(m.position(), Coordinates(3, 2, 1, -2))
|
self.assertEqual(m.position(), Coordinates(3, 2, 1, -2))
|
||||||
m.do_command(GCode.parse_line("G1X1Y2Z3E4"))
|
m.do_command(GCode.parse_line("G1X1Y2Z3E4"))
|
||||||
@@ -185,7 +187,7 @@ class TestGMachine(unittest.TestCase):
|
|||||||
m.do_command(GCode.parse_line("X1Y1Z1E1"))
|
m.do_command(GCode.parse_line("X1Y1Z1E1"))
|
||||||
self.assertEqual(m.position(), Coordinates(1, 1, 1, 1))
|
self.assertEqual(m.position(), Coordinates(1, 1, 1, 1))
|
||||||
|
|
||||||
def test_g90_g92(self):
|
def test_g53_g92(self):
|
||||||
m = GMachine()
|
m = GMachine()
|
||||||
m.do_command(GCode.parse_line("G92X100Y100Z100E100"))
|
m.do_command(GCode.parse_line("G92X100Y100Z100E100"))
|
||||||
m.do_command(GCode.parse_line("X101Y102Z103E104"))
|
m.do_command(GCode.parse_line("X101Y102Z103E104"))
|
||||||
@@ -196,9 +198,17 @@ class TestGMachine(unittest.TestCase):
|
|||||||
m.do_command(GCode.parse_line("G92X3Y4Z5E6"))
|
m.do_command(GCode.parse_line("G92X3Y4Z5E6"))
|
||||||
m.do_command(GCode.parse_line("X0Y0Z0E0"))
|
m.do_command(GCode.parse_line("X0Y0Z0E0"))
|
||||||
self.assertEqual(m.position(), Coordinates(0, 0, 0, 0))
|
self.assertEqual(m.position(), Coordinates(0, 0, 0, 0))
|
||||||
m.do_command(GCode.parse_line("G90"))
|
m.do_command(GCode.parse_line("X1Y2Z3E4"))
|
||||||
|
self.assertEqual(m.position(), Coordinates(1, 2, 3, 4))
|
||||||
|
m.do_command(GCode.parse_line("G53"))
|
||||||
m.do_command(GCode.parse_line("X6Y7Z8E9"))
|
m.do_command(GCode.parse_line("X6Y7Z8E9"))
|
||||||
self.assertEqual(m.position(), Coordinates(6, 7, 8, 9))
|
self.assertEqual(m.position(), Coordinates(6, 7, 8, 9))
|
||||||
|
m.do_command(GCode.parse_line("G92E0"))
|
||||||
|
m.do_command(GCode.parse_line("X6Y7Z8E1"))
|
||||||
|
self.assertEqual(m.position(), Coordinates(6, 7, 8, 10))
|
||||||
|
m.do_command(GCode.parse_line("G92"))
|
||||||
|
m.do_command(GCode.parse_line("X1Y1Z1E1"))
|
||||||
|
self.assertEqual(m.position(), Coordinates(7, 8, 9, 11))
|
||||||
|
|
||||||
def test_g53_g91_g92(self):
|
def test_g53_g91_g92(self):
|
||||||
m = GMachine()
|
m = GMachine()
|
||||||
|
|||||||
Reference in New Issue
Block a user