Dev.to AI πŸ€– Ai πŸ‘ 0 πŸ“– 14 min read

AI + TiaLink: a TIA Portal PLC project becomes a 3D scene in 80 minutes

Project: PLC_SCADA_HMI from multirobot_painting_control_system (TIA Portal V19, MIT) Tools: TiaLink (Openness bridge) + three.js r150.1 Output: one ~680 KB HTML file, double-click to run A PLC project in TIA Portal is

AI + TiaLink: a TIA Portal PLC project becomes a 3D scene in 80 minutes

Project: PLC_SCADA_HMI from multirobot_painting_control_system (TIA Portal V19, MIT)
Tools: TiaLink (Openness bridge) + three.js r150.1
Output: one ~680 KB HTML file, double-click to run

A PLC project in TIA Portal is a tree: devices, blocks, tag tables, HMI screens. It has logic. It has no sense of space.

Nothing in the scene below was hand-written. The human side of this job was two things only β€” an open TIA Portal project, and a running commentary of "this looks wrong". Reading the project, building the geometry, writing the state machine and hunting the six bugs came from an agent shuttling between a gateway and a headless browser. This post is that run, plus the six traps it walked into that I only caught by staring at screenshots.

Stack: TiaLink reads the project, three.js draws it. The artifact is a single ~680 KB HTML file with no external dependency. Wall clock: about 80 minutes.

Start here: TiaLink turns the project into readable data

The hard part of PLC visualisation is rarely the 3D. It's knowing what is in the project.

TiaLink connects over TIA Portal Openness to the project that is currently open, and exposes devices, CPUs, blocks, tag tables and HMI screens as structured data. You query the project instead of clicking down a tree.

The project here is PLC_SCADA_HMI, TIA Portal V19, from the open-source repo rassulz/multirobot_painting_control_system β€” an MIT-licensed multi-robot painting line with an S7-1500, WinCC, MATLAB/Simulink and CAD material. Only the TIA Portal project is used here.

Four tool groups covered everything the scene needed:

  • tialink_health β€” is the gateway attached to a project, and what prerequisite is missing
  • tialink_devices β€” devices, CPU types, PROFINET stations
  • tialink_model β€” all blocks, tag tables, UDTs and source files in one call (far cheaper than exporting one at a time)
  • tialink_context_* β€” the project knowledge graph: index, summary, search, nodes, edges, blocks, impact

That returned the cast list:

  • 4 devices: S7-1500 station (CPU 1513F-1 PN), ET 200SP remote IO (IM 155-6 PN ST), HMI_1, PC-System_1
  • 5 PLC blocks: OB1 Main, FB2 Auto_mode, FB3 Manu_mode, plus two instance DBs
  • 51 PLC tags across Main_variables and additional_variables
  • 3 HMI screens: Main Part, Error_Status, PID
  • PROFINET subnet PN/IE_1, PLC 172.31.17.15, ET 200SP .16, HMI .25, PC station .99

Those five lines decide who stands on the line, who moves, who displays, and where alarms come from.

PLC_SCADA_HMI 3D control scene: conveyor, painting gantry, pick-and-place arm, HMI operator station and the status panel on the right

The devices, tags and HMI screens TiaLink read back, rebuilt as an interactive 3D line. Belt running, gantry spraying, RB-102 palletising, the status card on the right flipping between RUNNING and IDLE (~3 s loop). Play with it here β†’

TiaLink does not hand you 3D models

Worth stating plainly: TiaLink gives you the logical structure of a control project, not CAD geometry. No 3D model of this line exists inside TIA Portal, so every conveyor, arm, fan and cabinet in the scene is built procedurally from the device name and its role in the process.

TiaLink owns what is true. three.js owns what it looks like.

The whole run is read-only: no block modified, no tag changed, no project saved. The scene is an offline interpreter, not a simulator that writes back to the PLC.

The constraint: one file, zero external assets

The requirement was blunt: a single HTML file, generated procedurally, no external elements.

Which rules out a CDN, glTF loading, external textures and web fonts. What worked:

  • three.js r150.1's UMD build, inlined into the HTML (that release still ships a directly inlinable UMD file β€” no build step needed)
  • no <script src>, no <img>, no url(...), no network request anywhere in the page
  • every machine built from Box / Cylinder / Torus / Cone
  • every label, HMI screen, floor marking and particle sprite drawn with Canvas 2D at runtime
  • camera control without OrbitControls β€” about sixty lines of drag / zoom / pan

The cost is size: three.js is ~600 KB on its own, the final HTML ~680 KB. What you buy is a single file you can send anyone; they double-click it, and there is no server, no half-loaded frame with a broken image.

From TiaLink data to objects

The layout follows the project's device relationships, not artistic licence:

