First Z adjust tests. The path of the drill is represented in real time.

pull/6/head
carlosgs 2013-05-29 23:35:02 +02:00
parent 6375fbcab0
commit 75cde8c2fc
12 changed files with 41205 additions and 40908 deletions

View File

@ -36,7 +36,7 @@ import serial
import time import time
from datetime import datetime from datetime import datetime
import helper from helper import *
# End modules # End modules
# Begin configuration. It is overwritten when running setup(baudrate, device) # Begin configuration. It is overwritten when running setup(baudrate, device)
@ -49,7 +49,10 @@ serial_timeout = 5 # Timeout for the serial port [seconds]
OK_response = "ok" # First two characters of an OK response (case insensitive) OK_response = "ok" # First two characters of an OK response (case insensitive)
CNC_Machine = []
def connect(baudrate, device): def connect(baudrate, device):
global CNC_Machine
BAUDRATE = baudrate BAUDRATE = baudrate
DEVICE = device DEVICE = device
print "Connecting to Cyclone..." print "Connecting to Cyclone..."
@ -69,14 +72,12 @@ def flushRecvBuffer(): # We could also use flushInput(), but showing the data th
def sendLine(line): def sendLine(line):
flushRecvBuffer() flushRecvBuffer()
CNC_Machine.write(line) CNC_Machine.write(line)
print "SENT: ", line #print "SENT: ", line
def recvLine(): def recvLine():
response = CNC_Machine.readline() response = CNC_Machine.readline()
if response != '': #if response != '': print "RECV: ", response
print "RECV: ", response #else: print "RECV: Receive timed out!"
else:
print "RECV: Receive timed out!"
return response return response
def recvOK(): def recvOK():
@ -86,9 +87,9 @@ def recvOK():
return 0 return 0
def waitForOK(): # This is a blocking function def waitForOK(): # This is a blocking function
print "Waiting for confirmation" #print "Waiting for confirmation"
while recvOK() != 1: while recvOK() != 1:
print " Checking again..." #print " Checking again..."
time.sleep(millis_wait) # Wait some milliseconds between attempts time.sleep(millis_wait) # Wait some milliseconds between attempts
def sendCommand(command): # Send command and wait for OK def sendCommand(command): # Send command and wait for OK
@ -109,28 +110,28 @@ def homeZXY():
sendCommand("G28 X0\n") # move X to min endstop sendCommand("G28 X0\n") # move X to min endstop
sendCommand("G28 Y0\n") # move Y to min endstop sendCommand("G28 Y0\n") # move Y to min endstop
def move(X, Y, Z, F): def moveXYZ(X, Y, Z, F):
print "Moving to:" #print "Moving to:"
sendCommand("G1 X"+floats(X)+" Y"+floats(Y)+" Z"+floats(Z)+" F"+floats(F)+"\n") sendCommand("G1 X"+floats(X)+" Y"+floats(Y)+" Z"+floats(Z)+" F"+floats(F)+"\n")
def moveXY(X, Y, F): def moveXY(X, Y, F):
print "Moving to:" #print "Moving to:"
sendCommand("G1 X"+floats(X)+" Y"+floats(Y)+" F"+floats(F)+"\n") sendCommand("G1 X"+floats(X)+" Y"+floats(Y)+" F"+floats(F)+"\n")
def moveZ(Z, F): def moveZ(Z, F):
print "Moving Z absolute:" #print "Moving Z absolute:"
sendCommand("G1 Z"+floats(Z)+" F"+floats(F)+"\n") sendCommand("G1 Z"+floats(Z)+" F"+floats(F)+"\n")
def moveZrel(Z, F): def moveZrel(Z, F):
print "Moving Z relative:" #print "Moving Z relative:"
sendCommand("G91\n") # Set relative positioning sendCommand("G91\n") # Set relative positioning
sendCommand("G1 Z"+floats(Z)+" F"+floats(F)+"\n") sendCommand("G1 Z"+floats(Z)+" F"+floats(F)+"\n")
sendCommand("G90\n") # Set absolute positioning sendCommand("G90\n") # Set absolute positioning
def moveZrelSafe(Z, F): def moveZrelSafe(Z, F):
cy.sendCommand("M121\n") # Enable endstops (for protection! usually it should **NOT** hit neither the endstop nor the PCB) sendCommand("M121\n") # Enable endstops (for protection! usually it should **NOT** hit neither the endstop nor the PCB)
moveZrel(Z, F) moveZrel(Z, F)
cy.sendCommand("M120\n") # Disable endstops (we only use them for homing) sendCommand("M120\n") # Disable endstops (we only use them for homing)
def probeZ(): def probeZ():
print "Probing Z" print "Probing Z"
@ -164,16 +165,19 @@ def probeGrid(grid_origin, grid_len, grid_N, Zlift):
Z_probing_lift = float(Zlift) # lift between Z probings [mm] Z_probing_lift = float(Zlift) # lift between Z probings [mm]
F_fastMove = 400
F_slowMove = 100
grid_inc_X = grid_len_X/float(grid_N_X-1) # [mm] grid_inc_X = grid_len_X/float(grid_N_X-1) # [mm]
grid_inc_Y = grid_len_Y/float(grid_N_Y-1) grid_inc_Y = grid_len_Y/float(grid_N_Y-1)
x_points = [ float(x_i)*grid_inc_X + grid_origin_X for x_i in range(grid_N_X) ] # Calculate X coordinates x_points = [ float(x_i)*grid_inc_X + grid_origin_X for x_i in range(grid_N_X) ] # Calculate X coordinates
y_points = [ float(y_i)*grid_inc_Y + grid_origin_Y for y_i in range(grid_N_Y) ] # Calculate X coordinates y_points = [ float(y_i)*grid_inc_Y + grid_origin_Y for y_i in range(grid_N_Y) ] # Calculate X coordinates
probe_result = [ [ 0 for j in range(grid_N_Y) ] for i in range(grid_N_X) ] probe_result = [ [ 0 for j in range(grid_N_X) ] for i in range(grid_N_Y) ]
# Show our grid (initialised as zeros) # Show our grid (initialised as zeros)
for row in probe_grid: for row in probe_result:
print row print row
print "Probing begins!" print "Probing begins!"
@ -181,7 +185,7 @@ def probeGrid(grid_origin, grid_len, grid_N, Zlift):
beginTime = datetime.now() # Store current time in a variable, will be used to measure duration of the probing beginTime = datetime.now() # Store current time in a variable, will be used to measure duration of the probing
# Move to grid's origin # Move to grid's origin
machineToCoordsXY(grid_origin_X, grid_origin_Y, F_fastMove) moveXY(grid_origin_X, grid_origin_Y, F_fastMove)
for x_i in range(grid_N_X): # For each point on the grid... for x_i in range(grid_N_X): # For each point on the grid...
x_val = float(x_i)*grid_inc_X + grid_origin_X; # Calculate X coordinate x_val = float(x_i)*grid_inc_X + grid_origin_X; # Calculate X coordinate
@ -190,18 +194,18 @@ def probeGrid(grid_origin, grid_len, grid_N, Zlift):
optimal_range = reversed(optimal_range) optimal_range = reversed(optimal_range)
for y_i in optimal_range: for y_i in optimal_range:
y_val = float(y_i)*grid_inc_Y + grid_origin_Y; # Calculate Y coordinate y_val = float(y_i)*grid_inc_Y + grid_origin_Y; # Calculate Y coordinate
machineToCoordsXY(x_val, y_val, F_fastMove) # Move to position moveXY(x_val, y_val, F_fastMove) # Move to position
probe_result[x_i][y_i] = machineProbeZ() # Do the Z probing probe_result[y_i][x_i] = probeZ() # Do the Z probing
machineToCoordsZrelative(Z_probing_lift, F_fastMove/2) # Lift the probe moveZrel(Z_probing_lift, F_fastMove/2) # Lift the probe
# Once we have all the points, we set the origin as (0,0) and offset the rest of values # Once we have all the points, we set the origin as (0,0) and offset the rest of values
Z_offset = probe_grid[0][0] Z_offset = probe_result[0][0]
print "The origin Z height is", Z_offset print "The origin Z height is", Z_offset
probe_grid = [[elem - Z_offset for elem in row] for row in probe_grid] probe_result = [[elem - Z_offset for elem in row] for row in probe_result]
# Return to the grid's origin # Return to the grid's origin
machineToCoordsZrelative(10, F_slowMove) # Lift Z moveZrel(10, F_slowMove) # Lift Z
machineToCoordsXY(grid_origin_X, grid_origin_Y, F_fastMove) # Move to grid's origin moveXY(grid_origin_X, grid_origin_Y, F_fastMove) # Move to grid's origin
duration = datetime.now() - beginTime duration = datetime.now() - beginTime
print "Probing duration:", str(duration) print "Probing duration:", str(duration)
@ -209,3 +213,6 @@ def probeGrid(grid_origin, grid_len, grid_N, Zlift):
return (x_points, y_points, probe_result, Z_offset, duration_s) return (x_points, y_points, probe_result, Z_offset, duration_s)

