Problem
Automate a benchtop widget assembly cell that sorts incoming parts by type, assembles two of them into a sub-assembly, and rejects any failed inspection — all with graceful recovery from power loss and hopper overflow.
Approach
A LabVIEW state machine on an NI USB-6009 DAQ. Four optical sensors along the conveyor map to four states; two solenoid gates handle sort decisions; a webcam-based inspection step gates the final accept/reject. Every state transition is written to a journal file so the system can recover to the last consistent state after a power cycle.
Implementation
The control logic uses a PID loop on the conveyor DC motor to hold belt speed within 1 % of setpoint. The hopper sensor triggers an emergency-stop subroutine when overflow is imminent and pings the operator HMI with an audible alert. The LabVIEW dataflow paradigm made parallelism cheap — sensor polling, control, and HMI run in three independent loops with almost no boilerplate.
Sort error rate over 1000 cycle run
Results
Over a 1000-cycle continuous run, sort errors dropped from 4 in the first batch (operator-tuning phase) to 0 in the final eight batches. Recovery from forced power-cycle succeeded in all 10 test pulls.
Lessons
Journalled state machines are dramatically easier to reason about than ad-hoc resume logic. Once the state diagram exists, the journal file is a one-line write per transition — and recovery becomes the same code path as a normal start, just with a non-default initial state.
Gallery

