Skip to content

Commit

Permalink
Merge pull request #3 from meerk40t/rotary_correction
Browse files Browse the repository at this point in the history
Add Rotary Commands to Galvo Commands
  • Loading branch information
tatarize authored Jul 13, 2023
2 parents 6c13f2a + 4540550 commit 1b1771b
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 12 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -154,5 +154,5 @@ See https://github.com/meerk40t/galvoplotter/tree/main/examples for example scri
# Thanks
* Bryce Schroeder - Did the initial work for reverse engineering the format for the laser.
* See: https://gitlab.com/bryce15/balor for his project.
* inpain / tiger12506 - Did considerable with galvo lasers to faciliate the reverse engineering.
* inpain / tiger12506 - Did considerable debugging with galvo lasers to facilitate the reverse engineering.
* Sandor Konya - Introductions, advice and support
37 changes: 27 additions & 10 deletions galvo/controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
Galvo Controller
The balor controller takes low level lmc galvo commands and converts them into lists and shorts commands to send
to the hardware controller.
to the hardware controller as both spooled and realtime commands.
"""

import struct
Expand All @@ -17,6 +17,7 @@

BUSY = 0x04
READY = 0x20
AXIS = 0x40

nop = [0x02, 0x80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
empty = bytearray(nop * 0x100)
Expand All @@ -29,7 +30,7 @@ class GalvoController:
This should serve as a next generation command sequencer written from scratch for galvo lasers. The goal is to
provide all the given commands in a coherent queue structure which provides correct sequences between list and
single commands.
single commands. As well as some higher level helper commands tasked with simplifying scripts and workflows.
"""

def __init__(
Expand Down Expand Up @@ -640,6 +641,12 @@ def light_off(self, override_list=None):
else:
self.write_port()

def rotary(self, position, min_speed=100, max_speed=5000, origin_param=100, **kwgs):
self.set_axis_motion_param(min_speed & 0xFFFF, max_speed & 0xFFFF)
self.set_axis_origin_param(origin_param)
self.move_axis_to(position & 0xFFFF)
self.wait_axis()

def get_last_xy(self):
return self._last_x, self._last_y

Expand All @@ -655,6 +662,10 @@ def is_ready(self):
status = self.status()
return bool(status & READY)

def is_axis(self):
status = self.status()
return bool(status & AXIS)

def is_ready_and_not_busy(self):
status = self.status()
return bool(status & READY) and not bool(status & BUSY)
Expand All @@ -665,6 +676,12 @@ def wait_finished(self):
if not self._sending:
return

def wait_axis(self):
while self.is_axis():
time.sleep(0.01)
if not self._sending:
return

def wait_ready(self):
while not self.is_ready():
time.sleep(0.01)
Expand Down Expand Up @@ -1440,17 +1457,17 @@ def write_analog_port_x(self, port):
def read_port(self):
return self._command(ReadPort)

def set_axis_motion_param(self, param):
return self._command(SetAxisMotionParam, param)
def set_axis_motion_param(self, p0=0, p1=0, p2=0, p3=0):
return self._command(SetAxisMotionParam, p0, p1, p2, p3)

def set_axis_origin_param(self, param):
return self._command(SetAxisOriginParam, param)
def set_axis_origin_param(self, p0=0, p1=0, p2=0, p3=0):
return self._command(SetAxisOriginParam, p0, p1, p2, p3)

def axis_go_origin(self):
return self._command(AxisGoOrigin)
def axis_go_origin(self, p0=0, p1=0):
return self._command(AxisGoOrigin, p0, p1)

def move_axis_to(self, a):
return self._command(MoveAxisTo)
def move_axis_to(self, p0, p1=0, p2=0, p3=0):
return self._command(MoveAxisTo, p0, p1, p2, p3)

def get_axis_pos(self):
return self._command(GetAxisPos)
Expand Down
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[metadata]
name = galvoplotter
version = 0.1.0
version = 0.1.1
description = Galvo Plotter
long_description_content_type=text/markdown
long_description = file: README.md
Expand Down

0 comments on commit 1b1771b

Please sign in to comment.