Struct k::node::Node

source ·
pub struct Node<T: RealField>(/* private fields */);
Expand description

Parts of Chain

It contains joint, joint (transform), and parent/children.

Implementations§

source§

impl<T> Node<T>
where T: RealField + SubsetOf<f64>,

source

pub fn new(joint: Joint<T>) -> Self

source

pub fn joint(&self) -> JointRefGuard<'_, T>

source

pub fn joint_position(&self) -> Option<T>

source

pub fn parent(&self) -> Option<Node<T>>

source

pub fn children(&self) -> ChildrenRefGuard<'_, T>

source

pub fn iter_ancestors(&self) -> Ancestors<T>

iter from the end to root, it contains nodes[id] itself

source

pub fn iter_descendants(&self) -> Descendants<T>

iter to the end, it contains nodes[id] itself

source

pub fn set_parent(&self, parent: &Node<T>)

Set parent and child relations at same time

source

pub fn remove_parent(&self, parent: &Node<T>)

Remove parent and child relations at same time

source

pub fn is_root(&self) -> bool

§Examples
use k::*;

let l0 = k::NodeBuilder::<f32>::new().into_node();
let l1 = k::NodeBuilder::new().into_node();
l1.set_parent(&l0);
assert!(l0.is_root());
assert!(!l1.is_root());
source

pub fn is_end(&self) -> bool

§Examples
let l0 = k::NodeBuilder::<f64>::new().into_node();
let l1 = k::NodeBuilder::new().into_node();
l1.set_parent(&l0);
assert!(!l0.is_end());
assert!(l1.is_end());
source

pub fn set_origin(&self, trans: Isometry3<T>)

Set the origin transform of the joint

source

pub fn origin(&self) -> Isometry3<T>

Get the origin transform of the joint

source

pub fn set_joint_position(&self, position: T) -> Result<(), Error>

Set the position (angle) of the joint

If position is out of limit, it returns Err.

§Examples
use k::*;
let l0 = NodeBuilder::new()
    .joint_type(JointType::Linear{axis: Vector3::z_axis()})
    .limits(Some((0.0..=2.0).into()))
    .into_node();
assert!(l0.set_joint_position(1.0).is_ok());
assert!(l0.set_joint_position(-1.0).is_err());

Setting position for Fixed joint is error.

use k::*;
let l0 = NodeBuilder::new()
    .joint_type(JointType::Fixed)
    .into_node();
assert!(l0.set_joint_position(0.0).is_err());

k::joint::Mimic can be used to copy other joint’s position.

use k::*;
let j0 = NodeBuilder::new()
    .joint_type(JointType::Linear{axis: Vector3::z_axis()})
    .limits(Some((0.0..=2.0).into()))
    .into_node();
let j1 = NodeBuilder::new()
    .joint_type(JointType::Linear{axis: Vector3::z_axis()})
    .limits(Some((0.0..=2.0).into()))
    .into_node();
j1.set_mimic_parent(&j0, k::joint::Mimic::new(1.5, 0.1));
assert_eq!(j0.joint_position().unwrap(), 0.0);
assert_eq!(j1.joint_position().unwrap(), 0.0);
assert!(j0.set_joint_position(1.0).is_ok());
assert_eq!(j0.joint_position().unwrap(), 1.0);
assert_eq!(j1.joint_position().unwrap(), 1.6);
source

pub fn set_joint_position_clamped(&self, position: T)

Set the clamped position (angle) of the joint

It refers to the joint limit and clamps the argument. This function does nothing if this is fixed joint.

§Examples
use k::*;
let l0 = NodeBuilder::new()
    .joint_type(JointType::Linear{axis: Vector3::z_axis()})
    .limits(Some((-1.0..=1.0).into()))
    .into_node();
l0.set_joint_position_clamped(2.0);
assert_eq!(l0.joint().joint_position(), Some(1.0));
l0.set_joint_position_clamped(-2.0);
assert_eq!(l0.joint().joint_position(), Some(-1.0));
source

pub fn set_joint_position_unchecked(&self, position: T)

source

pub fn world_transform(&self) -> Option<Isometry3<T>>

Get the calculated world transform. Call Chain::update_transforms() before using this method.

§Examples
use k::*;
use k::prelude::*;

let l0 = NodeBuilder::new()
    .translation(Translation3::new(0.0, 0.0, 0.2))
    .joint_type(JointType::Rotational{axis: Vector3::y_axis()})
    .into_node();
let l1 = NodeBuilder::new()
    .translation(Translation3::new(0.0, 0.0, 1.0))
    .joint_type(JointType::Linear{axis: Vector3::z_axis()})
    .into_node();
l1.set_parent(&l0);
let tree = Chain::<f64>::from_root(l0);
tree.set_joint_positions(&vec![3.141592 * 0.5, 0.1]).unwrap();
assert!(l1.world_transform().is_none());
assert!(l1.world_transform().is_none());
let _poses = tree.update_transforms();
assert!((l1.world_transform().unwrap().translation.vector.x - 1.1).abs() < 0.0001);
assert!((l1.world_transform().unwrap().translation.vector.z - 0.2).abs() < 0.0001);

// _poses[0] is as same as l0.world_transform()
// _poses[1] is as same as l1.world_transform()
source

pub fn world_velocity(&self) -> Option<Velocity<T>>

source

pub fn mimic_parent(&self) -> Option<Node<T>>

source

pub fn set_mimic_parent(&self, parent: &Node<T>, mimic: Mimic<T>)

Trait Implementations§

source§

impl<T> Clone for Node<T>
where T: RealField,

source§

fn clone(&self) -> Self

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl<T: Debug + RealField> Debug for Node<T>

source§

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

Formats the value using the given formatter. Read more
source§

impl<T: RealField + SubsetOf<f64>> Display for Node<T>

source§

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

Formats the value using the given formatter. Read more
source§

impl<T> From<Joint<T>> for Node<T>
where T: RealField + SubsetOf<f64>,

source§

fn from(joint: Joint<T>) -> Self

Converts to this type from the input type.
source§

impl<T> PartialEq for Node<T>
where T: RealField,

source§

fn eq(&self, other: &Node<T>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.

Auto Trait Implementations§

§

impl<T> Freeze for Node<T>

§

impl<T> RefUnwindSafe for Node<T>

§

impl<T> Send for Node<T>

§

impl<T> Sync for Node<T>

§

impl<T> Unpin for Node<T>

§

impl<T> UnwindSafe for Node<T>

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> CloneToUninit for T
where T: Clone,

source§

unsafe fn clone_to_uninit(&self, dst: *mut T)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T> Instrument for T

source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> Same for T

source§

type Output = T

Should always be Self
source§

impl<SS, SP> SupersetOf<SS> for SP
where SS: SubsetOf<SP>,

source§

fn to_subset(&self) -> Option<SS>

The inverse inclusion map: attempts to construct self from the equivalent element of its superset. Read more
source§

fn is_in_subset(&self) -> bool

Checks if self is actually part of its subset T (and can be converted to it).
source§

fn to_subset_unchecked(&self) -> SS

Use with care! Same as self.to_subset but without any property checks. Always succeeds.
source§

fn from_subset(element: &SS) -> SP

The inclusion map: converts self to the equivalent element of its superset.
source§

impl<T> ToOwned for T
where T: Clone,

source§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T> ToString for T
where T: Display + ?Sized,

source§

default fn to_string(&self) -> String

Converts the given value to a String. Read more
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.
source§

impl<T> WithSubscriber for T

source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
source§

impl<T> Scalar for T
where T: 'static + Clone + PartialEq + Debug,