Skip to content
Snippets Groups Projects
Commit 3f12b65d authored by Jingyan Ling's avatar Jingyan Ling
Browse files

update joranl,structrue

parent 5718be71
Branches
No related merge requests found
...@@ -9,7 +9,10 @@ ...@@ -9,7 +9,10 @@
- 3. Offset original path based on given width - 3. Offset original path based on given width
- 4. find intersect between paths with offset and angle bisectors - 4. find intersect between paths with offset and angle bisectors
- 5. connect intersect points and 4 end-points - 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 ### 08/09/2019
- Potential problem: - Potential problem:
......
No preview for this file type
...@@ -23,6 +23,7 @@ import sys ...@@ -23,6 +23,7 @@ import sys
import subprocess import subprocess
sys.path.insert(1,dsnwritier_dir) sys.path.insert(1,dsnwritier_dir)
from sesreader import * from sesreader import *
from roco_ee_dwg_processing import *
#########for paperbot only######## #########for paperbot only########
import paperbot_dsn import paperbot_dsn
...@@ -33,4 +34,4 @@ paperbot_dsn.brd_design(dwg_path,0,module_libpath,save_name) ...@@ -33,4 +34,4 @@ paperbot_dsn.brd_design(dwg_path,0,module_libpath,save_name)
unrouted_dsn_file=save_name+'.dsn' unrouted_dsn_file=save_name+'.dsn'
subprocess.call(['java','-jar','freeRouting.jar','-de',unrouted_dsn_file,'-white','-s']) subprocess.call(['java','-jar','freeRouting.jar','-de',unrouted_dsn_file,'-white','-s'])
wiring_path=find_wire(save_name) wiring_path=find_wire(save_name)
paperbot_draw.post_process(dwg_path,wiring_path) post_process(dwg_path,wiring_path)
...@@ -4,6 +4,7 @@ import ezdxf ...@@ -4,6 +4,7 @@ import ezdxf
import random import random
from math import sqrt from math import sqrt
import copy import copy
from roco_ee_dwg_processing import *
unit_convert=10000 #ses to dxf unit_convert=10000 #ses to dxf
class pre_process(): class pre_process():
...@@ -24,7 +25,7 @@ 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.remove_wheels() ##remove wheel drawings for this design, no need to call for other designs
self.center_arr=self.find_pin() 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) self.dwg.saveas(self.save_name)
...@@ -73,135 +74,3 @@ class pre_process(): ...@@ -73,135 +74,3 @@ class pre_process():
center_arr=np.unique(center_arr,axis=0) center_arr=np.unique(center_arr,axis=0)
center_arr=center_arr[1:] center_arr=center_arr[1:]
return center_arr 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'})
#!/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
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment