Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
proclaim committed Mar 3, 2017
2 parents e7636e0 + 2075a7d commit 4282b10
Show file tree
Hide file tree
Showing 15 changed files with 13,999 additions and 5,079 deletions.
2 changes: 1 addition & 1 deletion fluxclient/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,5 @@ def check_platform():
p = "OSX"
return (p, platform.architecture()[0])

__version__ = "1.2.4"
__version__ = "1.2.6"
SUPPORT_PCL = check_pcl()
42 changes: 23 additions & 19 deletions fluxclient/fcode/f_to_g.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,9 @@ def change_img(self, buf):
else:
return False

def writeStr(self, o, s):
o.write(s);

def get_metadata(self):
"""
get the metadata
Expand All @@ -143,42 +146,43 @@ def f_to_g(self, outstream, include_meta=False):
if include_meta:
meta = self.get_metadata()
for key, value in meta.items():
outstream.write(";%s=%s\n" % (key, value))
outstream.write("\n")
#print(bytes("WELL.. %s=%s\n" % (key, value)), file=sys.stderr)
outstream.write(bytes(";%s=%s\n" % (key, value), "UTF-8"))
outstream.write(bytes("\n", "UTF-8"))

index = 12
while index < 12 + self.script_size:
command = uchar_unpacker(self.data[index:index + 1])
index += 1
if command == 1:
outstream.write('G28\n')
self.writeStr(outstream, 'G28\n')
elif command == 2:
outstream.write('G90\n')
self.writeStr(outstream, 'G90\n')
elif command == 3:
outstream.write('G91\n')
self.writeStr(outstream, 'G91\n')
elif command == 4:
outstream.write('G4 P{}\n'.format(float_unpacker(self.data[index:index + 4])))
self.writeStr(outstream, 'G4 P{}\n'.format(float_unpacker(self.data[index:index + 4])))
index += 4
elif command == 5:
print('find pause fcode', file=sys.stderr)

elif command == 6:
outstream.write('; raw command to mb\n')
self.writeStr(outstream, '; raw command to mb\n')
start = index
while self.data[index: index + 1] != b'\n':
index += 1
index += 1
outstream.write(self.data[start:index])
outstream.write('; raw command to mb end.\n')
self.writeStr(outstream, elf.data[start:index])
self.writeStr(outstream, '; raw command to mb end.\n')

elif command == 7:
outstream.write('; raw command to print head\n')
self.writeStr(outstream, '; raw command to print head\n')
start = index
while self.data[index] != '\n':
index += 1
index += 1
outstream.write(self.data[start:index])
outstream.write('; raw command to print head end.\n')
self.writeStr(outstream, elf.data[start:index])
self.writeStr(outstream, '; raw command to print head end.\n')

elif command >= 16 and command <= 31: # temperature
if command & 8:
Expand All @@ -188,7 +192,7 @@ def f_to_g(self, outstream, include_meta=False):
temp = float_unpacker(self.data[index:index + 4])
if temp == float('-inf'):
temp = 0
outstream.write('{} T{} S{}\n'.format(c, command & 7, temp)) # not T but P????
self.writeStr(outstream, '{} T{} S{}\n'.format(c, command & 7, temp)) # not T but P????
index += 4
elif command >= 32 and command <= 39: # laser
strength = float_unpacker(self.data[index:index + 4])
Expand All @@ -197,7 +201,7 @@ def f_to_g(self, outstream, include_meta=False):
self.laserflag = True
else:
self.laserflag = False
outstream.write('X2O{} T{}\n'.format(strength, command & 7))
self.writeStr(outstream, 'X2O{} T{}\n'.format(strength, command & 7))
index += 4
elif command >= 48 and command <= 63: # fan speed
speed = float_unpacker(self.data[index:index + 4])
Expand All @@ -206,7 +210,7 @@ def f_to_g(self, outstream, include_meta=False):
c = 'M107'
else:
c = 'M106'
outstream.write('{} S{} T{}\n'.format(c, speed, command & 15))
self.writeStr(outstream, '{} S{} T{}\n'.format(c, speed, command & 15))
index += 4
elif command >= 64 and command <= 127: # set position
tmp = num_to_XYZE(command)
Expand All @@ -217,16 +221,16 @@ def f_to_g(self, outstream, include_meta=False):
index += 4
s.append('{}{} '.format(c, value))
s.append('\n')
outstream.write(''.join(s))
self.writeStr(outstream, ''.join(s))

for i in range(4, 6):
if tmp[i]:
if self.current_T != i - 4:
outstream.write('T{}\n'.format(i - 4))
self.writeStr(outstream, 'T{}\n'.format(i - 4))
self.current_T = i - 4
value = float_unpacker(self.data[index:index + 4])
index += 4
outstream.write('G92 E{}\n'.format(value))
self.writeStr(outstream, 'G92 E{}\n'.format(value))

elif command >= 128 and command <= 255: # moving
line_segment = num_to_XYZE(command)
Expand All @@ -242,7 +246,7 @@ def f_to_g(self, outstream, include_meta=False):
if i >= 1:
self.current_pos[i - 1] = value
s.append('\n')
outstream.write(''.join(s))
self.writeStr(outstream, ''.join(s))

if any(i is not None for i in line_segment[4:6]):
self.extrudeflag = True
Expand Down
11 changes: 8 additions & 3 deletions fluxclient/laser/laser_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import sys
from io import BytesIO, StringIO
from math import pi, sin, cos, sqrt, degrees
from math import sin, cos, degrees
from time import time
from datetime import datetime

Expand Down Expand Up @@ -89,7 +89,7 @@ def turnOff(self):
self.current_power = 0
return ["X2O0;turnOff", "G4 P20"]

def turnTo(self, power=None):
def turnTo(self, power=None, wait_sec=20):
"""
set laser power
"""
Expand All @@ -105,14 +105,19 @@ def turnTo(self, power=None):
return []
self.current_power = power
self.laser_on = True
return ["X2O%d" % round(power * self.draw_power / 255.0), "G4 P20"]
return ["X2O%d" % round(power * self.draw_power / 255.0), "G4 P%d" % wait_sec]

elif power == 0:
if self.current_power == 0:
return []
self.current_power = 0
return self.turnOff()

def moveZ(self, z):
"""Generate gcode for moving to z (pos_z)"""
return ["G1 F%.5f Z%.5f" % (self.laser_speed, z)]


def moveTo(self, x, y, speed=None, z=None, ending=None):
"""
apply global "rotation" and "scale"
Expand Down
13 changes: 9 additions & 4 deletions fluxclient/laser/laser_bitmap.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ def reset(self):
self.ratio *= 1 / self.pixel_per_mm

