Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor to use fr3 and panda #2

Draft
wants to merge 63 commits into
base: master
Choose a base branch
from

Conversation

marcbone
Copy link
Owner

@marcbone marcbone commented Apr 21, 2023

Huge Pr to allow the use FR3 and Panda. They are separate structs and can be abstracted over the RobotWrapper type.

Example

use std::f64::consts::PI;
use std::time::Duration;

use clap::Parser;

use franka::{Fr3, FrankaResult, JointPositions, MotionFinished, Panda, Robot, RobotState};

/// An example showing how to generate a joint position motion.
///
/// WARNING: Before executing this example, make sure there is enough space in front of the robot.
#[derive(Parser, Debug)]
#[clap(author, version, name = "generate_joint_position_motion")]
struct CommandLineArguments {
    /// IP-Address or hostname of the robot
    pub franka_ip: String,
    /// Use this option to run the example on a Panda
    #[clap(short, long, action)]
    pub panda: bool,
}

fn main() -> FrankaResult<()> {
    let args = CommandLineArguments::parse();
    match args.panda {
        true => {
            let robot = Panda::new(args.franka_ip.as_str(), None, None)?;
            generate_motion(robot)
        }
        false => {
            let robot = Fr3::new(args.franka_ip.as_str(), None, None)?;
            generate_motion(robot)
        }
    }
}

fn generate_motion<R: Robot>(mut robot: R) -> FrankaResult<()> {
    robot.set_default_behavior()?;
    println!("WARNING: This example will move the robot! Please make sure to have the user stop button at hand!");
    println!("Press Enter to continue...");
    std::io::stdin().read_line(&mut String::new()).unwrap();

    // Set additional parameters always before the control loop, NEVER in the control loop!
    // Set collision behavior.
    robot.set_collision_behavior(
        [20.0, 20.0, 18.0, 18.0, 16.0, 14.0, 12.0],
        [20.0, 20.0, 18.0, 18.0, 16.0, 14.0, 12.0],
        [20.0, 20.0, 18.0, 18.0, 16.0, 14.0, 12.0],
        [20.0, 20.0, 18.0, 18.0, 16.0, 14.0, 12.0],
        [20.0, 20.0, 20.0, 25.0, 25.0, 25.0],
        [20.0, 20.0, 20.0, 25.0, 25.0, 25.0],
        [20.0, 20.0, 20.0, 25.0, 25.0, 25.0],
        [20.0, 20.0, 20.0, 25.0, 25.0, 25.0],
    )?;

    let q_goal = [0., -PI / 4., 0., -3. * PI / 4., 0., PI / 2., PI / 4.];
    robot.joint_motion(0.5, &q_goal)?;
    println!("Finished moving to initial joint configuration.");
    let mut initial_position = JointPositions::new([0.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0]);
    let mut time = 0.;
    let callback = |state: &RobotState, time_step: &Duration| -> JointPositions {
        time += time_step.as_secs_f64();
        if time == 0. {
            initial_position.q = state.q_d;
        }
        let mut out = JointPositions::new(initial_position.q);
        let delta_angle = PI / 8. * (1. - f64::cos(PI / 2.5 * time));
        out.q[3] += delta_angle;
        out.q[4] += delta_angle;
        out.q[6] += delta_angle;
        if time >= 5.0 {
            println!("Finished motion, shutting down example");
            return out.motion_finished();
        }
        out
    };
    robot.control_joint_positions(callback, None, None, None)
}

The examples are already working and the usage for end-users is as I intended. However, there are still things to do:

  • Refactor to clear up the mess
  • Fix missing documentation
  • Fix broken intra-doc links
  • Properly document how to use the new version of library
  • Decide on version number
  • Test every example on real robot
  • Come up with a solution for the different defaults for the rate-limiter
  • Adapt README.md
  • Create Changelog
  • Add code coverage
  • Find out why gripper::tests::gripper_read_once is failing on CI

Marco Boneberger added 30 commits September 9, 2022 09:58
…_pose_motion example

TODO:
* make the logger compatible
* get rid of code duplication
* Make FR3 actually use FR3 data type
* Fix warnings and lints
* make other examples work
* Fix documentation
@marcbone marcbone force-pushed the refactor-to-use-fr3-and-panda branch 9 times, most recently from 9e7214b to 8eaa2a7 Compare October 19, 2023 08:15
@marcbone marcbone force-pushed the refactor-to-use-fr3-and-panda branch from 8eaa2a7 to 03af643 Compare October 19, 2023 08:24
@codecov
Copy link

codecov bot commented Oct 19, 2023

Welcome to Codecov 🎉

Once merged to your default branch, Codecov will compare your coverage reports and display the results in this comment.

Thanks for integrating Codecov - We've got you covered ☂️

@marcbone marcbone force-pushed the refactor-to-use-fr3-and-panda branch from 623a86f to 7c1d5ce Compare October 19, 2023 12:52
@marcbone marcbone force-pushed the refactor-to-use-fr3-and-panda branch from d66cf66 to 708b065 Compare October 20, 2023 14:36
Marco Boneberger added 6 commits October 30, 2023 09:32
The Robot trait does not need a Model type anymore. Instead, it uses the RobotModel struct, which is an abstraction over the model for panda and fr3.
Since currently fr3 and panda can work with the type, the RobotModel is also used internally. Should at a later point those two become incompatible, the internal model can be replaced with a type that converts into RobotModel
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant