Digital Twin of a Flexible CNC Manufacturing Cell

Industry challenge with ORZA Tech — virtual CNC cell commissioned 100 % in software (S7-1500 PLC programming in TIA Portal, UR5 VRC, CAM and G-code, Cognex vision, SCADA/KPIs)

A fully virtual CNC milling cell commissioned with zero physical hardware. A virtual S7-1500 runs the ladder program, Process Simulate drives the 3D cell, a Virtual Robot Controller runs the UR5 pick-and-place program, a Cognex inspector classifies each part (pass / rework / scrap), a WinCC HMI gives the operator automatic and manual control, and a SCADA dashboard tracks OEE and KPIs in real time. Behind the machining step is a six-tool milling program for an aluminium piston body that I analysed down to chip load and cycle time (≈ 12.8 min), and the same course added a Cognex inspection exam and a lathe CAM exercise that I carried from stock definition to G-code.

Walkthrough with narration: scrapping a part, the CNC cell working in Process Simulate, and an explanation of how the HMI and the PLC logic run together with the simulation.

Design at a glance

Cell layout in Process Simulate
Cell layout in Process Simulate
Part P2 in SOLIDWORKS CAM
Part P2 in SOLIDWORKS CAM
My CNC milling station
My CNC milling station
SCADA: OEE, cycle time, scrap
SCADA: OEE, cycle time, scrap

Design decisions, from first principles

Decision Engineering reasoning Result
Interlock every move against twin sensors, no timers The PLC program is what goes to the real machine unchanged, so it must react to the plant, not to assumed times Full cycles incl. rework and scrap branches
Check the chip load by hand fz = 1645.9 / (12 000 × 2) ≈ 0.069 mm/tooth, inside 0.05–0.13 mm for aluminium Cycle ≈ 12.8 min; spindle speed flagged as too high for the lab machine
Spot-drill before the small holes A short, stiff spot drill keeps the thin Ø1.75 mm drill from wandering Correct hole positions in simulation
Validate the Cognex inspection against calipers Reflective foil creates bright edges that the outline tool reads as part edges Found a 3.7–3.9 % oversize and documented the fix
Full technical write-up

Challenge

Design, implement and validate a virtual digital twin of a flexible manufacturing cell — supplier, three CNC stations, intralogistics, quality inspection, assembly and warehouse — with simulated industrial communication, two operating modes, traceability and KPIs. Everything is virtual: no physical PLCs, robots or AGVs. Automation of Manufacturing Systems, Tec de Monterrey, challenge proposed by ORZA Tech; team of three, one CNC station per member.

Manufacturing cell workflow
Material flow: supplier, transport, CNC machining, quality inspection (pass, rework or scrap), assembly and warehouse.
Network diagram of the three workstations
Real network: three workstations on one Ethernet switch, each running Process Simulate, a VMware Tecnomatix server, a Modbus sensor and a PLCSIM Advanced instance.

My contribution — CNC milling cell (Station 3)

  • PLC program (core of the challenge): the complete ladder program in TIA Portal for a virtual S7-1500 in PLCSIM Advanced: 35-step sequence, interlocks, safety stop, manual mode, quality routing, recipes, KPIs and logging
  • Digital twin: my cell in Process Simulate (supplier rack with pneumatic actuator, AGV, two conveyors, three UR5 robots, CNC milling machine and inspection camera), with every actuator and sensor mapped to PLC I/O
  • Robot integration: a UR5 in Virtual Robot Controller mode running its own PolyScope program, synchronised with the PLC through a digital handshake
  • HMI and SCADA: the WinCC operator screens of the cell and the plant-wide KPI screen
  • Machining: the SOLIDWORKS CAM model of part P2 and a block-by-block analysis of its G-code
  • Communication: a C# Modbus TCP field sensor and the S7 GET/PUT link to the assembly station, with an alarm when the link fails
  • Layout concept: proposed the ladder-type layout of the full system

The team built the full layout in Process Simulate and integrated the three PCs over one Ethernet switch.

Top view of the cell layout
Top view of the line operation in Process Simulate: conveyors, AGV path, CNC cells and robots.
CNC station with UR5 robots
CNC station: two UR5 robots load and unload the milling machine and present the part to the camera.

PLC program

The cell runs as a chain of step flags (K1 … K35): supply, AGV transport, loading by a UR5, machining, unloading and inspection, routing and cycle close. A step advances only when the twin confirms the previous action really finished — a sensor, a door, the machine’s done signal — never on a timer. In a virtual commissioning the PLC is the part that would go to the real machine unchanged, so any wrong assumption showed up as a stuck part, a collision or a cell that never finished.

  • Interlocks: a function block turns raw sensor signals into named bits (part present, CNC ready, conveyor clear), so wiring and sequence stay decoupled
  • Safety: one global stop contact sits in every step rung; any alarm puts the cell in Fault until it is reset from the HMI
  • Manual mode: every step can be driven from the HMI, but only in manual mode, so manual and automatic commands cannot fight each other
  • Routing and recipes: the inspection result (OK, rework, scrap) is locked by the PLC and decides the next conveyor; a FIFO recipe queue sets which stations a part type needs and the batch size
  • KPIs: yield, scrap rate and Micro OEE computed in the PLC every cycle, with a 100-entry retentive log that survives a restart
HMI main menu
Main menu.
Station monitor screen
Station monitor: mode, current process, station progress and batch quantity.
Supplier and conveyor screen
Supplier and conveyor screen with manual commands.
CNC and quality inspection screen
CNC and quality inspection: manual machining commands and the OK / rework / scrap result.
DATA_LOG data block
The retentive DATA_LOG block with counters, KPIs, alarm bits and the 100-entry log.
SCADA counters and trends
Global SCADA screen at the end of a demonstration run: 11 parts, 11 OK, 0 scrap, with yield, scrap and Micro OEE trends.

