Skip to main content

ComponentTypeBuilder

Struct ComponentTypeBuilder 

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

Declares one component type: the capabilities and structure every instance of it has, and how a simulated world models it.

Reached through RobotBuilder::component_type.

Implementations§

Source§

impl ComponentTypeBuilder

Source

pub fn capability(self, capability: &str, declared: Capability) -> Self

Declare one capability, exactly as the canonical model carries it.

Every shorthand below is this method with one kind’s defaults filled in; reach for this one when a capability needs parameters, or a structural target, that its shorthand does not offer.

use phoxal_model::builder::RobotBuilder;
use phoxal_model::component::capability::{
    Capability, Motor, MotorCommand, StructuralTarget,
};
use phoxal_model::identity::JointId;

let robot = RobotBuilder::new("arm-bot")
    .component_type("joint_motor", |joint_motor| {
        joint_motor.capability(
            "lift",
            Capability::Motor(Motor {
                target: StructuralTarget::Joint { id: JointId::new("elbow") },
                command: MotorCommand::Position,
                gear_ratio: 50.0,
                max_torque_nm: Some(12.0),
                max_velocity_radps: None,
            }),
        )
    })
    .component("arm", "joint_motor")
    .build()?;

let (motor, _sign) = robot.require_motor(&"arm.lift".parse()?)?;
assert_eq!(motor.gear_ratio, 50.0);
Source

pub fn joint(self, joint: Joint<'_>) -> Self

Add one joint, and its child link, to this component’s structure.

A component that states nothing still gets a joint or link for every capability target it declares.

Give one link of this component’s structure a body.

A link no stated joint attaches is added beneath mount by a fixed joint named <link>_joint, so this is enough on its own to put a link on the component. Stating the same link twice replaces the earlier body.

use phoxal_model::builder::{Link, RobotBuilder, Visual};
use phoxal_model::structure::Geometry;

let robot = RobotBuilder::new("rover")
    .component_type("rgbd", |camera| {
        camera.camera("rgb", "lens").link(Link {
            name: "lens",
            visuals: vec![Visual::new(Geometry::Cylinder {
                radius: 0.02,
                length: 0.01,
            })],
            ..Link::default()
        })
    })
    .component("front_camera", "rgbd")
    .build()?;

let camera = robot
    .component_for_instance("front_camera")
    .expect("the mounted type is loaded");
let lens = camera.structure().link("lens").expect("the stated link");
assert_eq!(lens.visuals().len(), 1);
Source

pub fn material(self, material: Material<'_>) -> Self

Add one material to this component structure’s own catalogue.

The component counterpart of RobotBuilder::material. Restating a name replaces the earlier material.

Source

pub fn simulated(self, capability: &str, simulated: Capability) -> Self

Model one of this type’s capabilities in a simulated world.

The named capability must be one this type declares, of the same kind, which RobotBuilder::build checks.

use phoxal_model::builder::RobotBuilder;
use phoxal_model::simulation;

let robot = RobotBuilder::new("rover")
    .component_type("drive_motor", |motor| {
        motor.motor("spin", "axle").simulated(
            "spin",
            simulation::Capability::Motor(simulation::Motor::default()),
        )
    })
    .component("left_drive", "drive_motor")
    .build()?;

assert!(robot.simulation_for_instance("left_drive").is_some());
Source

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

Give one component-local link a simulated contact material.

Source

pub fn motor(self, capability: &str, joint: &str) -> Self

A velocity motor driving joint, geared one to one.

Source

pub fn encoder(self, capability: &str, joint: &str) -> Self

An incremental encoder measuring joint, geared one to one.

Source

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

A three-axis accelerometer on link.

Source

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

A three-axis gyroscope on link.

Source

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

A three-axis magnetometer on link.

Source

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

A fused inertial measurement unit on link.

Source

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

A satellite receiver on link, reporting in the robot’s local frame.

Source

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

A 640x480 colour camera looking out of link.

Source

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

A 640x480 depth sensor looking out of link.

Source

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

An emergency stop input on link.

Source

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

A narrow single-beam range finder on link.

Source

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

A planar lidar on link, publishing ranges.

Source

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

A millimetre-wave radar on link.

Source

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

A microphone on link.

Source

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

A speaker on link.

Source

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

A 12 V battery on link.

Source

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

An indicator light on link.

Trait Implementations§

Source§

impl Debug for ComponentTypeBuilder

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.