Skip to main content

ControlRunner

Struct ControlRunner 

Source
pub struct ControlRunner<P: ControlProgram> { /* private fields */ }
Expand description

The main execution engine for control programs.

ControlRunner handles all the infrastructure required to run a control program:

  • Connecting to the autocore-server via IPC
  • Opening and mapping shared memory
  • Setting up synchronization signals
  • Running the real-time control loop
  • Sending log messages to the server

§Usage

use autocore_std::{ControlRunner, RunnerConfig};

let config = RunnerConfig {
    shm_name: "my_project_shm".to_string(),
    tick_signal_name: "tick".to_string(),
    ..Default::default()
};

ControlRunner::new(MyProgram::new())
    .config(config)
    .run()?;  // Blocks forever

§Control Loop

The runner executes a synchronous control loop:

  1. Wait - Blocks until the tick signal is set by the server
  2. Read - Copies shared memory to a local buffer (acquire barrier)
  3. Execute - Calls your process_tick method
  4. Write - Copies local buffer back to shared memory (release barrier)
  5. Signal - Sets the busy signal (if configured) to indicate completion

This ensures your code always sees a consistent snapshot of the data and that your writes are atomically visible to other processes.

Implementations§

Source§

impl<P: ControlProgram> ControlRunner<P>

Source

pub fn new(program: P) -> Self

Creates a new runner for the given control program.

Uses default configuration. Call .config() to customize.

§Arguments
  • program - Your control program instance
§Example
let runner = ControlRunner::new(MyProgram::new());
Source

pub fn config(self, config: RunnerConfig) -> Self

Sets the configuration for this runner.

§Arguments
  • config - The configuration to use
§Example
ControlRunner::new(MyProgram::new())
    .config(RunnerConfig {
        shm_name: "custom_shm".to_string(),
        ..Default::default()
    })
    .run()?;
Source

pub fn run(self) -> Result<()>

Starts the control loop.

This method blocks indefinitely, running the control loop until an error occurs or the process is terminated.

§Returns

Returns Ok(()) only if the loop exits cleanly (which typically doesn’t happen). Returns an error if:

  • IPC connection fails
  • Shared memory cannot be opened
  • Signal offsets cannot be found
  • A critical error occurs during execution
§Example
fn main() -> anyhow::Result<()> {
    ControlRunner::new(MyProgram::new())
        .config(config)
        .run()
}

Auto Trait Implementations§

§

impl<P> Freeze for ControlRunner<P>
where P: Freeze,

§

impl<P> RefUnwindSafe for ControlRunner<P>
where P: RefUnwindSafe,

§

impl<P> Send for ControlRunner<P>
where P: Send,

§

impl<P> Sync for ControlRunner<P>
where P: Sync,

§

impl<P> Unpin for ControlRunner<P>
where P: Unpin,

§

impl<P> UnwindSafe for ControlRunner<P>
where P: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V