Skip to content

Commit

Permalink
tests complete still bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
swissembedded committed Jun 2, 2019
1 parent bf38543 commit 88f673d
Show file tree
Hide file tree
Showing 4 changed files with 86 additions and 29 deletions.
13 changes: 12 additions & 1 deletion app/excellon.py
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ def set_panel_reference_1(panel,index,x,y,z):
panel[index]['RefY1']=y
panel[index]['RefZ1']=z

# get panel reference point 1
# get panel reference point 2
def get_panel_reference_2(panel,index):
return panel[index]['RefX2'], panel[index]['RefY2'], panel[index]['RefZ2']

Expand All @@ -275,3 +275,14 @@ def set_panel_reference_2(panel,index,x,y,z):
panel[index]['RefX2']=x
panel[index]['RefY2']=y
panel[index]['RefZ2']=z

# get list of soldering profile
def get_list_soldering_profile(solderingprofile):
profile=[]
for p, elem in enumerate(solderingprofile['SolderingProfile']):
profile.append(solderingprofile['SolderingProfile'][p]['Id'])
return profile

# get item of soldering profile
def get_soldering_profile(solderingprofile, index):
return solderingprofile['SolderingProfile'][index]
57 changes: 33 additions & 24 deletions app/robotcontrol.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,19 @@
# https://reprap.org/wiki/G-code

# Fill in parameters into template g-code
import string
import math
from numpy import (array, dot, arccos, clip, subtract, arcsin, arccos)
from numpy.linalg import norm
import excellon



def complete_template(template, parameters):
gcode=template.copy()
for p, elem in enumerate(parameters):
parameter=parameters[p]
gcode.replace("%"+parameter.keys()[0], str(parameter.values()[0]))
gcode=template
for key,value in parameters.items():
token="%"+key
gcode=gcode.replace(token,str(value))
return gcode

# coordinate transformation
Expand All @@ -42,18 +45,18 @@ def get_printer_point(point, radians, scale, origin=(0, 0), translation=(0,0)):

def panel_soldering(data, panelSelection, isTest):
# header
parameters={ "TravelX" : round(data['Setup']['TravelX'],5),
"TravelY" : round(data['Setup']['TravelY'],5),
"TravelZ" : round(data['Setup']['TravelZ'],5)}
parameters={ "TravelX" : round(data['Setup']['TravelX'],2),
"TravelY" : round(data['Setup']['TravelY'],2),
"TravelZ" : round(data['Setup']['TravelZ'],2)}
gcode = complete_template(data['GHeader'],parameters)
# soldering backside?
if data('SolderSide')=="Top":
if data['SolderSide']=="Top":
flip=1
else:
flip=-1
# for each selected panel soldering
for p, elem in enumerate(panelSelection):
panel=data['Panel'][p]
panel=data['Panel'][panelSelection[p]]
# get panel data
# teached panel coordinates
xp1=panel['RefX1']
Expand All @@ -62,6 +65,9 @@ def panel_soldering(data, panelSelection, isTest):
xp2=panel['RefX2']
yp2=panel['RefY2']
zp2=panel['RefZ2']
if xp1==-1 or xp2==-1 or yp1==-1 or yp2==-1 or zp1==-1 or zp2==-1:
print("error missing reference, skipping panel",p)
continue
zp=(zp1+zp2)/2.0
# solder toolpath
soldertoolpath=data['SolderToolpath']
Expand All @@ -86,36 +92,39 @@ def panel_soldering(data, panelSelection, isTest):
radians = arccos(c)
scale = vplen / vnlen
# iterate over each solder point in the toolpath
for s in range(get_number_solderpoints(soldertoolpath)):
stp=get_solderpoint(s)
for s in range(excellon.get_number_solderpoints(soldertoolpath)):
stp=soldertoolpath[excellon.get_solderpoint(soldertoolpath,s)]
xn=stp['NCPositionX']*flip
yn=stp['NCPositionY']
vn=array[xn, yn]
sp=data['SolderingProfile'][stp['SolderingProfile']]
vn=array([xn, yn])
xp, yp = get_printer_point(vn, -radians, scale, vn1, vp1)
sp=excellon.get_soldering_profile(data['SolderingProfile'],stp['SolderingProfile'])
# create parameterlist
parameters={
"TravelZ" : round(sp['TravelZ'],5),
"ApproxX" : round(xp-sp['ApproxOffsetX'],5),
"ApproxY" : round(yp-sp['ApproxOffsetY'],5),
"ApproxZ" : round(zp-sp['ApproxOffsetZ'],5),
"SolderX" : round(xp-sp['SolderOffsetX'],5),
"SolderY" :round(yp-sp['SolderOffsetY'],5),
"SolderZ" : round(zp-sp['SolderOffsetZ'],5),
"TravelZ" : round(sp['TravelZ'],2),
"ApproxX" : round(xp-sp['ApproxOffsetX'],2),
"ApproxY" : round(yp-sp['ApproxOffsetY'],2),
"ApproxZ" : round(zp-sp['ApproxOffsetZ'],2),
"SolderX" : round(xp-sp['SolderOffsetX'],2),
"SolderY" :round(yp-sp['SolderOffsetY'],2),
"SolderZ" : round(zp-sp['SolderOffsetZ'],2),
"Heatup" : sp['Heatup'],
"SolderLength" : sp['SolderLength'],
"Melting" : sp['Melting'] }
if isTest:
gpos = complete_template(data['GSoldertest'], parameters)
else:
gpos = complete_template(data['GSolder'], parameters)
g_code+=gpos
gcode = complete_template(data['GFooter'], {})
gcode+=gpos
gcode += complete_template(data['GFooter'], {})
return gcode

