k: Kinematics Library for rust-lang
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
benches
examples
img
src
tests
urdf
.gitignore
.travis.yml
Cargo.toml
LICENSE
README.md

README.md

k: Kinematics library for rust-lang Build Status crates.io

k has below functionalities.

  1. Forward kinematics
  2. Inverse kinematics
  3. URDF Loader

k uses nalgebra as math library.

See Document and examples/ for more details.

Requirements to build examples

sudo apt install g++ cmake xorg-dev libglu1-mesa-dev

IK example with GUI

cargo run --release --example interactive_ik

ik_sample

Push below keys to move the end of the manipulator.

  • f: forward
  • b: backward
  • p: up
  • n: down
  • l: left
  • r: right
  • z: reset the manipulator state.

Create link tree from urdf and solve IK

extern crate k;

use k::prelude::*;
use k::urdf::FromUrdf;

fn main() {
    let robot = k::LinkTree::<f64>::from_urdf_file("urdf/sample.urdf").unwrap();
    let mut arm = k::Manipulator::from_link_tree("l_wrist2", &robot).unwrap();
    // set joint angles
    let angles = vec![0.8, 0.2, 0.0, -1.5, 0.0, -0.3];
    arm.set_joint_angles(&angles).unwrap();
    println!("initial angles={:?}", arm.joint_angles());
    // get the transform of the end of the manipulator (forward kinematics)
    let mut target = arm.end_transform();
    println!("initial target pos = {}", target.translation);
    println!("move z: +0.2");
    target.translation.vector[2] += 0.2;
    let solver = k::JacobianIKSolverBuilder::new().finalize();
    // solve and move the manipulator angles
    solver.solve(&mut arm, &target).unwrap_or_else(|err| {
        println!("Err: {}", err);
        0.0f32
    });
    println!("solved angles={:?}", arm.joint_angles());
    println!(
        "solved target pos = {}",
        arm.end_transform().translation
    );
}