inial commit

This commit is contained in:
uvos 2023-02-05 18:45:48 +01:00
commit c1392c1b9c
23 changed files with 1251 additions and 0 deletions

222
3040T.hal Normal file
View file

@ -0,0 +1,222 @@
#Real Time Modules
loadrt [KINS]KINEMATICS
loadrt [EMCMOT]EMCMOT base_period_nsec=[EMCMOT]BASE_PERIOD servo_period_nsec=[EMCMOT]SERVO_PERIOD num_joints=[KINS]JOINTS
loadrt hal_parport cfg="0 out"
setp parport.0.reset-time 5000
loadrt stepgen step_type=0,0,0,0 ctrl_type=p,p,p,p
loadrt ilowpass count=1
loadrt timedelay count=2
loadrt not count=1
loadrt or2 count=3
loadrt xor2 count=2
loadrt mux2 count=1
loadrt and2 count=1
addf parport.0.read base-thread
addf stepgen.make-pulses base-thread
addf parport.0.write base-thread
addf parport.0.reset base-thread
addf stepgen.capture-position servo-thread
addf motion-command-handler servo-thread
addf motion-controller servo-thread
addf stepgen.update-freq servo-thread
#Pin Assignments
net probe-in => motion.probe-input
net estop-out => parport.0.pin-01-out
net xstep => parport.0.pin-02-out
setp parport.0.pin-02-out-reset 1
net xdir => parport.0.pin-03-out
net ystep => parport.0.pin-04-out
setp parport.0.pin-04-out-reset 1
net ydir => parport.0.pin-05-out
net zstep => parport.0.pin-06-out
setp parport.0.pin-06-out-reset 1
setp parport.0.pin-07-out-invert 1
net zdir => parport.0.pin-07-out
net astep => parport.0.pin-16-out
net adir => parport.0.pin-17-out
net estop-ext <= parport.0.pin-10-in
net min-home-x <= parport.0.pin-11-in-not
net min-home-y <= parport.0.pin-12-in-not
net max-home-z <= parport.0.pin-13-in-not
net probe-in <= parport.0.pin-15-in-not
#X-Axis
setp stepgen.0.position-scale [JOINT_0]SCALE
setp stepgen.0.steplen 1
setp stepgen.0.stepspace 0
setp stepgen.0.dirhold 36000
setp stepgen.0.dirsetup 36000
setp stepgen.0.maxaccel [JOINT_0]STEPGEN_MAXACCEL
net xpos-cmd joint.0.motor-pos-cmd => stepgen.0.position-cmd
net xpos-fb stepgen.0.position-fb => joint.0.motor-pos-fb
net xstep <= stepgen.0.step
net xdir <= stepgen.0.dir
net xenable joint.0.amp-enable-out => stepgen.0.enable
net min-home-x => joint.0.home-sw-in
net min-home-x => joint.0.neg-lim-sw-in
#Y-Axis
setp stepgen.1.position-scale [JOINT_1]SCALE
setp stepgen.1.steplen 1
setp stepgen.1.stepspace 0
setp stepgen.1.dirhold 36000
setp stepgen.1.dirsetup 36000
setp stepgen.1.maxaccel [JOINT_1]STEPGEN_MAXACCEL
net ypos-cmd joint.1.motor-pos-cmd => stepgen.1.position-cmd
net ypos-fb stepgen.1.position-fb => joint.1.motor-pos-fb
net ystep <= stepgen.1.step
net ydir <= stepgen.1.dir
net yenable joint.1.amp-enable-out => stepgen.1.enable
net min-home-y => joint.1.home-sw-in
net min-home-y => joint.1.neg-lim-sw-in
#Z-Axis
setp stepgen.2.position-scale [JOINT_2]SCALE
setp stepgen.2.steplen 1
setp stepgen.2.stepspace 0
setp stepgen.2.dirhold 36000
setp stepgen.2.dirsetup 36000
setp stepgen.2.maxaccel [JOINT_2]STEPGEN_MAXACCEL
net zpos-cmd joint.2.motor-pos-cmd => stepgen.2.position-cmd
net zpos-fb stepgen.2.position-fb => joint.2.motor-pos-fb
net zstep <= stepgen.2.step
net zdir <= stepgen.2.dir
net zenable joint.2.amp-enable-out => stepgen.2.enable
net max-home-z => joint.2.home-sw-in
net max-home-z => joint.2.pos-lim-sw-in
#A-Axis
setp stepgen.3.position-scale [JOINT_3]SCALE
setp stepgen.3.steplen 1
setp stepgen.3.stepspace 0
setp stepgen.3.dirhold 36000
setp stepgen.3.dirsetup 36000
setp stepgen.3.maxaccel [JOINT_3]STEPGEN_MAXACCEL
net astep <= stepgen.3.step
net adir <= stepgen.3.dir
net aenable joint.3.amp-enable-out => stepgen.3.enable
#net apos-cmd joint.3.motor-pos-cmd => stepgen.3.position-cmd
#net apos-fb stepgen.3.position-fb => joint.3.motor-pos-fb
net estop-out <= iocontrol.0.user-enable-out
net estop-ext => iocontrol.0.emc-enable-in
#Toolchanger
loadusr -W hal_manualtoolchange
net tool-change iocontrol.0.tool-change => hal_manualtoolchange.change
net tool-changed iocontrol.0.tool-changed <= hal_manualtoolchange.changed
net tool-number iocontrol.0.tool-prep-number => hal_manualtoolchange.number
net tool-prepare-loopback iocontrol.0.tool-prepare => iocontrol.0.tool-prepared
#CNCExtension
loadusr -Wn cncextension ./cncextension
#Amp enable
net amp-enable halui.machine.is-on => cncextension.wr0
#Spindle Control
addf mux2.0 servo-thread
net spindle-select => mux2.0.sel
sets spindle-select 1
net spindle-cmd-rpm <= spindle.0.speed-out
net spindle-cmd-rpm => mux2.0.in0
setp mux2.0.in1 0
net spindle-axis-rpm mux2.0.out => stepgen.3.velocity-cmd
addf and2.0 servo-thread
net spindle-fwd-and spindle.0.forward => and2.0.in0
net spindle-select => and2.0.in1
net spindle-main-fwd <= and2.0.out
net spindle-main-fwd => cncextension.ch0
net spindle-main-fwd => cncextension.opt
addf timedelay.0 servo-thread
setp timedelay.0.on-delay 10
setp timedelay.0.off-delay 0
net spindle-main-fwd => timedelay.0.in
net spindle-on-timer <= timedelay.0.out
addf timedelay.1 servo-thread
setp timedelay.1.on-delay 10
setp timedelay.1.off-delay 0
net spindle-main-break spindle.0.brake => timedelay.1.in
net spindle-off-timer <= timedelay.1.out
addf or2.0 servo-thread
net spindle-on-timer => or2.0.in0
net spindle-off-timer => or2.0.in1
net spindle-main-inhibit <= or2.0.out
addf or2.1 servo-thread
addf not.0 servo-thread
net spindle-select => not.0.in
net spindle-select-neg <= not.0.out
net spindle-select-neg => or2.1.in0
net spindle-main-inhibit => or2.1.in1
net spindle-inhibit <= or2.1.out
net spindle-inhibit => spindle.0.at-speed
net spindle-position <= stepgen.3.position-fb
net spindle-position => spindle.0.revs
net spindle-axis-rpm => spindle.0.speed-in
net spindle-index-enable encoder.3.index-enable <=> spindle.0.index-enable
#MPG
setp joint.0.jog-vel-mode 0
setp axis.x.jog-vel-mode 0
setp joint.1.jog-vel-mode 0
setp axis.y.jog-vel-mode 0
setp joint.2.jog-vel-mode 0
setp axis.z.jog-vel-mode 0
setp joint.0.jog-scale 0.0001
setp axis.x.jog-scale 0.0001
setp joint.1.jog-scale 0.0001
setp axis.y.jog-scale 0.0001
setp joint.2.jog-scale 0.00005
setp axis.z.jog-scale 0.00005
net x_enable cncextension.xEnable => axis.x.jog-enable
net y_enable cncextension.yEnable => axis.y.jog-enable
net z_enable cncextension.zEnable => axis.z.jog-enable
net raw-encoder-counts <= cncextension.encoder
addf ilowpass.0 servo-thread
setp ilowpass.0.scale 1024
setp ilowpass.0.gain 0.01
net raw-encoder-counts => ilowpass.0.in
net encoder-counts <= ilowpass.0.out
net encoder-counts => axis.x.jog-counts
net encoder-counts => axis.y.jog-counts
net encoder-counts => axis.z.jog-counts
#Collisionavoid
loadusr -Wn collisionavoid ./collisionavoid
net xpos-abs-cmd joint.0.pos-cmd => collisionavoid.xaxis
net ypos-abs-cmd joint.1.pos-cmd => collisionavoid.yaxis
net zpos-abs-cmd joint.2.pos-cmd => collisionavoid.zaxis
net collision-stop collisionavoid.stop => halui.estop.activate
#Autolevel
loadusr -Wn compensation python2 compensation.py probe-results.txt cubic
net xpos-abs-cmd => compensation.x-pos
net ypos-abs-cmd => compensation.y-pos
net zpos-abs-cmd => compensation.z-pos
net eoffset-enable compensation.enable-out => axis.z.eoffset-enable
net eoffset-scale compensation.scale => axis.z.eoffset-scale
net eoffset-counts compensation.counts => axis.z.eoffset-counts
net eoffset-clear compensation.clear => axis.z.eoffset-clear

