diff --git a/README.md b/README.md index 3cb92290018047319ace1e27c8dbc74e263f2085..c2a5605baea2050b54ca5c36170c28bc122c622c 100644 --- a/README.md +++ b/README.md @@ -9,7 +9,10 @@ - 3. Offset original path based on given width - 4. find intersect between paths with offset and angle bisectors - 5. connect intersect points and 4 end-points -- + +- Separate file `paperbot_draw` to a general useful file `roco_ee_dwg_processing.py` and operations specifically for paperbot `paperbot_draw.py` + - functions and classes in `roco_ee_dwg_processing.py` will be useful for future foldable robot project. + ### 08/09/2019 - Potential problem: diff --git a/paperbot_ee_autoroute/__pycache__/paperbot_draw.cpython-36.pyc b/paperbot_ee_autoroute/__pycache__/paperbot_draw.cpython-36.pyc index 5d7a6291f4b167c9ce2b62597dc32a8dfe7c9259..5a079a0f65bd77fc2378e2165cb2526a0871b0f2 100644 Binary files a/paperbot_ee_autoroute/__pycache__/paperbot_draw.cpython-36.pyc and b/paperbot_ee_autoroute/__pycache__/paperbot_draw.cpython-36.pyc differ diff --git a/paperbot_ee_autoroute/fab_drawing.py b/paperbot_ee_autoroute/fab_drawing.py index 09e4b83e47057342cae98ea16d002c47c0f018a5..bd6428217d31767c1866593de67b407d90041520 100644 --- a/paperbot_ee_autoroute/fab_drawing.py +++ b/paperbot_ee_autoroute/fab_drawing.py @@ -23,6 +23,7 @@ import sys import subprocess sys.path.insert(1,dsnwritier_dir) from sesreader import * +from roco_ee_dwg_processing import * #########for paperbot only######## import paperbot_dsn @@ -33,4 +34,4 @@ paperbot_dsn.brd_design(dwg_path,0,module_libpath,save_name) unrouted_dsn_file=save_name+'.dsn' subprocess.call(['java','-jar','freeRouting.jar','-de',unrouted_dsn_file,'-white','-s']) wiring_path=find_wire(save_name) -paperbot_draw.post_process(dwg_path,wiring_path) +post_process(dwg_path,wiring_path) diff --git a/paperbot_ee_autoroute/paperbot_draw.py b/paperbot_ee_autoroute/paperbot_draw.py index cdfc16813922022a589c4069b1c79772096e9088..7a1ec41216215415ea5abc4d820667e834d2f863 100644 --- a/paperbot_ee_autoroute/paperbot_draw.py +++ b/paperbot_ee_autoroute/paperbot_draw.py @@ -4,6 +4,7 @@ import ezdxf import random from math import sqrt import copy +from roco_ee_dwg_processing import * unit_convert=10000 #ses to dxf class pre_process(): @@ -24,7 +25,7 @@ class pre_process(): self.remove_wheels() ##remove wheel drawings for this design, no need to call for other designs self.center_arr=self.find_pin() - self.cross_cut(2,self.center_arr) + cross_cut(self.msp,2,self.center_arr) self.dwg.saveas(self.save_name) @@ -73,135 +74,3 @@ class pre_process(): center_arr=np.unique(center_arr,axis=0) center_arr=center_arr[1:] return center_arr - - def cross_cut(self,cross_size,pin_loc): - """ - cross_size= lenght of bounding box of the cross cut - """ - tipat=cross_size/2 - for pt in pin_loc: - x=pt[0] - y=pt[1] - cross_s1=(x-tipat,y-tipat) - cross_e1=(x+tipat,y+tipat) - cross_s2=(x-tipat,y+tipat) - cross_e2=(x+tipat,y-tipat) - self.msp.add_line(cross_s1,cross_e1,dxfattribs={'linetype':'DASHDOT', 'layer':'Circuit'}) - self.msp.add_line(cross_s2,cross_e2,dxfattribs={'linetype':'DASHDOT', 'layer':'Circuit'}) - - # def line_to_path(self) - - -class post_process(): - def __init__(self,dxf_file,wiring_path): - if not dxf_file.endswith('.dxf'): - dxf_file+='.dxf' - self.dxf_file=dxf_file - self._wiring=wiring_path - self.wiring=[] - self.dwg=ezdxf.readfile(dxf_file) - self.msp=self.dwg.modelspace() - - self.convert_unit() - self.draw_wires() - self.parallel_trace(1) - - self.dwg.saveas('route_text.dxf') - - def convert_unit(self): - for path in self._wiring: - p=np.array(path)/unit_convert - p[:,1]*=-1 - self.wiring.append(p.tolist()) - def draw_wires(self): - for path in self.wiring: - for i in range(len(path)-1): - self.msp.add_line(path[i],path[i+1],dxfattribs={ - 'layer':'Circuit', - 'linetype':'DASHDOT'}) - def find_lind_eq(self,pt1,pt2): - """ - input: two points on a line - pt1:[x1,y1] - pt2:[x2,y2] - return: a,b,theta in terms of cy=ax+b - """ - x1,y1=pt1[0],pt1[1] - x2,y2=pt2[1],pt2[1] - - if x1==x2: - theta=-np.pi/2 - #x= number - a=1 - b=-x1 - c=0 - else: - theta=np.arctan((y2-y1)/(x2-x1)) - A=np.array([[x1,1],[x2,1]]) - k=np.array([y1,y2]) - sol=np.linalg.solve(A,k) - a,b=sol[0],sol[1] - c=1 - return a,b,c,theta - - - def parallel_trace(self,width): - halfw=width/2 - for path in self.wiring: - for i in range(len(path)-1): - start_x,start_y=path[i][0],path[i][1] - end_x,end_y=path[i+1][0],path[i+1][1] - - theta=self.find_lind_eq(path[i],path[i+1])[3] - sinw=np.sin(theta)*halfw - cosw=np.cos(theta)*halfw - s1i=[start_x-sinw,start_y+cosw] - s1o=[start_x+sinw,start_y-cosw] - e1i=[end_x-sinw,end_y+cosw] - e1o=[end_x+sinw,end_y-cosw] - - line1i=self.find_lind_eq(s1i,e1i) - line1o=self.find_lind_eq(s1o,e1o) - - if i==0: - s1=s1i - s2=s1o - else: - s1=e1 - s2=e2 - - if i<len(path)-2: - next_x,next_y=path[i+2][0],path[i+2][1] - theta2=self.find_lind_eq(path[i+1],path[i+2])[3] - - sinw2=np.sin(theta2)*halfw - cosw2=np.cos(theta2)*halfw - - s2i=[end_x-sinw2,end_y+cosw2] - s2o=[end_x+sinw2,end_y-cosw2] - e2i=[next_x-sinw2,next_y+cosw2] - e2o=[next_x+sinw2,next_y-cosw2] - - line2i=self.find_lind_eq(s2i,e2i) - line2o=self.find_lind_eq(s2o,e2o) - - Ainteri=np.array([[line1i[0],-line1i[2]],[line2i[0],-line2i[2]]]) - binteri=np.array([-line1i[1],-line2i[1]]) - Aintero=np.array([[line1o[0],-line1o[2]],[line2o[0],-line2o[2]]]) - bintero=np.array([-line1o[1],-line2o[1]]) - - e1=np.linalg.solve(Ainteri,binteri) - e2=np.linalg.solve(Aintero,bintero) - - else: - #from last end point to this end - e1=[end_x-sinw,end_y+cosw] - e2=[end_x+sinw,end_y-cosw] - - - self.msp.add_line(s1i,e1i,dxfattribs={ - 'layer':'Circuit', - 'linetype':'DASHDOT'}) - self.msp.add_line(s1o,e1o,dxfattribs={ - 'layer':'Circuit', - 'linetype':'DASHDOT'}) diff --git a/paperbot_ee_autoroute/roco_ee_dwg_processing.py b/paperbot_ee_autoroute/roco_ee_dwg_processing.py new file mode 100644 index 0000000000000000000000000000000000000000..761b58d9a7a578655be1f1fa1e28776da91528d2 --- /dev/null +++ b/paperbot_ee_autoroute/roco_ee_dwg_processing.py @@ -0,0 +1,153 @@ +#!/usr/bin/env python3 + +import numpy as np +import ezdxf +import random +from math import sqrt +import copy +unit_convert=10000 #ses to dxf + + +def cross_cut(msp,cross_size,pin_loc): + """ + cross_size= lenght of bounding box of the cross cut + """ + tipat=cross_size/2 + for pt in pin_loc: + x=pt[0] + y=pt[1] + cross_s1=(x-tipat,y-tipat) + cross_e1=(x+tipat,y+tipat) + cross_s2=(x-tipat,y+tipat) + cross_e2=(x+tipat,y-tipat) + msp.add_line(cross_s1,cross_e1,dxfattribs={'linetype':'DASHDOT', 'layer':'Circuit'}) + msp.add_line(cross_s2,cross_e2,dxfattribs={'linetype':'DASHDOT', 'layer':'Circuit'}) + +# def line_to_path() + +class post_process(): + def __init__(self,dxf_file,wiring_path): + if not dxf_file.endswith('.dxf'): + dxf_file+='.dxf' + self.dxf_file=dxf_file + self._wiring=wiring_path + self.wiring=[] + self.dwg=ezdxf.readfile(dxf_file) + self.msp=self.dwg.modelspace() + + self.convert_unitfrom_ses() + # self.draw_wires() + self.parallel_trace(1) + + self.dwg.saveas('route_text.dxf') + + def convert_unitfrom_ses(self): + for path in self._wiring: + p=np.array(path)/unit_convert + p[:,1]*=-1 + self.wiring.append(p.tolist()) + def draw_wires(self): + for path in self.wiring: + for i in range(len(path)-1): + self.msp.add_line(path[i],path[i+1],dxfattribs={ + 'layer':'Circuit', + 'linetype':'DASHDOT'}) + + def parallel_trace(self,width): + halfw=width/2 + for path in self.wiring: + for i in range(len(path)-1): + start_x,start_y=path[i][0],path[i][1] + end_x,end_y=path[i+1][0],path[i+1][1] + + theta=self.find_lind_eq(path[i],path[i+1])[3] + sinw=np.sin(theta)*halfw + cosw=np.cos(theta)*halfw + s1i=[start_x-sinw,start_y+cosw] + s1o=[start_x+sinw,start_y-cosw] + e1i=[end_x-sinw,end_y+cosw] + e1o=[end_x+sinw,end_y-cosw] + + line1i=self.find_lind_eq(s1i,e1i) + line1o=self.find_lind_eq(s1o,e1o) + + if i==0: + s1=s1i + s2=s1o + else: + s1=e1 + s2=e2 + + if i<len(path)-2: + next_x,next_y=path[i+2][0],path[i+2][1] + theta2=self.find_lind_eq(path[i+1],path[i+2])[3] + + sinw2=np.sin(theta2)*halfw + cosw2=np.cos(theta2)*halfw + + s2i=[end_x-sinw2,end_y+cosw2] + s2o=[end_x+sinw2,end_y-cosw2] + e2i=[next_x-sinw2,next_y+cosw2] + e2o=[next_x+sinw2,next_y-cosw2] + + line2i=find_lind_eq(s2i,e2i) + line2o=find_lind_eq(s2o,e2o) + + Ainteri=np.array([[line1i[0],-line1i[2]],[line2i[0],-line2i[2]]]) + binteri=np.array([-line1i[1],-line2i[1]]) + Aintero=np.array([[line1o[0],-line1o[2]],[line2o[0],-line2o[2]]]) + bintero=np.array([-line1o[1],-line2o[1]]) + + e1=np.linalg.solve(Ainteri,binteri) + e2=np.linalg.solve(Aintero,bintero) + + else: + #from last end point to this end + e1=[end_x-sinw,end_y+cosw] + e2=[end_x+sinw,end_y-cosw] + + + self.msp.add_line(s1i,e1i,dxfattribs={ + 'layer':'Circuit', + 'linetype':'DASHDOT'}) + self.msp.add_line(s1o,e1o,dxfattribs={ + 'layer':'Circuit', + 'linetype':'DASHDOT'}) + +def find_line_eq(pt1,pt2): + """ + input: two points on a line + pt1:[x1,y1] + pt2:[x2,y2] + return: a,b,theta in terms of cy=ax+b + """ + + x1,y1=pt1[0],pt1[1] + x2,y2=pt2[0],pt2[1] + if x1>x2: + x1,y1=pt2[0],pt2[1] + x2,y2=pt1[0],pt1[1] + + if x1==x2: + theta=-np.pi/2 + #x= number + a=1 + b=-x1 + c=0 + else: + theta=np.arctan((y2-y1)/(x2-x1)) + A=np.array([[x1,1],[x2,1]]) + k=np.array([y1,y2]) + sol=np.linalg.solve(A,k) + a,b=sol[0],sol[1] + c=1 + + return a,b,c,theta + +def find_angle_bisector(line_eq1,line_eq2): + """ + line_equation follows same pattern as find_line_eq() + eq=[a,b,c,theta] + which refers to cy=ax+b + """ + \ No newline at end of file