View File

@ -31,12 +31,17 @@ def plotPath(etch_moves, travel_moves, etch_color, travel_color, etch_diam, trav
plotPoints(etch_moves, etch_color, etch_diam) plotPoints(etch_moves, etch_color, etch_diam)
plotPoints(travel_moves, travel_color, travel_diam) plotPoints(travel_moves, travel_color, travel_diam)
def view(filePath,fileName): def pltShowNonBlocking():
plt.ion() # Enable real-time plotting to avoid blocking behaviour for plt.show()
plt.show()
plt.ioff() # Disable real-time plotting
def view(filePath,fileName,showAll=0,showEtch=0,showEtch2=0,showEtch3=0,showDrill=0,showEdge=0):
#filePath = "../GcodeGenerators/pyGerber2Gcode_CUI/out/" #filePath = "../GcodeGenerators/pyGerber2Gcode_CUI/out/"
#fileName = "printshield" # sys.argv[1] #fileName = "printshield" # sys.argv[1]
plt.figure() fig = plt.figure()
drill_diam = 0.8 drill_diam = 0.8
etch_diam = 0.1 etch_diam = 0.1
@ -65,38 +70,42 @@ def view(filePath,fileName):
plt.title("Gcode viewer") plt.title("Gcode viewer")
plt.axis('equal') # 1:1 aspect ratio plt.axis('equal') # 1:1 aspect ratio
print "\n Loading etch..." if showAll or showEtch:
gcode_file = filePath+fileName+"_etch.gcode" print "\n Loading etch..."
(etch_moves, travel_moves, gcode_originXY, grid_sizeXY) = gcp.parseGcodeRaw(gcode_file) gcode_file = filePath+fileName+"_etch.gcode"
(etch_moves, travel_moves) = gcp.optimize(etch_moves) (etch_moves, travel_moves, gcode_originXY, grid_sizeXY) = gcp.parseGcodeRaw(gcode_file)
plotPath(etch_moves, travel_moves, etch_color, travel_color, etch_diam, travel_diam) (etch_moves, travel_moves) = gcp.optimize(etch_moves)
plotPath(etch_moves, travel_moves, etch_color, travel_color, etch_diam, travel_diam)
print "\n Loading etch (2nd pass)..." if showAll or showEtch2:
gcode_file = filePath+fileName+"_etch2pass.gcode" print "\n Loading etch (2nd pass)..."
(etch_moves, travel_moves, gcode_originXY, grid_sizeXY) = gcp.parseGcodeRaw(gcode_file) gcode_file = filePath+fileName+"_etch2pass.gcode"
(etch_moves, travel_moves) = gcp.optimize(etch_moves) (etch_moves, travel_moves, gcode_originXY, grid_sizeXY) = gcp.parseGcodeRaw(gcode_file)
plotPath(etch_moves, travel_moves, etch2pass_color, travel_color, etch2pass_diam, travel_diam) (etch_moves, travel_moves) = gcp.optimize(etch_moves)
plotPath(etch_moves, travel_moves, etch2pass_color, travel_color, etch2pass_diam, travel_diam)
print "\n Loading etch (3nd pass)..." if showAll or showEtch3:
gcode_file = filePath+fileName+"_etch3pass.gcode" print "\n Loading etch (3nd pass)..."
(etch_moves, travel_moves, gcode_originXY, grid_sizeXY) = gcp.parseGcodeRaw(gcode_file) gcode_file = filePath+fileName+"_etch3pass.gcode"
(etch_moves, travel_moves) = gcp.optimize(etch_moves) (etch_moves, travel_moves, gcode_originXY, grid_sizeXY) = gcp.parseGcodeRaw(gcode_file)
plotPath(etch_moves, travel_moves, etch3pass_color, travel_color, etch3pass_diam, travel_diam) (etch_moves, travel_moves) = gcp.optimize(etch_moves)
plotPath(etch_moves, travel_moves, etch3pass_color, travel_color, etch3pass_diam, travel_diam)
print "\n Loading drill..." if showAll or showDrill:
gcode_file = filePath+fileName+"_drill.gcode" print "\n Loading drill..."
(etch_moves, travel_moves, gcode_originXY, grid_sizeXY) = gcp.parseGcodeRaw(gcode_file) gcode_file = filePath+fileName+"_drill.gcode"
(etch_moves, travel_moves) = gcp.optimize(etch_moves) (etch_moves, travel_moves, gcode_originXY, grid_sizeXY) = gcp.parseGcodeRaw(gcode_file)
plotPath(etch_moves, travel_moves, drill_color, travel_color, drill_diam, travel_diam) (etch_moves, travel_moves) = gcp.optimize(etch_moves)
plotPath(etch_moves, travel_moves, drill_color, travel_color, drill_diam, travel_diam)
print "\n Loading edge..." if showAll or showEdge:
gcode_file = filePath+fileName+"_edge.gcode" print "\n Loading edge..."
(etch_moves, travel_moves, gcode_originXY, grid_sizeXY) = gcp.parseGcodeRaw(gcode_file) gcode_file = filePath+fileName+"_edge.gcode"
(etch_moves, travel_moves) = gcp.optimize(etch_moves) (etch_moves, travel_moves, gcode_originXY, grid_sizeXY) = gcp.parseGcodeRaw(gcode_file)
plotPath(etch_moves, travel_moves, edge_color, travel_color, edge_diam, travel_diam) (etch_moves, travel_moves) = gcp.optimize(etch_moves)
plotPath(etch_moves, travel_moves, edge_color, travel_color, edge_diam, travel_diam)
plt.ion() # Enable real-time plotting to avoid blocking behaviour for pyplot pltShowNonBlocking()
plt.show()
return plt return (etch_moves, travel_moves, fig)

View File

@ -1,59 +1,59 @@
(Generated by ./pygerber2gcode_cui_MOD.py ) (Generated by ./pygerber2gcode_cui_MOD.py )
( 2013-05-29 17:29:04 ) ( 2013-05-29 19:50:34 )
(Initialize) (Initialize)
(Start form here) (Start form here)
G0 Z2.000000 G0 Z2.000000
G0 X59.163215 Y58.401215 G0 X69.163215 Y58.401215
G1 Z-0.271429 F30.000000 G1 Z-0.271429 F30.000000
G1 X3.029215 F50.000000 G1 X13.029215 F50.000000
G1 Y4.553215 F50.000000 G1 Y4.553215 F50.000000
G1 Y4.299215 F50.000000 G1 Y4.299215 F50.000000
G1 X60.433215 F50.000000 G1 X70.433215 F50.000000
G1 Y58.401215 F50.000000 G1 Y58.401215 F50.000000
G1 X59.163215 F50.000000 G1 X69.163215 F50.000000
G1 Z-0.542857 F30.000000 G1 Z-0.542857 F30.000000
G1 X3.029215 F50.000000 G1 X13.029215 F50.000000
G1 Y4.553215 F50.000000 G1 Y4.553215 F50.000000
G1 Y4.299215 F50.000000 G1 Y4.299215 F50.000000
G1 X60.433215 F50.000000 G1 X70.433215 F50.000000
G1 Y58.401215 F50.000000 G1 Y58.401215 F50.000000
G1 X59.163215 F50.000000 G1 X69.163215 F50.000000
G1 Z-0.814286 F30.000000 G1 Z-0.814286 F30.000000
G1 X3.029215 F50.000000 G1 X13.029215 F50.000000
G1 Y4.553215 F50.000000 G1 Y4.553215 F50.000000
G1 Y4.299215 F50.000000 G1 Y4.299215 F50.000000
G1 X60.433215 F50.000000 G1 X70.433215 F50.000000
G1 Y58.401215 F50.000000 G1 Y58.401215 F50.000000
G1 X59.163215 F50.000000 G1 X69.163215 F50.000000
G1 Z-1.085714 F30.000000 G1 Z-1.085714 F30.000000
G1 X3.029215 F50.000000 G1 X13.029215 F50.000000
G1 Y4.553215 F50.000000 G1 Y4.553215 F50.000000
G1 Y4.299215 F50.000000 G1 Y4.299215 F50.000000
G1 X60.433215 F50.000000 G1 X70.433215 F50.000000
G1 Y58.401215 F50.000000 G1 Y58.401215 F50.000000
G1 X59.163215 F50.000000 G1 X69.163215 F50.000000
G1 Z-1.357143 F30.000000 G1 Z-1.357143 F30.000000
G1 X3.029215 F50.000000 G1 X13.029215 F50.000000
G1 Y4.553215 F50.000000 G1 Y4.553215 F50.000000
G1 Y4.299215 F50.000000 G1 Y4.299215 F50.000000
G1 X60.433215 F50.000000 G1 X70.433215 F50.000000
G1 Y58.401215 F50.000000 G1 Y58.401215 F50.000000
G1 X59.163215 F50.000000 G1 X69.163215 F50.000000
G1 Z-1.628571 F30.000000 G1 Z-1.628571 F30.000000
G1 X3.029215 F50.000000 G1 X13.029215 F50.000000
G1 Y4.553215 F50.000000 G1 Y4.553215 F50.000000
G1 Y4.299215 F50.000000 G1 Y4.299215 F50.000000
G1 X60.433215 F50.000000 G1 X70.433215 F50.000000
G1 Y58.401215 F50.000000 G1 Y58.401215 F50.000000
G1 X59.163215 F50.000000 G1 X69.163215 F50.000000
G1 Z-1.900000 F30.000000 G1 Z-1.900000 F30.000000
G1 X3.029215 F50.000000 G1 X13.029215 F50.000000
G1 Y4.553215 F50.000000 G1 Y4.553215 F50.000000
G1 Y4.299215 F50.000000 G1 Y4.299215 F50.000000
G1 X60.433215 F50.000000 G1 X70.433215 F50.000000
G1 Y58.401215 F50.000000 G1 Y58.401215 F50.000000
G1 X59.163215 F50.000000 G1 X69.163215 F50.000000
(Goto to Initial position) (Goto to Initial position)
G0 Z2.000000 G0 Z2.000000

View File

@ -27,7 +27,7 @@ OUT_INCH_FLAG=0
MCODE_FLAG=0 MCODE_FLAG=0
XY_SPEED=100 XY_SPEED=100
Z_SPEED=60 Z_SPEED=60
LEFT_X=5.0 LEFT_X=15.0
LOWER_Y=5.0 LOWER_Y=5.0
DRILL_SPEED=30 DRILL_SPEED=30
DRILL_DEPTH=-1.7 DRILL_DEPTH=-1.7

View File

@ -0,0 +1,194 @@
#!/usr/bin/python
# AUTHOR:
# Carlosgs (http://carlosgs.es)
# LICENSE:
# Attribution - Share Alike - Creative Commons (http://creativecommons.org/licenses/by-sa/3.0/)
#
# DISCLAIMER:
# This software is provided "as is", and you use the software at your own risk. Under no
# circumstances shall Carlosgs be liable for direct, indirect, special, incidental, or
# consequential damages resulting from the use, misuse, or inability to use this software,
# even if Carlosgs has been advised of the possibility of such damages.
# Begin configuration
BAUDRATE = 115200
DEVICE = "/dev/ttyUSB0"
# End configuration
# Begin modules
import sys
from datetime import datetime
import time
import numpy as np
from scipy import interpolate
import matplotlib.pyplot as plt
sys.path.append("../CycloneHost")
import GcodeViewer as gcv
import CycloneHost as cy
# End modules
filePath = "../GcodeGenerators/pyGerber2Gcode_CUI/out/"
fileName = "printshield" # sys.argv[1]
# Display the Gcode that is going to be etched
(etch_moves, travel_moves, gcodeviewer) = gcv.view(filePath,fileName,showEtch=1)
figId = gcodeviewer.number
def pltShowNonBlocking():
plt.ion() # Enable real-time plotting to avoid blocking behaviour for plt.show()
plt.show()
plt.ioff() # Disable real-time plotting
toolPos_point = []
def toolPos_draw(x, y, etching=0):
if etching:
color = 'r'
else:
color = 'g'
toolPos_point.set_data(x, y)
toolPos_point.set_color(color)
gcodeviewer.canvas.draw()
toolRefreshSteps = 1
toolRefresh = 50
def toolPos_refresh(x, y, etching=0):
global toolRefresh
if toolRefresh >= toolRefreshSteps:
toolPos_draw(toolPos_X, toolPos_Y, etching)
toolRefresh = 0
toolRefresh = toolRefresh + 1
def drawTool(x, y):
global toolPos_point
plt.figure(figId)
toolPos_point, = plt.plot(0, 0, markersize=12, c='g', marker='x')
pltShowNonBlocking()
F_slowMove = 200 # Move speed [mm/min?]
F_fastMove = 700
F_etchMove = 50
F_drillMove = 50
F_edgeMove = 25
cy.connect(BAUDRATE, DEVICE)
cy.sendCommand("G90\n") # Set absolute positioning
cy.homeZXY() # Home all the axis
drawTool(10, 20) # Show a marker on the gcode plot
# Warning: Do not lower too much or you will potentially cause damage!
initial_Z_lowering_distance = -20
cy.moveZrelSafe(initial_Z_lowering_distance,F_slowMove/2) # Move Z towards the PCB (saves some probing time for the first coord)
Z_origin_offset = cy.probeZ()
print "Z offset:", Z_origin_offset
Z_workbed_surface = []
def probingResults():
global Z_workbed_surface
x_points = [0.0, 12.272727272727273, 24.545454545454547, 36.81818181818182, 49.09090909090909, 61.36363636363637, 73.63636363636364, 85.9090909090909, 98.18181818181819, 110.45454545454547, 122.72727272727273, 135.0]
y_points = [0.0, 16.8, 33.6, 50.400000000000006, 67.2, 84.0]
probe_result = [[0.0, 0.2, 0.4, 0.53, 0.58, 0.6, 0.56, 0.53, 0.5, 0.44, 0.33, 0.2], [-0.03, 0.07, 0.16, 0.26, 0.32, 0.33, 0.33, 0.33, 0.29, 0.23, 0.15, 0.05], [-0.07, 0.0, 0.05, 0.12, 0.16, 0.2, 0.2, 0.22, 0.2, 0.16, 0.08, 0.0], [-0.07, -0.03, 0.04, 0.11, 0.15, 0.19, 0.2, 0.22, 0.22, 0.19, 0.11, 0.04], [0.0, 0.04, 0.08, 0.19, 0.23, 0.29, 0.33, 0.36, 0.37, 0.32, 0.2, 0.11], [0.13, 0.2, 0.27, 0.37, 0.44, 0.51, 0.55, 0.61, 0.64, 0.55, 0.41, 0.22]]
duration = 346.076061
# Show our grid
# print "--- Probing results ---"
# print "-> X points:", x_points
# print "-> Y points:", y_points
# print "-> Grid:", probe_result
# print "-> Duration:", duration
# Must be converted into arrays to use scipy
x_points = np.array(x_points)
y_points = np.array(y_points)
probe_result = np.array(probe_result)
# plt.figure()
# plt.pcolor(x_points, y_points, probe_result)
# plt.colorbar()
# plt.title("Z probing results [mm]")
# plt.axis('equal') # 1:1 aspect ratio
# pltShowNonBlocking()
# Interpolation
Z_workbed_surface = interpolate.RectBivariateSpline(y_points, x_points, probe_result)
x_points = np.linspace(min(x_points),max(x_points),100)
y_points = np.linspace(min(y_points),max(y_points),100)
z_points = Z_workbed_surface(y_points,x_points)
plt.figure()
plt.pcolor(x_points, y_points, z_points)
plt.colorbar()
plt.title("Z probing results (interpolated) [mm]")
plt.axis('equal') # 1:1 aspect ratio
pltShowNonBlocking()
def getZoffset(x,y):
return Z_workbed_surface(y,x)[0][0]
probingResults()
#print "Zero:",str(getZoffset(0,0))
toolPos_X = 0
toolPos_Y = 0
toolPos_Z = 0
X_dest = 0
Y_dest = 0
Z_dest = 0
cy.moveZrelSafe(10,F_slowMove)
toolPos_Z = 10
plt.figure(figId)
Zlift = 0.5
for path in etch_moves:
toolRefresh = 0
toolPos_draw(toolPos_X, toolPos_Y, etching=0)
cy.moveZrel(Zlift,F_fastMove) # Raise and move to next point
X_dest = path[0][0]
Y_dest = path[0][1]
cy.moveXY(X_dest, Y_dest, F_fastMove)
toolPos_draw(X_dest, Y_dest, etching=0)
cy.moveZrel(-Zlift,F_slowMove)
for coord in path[1:]:
X_dest = coord[0]
Y_dest = coord[1]
Z_dest = coord[2]
#print "Pos:",toolPos_X, toolPos_Y
Z_real = Z_dest+Z_origin_offset+getZoffset(X_dest, Y_dest)+0.02+10
cy.moveXYZ(X_dest, Y_dest, Z_real, F_slowMove)
toolPos_refresh(toolPos_X, toolPos_Y, etching=1)
toolPos_X = X_dest
toolPos_Y = Y_dest
toolPos_Z = Z_dest
#cy.close() # Close the serial port connection
raw_input("Press enter to exit...")

View File

@ -40,11 +40,18 @@ grid_N = (12,6) # Number of points
Zlift = 0.5 # mm Zlift = 0.5 # mm
F_slowMove = 100
# Warning: Do not lower too much or you will potentially cause damage! # Warning: Do not lower too much or you will potentially cause damage!
initial_Z_lowering_distance = -15 initial_Z_lowering_distance = -15
cy.moveZrelSafe(initial_Z_lowering_distance,F_slowMove) # Move Z towards the PCB (saves some probing time for the first coord) cy.moveZrelSafe(initial_Z_lowering_distance,F_slowMove) # Move Z towards the PCB (saves some probing time for the first coord)
(x_points, y_points, probe_result, Z_offset, duration) = cy.probeGrid(grid_origin, grid_len, grid_N, Zlift) #(x_points, y_points, probe_result, Z_offset, duration) = cy.probeGrid(grid_origin, grid_len, grid_N, Zlift)
x_points = [0.0, 12.272727272727273, 24.545454545454547, 36.81818181818182, 49.09090909090909, 61.36363636363637, 73.63636363636364, 85.9090909090909, 98.18181818181819, 110.45454545454547, 122.72727272727273, 135.0]
y_points = [0.0, 16.8, 33.6, 50.400000000000006, 67.2, 84.0]
probe_result = [[0.0, 0.2, 0.4, 0.53, 0.58, 0.6, 0.56, 0.53, 0.5, 0.44, 0.33, 0.2], [-0.03, 0.07, 0.16, 0.26, 0.32, 0.33, 0.33, 0.33, 0.29, 0.23, 0.15, 0.05], [-0.07, 0.0, 0.05, 0.12, 0.16, 0.2, 0.2, 0.22, 0.2, 0.16, 0.08, 0.0], [-0.07, -0.03, 0.04, 0.11, 0.15, 0.19, 0.2, 0.22, 0.22, 0.19, 0.11, 0.04], [0.0, 0.04, 0.08, 0.19, 0.23, 0.29, 0.33, 0.36, 0.37, 0.32, 0.2, 0.11], [0.13, 0.2, 0.27, 0.37, 0.44, 0.51, 0.55, 0.61, 0.64, 0.55, 0.41, 0.22]]
duration = 346.076061
# Show our grid # Show our grid
print "--- Probing results ---" print "--- Probing results ---"
@ -53,13 +60,38 @@ print "-> Y points:", y_points
print "-> Grid:", probe_result print "-> Grid:", probe_result
print "-> Duration:", duration print "-> Duration:", duration
plt.ion() # Enable real-time plotting to avoid blocking behaviour for pyplot # Must be converted into arrays to use scipy
x_points = np.array(x_points)
y_points = np.array(y_points)
probe_result = np.array(probe_result)
plt.figure(1) def pltShowNonBlocking():
plt.pcolor(np.array(x_points), np.array(y_points), np.array(probe_result)) plt.ion() # Enable real-time plotting to avoid blocking behaviour for plt.show()
plt.show()
plt.ioff() # Disable real-time plotting
plt.figure()
plt.pcolor(x_points, y_points, probe_result)
plt.colorbar() plt.colorbar()
plt.title("Z probing results [mm]") plt.title("Z probing results [mm]")
plt.show() plt.axis('equal') # 1:1 aspect ratio
pltShowNonBlocking()
# Interpolation
Z_workbed_surface = interpolate.RectBivariateSpline(y_points, x_points, probe_result)
x_points = np.linspace(min(x_points),max(x_points),100)
y_points = np.linspace(min(y_points),max(y_points),100)
z_points = Z_workbed_surface(y_points,x_points)
print z_points
plt.figure()
plt.pcolor(x_points, y_points, z_points)
plt.colorbar()
plt.title("Z probing results (interpolated) [mm]")
plt.axis('equal') # 1:1 aspect ratio
pltShowNonBlocking()
# TODO: # TODO:
# - Export results to a file with a standarized format # - Export results to a file with a standarized format

View File

@ -0,0 +1,55 @@
# -*- encoding: utf-8 -*-
# Based on http://scipy-user.10969.n7.nabble.com/2D-Interpolation-td4248.html
import scipy
import scipy.interpolate
def pltShowNonBlocking():
plt.ion() # Enable real-time plotting to avoid blocking behaviour for plt.show()
plt.show()
plt.ioff() # Disable real-time plotting
# the two axes
x = scipy.array([0.0, 12.272727272727273, 24.545454545454547, 36.81818181818182, 49.09090909090909, 61.36363636363637, 73.63636363636364, 85.9090909090909, 98.18181818181819, 110.45454545454547, 122.72727272727273, 135.0])
y = scipy.array([0.0, 16.8, 33.6, 50.400000000000006, 67.2, 84.0])
# make some pretend data
gridy, gridx = scipy.meshgrid(x,y)
z = scipy.array([[0.0, 0.2, 0.4, 0.53, 0.58, 0.6, 0.56, 0.53, 0.5, 0.44, 0.33, 0.2], [-0.03, 0.07, 0.16, 0.26, 0.32, 0.33, 0.33, 0.33, 0.29, 0.23, 0.15, 0.05], [-0.07, 0.0, 0.05, 0.12, 0.16, 0.2, 0.2, 0.22, 0.2, 0.16, 0.08, 0.0], [-0.07, -0.03, 0.04, 0.11, 0.15, 0.19, 0.2, 0.22, 0.22, 0.19, 0.11, 0.04], [0.0, 0.04, 0.08, 0.19, 0.23, 0.29, 0.33, 0.36, 0.37, 0.32, 0.2, 0.11], [0.13, 0.2, 0.27, 0.37, 0.44, 0.51, 0.55, 0.61, 0.64, 0.55, 0.41, 0.22]])
# create a spline interpolator
spl = scipy.interpolate.RectBivariateSpline(y,x,z)
# make some new axes to interpolate to
nx = scipy.linspace(min(x),max(x),100)
ny = scipy.linspace(min(y),max(y),100)
# evaluate
nz = spl(ny, nx)
import matplotlib.pyplot as plt
plt.figure()
plt.pcolor(x, y, z)
plt.title("Datos [mm]")
plt.colorbar()
plt.axis('equal') # 1:1 aspect ratio
pltShowNonBlocking()
plt.figure()
plt.pcolor(nx, ny, nz)
plt.title("Datos interpolados [mm]")
plt.colorbar()
plt.axis('equal') # 1:1 aspect ratio
pltShowNonBlocking()
# Comprobación de que el error es mínimo
plt.figure()
plt.pcolor(x, y, spl(y,x) - z)
plt.title("Diferencia entre datos originales e interpolados (error) [mm]")
plt.colorbar()
plt.axis('equal') # 1:1 aspect ratio
pltShowNonBlocking()
raw_input("Press enter to exit...")

View File

@ -19,16 +19,16 @@ import GcodeViewer as gcv
# End modules # End modules
# Temporary path to speedup testing # Temporary path to speedup testing
#import os import os
#from subprocess import call from subprocess import call
#os.chdir("../GcodeGenerators/pyGerber2Gcode_CUI/") os.chdir("../GcodeGenerators/pyGerber2Gcode_CUI/")
#call(["pypy","./pygerber2gcode_cui_MOD.py"]) call(["pypy","./pygerber2gcode_cui_MOD.py"])
#os.chdir("../../gcode_Z_adjust") os.chdir("../../gcode_Z_adjust")
filePath = "../GcodeGenerators/pyGerber2Gcode_CUI/out/" filePath = "../GcodeGenerators/pyGerber2Gcode_CUI/out/"
fileName = "printshield" # sys.argv[1] fileName = "printshield" # sys.argv[1]
gcv.view(filePath,fileName) gcv.view(filePath,fileName,showAll=1)
raw_input("Press enter to exit...") raw_input("Press enter to exit...")