summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Haberler <git@mah.priv.at>2011-08-13 08:14:30 +0200
committerMichael Haberler <git@mah.priv.at>2011-10-28 08:26:08 +0200
commit58bf1c38dc6c054e935df917b856627cf7590c47 (patch)
tree5b72906ef93f212da089fec6d3f255348b0705d3
parent211212da0d851bdc1b4bb1d65507daafe5afe9ad (diff)
downloadlinuxcnc-58bf1c38dc6c054e935df917b856627cf7590c47.tar.gz
linuxcnc-58bf1c38dc6c054e935df917b856627cf7590c47.zip
catchup
-rw-r--r--configs/sim/pysubs/customtask.py226
-rw-r--r--configs/sim/pysubs/sqltooltable.py46
-rw-r--r--src/emc/task/emctaskmain.cc2
-rw-r--r--src/emc/toolstore/sql/schema-simple.sql46
4 files changed, 203 insertions, 117 deletions
diff --git a/configs/sim/pysubs/customtask.py b/configs/sim/pysubs/customtask.py
index 0ced4aa8e..010cb29ec 100644
--- a/configs/sim/pysubs/customtask.py
+++ b/configs/sim/pysubs/customtask.py
@@ -7,6 +7,7 @@ import hal
import tooltable
import sqltooltable
import emc # ini only
+import sys, traceback
try:
import cPickle as pickle
@@ -21,67 +22,90 @@ except ImportError:
def debug():
return interpreter.this.debugmask & 0x00040000 # EMC_DEBUG_PYTHON_TASK
-class CustomTask(emctask.Task,UserFuncs):
+def myexcepthook(exctype, value, traceback):
+ if exctype == KeyboardInterrupt:
+ print "Handler code goes here"
+ else:
+ _old_excepthook(exctype, value, traceback)
- def __init__(self):
- if debug(): print "py: CustomTask()"
- emctask.Task.__init__(self)
+import signal, time
- self.inifile = emc.ini(emctask.ini_filename())
- yn = self.inifile.find("PYTHON", "TASK_TOOLCHANGE_PINS")
- self.tcpins = int(yn) if yn else 0
- yn = self.inifile.find("PYTHON", "TASK_START_CHANGE_PINS")
- self.startchange_pins = self.tcpins and (int(yn) if yn else 0)
- yn = self.inifile.find("PYTHON", "TASK_TOOLCHANGE_FAULT_PINS")
- self.fault_pins = self.tcpins and (int(yn) if yn else 0)
+def handler(signum, frame):
+ print 'I just clicked on CTRL-C '
- h = hal.component("iocontrol.0")
- h.newpin("coolant-flood", hal.HAL_BIT, hal.HAL_OUT)
- h.newpin("coolant-mist", hal.HAL_BIT, hal.HAL_OUT)
- h.newpin("lube-level", hal.HAL_BIT, hal.HAL_OUT)
- h.newpin("lube", hal.HAL_BIT, hal.HAL_OUT)
+class CustomTask(emctask.Task,UserFuncs):
- h.newpin("emc-enable-in", hal.HAL_BIT, hal.HAL_IN)
- h.newpin("user-enable-out", hal.HAL_BIT, hal.HAL_OUT)
- h.newpin("user-request-enable", hal.HAL_BIT, hal.HAL_OUT)
+ def __init__(self):
+ ## global _old_excepthook
+ ## _old_excepthook = sys.excepthook
+ ## sys.excepthook = myexcepthook
+ signal.signal(signal.SIGINT, handler)
+ signal.signal(signal.SIGTERM, handler)
+
+
+ try:
+ if debug(): print "py: CustomTask()"
+ emctask.Task.__init__(self)
+ self.inifile = emc.ini(emctask.ini_filename())
+ #self.random_toolchanger = int(self.inifile.find("EMCIO", "RANDOM_TOOLCHANGER") or 0)
+ self.tcpins = int(self.inifile.find("PYTHON", "TASK_TOOLCHANGE_PINS") or 0)
+ self.startchange_pins = int(self.inifile.find("PYTHON", "TASK_START_CHANGE_PINS") or 0)
+ self.fault_pins = int(self.inifile.find("PYTHON", "TASK_TOOLCHANGE_FAULT_PINS") or 0)
+
+ h = hal.component("iocontrol.0")
+ h.newpin("coolant-flood", hal.HAL_BIT, hal.HAL_OUT)
+ h.newpin("coolant-mist", hal.HAL_BIT, hal.HAL_OUT)
+
+ h.newpin("lube-level", hal.HAL_BIT, hal.HAL_OUT)
+ h.newpin("lube", hal.HAL_BIT, hal.HAL_OUT)
+
+ h.newpin("emc-enable-in", hal.HAL_BIT, hal.HAL_IN)
+ h.newpin("user-enable-out", hal.HAL_BIT, hal.HAL_OUT)
+ h.newpin("user-request-enable", hal.HAL_BIT, hal.HAL_OUT)
+
+ if self.tcpins:
+ h.newpin("tool-change", hal.HAL_BIT, hal.HAL_OUT)
+ h.newpin("tool-changed", hal.HAL_BIT, hal.HAL_IN)
+ h.newpin("tool-number", hal.HAL_S32, hal.HAL_OUT)
+ h.newpin("tool-prep-number", hal.HAL_S32, hal.HAL_OUT)
+ h.newpin("tool-prep-pocket", hal.HAL_S32, hal.HAL_OUT)
+ h.newpin("tool-prepare", hal.HAL_BIT, hal.HAL_OUT)
+ h.newpin("tool-prepared", hal.HAL_BIT, hal.HAL_IN)
+ if self.startchange_pins:
+ h.newpin("start-change", hal.HAL_BIT, hal.HAL_OUT)
+ h.newpin("start-change-ack", hal.HAL_BIT, hal.HAL_IN)
+ if self.fault_pins:
+ h.newpin("emc-abort", hal.HAL_BIT, hal.HAL_OUT)
+ h.newpin("emc-abort-ack", hal.HAL_BIT, hal.HAL_IN)
+ h.newpin("emc-reason", hal.HAL_S32, hal.HAL_OUT)
+ h.newpin("toolchanger-fault", hal.HAL_BIT, hal.HAL_IN)
+ h.newpin("toolchanger-fault-ack", hal.HAL_BIT, hal.HAL_OUT)
+ h.newpin("toolchanger-reason", hal.HAL_S32, hal.HAL_IN)
+ h.newpin("toolchanger-faulted", hal.HAL_BIT, hal.HAL_OUT)
+ h.newpin("toolchanger-clear-fault", hal.HAL_BIT, hal.HAL_IN)
+
+ h.ready()
+ self.components = dict()
+ self.components["iocontrol.0"] = h
+ self.hal = h
+ self.hal_init_pins()
+ self.e = emctask.emcstat
+ self.e.io.aux.estop = 1
+ self._callback = None
+ self._check = None
+ tt = self.e.io.tool.toolTable
+ for p in range(0,len(tt)):
+ tt[p].zero()
+ UserFuncs.__init__(self)
+ self.enqueue = EnqueueCall(self)
+ except Exception,e:
+ print "__init__"
+ print_exc_plus()
+ self.e.io.status = emctask.RCS_STATUS.RCS_ERROR
+ else:
+ self.e.io.status = emctask.RCS_STATUS.RCS_DONE
- if self.tcpins:
- h.newpin("tool-change", hal.HAL_BIT, hal.HAL_OUT)
- h.newpin("tool-changed", hal.HAL_BIT, hal.HAL_IN)
- h.newpin("tool-number", hal.HAL_S32, hal.HAL_OUT)
- h.newpin("tool-prep-number", hal.HAL_S32, hal.HAL_OUT)
- h.newpin("tool-prep-pocket", hal.HAL_S32, hal.HAL_OUT)
- h.newpin("tool-prepare", hal.HAL_BIT, hal.HAL_OUT)
- h.newpin("tool-prepared", hal.HAL_BIT, hal.HAL_IN)
- if self.startchange_pins:
- h.newpin("start-change", hal.HAL_BIT, hal.HAL_OUT)
- h.newpin("start-change-ack", hal.HAL_BIT, hal.HAL_IN)
- if self.fault_pins:
- h.newpin("emc-abort", hal.HAL_BIT, hal.HAL_OUT)
- h.newpin("emc-abort-ack", hal.HAL_BIT, hal.HAL_IN)
- h.newpin("emc-reason", hal.HAL_S32, hal.HAL_OUT)
- h.newpin("toolchanger-fault", hal.HAL_BIT, hal.HAL_IN)
- h.newpin("toolchanger-fault-ack", hal.HAL_BIT, hal.HAL_OUT)
- h.newpin("toolchanger-reason", hal.HAL_S32, hal.HAL_IN)
- h.newpin("toolchanger-faulted", hal.HAL_BIT, hal.HAL_OUT)
- h.newpin("toolchanger-clear-fault", hal.HAL_BIT, hal.HAL_IN)
-
- h.ready()
- self.components = dict()
- self.components["iocontrol.0"] = h
- self.hal = h
- self.hal_init_pins()
- self.e = emctask.emcstat
- self.e.io.aux.estop = 1
- self._callback = None
- self._check = None
- tt = self.e.io.tool.toolTable
- for p in range(0,len(tt)):
- tt[p].zero()
- UserFuncs.__init__(self)
- self.enqueue = EnqueueCall(self)
- self.e.io.status = emctask.RCS_STATUS.RCS_DONE
def emcIoInit(self):
if debug(): print "py: emcIoInit tt=",self.tooltable_filename
@@ -105,22 +129,26 @@ class CustomTask(emctask.Task,UserFuncs):
self.fms = dict()
self.tt.load(self.e.io.tool.toolTable,self.comments,self.fms)
#self.tt.save(self.e.io.tool.toolTable,self.comments,self.fms)
+ # self.e.io.tool.toolInSpindle = 2 # works
self.reload_tool_number(self.e.io.tool.toolInSpindle)
except Exception,e:
- print "emcIoInit:",e
+ print "emcIoInit",e
+ print_exc_plus()
self.e.io.status = emctask.RCS_STATUS.RCS_ERROR
else:
self.e.io.status = emctask.RCS_STATUS.RCS_DONE
return 0
def emcToolLoadToolTable(self,file):
+ # triggered by UI if tooltable was edited
if debug(): print "py: emcToolLoadToolTable file =",file
self.comments = dict()
self.fms = dict()
try:
self.tt.load(self.e.io.tool.toolTable,self.comments,self.fms)
except Exception,e:
+ print_exc_plus()
self.e.io.status = emctask.RCS_STATUS.RCS_ERROR
else:
self.reload_tool_number(self.e.io.tool.toolInSpindle)
@@ -194,7 +222,10 @@ class CustomTask(emctask.Task,UserFuncs):
self.e.io.status = emctask.RCS_STATUS.RCS_DONE
return 0
- if not self.random_toolchanger and (self.e.io.tool.pocketPrepped > 0) and self.e.io.tool.toolInSpindle == self.e.io.tool.toolTable[self.e.io.tool.pocketPrepped].toolno:
+ if not self.random_toolchanger and (self.e.io.tool.pocketPrepped > 0) and (
+ self.e.io.tool.toolInSpindle ==
+ self.e.io.tool.toolTable[self.e.io.tool.pocketPrepped].toolno):
+
self.e.io.status = emctask.RCS_STATUS.RCS_DONE
return 0
@@ -372,24 +403,36 @@ class CustomTask(emctask.Task,UserFuncs):
return 0
def emcIoUpdate(self):
- # if debug(): print "py: emcIoUpdate"
- self.hal["user-request-enable"] = 0
- self.e.io.aux.estop = not self.hal["emc-enable-in"]
- if self.fault_pins:
- if self.hal["toolchanger-fault"]:
- self.e.io.reason = self.hal["toolchanger-reason"]
- self.hal["toolchanger-fault-ack"] = 1
- self.hal["toolchanger-faulted"] = 1 # fault indicator latch
- self.e.io.fault = 1
+ try:
+ #if debug(): print "py: emcIoUpdate"
+ self.hal["user-request-enable"] = 0
+ self.e.io.aux.estop = not self.hal["emc-enable-in"]
+ if self.fault_pins:
+ if self.hal["toolchanger-fault"]:
+ self.e.io.reason = self.hal["toolchanger-reason"]
+ self.hal["toolchanger-fault-ack"] = 1
+ self.hal["toolchanger-faulted"] = 1 # fault indicator latch
+ self.e.io.fault = 1
+ return 0
+ else:
+ self.hal["toolchanger-fault-ack"] = 0
+ if self.hal["toolchanger-clear-fault"]:
+ self.hal["toolchanger-faulted"] = 0 # reset fault indicator latch
+ self.e.io.reason = 0
+ if self._check:
+ self.e.io.status = self._check()
return 0
- else:
- self.hal["toolchanger-fault-ack"] = 0
- if self.hal["toolchanger-clear-fault"]:
- self.hal["toolchanger-faulted"] = 0 # reset fault indicator latch
- self.e.io.reason = 0
- if self._check:
- self.e.io.status = self._check()
- return 0
+ except KeyboardInterrupt: # shutting down
+ print "emcIoUpdate----KeyboardInterrupt:"
+
+ return -1
+ pass
+ except Exception, e:
+ print "emcIoUpdate----:"
+ print_exc_plus()
+ return -1
+ else:
+ return 0
def wait_for_named_pin_callback(self):
if self._comp[self._pin] == self._value:
@@ -459,3 +502,38 @@ class EnqueueCall(object):
def __getattr__(self, name):
self._name = name
return self._encode
+
+## {{{ http://code.activestate.com/recipes/52215/ (r1)
+
+def print_exc_plus():
+ """
+ Print the usual traceback information, followed by a listing of all the
+ local variables in each frame.
+ """
+ tb = sys.exc_info()[2]
+ while 1:
+ if not tb.tb_next:
+ break
+ tb = tb.tb_next
+ stack = []
+ f = tb.tb_frame
+ while f:
+ stack.append(f)
+ f = f.f_back
+ stack.reverse()
+ traceback.print_exc()
+ print "Locals by frame, innermost last"
+ for frame in stack:
+ print
+ print "Frame %s in %s at line %s" % (frame.f_code.co_name,
+ frame.f_code.co_filename,
+ frame.f_lineno)
+ for key, value in frame.f_locals.items():
+ print "\t%20s = " % key,
+ #We have to be careful not to cause a new error in our error
+ #printer! Calling str() on an unknown object could cause an
+ #error we don't want.
+ try:
+ print value
+ except:
+ print "<ERROR WHILE PRINTING VALUE>"
diff --git a/configs/sim/pysubs/sqltooltable.py b/configs/sim/pysubs/sqltooltable.py
index 0816b9ade..a59c27842 100644
--- a/configs/sim/pysubs/sqltooltable.py
+++ b/configs/sim/pysubs/sqltooltable.py
@@ -2,6 +2,8 @@ import os
import re
import pyodbc
+import sys, traceback
+
class SqlToolTable(object):
'''
@@ -15,6 +17,7 @@ class SqlToolTable(object):
def __init__(self,filename,random_toolchanger):
print "SQL tt init"
+
self.filename = filename
self.random_toolchanger = random_toolchanger
self.conn = pyodbc.connect('Driver=SQLite3;Database=' + self.filename)
@@ -28,22 +31,23 @@ class SqlToolTable(object):
for row in self.cursor.fetchall():
pocket = row.pocket
t = tooltable[pocket]
- if row.toolno: t.toolno = row.toolno
- if row.orientation: t.orientation = row.orientation
- if row.diameter: t.diameter = row.diameter
- if row.frontangle: t.frontangle = row.frontangle
- if row.backangle: t.backangle = row.backangle
- if row.x_offset: t.offset.tran.x = row.x_offset
- if row.y_offset: t.offset.y = row.y_offset
- if row.z_offset: t.offset.z = row.z_offset
- if row.a_offset: t.offset.a = row.a_offset
- if row.b_offset: t.offset.b = row.b_offset
- if row.c_offset: t.offset.c = row.c_offset
- if row.u_offset: t.offset.u = row.u_offset
- if row.v_offset: t.offset.v = row.v_offset
- if row.w_offset: t.offset.w = row.w_offset
- except Exception,e:
- print "---- load:",e
+ t.toolno = row.toolno
+ t.orientation = row.orientation
+ t.diameter = row.diameter
+ t.frontangle = row.frontangle
+ t.backangle = row.backangle
+ t.offset.tran.x = row.x_offset
+ t.offset.y = row.y_offset
+ t.offset.z = row.z_offset
+ t.offset.a = row.a_offset
+ t.offset.b = row.b_offset
+ t.offset.c = row.c_offset
+ t.offset.u = row.u_offset
+ t.offset.v = row.v_offset
+ t.offset.w = row.w_offset
+
+ except pyodbc.Error, e:
+ traceback.print_exc(file=sys.stdout)
else:
start = 0 if self.random_toolchanger else 1
for p in range(start,len(tooltable)):
@@ -51,7 +55,7 @@ class SqlToolTable(object):
if t.toolno != -1: print str(t)
def save(self, tooltable, comments,fms):
- print "SQL save"
+ print "SQL save",
try:
self.cursor.execute("delete from tools;")
start = 0 if self.random_toolchanger else 1
@@ -64,5 +68,9 @@ class SqlToolTable(object):
t.offset.c,t.offset.u,t.offset.v,t.offset.w))
self.cursor.execute("commit;")
- except Exception,e:
- print "---- save:",e
+ print "done"
+
+ except pyodbc.Error, msg:
+ traceback.print_exc(file=sys.stdout)
+ print "saving tooltable to %s failed" % (self.filename)
+
diff --git a/src/emc/task/emctaskmain.cc b/src/emc/task/emctaskmain.cc
index 6092d0371..699dd0d40 100644
--- a/src/emc/task/emctaskmain.cc
+++ b/src/emc/task/emctaskmain.cc
@@ -152,7 +152,7 @@ static void emctask_quit(int sig)
{
// set main's done flag
done = 1;
-
+ printf("-------------main done\n");
// restore signal handler
signal(sig, emctask_quit);
}
diff --git a/src/emc/toolstore/sql/schema-simple.sql b/src/emc/toolstore/sql/schema-simple.sql
index 15cabec6a..513a572c5 100644
--- a/src/emc/toolstore/sql/schema-simple.sql
+++ b/src/emc/toolstore/sql/schema-simple.sql
@@ -5,35 +5,35 @@ DROP TABLE IF EXISTS "tools";
CREATE TABLE "tools" (
- toolno INTEGER PRIMARY KEY, -- AUTOINCREMENT,
+ toolno INTEGER PRIMARY KEY,
pocket INTEGER,
- diameter REAL DEFAULT (NULL),
- backangle REAL DEFAULT (NULL),
- frontangle REAL DEFAULT (NULL),
- orientation INTEGER DEFAULT (NULL),
+ diameter REAL DEFAULT (0.0),
+ backangle REAL DEFAULT (0.0),
+ frontangle REAL DEFAULT (0.0),
+ orientation INTEGER DEFAULT (0.0),
comment TEXT DEFAULT (NULL),
- x_offset REAL DEFAULT (NULL),
- y_offset REAL DEFAULT (NULL),
- z_offset REAL DEFAULT (NULL),
- a_offset REAL DEFAULT (NULL),
- b_offset REAL DEFAULT (NULL),
- c_offset REAL DEFAULT (NULL),
- u_offset REAL DEFAULT (NULL),
- v_offset REAL DEFAULT (NULL),
- w_offset REAL DEFAULT (NULL)
+ x_offset REAL DEFAULT (0.0),
+ y_offset REAL DEFAULT (0.0),
+ z_offset REAL DEFAULT (0.0),
+ a_offset REAL DEFAULT (0.0),
+ b_offset REAL DEFAULT (0.0),
+ c_offset REAL DEFAULT (0.0),
+ u_offset REAL DEFAULT (0.0),
+ v_offset REAL DEFAULT (0.0),
+ w_offset REAL DEFAULT (0.0)
);
-INSERT INTO "tools" VALUES (1,2,4.0, NULL,NULL,NULL,"tool1",1.2,NULL,3.7,NULL,NULL,NULL,NULL,NULL,NULL);
-INSERT INTO "tools" VALUES (2,1,2.0, NULL,NULL,NULL,"tool2",0.2,NULL,1.2,NULL,NULL,NULL,NULL,NULL,NULL);
-INSERT INTO "tools" VALUES (3,7,3.3, NULL,NULL,NULL,"tool3",3.2,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL);
-INSERT INTO "tools" VALUES (4,3,1.2, NULL,NULL,NULL,"tool4",NULL,NULL,5.9,NULL,NULL,NULL,NULL,NULL,NULL);
-INSERT INTO "tools" VALUES (5,5,6.2, NULL,NULL,NULL,"tool5",NULL,NULL,1.1,NULL,NULL,NULL,NULL,NULL,NULL);
-INSERT INTO "tools" VALUES (6,9,1.9, NULL,NULL,NULL,"tool6",NULL,NULL,3.4,NULL,NULL,NULL,NULL,NULL,NULL);
-INSERT INTO "tools" VALUES (7,8,0.3, NULL,NULL,NULL,"tool7",NULL,NULL,1.7,NULL,NULL,NULL,NULL,NULL,NULL);
-INSERT INTO "tools" VALUES (8,11,2.50, NULL,NULL,NULL,"tool8",NULL,NULL,2.7,NULL,NULL,NULL,NULL,NULL,NULL);
-INSERT INTO "tools" VALUES (9,24,1.1, NULL,NULL,NULL,"tool9",NULL,NULL,4.9,NULL,NULL,NULL,NULL,NULL,NULL);
+INSERT INTO "tools" VALUES (1,2,4.0, 0.0,0.0,0.0,"tool1",1.2,0.0,3.7,0.0,0.0,0.0,0.0,0.0,0.0);
+INSERT INTO "tools" VALUES (2,1,2.0, 0.0,0.0,0.0,"tool2",0.2,0.0,1.2,0.0,0.0,0.0,0.0,0.0,0.0);
+INSERT INTO "tools" VALUES (3,7,3.3, 0.0,0.0,0.0,"tool3",3.2,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0);
+INSERT INTO "tools" VALUES (4,3,1.2, 0.0,0.0,0.0,"tool4",0.0,0.0,5.9,0.0,0.0,0.0,0.0,0.0,0.0);
+INSERT INTO "tools" VALUES (5,5,6.2, 0.0,0.0,0.0,"tool5",0.0,0.0,1.1,0.0,0.0,0.0,0.0,0.0,0.0);
+INSERT INTO "tools" VALUES (6,9,1.9, 0.0,0.0,0.0,"tool6",0.0,0.0,3.4,0.0,0.0,0.0,0.0,0.0,0.0);
+INSERT INTO "tools" VALUES (7,8,0.3, 0.0,0.0,0.0,"tool7",0.0,0.0,1.7,0.0,0.0,0.0,0.0,0.0,0.0);
+INSERT INTO "tools" VALUES (8,11,2.50, 0.0,0.0,0.0,"tool8",0.0,0.0,2.7,0.0,0.0,0.0,0.0,0.0,0.0);
+INSERT INTO "tools" VALUES (9,24,1.1, 0.0,0.0,0.0,"tool9",0.0,0.0,4.9,0.0,0.0,0.0,0.0,0.0,0.0);