MOD (Modulo)
Computes the remainder of IN1 divided by IN2 (IN1 MOD IN2) and writes the result to the target variable.
Description
The MOD instruction calculates the modulo remainder of two numeric operands (src1 and src2) and stores the result in the target variable.
Common uses include:
- Wrapping rotary table or circular buffer indices (
(index + 1) MOD capacity). - Alternating between stations on even/odd cycles (
cycle_count MOD 2). - Extracting column positions in a grid (
slot_index MOD columns).
When using
MODwith theN(non-stored) qualifier, the calculation runs every scan cycle while the step is active. UseActionQualifier.P(pulse) to compute once when the step activates.
Syntax
- step: the parent step or transition object
- variable_name: the target numeric variable receiving the remainder
- qualifier: typically
ActionQualifier.Pfor a single execution on step activation - instruction:
ActionInstruction.MOD - src1: dividend value or variable (
IN1) - src2: divisor value or variable (
IN2)
Sequence Visual Editor
- Select an action on a step or transition and hold Alt (or right-click -> Edit Qualifier & Instruction).
- Choose Math -> MOD and select the P (Pulse) or N qualifier.
- Fill in the target variable, dividend (
IN1), and divisor (IN2) operand chips.
Python
from automation_machine import ActionQualifier, ActionInstruction
step.add_action("slot_col", "Compute column index", qualifier=ActionQualifier.P, instruction=ActionInstruction.MOD, src1="part_index", src2="4")