def go_xyz(data, x,y,z):
parameters = { "CoordX": x, "CoordY" : y, "CoordZ" : z }
gcode = complete_template(gpos, data['GGo'], parameters)
parameters = {
"CoordX": round(x,2),
"CoordY" : round(y,2),
"CoordZ" : round(z,2) }
gcode = complete_template(data['GGo'], parameters)
return gcode

def go_home(data):
Expand Down
2 changes: 1 addition & 1 deletion app/solderingprofile.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@
{ "Id": "USB Signals", "SolderOffsetX" : 0.5, "SolderOffsetY" : 0.0, "SolderOffsetZ" : 0.0, "ApproxOffsetX": 1.0, "ApproxOffsetY": 0.0, "ApproxOffsetZ": -2.0, "TravelZ": 50, "Heatup":2000, "SolderLength" : 1.5, "Melting": 2000 },
{ "Id": "USB Mounts", "SolderOffsetX" : 1.8, "SolderOffsetY" : 0.0, "SolderOffsetZ" : 0.0, "ApproxOffsetX": 2.2, "ApproxOffsetY": 0.0, "ApproxOffsetZ": -2.5, "TravelZ": 50, "Heatup":3000, "SolderLength" : 15.0, "Melting": 3000 }
]
}
}
43 changes: 40 additions & 3 deletions app/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,44 @@
else:
print("nok panel ref 2", x2, y2, z2)

# create g-code for soldering
# soldering profile list for gui selection
solderingprofile=prjdata['SolderingProfile']
list=excellon.get_list_soldering_profile(solderingprofile)
if len(list)==len(solderingprofile['SolderingProfile']):
print("ok soldering profile list")
else:
print("nok soldering profile list", len(list), len(solderingprofile), solderingprofile['SolderingProfile'])
# soldering profile first entry
firstprofile=excellon.get_soldering_profile(solderingprofile,0)
if firstprofile==solderingprofile['SolderingProfile'][0]:
print("ok sodering profile")
else:
print("nok soldering profile")

# make array out of gcode
garray=robotcontrol.make_array("1\n2\n3\n")
if len(garray) == 3:
print("ok gcode array")
else:
print("nok gcode array")

# create g-code for home
# create g-code for go xyz
# convert g-code to array
#go_xyz(prjdata, x,y,z)
gcode=robotcontrol.go_xyz(prjdata, 1,2,3)
if "G1 X1 Y2 Z3" in gcode:
print("ok go xyz")
else:
print("nok goxyz", gcode)

#go_home(prjdata)
gcode=robotcontrol.go_home(prjdata)
if "G28" in gcode and "G90" in gcode:
print("ok home")
else:
print("nok home", gcode)

# create g-code for soldering
prjdata['Panel']=panel
prjdata['SolderToolpath']=soldertoolpath
gcode=robotcontrol.panel_soldering(prjdata, [0], False)
print("soldering", gcode)

0 comments on commit 88f673d

Please sign in to comment.