TiaLink / project element In the 3D scene
CV-101 conveyor Belt along X, scrolling texture, rollers, drive motor
RB-101 painting robot Gantry spanning the conveyor, carriage and nozzle on the beam
RB-102 pick-and-place Two-link arm with gripper, palletising finished parts
FN-101 fan Axial fan behind the line, blades spinning, air particles
ZS-101 … ZS-104 Four photoelectric sensors along the line, red beams turning green on trigger
PS101–PS104 / ES101 Operator panel front-left, five clickable 3D buttons
HMI_1 Operator station, screen showing MAIN PART / PID / ERROR STATUS
PLC_1 / ET 200SP Control cabinet and remote IO station in the background
WP101–WP104 Workpieces on the belt: paint them, then stack them

HMI_1 and PC-System_1 show the same screens in the project, so the scene uses HMI_1 for the operator station rather than have two screens telling one story.

Spatially: the conveyor is the spine, painting happens left-of-centre, pick-and-place at the right end, panel and HMI on the operator side, PLC cabinet and ET 200SP pushed to the background. The default camera then shows field devices and control hardware in one frame.

Modelling: no model files, only geometry and Canvas

No external asset anywhere, so all visual detail is code:

  • Belt: Canvas draws dark rubber with cross ribs, becomes a RepeatWrapping texture, offset.x scrolls at runtime
  • Safety markings: Canvas yellow-black hatching, laid as two floor bands
  • Floor text: "LINE 01 Β· PLC_SCADA_HMI" drawn to Canvas, used as a transparent decal
  • Device labels: each is a 512Γ—104 Canvas with a rounded plate and text, mapped onto a Sprite
  • HMI screen: a 768Γ—480 Canvas repainted every 120 ms β€” title, three tabs, line schematic, counters, PID trend, alarm list
  • Operator panel: a 768Γ—448 Canvas for the plate, button wells and silkscreen, with 3D buttons layered on top
  • Particles: one 64Γ—64 radial-gradient Canvas for soft dots, shared by spray and airflow

Materials: MeshStandardMaterial with environment reflection for metal, where the environment map is itself a Canvas-drawn equirectangular gradient β€” no HDR file. Lighting is Hemisphere + Directional (2048 shadow map) + a few cool/warm point lights, which fixes the shadow direction and gives the HMI and panel local brightness.

Making it move: a very small line state machine

This is not simulation software. It is closer to a control-logic interpreter. All state lives in one object:

const S = {
  running: false,
  mode: 'AUTO',
  estop: false,
  sims: { cv: false, rb101: false, rb102: false, fn: false },
  jog:  { cv: false, fn: false, rb101: false, rb102: false },
  painted: 0,
  delivered: 0,
  belt: 0,
  fan: 0,
  sprayOn: false,
  pid: { sp: 62, pv: 34, kp: 1.2, ki: 0.08, kd: 0.02 },
};

Each frame does four things:

  1. Derive target states for belt, fan, spray and arms from running / mode / estop / sims
  2. Ease speeds with exponential interpolation, so nothing snaps
  3. Advance the part queue, spray progress, arm phases and pallet stacking
  4. Repaint the HMI Canvas, the status card and the button lamps

Auto / manual / e-stop / fault map directly onto Main calling Auto_mode and Manu_mode, and onto the real tags PS101–PS104, ES101, ALM_*, SIM_*. The scene only translates them into visible motion.

In auto mode the belt carries parts into the spray zone. The gantry locks onto the nearest unpainted part, the nozzle emits particles, and the part's colour lerps from bare metal grey to the target colour. After spraying, the part travels to the end of the line and RB-102 runs:

approach β†’ down β†’ grab β†’ lift β†’ swing β†’ place β†’ release β†’ retract β†’ home

Grab and place both use two-link inverse kinematics. The pallet takes 8 slots in a 2Γ—2Γ—2 stack; past 8, the oldest box is recycled so a demo can run forever.

In manual mode the auto cycle is off and the four jog buttons drive CV, FN, RB-101 and RB-102. E-stop freezes every motion and lights the red beacon. Fault simulation injects SIM_CV101 / SIM_RB101 / SIM_RB102 / SIM_FN101 individually, and the matching device plus its alarm change together.

HMI and interaction: a 2D interface inside 3D

The HMI screen is a live Canvas texture, not a static image:

  • MAIN PART: line schematic, part positions, sprayed / delivered / alarm counters
  • PID: setpoint, process value, Kp/Ki/Kd, trend
  • ERROR STATUS: four alarms, SIM state, Repair all

The three HMI screens: MAIN PART line overview, PID loop tuning, ERROR STATUS faults and simulation

HMI_1's MAIN PART, PID and ERROR STATUS screens β€” repainted every frame, not pasted on. MAIN PART is in stopped state here; the MANU button overlapping the MODE/BELT readouts is a first-pass layout defect.

