Expand description
§AutoCore Standard Library
The standard library for writing AutoCore control programs. This crate provides everything you need to build real-time control applications that integrate with the AutoCore server ecosystem.
§Overview
AutoCore control programs run as separate processes that communicate with the autocore-server via shared memory and IPC. This library handles all the low-level details, allowing you to focus on your control logic.
┌─────────────────────────┐ ┌─────────────────────────┐
│ autocore-server │ │ Your Control Program │
│ │ │ │
│ ┌─────────────────┐ │ │ ┌─────────────────┐ │
│ │ Shared Memory │◄───┼─────┼──│ ControlRunner │ │
│ │ (GlobalMemory) │ │ │ │ │ │
│ └─────────────────┘ │ │ │ ┌─────────────┐ │ │
│ │ │ │ │ Your Logic │ │ │
│ ┌─────────────────┐ │ │ │ └─────────────┘ │ │
│ │ Tick Signal │────┼─────┼──│ │ │
│ └─────────────────┘ │ │ └─────────────────┘ │
└─────────────────────────┘ └─────────────────────────┘§Quick Start
-
Create a new control project using
acctl:acctl clone <server-ip> <project-name> -
Implement the
ControlProgramtrait:ⓘuse autocore_std::{ControlProgram, TickContext}; use autocore_std::fb::RTrig; // GlobalMemory is generated from your project.json mod gm; use gm::GlobalMemory; pub struct MyProgram { start_button: RTrig, } impl MyProgram { pub fn new() -> Self { Self { start_button: RTrig::new(), } } } impl ControlProgram for MyProgram { type Memory = GlobalMemory; fn process_tick(&mut self, ctx: &mut TickContext<Self::Memory>) { // Detect rising edge on start button if self.start_button.call(ctx.gm.inputs.start_button) { ctx.gm.outputs.motor_running = true; autocore_std::log::info!("Motor started!"); } } } -
Use the
autocore_main!macro for the entry point:ⓘautocore_std::autocore_main!(MyProgram, "my_project_shm", "tick");
§Function Blocks (IEC 61131-3 Inspired)
This library includes standard function blocks commonly used in PLC programming:
fb::RTrig- Rising edge detector (false→true transition)fb::FTrig- Falling edge detector (true→false transition)fb::Ton- Timer On Delay (output after delay)fb::BitResetOnDelay- Resets a boolean after it has been true for a durationfb::SimpleTimer- Simple one-shot timer (NOT IEC 61131-3, for imperative use)fb::StateMachine- State machine helper with automatic timer managementfb::RunningAverage- Accumulates values and computes their arithmetic meanfb::Beeper- Audible beeper controller with configurable beep sequencesfb::Heartbeat- Monitors a remote heartbeat counter for connection loss
§Example: Edge Detection
use autocore_std::fb::RTrig;
let mut trigger = RTrig::new();
// First call with false - no edge
assert_eq!(trigger.call(false), false);
// Rising edge detected!
assert_eq!(trigger.call(true), true);
// Still true, but no edge (already high)
assert_eq!(trigger.call(true), false);
// Back to false
assert_eq!(trigger.call(false), false);
// Another rising edge
assert_eq!(trigger.call(true), true);§Example: Timer
use autocore_std::fb::Ton;
use std::time::Duration;
let mut timer = Ton::new();
let delay = Duration::from_millis(100);
// Timer not enabled - output is false
assert_eq!(timer.call(false, delay), false);
// Enable timer - starts counting
assert_eq!(timer.call(true, delay), false);
// Still counting...
std::thread::sleep(Duration::from_millis(50));
assert_eq!(timer.call(true, delay), false);
assert!(timer.et < delay); // Elapsed time < preset
// After delay elapsed
std::thread::sleep(Duration::from_millis(60));
assert_eq!(timer.call(true, delay), true); // Output is now true!§Logging
Control programs can send log messages to the autocore-server for display in the
web console. Logging is handled automatically when using ControlRunner.
use autocore_std::log;
log::trace!("Detailed trace message");
log::debug!("Debug information");
log::info!("Normal operation message");
log::warn!("Warning condition detected");
log::error!("Error occurred!");See the logger module for advanced configuration.
§Memory Synchronization
The ControlRunner handles all shared memory synchronization automatically:
- Wait for tick - Blocks until the server signals a new cycle
- Read inputs - Copies shared memory to local buffer (atomic snapshot)
- Execute logic - Your
process_tickruns on the local buffer - Write outputs - Copies local buffer back to shared memory
This ensures your control logic always sees a consistent view of the data, even when other processes are modifying shared memory.
Re-exports§
pub use command_client::CommandClient;pub use log;
Modules§
- command_
client - Client for sending IPC commands to external modules via WebSocket. Client for sending IPC commands to external modules via WebSocket.
- diagnostics
- Lightweight process diagnostics (FD count, RSS).
Lightweight process diagnostics via
/proc/self. - ethercat
- EtherCAT utilities (SDO client, etc.). EtherCAT utilities for control programs.
- fb
- Function blocks for control programs (IEC 61131-3 inspired).
- iface
- Interface protocols for communication between control programs and external sources.
- logger
- UDP logger for sending log messages to autocore-server.
- motion
- CiA 402 motion control: axis abstraction, traits, and types. CiA 402 motion control: axis abstraction, traits, and types.
- shm
- Shared memory utilities for external modules.
Macros§
- autocore_
main - Generates the standard
mainfunction for a control program. - teknic_
pp_ view - Create a
TeknicPpViewby projecting GlobalMemory fields with a common prefix.
Structs§
- Control
Runner - The main execution engine for control programs.
- Runner
Config - Configuration for the
ControlRunner. - Tick
Context - Per-tick context passed to the control program by the framework.
Constants§
- DEFAULT_
WS_ PORT - Default WebSocket port for autocore-server
Traits§
- Auto
Core Memory - Marker trait for generated GlobalMemory structs.
- Change
Tracker - Trait for detecting changes in memory structures.
- Control
Program - The trait that defines a control program’s logic.