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>
impl<T> Node<T>
pub fn new(joint: Joint<T>) -> Self
pub fn joint(&self) -> JointRefGuard<'_, T>
pub fn joint_position(&self) -> Option<T>
pub fn parent(&self) -> Option<Node<T>>
pub fn children(&self) -> ChildrenRefGuard<'_, T>
sourcepub fn iter_ancestors(&self) -> Ancestors<T> ⓘ
pub fn iter_ancestors(&self) -> Ancestors<T> ⓘ
iter from the end to root, it contains nodes[id]
itself
sourcepub fn iter_descendants(&self) -> Descendants<T> ⓘ
pub fn iter_descendants(&self) -> Descendants<T> ⓘ
iter to the end, it contains nodes[id]
itself
sourcepub fn set_parent(&self, parent: &Node<T>)
pub fn set_parent(&self, parent: &Node<T>)
Set parent and child relations at same time
sourcepub fn remove_parent(&self, parent: &Node<T>)
pub fn remove_parent(&self, parent: &Node<T>)
Remove parent and child relations at same time
sourcepub fn is_root(&self) -> bool
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());
sourcepub fn is_end(&self) -> bool
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());
sourcepub fn set_origin(&self, trans: Isometry3<T>)
pub fn set_origin(&self, trans: Isometry3<T>)
Set the origin transform of the joint
sourcepub fn set_joint_position(&self, position: T) -> Result<(), Error>
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);
sourcepub fn set_joint_position_clamped(&self, position: T)
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));
pub fn set_joint_position_unchecked(&self, position: T)
sourcepub fn world_transform(&self) -> Option<Isometry3<T>>
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()
pub fn world_velocity(&self) -> Option<Velocity<T>>
pub fn mimic_parent(&self) -> Option<Node<T>>
pub fn set_mimic_parent(&self, parent: &Node<T>, mimic: Mimic<T>)
pub fn set_link(&self, link: Option<Link<T>>)
pub fn link(&self) -> OptionLinkRefGuard<'_, T>
Trait Implementations§
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
🔬This is a nightly-only experimental API. (
clone_to_uninit
)source§impl<T> Instrument for T
impl<T> Instrument for T
source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
The inverse inclusion map: attempts to construct
self
from the equivalent element of its
superset. Read moresource§fn is_in_subset(&self) -> bool
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
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
fn from_subset(element: &SS) -> SP
The inclusion map: converts
self
to the equivalent element of its superset.