mirror of
https://github.com/sinseman44/PyCNC.git
synced 2026-04-19 18:38:14 +00:00
refactoring
This commit is contained in:
@@ -1,11 +1,15 @@
|
||||
#!/bin/sh
|
||||
set -e
|
||||
PASS=raspberry
|
||||
ADDR=pi@192.168.0.208
|
||||
ADDRESS=pi@192.168.0.211
|
||||
if [ ! -z $1 ]; then
|
||||
ADDR=pi@$1
|
||||
if [[ $1 == *"@"* ]]; then
|
||||
ADDRESS=$1
|
||||
else
|
||||
ADDRESS=pi@$1
|
||||
fi
|
||||
fi
|
||||
find cnc/hal_raspberry -name "rpgpio*.py" -o -name "pycnc" | tar -cjf $(dirname "$0")/../pycnc.tar.bz2 -T -
|
||||
sshpass -p${PASS} scp $(dirname "$0")/../pycnc.tar.bz2 "${ADDR}:~/pycnc"
|
||||
sshpass -p${PASS} ssh -t ${ADDR} "(cd ~/pycnc && tar xvf pycnc.tar.bz2) > /dev/null" &> /dev/null
|
||||
sshpass -p${PASS} ssh -t ${ADDR} "(cd ~/pycnc && sudo pypy -m cnc.hal_raspberry.rpgpio)"
|
||||
sshpass -p${PASS} scp $(dirname "$0")/../pycnc.tar.bz2 "${ADDRESS}:~/pycnc"
|
||||
sshpass -p${PASS} ssh -t ${ADDRESS} "(cd ~/pycnc && tar xvf pycnc.tar.bz2) > /dev/null" &> /dev/null
|
||||
sshpass -p${PASS} ssh -t ${ADDRESS} "(cd ~/pycnc && sudo pypy -m cnc.hal_raspberry.rpgpio)"
|
||||
|
||||
@@ -131,6 +131,7 @@ class TestCoordinates(unittest.TestCase):
|
||||
|
||||
def test_abs(self):
|
||||
c = Coordinates(-1, -2.5, -99, -23)
|
||||
# noinspection PyTypeChecker
|
||||
r = abs(c)
|
||||
self.assertEqual(r.x, 1.0)
|
||||
self.assertEqual(r.y, 2.5)
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
import unittest
|
||||
import math
|
||||
|
||||
from cnc.coordinates import *
|
||||
from cnc.gcode import *
|
||||
|
||||
|
||||
@@ -16,7 +14,7 @@ class TestGCode(unittest.TestCase):
|
||||
# GCode shouldn't be created with constructor, but since it uses
|
||||
# internally, let's check it.
|
||||
self.assertRaises(TypeError, GCode)
|
||||
gc = GCode({"X": "1", "Y": "-2", "Z":"0", "E": 99, "G": "1"})
|
||||
gc = GCode({"X": "1", "Y": "-2", "Z": "0", "E": 99, "G": "1"})
|
||||
self.assertEqual(gc.coordinates(self.default, 1).x, 1.0)
|
||||
self.assertEqual(gc.coordinates(self.default, 1).y, -2.0)
|
||||
self.assertEqual(gc.coordinates(self.default, 1).z, 0.0)
|
||||
@@ -122,11 +120,12 @@ class TestGCode(unittest.TestCase):
|
||||
gc = GCode.parse_line("X2 Y(inline comment)7")
|
||||
self.assertEqual(gc.coordinates(self.default, 1).x, 2.0)
|
||||
self.assertEqual(gc.coordinates(self.default, 1).y, 7.0)
|
||||
gc = GCode.parse_line("X2 Y(inline comment)3 \t(one more comment) \tz4 ; multi comment test")
|
||||
gc = GCode.parse_line("X2 Y(inline comment)3 \t(one more comment) "
|
||||
"\tz4 ; multi comment test")
|
||||
self.assertEqual(gc.coordinates(self.default, 1).x, 2.0)
|
||||
self.assertEqual(gc.coordinates(self.default, 1).y, 3.0)
|
||||
self.assertEqual(gc.coordinates(self.default, 1).z, 4.0)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
unittest.main()
|
||||
|
||||
@@ -1,9 +1,8 @@
|
||||
import unittest
|
||||
import time
|
||||
|
||||
from cnc.coordinates import *
|
||||
from cnc.gcode import *
|
||||
from cnc.gmachine import *
|
||||
from cnc.coordinates import *
|
||||
|
||||
|
||||
class TestGMachine(unittest.TestCase):
|
||||
@@ -83,7 +82,8 @@ class TestGMachine(unittest.TestCase):
|
||||
self.assertRaises(GMachineException,
|
||||
m.do_command, GCode.parse_line("G3I0J0K1"))
|
||||
self.assertRaises(GMachineException,
|
||||
m.do_command, GCode.parse_line("G2X99999999Y99999999I1J1"))
|
||||
m.do_command, GCode.parse_line("G2X99999999Y99999999"
|
||||
"I1J1"))
|
||||
self.assertRaises(GMachineException,
|
||||
m.do_command, GCode.parse_line("G2X2Y2Z99999999I1J1"))
|
||||
self.assertEqual(m.position(), Coordinates(0, 0, 0, 0))
|
||||
@@ -194,4 +194,4 @@ class TestGMachine(unittest.TestCase):
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
unittest.main()
|
||||
|
||||
@@ -24,5 +24,5 @@ g90
|
||||
g92x100y100z100
|
||||
m111
|
||||
g1x98y98z98
|
||||
(head should be in zero position, and last movent with 500 mm/min velocity)
|
||||
(head should be in zero position, and last movement with 500 mm/min velocity)
|
||||
m2
|
||||
|
||||
@@ -1,9 +1,8 @@
|
||||
import unittest
|
||||
import time
|
||||
|
||||
from cnc.coordinates import *
|
||||
from cnc.pulses import *
|
||||
from cnc.config import *
|
||||
from cnc.coordinates import *
|
||||
from cnc import hal_virtual
|
||||
|
||||
|
||||
@@ -35,8 +34,8 @@ class TestPulses(unittest.TestCase):
|
||||
0, 0, 0),
|
||||
self.v)
|
||||
i = 0
|
||||
for dir, px, py, pz, pe in g:
|
||||
if dir:
|
||||
for direction, px, py, pz, pe in g:
|
||||
if direction:
|
||||
continue
|
||||
i += 1
|
||||
self.assertEqual(px, 0)
|
||||
@@ -51,8 +50,8 @@ class TestPulses(unittest.TestCase):
|
||||
1.0 / STEPPER_PULSES_PER_MM_E),
|
||||
self.v)
|
||||
i = 0
|
||||
for dir, px, py, pz, pe in g:
|
||||
if dir:
|
||||
for direction, px, py, pz, pe in g:
|
||||
if direction:
|
||||
continue
|
||||
i += 1
|
||||
self.assertEqual(px, 0)
|
||||
@@ -61,20 +60,19 @@ class TestPulses(unittest.TestCase):
|
||||
self.assertEqual(pe, 0)
|
||||
self.assertEqual(i, 1)
|
||||
|
||||
|
||||
def __check_circular(self, delta, radius, plane, direction = CW):
|
||||
def __check_circular(self, delta, radius, plane, direction=CW):
|
||||
g = PulseGeneratorCircular(delta, radius, plane, direction, self.v)
|
||||
x, y, z, e = 0, 0, 0, 0
|
||||
dx, dy, dz, de = None, None, None, None
|
||||
dir_changed = 0
|
||||
dir_requested = False
|
||||
t = -1
|
||||
for dir, px, py, pz, pe in g:
|
||||
if dir:
|
||||
for direction_i, px, py, pz, pe in g:
|
||||
if direction_i:
|
||||
dx, dy, dz, de = px, py, pz, pe
|
||||
dir_requested = True
|
||||
continue
|
||||
if dir_requested: # ignore last change
|
||||
if dir_requested: # ignore last change
|
||||
dir_requested = False
|
||||
dir_changed += 1
|
||||
if px is not None:
|
||||
@@ -97,53 +95,43 @@ class TestPulses(unittest.TestCase):
|
||||
def test_single_radius_circles(self):
|
||||
# Check if PulseGenerator returns correctly single radius movement in
|
||||
# both direction.
|
||||
_, pos = self.__check_circular(Coordinates(0, 0, 0, 0),
|
||||
Coordinates(1.0 / STEPPER_PULSES_PER_MM_X, 0, 0, 0),
|
||||
zero_delta = Coordinates(0, 0, 0, 0)
|
||||
radius = Coordinates(1.0 / STEPPER_PULSES_PER_MM_X, 0, 0, 0)
|
||||
_, pos = self.__check_circular(zero_delta, radius, PLANE_XY, CW)
|
||||
self.assertEqual(pos, Coordinates(0, 0, 0, 0))
|
||||
radius = Coordinates(-1.0 / STEPPER_PULSES_PER_MM_X, 0, 0, 0)
|
||||
_, pos = self.__check_circular(zero_delta, radius,
|
||||
PLANE_XY, CW)
|
||||
self.assertEqual(pos, Coordinates(0, 0, 0, 0))
|
||||
_, pos = self.__check_circular(Coordinates(0, 0, 0, 0),
|
||||
Coordinates(-1.0 / STEPPER_PULSES_PER_MM_X, 0, 0, 0),
|
||||
PLANE_XY, CW)
|
||||
radius = Coordinates(0, 1.0 / STEPPER_PULSES_PER_MM_Y, 0, 0)
|
||||
_, pos = self.__check_circular(zero_delta, radius, PLANE_YZ, CW)
|
||||
self.assertEqual(pos, Coordinates(0, 0, 0, 0))
|
||||
_, pos = self.__check_circular(Coordinates(0, 0, 0, 0),
|
||||
Coordinates(0, 1.0 / STEPPER_PULSES_PER_MM_Y, 0, 0),
|
||||
PLANE_YZ, CW)
|
||||
radius = Coordinates(0, -1.0 / STEPPER_PULSES_PER_MM_Y, 0, 0)
|
||||
_, pos = self.__check_circular(zero_delta, radius, PLANE_YZ, CW)
|
||||
self.assertEqual(pos, Coordinates(0, 0, 0, 0))
|
||||
_, pos = self.__check_circular(Coordinates(0, 0, 0, 0),
|
||||
Coordinates(0, -1.0 / STEPPER_PULSES_PER_MM_Y, 0, 0),
|
||||
PLANE_YZ, CW)
|
||||
radius = Coordinates(0, 0, 1.0 / STEPPER_PULSES_PER_MM_Z, 0)
|
||||
_, pos = self.__check_circular(zero_delta, radius, PLANE_ZX, CW)
|
||||
self.assertEqual(pos, Coordinates(0, 0, 0, 0))
|
||||
_, pos = self.__check_circular(Coordinates(0, 0, 0, 0),
|
||||
Coordinates(0, 0, 1.0 / STEPPER_PULSES_PER_MM_Z, 0),
|
||||
PLANE_ZX, CW)
|
||||
radius = Coordinates(0, 0, -1.0 / STEPPER_PULSES_PER_MM_Z, 0)
|
||||
_, pos = self.__check_circular(zero_delta, radius, PLANE_ZX, CW)
|
||||
self.assertEqual(pos, Coordinates(0, 0, 0, 0))
|
||||
_, pos = self.__check_circular(Coordinates(0, 0, 0, 0),
|
||||
Coordinates(0, 0, -1.0 / STEPPER_PULSES_PER_MM_Z, 0),
|
||||
PLANE_ZX, CW)
|
||||
radius = Coordinates(1.0 / STEPPER_PULSES_PER_MM_X, 0, 0, 0)
|
||||
_, pos = self.__check_circular(zero_delta, radius, PLANE_XY, CCW)
|
||||
self.assertEqual(pos, Coordinates(0, 0, 0, 0))
|
||||
_, pos = self.__check_circular(Coordinates(0, 0, 0, 0),
|
||||
Coordinates(1.0 / STEPPER_PULSES_PER_MM_X, 0, 0, 0),
|
||||
PLANE_XY, CCW)
|
||||
radius = Coordinates(-1.0 / STEPPER_PULSES_PER_MM_X, 0, 0, 0)
|
||||
_, pos = self.__check_circular(zero_delta, radius, PLANE_XY, CCW)
|
||||
self.assertEqual(pos, Coordinates(0, 0, 0, 0))
|
||||
_, pos = self.__check_circular(Coordinates(0, 0, 0, 0),
|
||||
Coordinates(-1.0 / STEPPER_PULSES_PER_MM_X, 0, 0, 0),
|
||||
PLANE_XY, CCW)
|
||||
radius = Coordinates(0, 1.0 / STEPPER_PULSES_PER_MM_Y, 0, 0)
|
||||
_, pos = self.__check_circular(zero_delta, radius, PLANE_YZ, CCW)
|
||||
self.assertEqual(pos, Coordinates(0, 0, 0, 0))
|
||||
_, pos = self.__check_circular(Coordinates(0, 0, 0, 0),
|
||||
Coordinates(0, 1.0 / STEPPER_PULSES_PER_MM_Y, 0, 0),
|
||||
PLANE_YZ, CCW)
|
||||
radius = Coordinates(0, -1.0 / STEPPER_PULSES_PER_MM_Y, 0, 0)
|
||||
_, pos = self.__check_circular(zero_delta, radius, PLANE_YZ, CCW)
|
||||
self.assertEqual(pos, Coordinates(0, 0, 0, 0))
|
||||
_, pos = self.__check_circular(Coordinates(0, 0, 0, 0),
|
||||
Coordinates(0, -1.0 / STEPPER_PULSES_PER_MM_Y, 0, 0),
|
||||
PLANE_YZ, CCW)
|
||||
radius = Coordinates(0, 0, 1.0 / STEPPER_PULSES_PER_MM_Z, 0)
|
||||
_, pos = self.__check_circular(zero_delta, radius, PLANE_ZX, CCW)
|
||||
self.assertEqual(pos, Coordinates(0, 0, 0, 0))
|
||||
_, pos = self.__check_circular(Coordinates(0, 0, 0, 0),
|
||||
Coordinates(0, 0, 1.0 / STEPPER_PULSES_PER_MM_Z, 0),
|
||||
PLANE_ZX, CCW)
|
||||
self.assertEqual(pos, Coordinates(0, 0, 0, 0))
|
||||
_, pos = self.__check_circular(Coordinates(0, 0, 0, 0),
|
||||
Coordinates(0, 0, -1.0 / STEPPER_PULSES_PER_MM_Z, 0),
|
||||
PLANE_ZX, CCW)
|
||||
radius = Coordinates(0, 0, -1.0 / STEPPER_PULSES_PER_MM_Z, 0)
|
||||
_, pos = self.__check_circular(zero_delta, radius, PLANE_ZX, CCW)
|
||||
self.assertEqual(pos, Coordinates(0, 0, 0, 0))
|
||||
|
||||
def test_with_hal_virtual(self):
|
||||
@@ -158,30 +146,29 @@ class TestPulses(unittest.TestCase):
|
||||
hal_virtual.move(PulseGeneratorLinear(Coordinates(25.4, 0, 0, 0),
|
||||
self.v))
|
||||
hal_virtual.move(PulseGeneratorLinear(Coordinates(TABLE_SIZE_X_MM,
|
||||
TABLE_SIZE_Y_MM,
|
||||
TABLE_SIZE_Z_MM,
|
||||
100.0), self.v))
|
||||
TABLE_SIZE_Y_MM,
|
||||
TABLE_SIZE_Z_MM,
|
||||
100.0), self.v))
|
||||
hal_virtual.move(PulseGeneratorCircular(Coordinates(0, 20, 0, 0),
|
||||
Coordinates(-10, 10, 0, 0),
|
||||
PLANE_XY, CW, self.v))
|
||||
hal_virtual.move(PulseGeneratorCircular(Coordinates(-4, -4, 0, 0),
|
||||
Coordinates(-2, -2, 0, 0),
|
||||
PLANE_XY, CW, self.v))
|
||||
hal_virtual.move(PulseGeneratorCircular(Coordinates(- 2.0 / STEPPER_PULSES_PER_MM_X,
|
||||
- 2.0 / STEPPER_PULSES_PER_MM_Y,
|
||||
0, 0),
|
||||
Coordinates(- 1.0 / STEPPER_PULSES_PER_MM_X,
|
||||
- 1.0 / STEPPER_PULSES_PER_MM_Y,
|
||||
0, 0),
|
||||
PLANE_XY, CW, self.v))
|
||||
delta = Coordinates(- 2.0 / STEPPER_PULSES_PER_MM_X,
|
||||
- 2.0 / STEPPER_PULSES_PER_MM_Y, 0, 0)
|
||||
radius = Coordinates(- 1.0 / STEPPER_PULSES_PER_MM_X,
|
||||
- 1.0 / STEPPER_PULSES_PER_MM_Y, 0, 0)
|
||||
hal_virtual.move(PulseGeneratorCircular(delta, radius, PLANE_XY, CW,
|
||||
self.v))
|
||||
|
||||
def test_twice_faster_linear(self):
|
||||
# Checks if one axis moves exactly twice faster, pulses are correct.
|
||||
m = Coordinates(2, 4, 0, 0)
|
||||
g = PulseGeneratorLinear(m, self.v)
|
||||
i = 0
|
||||
for dir, px, py, pz, pe in g:
|
||||
if dir:
|
||||
for direction, px, py, pz, pe in g:
|
||||
if direction:
|
||||
continue
|
||||
if i % 2 == 0:
|
||||
self.assertNotEqual(px, None)
|
||||
@@ -203,8 +190,8 @@ class TestPulses(unittest.TestCase):
|
||||
iz = 0
|
||||
ie = 0
|
||||
t = -1
|
||||
for dir, px, py, pz, pe in g:
|
||||
if dir:
|
||||
for direction, px, py, pz, pe in g:
|
||||
if direction:
|
||||
continue
|
||||
if px is not None:
|
||||
ix += 1
|
||||
@@ -244,8 +231,9 @@ class TestPulses(unittest.TestCase):
|
||||
g = PulseGeneratorLinear(m, self.v)
|
||||
i = 0
|
||||
lx = 0
|
||||
for dir, px, py, pz, pe in g:
|
||||
if dir:
|
||||
lt, at, bt = None, None, None
|
||||
for direction, px, py, pz, pe in g:
|
||||
if direction:
|
||||
continue
|
||||
if i == 2:
|
||||
at = px - lx
|
||||
@@ -254,7 +242,8 @@ class TestPulses(unittest.TestCase):
|
||||
bt = px - lx
|
||||
lx = px
|
||||
i += 1
|
||||
self.assertEqual(round(60.0 / lt / STEPPER_PULSES_PER_MM_X), round(self.v))
|
||||
self.assertEqual(round(60.0 / lt / STEPPER_PULSES_PER_MM_X),
|
||||
round(self.v))
|
||||
self.assertGreater(at, lt)
|
||||
self.assertGreater(bt, lt)
|
||||
|
||||
@@ -263,8 +252,8 @@ class TestPulses(unittest.TestCase):
|
||||
m = Coordinates(1, -2, 3, -4)
|
||||
g = PulseGeneratorLinear(m, self.v)
|
||||
dir_found = False
|
||||
for dir, px, py, pz, pe in g:
|
||||
if dir:
|
||||
for direction, px, py, pz, pe in g:
|
||||
if direction:
|
||||
# should be once
|
||||
self.assertFalse(dir_found)
|
||||
dir_found = True
|
||||
@@ -273,8 +262,8 @@ class TestPulses(unittest.TestCase):
|
||||
m = Coordinates(-1, 2, -3, 4)
|
||||
g = PulseGeneratorLinear(m, self.v)
|
||||
dir_found = False
|
||||
for dir, px, py, pz, pe in g:
|
||||
if dir:
|
||||
for direction, px, py, pz, pe in g:
|
||||
if direction:
|
||||
# should be once
|
||||
self.assertFalse(dir_found)
|
||||
dir_found = True
|
||||
|
||||
Reference in New Issue
Block a user