Skip to main content

ComponentBuilder

Struct ComponentBuilder 

Source
pub struct ComponentBuilder { /* private fields */ }
Expand description

Configures one mounted component instance.

Reached through RobotBuilder::component_with.

Implementations§

Source§

impl ComponentBuilder

Source

pub fn mounted_on(self, link: &str) -> Self

Mount this instance on the named robot link rather than on the one generated from its instance id.

The link is added beneath base_link unless a stated joint already attaches it.

Source

pub fn direction_sign(self, capability: &str, sign: i8) -> Self

State which way this instance’s capability is turned, as 1 or -1.

This is what Robot::require_motor and Robot::require_encoder return beside the capability, so that a mirrored actuator is described once on the model rather than by every consumer that drives it.

Source

pub fn driver(self, driver: Value) -> Self

Give this instance the hardware connection block that makes it a driven component.

Its presence is what says a component driver runs for this instance, under the instance’s own id, and the block is that driver’s configuration. An instance without one is modelled and observed but launches no process.

use phoxal_model::builder::RobotBuilder;

let robot = RobotBuilder::new("rover")
    .component_type("drive_motor", |motor| motor.motor("spin", "axle"))
    .component_with("left_drive", "drive_motor", |mounted| {
        mounted.driver(serde_json::json!({ "connection": "/dev/ttyUSB0" }))
    })
    .build()?;

let left = robot.component("left_drive").expect("the mounted instance");
assert!(left.instance().driver().is_some());

Trait Implementations§

Source§

impl Debug for ComponentBuilder

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

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.