None of it is invented: the screen names are the project's three Screens, the alarm names are real tags like ALM_XA101_CV101, and the PID fields match Setpoint / K_p / K_i / K_d on the HMI.

Clicking the screen raycasts to get UVs: hit the tab strip and the x coordinate selects the screen; hit anywhere else and it cycles.

The five panel buttons are separate cylinder / mushroom meshes. A raycast hit fires START / STOP / AUTO / MANUAL / E-STOP. The HTML panel on the right handles fault injection, jogging, the PID setpoint and camera reset. Keyboard is mapped too: Space start/stop, A auto, M manual, E e-stop, R reset, H cycle the HMI.

Close-up of the operator panel and HMI_1 with SIM_FN101 injected, HMI on ERROR STATUS

Panel and HMI_1 close up. SIM_FN101 injected, HMI switched to ERROR STATUS; all five panel buttons are independent raycast targets.

Six traps, and how they surfaced

1. The "supplement angle" in the IK

The first arm looked like a crane, and the wrist never reached the target. The elbow term was wrong:

// wrong: this is the supplement angle, the arm comes up short
const a2 = -Math.acos((L1*L1 + L2*L2 - D*D) / (2*L1*L2));

The cosine numerator has to be DΒ² - L1Β² - L2Β²:

const D = Math.hypot(r, dy);

const a1 = Math.atan2(dy, r)
         + Math.acos(clamp((L1*L1 + D*D - L2*L2) / (2*L1*D), -1, 1));

const a2 = -Math.acos(clamp((D*D - L1*L1 - L2*L2) / (2*L1*L2), -1, 1));

The symptom is what makes this expensive: the arm moves fine, but at grab time the part "jumps" under the gripper, because the wrist was ~0.8 m off target and the part was force-snapped to the wrong pose. Doing the triangle on paper once beats watching the animation for ten minutes.

2. pointer-events on the HUD

Every button on the page was dead; clicks landed on the canvas. Cause:

#hud { pointer-events: none; }
#hud > * { pointer-events: none; }  /* the ID specificity beat the children's auto */

#hud > * outranks .toolbar { pointer-events: auto }, so buttons looked clickable and passed every click straight through. Deleting the second rule and setting auto explicitly on the cards and toolbar that need interaction fixed it.

3. Particles culled by the frustum

Spray and airflow particles updated every frame and never appeared. They were all initialised at y = -40; BufferGeometry computed the bounding sphere on the first frame, marked the object off-screen, and never recomputed it after positions changed β€” so Points was culled wholesale.

const sprayPts = new THREE.Points(sprayGeo, sprayMat);
sprayPts.frustumCulled = false;

For dynamic point and line objects, turning frustum culling off is the cheap answer.

4. The held part became a roadblock

The part queue only let the head of the queue stop at the pickup position. To prevent overlap, the code looked for "the part in front" as a blocker:

const blocker = parts.find(p => p.state === 'reserved' || p.state === 'held');
if (blocker) frontLimit = blocker.x - 1.18;

Problem: a held part's x follows the arm out to the pallet (~8.2), which pushed the downstream limit past the end of the belt. Fix: only queued parts block, and the cap is pinned to the pickup position:

const blocker = parts.find(p => p.state === 'reserved');
if (blocker) frontLimit = Math.min(4.72, blocker.x - 1.18);

5. The 3D e-stop was hidden behind the HMI screen

The e-stop button sat at the panel's bottom-right, which projected onto the HMI screen in screen space. The raycast returns the closer HMI, so every e-stop press switched screens instead.

This is not a rendering bug β€” it's 3D UI layout. Screen-space occlusion matters as much as world-space placement. Moving the e-stop to the panel's bottom-left with its label to the right of the button cleared the HMI and matched real panel habits.

6. A 19 cm grab offset

Wrist target 1.92 m, fingertip offset 0.5 m, so the fingertip lands at 1.42 m β€” exactly the top face of the part. Minus half the part height, 0.19 m, that's 1.23 m. The first version skipped the conversion, so the part sank into the belt when grabbed. Validating wrist β†’ fingertip β†’ part-centre once for grab and once for place removed it.

Symptom β†’ cause cheat sheet

None of the six symptoms point at their own cause, which is why the table is worth keeping (in the order I hit them):

Trap What you see One-line fix
IK supplement angle Arm moves, part "sucks" to the gripper, wrist ~0.8 m off Cosine numerator DΒ² βˆ’ L1Β² βˆ’ L2Β²; split a1 into two terms
#hud > * Buttons look clickable, clicks pass through Delete the blanket rule; set auto explicitly
Dynamic particles Particles update, frame stays clean frustumCulled = false on dynamic Points / Line
Queue blocking Downstream part runs off the end of the belt Only reserved parts block; cap with Math.min(4.72, …)
3D button occlusion Pressing e-stop switches the HMI screen Screen-space occlusion steals rays too β€” move the button
Grab height Part sinks 19 cm into the belt Wrist β†’ fingertip β†’ part centre, twice (grab, place)