191
3040T.ini Normal file
View file

@ -0,0 +1,191 @@
# This config file was created 2021-03-12 16:42:08.823352 by the update_ini script
# The original config files may be found in the /home/philipp/linuxcnc/configs/3040T/3040T.old directory
[EMC]
# The version string for this INI file.
VERSION = 1.1
MACHINE = 3040T
DEBUG = 0
[DISPLAY]
DISPLAY = axis
EDITOR = gedit
POSITION_OFFSET = RELATIVE
POSITION_FEEDBACK = ACTUAL
ARCDIVISION = 64
GRIDS = 10mm 20mm 50mm 100mm
MAX_FEED_OVERRIDE = 2
MIN_SPINDLE_OVERRIDE = 0.5
MAX_SPINDLE_OVERRIDE = 1.2
DEFAULT_LINEAR_VELOCITY = 6.00
MIN_LINEAR_VELOCITY = 0
MAX_LINEAR_VELOCITY = 55
DEFAULT_ANGULAR_VELOCITY = 40
MAX_ANGULAR_VELOCITY = 250
INTRO_GRAPHIC = ./UVOSBannerLCNC.gif
INTRO_TIME = 5
INCREMENTS = 5mm 1mm .5mm .1mm .05mm .01mm .005mm
PYVCP=pannel.xml
OPEN_FILE =""
PROGRAM_PREFIX=/home/philipp/linuxcnc/nc_files
[FILTER]
PROGRAM_EXTENSION = .png,.gif,.jpg Greyscale Depth Image
PROGRAM_EXTENSION = .py Python Script
png = image-to-gcode
gif = image-to-gcode
jpg = image-to-gcode
py = python
[RS274NGC]
PARAMETER_FILE = linuxcnc.var
SUBROUTINE_PATH = /home/philipp/linuxcnc/configs/3040T
USER_M_PATH = /home/philipp/linuxcnc/configs/3040T
RS274NGC_STARTUP_CODE =G64 P0.1 s2400
REMAP=M6 modalgroup=6 ngc=tool-change
REMAP=M400 modalgroup=10 ngc=touchoff-z-to-bead
REMAP=M600 modalgroup=6 ngc=tool-job-begin
FEATURES=12
[EMCMOT]
EMCMOT = motmod
COMM_TIMEOUT = 1.0
BASE_PERIOD = 35000
SERVO_PERIOD = 1000000
[TASK]
TASK = milltask
CYCLE_TIME = 0.010
[HAL]
HALUI=halui
HALFILE = 3040T.hal
POSTGUI_HALFILE = custom_postgui.hal
[HALUI]
MDI_COMMAND = M600
MDI_COMMAND = G0 X0 Y0
MDI_COMMAND = G53 G0 X0 Y0 Z0
MDI_COMMAND = G53 g0 z0
MDI_COMMAND = G10 L20 p0 x0 y0 z0
MDI_COMMAND = G10 L20 p0 x36.575 y-38.364
MDI_COMMAND = G10 L2 p0 x261.3 y286.9
MDI_COMMAND = M400
MDI_COMMAND = o<rectangle_probe> call
[TRAJ]
COORDINATES = XYZA
LINEAR_UNITS = mm
ANGULAR_UNITS = degree
DEFAULT_LINEAR_VELOCITY = 6.00
MAX_LINEAR_VELOCITY = 60.00
[EMCIO]
EMCIO = io
CYCLE_TIME = 0.100
TOOL_TABLE = tool.tbl
TOOL_CHANGE_AT_G30 = 0
[KINS]
KINEMATICS = trivkins coordinates=XYZA
JOINTS = 4
[AXIS_X]
MIN_LIMIT = -0.001
MAX_LIMIT = 290.0
MAX_VELOCITY = 55
MAX_ACCELERATION = 1500.0
[JOINT_0]
TYPE = LINEAR
HOME = 0.0
MAX_VELOCITY = 55
MAX_ACCELERATION = 1500.0
STEPGEN_MAXACCEL = 1875.0
SCALE = -400.0
FERROR = 1
MIN_FERROR = .25
MIN_FERROR = 10.25
MIN_LIMIT = -0.001
MAX_LIMIT = 290.0
HOME_OFFSET = -1.000000
HOME_SEARCH_VEL = -20.000000
HOME_LATCH_VEL = -1.250000
HOME_IGNORE_LIMITS = YES
HOME_SEQUENCE = 1
[AXIS_Y]
MIN_LIMIT = -0.001
MAX_LIMIT = 395.0
MAX_VELOCITY = 55
MAX_ACCELERATION = 800.0
[JOINT_1]
TYPE = LINEAR
HOME = 0.0
MAX_VELOCITY = 55
MAX_ACCELERATION = 800.0
STEPGEN_MAXACCEL = 1250.0
SCALE = -400.0
FERROR = 1
MIN_FERROR = .25
MIN_LIMIT = -0.001
MAX_LIMIT = 395.0
BACKLASH = 0.01
HOME_OFFSET = -1.000000
HOME_SEARCH_VEL = -20.000000
HOME_LATCH_VEL = -1.250000
HOME_IGNORE_LIMITS = YES
HOME_SEQUENCE = 1
[AXIS_Z]
MIN_LIMIT = -75
MAX_LIMIT = 0.001
MAX_VELOCITY = 50
MAX_ACCELERATION = 2000.0
OFFSET_AV_RATIO = 0.2
[JOINT_2]
TYPE = LINEAR
HOME = 0.0
MAX_VELOCITY = 50
MAX_ACCELERATION = 2000.0
STEPGEN_MAXACCEL = 2500.0
SCALE = -400.0
FERROR = 1
MIN_FERROR = .25
MIN_LIMIT = -75
MAX_LIMIT = 0.001
HOME_OFFSET = 1.000000
HOME_SEARCH_VEL = 30.000000
HOME_LATCH_VEL = 1.250000
HOME_IGNORE_LIMITS = YES
HOME_SEQUENCE = 0
[AXIS_A]
MIN_LIMIT = -99999
MAX_LIMIT = 99999
MAX_VELOCITY = 3.33
MAX_ACCELERATION = 2000.0
[JOINT_3]
TYPE = ANGULAR
HOME = 0.0
MAX_VELOCITY = 3.33
MAX_ACCELERATION = 2000.0
STEPGEN_MAXACCEL = 2500.0
#SCALE = 4.6296 #old scale maybe accurate for absolute positon mode?
SCALE = 27.7776
FERROR = 1
MIN_FERROR = .25
MIN_LIMIT = -99999
MAX_LIMIT = 99999
SEARCH_VEL = 0
LATCH_VEL = 0
USE_INDEX = NO
HOME_SEQUENCE = 0

