Skip to content

Commit

Permalink
Update api
Browse files Browse the repository at this point in the history
  • Loading branch information
kevindlewis23 committed Jul 9, 2024
1 parent 0220fd6 commit d7f3921
Show file tree
Hide file tree
Showing 3 changed files with 95 additions and 70 deletions.
10 changes: 9 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,15 @@ This is a Rust implementation of the analytic inverse kinematics algorithms foun
To use this package, you either need to choose a an implemented model by name, or specify the kinematics as a Product of Exponentials and select the appropriate problem decomposition.

```rust
use ik_geo::{irb6640, spherical_bot, three_parallel_bot, two_parallel_bot, ur5, Robot};
// Only need to import the one you are using
use ik_geo::{
spherical, spherical_two_parallel, spherical_two_intersecting, three_parallel_two_intersecting, three_parallel, two_parallel,
two_intersecting, gen_six_dof
}
use ik_geo::{
ur5, irb6640, three_parallel_bot, two_parallel_bot, spherical_bot
}

fn main() {
let robot = ur5();

Expand Down
43 changes: 39 additions & 4 deletions src/interface_tests.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
use crate::robot::{
irb6640, spherical_bot, three_parallel_bot, two_parallel_bot, ur5, IKSolver, Robot,
};
use crate::{inverse_kinematics::hardcoded::setups::{Irb6640, KukaR800FixedQ3, SphericalBot, ThreeParallelBot, TwoParallelBot, Ur5}, robot::{
irb6640, spherical, spherical_bot, spherical_two_intersecting, spherical_two_parallel, three_parallel, three_parallel_bot, three_parallel_two_intersecting, two_parallel, two_parallel_bot, ur5, IKSolver, Robot
}};

use std::f64::consts::PI;

use rand::prelude::*;
use rand_pcg::Pcg64;
use rand_seeder::Seeder;
Expand Down Expand Up @@ -65,3 +64,39 @@ fn test_two_parallel_bot() {
fn test_ur5() {
test_robot(ur5());
}

#[test]
fn test_spherical() {
let kin = SphericalBot::get_kin();
test_robot(spherical(kin.h, kin.p));
}

#[test]
fn test_spherical_two_intersecting() {
let (kin, _) = KukaR800FixedQ3::get_kin_partial();
test_robot(spherical_two_intersecting(kin.h, kin.p));
}

#[test]
fn test_spherical_two_parallel() {
let kin = Irb6640::get_kin();
test_robot(spherical_two_parallel(kin.h, kin.p));
}

#[test]
fn test_three_parallel() {
let kin = ThreeParallelBot::get_kin();
test_robot(three_parallel(kin.h, kin.p));
}

#[test]
fn test_three_parallel_two_intersecting() {
let kin = Ur5::get_kin();
test_robot(three_parallel_two_intersecting(kin.h, kin.p));
}

#[test]
fn test_two_parallel() {
let kin = TwoParallelBot::get_kin();
test_robot(two_parallel(kin.h, kin.p));
}
112 changes: 47 additions & 65 deletions src/robot.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
use crate::inverse_kinematics::{
auxiliary::{Kinematics, Matrix3x7}, gen_six_dof, hardcoded::*, setups::calculate_ik_error, spherical,
spherical_two_intersecting, spherical_two_parallel, three_parallel,
three_parallel_two_intersecting, two_intersecting, two_parallel,
auxiliary::{Kinematics, Matrix3x7}, hardcoded::*, setups::calculate_ik_error,
gen_six_dof as gen_six_dof_solver,
spherical as spherical_solver,
spherical_two_intersecting as spherical_two_intersecting_solver,
spherical_two_parallel as spherical_two_parallel_solver,
three_parallel as three_parallel_solver,
three_parallel_two_intersecting as three_parallel_two_intersecting_solver,
two_intersecting as two_intersecting_solver,
two_parallel as two_parallel_solver,
};

use nalgebra::{Matrix3, Matrix3x6, Vector3, Vector6};
Expand All @@ -22,57 +28,57 @@ pub trait IKSolver {
impl Robot {
pub fn spherical_two_parallel(kinematics: Kinematics<6, 7>) -> Self {
Robot {
sub_problem_solver: spherical_two_parallel,
kinematics: kinematics,
sub_problem_solver: spherical_two_parallel_solver,
kinematics
}
}

pub fn spherical_two_intersecting(kinematics: Kinematics<6, 7>) -> Self {
Robot {
sub_problem_solver: spherical_two_intersecting,
kinematics: kinematics,
sub_problem_solver: spherical_two_intersecting_solver,
kinematics
}
}

pub fn spherical(kinematics: Kinematics<6, 7>) -> Self {
Robot {
sub_problem_solver: spherical,
kinematics: kinematics,
sub_problem_solver: spherical_solver,
kinematics
}
}

pub fn three_parallel_two_intersecting(kinematics: Kinematics<6, 7>) -> Self {
Robot {
sub_problem_solver: three_parallel_two_intersecting,
kinematics: kinematics,
sub_problem_solver: three_parallel_two_intersecting_solver,
kinematics
}
}

pub fn three_parallel(kinematics: Kinematics<6, 7>) -> Self {
Robot {
sub_problem_solver: three_parallel,
kinematics: kinematics,
sub_problem_solver: three_parallel_solver,
kinematics
}
}

pub fn two_parallel(kinematics: Kinematics<6, 7>) -> Self {
Robot {
sub_problem_solver: two_parallel,
kinematics: kinematics,
sub_problem_solver: two_parallel_solver,
kinematics
}
}

pub fn two_intersecting(kinematics: Kinematics<6, 7>) -> Self {
Robot {
sub_problem_solver: two_intersecting,
kinematics: kinematics,
sub_problem_solver: two_intersecting_solver,
kinematics
}
}

pub fn gen_six_dof(kinematics: Kinematics<6, 7>) -> Self {
Robot {
sub_problem_solver: gen_six_dof,
kinematics: kinematics,
sub_problem_solver: gen_six_dof_solver,
kinematics
}
}

Expand Down Expand Up @@ -130,86 +136,62 @@ impl IKSolver for Robot {
fn create_kinematics(h: Matrix3x6<f64>, p: Matrix3x7<f64>) -> Kinematics<6, 7> {
Kinematics {
h,
p
p,
}
}

// Create each bot from h, p
pub fn new_spherical_two_parallel(h: Matrix3x6<f64>, p: Matrix3x7<f64>) -> Robot {
Robot {
sub_problem_solver: spherical_two_parallel,
kinematics: create_kinematics(h, p),
}
pub fn spherical_two_parallel(h: Matrix3x6<f64>, p: Matrix3x7<f64>) -> Robot {
Robot::spherical_two_parallel(create_kinematics(h, p))
}

pub fn new_spherical_two_intersecting(h: Matrix3x6<f64>, p: Matrix3x7<f64>) -> Robot {
Robot {
sub_problem_solver: spherical_two_intersecting,
kinematics: create_kinematics(h, p),
}
pub fn spherical_two_intersecting(h: Matrix3x6<f64>, p: Matrix3x7<f64>) -> Robot {
Robot::spherical_two_intersecting(create_kinematics(h, p))
}

pub fn new_spherical(h: Matrix3x6<f64>, p: Matrix3x7<f64>) -> Robot {
Robot {
sub_problem_solver: spherical,
kinematics: create_kinematics(h, p),
}
pub fn spherical(h: Matrix3x6<f64>, p: Matrix3x7<f64>) -> Robot {
Robot::spherical(create_kinematics(h, p))
}

pub fn new_three_parallel_two_intersecting(h: Matrix3x6<f64>, p: Matrix3x7<f64>) -> Robot {
Robot {
sub_problem_solver: three_parallel_two_intersecting,
kinematics: create_kinematics(h, p),
}
pub fn three_parallel_two_intersecting(h: Matrix3x6<f64>, p: Matrix3x7<f64>) -> Robot {
Robot::three_parallel_two_intersecting(create_kinematics(h, p))
}

pub fn new_three_parallel(h: Matrix3x6<f64>, p: Matrix3x7<f64>) -> Robot {
Robot {
sub_problem_solver: three_parallel,
kinematics: create_kinematics(h, p),
}
pub fn three_parallel(h: Matrix3x6<f64>, p: Matrix3x7<f64>) -> Robot {
Robot::three_parallel(create_kinematics(h, p))
}

pub fn new_two_parallel(h: Matrix3x6<f64>, p: Matrix3x7<f64>) -> Robot {
Robot {
sub_problem_solver: two_parallel,
kinematics: create_kinematics(h, p),
}
pub fn two_parallel(h: Matrix3x6<f64>, p: Matrix3x7<f64>) -> Robot {
Robot::two_parallel(create_kinematics(h, p))
}

pub fn new_two_intersecting(h: Matrix3x6<f64>, p: Matrix3x7<f64>) -> Robot {
Robot {
sub_problem_solver: two_intersecting,
kinematics: create_kinematics(h, p),
}
pub fn two_intersecting(h: Matrix3x6<f64>, p: Matrix3x7<f64>) -> Robot {
Robot::two_intersecting(create_kinematics(h, p))
}

pub fn new_gen_six_dof(h: Matrix3x6<f64>, p: Matrix3x7<f64>) -> Robot {
Robot {
sub_problem_solver: gen_six_dof,
kinematics: create_kinematics(h, p),
}
pub fn gen_six_dof(h: Matrix3x6<f64>, p: Matrix3x7<f64>) -> Robot {
Robot::gen_six_dof(create_kinematics(h, p))
}

// Hardcoded bots

pub fn new_irb6640() -> Robot {
pub fn irb6640() -> Robot {
Robot::spherical_two_parallel(Irb6640::get_kin())
}

pub fn new_ur5() -> Robot {
pub fn ur5() -> Robot {
Robot::three_parallel_two_intersecting(Ur5::get_kin())
}

pub fn new_three_parallel_bot() -> Robot {
pub fn three_parallel_bot() -> Robot {
Robot::three_parallel(ThreeParallelBot::get_kin())
}

pub fn new_two_parallel_bot() -> Robot {
pub fn two_parallel_bot() -> Robot {
Robot::two_parallel(TwoParallelBot::get_kin())
}

pub fn new_spherical_bot() -> Robot {
pub fn spherical_bot() -> Robot {
Robot::spherical(SphericalBot::get_kin())
}

Expand Down

0 comments on commit d7f3921

Please sign in to comment.