pub trait ControlProgram {
type Memory: Copy + ChangeTracker + GmCompat;
// Required method
fn process_tick(&mut self, ctx: &mut TickContext<'_, Self::Memory>);
// Provided method
fn initialize(&mut self, _mem: &mut Self::Memory) { ... }
}Required Associated Types§
Sourcetype Memory: Copy + ChangeTracker + GmCompat
type Memory: Copy + ChangeTracker + GmCompat
The shared memory structure type (usually the generated GlobalMemory).
Must implement Copy to allow efficient memory synchronization, and
GmCompat so the runner can verify it matches the live segment.
Required Methods§
Sourcefn process_tick(&mut self, ctx: &mut TickContext<'_, Self::Memory>)
fn process_tick(&mut self, ctx: &mut TickContext<'_, Self::Memory>)
The main control loop - called once per scan cycle.
This is where your control logic lives. Read inputs from ctx.gm,
perform calculations, and write outputs back to ctx.gm. Use
ctx.client for IPC commands and ctx.cycle for the current cycle
number.
The framework calls CommandClient::poll before each invocation,
so incoming responses are already buffered when your code runs.
§Arguments
ctx- ATickContextcontaining the local shared memory copy, the IPC command client, and the current cycle number.
§Timing
This method should complete within the scan cycle time. Long-running operations will cause cycle overruns.
Provided Methods§
Sourcefn initialize(&mut self, _mem: &mut Self::Memory)
fn initialize(&mut self, _mem: &mut Self::Memory)
Called once when the control program starts.
Use this to initialize output states, reset counters, or perform any one-time setup. The default implementation does nothing.
§Arguments
mem- Mutable reference to the shared memory. Changes are written back to shared memory after this method returns.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".