Commit 7464eafa authored by electrolab's avatar electrolab

Add lathemacro

parent 8e792550
......@@ -4,4 +4,7 @@ linuxcnc.var.bak
old/*
*.pref
tool.tbl
*.pyc
postion.txt
savestate.*
savestatemacro.*
This source diff could not be displayed because it is too large. You can view the blob instead.
#!/usr/bin/env python
# vim: sts=4 sw=4 et
# This is a component of EMC
# savestate.py copyright 2013 Andy Pugh
# based on code from
# probe.py Copyright 2010 Michael Haberler
#
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU 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''''''
import os,sys
from gladevcp.persistence import IniFile,widget_defaults,set_debug,select_widgets
import hal
import hal_glib
import gtk
import glib
import linuxcnc
import rsvg
import cairo
import signal
import pango
debug = 0
class HandlerClass:
active = False
tab_num = 0
firstpress = 0
def on_expose(self,nb,data=None):
tab_num = nb.get_current_page()
tab = nb.get_nth_page(tab_num)
cr = tab.window.cairo_create()
cr.set_operator(cairo.OPERATOR_OVER)
x, y, w, h = tab.allocation
sx, sy, sw, sh = self.svg.get_dimension_data()
cr.translate(0, y)
cr.scale(1.0 *w / sw, 1.0*h/sh)
self.svg.render_cairo(cr = cr, id = '#layer%i' % tab_num)
# This catches our messages from another program
def event(self,w,event):
print event.message_type,event.data
if event.message_type == 'Gladevcp':
if event.data[:7] == 'Visible':
self.active = True
else:
self.active = False
# We connect to client-events from the new toplevel widget
def on_map_event(self, widget, data=None):
top = widget.get_toplevel()
print "map event"
top.connect('client-event', self.event)
def on_destroy(self,obj,data=None):
self.ini.save_state(self)
def on_restore_defaults(self,button,data=None):
'''
example callback for 'Reset to defaults' button
currently unused
'''
self.ini.create_default_ini()
self.ini.restore_state(self)
def __init__(self, halcomp,builder,useropts):
self.halcomp = halcomp
self.builder = builder
self.ini_filename = 'savestatemacro.sav'
self.defaults = { IniFile.vars: dict(),
IniFile.widgets : widget_defaults(select_widgets(self.builder.get_objects(), hal_only=False,output_only = True))
}
self.ini = IniFile(self.ini_filename,self.defaults,self.builder)
self.ini.restore_state(self)
# A pin to use a physical switch to start the cycle
self.cycle_start = hal_glib.GPin(halcomp.newpin('cycle-start', hal.HAL_BIT, hal.HAL_IN))
self.cycle_start.connect('value-changed', self.cycle_pin)
# This catches the signal from Touchy to say that the tab is exposed
t = self.builder.get_object('eventbox1')
t.connect('map-event',self.on_map_event)
t.add_events(gtk.gdk.STRUCTURE_MASK)
self.cmd = linuxcnc.command()
# This conects the expose event to re-draw and scale the SVG frames
t = self.builder.get_object('tabs1')
t.connect_after("expose_event", self.on_expose)
t.connect("destroy", gtk.main_quit)
t.add_events(gtk.gdk.STRUCTURE_MASK)
self.svg = rsvg.Handle(file='LatheMacro.svg', )
def show_keyb(self, obj, data=None):
self.active_ctrl = obj
self.keyb = self.builder.get_object('keyboard')
self.entry = self.builder.get_object('entry1')
self.entry.modify_font(pango.FontDescription("courier 42"))
#set text to previous value
self.entry.set_text(self.active_ctrl.get_text())
self.entry.select_region(0,-1)
#clear text
#self.entry.set_text("")
self.firstpress = 1
resp = self.keyb.run()
#Add for prevent but if closing the windows without click cancel
self.keyb.hide()
def keyb_prev_click(self, obj, data=None):
pos = self.entry.get_position()
self.entry.set_text(self.active_ctrl.get_text())
self.entry.set_position(pos)
def keyb_number_click(self, obj, data=None):
dataval = obj.get_label()
entryval = self.entry.get_text()
#do some sanity checking
if '.' in dataval:
if self.firstpress == 0:
tarr = entryval.split('/')
pos = self.entry.get_position()
if len(tarr[0]) >= pos:
#cursor is in the numerator
if '.' in tarr[0]:
return
elif len(tarr) > 1:
if '.' in tarr[1]:
return
if '/' in dataval and '/' in entryval:
return #only one divisor
self.firstpress = 0
#otherwise send the value to the entry box
event = gtk.gdk.Event(gtk.gdk.KEY_PRESS)
data = obj.get_label()
virtkey = int(gtk.gdk.unicode_to_keyval(ord(data[0])))
event.keyval = virtkey
self.entry.emit('key_press_event', event)
def process_entry(self):
self.firstpress = 0
data = self.entry.get_text()
darr = data.split('/')
if len(darr) == 1:
#is a single number
return darr[0]
else:
if float(darr[1]) == 0:
return darr[0] #not really correct for divide by 0 but this should be fine
else:
value = float(darr[0]) / float(darr[1])
return "%.5f" % value
def keyb_pm_click(self, obj, data=None):
data = self.process_entry()
if data[0] == '-':
data = data[1:]
else:
data = '-' + data
self.entry.set_text(data)
self.entry.set_position(-1)
def keyb_convert_click(self, obj, data=None):
v = float(self.process_entry())
op = obj.get_label()
if op == 'in->mm':
v = v * 25.4
elif op == 'mm->in':
v = v / 25.4
elif op == 'tpi->pitch':
v = 25.4 / v
elif op == 'pitch->tpi':
v = 25.4 / v
self.entry.set_text('%6.4f'%v)
self.entry.set_position(-1)
def keyb_del_click(self, obj, data=None):
data = self.entry.get_text()
pos = self.entry.get_position()
data = data[:(pos-1)] + data[pos:]
self.entry.set_text(data)
self.entry.set_position(pos-1)
def keyb_clear_click(self, obj, data=None):
self.entry.set_text("0")
self.entry.select_region(0,-1)
def keyb_cancel_click(self, obj, data=None):
self.keyb.hide()
def keyb_ok_click(self, obj, data=None):
if self.entry.get_text() != '':
self.active_ctrl.set_value(float(self.process_entry()))
self.keyb.hide()
def set_alpha(self, obj, data = None):
cr = obj.window.cairo_create()
cr.set_source_rgba(1.0, 1.0, 1.0, 0.0)
def cycle_pin(self, pin, data = None):
if pin.get() == 0:
return
print 'cycle pin'
if self.active:
nb = self.builder.get_object('tabs1')
print 'current tab', nb.get_current_page()
tab = nb.get_nth_page(nb.get_current_page())
for c in tab.get_children():
if c.name.partition('.')[2] == 'action':
self.cmd.abort()
self.cmd.mode(linuxcnc.MODE_MDI)
self.cmd.wait_complete()
c.emit('clicked')
def gash(self, obj, data = None):
print 'event', data
def spin_handler(self, obj, data=None):
data = obj.get_text()
if data[-3:] == 'tpi':
obj.set_value(25.4/float(data[:-3]))
obj.set_position(-1)
elif data[-2:] == 'in':
obj.set_value(25.4*float(data[:-2]))
obj.set_position(-1)
elif data[-2:] == 'mm':
obj.set_value(float(data[:-2])/25.4)
obj.set_position(-1)
elif data[-5:] == 'pitch':
obj.set_value(25.4/float(data[:-5]))
obj.set_position(-1)
elif data[-2:] in [ '/2', '/4', '/8']:
v = data[:-2].split()
if len(v) == 2:
obj.set_value(float(v[0]) + float(v[1]) / float(data[-1:]))
obj.set_position(-1)
elif len(v) == 1:
obj.set_value(float(v[0]) / float(data[-1:]))
obj.set_position(-1)
elif data[-3:] in [ '/16', '/32', '/64']:
v = data[:-3].split()
if len(v) == 2:
obj.set_value(float(v[0]) + float(v[1]) / float(data[-2:]))
obj.set_position(-1)
elif len(v) == 1:
obj.set_value(float(v[0]) / float(data[-2:]))
obj.set_position(-1)
def get_handlers(halcomp,builder,useropts,dummy=False):
global debug
for cmd in useropts:
exec cmd in globals()
set_debug(debug)
return [HandlerClass(halcomp,builder,useropts)]
This diff is collapsed.
# This config file was created 2016-09-30 19:50:17.541521 by the update_ini script
# The original config files may be found in the /home/andypugh/linuxcnc/configs/LatheMacro-3/lathemacro.old directory
# EMC controller parameters for a simulated machine.
# General note: Comments can either be preceded with a # or ; - either is
# acceptable, although # is in keeping with most linux config files.
# General section -------------------------------------------------------------
[EMC]
# Version of this INI file
VERSION = 1.0
# Name of machine, for use with display, etc.
MACHINE = GLADEVCP-LATHE
# Debug level, 0 means no messages. See src/emc/nml_int/emcglb.h for others
#DEBUG = 0x7FFFFFFF
DEBUG = 0
# Sections for display options ------------------------------------------------
[DISPLAY]
# add GladeVCP panel where PyVCP used to live:
EMBED_TAB_NAME=Cycles
EMBED_TAB_COMMAND=halcmd loadusr -Wn gladevcp gladevcp -c gladevcp -u lathehandler.py -x {XID} lathemacro-en-numpad.ui
# Name of display program, e.g., xemc
DISPLAY = touchy
OPEN_FILE = ""
# Cycle time, in seconds, that display will sleep between polls
CYCLE_TIME = 0.100
# Path to help file
HELP_FILE = doc/help.txt
# Initial display setting for position, RELATIVE or MACHINE
POSITION_OFFSET = RELATIVE
# Initial display setting for position, COMMANDED or ACTUAL
POSITION_FEEDBACK = ACTUAL
# Highest value that will be allowed for feed override, 1.0 = 100%
MAX_FEED_OVERRIDE = 1.2
MAX_SPINDLE_OVERRIDE = 1.0
LATHE = 1
MAX_LINEAR_VELOCITY = 120
DEFAULT_LINEAR_VELOCITY = 120
# Prefix to be used
PROGRAM_PREFIX = ~/linuxcnc/nc_files
# Introductory graphic
INTRO_GRAPHIC = linuxcnc.gif
INTRO_TIME = 5
EDITOR = gedit
TOOL_EDITOR = tooledit
INCREMENTS = 10mm, 1mm, 0.1mm, 0.01mm
[FILTER]
PROGRAM_EXTENSION = .png,.gif,.jpg Grayscale Depth Image
PROGRAM_EXTENSION = .py Python Script
png = image-to-gcode
gif = image-to-gcode
jpg = image-to-gcode
py = python
# Task controller section -----------------------------------------------------
[RS274NGC]
# File containing interpreter variables
PARAMETER_FILE = sim.var
RS274NGC_STARTUP_CODE = G7 G21
# gladevcp Demo specific Oword subs live here
SUBROUTINE_PATH = ../../../nc_files/gladevcp_lib:./
FEATURES = 0
# Motion control section ------------------------------------------------------
[EMCMOT]
EMCMOT = motmod
# Timeout for comm to emcmot, in seconds
COMM_TIMEOUT = 1.0
# Interval between tries to emcmot, in seconds
COMM_WAIT = 0.010
# BASE_PERIOD is unused in this configuration but specified in core_sim.hal
BASE_PERIOD = 0
# Servo task period, in nano-seconds
SERVO_PERIOD = 1000000
# Hardware Abstraction Layer section --------------------------------------------------
[TASK]
# Name of task controller program, e.g., milltask
TASK = milltask
# Cycle time, in seconds, that task controller will sleep between polls
CYCLE_TIME = 0.001
# Part program interpreter section --------------------------------------------
[HAL]
# The run script first uses halcmd to execute any HALFILE
# files, and then to execute any individual HALCMD commands.
#
# list of hal config files to run through halcmd
# files are executed in the order in which they appear
HALFILE = lathe.hal
HALFILE = axis_manualtoolchange.hal
HALFILE = simulated_home.hal
HALUI = halui
# Trajectory planner section --------------------------------------------------
[HALUI]
#No Content
[TRAJ]
AXES = 2
COORDINATES = X Z
HOME = 0 0 0
LINEAR_UNITS = mm
ANGULAR_UNITS = degree
CYCLE_TIME = 0.010
DEFAULT_VELOCITY = 120
POSITION_FILE = position.txt
MAX_LINEAR_VELOCITY = 120
NO_FORCE_HOMING = 1
# Axes sections ---------------------------------------------------------------
# First axis
[EMCIO]
# Name of IO controller program, e.g., io
EMCIO = io
# cycle time, in seconds
CYCLE_TIME = 0.100
# tool table file
TOOL_TABLE = tool.tbl
[KINS]
KINEMATICS = trivkins coordinates=XZ
#This is a best-guess at the number of joints, it should be checked
JOINTS = 2
[AXIS_X]
MIN_LIMIT = -1
MAX_LIMIT = 400.0
MAX_VELOCITY = 120
MAX_ACCELERATION = 1000.0
[JOINT_0]
TYPE = LINEAR
HOME = 0.000
MAX_VELOCITY = 120
MAX_ACCELERATION = 1000.0
BACKLASH = 0.000
INPUT_SCALE = 4000
OUTPUT_SCALE = 1.00072
MIN_LIMIT = -1
0
MAX_LIMIT = 400.0
FERROR = 0.050
MIN_FERROR = 0.010
HOME_OFFSET = 0.0
HOME_SEARCH_VEL = 200.0
HOME_LATCH_VEL = 200.0
HOME_USE_INDEX = NO
HOME_IGNORE_LIMITS = NO
HOME_SEQUENCE = 0
[AXIS_Z]
MIN_LIMIT = 0
MAX_LIMIT = 1000
MAX_VELOCITY = 400
MAX_ACCELERATION = 1000.0
[JOINT_1]
TYPE = LINEAR
HOME = 0.000
MAX_VELOCITY = 400
MAX_ACCELERATION = 1000.0
BACKLASH = 0.000
INPUT_SCALE = 4000
OUTPUT_SCALE = 1.000
MIN_LIMIT = 0
MAX_LIMIT = 1000
FERROR = 0.050
MIN_FERROR = 0.010
HOME_OFFSET = 0.0
HOME_SEARCH_VEL = 200.0
HOME_LATCH_VEL = 200.0
HOME_USE_INDEX = NO
HOME_IGNORE_LIMITS = NO
HOME_SEQUENCE = 1
This diff is collapsed.
;boring
O<boring> sub
#<ccomp> = #<_ccomp>
#<metric> = #<_metric>
#<absolute> = #<_absolute>
#<feed> = #<_feed>
#<coord_system> = #<_coord_system>
#<lathe_diameter_mode> = #<_lathe_diameter_mode>
#<ijk_absolute_mode> = #<_ijk_absolute_mode>
G8 ; Lathe radius Mode
G90 ; Absolute Distance
G91.1 ; but not for arcs
; #1 X coord
; #2 surface speed
; #3 cut size
; #4 feed/rpm
; #5 Z coord
; #6 radius
; #7 angle
; #8 tool number
; #9 coolant
O10 if [#9 EQ 1]
M8
O10 endif
;M6 T#8 G43
O100 if [#8 NE #<_current_tool>]
(MSG, ERROR : Set tool before use macro)
O<restore> call [#<metric>] [#<absolute>] [#<feed>] [#<ccomp>] [#<coord_system>] [#<lathe_diameter_mode>] [#<ijk_absolute_mode>]
O100 return [-2] ; indicate failure to epilog
O100 endif
#1 = [#1 / 2] ; because of radius mode
#14 = [#<_x>] (startinG X)
#13 = #<_z> (startinG Z)
#20 = [#6 * SIN[#7]]
#21 = [-#6 * COS[#7]]
#22 = [#6 / COS[#7]]
#23 = [#5 + #6 - #20]
#24 = [[#23 - #13] * TAN[#7]]
G96 D2500 S#2 ; Constant Surface Speed Mode
M3 ;Start Spindle
G95 F#4 ; Feed-Per-Rev Mode
G4P1 ; Wait to reach speed
(debuG, TurninG finish dia #1 start dia #14 start lenGth #13 finish lenGth #5)
O101 WHILE [#14 LT [#1 - #3]]
G0 X #14
#14=[#14 + #3]
G1 X #14
G1 Z #23 X[#14 + #24]
o102 IF [#6 GT 0]
G3 Z#5 X[#14 + #24 + #21] I#21 K#20
G1 X[#14 + #24 + #21 - #3]
o102 ELSE
G1 X[#14 + #24 - [#3 * 1.5]]
o102 ENDIF
G0 Z[#13]
O101 ENDWHILE
G0 X#1
G1 Z#23 X[#1 + #24]
O103 IF [#6 GT 0]
G3 Z#5 X[#1 + #24 + #21] I#21 K#20
G1 X[#1 + #24 + #21 - #3]
O103 ELSE
G1 X[#1 + #24 - #3]
O103 ENDIF
G0 Z#13
G0 X#1 ; For touch-off
M5
M9
; restore g20/21, g90/g91, feed
O<restore> call [#<metric>] [#<absolute>] [#<feed>] [#<ccomp>] [#<coord_system>] [#<lathe_diameter_mode>] [#<ijk_absolute_mode>]
O<boring> endsub
M2
%
;chamfer
O<chamfer> sub
#<ccomp> = #<_ccomp>
#<metric> = #<_metric>
#<absolute> = #<_absolute>
#<feed> = #<_feed>
#<coord_system> = #<_coord_system>
#<lathe_diameter_mode> = #<_lathe_diameter_mode>
#<ijk_absolute_mode> = #<_ijk_absolute_mode>
G8 ; Lathe radius Mode
G90 ; Absolute Distance
; #1 X coord
; #2 feed/rpm
; #3 0.5 ?
; #4 0 ?
; #5 Z coord
; #6 tool number
; #7 0 ?
; #8 chamfer size
; #9 exterior front
; #10 interior
; #11 exterior rear
; #12 coolant
O10 if [#12 EQ 1]
M8
O10 endif
;M6 T#6 G43
O100 if [#6 NE #<_current_tool>]
(MSG, ERROR : Set tool before use macro)
O<restore> call [#<metric>] [#<absolute>] [#<feed>] [#<ccomp>] [#<coord_system>] [#<lathe_diameter_mode>] [#<ijk_absolute_mode>]
O100 return [-2] ; indicate failure to epilog
O100 endif
#1 = [#1 / 2] ; because of radius mode
#14 = [#<_x>] (starting X)
#13 = [#<_z>] (starting Z)
G96 D2500 S#2 ; Constant Surface Speed Mode
M3
G95 F0.1 ; Feed-Per-Rev Mode
#20 = 0
O101 if [#9 GT 0.5] ; front outside
o102 while [[#20 + #3] lt #8]
#20 = [#20 + #3]
G0 x[#1 - #20] z#13
G1 z#5
G1 x#1 z[#5 - #20]
G1 x #14
G0 z#13
o102 endwhile
G0 x#14 z#13
G0 x[#1 - #8]
G1 z#5
G1 x#1 z[#5 - #8]
G1 x #14
G0 z#13
O101 elseif [#10 GT 0.5] ; front inside
o103 while [[#20 + #3] lt #8]
#20 = [#20 + #3]
G0 x[#1 + #20] z#13
G1 z#5
G1 x#1 z[#5 - #20]
G1 x #14
G0 z#13
o103 endwhile
G0 x#14 z#13
G0 x[#1 + #8]
G1 z#5
G1 x#1 z[#5 - #8]
G1 x #14
G0 z#13
O101 elseif [#11 GT 0.5] ; back outside
o104 while [[#20 + #3] lt #8]
#20 = [#20 + #3]
G0 x[#1 - #20] z#13
G1 z#5
G1 x#1 z[#5 + #20]
G1 x #14
G0 z#13
o104 endwhile
G0 x#14 z#13
G0 x[#1 - #8]
G1 z#5
G1 x#1 z[#5 + #8]
G1 x #14
G0 z#13
O101 endif
M5
M9
; restore g20/21, g90/g91, feed
O<restore> call [#<metric>] [#<absolute>] [#<feed>] [#<ccomp>] [#<coord_system>] [#<lathe_diameter_mode>] [#<ijk_absolute_mode>]
O<chamfer> endsub
M2
%
;drill
O<drill> sub
#<ccomp> = #<_ccomp>
#<metric> = #<_metric>
#<absolute> = #<_absolute>
#<feed> = #<_feed>
#<coord_system> = #<_coord_system>
#<lathe_diameter_mode> = #<_lathe_diameter_mode>
#<ijk_absolute_mode> = #<_ijk_absolute_mode>
G7 ; diameter mode
G90 ; Absolute Distance
; #1 drill diameter
; #2 ydepth
; #3 speed
; #4 feed/rpm
; #5 tool number
; #6 peck amount
; #7 retract amount
; #8 coolant
O10 if [#8 EQ 1]
M8
O10 endif