Covers Engine 2.0.0
Overview
Choose calculations, events, tasks, or sequences for engine-side automation.
DCode is DARTWIC’s language for automation over RAPID channels. Scripts live in the active project’s scripts directory and use the .dcode extension. You can compute values, react to conditions, run sequences, and call functions supplied by plugins.
Choose how the logic runs
| Use case | DCode block | Execution |
|---|---|---|
| Convert or derive a signal | channel_calculation | Inline on target writes or dependency commits. |
| Raise an event and react to a limit | event | Condition evaluated at activation and on dependency commits. |
| Repeat logic at a frequency | task_periodic | Scheduled CAESAR task. |
| Move through named operating states | task_state_machine | Current-state handler runs on a scheduled task loop. |
| Execute ordered steps with waits | task_sequence | Managed sequence with source-line tracking. |
| Run a named callback without a task card | loop | Scheduled loop at the declared frequency. |
A calculation in four lines
Assume a driver publishes sensor_voltage. This declaration derives pressure whenever that input updates:
channel_calculation sensor_pressure:
local voltage = |sensor_voltage|
return voltage * 20The result is written to |sensor_pressure|. It does not wait for a periodic task tick. Telemetry and recording observe the committed result asynchronously.
Follow Getting Started to save, validate, activate, and inspect a complete demo without hardware.
Syntax you will use
Lua is the default execution backend. Native C++ Execution explains how to compile numeric automation, install its build tools, and verify fixed channel bindings. The examples below use Lua where they include metadata or module features; backend differences are documented in the shared reference.
local measured = |tank_pressure|
|demo_pressure| = measured
|demo_pressure|:units = "bar"Pipes address channel values; put metadata after the closing pipe. Use local for temporary variables and state for task data that survives iterations. Bare assignments and functions belong to the script module. Modules and Native Functions covers reusable helpers.
DCode uses Lua-style expressions. In Lua, numeric 0 is truthy: test a numeric switch with |start_request| == 1, not merely if |start_request|:. Keep numeric channel writes explicit with 0 and 1 when representing off/on.
Timing and ownership
Use a calculation or event condition when logic must react during a local signal update. Use scheduled tasks for time-based work. Keep slow I/O, sleeps, and blocking prompts out of inline reactions. Execution and Timing explains the limits of synchronous behavior.
A plain assignment updates a free channel without claiming it. command and claim establish automatic ownership; set establishes observe-only ownership. override is the explicit automatic safety/interlock path: it supersedes ordinary automation until the same controller calls free. It never supersedes operator manual control. See Commanding and Control.
Abort action with explicit cleanup
An abort event describes the condition; the reaction below defines the application-specific command. The event calls on_firing: both when its trigger asserts and when it clears, so the cleanup is visible in the script instead of being hardcoded by the engine:
event engine_temperature_abort:
title: "Engine temperature limit exceeded"
type: abort
channels: |engine_temperature_voted|
trigger:
if |engine_temperature_voted| > |engine_temp_abort_limit|:
return 1
return 0
on_firing:
if value == 1:
override |engine_fuel_valve| = 0
if value == 0:
free |engine_fuel_valve|
on_event:
if value == 0:
free |engine_fuel_valve|on_event: provides a second explicit cleanup path if the event leaves the board. Both hooks have the same event controller identity, so either can release the override. Verify the resulting hardware feedback independently; this example is a control pattern, not a complete safety case.
The generated language reference contains the full syntax and function catalog.