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:
- Wait - Blocks until the tick signal is set by the server
- Read - Copies shared memory to a local buffer (acquire barrier)
- Execute - Calls your
process_tickmethod - Write - Copies local buffer back to shared memory (release barrier)
- 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>
impl<P: ControlProgram> ControlRunner<P>
Sourcepub fn config(self, config: RunnerConfig) -> Self
pub fn config(self, config: RunnerConfig) -> Self
Sourcepub fn run(self) -> Result<()>
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more