Skip to main content

Module fb

Module fb 

Source
Expand description

Function blocks for control programs (IEC 61131-3 inspired).

§Function Blocks

Reusable function blocks for control program development, inspired by the IEC 61131-3 standard. Each block is a stateful struct that you call cyclically (once per scan) from your ControlProgram::process_tick implementation.

§Available Blocks

BlockDescription
RTrigRising edge detector (false → true)
FTrigFalling edge detector (true → false)
TonTimer On Delay — output activates after a duration
SimpleTimerOne-shot timer for imperative start/check patterns
StateMachineState machine helper with automatic timer management
BitResetOnDelayResets a boolean after it has been true for a duration
RunningAverageAccumulates values and computes their arithmetic mean
BeeperAudible beeper controller with configurable beep sequences
HeartbeatMonitors a remote heartbeat counter for connection loss
ShutdownNon-blocking system shutdown initiation and cancellation via IPC

§Usage Pattern

All function blocks follow the same pattern:

  1. Create the block once (typically in your program struct)
  2. Call it every scan cycle with the current inputs
  3. Read its outputs to drive your logic
use autocore_std::fb::{RTrig, Ton};
use std::time::Duration;

struct MyProgram {
    start_trigger: RTrig,
    start_delay: Ton,
}

impl MyProgram {
    fn new() -> Self {
        Self {
            start_trigger: RTrig::new(),
            start_delay: Ton::new(),
        }
    }
}

§IEC 61131-3 Naming

IEC 61131-3 NameRust Name
R_TRIGRTrig
F_TRIGFTrig
TONTon
FB_StateMachineStateMachine
FB_BitResetOnDelayBitResetOnDelay
FB_RunningAverageRunningAverage
FB_BeeperBeeper
FB_HeartbeatHeartbeat
FB_ShutdownShutdown

Structs§

Beeper
Audible Beeper Controller (FB_Beeper)
BitResetOnDelay
Resets a boolean value after it has been true for a specified duration.
FTrig
Falling Edge Trigger (F_TRIG)
Heartbeat
Heartbeat Monitor (FB_Heartbeat)
RTrig
Rising Edge Trigger (R_TRIG)
RunningAverage
Running Average (FB_RunningAverage)
Shutdown
SimpleTimer
Simple One-Shot Timer
StateMachine
State Machine Helper (FB_StateMachine)
Ton
Timer On Delay (TON)

Traits§

Averageable
Trait for types that can be used with RunningAverage.