CAM & G-code

Part P2 is an aluminium piston body of 32 × 20 × 20 mm with a Ø16 bore, a pocket and two pairs of small holes, machined with six tools: spot drill and Ø16 peck drilling, a centre drill before the small holes so the thin drill does not wander, pocket roughing in eight Z levels, and seven contour passes with cutter compensation (G41), so tool wear is corrected with one offset value. I recalculated every surface speed (vc = π·D·n/1000) and the chip load, fz ≈ 0.069 mm/tooth, inside the 0.05–0.13 mm range for aluminium. The estimated cycle is 12.8 min, 72 % of it roughing; the weak point is the 12 000 rpm spindle speed, fine in simulation but above what the lab machine runs.

Technical drawing of part P2
Technical drawing of P2 (SOLIDWORKS, scale 2:1).
P2 inside its billet in SOLIDWORKS CAM
P2 inside the billet in SOLIDWORKS CAM.
CAM toolpath simulation of P2 (2× speed).

In a second exercise I programmed a turned AISI 304 shaft from stock to post-processed G-code (8 operations, 9.0 min) and found what I would fix before a real lathe: a missing spindle-speed clamp (G50) and a cut-off that takes 62 % of the cycle.

Operation tree in SOLIDWORKS CAM
Operation tree: facing, drilling, turning, groove and cut-off.
Toolpath simulation of the turned shaft
Toolpath simulation with the stock in the chuck.

Robot: from virtual to real

The AGV-to-conveyor UR5 runs its own PolyScope program in URSim, Universal Robots’ official emulator, so the program is real and portable instead of a simulation-only path. The PLC treats it as an external device and only exchanges seven agreed handshake signals (start, grip confirmed, release confirmed, pick in progress, place complete). Before trusting the virtual robot, I programmed the lab’s physical UR5e — here a vacuum-gripper pick-and-place in a 2 × 2 pattern.

PolyScope program for pick and place
PolyScope program in URSim: BeforeStart, the trigger loop, and the pick and place routines with their wait-for-confirmation steps.
Physical UR5e in the lab: vacuum-gripper pick-and-place programmed in PolyScope.

Communication

S7 GET/PUT links my PLC to the assembly station on another PC, and a C# Modbus TCP sensor exchanges holding registers with the PLC. When the link is cut, the GET block reports the error, the HMI raises an alarm and the station stops passing stale data downstream.

S7 GET block
S7 GET block reading a byte from the partner PLC, triggered at 10 Hz.
C# Modbus sensor application
C# Modbus TCP sensor simulator exchanging the supplier stock value with the PLC.

Quality inspection (Cognex In-Sight)

A complete inspection built on my own on a reflective anti-static bag: 20 images with deliberate errors, grid calibration (0.33 px average error over 823 points), a PatMax reference frame that follows the part as it moves, circle and caliper measurements in millimetres, QR, barcode and OCR reading, and a spreadsheet that passes a part only if every feature passes. Seals and label matched a vernier caliper within ±3 %; the package outline came out 3.7–3.9 % too large, because the foil’s highlights were read as edges.

Golden reference image of the package
Golden image: two colour seals, QR code, barcode, "QTY" text and the label.
Deliberately faulty sample
Deliberately faulty sample: one seal only partly present and a QR code that does not match the part inside.
Image acquisition setup
Acquisition setup: phone fixed above a matte black surface, ceiling light only, calibration checkerboard at the side.
PatMax reference frame on the package
PatMax reference frame that anchors every inspection tool.
Circle tool on a seal
FindCircle measuring the radius of a colour seal.
Caliper failure due to reflection
Failure case: a specular highlight on the foil is taken as an edge by the caliper.
Calibration result
Grid calibration: 0.33 px average error over 823 points.
Vernier caliper measurement of a seal
Physical validation: measuring a seal with the vernier caliper.
Cognex In-Sight spreadsheet
In-Sight spreadsheet: raw tool outputs on the left, and the quality-control table with nominal, limits and pass flags on the right.

Tools & technologies

  • TIA Portal, S7-1500, PLCSIM Advanced, WinCC: PLC program, HMI and SCADA
  • Tecnomatix Process Simulate: digital twin and virtual commissioning
  • URSim / PolyScope, physical UR5e: robot programming
  • SOLIDWORKS CAM: milling and turning toolpaths, G-code analysis
  • C# (Modbus TCP), S7 GET/PUT: communication between stations and sensors
  • Cognex In-Sight: calibrated vision inspection

Results & lessons

Full demonstration of the CNC cell: Process Simulate, PLC and HMI running together.
  • Closed loop: every PLC output drives the 3D scene and every virtual sensor feeds back; the cell completes full automatic cycles, including the rework and scrap branches
  • Communication: Modbus TCP verified in both directions; a cut link raises an alarm and stops stale data
  • Integration: each S7 link worked alone, but the full three-station interconnection was not completed because of IP conflicts, duplicate tags and stale PLCSIM connections
  • Integration is its own engineering task: one IP plan and tag namespace agreed first would have saved most of the lost time
  • Limits come from the requirement: my inspection pass limits were ±10 %, wider than the ±3 % target; next time I would derive them first and build the tools around them

Stack: Tecnomatix Process Simulate · TIA Portal, S7-1500, PLCSIM Advanced, ladder logic · WinCC Runtime Advanced · URSim / PolyScope (UR5 VRC), physical UR5e · S7 GET/PUT, Modbus TCP · C# (Modbus simulator) · SOLIDWORKS CAM (milling and turning), G-code (G71/G72, G82/G83, G41/G43, G96/G97) · Cognex In-Sight (PatMax RedLine, FindCircle, Caliper, ReadIDMax, OCRMax)