Skip to content

Commit 11aed27

Browse files
committed
Change how speed units are handled. #30
1 parent 1cd7586 commit 11aed27

File tree

6 files changed

+65
-29
lines changed

6 files changed

+65
-29
lines changed

inkcut/core/utils.py

+16
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,22 @@ def to_unit(val, unit="px"):
9797
return QtSvgDoc.convertToUnit(val, unit)
9898

9999

100+
def from_speed_unit(val, unit):
101+
dist_unit, time_unit = unit.split('/')
102+
speed = from_unit(val, dist_unit)
103+
if time_unit == 'min':
104+
speed /= 60
105+
return speed
106+
107+
108+
def to_speed_unit(val, unit):
109+
dist_unit, time_unit = unit.split('/')
110+
speed = to_unit(val, dist_unit)
111+
if time_unit == 'min':
112+
speed *= 60
113+
return speed
114+
115+
100116
def parse_unit(val):
101117
"""Parse a string into pixels"""
102118
return QtSvgDoc.parseUnit(val)

inkcut/device/plugin.py

+9-17
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ def set_velocity(self, v):
167167
Parameters
168168
----------
169169
v: int
170-
The force setting value to send to the device
170+
velocity in inkcut units/s
171171
172172
"""
173173

@@ -280,12 +280,12 @@ class DeviceConfig(Model):
280280
#: Time between each path command
281281
#: Time to wait between each step so we don't get
282282
#: way ahead of the cutter and fill up it's buffer
283-
step_time = Float(strict=False).tag(config=True)
283+
step_time = Float(strict=False).tag(config=True) # ms
284284
custom_rate = Float(-1, strict=False).tag(config=True)
285285

286286
#: Distance between each command in user units
287287
#: this is effectively the resolution the software supplies
288-
step_size = Float(parse_unit('1mm'), strict=False).tag(config=True)
288+
step_size = Float(from_unit(1, 'mm'), strict=False).tag(config=True)
289289

290290
#: Interpolate paths breaking them into small sections that
291291
#: can be sent. This allows pausing mid plot as many devices do not have
@@ -347,9 +347,8 @@ class DeviceConfig(Model):
347347
#: Defines prescaling before conversion to a polygon
348348
quality_factor = Float(1, strict=False).tag(config=True)
349349

350-
#: In cm/s
351-
speed = Float(4, strict=False).tag(config=True)
352-
speed_units = Enum('in/s', 'cm/s').tag(config=True)
350+
speed = Float(4, strict=False).tag(config=True) # in inkcut units/s
351+
speed_display_units = Enum('in/s', 'cm/s', 'mm/s', 'mm/min').tag(config=True)
353352
speed_enabled = Bool().tag(config=True)
354353

355354
#: Force in g
@@ -381,10 +380,7 @@ def _default_step_time(self):
381380
382381
383382
"""
384-
#: Convert speed to px/s then to mm/s
385-
units = self.speed_units.split("/")[0]
386-
speed = parse_unit('%s%s' % (self.speed, units))
387-
speed = to_unit(speed, 'mm')
383+
speed = self.speed
388384
if speed == 0:
389385
return 0
390386

@@ -394,7 +390,7 @@ def _default_step_time(self):
394390
def _default_area(self):
395391
return AreaBase()
396392

397-
@observe('speed', 'speed_units', 'step_size')
393+
@observe('speed', 'step_size')
398394
def _update_step_time(self, change):
399395
if change['type'] == 'update':
400396
self.step_time = self._default_step_time()
@@ -703,9 +699,7 @@ def init(self, job):
703699
log.debug("device | init {}".format(job))
704700
config = self.config
705701

706-
# Set the speed of this device for tracking purposes
707-
units = config.speed_units.split("/")[0]
708-
job.info.speed = from_unit(config.speed, units)
702+
job.info.speed = config.speed
709703

710704
direction = self.config.expansion_direction
711705

@@ -865,9 +859,7 @@ def submit(self, job, test=False):
865859
else:
866860
rate = 0 # Undefined
867861
else:
868-
rate = from_unit(
869-
config.speed, # in/s or cm/s
870-
config.speed_units.split("/")[0])/1000.0
862+
rate = config.speed/1000.0
871863

872864
# Device model is updated in real time
873865
model = yield defer.maybeDeferred(self.init, job)

inkcut/device/protocols/gcode.py

+11-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
import atom.api
88
import twisted.internet.task
99

10-
from inkcut.core.utils import async_sleep, log
10+
from inkcut.core.utils import async_sleep, log, from_speed_unit, to_speed_unit
1111
from inkcut.device.plugin import DeviceProtocol, Model
1212
from inkcut.core.api import from_unit, to_unit
1313
from twisted.internet import defer
@@ -195,8 +195,17 @@ def move(self, x, y, z, absolute=True):
195195
def set_force(self, f):
196196
raise NotImplementedError
197197