def gcode_generate(self, res=1):

if self.focus_by_color:
self.laser_speed = 8 * 60
"""
return gcode in string type
res: resolution
Expand All @@ -59,6 +62,10 @@ def gcode_generate(self, res=1):
if h % res != 0:
continue


h_calibration_offset = ((h - abs_shift) * self.ratio) * 0.2 / 2.5
gcode += self.moveZ(self.focal_l + self.obj_height + self.height_offset + h_calibration_offset)

if self.one_way or h & 1 == 0:
itera = itera_o
# this 0.5 is for fixing tiny difference between iter from "left to right " and "right to left"
Expand Down Expand Up @@ -94,10 +101,8 @@ def gcode_generate(self, res=1):
else:
gcode += self.moveTo(itera[w_record] - abs_shift_x, abs_shift - h)

if self.focus_by_color and this < 255:
offset = float((this - 64.0) / 5.0) * 0.2
gcode += self.moveTo(itera[w_record] - abs_shift_x, abs_shift - h, None, self.focal_l + self.obj_height + self.height_offset + offset)
gcode += self.turnTo(255)
if self.focus_by_color:
gcode += self.turnTo(255 - this, wait_sec = 1)
else:
gcode += self.turnTo(255 - this)
gcode += self.moveTo(itera[w] - abs_shift_x, abs_shift - h)
Expand Down
Loading

0 comments on commit 4282b10

Please sign in to comment.