Skip to main content

Crate sim_opcua

Crate sim_opcua 

Source
Expand description

PLC link: the simulator as an OPC UA server. A PLC (or any client) sends targets and setpoints and reads back every signal. The servo loops stay inside the simulator; OPC UA is far too slow to close them.

The variables are generated from the simulation’s signal list, never written per machine:

node (string id in the simulator’s namespace)typeaccessmeaning
signal.<signal id>Doublereadevery signal of the simulation
command.target.<axis id>Doublewritetarget of the next point-to-point move
command.moveBooleanwritetrue starts the move to the targets
command.setpoint.<axis id>Doublewritestreamed position setpoint, interpolated
command.cycleBooleanwritetrue starts the cycle, false stops it
command.disableBooleanwritetrue switches the drives off (brakes on)
command.enableBooleanwritetrue switches the drives on again
command.stop_categoryInt32write0, 1 or 2 stops the machine in that stop category (Command::Halt)
command.pathStringwritea path, in the text of a path file
command.path_time_optimalBooleanwriteplan the path as fast as the motors allow
command.run_pathBooleanwritetrue plans command.path and runs it
status.busyBooleanreada move, path or the cycle is under way
status.refusedStringreadkey of the last refused command, or empty

An axis the PLC does not write stays where it is: command.target.<axis id> reads the planned position until it is written, and again after the move it was written for; command.setpoint.<axis id> reads the setpoint the controller follows, which is the planned position whenever no setpoint is on its way. So a write to one axis never carries an old value for the others.

The path is planned from where the machine stands when command.run_path arrives, as Sim::plan_path plans it (format: see sim_components::path). A path that cannot be read is refused with opcua-error-path-line; one that cannot be planned or run with the key the planner or the controller gives.

status.refused keeps a refusal until a command of the same kind (move, setpoint, cycle start, …) is accepted. Accepted commands of another kind, such as a stream of setpoints, do not wipe it.

Next to these, every axis has PLCopen motion function blocks as handshake variables (see plcopen and docs/plc.md), in the folder axis.<axis id>:

nodetypeaccessmeaning
axis.<id>.Power.EnableBooleanwriteMC_Power: true powers the axis
axis.<id>.Power.Status, .ValidBooleanreaddrives on; on and without error
axis.<id>.Power.Error, .ErrorIDBoolean, UInt16readthe axis error (ErrorStop), also unpowered
axis.<id>.<FB>.ExecuteBooleanwriterising edge starts FB = Home, MoveAbsolute, MoveRelative, Stop, Reset, GearIn, GearOut, CamIn, CamOut
axis.<id>.GearIn.Master, .CamIn.Master, .CamIn.TableStringwritethe master’s axis id; the client’s cam table
axis.<id>.GearIn.RatioNumerator, …, .CamIn.CamTableIDDoublewriteinputs of GearIn and CamIn, taken on the rising edge
axis.<id>.MoveAbsolute.Position, .Velocity, .Acceleration, .Deceleration, .JerkDoublewriteinputs, taken on the rising edge
axis.<id>.MoveRelative.Distance, …Doublewriteas for MoveAbsolute
axis.<id>.Stop.DecelerationDoublewritebraking deceleration of MC_Stop
axis.<id>.<FB>.Done, .Busy, .Active, .CommandAborted, .ErrorBooleanreadoutputs (InGear, InSync for GearIn, CamIn)
axis.<id>.<FB>.ErrorIDUInt16readwhy the block failed, 0 without error
axis.<id>.State, .StateIDString, Int32readPLCopen state (Disabled 1, Standstill 2, ErrorStop 3, Stopping 4, Homing 5, DiscreteMotion 6, ContinuousMotion 7, SynchronizedMotion 8)
axis.<id>.ActualPosition, .ActualVelocityDoublereadfrom the simulated axis
axis.<id>.IsHomed, .Error, .ErrorIDBoolean, Boolean, UInt16readhomed; the axis error (ErrorStop)