198+
@defer.inlineCallbacks
198199
def set_velocity(self, v):
199-
raise NotImplementedError
200+
# Marlin docs -> unit/min
201+
# FluidNC -> unit/min (unless inverse time mode is active)
202+
# reprap wiki unit/min
203+
# LinuxCNC -> unit/min (unless inverse time mode active)
204+
if self.config.unit_mode == GCodeConfig.UNIT_METRIC:
205+
v = to_speed_unit(v, "mm/min")
206+
else:
207+
v = to_speed_unit(v, "in/min")
208+
yield self.write("G1 F{:.3f}".format(v))
200209

201210
def set_pen(self, p):
202211
raise NotImplementedError

inkcut/device/protocols/gpgl.py

+6-1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
from inkcut.device.plugin import DeviceProtocol
1212
from atom.api import Instance, Float, Bool, Int, Enum
1313
from inkcut.device.plugin import DeviceProtocol, Model
14+
from inkcut.core.utils import to_unit
1415

1516

1617
class GPGLConfig(Model):
@@ -39,7 +40,11 @@ def move(self, x, y, z, absolute=True):
3940
self.write("%s%i,%i" % ('E' if z else 'O', x, y))
4041

4142
def set_velocity(self, v):
42-
self.write('!%i' % v)
43+
# MP4000 series command set reference manual -> 10mm/s = cm/s
44+
# note that speed can be set in two different modes 1-10 uses an abstract scale from min to max speed
45+
# 100...(max_speed+100) specifies spped offset by 100 in cm/s
46+
speed = max(1, round(to_unit(v, "cm")))
47+
self.write('!{:i}'.format(speed + 100))
4348

4449
def set_force(self, f):
4550
self.write("FX%i,1" % f)

inkcut/device/protocols/hpgl.py

+6-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"""
77
from atom.api import Instance, Float, Bool, Int
88
from inkcut.device.plugin import DeviceProtocol, Model
9-
from inkcut.core.utils import log
9+
from inkcut.core.utils import log, to_speed_unit
1010

1111

1212
class HPGLConfig(Model):
@@ -47,7 +47,11 @@ def set_force(self, f):
4747
self.write("FS%i; " % f)
4848

4949
def set_velocity(self, v):
50-
self.write("VS%i;" % v)
50+
# HP DraftPro programmers reference says that speed units are cm/s
51+
# HP 7585B service manual -> "1 to 6cm/s (0.4 to 24in/s) in 1cm increments"
52+
# Siemens C1613 PROGRAMMIERHANDBUCH cm/sek
53+
# Roland DPX-3300 operation manual cm/s
54+
self.write("VS{}".format(round(to_speed_unit(v, 'cm/s'))))
5155

5256
def set_pen(self, p):
5357
self.write("SP%i;" % p)

inkcut/device/view.enaml

+17-7
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ from enaml.widgets.api import (
2323
from enamlx.widgets.api import DoubleSpinBox
2424
from inkcut.core.api import Model, DockItem
2525
from inkcut.core.models import AreaBase
26-
from inkcut.core.utils import to_unit, from_unit, load_icon
26+
from inkcut.core.utils import to_unit, from_unit, to_speed_unit, from_speed_unit, load_icon
2727
from inkcut.preview.plot_view import PlotView
2828
from inkcut.ui.widgets import AlignmentChoice9
2929
from .plugin import DeviceConfig
@@ -80,12 +80,22 @@ enamldef DeviceConfigView(Container):
8080
Form:
8181
Label:
8282
text = QApplication.translate("device", "Speed")
83-
DoubleSpinBox:
84-
minimum = 0
85-
maximum = 999999999
86-
value := model.speed
87-
single_step = 4
88-
suffix << " {}".format(model.speed_units)
83+
Container:
84+
padding = 0
85+
constraints = [
86+
hbox(speed, speed_unit)
87+
]
88+
DoubleSpinBox: speed:
89+
minimum = 0
90+
maximum = 999999999
91+
value << to_speed_unit(model.speed, model.speed_display_units)
92+
value :: model.speed = from_speed_unit(change['value'], model.speed_display_units)
93+
single_step = 4
94+
suffix << " {}".format(model.speed_display_units)
95+
ObjectCombo: speed_unit:
96+
items = list(model.get_member('speed_display_units').items)
97+
selected := model.speed_display_units
98+
tool_tip = QApplication.translate("device", "Display units for speed, does not affect units used by protocol.")
8999
Label:
90100
text = ""
91101
CheckBox:

0 commit comments

Comments
 (0)