Sysmac Studio Β· NJ/NX Β· IEC 61131-3

The robot factory

Write a machine once and stamp out as many copies as you need, each with its own private memory: that is what a function block gives you. Here you build a robot template and then run a whole line of them.

πŸ€– FUNCTION_BLOCK ~12 min
01 Β· The idea

A cookie cutter, not a cookie

The template (defined once)

FUNCTION_BLOCK FB_Robot
VAR_INPUT
  Run : BOOL;       // pulse to make a part
END_VAR
VAR_OUTPUT
  PartsMade : UINT;
END_VAR
VAR
  count : UINT;     // private memory
END_VAR

The body (runs every cycle)

IF Run THEN
  count := count + 1;
END_IF;
PartsMade := count;

πŸ’‘ Defining FB_Robot doesn't build anything yet; it's a cookie cutter sitting in a drawer. You get a working robot only when you create an instance of it.

02 Β· Play

Stamp out the line

Each instance is a real robot with its own count. Add a few, then run cycles and watch every robot keep its own tally. Click one robot to cycle just that one.

Instances: 0 Line total: 0 parts
No robots yet. Stamp one out β†’

πŸ‘† Click an individual robot to pulse only its Run. The others don't change, which shows each instance's memory is completely separate.

03 Β· How it's wired

Declaring the instances

In your program's variable table

// add a robot to see this grow

Calling Arm1(Run := TRUE) touches only Arm1's count. Arm2 is a different robot with its own drawer of memory: same blueprint, separate state. That independence is what lets function blocks scale across a whole machine.

04 Β· Check yourself

One quick question

You have Arm1 and Arm2, both of type FB_Robot. You call Arm1(Run := TRUE) five times. What is Arm2.PartsMade?