Concepts
Ports and data types
Komods talk to each other through ports. A port is typed: only an output and an input of the same type can be linked (the graph editor does not allow a wrong link).
[Input("temperature", Deadline = "00:00:05")]
public required IInput<Scalar> Temperature { get; init; }
[Output("heater")]
public required IOutput<BoolValue> Heater { get; init; }
KOFA fills in the properties when the instance is created (required … init). The port id ("temperature") is unique within the Komod and should stay stable between versions, because the links in the graph refer to it.
Output and input
- Output:
Publish(value)(the measurement time is now) orPublish(value, timestamp). One output can be linked to several inputs (fan-out). - Input:
ReadAllAsync(stream),ReadAsync(the next message),TryRead(does not block),Latest(the last one, even if you already read it). - A message is a
KofaMessage<T>:Value,Seq(sequence number),TimestampUtc(measurement time),SourceInstanceId.
Input settings
[Input] property |
Meaning |
|---|---|
Deadline |
A time span ("00:00:00.300"). If no message arrives for this long, OnInputTimeout is called. Mandatory for a Komod that operates something. |
QueueCapacity |
0 (default): only the latest value is kept, the old one is dropped (sensor, control). A positive number: a queue, for events and logs. |
Multiple |
Several outputs may be linked to the input; the messages are merged. By default one source can be linked. |
FromUi |
The input value is given by the browser, not a link. UI input. |
Data types
The data is a type; every type has an id (kofa.scalar/1: a name and a major version). Two ports can be linked when the id and the major version match.
KOFA provides ready, common types (Kofa.Abstractions.DataTypes) so that Komods by different authors can be connected:
| Type | Id | What it is for |
|---|---|---|
Scalar |
kofa.scalar/1 |
A general measurement with a unit. |
BoolValue |
kofa.bool/1 |
A switch, a state. |
Trigger |
kofa.trigger/1 |
An event without data (emergency stop, reset). |
DriveCommand |
kofa.drive.command/1 |
Car: steering, throttle, brake. |
SailCommand |
kofa.sail.command/1 |
Sailboat: rudder, mainsheet, jib sheet. |
ActuatorChannels |
kofa.actuator.channels/1 |
PWM channel values. |
CameraFrame |
kofa.camera.frame/1 |
A camera image. |
The full list with the fields: Data types.
Conventions: SI units (m, m/s, rad, V, A); angles in radians; normalized control signals in the range [-1, 1] or [0, 1] (the type's description says which). The UI converts angles to degrees.
Important
Always use an existing common type if there is one: then your Komod can be linked with Komods by other authors. Introduce a new type only if none fits; see Own types.
How the data travels
Inside the server the object itself (without copying) passes between Komods. Towards the browser it travels as JSON (camelCase, enums as text) and the server thins it (maxRateHz). Send large data (camera images) only as needed and less often; for remote (relay) connections see the relay priority.