Trigger and Notify
Add the Mode-Change Trigger
A Mode Change trigger issues a check when an asset enters a mode. The production run supplies both the asset and the item, which fills in the context the FAI requires.
- Open
Machining - First Article Inspectionand go to the Triggers tab. - Add a trigger of type
Mode Changewith modeProduction. - Set Delay
0, Coming Due5, Over Due5and Grace5minutes. - Save and release the check sheet.
Trigger and Complete an FAI
An automatic check only helps if the operator sees it. The Notifications card on the Operator Station's info panel counts checks that are due, and uncoded downtime, and opens them with one click. The Event Notifications dashboard widget lists the same.
- Open
Machine 1's operation page, and tap the mode card on the info panel to open Run Control. - In Run Control, set the mode to
Changeover, then selectSC-2024on the Product tab and click Start Run. The machine enters Production. Close Run Control. - Within a minute, the info panel's Notifications card says 1 quality check coming due; after the trigger's 5 Coming Due minutes it says due. Tap it, then click the check in the list to open Active Checks with Machine 1 selected.
- Open the FAI and confirm the asset and item are filled in.
- Enter three diameters near 25 mm, two lengths, and a visual result, then submit.
- Complete a second FAI on another machine. Trigger a third and leave it unfinished, so the next lesson has some late checks to analyze.
Check Your Work
Copy this script into the Ignition Designer Script Console (Tools → Script Console) and run it. It checks that the FAI is released with an enabled Production Mode Change trigger and the timers from this lesson, that a run start has issued an FAI with its machine and part filled in, that FAIs are completed on two machines with every measurement, and that one is left unfinished. Each check prints PASS or FAIL with what to fix. It doesn't change anything.
Show the check script
# Kanoa Quality Training - check "Trigger and Notify" (First Article Inspection, lesson 3)
#
# Run in the Ignition Designer Script Console (Tools > Script Console), in the
# project that inherits KANOA_SCRIPTS. It only reads; it changes nothing.
# Every check prints PASS or FAIL with what to fix, then a summary.
SHEET = 'Machining - First Article Inspection'
MODE = 'Production'
TIMERS = [('delayMins', 'Delay', 0), ('comingDueMins', 'Coming Due', 5), ('overDueMins', 'Over Due', 5), ('graceMins', 'Grace', 5)]
AREA = 'CoreForge\\Philadelphia\\Machining\\'
FIRST_MACHINE = 'CoreForge\\Philadelphia\\Machining\\Machine 1'
UNFINISHED = ['Coming Due', 'Due', 'Overdue', 'In Progress', 'Missed']
results = []
def check(ok, what, fix=None):
results.append(bool(ok))
if ok:
print 'PASS %s' % what
else:
print 'FAIL %s' % what
if fix:
print ' -> %s' % fix
def note(what):
print 'NOTE %s' % what
def field(row, *names):
for n in names:
if n in row and row[n] is not None:
return row[n]
return None
def text(v):
return '' if v is None else unicode(v).strip()
def key(v):
return ' '.join(text(v).lower().split())
def truthy(v):
return str(v).lower() in ('true', '1', 'yes')
def num(v):
try:
return float(v)
except:
return None
def rows(data):
# Kanoa returns a dataset, a list of dictionaries, or None
if data is None:
return []
if hasattr(data, 'getRowCount'):
cols = list(data.getColumnNames())
return [dict((c, data.getValueAt(i, c)) for c in cols) for i in range(data.getRowCount())]
return [dict(r) for r in data]
def findSheet(name):
"""All versions of a check sheet, and the one to check: the Released version, or else the newest.
A revision renames the archived version '<name> - N' and the open one '<name> - In Revision',
so the other versions are found by their master sheet, not by name."""
sheets = rows(system.kanoa.quality.sheet.getSheets({}))
named = [s for s in sheets if text(field(s, 'chkShtName')) == name] or \
[s for s in sheets if key(field(s, 'chkShtName')) == key(name)]
if not named:
return None, []
masters = set(text(field(s, 'masterChkShtId', 'chkShtId')) for s in named)
versions = [s for s in sheets if text(field(s, 'masterChkShtId', 'chkShtId')) in masters]
versions.sort(key=lambda s: num(field(s, 'chkShtVersionNumber')) or 0)
released = [s for s in versions if text(field(s, 'chkShtVersionStateName')) == 'Released']
return (released or versions)[-1], versions
def millis(v):
return v.getTime() if hasattr(v, 'getTime') else 0
def sheetEvents(versions):
"""Every check event of any version of the sheet, newest first."""
out = []
for s in versions:
out += rows(system.kanoa.quality.event.getChkShtEvents({'chkShtId': field(s, 'chkShtId')}))
out.sort(key=lambda e: millis(field(e, 'scheduledDate', 'takenDate')), reverse=True)
return out
def eventItems(event):
"""The recorded values of a check event, by check item name."""
byName = {}
for r in rows(system.kanoa.quality.event.getChkShtEventItems({'chkShtEventId': field(event, 'chkShtEventId')})):
byName.setdefault(text(field(r, 'chkItemName')), []).append(r)
return byName
def readings(itemRows):
"""The measurements recorded for one check item."""
return [num(field(r, 'chkItemValue')) for r in itemRows or [] if num(field(r, 'chkItemValue')) is not None]
print '=' * 70
print 'Kanoa Quality Training - Trigger and Notify check'
print '=' * 70
sheet, versions = findSheet(SHEET)
if sheet is None:
check(False, 'Check sheet %s exists' % SHEET, 'Build it in the previous lesson first.')
else:
# 1. The mode-change trigger
print '\n-- Mode Change trigger'
triggers = rows(system.kanoa.quality.config.getChkShtTriggers({'chkShtId': field(sheet, 'chkShtId')}))
modeTriggers = [t for t in triggers if text(field(t, 'triggerTypeName')) == 'Mode Change']
if not modeTriggers:
check(False, 'It has a Mode Change trigger', 'On the Triggers tab, add a trigger of type Mode Change with mode %s.' % MODE)
else:
t = ([m for m in modeTriggers if text(field(m, 'modeName')) == MODE] or modeTriggers)[0]
check(text(field(t, 'modeName')) == MODE, 'The trigger is for mode %s' % MODE,
"It's for '%s'. Edit the trigger and set the mode to %s." % (text(field(t, 'modeName')) or 'no mode', MODE))
check(truthy(field(t, 'enabled')), 'The trigger is enabled', 'Edit the trigger and select Enabled.')
for col, label, expected in TIMERS:
actual = num(field(t, col))
check(actual == expected, '%s is %d minutes' % (label, expected),
"It's %s. Edit the Mode Change trigger and set %s to %d." % (text(field(t, col)) or 'blank', label, expected))
state = text(field(sheet, 'chkShtVersionStateName'))
check(state == 'Released', 'The check sheet is Released',
"It's %s. Close the editor and change its status to Released." % (state or 'not set'))
# 2. Inspections issued by the trigger
print '\n-- Inspections'
events = sheetEvents(versions)
triggered = [e for e in events if text(field(e, 'triggerTypeName')) == 'Mode Change']
check(triggered, 'A run start has issued an FAI (%d so far)' % len(triggered),
"In Run Control for Machine 1, set the mode to Changeover, pick SC-2024 on the Product tab and click Start Run. "
"If nothing appears, check Machine 1 has Enable Quality Triggers selected.")
if triggered:
withContext = [e for e in triggered if text(field(e, 'assetPath')) and text(field(e, 'itemName'))]
check(withContext, 'Issued FAIs have the machine and the part filled in',
'The run supplies them. Start the run with a product selected on the Product tab.')
if not [e for e in triggered if text(field(e, 'assetPath')) == FIRST_MACHINE]:
note('No FAI was issued on Machine 1 yet. The lesson starts with Machine 1.')
approved = [e for e in events if text(field(e, 'chkShtStateName')) == 'Approved']
machines = sorted(set(text(field(e, 'assetPath')).split('\\')[-1] for e in approved if text(field(e, 'assetPath')).startswith(AREA)))
check(len(machines) >= 2, 'FAIs are completed on two machines (%s)' % (', '.join(machines) or 'none'),
'Complete an FAI on Machine 1 and another on a second machine: enter three diameters, two lengths and a visual result, then submit.')
if approved:
byName = eventItems(approved[0])
diameters = readings(byName.get('Diameter'))
lengths = readings(byName.get('Length'))
check(len(diameters) >= 3 and len(lengths) >= 2, 'The latest completed FAI has three diameters and two lengths',
'It has %d diameter and %d length reading(s). Enter every measurement before submitting.' % (len(diameters), len(lengths)))
if not [r for r in byName.get('Visual Defect Check', []) if text(field(r, 'chkItemValue'))]:
note('The latest completed FAI has no visual result.')
unfinished = [e for e in events if text(field(e, 'chkShtStateName')) in UNFINISHED]
check(unfinished, 'An FAI is left unfinished, for the next lesson to analyze',
'Start a run on another machine and leave its FAI unfinished.')
passed = results.count(True)
print '\n' + '=' * 70
print 'Result: %d of %d checks passed' % (passed, len(results))
if passed == len(results):
print 'All good. Your FAI is triggered by production runs.'
else:
print 'Fix the FAIL items above, then run this again.'
print '=' * 70
check-sheet-machining-first-article-inspection.json: the finished FAI check sheet, including the FAI Diameter tolerances, to compare with your build.