PLC

Topics

Scope

ECMC PLCs provide deterministic real-time logic in the ecmc cycle for:

  • EtherCAT I/O conditioning and interlocks
  • axis synchronization and supervisory logic
  • motion limit/home override logic
  • derived signals and buffering workflows

By Task

Load and run PLC code

  • Use classic text PLC loading:
${SCRIPTEXEC} ${ecmccfg_DIR}loadPLCFile.cmd, "FILE=<filename>, INC=<include_dirs>, SAMPLE_RATE_MS=<rate_ms>, PLC_MACROS='<custom_macros>'"
  • Use YAML wrapper loading:
${SCRIPTEXEC} ${ECMC_CONFIG_ROOT}loadYamlPlc.cmd, "FILE=./plc.yaml, ECMC_TMPDIR=/tmp/"

YAML PLC loading supports both parser backends:

  • jinja (default, Python-based)
  • ecb (C++ backend via ECMC_CFG_TOOL=ecb, see ecb)

Understand language/syntax and available variables

  • syntax for operators, declarations, comments, examples, and axis/ec/ds/plc variable namespaces.

Reuse PLC functions and shared code

  • function libs for loadPLCLib.cmd, function signatures, and constraints.

Apply robust coding patterns

  • best practice for macros, include/substitute usage, printout strategy, and declaration patterns.

PLC Definition Styles

ecmccfg supports three styles:

  1. Pure text PLC files (classic)
  2. Pure YAML PLC definitions
  3. YAML header + external text PLC file (recommended for complex PLCs)

Pure YAML (minimal)

All keys are mandatory:

  • id: unique PLC id (uint)
  • enable: start enabled/disabled
  • rateMilliseconds: execution rate in ms (-1 means every cycle)
  • code: list of PLC code lines
plc:
  id: 1
  enable: no
  rateMilliseconds: 10
  code:
    - 'ec0.s2.binaryOutput07:=global.test|'
    - '${PLC_ID}.enable:=plc0.enable|'
    - 'ec0.s2.binaryOutput05:=not(ec0.s2.binaryOutput05)|'

YAML Header + Text File

Use file: to keep large PLC logic in text files:

plc:
  id: 1
  enable: yes
  rateMilliseconds: 10
  file: plc1.plc

If file is set, entries in code are overwritten.

Formatting Notes

YAML is indentation-sensitive.

Use 2-space indentation.

PLC statement line terminator remains | in YAML-based code lines.

  1. syntax
  2. best practice
  3. function libs