Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
  • jllemur813/roco_electrical
1 result
Show changes
Commits on Source (14)
Showing
with 7912 additions and 23318 deletions
......@@ -53,7 +53,7 @@ $HANDLING
9
$TDUPDATE
40
2458725.645324074
2458726.6778472224
9
$HANDSEED
5
......
......@@ -231,13 +231,14 @@ class post_process():
else:
k=0
kk=1
further_ept=path[kk]
for pin in self.pin_at:
if point_within_pinbox(ept,pin,self.iso_size):
self.wiring[i][k]=pin
if point_within_pinbox(further_ept,pin,self.iso_size):
self.wiring[i].pop(kk)
break
if len(path)>1:
further_ept=path[kk]
for pin in self.pin_at:
if point_within_pinbox(ept,pin,self.iso_size):
self.wiring[i][k]=pin
if point_within_pinbox(further_ept,pin,self.iso_size):
self.wiring[i].pop(kk)
break
path_list=copy.deepcopy(self.wiring)
self.wiring=[]
......@@ -338,8 +339,9 @@ class post_process():
dis=[]
for off_line in offset_lines:
inter=find_intersect(l2,off_line)
dis_=distance_between_pts(further_ept,inter)
dis.append(dis_)
if type(inter)!=type(None):
dis_=distance_between_pts(further_ept,inter)
dis.append(dis_)
off_l=offset_lines[np.argmin(dis)]
off_l2in,off_l2out=find_offset(l2,width)
s_=find_intersect(off_l2in,off_l)
......
......@@ -10,7 +10,7 @@
(place U1 1040000 461000 front 90)
)
(component T1
(place T1 870000 900000 back 0)
(place T1 870000 900000 front 0)
)
(component L1
(place L1 670000 410000 front 90)
......@@ -32,98 +32,112 @@
(network_out
(net 3v3
(wire
(path F.Cu 15238
1095538 750926
1205100 641363
1205100 575300
(path F.Cu 20000
1208927 769036
1208927 581620
)
)
(wire
(path F.Cu 20000
1251600 929529
1208927 886856
1208927 769036
)
)
(wire
(path F.Cu 20000
1208927 769036
889067 769036
889067 769037
)
)
(wire
(path F.Cu 15238
870000 798400
870000 808782
885189 823971
1022492 823971
1095538 750926
870000 788103
889067 769037
)
)
(wire
(path F.Cu 20000
1251600 945976
1251600 906988
1095538 750926
(path F.Cu 15238
1208927 581620
1205100 577793
1205100 575300
)
)
(wire
(path F.Cu 15238
1251600 973500
1251600 945976
1251600 929529
)
)
)
(net GND
(wire
(path F.Cu 20000
837766 805234
804441 805234
670000 670793
897207 826443
824970 826443
670000 671473
670000 435400
)
)
(wire
(path F.Cu 20000
837766 805234
837766 809363
966519 938116
1212735 938116
1226200 951581
897207 826443
1104527 826443
1226200 948116
)
)
(wire
(path F.Cu 20000
670000 435400
668570 435400
642254 409084
642254 385621
671591 356284
808268 356284
1001900 549916
897207 816057
897207 826443
)
)
(wire
(path F.Cu 15238
1001900 549916
1001900 575300
895400 798400
897207 800207
897207 816057
)
)
(wire
(path F.Cu 15238
1226200 951581
1226200 948116
1226200 973500
)
)
(wire
(path F.Cu 20000
670000 435400
668555 435400
642308 409153
642308 385925
671949 356284
808268 356284
1001900 549916
)
)
(wire
(path F.Cu 15238
837766 805234
844600 798400
1001900 549916
1001900 575300
)
)
)
(net NET1
(wire
(path F.Cu 20000
897624 796176
897624 786640
881379 770395
805231 770395
720000 685164
837017 790817
825375 790817
720000 685442
720000 422700
)
)
(wire
(path F.Cu 15238
897624 796176
895400 798400
844600 798400
837017 790817
)
)
)
......@@ -139,59 +153,54 @@
(net SCL
(wire
(path F.Cu 20000
1205645 993546
1200800 988701
)
)
(wire
(path F.Cu 20000
1052700 561509
1066737 547472
1216392 547472
1279223 610303
1279223 984942
1263042 1001123
1213222 1001123
1205645 993546
1200800 988622
1213751 1001573
1262669 1001573
1279703 984539
1279703 610226
1216911 547434
1055182 547434
1052700 549916
)
)
(wire
(path F.Cu 15238
1200800 973500
1200800 988701
1052700 549916
1052700 575300
)
)
(wire
(path F.Cu 15238
1052700 575300
1052700 561509
1200800 988622
1200800 973500
)
)
)
(net SDA
(wire
(path F.Cu 20000
1027300 549916
1055324 521892
1226301 521892
1304527 600118
1304527 994994
1272595 1026926
1203255 1026926
1175400 999071
1175400 988622
1027300 549505
1027300 539917
1045031 522186
1227572 522186
1304811 599425
1304811 995273
1272940 1027144
1203241 1027144
1175400 999303
1175400 990546
)
)
(wire
(path F.Cu 15238
1027300 549916
1027300 575300
1175400 973500
1175400 990546
)
)
(wire
(path F.Cu 15238
1175400 988622
1175400 973500
1027300 575300
1027300 549505
)
)
)
......
......@@ -15,7 +15,7 @@ class brd_design():
self.module_list=[
['mpu-9250.kicad_mod','J1',[115000,91000],'front',270],
['ESP12F-Devkit-V3.kicad_mod','U1',[104000,46100],'front',90],
['touch_sensor.kicad_mod','T1',[87000,90000],'back',0],
['touch_sensor.kicad_mod','T1',[87000,90000],'front',0],
['LED_D3.0mm.kicad_mod','L1',[67000,41000],'front',90],
['Resistor.kicad_mod','R1',[72000,41000],'front',270],
......
This diff is collapsed.
#!/usr/bin/env python
import numpy as np
import ezdxf
import random
from math import sqrt
import cv2
import os
from pathfinding.core.diagonal_movement import DiagonalMovement
from pathfinding.core.grid import Grid
from pathfinding.finder.a_star import AStarFinder
import copy
import matplotlib.pyplot as plt
import matplotlib.animation as animation
from matplotlib import cm
class auto_rounter:
def __init__(self,path,dxf_file):
self.dwg=ezdxf.readfile(path+dxf_file)
self.msp=self.dwg.modelspace()
self.dxf_name='silhouette_ele.dxf'
self.fail_flag=False #return True when path not found
self.create_layer('Cut',5)
self.create_layer('Circuit',1)
self.create_layer('Label',3)
self.create_layer('Fold',4)
self.create_layer('Pin_temp',6)
self.layer_rearrange() ## reagrrange cut and fold lines to corresponding layers
self.remove_wheels() ##remove wheel drawings for this design, no need to call for other designs
self.find_pin()
isolength=2.6 #mm
# self.draw_on_pin(isolength)
self.matrix_shape=(270,210)
self.read_dxf_as_matrix()
# self.connections_list=np.array([[0,0],[0,0]]).reshape(1,2,2)
# connection_amount=4
# for i in range(connection_amount):
# s=random.randint(0,len(self.center_arr)-1)
# e=random.randint(0,len(self.center_arr)-1)
# connections=np.array([[self.center_arr[s],self.center_arr[e]]]).reshape(1,2,2)
# self.connections_list=np.append(self.connections_list,connections,axis=0)
# self.connections_list=np.rint(self.connections_list)[1:]
############for testing and demo purpose #############
self.connections_list=self.test_connections()
# self.matrix_temp=copy.deepcopy(self.matrix)
# self.img=plt.imshow(self.matrix_temp,interpolation='nearest',cmap=cm.Spectral)
# ani=animation.FuncAnimation(self.fig,self.find_multi_path,interval=10)
# plt.show()
self.find_multi_path(1)
self.dwg.saveas(self.dxf_name)
def create_layer(self,layer_name,color):
if not layer_name in self.dwg.layers:
self.dwg.layers.new(name=layer_name,dxfattribs={'color':color})
def layer_rearrange(self):
# put fold lines to the new layer 'Fold'
# put cut lines to the new layer 'Cut
for e in self.msp.query('LINE'):
if e.dxf.color!=5:
e.dxf.layer='Fold'
else:
e.dxf.layer='Cut'
def find_pin(self):
tolerance=0.05 #mm
pincutsize=1 #mm
pin_edge_arr=np.array([[0,0],[0,0]]).reshape(1,2,2)
self.center_arr=np.array([[0,0]])
for e in self.msp.query('LINE[layer=="Cut"]'):
length= sqrt((e.dxf.start[0]-e.dxf.end[0])**2+(e.dxf.start[1]-e.dxf.end[1])**2)
if length > pincutsize-tolerance and length < pincutsize + tolerance:
e.dxf.layer='Pin_temp'
if e.dxf.start[1]==e.dxf.end[1]: ##this line is horizontal
pin_edge=np.array([e.dxf.start,e.dxf.end])[:,:2]
pin_edge_arr=np.concatenate((pin_edge_arr,pin_edge.reshape(1,2,2)),axis=0)
pin_edge_arr=pin_edge_arr[1:]
# print(pin_edge_arr)
for i in range(len(pin_edge_arr)):
for e in np.delete(pin_edge_arr,i,axis=0):
if pin_edge_arr[i][0,1]-e[0,1]==1.0:
center_x=pin_edge_arr[i][0,0]-0.5
center_y=pin_edge_arr[i][0,1]-0.5
center=np.array([center_x,center_y]).reshape(1,2)
self.center_arr=np.append(self.center_arr,center,axis=0)
self.center_arr=np.unique(self.center_arr,axis=0)
self.center_arr=self.center_arr[1:]
# print(self.center_arr)
def remove_wheels(self):
#no need to call this function for other design
for e in self.msp.query('Arc LINE[layer=="Cut"]'):
if e.dxf.start[0]>=179:
self.msp.delete_entity(e)
def draw_on_pin(self,fulllength): #isolation
iso=self.dwg.blocks.new(name='ISO_BLK')
isolength=fulllength/2
trace_w=0.8
iso.add_line((-isolength,isolength),(isolength,isolength),dxfattribs={'linetype':'DASHDOT'})
iso.add_line((-isolength,-isolength),(isolength,-isolength),dxfattribs={'linetype':'DASHDOT'})
iso.add_line((-isolength,-isolength),(-isolength,isolength),dxfattribs={'linetype':'DASHDOT'})
iso.add_line((isolength,-isolength),(isolength,isolength),dxfattribs={'linetype':'DASHDOT'})
iso.add_line((-isolength,-trace_w/2),(-(isolength+5),-trace_w/2),dxfattribs={'linetype':'DASHDOT'})
iso.add_line((-isolength,trace_w/2),(-(isolength+5),trace_w/2),dxfattribs={'linetype':'DASHDOT'})
for center_point in self.center_arr:
self.msp.add_blockref('ISO_BLK',center_point,dxfattribs={'layer':'Circuit'})
def read_dxf_as_matrix(self):
"""unit: mm
accuracy issue expected atm (mm round up)
"""
self.matrix=np.ones(self.matrix_shape)
for line in self.msp.query('LINE[layer!="Fold" & layer!="Label" & layer!="Pin_temp"]'):
start=np.rint(line.dxf.start)
end=np.rint(line.dxf.end)
i=int(start[0])
j=int(start[1])
#can draw horizontal or vertical lines only
if j==end[1]: #this line is a horizontal line
self.matrix[j,i]=0
while i!=end[0]:
if i<end[0]:
i+=1
else:
i-=1
self.matrix[j,i]=0
elif i==end[0]: #this line is a vertical line
self.matrix[j,i]=0
while j!=end[1]:
if j<end[1]:
j+=1
else:
j-=1
self.matrix[j,i]=0
def find_a_path(self,matrixws,start_point,end_point):
"""
find a path between two points on img=matrix
start_point and end_point shape: (2,)
"""
#DEBUG:
# if not np.array_equal(matrixws,self.matrix):
# print('Map updated')
grid = Grid(matrix=matrixws)
start=grid.node(int(start_point[0]),int(start_point[1]))
end=grid.node(int(end_point[0]),int(end_point[1]))
finder = AStarFinder(diagonal_movement=4)
path, runs = finder.find_path(start, end, grid)
return path
def draw_a_path(self,path,matrix,dxf=False):
""" draw a path on img=matrix, or on dxf file too"""
#draw on matrix:
for point in path:
matrix[point[1],point[0]]=0
#draw on dxf:
if dxf:
for i in range(len(path)-1):
self.msp.add_line(path[i],path[i+1],dxfattribs={
'layer':'Circuit',
'linetype':'DASHDOT'})
def get_cost(self,path):
if len(path)==0: #if no path found
print('one path not found')
self.fail_flag=True
cost=1000
else: cost=len(path)
return cost
def find_multi_path(self,i):
"""connection list shape : NX2X2 """
E=20
print("==========Auto rounting start===========")
for episode in range(E):
print 'episode:',episode+1,'(/',E,')==========='
self.matrix_temp=copy.deepcopy(self.matrix)
self.Q=0
self.fail_flag=False
random_ix=random.randint(0,len(self.connections_list)-1)
init_s=self.connections_list[random_ix]
current_solving=np.array([init_s]).reshape(1,2,2)
con_list_temp=np.delete(self.connections_list,random_ix,axis=0)
cur_path=self.find_a_path(self.matrix_temp,init_s[0],init_s[1])
self.draw_a_path(cur_path,self.matrix_temp)
# self.img.set_array(self.matrix_temp)
cost=self.get_cost(cur_path)
self.Q=self.Q+cost
curpath_temp=[cur_path]
while len(con_list_temp)!=0:
random_ix=random.randint(0,len(con_list_temp)-1)
next_conn=con_list_temp[random_ix]
current_solving=np.append(current_solving,next_conn.reshape(1,2,2),axis=0)
con_list_temp=np.delete(con_list_temp,random_ix,axis=0)
curpath=self.find_a_path(self.matrix_temp,next_conn[0],next_conn[1])
self.draw_a_path(curpath,self.matrix_temp)
curpath_temp.append(curpath)
# self.img.set_array(self.matrix_temp)
cost=self.get_cost(curpath)
self.Q=self.Q+cost
if episode==0:
self.Q_buff=copy.deepcopy(self.Q)
if self.Q<=self.Q_buff:
self.Q_buff=copy.deepcopy(self.Q)
self.final_solving=current_solving
self.final_path=curpath_temp
self.final_fail=self.fail_flag
print 'Current cost:',self.Q,'Best cost',self.Q_buff
episode+=1
if not self.final_fail:
for i in range(len(self.final_path)):
self.draw_a_path(self.final_path[i],self.matrix,True)
else:
print 'One or more path cannot be solved'
def test_connections(self):
y=97
x=90
arti_pin_array=np.empty((1,2))
center_pin_conn=np.empty((1,2))
pin_conn=np.empty((1,2,2))
for i in range(10):
arti_pin=(x+i,y)
arti_pin_array=np.append(arti_pin_array,[arti_pin],axis=0)
arti_pin_array=arti_pin_array[1:]
for i in range(len(self.center_arr)):
if self.center_arr[i][1]<60:
center_pin_conn=np.append(center_pin_conn,self.center_arr[i].reshape(1,2),axis=0)
if len(center_pin_conn)>10: break
center_pin_conn=center_pin_conn[1:]
for i in range(10):
pin_conn_temp=np.array([arti_pin_array[i],center_pin_conn[i]]).reshape(1,2,2)
pin_conn=np.append(pin_conn,pin_conn_temp,axis=0)
pin_conn=pin_conn[1:]
return pin_conn
# def main():
path='/home/jingyan/Documents/summer_intern_lemur/roco_electrical/'
dxf_file='graph-silhouette.dxf'
router=auto_rounter(path,dxf_file)
# animation.FuncAnimation(edit.fig,plt.imshow(edit.matrix_temp))
# plt.show()
# if __name__ == '__main__':
# main()
This diff is collapsed.