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 (37)
Showing
with 20571 additions and 8052 deletions
*.erc
*.log
**/libraries
\ No newline at end of file
**/libraries
**/research_log
\ No newline at end of file
File added
File added
File added
File added
File added
File added
File added
This diff is collapsed.
This diff is collapsed.
(session paperbot_ee.ses
(base_design paperbot_ee.dsn)
(placement
(resolution um 10)
(component J1
(place J1 1150000 910000 front 270)
)
(component U1
(place U1 1040000 461000 front 90)
)
(component T1
(place T1 870000 900000 front 0)
)
(component L1
(place L1 670000 410000 front 90)
)
(component R1
(place R1 720000 410000 front 270)
)
)
(was_is
)
(routes
(resolution um 10)
(parser
(host_cad "KiCad's Pcbnew")
(host_version "5.1.3-ffb9f22~84~ubuntu18.04.1")
)
(library_out
)
(network_out
(net 3v3
(wire
(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 788103
889067 769037
)
)
(wire
(path F.Cu 15238
1208927 581620
1205100 577793
1205100 575300
)
)
(wire
(path F.Cu 15238
1251600 973500
1251600 929529
)
)
)
(net GND
(wire
(path F.Cu 20000
897207 826443
824970 826443
670000 671473
670000 435400
)
)
(wire
(path F.Cu 20000
897207 826443
1104527 826443
1226200 948116
)
)
(wire
(path F.Cu 20000
897207 816057
897207 826443
)
)
(wire
(path F.Cu 15238
895400 798400
897207 800207
897207 816057
)
)
(wire
(path F.Cu 15238
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
1001900 549916
1001900 575300
)
)
)
(net NET1
(wire
(path F.Cu 20000
837017 790817
825375 790817
720000 685442
720000 422700
)
)
(wire
(path F.Cu 15238
844600 798400
837017 790817
)
)
)
(net NET2
(wire
(path F.Cu 20000
720000 384600
682700 384600
670000 397300
)
)
)
(net SCL
(wire
(path F.Cu 20000
1200800 988622
1213751 1001573
1262669 1001573
1279703 984539
1279703 610226
1216911 547434
1055182 547434
1052700 549916
)
)
(wire
(path F.Cu 15238
1052700 549916
1052700 575300
)
)
(wire
(path F.Cu 15238
1200800 988622
1200800 973500
)
)
)
(net SDA
(wire
(path F.Cu 20000
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
1175400 973500
1175400 990546
)
)
(wire
(path F.Cu 15238
1027300 575300
1027300 549505
)
)
)
)
)
)
\ No newline at end of file
#!/usr/bin/env python
#!/usr/bin/env python3
import numpy as np
import ezdxf
import random
from math import sqrt
import copy
class kicad_importer():
def __init__(self,path,dxf_file):
self.dwg=ezdxf.readfile(path+dxf_file)
class read_old_paperbot():
def __init__(self,dxf_file):
self.dwg=ezdxf.readfile(dxf_file)
self.msp=self.dwg.modelspace()
self.dxf_name='paperbot_kicad.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.create_layer('Pin_temp',6)
self.create_layer('Circuit_Cut',6)
self.create_layer('Circuit_Etc',8)
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()
# horizonal=[113.468,151.468]
# self.seprate_blocks(horizonal)
self.dwg.saveas(self.dxf_name)
self.center_arr=self.find_pin()
# cross_cut(self.msp,2,self.center_arr)
self.savename='dwg_w_layers.dxf'
self.dwg.saveas(self.savename)
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})
......@@ -49,14 +45,16 @@ class kicad_importer():
def find_pin(self):
tolerance=0.05 #mm
pincutsize=1 #mm
pincutsize_big=3 #mm
pincutsize_small=1 #mm
pin_edge_arr=np.array([[0,0],[0,0]]).reshape(1,2,2)
self.center_arr=np.array([[0,0]])
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 length > pincutsize_small-tolerance and length < pincutsize_big + tolerance:
# e.dxf.layer='Pin_temp'
self.msp.delete_entity(e) #08/13/2019 remove all pins in mechanical desing
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)
......@@ -69,29 +67,8 @@ class kicad_importer():
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 seprate_blocks(self,horizontal,vertical=[]):
# """
# horizontal: an array with each element representing horizontal internal cut(from small to large value )
# vertical: an array with each element representing vertical internal cut (from small to large value)
# this function moves every line above the horizonal coordinate/ on the right of vertical coordinate to make outlines a closed shape"""
# cut_thickness=0.1
# if len(horizontal)!=0:
# for axis in horizontal:
# for e in self.msp.query('*'):
# if e.dxf.start[1]>axis or e.dxf.end[1]>axis:
# e.dxf.start[1]+=cut_thickness
# e.dxf.end[1]+=cut_thickness
center_arr=np.append(center_arr,center,axis=0)
path='/home/jingyan/Documents/summer_intern_lemur/roco_electrical/'
dxf_file='graph-silhouette.dxf'
importer=kicad_importer(path,dxf_file)
\ No newline at end of file
center_arr=np.unique(center_arr,axis=0)
center_arr=center_arr[1:]
return center_arr
......@@ -3,26 +3,40 @@
# sys.path.insert(1,'/home/jingyan/Documents/summer_intern_lemur/roco_electrical/dsn_python')
import dsnwritier
import csv
class brd_design():
def __init__(self,dwgfile,boundary_inx,libpath,savename):
def __init__(self,boundary_inx,libpath,netlist_csv,savename='paperbot_ee',dwgfile='dwg_for_autorouter.dxf'):
print('generating board desng file (dsn) ......')
self.dwgfile=dwgfile
self.boundary_inx=boundary_inx
self.libpath=libpath
self.savename=savename
self.module_list=[
['mpu-9250.kicad_mod','J1',[103000,88000],270],
['ESP12F-Devkit-V3.kicad_mod','U1',[103000,48000],90],
['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],'front',0],
['LED_D3.0mm.kicad_mod','L1',[67000,41000],'front',90],
['Resistor.kicad_mod','R1',[72000,41000],'front',270],
]
self.netlist=[
['3v3',['U1-3','J1-1']],
['VIN',['U1-1']],
['NET1',['U1-2','J1-5']]
['3v3',['U1-16','J1-1','T1-2']],
['GND',['U1-24','J1-2','L1-2','T1-3']],
['NET1',['T1-1','R1-1']],
['NET2',['R1-2','L1-1']],
['SCL',['J1-3','U1-22']],
['SDA',['J1-4','U1-23']]
]
# self.netlist=[
# ['3v3',['U1-16','J1-1','T1-2']],
# ['GND',['U1-24','J1-2','L1-2','T1-3']],
# ]
self.netclass_list=[
['default',['3v3','VIN','NET1'],'',1000,200]
['default',['3v3','GND','NET1','NET2','SCL','SDA'],'',2000,500]
]
# self.module_list,self.netlist,self.netclass_list=self.read_from_csv(netlist_csv)
self.brd_general()
self.boundary,self.keepout=self.load_drawing()
......@@ -31,23 +45,24 @@ class brd_design():
self.net,self.netclass=self.create_net()
self.write_dsn()
self.get_pin_loc()
def brd_general(self):
self.brd=dsnwritier.Dsn()
self.layers=[
dsnwritier.Layer('F.Cu'),
dsnwritier.Layer('B.Cu'),
dsnwritier.Layer('F.Mask'),
dsnwritier.Layer('B.Mask')
dsnwritier.Layer('F.Cu')
# dsnwritier.Layer('B.Cu'),
# dsnwritier.Layer('F.Mask'),
# dsnwritier.Layer('B.Mask')
]
self.parsers= dsnwritier.Parser()
self.rule=dsnwritier.Rule()
clearance=[
dsnwritier.Clearance(200.1),
dsnwritier.Clearance(200.1,'default_smd'),
dsnwritier.Clearance(50,'smd_smd')]
dsnwritier.Clearance(1000.1),
dsnwritier.Clearance(1000.1,'default_smd'),
dsnwritier.Clearance(1000,'smd_smd')]
self.rule.clearance=clearance
......@@ -73,16 +88,21 @@ class brd_design():
"""
image=[]
for mod in self.module_list:
for i in range(len(self.module_list)):
mod=self.module_list[i]
img=dsnwritier.Footprint.from_file(self.libpath+mod[0],ref=mod[1])
image.append(img)
padstack=dsnwritier.Padstack.auto_detect(self.libpath+'mpu-9250.kicad_mod')
if i==0:
padstack=dsnwritier.Padstack.auto_detect(self.libpath+mod[0])
else:
padstack+=dsnwritier.Padstack.auto_detect(self.libpath+mod[0])
return image,padstack
def place_modules(self):
placement=[]
for mod in self.module_list:
place=dsnwritier.Placement(name=mod[0],ref1=mod[1],at=mod[2],orientation=mod[3])
place=dsnwritier.Placement(name=mod[0],ref1=mod[1],at=mod[2],flip=mod[3],orientation=mod[4])
placement.append(place)
return placement
def create_net(self):
......@@ -110,8 +130,86 @@ class brd_design():
self.brd.placement=self.placement
self.brd.net=self.net
self.brd.netclass=self.netclass
self.brd.to_file(self.savename)
print('dsn file generated.....')
def get_pin_loc(self):
from pykicad.module import Module as mod
import numpy as np
from math import sqrt
self.pins_at=[]
for img in self.module_list:
module=mod.from_file(self.libpath+img[0])
pin_at_arr=[]
module_at=np.array([img[2][0],img[2][1]])/1000
flip=1
orientation=img[4]
theta=orientation/180*np.pi
if img[3]=='back':
flip=-1
orientation=img[4]
for i in range(len(module.pads)):
pad=module.pads[i]
pin_at_relative=np.array(pad.at) ##mm
x,y=pin_at_relative[0]*flip,-pin_at_relative[1]
x_=x*np.cos(theta)-y*np.sin(theta)
y_=y*np.cos(theta)+x*np.sin(theta)
pin_at_relative=np.array([x_,y_])
pin_at_abs=list(pin_at_relative+module_at)
pin_at_arr.append(pin_at_abs)
self.pins_at.append(pin_at_arr)
def read_from_csv(self,csv_file):
with open(csv_file, mode='r') as csv_file:
csv_reader = csv.DictReader(csv_file, delimiter = ';')
myDict = list(csv_reader)
numOfRows = len(myDict)
keys = myDict[0].keys()
moduleCols = 4
netCols = 2
netclassCols = 5
moduleRows = 0
netRows = 0
netclassRows = 0
moduleHeaders = ['Module name','Ref','Position','Orientation']
netHeaders = ['Connection name','Pins']
netclassHeaders = ['Netclass','Net connections','Via name','Width','Clearance']
for x in range(numOfRows):
if myDict[x].get('Module name') != '' and myDict[x].get('Module name') != 'None':
moduleRows += 1
if myDict[x].get('Connection name') != '' and myDict[x].get('Connection name') != None:
netRows += 1
if myDict[x].get('Netclass') != '' and myDict[x].get('Netclass') != None:
netclassRows +=1
moduleList = [[0 for i in range(moduleCols)] for j in range(moduleRows)]
netList = [[0 for i in range(netCols)] for j in range(netRows)]
netclassList = [[0 for i in range(netclassCols)] for j in range(netclassRows)]
for x in range(moduleRows):
for y in range(moduleCols):
header = moduleHeaders[y]
moduleList[x][y] = myDict[x].get(header)
for x in range(netRows):
for y in range(netCols):
header = netHeaders[y]
netList[x][y] = myDict[x].get(header)
for x in range(netclassRows):
for y in range(netclassCols):
header = netclassHeaders[y]
netclassList[x][y] = myDict[x].get(header)
return moduleList,netList,netclassList
# libpath='/home/jingyan/Documents/summer_intern_lemur/roco_electrical/libraries/kicad-ESP8266/ESP8266.pretty/'
......
#!/usr/bin/env python3
def roco_add_ee(me_drawing,netlist_csv,module_libpath,dsnwritier_dir,
trace_width=2,iso_size=2,cross_size=0.66):
"""
This module call script 'roco_dsn.py' to generate a DSN file for auto_router.
An interface will pop up for the user to confirm wiring design,
if a user does not want to change anything, one can just simply close the window.
Routing information will be stored automatically in the same directory.
The routing information will be read and draw the corresponding line on the dxf file
(Please make sure the ME drawing has everything need to cut (obstacles) in "Cut" layer)
Tested Python Version: 3.6
path information needed:
- mechanical design drawing file
- A csv file describes your netlist
- modules library dir
- dsnwritier(sesreader) dir
"""
##########general lib############
import sys
import subprocess
import os
sys.path.insert(1,dsnwritier_dir)
from sesreader import find_wire
from roco_dsn import brd_design
from ee_dwg_processing import pre_process, post_process
ready_for_autorouter=pre_process(me_drawing) #get dwg_for_autorouter.dxf
ee_design=brd_design(ready_for_autorouter.bry_ind,module_libpath,netlist_csv)#,dwgfile='dwg_for_autorouter_temp.dxf') #get paperbot_ee.dsn
subprocess.call(['java','-jar','freeRouting.jar','-de',ee_design.savename+'.dsn','-white','-s'])
wiring_path=find_wire(ee_design.savename,ee_design.pins_at) #read ses file
post_process(me_drawing,wiring_path,ee_design.pins_at,trace_width,iso_size,cross_size) # draw for fabrication
os.remove(ready_for_autorouter.savename)
os.remove(ee_design.savename+'.dsn')
# os.remove(ee_design.savename+'.ses')
os.remove(ee_design.savename+'.rules')
def test():
from read_old_paperbot import read_old_paperbot
dsnwritier_dir='/home/jingyan/Documents/summer_intern_lemur/roco_electrical/dsn_python'
module_libpath='/home/jingyan/Documents/summer_intern_lemur/roco_electrical/libraries/kicad-ESP8266/ESP8266.pretty/'
dwg_path='/home/jingyan/Documents/summer_intern_lemur/roco_electrical/graph-silhouette.dxf'
net_csv='/home/jingyan/Downloads/moduleList.csv'
old=read_old_paperbot(dwg_path) #get dwg_w_layer.dxf
me_dwg=old.savename
roco_add_ee(me_dwg,net_csv,module_libpath,dsnwritier_dir)
test()
\ No newline at end of file
This diff is collapsed.
File deleted