franky Control Library

repository·master·Indexed 43 days ago

https://github.com/timschneider42/franky

A high-level control library for Franka robots providing Python and C++ interfaces. It abstracts 1 kHz real-time programming using Ruckig for time-optimal trajectory planning. Key features include Cartesian and Joint position/velocity control, torque and impedance control, real-time preemption, reactive behavior, and full libfranka access.

Tokens
19.6K
Snippets
55
Records
74
Agent score
55%

What's inside franky

  1. Overview of franky features

    master

    franky is a high-level control library for Franka robots that supports both Python and C++. It uses the Ruckig library to plan time-optimal trajectories, allowing for smooth motion without requiring the user to manage 1 kHz real-time programming.

    Key capabilities include:

    • Trajectory Control: Cartesian (position/velocity) and Joint (position/velocity) control.
    • Torque Control: Direct joint torque control and built-in Cartesian/Joint impedance control.
    • Real-time Preemption: Ability to change targets or preempt motions on the fly.
    • Reactive Behavior: Define reactions to unexpected events like environmental contact.
    • Callbacks: Non-blocking motion and reaction callbacks for logging or debugging.
    • Full libfranka Access: Direct Python access to most libfranka functionality (e.g., gripper control, reading robot state, setting force thresholds).
  2. Overview of franky High-Level Control

    master

    franky is a high-level control library for Franka robots supporting both Python and C++. It is designed to allow control from non-real-time environments (like Python) by abstracting away the requirement for strict 1 kHz real-time programming.

    Instead of low-level commands, franky accepts high-level position or velocity targets. It uses the Ruckig library to plan time-optimal trajectories in real-time. Key features include:

    • Dynamic Re-planning: Motions can be preempted at any time, triggering immediate trajectory re-planning.
    • Reaction System: A system to handle unforeseen situations (e.g., unexpected contact) by updating motion commands dynamically.
    • libfranka Integration: Most libfranka functionality, such as gripper control, is exposed directly in Python.
  3. Impedance and Torque Control

    master

    For advanced interaction, Franky provides client-side impedance controllers that run in torque mode. These allow for compliant behavior in either joint or Cartesian space.

    • Joint Impedance: Use JointImpedanceBase, JointImpedanceMotion, JointImpedanceTrackingMotion, and JointImpedanceTracker with JointImpedanceGains and JointImpedanceParams.
    • Cartesian Impedance: Use CartesianImpedanceBase, CartesianImpedanceMotion, CartesianImpedanceTrackingMotion, and CartesianImpedanceTracker with CartesianImpedanceGains and CartesianImpedanceParams.
    • Torque Control: Use BaseTorqueMotion, SimpleTorqueMotion, and TorqueStopMotion.
    • Task-based Control: Includes PostureTask, ManipulabilityTask, and NullspaceGains.
  4. Trajectory Motion Control Modes

    master

    Franky supports four primary trajectory control modes. Each mode has specific motion classes for point-to-point, waypoint, or stop commands:

    Joint Position Control

    Used for moving specific joints to target positions. Classes: Motion, JointMotion, JointWaypointMotion, JointWaypoint, JointStopMotion, BaseJointPositionMotion.

    Joint Velocity Control

    Used for controlling the speed of individual joints. Classes: JointVelocityMotion, JointVelocityWaypointMotion, JointVelocityWaypoint, JointVelocityStopMotion, BaseJointVelocityMotion.

    Cartesian Position Control

    Used for moving the end-effector to specific poses in 3D space. Classes: CartesianMotion, CartesianWaypointMotion, CartesianWaypoint, CartesianStopMotion, BaseCartesianPoseMotion.

    Cartesian Velocity Control

    Used for controlling the end-effector's linear and angular velocity. Classes: CartesianVelocityMotion, CartesianVelocityWaypointMotion, CartesianVelocityWaypoint, CartesianVelocityStopMotion, BaseCartesianVelocityMotion.

  5. Use asynchronous gripper methods

    master

    To prevent blocking your main execution thread, use the asynchronous versions of gripper commands (moveAsync in C++, move_async in Python).

    In C++, these return a std::future<bool>. You can use wait_for to implement timeouts. If a timeout occurs, you should call gripper.stop() to cancel the motion.

    In Python, move_async returns an object where .wait(timeout_seconds) returns a boolean indicating if the operation completed within the window. If it returns False, call gripper.stop().

    // C++ Timeout Example
    std::future<bool> success_future = gripper.moveAsync(0.05, speed);
    
    if (success_future.wait_for(std::chrono::seconds(1)) != std::future_status::ready) {
      gripper.stop();
      success_future.wait();
      std::cout << "Gripper motion timed out." << std::endl;
    } else {
      std::cout << "Success: " << success_future.get() << std::endl;
    }
    # Python Timeout Example
    success_future = gripper.move_async(0.05, speed)
    
    if success_future.wait(1):
        print(f"Success: {success_future.get()}")
    else:
        gripper.stop()
        success_future.wait()
        print("Gripper motion timed out.")
  6. Understand Franky trajectory control modes

    master

    Franky supports four primary trajectory control modes, each invoked by passing an appropriate Motion object to the robot. These modes allow you to control the robot in either joint space or Cartesian space, using either position or velocity targets.

    Supported modes:

    • Joint Position Control: Moving joints to specific angles.
    • Joint Velocity Control: Moving joints at specific speeds.
    • Cartesian Position Control: Moving the end-effector to specific poses.
    • Cartesian Velocity Control: Moving the end-effector at specific linear and angular velocities.

    Additionally, Franky provides client-side impedance controllers in torque mode.

    Note on Units: All units are in meters ($m$), meters per second ($\frac{m}{s}$), radians ($\textit{rad}$), or radians per second ($\frac{\textit{rad}}{s}$).

  7. Understand naming differences between C++ and Python APIs

    master

    The franky C++ API is designed to closely mirror the functionality of the Python API. However, developers transitioning from Python should be aware of differences in naming conventions:

    As a result, some variable and method names will differ between the two languages even though the underlying logic and structure remain consistent.

  8. How impedance control works in franky

    master

    Impedance control in franky provides client-side spring-damper laws in torque mode. It allows the robot to behave like a mass-spring-damper system rather than following a rigid trajectory.

    There are two primary variants for both joint-space and Cartesian impedance:

    1. Fixed-target motions (JointImpedanceMotion, CartesianImpedanceMotion): These interpret a target once at the start of the motion and regulate toward it.
    2. Tracking motions (JointImpedanceTrackingMotion, CartesianImpedanceTrackingMotion): These keep the controller alive and allow for online updates to references and gains. In Python, the recommended interface for continuous updates (e.g., for manual guidance or teleoperation) is using the JointImpedanceTracker or CartesianImpedanceTracker classes.

    When updating gains via set_gains(), changes are smoothed in the real-time loop using exponential interpolation to avoid abrupt stiffness steps.

  9. How relative dynamics factors work

    master

    Relative dynamics factors allow you to scale the velocity, acceleration, and jerk limits of a motion. These factors can be set at three different layers:

    1. Robot level: Set via robot.relative_dynamics_factor.
    2. Move command level: Set via the relative_dynamics_factor argument in robot.move().
    3. Motion level: Set as a parameter on the motion object itself.

    Multiplication Rule: Factors from different layers are multiplied together, not overridden. For example, a factor on a motion will scale down the existing robot-level factor. A motion-level factor can only reduce dynamics, never increase them.

    Exception - MAX_DYNAMICS: If any layer sets the factor to RelativeDynamicsFactor.MAX_DYNAMICS, the motion will execute with maximum velocity, acceleration, and jerk limits, ignoring all other layers.

    ⚠️ Warning: MAX_DYNAMICS should only be used for emergency stops (e.g., unexpected contact). Using it for standard motions is dangerous and likely to cause discontinuity errors.

    # Setting a global scalar factor for the robot
    robot.relative_dynamics_factor = 0.05
    
    # Setting separate scaling factors for velocity, acceleration, and jerk
    robot.relative_dynamics_factor = RelativeDynamicsFactor(0.05, 0.1, 0.15)
    
    # Setting a factor during a specific move command (multiplied by robot factor)
    robot.move(m_jp2, relative_dynamics_factor=0.8)
  10. Configure the SimpleTorqueMotion signal watchdog

    master

    To prevent the robot from accelerating indefinitely if the control process stalls, SimpleTorqueMotion uses a watchdog. If no new torque is received via set_torque() within signal_timeout seconds, the motion terminates with a TorqueSignalTimeoutException.

    • Default timeout: 50 ms.
    • Loosen timeout: Increase signal_timeout for slower control loops.
    • Disable watchdog: Set signal_timeout=None to hold the last commanded torque indefinitely.

    Note: Exceptions thrown by the watchdog are stored in the robot's control thread and rethrown by the next call to Robot.join_motion or Robot.move.

    # Loosen timeout to 200ms
    motion = SimpleTorqueMotion(signal_timeout=0.2)
    
    # Disable watchdog entirely
    motion = SimpleTorqueMotion(signal_timeout=None)
  11. Run franky remotely via RPC

    master

    If your Franka robot is connected to a different machine than your development environment, you can run franky remotely using one of the following RPC-based projects:

    • zero-franky: Developed by franky co-maintainer Nick Walker.
    • franky-remote: A third-party tool.
    • net_franky: A third-party tool.

    Note: If you use franky-remote or net_franky, please ensure you credit the respective developers.

  12. Real-Time Reactions

    master

    Franky allows for real-time reactions to sensor events using a condition-action pattern. You can define Reaction objects that trigger based on specific Conditions.

    Supported sensor measurements for reactions:

    • TorqueReaction (Torque)
    • JointPositionReaction (Joint Position)
    • JointVelocityReaction (Joint Velocity)
    • CartesianPoseReaction (Cartesian Pose)
    • CartesianVelocityReaction (Cartesian Velocity)