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.
Design at a glance




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.


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.


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






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.


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.


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.

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.


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.









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
- 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)