diff --git a/axi/device.py b/axi/device.py index cf0959c..ccdf714 100644 --- a/axi/device.py +++ b/axi/device.py @@ -26,12 +26,12 @@ PEN_DOWN_POSITION = 45 PEN_DOWN_SPEED = 150 PEN_DOWN_DELAY = 0 -ACCELERATION = 5 +ACCELERATION = 6 MAX_VELOCITY = 1 -CORNER_FACTOR = 0.005 +CORNER_FACTOR = 0.005*3 JOG_ACCELERATION = 8 -JOG_MAX_VELOCITY = 6 +JOG_MAX_VELOCITY = 5 VID_PID = '04D8:FD92' @@ -170,6 +170,11 @@ class Device(object): self.run_plan(plan) def run_drawing(self, drawing, progress=True): + print 'number of paths : %d' % len(drawing.paths) + print 'pen down length : %g' % drawing.down_length + print 'pen up length : %g' % drawing.up_length + print 'total length : %g' % drawing.length + print 'drawing bounds : %s' % str(drawing.bounds) self.pen_up() position = (0, 0) bar = Bar(drawing.length, enabled=progress) diff --git a/axi/drawing.py b/axi/drawing.py index 8d5921d..a468315 100644 --- a/axi/drawing.py +++ b/axi/drawing.py @@ -1,6 +1,6 @@ from __future__ import division -from math import sin, cos, radians +from math import sin, cos, radians, hypot from .paths import ( simplify_paths, sort_paths, join_paths, crop_paths, convex_hull, @@ -19,6 +19,7 @@ class Drawing(object): def dirty(self): self._bounds = None self._length = None + self._down_length = None self._hull = None @classmethod @@ -96,9 +97,24 @@ class Drawing(object): @property def length(self): if self._length is None: - self._length = paths_length(self.paths) + length = self._down_length + for p0, p1 in zip(self.paths, self.paths[1:]): + x0, y0 = p0[-1] + x1, y1 = p1[0] + length += hypot(x1 - x0, y1 - y0) + self._length = length return self._length + @property + def up_length(self): + return self.length - self.down_length + + @property + def down_length(self): + if self._down_length is None: + self._down_length = paths_length(self.paths) + return self._down_length + @property def width(self): x1, y1, x2, y2 = self.bounds diff --git a/examples/paths.py b/examples/paths.py index 0190850..1a0007b 100644 --- a/examples/paths.py +++ b/examples/paths.py @@ -14,7 +14,7 @@ def main(): # print len(d.paths) print 'transforming paths' # d = d.scale(1, -1) - d = d.rotate(180) + # d = d.rotate(180) d = d.rotate_and_scale_to_fit(12, 8.5, step=90) print 'sorting paths' d = d.sort_paths()