libfranka Documentation

repository·main·Indexed 19 days ago

https://github.com/frankarobotics/libfranka

C++ library and Python bindings (pylibfranka) for controlling Franka Robotics robots. Supports joint position, impedance, and gripper control via the Franka Control Interface (FCI). Includes guides for installation on Ubuntu 20.04, 22.04, and 24.04, network configuration for FCI, and examples for reading robot state and implementing motion control.

Tokens
25.3K
Snippets
73
Records
137
Agent score
65%

What's inside libfranka

  1. Overview of pylibfranka features

    main

    pylibfranka is a Python library designed for high-level access to Franka Robotics robots. It is optimized for real-time control and seamless integration with the scientific Python ecosystem.

    Key Capabilities

    • Real-time Control: Supports sending torque, position, and velocity commands at a 1 kHz frequency.
    • Control Modes: Provides multiple modes including Joint/Cartesian position, velocity, and torque control.
    • Robot State Access: Allows reading comprehensive robot state information, such as joint positions, velocities, and torques.
    • Dynamics Model: Includes tools to compute forward/inverse kinematics, mass matrix, Coriolis, and gravity.
    • Gripper Control: Provides full control capabilities for the Franka Hand gripper.
    • NumPy Integration: All data arrays are returned as NumPy arrays, facilitating easy use with other Python scientific libraries.
  2. Overview of libfranka

    main

    libfranka is a C++ library designed for low-level control of Franka Robotics research robots. It allows developers to interface directly with the robot hardware for research and development purposes.

    Key resources for developers:

    • API References: Detailed documentation of the library's functions and capabilities.
    • Franka Control Interface (FCI) Documentation: Information on robot setup and utilizing specific robot features.
    • Robot System Version Compatibility: A matrix to ensure the version of libfranka you are using is compatible with your specific robot system version.
  3. Overview of pylibfranka module organization

    main

    The pylibfranka module is organized into several functional categories:

    Robot Control

    Classes for establishing connections and managing control sessions:

    • Robot: The main interface for interacting with the robot.
    • ActiveControlBase: Represents an active control session.
    • RealtimeConfig: Configuration for real-time control.
    • ControllerMode: Selection of the controller mode.

    Motion Commands

    Data structures used to define and send motion commands:

    • JointPositions: Commands for joint position control.
    • JointVelocities: Commands for joint velocity control.
    • CartesianPose: Commands for Cartesian pose control.
    • CartesianVelocities: Commands for Cartesian velocity control.
    • Torques: Commands for torque control.

    Robot State and Model

    Classes for monitoring the robot and computing dynamics:

    • RobotState: Provides the complete current state of the robot.
    • Model: Provides the dynamics model (e.g., mass matrix, Coriolis, gravity).
    • RobotMode: Indicates the current operation mode.
    • Errors: Represents the error state.

    Gripper

    Classes for interacting with the robot's gripper:

    • Gripper: The main interface for gripper control.
    • GripperState: Provides the current state of the gripper.

    Exceptions

    pylibfranka uses a specific exception hierarchy for error handling:

    • FrankaException: The base exception for all library errors.
    • CommandException: Errors related to specific commands.
    • ControlException: Errors occurring during control or motion.
    • NetworkException: Errors related to network connectivity.
    • InvalidOperationException: Errors when performing an invalid operation.
    • RealtimeException: Errors related to real-time scheduling.
  4. Use libfranka robot models

    main

    libfranka provides built-in robot models that allow you to compute kinematic and dynamic parameters for any arbitrary robot state. This can be done in real-time or non-real-time (e.g., in an optimization loop).

    Included models cover:

    • Forward kinematics of all robot joints
    • Body and zero Jacobian matrices
    • Dynamic parameters: inertia matrix, Coriolis and centrifugal vector, and gravity vector.
  5. Read robot state inside a control loop

    main

    When using an active control interface (derived from ActiveControlBase), use the readOnce() method to synchronize state reading with the control cycle. This method returns a tuple containing the current RobotState and a Duration object representing the time elapsed since the last cycle.

    # Inside a control loop using an ActiveControl object
    state, duration = control.readOnce()
  6. Use Control and State classes for robot interaction

    main

    The core interaction with the Franka robot is managed through several key classes:

    • Robot: The primary interface used to connect to and control the robot.
    • ActiveControlBase: Represents an active control session. Use this class to read the current robot state and write commands during a control loop.
    • RobotState: Provides a complete snapshot of the robot's current state information.
    • Model: Provides access to the robot's dynamics model.
  7. Handle exceptions in pylibfranka

    main

    All errors raised by the library inherit from the base FrankaException. When writing robust robot control code, you should catch specific exception types to differentiate between network issues, control errors, or invalid operations.

    Exception Hierarchy:

    • FrankaException (Base class)
      • CommandException: Errors related to sending commands.
      • ControlException: Errors occurring during active control sessions.
      • NetworkException: Connectivity or communication issues.
      • InvalidOperationException: Attempting an operation that is not allowed in the current state.
      • RealtimeException: Violations of real-time constraints.
  8. Understand the pylibfranka exception hierarchy

    main

    The library uses a specific hierarchy to categorize errors. Understanding these allows you to implement different recovery strategies (e.g., retrying a command vs. attempting a network reconnection).

    Hierarchy:

    • FrankaException (Base class)
      • CommandException: Errors during command execution or invalid parameters.
      • NetworkException: Connection failures or timeouts.
      • ControlException: Errors during motion or torque control (e.g., safety violations).
      • InvalidOperationException: State-related errors (e.g., starting a loop while one is running).
      • RealtimeException: Real-time scheduling or kernel requirement failures.
  9. How to use the Dynamics Model for kinematics and dynamics

    main

    The Model class in pylibfranka provides a robot dynamics model used to compute various quantities such as the mass matrix, Coriolis and centrifugal forces, gravity torques, and the Jacobian.

    To obtain an instance of the Model, you must call Robot.load_model() on an existing Robot instance.

    import pylibfranka
    
    robot = pylibfranka.Robot("172.16.0.2")
    model = robot.load_model()
  10. Understand the <1 ms Communication Constraint

    main

    To maintain stable control, the sum of the following three time measurements must be less than 1 ms per cycle:

    1. Round trip time (RTT) between the workstation PC and FCI.
    2. Execution time of your motion generator or control loop.
    3. Robot processing time (time needed by the robot to process data and step the internal controller).

    Consequences of Violating the Constraint

    If the <1 ms constraint is violated, the received packet is dropped by the FCI.

    • Robot Stop Condition: If 20 consecutive packets are lost or dropped, the robot will stop with a communication_constraints_violation error.
    • Motion Generator Packet Drop: The robot performs linear extrapolation (constant acceleration) for the missed time step.
    • Controller Command Packet Drop: The FCI reuses the torques from the last successful received packet.

    Monitoring Communication Quality

    You can monitor the current communication quality using the RobotState::control_command_success_rate field.