Verification: use a headless browser, just don't run it in real time

All visual and interaction checks ran in headless Chrome + Playwright. Software rendering (SwiftShader) is very slow: tens of seconds to first frame, then about 1 fps. Wait 9 seconds and simulation time may have advanced 2 β€” early on this reads as "the belt is not moving".

So a logic-only debug entry point went in:

window.__step = (n, dt = 0.05) => {
  for (let i = 0; i < n; i++) updateSim(dt);
};

To see the line 32 seconds from now, call __step(640) β€” returns in milliseconds. Then read __debug.parts and __debug.robot to confirm the queue, the spraying and the palletising. Screenshots still go through real rendering; they just watch, they don't wait.

That same debug hook also verified:

  • toolbar START/STOP/AUTO/MANUAL/E-STOP/RESET
  • the SIM switches, Repair all and manual jog
  • switching all three HMI screens
  • raycast clicks on the 3D panel buttons
  • sidebar collapse and toolbar wrap at 820 px

Time ledger

Requirement to final file, wall clock ~80 minutes:

Phase Time
Understand the project, settle on one file 8 min
Base scene 26 min
Visual tuning (camera, lights, proportions, palette) 14 min
Interaction and line animation 12 min
Debugging 14 min
Packaging, mobile layout, preview 6 min

Roughly 17 screenshot checks, 25 code/build iterations, 2 arm rebuilds. The time did not go into placing geometry. It went into:

  1. Making it look right β€” camera, light and scale, over and over
  2. Making it move right β€” IK, grab height, queue blocking
  3. Making it clickable β€” HUD pointer events, 3D button occlusion
  4. Making it verifiable β€” headless rendering is too slow, so a single-step tool had to exist first

What I'd change on a rebuild

  • Write the debug shell first (camera presets, __step, state snapshots), then sculpt
  • Unit-test the IK as pure math, before it drives an animation
  • frustumCulled = false on dynamic particles, by default
  • Declare pointer-events per HUD child; never a blanket #hud > *
  • Fix reference framing and lighting up front to cut rework
  • Verify logic with fixed-step simulation, not with a headless browser's frame rate

The deliverable

PLC_SCADA_HMI_3D.html, ~680 KB, three.js inlined, no CDN, no external images, models or fonts at runtime. Open it and you can:

  • drag to orbit, wheel to zoom, right-drag or Shift-drag to pan
  • start/stop, change mode, e-stop from the toolbar or the 3D panel
  • click the HMI tab strip to switch MAIN / PID / ERROR
  • inject any of four faults, Repair all, jog manually
  • change the PID setpoint and watch the process value and trend
  • append #auto to the URL to start the demo immediately

It is not a precise digital twin and not a replacement for TIA/PLCSIM. It is closer to a 3D diagram you can argue in front of: devices, tags, modes, alarms and HMI screens compressed into one space, so "what is this line doing, why did it stop, what happens next" is visible at a glance.

The real result was not getting three.js to run. It was confirming one thing: TiaLink turns a PLC project from one .ap19 file into queryable data, and three.js turns that data into a space people can discuss.

Where the project came from

The TIA Portal project used here is rassulz/multirobot_painting_control_system (MIT License): a multi-robot painting line with two Waveshare RoArm-M2-S painting arms, a KUKA KR10 R1100-2 pick-and-place robot, a conveyor and an S7-1513F-1 PN PLC, with a MATLAB/Simulink monitoring layer.

The 3D scene is a procedural visualisation of its PLC/HMI data. Mechanical structure is simplified and does not represent exact proportions or cycle times of the original equipment; the scene code is separate from the original project, and copyright in the original project stays with its author.

Turning your next PLC project into an interactive scene

Three steps is the short path:

  1. Open the target project in TIA Portal β€” TiaLink attaches to the project you have open, it will not open one for you
  2. Call tialink_health and confirm attached: true (writes return 503 when it is false, and it names the missing prerequisite)
  3. Call tialink_model to get blocks, tag tables, UDTs and source files in one call β€” that list is your cast for the scene

TiaLink exposes devices, blocks, tags and HMI screens through TIA Portal Openness as data an AI agent can read. The scene above starts from exactly that data.

Meet TiaLink β†’

Full write-up with all screenshots: AI + TiaLink: a TIA Portal PLC project becomes a 3D scene in 80 minutes.

Disclosure: I work on TiaLink β€” the Openness gateway and the agent harness are my team's tools.

πŸ“° Read the original article on Dev.to AI

Originally published by Dev.to AI. Aggregated on AIWithGhost for educational purposes β€” full credit and traffic to the original publisher.