From 12ee1b57f6dd39e9ded8f5790faeea03ad77ef27 Mon Sep 17 00:00:00 2001 From: Somerset Schrock <55516370+srschrock@users.noreply.github.com> Date: Fri, 18 Jun 2021 11:16:20 -0400 Subject: [PATCH] v3.0 update Added functionality to utilize pyembroidery package to create any major embroidery file type. Code has been cleaned. --- R_6.0kOhms_UR_25.0kOhmpm.exp | Bin 650 -> 0 bytes R_75.0kOhms_UR_90.0kOhmpm.dst | Bin 0 -> 3422 bytes R_75.0kOhms_UR_90.0kOhmpm.exp | Bin 0 -> 1938 bytes __pycache__/exp_generation.cpython-38.pyc | Bin 0 -> 1540 bytes __pycache__/pads.cpython-38.pyc | Bin 0 -> 1470 bytes __pycache__/stitch_gen.cpython-38.pyc | Bin 0 -> 905 bytes exp_generation.py | 36 +++--- main.py | 133 +++++++++++++++------- pads.py | 20 ++-- stitch_gen.py | 32 +++--- 10 files changed, 139 insertions(+), 82 deletions(-) delete mode 100644 R_6.0kOhms_UR_25.0kOhmpm.exp create mode 100644 R_75.0kOhms_UR_90.0kOhmpm.dst create mode 100644 R_75.0kOhms_UR_90.0kOhmpm.exp create mode 100644 __pycache__/exp_generation.cpython-38.pyc create mode 100644 __pycache__/pads.cpython-38.pyc create mode 100644 __pycache__/stitch_gen.cpython-38.pyc diff --git a/R_6.0kOhms_UR_25.0kOhmpm.exp b/R_6.0kOhms_UR_25.0kOhmpm.exp deleted file mode 100644 index a3805c83e823baea4dd90a19ddec2fc75ec8e437..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 650 zcmd^-(F(vI2u06};Mo8FY6QKkoFj?y2Zn@QIVR*)vL#S>kIkngrDO=XTk?+&Pw=Sy^rl>eo?;b)eCM7Xzr=z9y{mC`2Vl6xRff$U~8o5NEi@ejte4JQN$`hjA5WV{+NS;FhN0zoD@2q zL+4?9+#B|(=gGmi?7Z9_4e)}SII-79%ARCTPX18NNzTdtbArC@-&eNn{fkdq%HaL3|s}gf@(u{Mjk+Qr*+C)?nQR~VM=__@miX2)G^YqSy+J1L6)jgn& z3cv7{(?c)fBdVg>=J2j;=VJ1rl$|A;Qdf|vD@E~S-wA6PLn9OI5Z?%w*i zcR$xA@8#J@o8DnIn2vN>DV=S60YhdR}!U&LA3)3fo0 zx;LKNXg|TNK{gs6G#D2bYXIug_eT9wef(vd=)L_U8}yU>0K)3-e{ali`>u^kX}FXX z^S@d%A$$3AYJ%1%{#7P`*Uj$@2yTAeN)&W~89o=w3Dz}ikWNQvFfiFPRfYp!SB{7M z|H~QvGccU%bv4?XHSQVSi3Qm@q1jsAG7Q)Rt4Evz>)ey0fkIk}&qXhl9MX=rXl^@+F9W;+p6< z3PmJC5kdpWNQ815_O7F-_H{+H@&&$lN9>5VywK~29nZXv{JYX@fjM~tkNZk^i)^?* Q%G5N`2Ry!<*DjQQ0&?0#1^@s6 literal 0 HcmV?d00001 diff --git a/__pycache__/pads.cpython-38.pyc b/__pycache__/pads.cpython-38.pyc new file mode 100644 index 0000000000000000000000000000000000000000..c1bbd4315f2d0ddac23e26a509b598b2bab95df3 GIT binary patch literal 1470 zcmbtU&2AGh5FR^!n?OQ=2vzioD&>MWAQhnsAsVTidO^LQMJ27>uu`%=_C_?4bAkup z5#X46)u-SIeBi<<5>LR1881ki)ov6CuRQCqJ>SUlefDX$+W~A3ufM-HIQmIWzHxM3 zV%L2%0tEXEZ$WTT!#@-CH!x^iv~cNPYvZ7S{Rq3hVE`${nC2%wgm>4AR?d60@C^UT z418k@ObtiOjleWaa}N$+0m*LZ4n{i!?}MoAg4@Zq$9+b)@wT{0#}u+*d_LRFR%db; zdqAui6oa;9SC-9f^D2&lFtyEj_UC$Hc|5URJQ8Or`lu}nEDwSusJjUC z`}pX&f2yU@zK*6+`NQa9HkDzj{o^2gJv;a1^jt-OkV;~_)PYVTbvBlvRHHPALLYJU z<9Ke{EGIqT!$}${B)$3K>@POrQUxj{U4o2~F3eI@ z@{(4hVnsv_JVl%;daD#Yf9e*Q+hn?AdSvd9A;D(m9*#0ePvm9#6unGv{J#Z9FYC#G bJK-sEa#>yeEcM|u60?bX;j~WI(tGj;KJ_D! literal 0 HcmV?d00001 diff --git a/__pycache__/stitch_gen.cpython-38.pyc b/__pycache__/stitch_gen.cpython-38.pyc new file mode 100644 index 0000000000000000000000000000000000000000..805e8dc6034e2fcc4a13e09e0950622fd0040863 GIT binary patch literal 905 zcma)3y>8S%5T0H8jIn(N2_kp|j)E41P=rV%Xh;KTkde7NFLx&X-Q9znw62J#^9Vpk zN0GaOt5|^1`kn0gerrK z9KZ|6=rb5N;}BCPCq@VHu!SPN609X%C{Zi_J>7$B;F-Kiwqu{@+#Il(VhCOT#&g22*-CN9Nc`nu$ z5v#u6FVeSttB~miGOg`?yE}LHC4-&mkhGhK?uDQ(-Gn_jB>eL^oPYgi#JxcrQB*l9 zeBCqexpQnD^Vq!jfa)F}RuiVZVbicG8^oIIYcki~epBa_)ZTnysVFpUP$q?TB&rRb zPo^>*)l$}FDr7FlQzmr$F3;q26nd4vH<>%lTnFVauhLOb zkN3=y;yEgyt`n00Kc56E&yC4xc6sanlL;K3o>WEdRl4XBQNDqFcLu~-yUCimj(6IB PP}bS3V4G%+pD6GLyJ^;E literal 0 HcmV?d00001 diff --git a/exp_generation.py b/exp_generation.py index 0190ceb..22962b5 100644 --- a/exp_generation.py +++ b/exp_generation.py @@ -1,28 +1,26 @@ import numpy -def make_file (xpoint,ypoint,file_name): - #mm*10 - xpoint = [x*10 for x in xpoint] - ypoint = [y*10 for y in ypoint] - - - #calc delta-x & y for each stitch - dx=[]; dy=[] - for i in range(0,len(xpoint)-1): - dx.append(xpoint[i+1]-xpoint[i]) - dy.append(ypoint[i+1]-ypoint[i]) +def make_file (dx,dy,file_name): + #mm*10 is used for creation of .exp + dx = [x*10 for x in dx] + dy = [y*10 for y in dy] + #helps filter out the 10's and 237's, important later dx = [numpy.round(x) for x in dx] dy = [numpy.round(y) for y in dy] #convert to byte - #1-127 are forward by that amount - #129-255 are backward by that same amount - dxn=[]; dyn=[] - #chr(10) and chr(237) mess things up, FYI - #need to alternate above and below these values to avoid offsets + #1-127 are forward by that amount in 0.1mm increments + #129-255 are backward by 0.1mm increments, + #where 255 is -0.1mm, 254 is -0.2mm, etc + + #chr(10) and chr(237) mess things up, FYI + #need to alternate above and below these values to avoid offsets + #the following code addresses this issue + dxn=[]; dyn=[] #initialize variables for excluded 10 and 237 + xpalt=True; xnalt=True; ypalt=True; ynalt=True; for stitch in range(0,len(dx)): if dx[stitch] < 0: @@ -63,15 +61,17 @@ def make_file (xpoint,ypoint,file_name): # convert movement number to uint8 format (hexad) # and merge into one continuous string string2="" - for stitch in range(0,int(len(dxn)/1)): + for stitch in range(0,int(len(dxn)/1)): #int(len(dxn)/1) string2+=chr(int(dxn[stitch])) string2+=chr(int(dyn[stitch])) + # adding extention for .exp file type + file_name += "exp" # write data to .exp file with open(file_name, 'w') as filehandle: filehandle.write(string2) #return values for troubleshooting if needed - return dxn,dyn + return diff --git a/main.py b/main.py index 106ff00..92a8717 100644 --- a/main.py +++ b/main.py @@ -1,37 +1,41 @@ -# RESISTOR FILE GENERATION TOOL (v2) +# RESISTOR FILE GENERATION TOOL (v3) # # This program is for creating embroidery files for electrical resistors # # Developed in Python 3.8 -# Last edit: May 1, 2021 -# writes to .exp (Melco, Bravo, and Bernina machines) +# +# Last edit: June 17, 2021 +# +# writes directly to .exp (Melco, Bravo, and Bernina machines) +# includes conversion tool for all major embroidery file types -import exp_generation -import stitch_gen -import pads -import numpy as np -import math -import matplotlib.pyplot as plt ################################ -#### user inputs +#### USER INPUTS ################################ -r = 6_000 # desired resistance (Ohms) -rho=25_000 # thread unit resistance (Ohms/m) +r = 75_000 # desired resistance (Ohms) +rho=90_000 # thread unit resistance (Ohms/m) gl = 1; #gap length (spacing between rows) (mm) sl = gl; #stitch length (gap between stitches) (mm) tgl = 2*gl; #gap length between terminal pads (mm) -pl = 2.5; #pad length (mm) -pad_rows = 3 #terminal pad stitch density (number of stitch rows) +pl = 3.8; #pad length (mm) +pad_rows = 4 #terminal pad stitch density (number of stitch rows) -#making a filename reflective of target resistance and thread unit resistance -#rename to your own filename if you so choose, otherwise leave as is -file_name="".join(["R_",str(round(r/1000,1)),"kOhms_UR_",str(round(rho/1000,1)),"kOhmpm.exp"]) +# supported file types to write to: + #dst,pec,pes,exp,vp3,jef,u01,svg,csv,xxx,png,txt,gcode +file_type="dst" #desired file type + +# making a filename reflective of target resistance and thread unit resistance +file_name="".join(["R_",str(round(r/1000,1)),"kOhms_UR_", + str(round(rho/1000,1)),"kOhmpm."]) + +# rename to your own filename if you so choose, otherwise leave as is +# file_name="manual_name." # be sure to include a "." at the end of the name ################################ -#### initialize counters, lists, and (x,y) coords +#### Initialize counters, lists, and (x,y) coords ################################ tl = 0; #total length of thread used (initialize counter) @@ -40,14 +44,18 @@ x = y = 0; #initial coordinates (0,0) ################################ -#### pattern calculations +#### Pattern Calculations ################################ -len = r/rho; #desired length of thread (ft) -len = len*1000; #length of wire (mm) +import numpy as np +import math -w=(-8*gl+math.sqrt(gl)*math.sqrt(16*gl+24*len+24*tgl+48*pl))/4; #width of resistor -h=w*2/3; #height of the tines +length = (r/rho)*1000; #desired length of thread (mm) + +#width of resistor +w=(-8*gl+math.sqrt(gl)*math.sqrt(16*gl+24*length+24*tgl+48*pl))/4; + +h=w*2/3; #height of the tines (mm) width_stitches = int((w/2)/gl)+1 height_stitches = int(h/sl) @@ -59,39 +67,88 @@ right_bottom_stitches = int((w/2-tgl/2-pl)/sl) #### Start of stitching process ################################## +import stitch_gen +import pads + #right terminal pad -right_pad_matrix = pads.pad_right(x,y, xpoint,ypoint,sl,pl,pad_rows) -x=right_pad_matrix[0]; y=right_pad_matrix[1] #(x,y) coords of current stitch -xpoint=right_pad_matrix[2]; ypoint=right_pad_matrix[3] +x,y,xpoint,ypoint = pads.pad_right(x,y, xpoint,ypoint,sl,pl,pad_rows) # main body of the resistor -main_matrix=stitch_gen.main_block(x,y, xpoint,ypoint,sl,pl,gl,tgl,right_bottom_stitches,width_stitches,height_stitches) - -x=main_matrix[0]; y=main_matrix[1] #(x,y) coords of current stitch - -xpoint=main_matrix[2]; ypoint=main_matrix[3] #list of (x,y) stitches -tl=main_matrix[4] #length of thread used in resistor (no pads) +x,y,xpoint,ypoint,tl =stitch_gen.main_block(x,y, xpoint,ypoint,sl,pl,gl,tgl, + right_bottom_stitches,width_stitches,height_stitches) #add left terminal pad -main_matrix = pads.pad_left(x,y, xpoint,ypoint,sl,pl,pad_rows) -xpoint=main_matrix[2]; ypoint=main_matrix[3] +x,y,xpoint,ypoint = pads.pad_left(x,y, xpoint,ypoint,sl,pl,pad_rows) ################################ -#### file generation (convert to .exp) +#### Calculate dx & dy ################################ xpoint = np.asarray(xpoint); ypoint = np.asarray(ypoint) -dx,dy = exp_generation.make_file(xpoint,ypoint,file_name) +#calc delta-x & y for each stitch +dx=[]; dy=[] +for i in range(0,int(len(xpoint))-1): + dx.append(xpoint[i+1]-xpoint[i]) + dy.append(ypoint[i+1]-ypoint[i]) ################################ -#### plotting resistor pattern +#### File Generation .EXP ################################ +import exp_generation +exp_generation.make_file(dx,dy,file_name) + + +################################ +#### File Generation .DST +################################ + +# needs development, better off converting from the created.exp + # with conversion tool pyembroidery + +# import dst_generation +# dst_generation.make_file(dx,dy,file_name) + + +################################ +#### File Conversion (to any file type) +################################ + +# supported file types to write to: + #dst,pec,pes,exp,vp3,jef,u01,svg,csv,xxx,png,txt,gcode + +# if package not yet downloaded, use command "pip install pyembroidery" + +if file_type != "exp": + import pyembroidery + + # two step process: + # pattern = pyembroidery.read("".join([file_name,"exp"])) + # pyembroidery.write(pattern,"".join([file_name,file_type])) + + # or in one step: + pyembroidery.convert("".join([file_name,"exp"]), + "".join([file_name,file_type])) + +# to show which file was created +print("File name: ","".join([file_name,file_type])) + + +# to show file location: +# import os +# print("File location: ",os.getcwd()) + +################################ +#### Plot Resistor Pattern +################################ + +import matplotlib.pyplot as plt plt.plot(xpoint,ypoint,'r-',xpoint,ypoint,'x') plt.ylabel('y coordinate (mm)') plt.xlabel('x coordinate (mm)') plt.title('Resistor Pattern') -plt.show() \ No newline at end of file +plt.show() + diff --git a/pads.py b/pads.py index c1f3f09..2b4f9cd 100644 --- a/pads.py +++ b/pads.py @@ -8,38 +8,38 @@ def pad_right(x,y, xpoint,ypoint,sl,pl,pad_rows): for ii in range(0,pad_rows): xpoint.append(x) ypoint.append(y) - x=x+pl/pad_rows; + x += (pl/pad_rows); xpoint.append(x) ypoint.append(y) - y=y+pl/(pad_rows*2-1); + y += pl/(pad_rows*2-1); for ii in range(0,pad_rows): xpoint.append(x) ypoint.append(y) - x=x-pl/pad_rows; + x -= (pl/pad_rows); xpoint.append(x) ypoint.append(y) - y=y+pl/(pad_rows*2-1); + y += pl/(pad_rows*2-1);#*2-1 #end of the loop to create connector pad (horizontal lines) (right) - y=y-pl/(pad_rows*2-1); #offset last movement + y -= pl/(pad_rows*2-1); #offset last movement *2-1 #vertical lines for i in range(0,pad_rows): for ii in range(0,pad_rows): xpoint.append(x) ypoint.append(y) - y=y-pl/pad_rows; + y -= pl/pad_rows; xpoint.append(x) ypoint.append(y) - x=x+pl/(pad_rows*2-1); + x += pl/(pad_rows*2-1); for ii in range(0,pad_rows): xpoint.append(x) ypoint.append(y) - y=y+pl/pad_rows; + y += pl/pad_rows; xpoint.append(x) ypoint.append(y) - x=x+pl/(pad_rows*2-1); + x += pl/(pad_rows*2-1); # end of the loop to create connector (vertical lines) (right) - x = x - pl / (pad_rows*2-1); # step back to top of pad + x -= pl / (pad_rows*2-1); # step back to top of pad return x, y, xpoint, ypoint # end of function pads_right diff --git a/stitch_gen.py b/stitch_gen.py index 11a141b..f6a2fe2 100644 --- a/stitch_gen.py +++ b/stitch_gen.py @@ -7,15 +7,15 @@ def main_block (x,y, xpoint,ypoint,sl,pl,gl,tgl,right_bottom_stitches,width_stit for i in range(0,right_bottom_stitches): xpoint.append(x) ypoint.append(y) - x+=sl; - tl+=sl; + x += sl; + tl += sl; #step upwards 2 gap lengths for step in range(0,2): xpoint.append(x) ypoint.append(y) - y+=gl; - tl+=gl; + y += gl; + tl += gl; #repeating columns for main block @@ -23,21 +23,21 @@ def main_block (x,y, xpoint,ypoint,sl,pl,gl,tgl,right_bottom_stitches,width_stit for i in range (0,height_stitches): xpoint.append(x) ypoint.append(y) - y+=sl; - tl+=sl; + y += sl; + tl += sl; xpoint.append(x) ypoint.append(y) - x-=gl; - tl+=gl; + x -= gl; + tl += gl; for i in range(0,height_stitches): xpoint.append(x) ypoint.append(y) - y-=sl; - tl+=sl; + y -= sl; + tl += sl; xpoint.append(x) ypoint.append(y) - x-=gl; - tl+=gl; + x -= gl; + tl += gl; #end of while loop, vertical tabs done x=x+gl; #cancel x jump of last loop @@ -45,8 +45,8 @@ def main_block (x,y, xpoint,ypoint,sl,pl,gl,tgl,right_bottom_stitches,width_stit for step in range(0,2): xpoint.append(x) ypoint.append(y) - y-=gl; #step down to start return path - tl+=gl; + y -= gl; #step down to start return path + tl += gl; #return to left terminal pad @@ -54,7 +54,7 @@ def main_block (x,y, xpoint,ypoint,sl,pl,gl,tgl,right_bottom_stitches,width_stit #for i in range(0,left_bottom_stitches): xpoint.append(x) ypoint.append(y) - x+=sl; - tl+=sl; + x += sl; + tl += sl; #print(xpoint) return(x,y, xpoint,ypoint,tl) \ No newline at end of file