Skip to main content

CuSrcTask

Trait CuSrcTask 

Source
pub trait CuSrcTask: Freezable + Reflect {
    type Output<'m>: CuMsgPayload;
    type Resources<'r>;

    // Required methods
    fn new(
        _config: Option<&ComponentConfig>,
        _resources: Self::Resources<'_>,
    ) -> CuResult<Self>
       where Self: Sized;
    fn process<'o>(
        &mut self,
        ctx: &CuContext,
        new_msg: &mut Self::Output<'o>,
    ) -> CuResult<()>;

    // 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 Src Task is a task that only produces messages. For example drivers for sensors are Src Tasks. They are in push mode from the runtime. To set the frequency of the pulls and align them to any hw, see the runtime configuration. Note: A source has the privilege to have a clock passed to it vs a frozen clock.

Required Associated Types§

Source

type Output<'m>: CuMsgPayload

Source

type Resources<'r>

Resources required by the task.

Required Methods§

Source

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.

Source

fn process<'o>( &mut self, ctx: &CuContext, new_msg: &mut Self::Output<'o>, ) -> CuResult<()>

Process is the most critical execution of the task. The goal will be to produce the output message as soon as possible. Use preprocess to prepare the task to make this method as short as possible.

Provided Methods§

Source

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.

Source

fn debug_state_type_path() -> &'static str
where Self: TypePath + Sized,

Returns the reflected type path used as this task’s debug-state schema.

Source

fn with_debug_state<R>(&self, f: impl FnOnce(&dyn Reflect) -> R) -> R
where 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.

Source

fn start(&mut self, _ctx: &CuContext) -> CuResult<()>

Start is called between the creation of the task and the first call to pre/process.

Source

fn preprocess(&mut self, _ctx: &CuContext) -> CuResult<()>

This is a method called by the runtime before “process”. 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 “process” as short as possible.

Source

fn postprocess(&mut self, _ctx: &CuContext) -> CuResult<()>

This is a method called by the runtime after “process”. It is best effort a chance for the task to update some state after process is out of the way. It can be use for example to maintain statistics etc. that are not time-critical for the robot.

Source

fn stop(&mut self, _ctx: &CuContext) -> CuResult<()>

Called to stop the task. It signals that the *process method won’t be called until start is called again.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§

Source§

impl<O: CuMsgPayload + 'static> CuSrcTask for CuSimSrcTaskPack<O>

Source§

type Resources<'r> = ()

Source§

type Output<'m> = O

Source§

impl<T, O> CuSrcTask for CuAsyncSrcTask<T, O>
where T: for<'m> CuSrcTask<Output<'m> = CuMsg<O>> + Send + 'static, O: CuMsgPayload + Send + 'static,

Source§

impl<T: CuMsgPayload + 'static> CuSrcTask for CuSimSrcTask<T>