pub trait CuAnytimeTask: Freezable + Reflect {
type Input<'m>: CuMsgPack;
type Output<'m>: CuMsgPayload;
type Resources<'r>;
type Quality: AnytimeQuality;
// Required methods
fn new(
_config: Option<&ComponentConfig>,
_resources: Self::Resources<'_>,
) -> CuResult<Self>
where Self: Sized;
fn base<'i, 'o>(
&mut self,
ctx: &CuContext,
input: &Self::Input<'i>,
output: &mut Self::Output<'o>,
) -> CuResult<AnytimeStatus<Self::Quality>>;
fn refine<'o>(
&mut self,
ctx: &CuContext,
output: &mut Self::Output<'o>,
) -> CuResult<AnytimeStatus<Self::Quality>>;
// Provided methods
fn register_debug_state_types(registry: &mut TypeRegistry)
where Self: GetTypeRegistration + Sized { ... }
fn debug_state_type_path() -> &'static str
where Self: TypePath + Sized { ... }
fn with_debug_state<R>(&self, f: impl FnOnce(&dyn Reflect) -> R) -> R
where Self: Sized { ... }
fn start(&mut self, _ctx: &CuContext) -> CuResult<()> { ... }
fn preprocess(&mut self, _ctx: &CuContext) -> CuResult<()> { ... }
fn postprocess(&mut self, _ctx: &CuContext) -> CuResult<()> { ... }
fn stop(&mut self, _ctx: &CuContext) -> CuResult<()> { ... }
}Expand description
A task producing a valid result from the bare-minimum compute, then improving it in bounded quanta for as long as the runtime allows.
Per job: preprocess → base → N × refine → postprocess, where N is chosen
by the runtime (possibly 0: a time budget may suppress every refinement, but
never the base computation).
Required Associated Types§
type Input<'m>: CuMsgPack
type Output<'m>: CuMsgPayload
Sourcetype Quality: AnytimeQuality
type Quality: AnytimeQuality
Measure reported through AnytimeStatus: Quality for tasks that can
score their result, () for tasks that cannot. A quality target can only be
configured for tasks whose Quality is comparable to it, so a target on a
() task is rejected at compile time.
Required Methods§
Sourcefn new(
_config: Option<&ComponentConfig>,
_resources: Self::Resources<'_>,
) -> CuResult<Self>where
Self: Sized,
fn new(
_config: Option<&ComponentConfig>,
_resources: Self::Resources<'_>,
) -> CuResult<Self>where
Self: Sized,
Here you need to initialize everything your task will need for the duration of its lifetime. The config allows you to access the configuration of the task.
Sourcefn base<'i, 'o>(
&mut self,
ctx: &CuContext,
input: &Self::Input<'i>,
output: &mut Self::Output<'o>,
) -> CuResult<AnytimeStatus<Self::Quality>>
fn base<'i, 'o>( &mut self, ctx: &CuContext, input: &Self::Input<'i>, output: &mut Self::Output<'o>, ) -> CuResult<AnytimeStatus<Self::Quality>>
Starts a new job and writes its minimum valid result into output.
On Ok: output is valid and safe to publish, refinement state from the
preceding job has been reset, and later refine() calls improve this job.
The task must capture into its own per-job state everything refinement will
need from input: refine() does not receive the input (in background
placements refinement outlives the copperlist that carried it), and the task
knows the cheapest representation to retain.
On Err: the job produced no valid output and the error propagates like a
CuTask::process failure.
Sourcefn refine<'o>(
&mut self,
ctx: &CuContext,
output: &mut Self::Output<'o>,
) -> CuResult<AnytimeStatus<Self::Quality>>
fn refine<'o>( &mut self, ctx: &CuContext, output: &mut Self::Output<'o>, ) -> CuResult<AnytimeStatus<Self::Quality>>
Performs exactly one bounded refinement quantum.
On Ok (any status), output is valid and holds the best result produced so
far for this job; see AnytimeStatus for the commit-only-improvements
contract.
Anything a quantum could want to know about its own job the task already has:
it can count its quanta, read the clock through ctx, and remembers the last
quality it reported.
This method must not contain an unbounded refinement loop: the runtime can only observe time and quality between calls, so one call must be one bounded quantum.
Provided Methods§
Sourcefn register_debug_state_types(registry: &mut TypeRegistry)where
Self: GetTypeRegistration + Sized,
fn register_debug_state_types(registry: &mut TypeRegistry)where
Self: GetTypeRegistration + Sized,
Registers the reflected type used as this task’s debug-state contract.
The default exposes the task struct itself. Override this when the task contains ignored, third-party, hardware, or otherwise non-inspectable internals and should expose a purpose-built debug-state view instead.
Sourcefn debug_state_type_path() -> &'static str
fn debug_state_type_path() -> &'static str
Returns the reflected type path used as this task’s debug-state schema.
Sourcefn with_debug_state<R>(&self, f: impl FnOnce(&dyn Reflect) -> R) -> Rwhere
Self: Sized,
fn with_debug_state<R>(&self, f: impl FnOnce(&dyn Reflect) -> R) -> Rwhere
Self: Sized,
Borrows this task’s current debug-state view.
Override this together with debug_state_type_path
when the debug state is a projected view rather than the task struct.
Sourcefn start(&mut self, _ctx: &CuContext) -> CuResult<()>
fn start(&mut self, _ctx: &CuContext) -> CuResult<()>
Start is called between the creation of the task and the first call to pre/base.
Sourcefn preprocess(&mut self, _ctx: &CuContext) -> CuResult<()>
fn preprocess(&mut self, _ctx: &CuContext) -> CuResult<()>
This is a method called by the runtime before “base”. This is a kind of best effort, as soon as possible call to give a chance for the task to do some work before to prepare to make “base” as short as possible.
Sourcefn postprocess(&mut self, _ctx: &CuContext) -> CuResult<()>
fn postprocess(&mut self, _ctx: &CuContext) -> CuResult<()>
This is a method called by the runtime after the job’s refinement window has closed. It is best effort a chance for the task to update some state out of the critical path, for example to release scratch memory or maintain statistics that are not time-critical for the robot.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".