pub trait CuSimApplication {
type Step<'z>;
// Required methods
fn get_original_config() -> String;
fn new(
clock: RobotClock,
unified_logger: Arc<Mutex<UnifiedLoggerWrite>>,
config_override: Option<CuConfig>,
sim_callback: &mut impl for<'z> FnMut(Self::Step<'z>) -> SimOverride,
) -> Result<Self, CuError>
where Self: Sized;
fn start_all_tasks(
&mut self,
sim_callback: &mut impl for<'z> FnMut(Self::Step<'z>) -> SimOverride,
) -> Result<(), CuError>;
fn run_one_iteration(
&mut self,
sim_callback: &mut impl for<'z> FnMut(Self::Step<'z>) -> SimOverride,
) -> Result<(), CuError>;
fn run(
&mut self,
sim_callback: &mut impl for<'z> FnMut(Self::Step<'z>) -> SimOverride,
) -> Result<(), CuError>;
fn stop_all_tasks(
&mut self,
sim_callback: &mut impl for<'z> FnMut(Self::Step<'z>) -> SimOverride,
) -> Result<(), CuError>;
fn restore_keyframe(&mut self, freezer: &KeyFrame) -> Result<(), CuError>;
}
Expand description
A trait that defines the structure and behavior of a simulation-enabled CuApplication.
CuSimApplication is the simulation version of an application and its runtime, allowing overriding of steps with simulated behavior.
The CuSimApplication
trait outlines the necessary functions required for managing an application lifecycle
in simulation mode, including configuration management, initialization, task execution, and runtime control.
Required Associated Types§
Required Methods§
Sourcefn get_original_config() -> String
fn get_original_config() -> String
Returns the original configuration as a string, typically loaded from a RON file. This configuration represents the default settings for the application before any overrides.
Sourcefn new(
clock: RobotClock,
unified_logger: Arc<Mutex<UnifiedLoggerWrite>>,
config_override: Option<CuConfig>,
sim_callback: &mut impl for<'z> FnMut(Self::Step<'z>) -> SimOverride,
) -> Result<Self, CuError>where
Self: Sized,
fn new(
clock: RobotClock,
unified_logger: Arc<Mutex<UnifiedLoggerWrite>>,
config_override: Option<CuConfig>,
sim_callback: &mut impl for<'z> FnMut(Self::Step<'z>) -> SimOverride,
) -> Result<Self, CuError>where
Self: Sized,
Creates a new simulation-enabled application.
§Arguments
clock
- ARobotClock
instance to be used for time-related operations in the implementing struct.unified_logger
- A thread-safe, shared reference toUnifiedLoggerWrite
, enabling logging functionalities.config_override
- An optionalCuConfig
instance that allows overriding the default configuration values.- If
Some
, the provided configuration will be used. - If
None
, the default configuration will be applied.
- If
sim_callback
- A mutable function reference that allows overriding individual simulation steps. The callback receives a Step parameter and returns a SimOverride indicating how to handle the step.
§Returns
A result containing either:
- An instantiated object of the implementing type (
Self
), or - A
CuResult
error in case of failure during initialization.
Sourcefn start_all_tasks(
&mut self,
sim_callback: &mut impl for<'z> FnMut(Self::Step<'z>) -> SimOverride,
) -> Result<(), CuError>
fn start_all_tasks( &mut self, sim_callback: &mut impl for<'z> FnMut(Self::Step<'z>) -> SimOverride, ) -> Result<(), CuError>
Starts all tasks managed by the application/runtime in simulation mode.
§Arguments
sim_callback
- A mutable function reference that allows overriding individual simulation steps.
§Returns
Ok(())
- If all tasks are started successfully.Err(CuResult)
- If an error occurs while attempting to start one or more tasks.
Sourcefn run_one_iteration(
&mut self,
sim_callback: &mut impl for<'z> FnMut(Self::Step<'z>) -> SimOverride,
) -> Result<(), CuError>
fn run_one_iteration( &mut self, sim_callback: &mut impl for<'z> FnMut(Self::Step<'z>) -> SimOverride, ) -> Result<(), CuError>
Executes a single iteration of copper-generated runtime in simulation mode.
§Arguments
sim_callback
- A mutable function reference that allows overriding individual simulation steps.
§Returns
CuResult<()>
- ReturnsOk(())
if the iteration completes successfully, or an error wrapped inCuResult
if something goes wrong during execution.
Sourcefn run(
&mut self,
sim_callback: &mut impl for<'z> FnMut(Self::Step<'z>) -> SimOverride,
) -> Result<(), CuError>
fn run( &mut self, sim_callback: &mut impl for<'z> FnMut(Self::Step<'z>) -> SimOverride, ) -> Result<(), CuError>
Runs indefinitely looping over run_one_iteration in simulation mode
§Arguments
sim_callback
- A mutable function reference that allows overriding individual simulation steps.
§Returns
Returns a CuResult<()>
, which indicates the success or failure of the
operation.
- On success, the result is
Ok(())
. - On failure, an appropriate error wrapped in
CuResult
is returned.
Sourcefn stop_all_tasks(
&mut self,
sim_callback: &mut impl for<'z> FnMut(Self::Step<'z>) -> SimOverride,
) -> Result<(), CuError>
fn stop_all_tasks( &mut self, sim_callback: &mut impl for<'z> FnMut(Self::Step<'z>) -> SimOverride, ) -> Result<(), CuError>
Stops all tasks managed by the application/runtime in simulation mode.
§Arguments
sim_callback
- A mutable function reference that allows overriding individual simulation steps.
§Returns
Returns a CuResult<()>
, which indicates the success or failure of the
operation.
- On success, the result is
Ok(())
. - On failure, an appropriate error wrapped in
CuResult
is returned.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.