pub trait GmCompat {
const LAYOUT_HASH: u64;
const TOTAL_SIZE: usize;
}Expand description
The trait that defines a control program’s logic.
Implement this trait to create your control program. The associated Memory
type should be the generated GlobalMemory struct from your project.
§Memory Type Requirements
The Memory type must implement Copy to allow efficient synchronization
between shared memory and local buffers. This is automatically satisfied
by the generated GlobalMemory struct.
§Lifecycle
initializeis called once at startupprocess_tickis called repeatedly in the control loop with aTickContextthat provides shared memory, the IPC client, and the current cycle number.
§Example
use autocore_std::{ControlProgram, TickContext};
mod gm;
use gm::GlobalMemory;
pub struct MyController {
cycle_counter: u64,
}
impl MyController {
pub fn new() -> Self {
Self { cycle_counter: 0 }
}
}
impl ControlProgram for MyController {
type Memory = GlobalMemory;
fn initialize(&mut self, mem: &mut GlobalMemory) {
// Set initial output states
mem.outputs.ready = true;
log::info!("Controller initialized");
}
fn process_tick(&mut self, ctx: &mut TickContext<Self::Memory>) {
self.cycle_counter = ctx.cycle;
// Your control logic here
if ctx.gm.inputs.start && !ctx.gm.inputs.estop {
ctx.gm.outputs.running = true;
}
}
}Compatibility constants for the GM segment a control program was generated
against. Code-generated gm.rs implements this for GlobalMemory, so every
control program carries the fingerprint of the exact layout it was built
for. The runner checks these against the server’s SHM header before reading
a single byte of the variable region (see ControlRunner::run).
Required Associated Constants§
Sourceconst LAYOUT_HASH: u64
const LAYOUT_HASH: u64
Fingerprint of the GM layout (must equal the server’s SHM header hash).
Sourceconst TOTAL_SIZE: usize
const TOTAL_SIZE: usize
Total GM segment size in bytes, including the header.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".