The loop’s real-time pacing is measured from the wall-clock times of its ticks, since the start or the last command.reset_pacing:

nodetypeaccessmeaning
status.cycle_sDoublereadthe loop’s nominal cycle
status.cycle_period_sDoublereadmean measured time between ticks
status.jitter_max_sDoublereadlargest deviation of a tick period from the cycle
status.jitter_rms_sDoublereadroot mean square of that deviation
status.overrunsUInt64readticks that came more than a whole cycle late
status.cyclesUInt64readticks measured
status.realtime_factorDoublereadsimulated time over wall-clock time
status.stepsUInt64readsimulation steps since the start
command.reset_pacingBooleanwritetrue starts the measurement anew

The clients’ cycle, from the arrival times of their Read and Write requests (ClientTiming), reset with the pacing:

nodetypeaccessmeaning
status.client_writes, status.client_readsUInt64readintervals measured
status.client_write_mean_s, status.client_read_mean_sDoublereadmean interval
status.client_write_std_s, status.client_read_std_sDoublereadstandard deviation of the intervals
status.client_write_max_s, status.client_read_max_sDoublereadlargest interval

Endpoints, certificates and users: see Security. docs/plc.md has the IEC 61131-3 type of every node.

Modules§

plcopen
One axis as PLCopen motion sees it: the function blocks MC_Power, MC_Home, MC_MoveAbsolute, MC_MoveRelative, MC_Stop and MC_Reset, and of synchronised motion MC_GearIn, MC_GearOut, MC_CamIn and MC_CamOut, as handshake variables, and the axis state machine behind them.

Structs§

ClientTiming
How regularly the clients read and write the simulator’s variables: a PLC that reads and writes once a task cycle shows its cycle and jitter here. One Read or Write request counts once, however many variables it holds; reads of other attributes than the value (browsing) and subscriptions do not count.
Intervals
The time between consecutive requests of one kind (Read or Write) from the clients, since the last reset.
Link
LinkError
A failure to start, as a translation key and a detail.
Pacing
The loop’s real-time pacing, measured from the wall-clock times of its ticks since the last reset.
Security
How the server lets clients in. It offers at the same URL the security policy None and every policy of POLICIES with Sign and with SignAndEncrypt. Its application instance certificate (self-signed, valid for 365 days) is created in the pki folder on the first start: own/cert.der and private/private.pem (certificate_days_left, renew_certificate).
Timed
The simple in-memory node manager, with the arrival of every Read and Write request timed.

Constants§

NAMESPACE
POLICIES
The secured endpoints, each offered with Sign and with SignAndEncrypt: every policy async-opcua has that OPC UA does not deprecate (Basic128Rsa15 and Basic256 are, and are left out).

Statics§

I18N
(language code, translation file contents) for the link’s own messages.

Functions§

certificate_days_left
Days until the server’s certificate in pki_dir expires (negative once it has); None without one (the next start creates it).
configured
The config of --config FILE (or else the machine’s default) with every --set path=value on top, read as sim-cli reads them; and the trajectory of --trajectory FILE (sim_components::path::parse_trajectory), to run at the start (Link::run_trajectory).
number
A number a client wrote, of any IEC 61131-3 numeric type: LREAL, REAL, SINT, INT, DINT, LINT, USINT, UINT, UDINT, ULINT. A 64-bit integer beyond 2^53 is refused: a double would not hold it exactly.
renew_certificate
Sets the server’s certificate and private key in pki_dir aside (.old beside them, replacing an older one), so that the next start creates new ones, valid for 365 days. Clients that trusted the old certificate must trust the new one. Nothing to do without one.
serve
Starts the server on listener and the simulation behind it, in real time, in ticks of cycle. labels names the variables for people browsing the server; pki_dir holds the server’s keys. Anonymous clients, and only client certificates already trusted: Security::default().
serve_secured
serve, letting clients in as security says.