Struct k::SerialChain

source ·
pub struct SerialChain<T: RealField> { /* private fields */ }
Expand description

Kinematic chain without any branch.

All joints are connected sequentially.

Implementations§

Convert Chain into SerialChain without any check

If the input Chain has any branches it causes serious bugs.

Convert Chain into SerialChain

If the input Chain has any branches it fails.

Examples
let node = k::NodeBuilder::<f32>::new().into_node();
let chain = k::Chain::from_root(node);
assert!(k::SerialChain::try_new(chain).is_some());
let node0 = k::NodeBuilder::<f32>::new().into_node();
let node1 = k::NodeBuilder::new().into_node();
let node2 = k::NodeBuilder::new().into_node();
node1.set_parent(&node0);
node2.set_parent(&node0);
let chain = k::Chain::from_root(node0);
assert!(k::SerialChain::try_new(chain).is_none());

Create SerialChain from the end Node

Examples
let node = k::NodeBuilder::<f32>::new().into_node();
let s_chain = k::SerialChain::from_end(&node);

Create SerialChain from the end Node and root Node.

Examples
let node0 = k::NodeBuilder::<f32>::new().into_node();
let node1 = k::NodeBuilder::<f32>::new().into_node();
let node2 = k::NodeBuilder::<f32>::new().into_node();
let node3 = k::NodeBuilder::<f32>::new().into_node();
use k::connect;
connect![node0 => node1 => node2 => node3];
let s_chain = k::SerialChain::from_end_to_root(&node2, &node1);
assert_eq!(s_chain.iter().count(), 2);

Safely unwrap and returns inner Chain instance

Calculate transform of the end joint

Methods from Deref<Target = Chain<T>>§

Set the Chain’s origin

Examples
use k::*;

let l0 = Node::new(Joint::new("fixed0", JointType::Fixed));
let l1 = Node::new(Joint::new("fixed1", JointType::Fixed));
l1.set_parent(&l0);
let c = Chain::<f32>::from_end(&l1);
let mut o = c.origin();
assert!(o.translation.vector[0].abs() < 0.000001);
o.translation.vector[0] = 1.0;
c.set_origin(o);
assert!((o.translation.vector[0] - 1.0).abs() < 0.000001);

Get the Chain’s origin

Iterate for all joint nodes

The order is from parent to children. You can assume that parent is already iterated.

Examples
use k::*;

let l0 = Node::new(Joint::new("fixed0", JointType::Fixed));
let l1 = Node::new(Joint::new("fixed1", JointType::Fixed));
l1.set_parent(&l0);
let tree = Chain::<f64>::from_root(l0);
let names = tree.iter().map(|node| node.joint().name.to_owned()).collect::<Vec<_>>();
assert_eq!(names.len(), 2);
assert_eq!(names[0], "fixed0");
assert_eq!(names[1], "fixed1");

Iterate for movable joints

Fixed joints are ignored. If you want to manipulate on Fixed, use iter() instead of iter_joints()

Iterate for links

Calculate the degree of freedom

Examples
use k::*;
let l0 = NodeBuilder::new()
    .joint_type(JointType::Fixed)
    .finalize()
    .into();
let l1 : Node<f64> = NodeBuilder::new()
    .joint_type(JointType::Rotational{axis: Vector3::y_axis()})
    .finalize()
    .into();
l1.set_parent(&l0);
let tree = Chain::from_root(l0);
assert_eq!(tree.dof(), 1);

Find the joint by name

Examples
use k::*;

let l0 = Node::new(NodeBuilder::new()
    .name("fixed")
    .finalize());
let l1 = Node::new(NodeBuilder::new()
    .name("pitch1")
    .translation(Translation3::new(0.0, 0.1, 0.0))
    .joint_type(JointType::Rotational{axis: Vector3::y_axis()})
    .finalize());
l1.set_parent(&l0);
let tree = Chain::from_root(l0);
let j = tree.find("pitch1").unwrap();
j.set_joint_position(0.5).unwrap();
assert_eq!(j.joint_position().unwrap(), 0.5);

Find the joint by link name

Examples
use k::*;

let l0 = Node::new(NodeBuilder::new()
    .name("fixed")
    .finalize());
l0.set_link(Some(link::LinkBuilder::new().name("link0").finalize()));
let mut l1 = Node::new(NodeBuilder::new()
    .name("pitch1")
    .translation(Translation3::new(0.0, 0.1, 0.0))
    .joint_type(JointType::Rotational{axis: Vector3::y_axis()})
    .finalize());
l1.set_parent(&l0);
l1.set_link(Some(link::LinkBuilder::new().name("link1").finalize()));
let tree = Chain::from_root(l0);
let joint_name = tree.find_link("link1").unwrap()
.joint().name.clone();
assert_eq!(joint_name, "pitch1");

Get the positions of the joints

FixedJoint is ignored. the length is the same with dof()

Set the positions of the joints

FixedJoints are ignored. the input number must be equal with dof()

Set the clamped positions of the joints

This function is safe, in contrast to set_joint_positions_unchecked.

Fast, but without check, dangerous set_joint_positions

Update world_transform() of the joints

Update world_velocity() of the joints

Update transforms of the links

Trait Implementations§

Returns a copy of the value. Read more
Performs copy-assignment from source. Read more
Formats the value using the given formatter. Read more
The resulting type after dereferencing.
Dereferences the value.
Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

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

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Should always be Self
The inverse inclusion map: attempts to construct self from the equivalent element of its superset. Read more
Checks if self is actually part of its subset T (and can be converted to it).
Use with care! Same as self.to_subset but without any property checks. Always succeeds.
The inclusion map: converts self to the equivalent element of its superset.
The resulting type after obtaining ownership.
Creates owned data from borrowed data, usually by cloning. Read more
Uses borrowed data to replace owned data, usually by cloning. Read more
Converts the given value to a String. Read more
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.
Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more