6
M100 Executable file
View file

@ -0,0 +1,6 @@
#!/bin/bash
cd ~/linuxcnc/scannout/default
LAST=$(find . -maxdepth 1 -name "*.jpg" -type f -printf "%p\n" | sed -e s/.\\/out-//g -e s/.jpg//g | sort -g | tail -1)
cnccapture -D /dev/v4l/by-id/usb-Etron_Technology__Inc._XWJ200-video-index0 out-$(($LAST + 1)).jpg

4
M101 Executable file
View file

@ -0,0 +1,4 @@
#!/bin/bash
rm ~/linuxcnc/scannout/default/* 2> /dev/null
exit 0

32
M102 Executable file
View file

@ -0,0 +1,32 @@
#!/bin/bash
cd ~/linuxcnc/scannout/multiscan
if [ -p /tmp/CNCCaptureCtl ]
then
echo exit > /tmp/CNCCaptureCtl
sleep 2
fi
LAST=$(find . -maxdepth 1 -type d -printf "%p\n" | sed -e s/.\\///g | sort -g | tail -1)
re='^[0-9]+$'
if ! [[ $LAST =~ $re ]] ; then
LAST=0
fi
mkdir $(($LAST+1))
cnccapture -d -D /dev/v4l/by-id/usb-Etron_Technology__Inc._XWJ200-video-index0 ~/linuxcnc/scannout/multiscan/$(($LAST+1))/ &
sleep 3
for i in {1..600}
do
if [ -f /tmp/CNCCaptureRdy ]; then
break
else
sleep 0.1
fi
done

24
M103 Executable file
View file

@ -0,0 +1,24 @@
#!/bin/bash
ctlPipe=/tmp/CNCCaptureCtl
if [[ -p $ctlPipe ]]
then
echo snap > "$ctlPipe"
sleep 0.5
for i in {1..600}
do
sleep 0.1
if [ -f /tmp/CNCCaptureRdy ]; then
echo "redy"
break
fi
done
exit 0
else
echo "no ctlPipe"
exit 1
fi

12
M104 Executable file
View file

@ -0,0 +1,12 @@
#!/bin/bash
if [ -p /tmp/CNCCaptureCtl ]
then
echo exit > /tmp/CNCCaptureCtl
sleep 1
exit 0
else
exit 1
fi

BIN
UVOSBannerLCNC.gif Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 16 KiB

232
compensation.py Normal file
View file

@ -0,0 +1,232 @@
#!/usr/bin/env python2
"""Copyright (C) 2020 Scott Alford, scottalford75@gmail.com
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU 2 General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
"""
update = 0.025 # this is how often the z external offset value is updated based on current x & y position
safeOffset = 20
import sys
import os.path, time
import numpy as np
from scipy.interpolate import griddata
from enum import Enum, unique
import linuxcnc
@unique
class States(Enum):
START = 1
IDLE = 2
LOADMAP = 3
RUNNING = 4
RESET = 5
STOP = 6
class Compensation :
def __init__(self) :
self.comp = {}
if len(sys.argv)<2:
print "ERROR! No input file name specified!"
sys.exit()
self.filename = sys.argv[1]
self.method = sys.argv[2]
# default to cubic if not specified
if self.method == "" : self.methond = "cubic"
def loadMap(self) :
# data coordinates and values
self.data = np.loadtxt(self.filename, dtype=float, delimiter=" ", usecols=(0, 1, 2))
self.x_data = np.around(self.data[:,0],1)
self.y_data = np.around(self.data[:,1],1)
self.z_data = self.data[:,2]
# get the x and y, min and max values from the data
self.xMin = int(np.min(self.x_data))
self.xMax = int(np.max(self.x_data))
self.yMin = int(np.min(self.y_data))
self.yMax = int(np.max(self.y_data))
print " xMin = ", self.xMin
print " xMax = ", self.xMax
print " yMin = ", self.yMin
print " yMax = ", self.yMax
# target grid to interpolate to, 1 grid per mm
self.xSteps = (self.xMax-self.xMin)+1
self.ySteps = (self.yMax-self.yMin)+1
self.x = np.linspace(self.xMin, self.xMax, self.xSteps)
self.y = np.linspace(self.yMin, self.yMax, self.ySteps)
self.xi,self.yi = np.meshgrid(self.x,self.y)
print " xSteps = ", self.xSteps
print " ySteps = ", self.ySteps
print " x = ", self.x
# interpolate, zi has all the offset values but need to be transposed
self.zi = griddata((self.x_data,self.y_data),self.z_data,(self.xi,self.yi),method=self.method)
self.zi = np.transpose(self.zi)
def compensate(self) :
# get our nearest integer position
self.xpos = int(round(self.h['x-pos']))
self.ypos = int(round(self.h['y-pos']))
zo = safeOffset
if self.xpos >= self.xMin and self.xpos <= self.xMax and self.ypos >= self.yMin and self.ypos <= self.yMax :
self.Xn = self.xpos - self.xMin
self.Yn = self.ypos - self.yMin
# get the nearest compensation offset and convert to counts (s32) with a scale (float)
# Requested offset == counts * scale
zo = self.zi[self.Xn,self.Yn]
if np.isnan(zo) :
zo = safeOffset
self.scale = 0.001
compensation = int(zo / self.scale)
return compensation
def run(self) :
import hal, time
self.h = hal.component("compensation")
self.h.newpin("enable-in", hal.HAL_BIT, hal.HAL_IN)
self.h.newpin("enable-out", hal.HAL_BIT, hal.HAL_OUT)
self.h.newpin("scale", hal.HAL_FLOAT, hal.HAL_IN)
self.h.newpin("counts", hal.HAL_S32, hal.HAL_OUT)
self.h.newpin("clear", hal.HAL_BIT, hal.HAL_IN)
self.h.newpin("x-pos", hal.HAL_FLOAT, hal.HAL_IN)
self.h.newpin("y-pos", hal.HAL_FLOAT, hal.HAL_IN)
self.h.newpin("z-pos", hal.HAL_FLOAT, hal.HAL_IN)
self.h.newpin("fade-height", hal.HAL_FLOAT, hal.HAL_IN)
self.h.ready()
s = linuxcnc.stat()
currentState = States.START
prevState = States.STOP
try:
while True:
time.sleep(update)
# get linuxcnc task_state status for machine on / off transitions
s.poll()
if currentState == States.START :
if currentState != prevState :
print("\nCompensation entering START state")
prevState = currentState
# do start-up tasks
print(" %s last modified: %s" % (self.filename, time.ctime(os.path.getmtime(self.filename))))
prevMapTime = 0
self.h["counts"] = 0
# transition to IDLE state
currentState = States.IDLE
elif currentState == States.IDLE :
if currentState != prevState :
print("\nCompensation entering IDLE state")
prevState = currentState
# stay in IDLE state until compensation is enabled
if self.h["enable-in"] :
currentState = States.LOADMAP
elif currentState == States.LOADMAP :
if currentState != prevState :
print("\nCompensation entering LOADMAP state")
prevState = currentState
mapTime = os.path.getmtime(self.filename)
if mapTime != prevMapTime:
self.loadMap()
print(" Compensation map loaded")
prevMapTime = mapTime
# transition to RUNNING state
currentState = States.RUNNING
elif currentState == States.RUNNING :
if currentState != prevState :
print("\nCompensation entering RUNNING state")
prevState = currentState
if self.h["enable-in"] :
# enable external offsets
self.h["enable-out"] = 1
fadeHeight = self.h["fade-height"]
zPos = self.h["z-pos"]
if fadeHeight == 0 :
compScale = 1
elif zPos < fadeHeight:
compScale = (fadeHeight - zPos)/fadeHeight
if compScale > 1 :
compScale = 1
else :
compScale = 0
if s.task_state == linuxcnc.STATE_ON :
# get the compensation if machine power is on, else set to 0
# otherwise we loose compensation eoffset if machine power is cycled
# when copensation is enable
compensation = self.compensate()
self.h["counts"] = compensation * compScale
self.h["scale"] = self.scale
else :
self.h["counts"] = 0
else :
# transition to RESET state
currentState = States.RESET
elif currentState == States.RESET :
if currentState != prevState :
print("\nCompensation entering RESET state")
prevState = currentState
# reset the eoffsets counts register so we don't accumulate
self.h["counts"] = 0
# toggle the clear output
self.h["clear"] = 1;
time.sleep(0.1)
self.h["clear"] = 0;
# disable external offsets
#self.h["enable-out"] = 0
# transition to IDLE state
currentState = States.IDLE
except KeyboardInterrupt:
raise SystemExit
comp = Compensation()
comp.run()

55
custom_postgui.hal Normal file
View file

@ -0,0 +1,55 @@
# Include your customized HAL commands here
# The commands in this file are run after the AXIS GUI (including PyVCP panel) starts
net mpg pyvcp.mpg-chkbtn => cncextension.enableMpg
#spindle
net spindle-select <= pyvcp.spindle-select.Milling
# Vacuume and coolant
addf xor2.0 servo-thread
net sigVacuumeBtn pyvcp.vacuume-chkbtn => xor2.0.in0
net sigIoctlFlood iocontrol.0.coolant-flood => xor2.0.in1
net vacuume <= xor2.0.out
net vacuume => cncextension.wr1
addf xor2.1 servo-thread
net sigAirBtn pyvcp.air-chkbtn => xor2.1.in0
net sigIoctlAir iocontrol.0.coolant-mist => xor2.1.in1
net air <= xor2.1.out
net air => cncextension.wr2
#alcohol
net alcohol pyvcp.alcohol-scale-i => cncextension.pwm
net alcoholPrime pyvcp.prime-chkbtn => cncextension.pwmPrime
net spindle-inhibit => pyvcp.feed-inhibit-led
addf or2.2 servo-thread
net touchoffall-btn pyvcp.touchoffall-btn => or2.2.in0
net button1 cncextension.button2 => or2.2.in1
net m600 halui.mdi-command-00 <= pyvcp.m600-btn
net g0x0y0 halui.mdi-command-01 <= pyvcp.x0y0-btn
net g53g0x0y0z0 halui.mdi-command-02 <= pyvcp.g53g0x0y0z0-btn
net g53g0z0 halui.mdi-command-03 <= pyvcp.g53g0z0-btn
net g10l20x0y0z0 halui.mdi-command-04 <= or2.2.out
net g10l20x20y20 halui.mdi-command-05 <= pyvcp.microscope-btn
net g53g10l20pin halui.mdi-command-06 <= pyvcp.touchoffpin-btn
net touchofzpin halui.mdi-command-07 <= pyvcp.touchofz-btn
#Collisionavoid
net collision-stop => pyvcp.collision-led
net chuck pyvcp.chuck-chkbtn => collisionavoid.chuck
setp pyvcp.chuck-chkbtn.changepin 1
#Autolevel
net levelpin pyvcp.level-chkbtn => compensation.enable-in
net runalprobe halui.mdi-command-08 <= pyvcp.alprobe-btn
#Autolevel spinbox display
net alprsx pyvcp.alprsx => pyvcp.alprsxDisp
net alprsy pyvcp.alprsy => pyvcp.alprsyDisp
net alintervl pyvcp.alintervl => pyvcp.alintervlDisp
net alheight pyvcp.alheight => pyvcp.alheightDisp

77
gcodeUtils/3dscann.ngc Normal file
View file

@ -0,0 +1,77 @@
%
(Workpice Settings)
#<Xsize> = 10
#<Ysize> = 10
#<Zsize> = 20
(Imaging Settings)
#<XStep> = 5
#<YStep> = 5
#<CameraOffset> = 5
(Milling Settings)
#<Feed> = 2000
#<Stepover> = 8
#<Stepdown> = 1
#<CurrentZ> = 0
g90
G64 P0.05
O010 while [[-1*#<Zsize>] LT #<CurrentZ>]
(MAKE IMAGES)
#1 = 0
#2 = 0
g0 z[#<CurrentZ>+#<CameraOffset>]
g0 x0y0
M102
O100 while [#1 LT [#<Ysize>]]
#2 = 0
g0 x0 y[#1]
M103
O101 while [#2 LT [#<Xsize>]]
#2 = [#2+#<XStep>]
g0 x[#2]
M103
O102 if [ #1 EQ 0 ]
#<XgridSize> = [#<XgridSize>+1]
O102 endif
O101 endwhile
#1 = [#1+#<YStep>]
#<YgridSize> = [#<YgridSize>+1]
O100 endwhile
M104
(AREA MILL)
G0 X0.0 Y0.0
M3
G4 P10
G1 F[#<Feed>] Z#<CurrentZ>
#1 = 0
O110 while [#1 LT #<Ysize>]
x0 y[#1]
G1 z#<CurrentZ>
x[#<Xsize>]
#1 = [#1+#<Stepover>]
G0 z[#<CurrentZ>+1]
O110 endwhile
O111 if [ #1 NE #<Ysize> ]
x0 y#<Ysize>
G1 z#<CurrentZ>
x[#<Xsize>]
G0 z[#<CurrentZ>+1]
O111 endif
m5
G4 P12
#<CurrentZ>=[#<CurrentZ>-#<Stepdown>]
O010 endwhile
%

29
gcodeUtils/AreaMill.ngc Normal file
View file

@ -0,0 +1,29 @@
%
#<Feed> = 2500
#<Xsize> = 75
#<Ysize> = 90
#<Stepover> = 3
G91 G28 Z0
M3
G0 G90 X0.0 Y0.0 S2400
G0 z5
#1 = 0
O100 while [#1 LT #<Ysize>]
G1 F[#<Feed>] z0
x[#<Xsize>]
#1 = [#1+#<Stepover>]
G0 z5
x0 y[#1]
O100 endwhile
g1 z0
F[#<Feed>] x[#<Xsize>]
G0 z5
x0 y0
G91 G28 Z0
G90
%

33
gcodeUtils/XCut.ngc Normal file
View file

@ -0,0 +1,33 @@
%
#<Feed> = 2000
#<Xsize> = 110
#<Depth> = 3
#<DPC> =1
(G91 G28 Z0)
G91 G28 Z0
G90
M3 s24000
G00 G90 X0.0 Y0.0
G0 z5
G1 F[#<Feed>]
#1 = 0
O100 while [#1 gt 0-[#<Depth>-#<DPC> ]]
#1 = [#1-#<DPC>]
G1 F[#<Feed>] z[#1]
x[#<Xsize>]
G0 z5
x0
O100 endwhile
G1 F[#<Feed>]
z[0-#<Depth>]
x[#<Xsize>]
G0 z5
x0
G91 G28 Z0
G90
M2
%

29
gcodeUtils/YCut.ngc Normal file
View file

@ -0,0 +1,29 @@
%
#<Feed> = 2000
#<Ysize> = 110
#<Depth> = 3
#<DPC> =1
G91 G28 Z0
G00 G90 X0.0 Y0.0 S0
G0 z5
G1 F[#<Feed>]
#1 = 0
O100 while [#1 gt 0-[#<Depth>-#<DPC>]]
#1 = [#1-#<DPC>]
G1 F[#<Feed>] z[#1]
Y[#<Ysize>]
G0 z5
Y0
O100 endwhile
G1 F[#<Feed>]
z[0-#<Depth>]
Y[#<Ysize>]
G0 z5
Y0
G91 G28 Z0
G90
%

36
gcodeUtils/scann.ngc Normal file
View file

@ -0,0 +1,36 @@
%
#<Xsize> = 50
#<Ysize> = 50
#<XStep> = 5
#<YStep> = 5
#<XgridSize> = 0
#<YgridSize> = 0
#1 = 0
#2 = 0
M102
g90 g0 x0y0
O100 while [#1 LT [#<Ysize>]]
#2 = 0
g0 x0 y[#1]
M103
O101 while [#2 LT [#<Xsize>]]
#2 = [#2+#<XStep>]
g0 x[#2]
M103
O102 if [ #1 EQ 0 ]
#<XgridSize> = [#<XgridSize>+1]
O102 endif
O101 endwhile
#1 = [#1+#<YStep>]
#<YgridSize> = [#<YgridSize>+1]
O100 endwhile
M104
(DEBUG, #<XgridSize> by #<YgridSize>)
%

34
gcodeUtils/scannSync.ngc Normal file
View file

@ -0,0 +1,34 @@
%
#<Xsize> = 50
#<Ysize> = 50
#<XStep> = 5
#<YStep> = 5
#<XgridSize> = 0
#<YgridSize> = 0
#1 = 0
#2 = 0
M101
g90 g0 x0y0
O100 while [#1 LT [#<Ysize>]]
#2 = 0
g0 x0 y[#1]
M100
O101 while [#2 LT [#<Xsize>]]
#2 = [#2+#<XStep>]
g0 x[#2]
M100
O102 if [ #1 EQ 0 ]
#<XgridSize> = [#<XgridSize>+1]
O102 endif
O101 endwhile
#1 = [#1+#<YStep>]
#<YgridSize> = [#<YgridSize>+1]
O100 endwhile
(DEBUG, #<XgridSize> by #<YgridSize>)
%

0
microscopeTuchoff.ngc Normal file
View file

73
rectangle_probe.ngc Normal file
View file

@ -0,0 +1,73 @@
( Rectangular area probe )
o<rectangle_probe> sub
#<xmin> = 0
#<xmax> = #<_hal[pyvcp.alprsx]>
#<xinterval> = #<_hal[pyvcp.alintervl]>
#<ymin> = 0
#<ymax> = #<_hal[pyvcp.alprsy]>
#<yinterval> = #<_hal[pyvcp.alintervl]>
#<zsafe> = #<_hal[pyvcp.alheight]>
#<zprobe> = 0
#<probespeed> = 50
#<xsteps> = [fix [abs[#<xmax> - #<xmin>]/#<xinterval> + 1]]
#<ysteps> = [fix [abs[#<ymax> - #<ymin>]/#<yinterval> + 1]]
O1 if[[#<xsteps>*#<xinterval>-#<xinterval>] lt #<xmax>]
#<xsteps> = [#<xsteps> + 1]
O1 endif
O2 if[[#<ysteps>*#<yinterval>-#<yinterval>] lt #<ymax>]
#<ysteps> = [#<ysteps> + 1]
O2 endif
#<points> = [#<xsteps> * #<ysteps>]
(debug, Probing #<xsteps> * #<ysteps> = #<points> points)
(LOGOPEN,probe-results.txt)
#<yct> = 0
#<xct> = 0
G53 G0 Z0
G0 X0 Y0
G30.1
G0Z#<zsafe>
F#<probespeed>
O12 while [#<yct> lt #<ysteps>]
#<xct> = 0
#<ytarget> = [#<ymin>+#<yinterval>*#<yct>]
O13 if [#<ytarget> gt #<ymax>]
#<ytarget> = #<ymax>
O13 endif
G0 Y#<ytarget>
O14 while [#<xct> lt #<xsteps>]
#<xtarget> = 0
O15 if [[#<yct>/2] - fix[#<yct>/2] eq 0]
#<xtarget> = [#<xmin> + #<xinterval> * #<xct>]
O15 else
#<xtarget> = [#<xmin> + #<xinterval> * [#<xsteps> - #<xct> - 1]]
O15 endif
O16 if [#<xtarget> gt #<xmax>]
#<xtarget> = #<xmax>
O16 endif
#<probesuccess> = 1
G0 x#<xtarget>
G38.2Z#<zprobe> (probe until contact, toward work, with error)
G0z#<zsafe>
#<probex> = [#5061+#5181]
#<probey> = [#5062+#5182]
#<probez> = #5063
(LOG,#<probex> #<probey> #<probez>)
#<xct> = [#<xct> + 1]
O14 endwhile
G0Z#<zsafe>
#<yct> = [#<yct> + 1]
O12 endwhile
(LOG,# Finished: total points = #<points>)
(LOGCLOSE)
(debug, Finished: see probe-results.txt)
G0Z#<zsafe>
G0X#<xmin>Y#<ymin>
o<rectangle_probe> endsub

1
testpannel.hal Normal file
View file

@ -0,0 +1 @@
loadusr pyvcp ./pannel.xml

96
tool-change.ngc Normal file
View file

@ -0,0 +1,96 @@
O<tool-change> SUB
#<_UseInches> = 0 ( set to 1 to use inches here, or 0 to use millimeters; should match units on tool.tbl dimensions )
#<_TravelZ> = 0 ( machine Z coordinate for travelling, typically near max Z to avoid ever hitting the work )
#<_TravelFeed> = 3000 ( feedrate used for general Z moves when avoiding G0 )
#<_ProbeX> = 9.5 ( machine X coordinate of switch/touch-off plate )
#<_ProbeY> = 24.5 ( machine Y coordinate of switch/touch-off plate )
#<_ProbeFastZ> = -20 ( machine Z coord to move to before starting probe, longest tool should not touch switch at this Z )
#<_ProbeMinZ> = -70 ( machine Z coord to stop probe, shortest tool must touch switch at this Z, must be > min Z )
#<_ProbeRetract> = 0.2 ( small distance to retract before approaching switch/touch-off plate second time )
#<_ProbeFastFeed> = 3000 ( feed rate for moving to _ProbeFastZ )
#<_ProbeFeed1> = 750 ( feed rate for touching switch/touch-off plate first time )
#<_ProbeFeed2> = 3 ( feed rate for touching switch/touch-off plate second time )
#<_ToolChangeX> = 100 ( machine X coordinate to pause at for manual tool changing )
#<_ToolChangeY> = 100 ( machine Y coordinate to pause at for manual tool changing )
#<_MistOnDuringProbe> = 0 ( set to 1 for mist, or 2 for coolant, or 0 for nothing during probing, to clear switch of swarf )
O100 IF [ EXISTS[#<_ToolDidReferance>] EQ 0 ]
#<_ToolDidReferance> = 0
O100 ENDIF
O101 IF [ EXISTS[#<_IgnoreFirstTool>] EQ 0 ]
#<_IgnoreFirstTool> = 0
O101 endif
O102 IF [ #<_IgnoreFirstTool> EQ 0 ]
#<_IgnoreFirstTool> = 1
O102 ELSE
M49 (disable spindle speed and feed rate override controls)
O105 IF [ #<_ToolDidReferance> EQ 0 ]
G49 ( clear tool length compensation prior to saving state if this is first time )
O105 ENDIF
(AXIS,hide)
M6 ( do the normal M6 stuff )
M70 ( save current modal state )
M9 ( turn off coolant, will be restored on return if it was on )
M5 ( turn off spindle, cannot be on during the probe )
G[21 - #<_UseInches>] ( use inches or millimeters as required here, units will be restored on return )
G30.1 ( save current position in #5181-#5183... )
G49 ( clear tool length compensation )
G90 ( use absolute positioning here )
G94 ( use feedrate in units/min )
G40 ( turn cutter radius compensation off here )
G53 G1 F[#<_TravelFeed>] Z[#<_TravelZ>] ( go to high travel level on Z )
O200 IF [ #<_ToolDidReferance> EQ 0 ]
G53 G0 X[#<_ProbeX>] Y[#<_ProbeY>] ( to probe switch )
G53 G1 F[#<_ProbeFastFeed>] Z[#<_ProbeFastZ>]( move tool closer to switch -- we shouldn't hit it )
G54 G1 F[#<_ProbeFeed1>] G91 ( use relative positioning )
O103 IF [ #<_MistOnDuringProbe> EQ 1 OR #<_MistOnDuringProbe> EQ 2 ]
M[7 + #<_MistOnDuringProbe> - 1] ( turn on mist/coolant )
O103 ENDIF
G38.2 Z[#<_ProbeMinZ> - #<_ProbeFastZ>] F[#<_ProbeFeed1>] ( trip switch slowly )
G0 Z[#<_ProbeRetract>] ( go up slightly )
G38.2 Z[#<_ProbeRetract>*-1.25] F[#<_ProbeFeed2>] ( trip switch very slowly )
M9 ( turn off mist )
G90 ( use absolute positioning )
#<_ToolZRef> = #5063 ( save trip point )
#<_ToolZLast> = #<_ToolZRef> ( save last tool Z position )
G53 G1 F[#<_TravelFeed>] Z[#<_TravelZ>] ( return to safe level )
#<_ToolDidReferance> = 1 ( we have been in this section to set reference value already )
G53 G0 X[#<_ToolChangeX>] Y[#<_ToolChangeY>] ( nice place for changing tool )
(MSG, SwitchTool )
M0 ( pause execution )
O200 ENDIF
G53 G0 X[#<_ProbeX>] Y[#<_ProbeY>] ( to high place directly over switch )
G53 G1 F[#<_ProbeFastFeed>] Z[#<_ProbeFastZ>]( move tool closer to switch -- we shouldn't hit it )
G54 G1 F[#<_ProbeFeed1>] G91 ( use relative positioning )
O104 IF [ #<_MistOnDuringProbe> EQ 1 OR #<_MistOnDuringProbe> EQ 2 ]
M[7 + #<_MistOnDuringProbe> - 1] ( turn on mist/coolant )
O104 ENDIF
G38.2 Z[#<_ProbeMinZ> - #<_ProbeFastZ>] F[#<_ProbeFeed1>] ( trip switch slowly )
G0 Z[#<_ProbeRetract>] ( go up slightly )
G38.2 Z[#<_ProbeRetract>*-1.25] F[#<_ProbeFeed2>] ( trip switch very slowly )
M9 ( turn off mist )
G90 ( use absolute positioning )
#<_ToolZ> = #5063 ( save new tool length )
G43.1 Z[#<_ToolZ> - #<_ToolZRef>] ( set new tool length Z offset, we do this now to show operator even though it has to be set again after M72 )
#<_ToolZLast> = #<_ToolZ> ( save last tool length )
G53 G0 Z[#<_TravelZ>] ( return to safe level )
G53 G0 X[#5181] Y[#5182] ( return to saved position )
G53 G0 Z[#5183]
M72 ( restore modal state )
M3
G43.1 Z[#<_ToolZ> - #<_ToolZRef>] ( set new tool length Z offset )
M48 (enable spindle speed and feed rate override controls)
(AXIS,show)
O102 ENDIF
O<tool-change> ENDSUB
M2

12
tool-job-begin.ngc Normal file
View file

@ -0,0 +1,12 @@
O<tool-job-begin> SUB
( Filename: tool-job-begin.ngc )
( LinuxCNC Manual Tool-Change Subroutines for Milling Machines version 1.1: subroutine 2/2 )
( Intended to be run as a remapped M600 command. Used to indicate that the next tool change, M6, is the first tool of a job. )
#<_ToolDidFirst> = 0 ( new job, we haven't yet called <tool-change> for the first time )
#<_IgnoreFirstTool> = 0
#<_ToolDidReferance> = 0
G49 ( clear tool height adjustment )
O<tool-job-begin> ENDSUB
M2

15
tool.tbl Normal file
View file

@ -0,0 +1,15 @@
T1 P1 D2 Z0
T2 P2 D2 Z0
T3 P3 D2 Z0
T4 P4 D2 Z0
T5 P5 D2 Z0
T6 P6 D2 Z0
T7 P7 D2 Z0
T8 P8 D2 Z0
T9 P9 D2 Z0
T10 P10 D2 Z0
T11 P11 D2 Z0
T12 P12 D2 Z0
T13 P13 D2 Z0
T14 P14 D2 Z0

38
touchoff-z-to-bead.ngc Normal file
View file

@ -0,0 +1,38 @@
o<touchoff-z-to-Bead> sub
#<_TravelZ> = 0 ( machine Z coordinate for travelling, typically near max Z to avoid ever hitting the work )
#<_ProbeX> = 9.5 ( machine X coordinate of switch/touch-off plate )
#<_ProbeY> = 24.5 ( machine Y coordinate of switch/touch-off plate )
#<_ProbeFastZ> = -20 ( machine Z coord to move to before starting probe, longest tool should not touch switch at this Z )
#<_ProbeMinZ> = -70 ( machine Z coord to stop probe, shortest tool must touch switch at this Z, must be > min Z )
#<_ProbeRetract> = 0.2 ( small distance to retract before approaching switch/touch-off plate second time )
#<_ProbeFastFeed> = 3000 ( feed rate for moving to _ProbeFastZ )
#<_ProbeFeed1> = 750 ( feed rate for touching switch/touch-off plate first time )
#<_ProbeFeed2> = 3 ( feed rate for touching switch/touch-off plate second time )
#<_ProbeToBeadZ> = 13.1
m73
G30.1 ( save current position in #5181-#5183... )
G49 ( clear tool length compensation )
G90 ( use absolute positioning here )
G94 ( use feedrate in units/min )
G40 ( turn cutter radius compensation off here )
G54 (use coordinate system 1)
M49 (disable spindle speed and feed rate override controls)
G53 G0 Z[#<_TravelZ>] ( go to high travel level on Z )
G53 G0 X[#<_ProbeX>] Y[#<_ProbeY>] ( to probe switch )
G53 G1 F[#<_ProbeFastFeed>] Z[#<_ProbeFastZ>] ( move tool closer to switch -- we shouldn't hit it )
G54 G1 F[#<_ProbeFeed1>] G91 ( use relative positioning )
G38.2 Z[#<_ProbeMinZ> - #<_ProbeFastZ>] F[#<_ProbeFeed1>] ( trip switch slowly )
G0 Z[#<_ProbeRetract>] ( go up slightly )
G38.2 Z[#<_ProbeRetract>*-1.25] F[#<_ProbeFeed2>] ( trip switch very slowly )
G90 ( use absolute positioning )
G10 L20 p0 z[#<_ProbeToBeadZ>]
(DEBUG, #5063)
G53 G0 Z[#<_TravelZ>] ( return to safe level )
G53 G0 X[#5181] Y[#5182]
G53 G0 Z[#5183]
M48 (enable spindle speed and feed rate override controls)
o<touchoff-z-to-Bead> endsub
M2