diff --git a/R_6.0kOhms_UR_25.0kOhmpm.exp b/R_6.0kOhms_UR_25.0kOhmpm.exp deleted file mode 100644 index a3805c8..0000000 Binary files a/R_6.0kOhms_UR_25.0kOhmpm.exp and /dev/null differ diff --git a/R_75.0kOhms_UR_90.0kOhmpm.dst b/R_75.0kOhms_UR_90.0kOhmpm.dst new file mode 100644 index 0000000..163ccc1 Binary files /dev/null and b/R_75.0kOhms_UR_90.0kOhmpm.dst differ diff --git a/R_75.0kOhms_UR_90.0kOhmpm.exp b/R_75.0kOhms_UR_90.0kOhmpm.exp new file mode 100644 index 0000000..43c8ad0 Binary files /dev/null and b/R_75.0kOhms_UR_90.0kOhmpm.exp differ diff --git a/__pycache__/exp_generation.cpython-38.pyc b/__pycache__/exp_generation.cpython-38.pyc new file mode 100644 index 0000000..1116437 Binary files /dev/null and b/__pycache__/exp_generation.cpython-38.pyc differ diff --git a/__pycache__/pads.cpython-38.pyc b/__pycache__/pads.cpython-38.pyc new file mode 100644 index 0000000..c1bbd43 Binary files /dev/null and b/__pycache__/pads.cpython-38.pyc differ diff --git a/__pycache__/stitch_gen.cpython-38.pyc b/__pycache__/stitch_gen.cpython-38.pyc new file mode 100644 index 0000000..805e8dc Binary files /dev/null and b/__pycache__/stitch_gen.cpython-38.pyc differ 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