### Example Installation of libfranka 0.19.0 on Ubuntu 22.04 Source: https://github.com/frankarobotics/libfranka/blob/main/README.rst This example demonstrates downloading, verifying, and installing a specific version of libfranka on Ubuntu 22.04. ```bash wget https://github.com/frankarobotics/libfranka/releases/download/0.19.0/libfranka_0.19.0_jammy_amd64.deb wget https://github.com/frankarobotics/libfranka/releases/download/0.19.0/libfranka_0.19.0_jammy_amd64.deb.sha256 sha256sum -c libfranka_0.19.0_jammy_amd64.deb.sha256 sudo dpkg -i libfranka_0.19.0_jammy_amd64.deb ``` -------------------------------- ### Quick Start Example for pylibfranka Source: https://github.com/frankarobotics/libfranka/blob/main/docs/installation.rst A basic example demonstrating how to connect to a Franka Robot, read its state, and access joint positions using pylibfranka. ```python import pylibfranka # Connect to the robot robot = pylibfranka.Robot("172.16.0.2") state = robot.read_once() # Print joint positions print(f"Joint positions: {state.q}") ``` -------------------------------- ### Install pylibfranka from Source Source: https://github.com/frankarobotics/libfranka/blob/main/pylibfranka/README.md Build and install pylibfranka from the source code using pip after installing prerequisites. ```bash pip install . ``` -------------------------------- ### Install TinyXML2 Source: https://github.com/frankarobotics/libfranka/blob/main/README.rst Clones, builds, and installs TinyXML2. Ensure to use the correct branch and installation prefix. ```bash git clone --depth 1 --branch 10.0.0 https://github.com/leethomason/tinyxml2.git cd tinyxml2 mkdir build && cd build cmake .. \ -DCMAKE_POSITION_INDEPENDENT_CODE=ON \ -DBUILD_SHARED_LIBS=OFF \ -DCMAKE_BUILD_TYPE=Release \ -DCMAKE_INSTALL_PREFIX=/usr/local make -j$(nproc) sudo make install cd ../.. && rm -rf tinyxml2 ``` -------------------------------- ### Verify libfranka Installation (Header Files) Source: https://github.com/frankarobotics/libfranka/blob/main/README.rst Lists the header files installed in the /usr/include/franka/ directory to confirm successful installation. ```bash ls /usr/include/franka/ ``` -------------------------------- ### Install Assimp Source: https://github.com/frankarobotics/libfranka/blob/main/README.rst Clones, builds, and installs Assimp with specific configurations for static libraries and disabling tests. Submodules are also initialized. ```bash git clone --depth 1 --recurse-submodules --shallow-submodules \ --branch v5.4.3 https://github.com/assimp/assimp.git cd assimp && mkdir build && cd build cmake .. -DBoost_USE_STATIC_LIBS=ON -DCMAKE_POSITION_INDEPENDENT_CODE=ON \ -DBUILD_SHARED_LIBS=OFF -DASSIMP_BUILD_TESTS=OFF \ -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=/usr/local make -j$(nproc) && sudo make install cd ../.. && rm -rf assimp ``` -------------------------------- ### Install pylibfranka from PyPI Source: https://github.com/frankarobotics/libfranka/blob/main/pylibfranka/README.md Install pylibfranka using pip. This is the recommended method as pre-built wheels include all necessary dependencies. ```bash pip install pylibfranka ``` -------------------------------- ### Install Prerequisites on Ubuntu/Debian Source: https://github.com/frankarobotics/libfranka/blob/main/pylibfranka/README.md Install necessary build tools and development headers on Ubuntu/Debian systems when building pylibfranka from source. ```bash sudo apt-get update sudo apt-get install -y build-essential cmake libeigen3-dev libpoco-dev python3-dev ``` -------------------------------- ### CMakeLists.txt Configuration for Examples Source: https://github.com/frankarobotics/libfranka/blob/main/examples/utility_examples/CMakeLists.txt This snippet shows how to define and build example executables using CMake. It sets up include paths and links against the Franka library and common utilities. ```cmake set(EXAMPLES logging_example ) foreach(example ${EXAMPLES}) add_executable(${example} ${example}.cpp) target_include_directories(${example} PUBLIC $ $ ) target_link_libraries(${example} Franka::Franka examples_common fmt::fmt) install(TARGETS ${example} RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} ) endforeach() ``` -------------------------------- ### Install Pre-commit Hooks Source: https://github.com/frankarobotics/libfranka/blob/main/README.rst Install pre-commit hooks for automated code formatting and linting before each commit. This is recommended for contributors. ```bash pip install pre-commit pre-commit install ``` -------------------------------- ### Build and Install Boost 1.77.0 from Source Source: https://github.com/frankarobotics/libfranka/blob/main/README.rst Download, bootstrap, build, and install Boost version 1.77.0 with static linking. This is a prerequisite for building libfranka from source. ```bash git clone --depth 1 --recurse-submodules --shallow-submodules \ --branch boost-1.77.0 https://github.com/boostorg/boost.git cd boost ./bootstrap.sh --prefix=/usr/local sudo ./b2 install -j$(nproc) cd .. && rm -rf boost ``` -------------------------------- ### Installing the Python Module Source: https://github.com/frankarobotics/libfranka/blob/main/pylibfranka/CMakeLists.txt Installs the compiled '_pylibfranka' target to the 'pylibfranka' destination directory for Python to use. ```cmake install(TARGETS _pylibfranka DESTINATION pylibfranka) ``` -------------------------------- ### Run Gripper Control Example Source: https://github.com/frankarobotics/libfranka/blob/main/pylibfranka/README.md Command to execute the gripper control example script. Specify robot IP and optional parameters for width, homing, speed, and force. ```bash cd examples python3 move_gripper.py --robot_ip [--width ] [--homing <0|1>] [--speed ] [--force ] ``` -------------------------------- ### Install System Packages for Building from Source Source: https://github.com/frankarobotics/libfranka/blob/main/README.rst Install essential system packages required for building libfranka from source, including build tools and development libraries. ```bash sudo apt-get update sudo apt-get install -y \ build-essential \ cmake \ git \ wget \ libeigen3-dev \ libpoco-dev \ libfmt-dev \ pybind11-dev ``` -------------------------------- ### Build and Install pylibfranka from Source Source: https://github.com/frankarobotics/libfranka/blob/main/docs/installation.rst Builds and installs the pylibfranka Python package from the libfranka source directory using pip. An editable install is also shown for development purposes. ```bash pip install . # For development (editable install): pip install -e . ``` -------------------------------- ### Run Other Control Examples Source: https://github.com/frankarobotics/libfranka/blob/main/pylibfranka/README.md Execute other available control examples. These scripts typically require the robot's IP address. ```bash cd examples python3 other_example.py --ip ``` -------------------------------- ### Run Joint Impedance Control Example Source: https://github.com/frankarobotics/libfranka/blob/main/pylibfranka/README.md Execute the joint impedance control example script. Requires specifying the robot's IP address. ```bash cd examples python3 joint_impedance_example.py --ip ``` -------------------------------- ### Install libfranka Debian Package Source: https://github.com/frankarobotics/libfranka/blob/main/README.rst Download the Debian package and its checksum, verify integrity, and then install the package using dpkg. ```bash sha256sum -c libfranka___amd64.deb.sha256 sudo dpkg -i libfranka___amd64.deb ``` -------------------------------- ### Running libfranka Examples Source: https://github.com/frankarobotics/libfranka/blob/main/docs/overview.rst Command to execute a specific libfranka example, 'generate_joint_velocity_motion', from the build directory. Ensure the robot has sufficient free space before running. ```shell ./examples/generate_joint_velocity_motion ``` -------------------------------- ### Install urdfdom_headers Source: https://github.com/frankarobotics/libfranka/blob/main/README.rst Clones, builds, and installs urdfdom_headers. This package provides header files for URDF parsing. ```bash git clone --depth 1 --branch 1.0.5 https://github.com/ros/urdfdom_headers.git cd urdfdom_headers mkdir build && cd build cmake .. \ -DCMAKE_BUILD_TYPE=Release \ -DCMAKE_INSTALL_PREFIX=/usr/local make -j$(nproc) sudo make install cd ../.. rm -rf urdfdom_headers ``` -------------------------------- ### Verify libfranka Installation (Library File) Source: https://github.com/frankarobotics/libfranka/blob/main/README.rst Checks for the presence of the libfranka shared library file in the standard installation path. ```bash ls -l /usr/lib/libfranka.so ``` -------------------------------- ### Install Debian Package on Host System (from Docker) Source: https://github.com/frankarobotics/libfranka/blob/main/README.rst Install the generated libfranka Debian package on the host system after building it inside a Docker container. ```bash # On host system (outside container) cd libfranka/build sudo dpkg -i libfranka*.deb ``` -------------------------------- ### Run Joint Position Example Source: https://github.com/frankarobotics/libfranka/blob/main/pylibfranka/README.md Execute the joint position control example script. Requires specifying the robot's IP address. ```bash cd examples python3 joint_position_example.py --ip ``` -------------------------------- ### Install console_bridge Source: https://github.com/frankarobotics/libfranka/blob/main/README.rst Clones, builds, and installs console_bridge. This is a dependency for some ROS packages. ```bash git clone --depth 1 --branch 1.0.2 https://github.com/ros/console_bridge.git cd console_bridge mkdir build && cd build cmake .. \ -DCMAKE_POSITION_INDEPENDENT_CODE=ON \ -DBUILD_SHARED_LIBS=OFF \ -DCMAKE_BUILD_TYPE=Release \ -DCMAKE_INSTALL_PREFIX=/usr/local make -j$(nproc) sudo make install cd ../.. rm -rf console_bridge ``` -------------------------------- ### Install Pinocchio with patch Source: https://github.com/frankarobotics/libfranka/blob/main/README.rst Downloads a patch, clones, applies the patch, builds, and installs Pinocchio. Python interface, documentation, and testing are disabled. ```bash wget https://raw.githubusercontent.com/frankarobotics/libfranka/main/.ci/pinocchio.patch git clone --depth 1 --recurse-submodules --shallow-submodules \ --branch v3.4.0 https://github.com/stack-of-tasks/pinocchio.git cd pinocchio && git apply ../pinocchio.patch mkdir build && cd build cmake .. -DBoost_USE_STATIC_LIBS=ON -DCMAKE_POSITION_INDEPENDENT_CODE=ON \ -DBUILD_SHARED_LIBS=OFF -DBUILD_PYTHON_INTERFACE=OFF \ -DBUILD_DOCUMENTATION=OFF -DBUILD_TESTING=OFF \ -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=/usr/local make -j$(nproc) && sudo make install cd ../.. && rm -rf pinocchio ``` -------------------------------- ### Handle Non-compliant Joint Motion Generator Start Pose Error Source: https://github.com/frankarobotics/libfranka/blob/main/docs/overview.rst Example of how to handle errors related to non-compliant initial values for a joint motion generator. It demonstrates sending the last commanded joint positions (robot_state.q_c) as the initial value for the control loop. ```c++ double time{0.0}; robot.control( [=, &time](const franka::RobotState& robot_state, franka::Duration period) -> franka::JointPositions { time += period.toSec(); if (time == 0) { // Send the last commanded q_c as the initial value return franka::JointPositions(robot_state.q_c); } else { // The rest of your control loop ... } }); ``` -------------------------------- ### Run Print Robot State Example Source: https://github.com/frankarobotics/libfranka/blob/main/pylibfranka/README.md Execute the script to read and display the robot's current state. Optional parameters for rate and count are available. ```bash cd examples python3 print_robot_state.py --ip [--rate ] [--count ] ``` -------------------------------- ### Run Async Joint Position Control Example Source: https://github.com/frankarobotics/libfranka/blob/main/pylibfranka/README.md Command to execute the asynchronous joint position control example script. Requires the robot's IP address. ```bash cd examples python3 async_position_control.py --ip ``` -------------------------------- ### Install Real-Time Kernel Packages Source: https://github.com/frankarobotics/libfranka/blob/main/docs/real_time_kernel.rst Installs the compiled kernel image and headers. The IGNORE_PREEMPT_RT_PRESENCE=1 environment variable may be necessary to bypass checks if NVIDIA drivers are present. ```bash sudo IGNORE_PREEMPT_RT_PRESENCE=1 dpkg -i ../linux-headers-*.deb ../linux-image-*.deb ``` -------------------------------- ### main.cpp for libfranka Example Source: https://github.com/frankarobotics/libfranka/blob/main/docs/installation.rst A basic C++ source file that includes the necessary libfranka headers and demonstrates a minimal application structure. This file should be placed in the root of your project alongside CMakeLists.txt. ```cpp #include #include int main() { try { // Replace "172.16.0.1" with the IP address of your Franka Emika robot franka::Robot robot("172.16.0.1"); // Print robot state std::cout << "Successfully connected to robot." << std::endl; auto state = robot.readOnce(); std::cout << "Robot state: " << state.toString() << std::endl; } catch (const franka::Exception& ex) { std::cerr << "Error connecting to robot: " << ex.what() << std::endl; return -1; } return 0; } ``` -------------------------------- ### Install urdfdom with patch Source: https://github.com/frankarobotics/libfranka/blob/main/README.rst Downloads a patch, clones, applies the patch, builds, and installs urdfdom. This ensures compatibility with specific versions. ```bash wget https://raw.githubusercontent.com/frankarobotics/libfranka/main/.ci/urdfdom.patch git clone --depth 1 --branch 4.0.0 https://github.com/ros/urdfdom.git cd urdfdom git apply ../urdfdom.patch mkdir build && cd build cmake .. \ -DCMAKE_POSITION_INDEPENDENT_CODE=ON \ -DBUILD_SHARED_LIBS=OFF \ -DCMAKE_BUILD_TYPE=Release \ -DCMAKE_INSTALL_PREFIX=/usr/local make -j$(nproc) sudo make install cd ../.. rm -rf urdfdom ``` -------------------------------- ### Import and Initialize Robot and Gripper Source: https://github.com/frankarobotics/libfranka/blob/main/pylibfranka/docs/modules.rst Import the pylibfranka library and initialize Robot and Gripper objects with the robot's IP address. This is a common starting point for interacting with a Franka Emika robot. ```python import pylibfranka robot = pylibfranka.Robot("172.16.0.2") gripper = pylibfranka.Gripper("172.16.0.2") ``` -------------------------------- ### Verify libfranka Installation Source: https://github.com/frankarobotics/libfranka/blob/main/docs/installation.rst Confirms that the libfranka package has been successfully installed on your system by checking the package manager's list. ```bash dpkg -l | grep libfranka ``` -------------------------------- ### Install Real-Time Kernel Dependencies Source: https://github.com/frankarobotics/libfranka/blob/main/docs/real_time_kernel.rst Installs essential build tools and libraries required for patching and compiling the Linux kernel. Run this command before downloading kernel sources. ```bash sudo apt-get install build-essential bc curl debhelper dpkg-dev devscripts \ fakeroot libssl-dev libelf-dev bison flex cpio kmod rsync libncurses-dev ``` -------------------------------- ### Run libfranka Communication Test Example Source: https://github.com/frankarobotics/libfranka/blob/main/README.rst Executes the communication test example program, which requires the robot's IP address as an argument. This is typically found in the build directory after compiling from source. ```bash cd build/examples ./communication_test ``` -------------------------------- ### Verify pylibfranka Installation Source: https://github.com/frankarobotics/libfranka/blob/main/docs/installation.rst Checks if the pylibfranka package is installed correctly and imports essential classes to confirm functionality. ```python import pylibfranka print(f"pylibfranka version: {pylibfranka.__version__}") # Verify key classes are available from pylibfranka import Robot, Gripper, Model, RobotState print("All core classes imported successfully") ``` -------------------------------- ### Example Robot State Output Source: https://github.com/frankarobotics/libfranka/blob/main/docs/getting_started.rst This is an example of the JSON output from the echo_robot_state command, showing various robot state parameters. Refer to the libfranka API documentation for detailed explanations of each field. ```text { "O_T_EE": [0.998578,0.0328747,-0.0417381,0,0.0335224,-0.999317,0.0149157,0,-0.04122,-0.016294, -0.999017,0,0.305468,-0.00814133,0.483198,1], "O_T_EE_d": [0.998582,0.0329548,-0.041575,0,0.0336027,-0.999313,0.0149824,0,-0.0410535, -0.0163585,-0.999023,0,0.305444,-0.00810967,0.483251,1], "F_T_EE": [0.7071,-0.7071,0,0,0.7071,0.7071,0,0,0,0,1,0,0,0,0.1034,1], "EE_T_K": [1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1], "m_ee": 0.73, "F_x_Cee": [-0.01,0,0.03], "I_ee": [0.001,0,0,0,0.0025,0,0,0,0.0017], ... } ``` -------------------------------- ### Download and Install libfranka Debian Package Source: https://github.com/frankarobotics/libfranka/blob/main/docs/installation.rst Installs the libfranka library using a pre-built Debian package. Ensure you replace the VERSION and CODENAME variables with your specific details. ```bash # Replace with your desired version and Ubuntu codename VERSION=0.19.0 CODENAME=focal # or jammy, noble wget https://github.com/frankarobotics/libfranka/releases/download/${VERSION}/libfranka_${VERSION}_${CODENAME}_amd64.deb sudo dpkg -i libfranka_${VERSION}_${CODENAME}_amd64.deb ``` -------------------------------- ### Custom CMake Build Configuration Source: https://github.com/frankarobotics/libfranka/blob/main/README.rst Example of configuring the libfranka build with specific CMake options, such as build type, enabling tests, and Python bindings. ```bash cmake -DCMAKE_BUILD_TYPE=Debug \ -DBUILD_TESTS=ON \ -DGENERATE_PYLIBFRANKA=ON \ .. ``` -------------------------------- ### Verify Robot State with echo_robot_state Source: https://github.com/frankarobotics/libfranka/blob/main/docs/getting_started.rst Run the echo_robot_state example to print the current robot state to the console. Ensure the robot is prepared for FCI usage and reachable via its IP address. ```shell ./examples/echo_robot_state ``` -------------------------------- ### Motion Generator with Motion Finished Flag Source: https://github.com/frankarobotics/libfranka/blob/main/docs/overview.rst This example demonstrates defining a motion generator callback directly within the robot.control call. It commands joint velocities and signals the end of the motion using franka::MotionFinished. ```c++ robot.control( [=, &time](const franka::RobotState&, franka::Duration period) -> franka::JointVelocities { time += period.toSec(); double cycle = std::floor(std::pow(-1.0, (time - std::fmod(time, time_max)) / time_max)); double omega = cycle * omega_max / 2.0 * (1.0 - std::cos(2.0 * M_PI / time_max * time)); franka::JointVelocities velocities = {{0.0, 0.0, 0.0, omega, omega, omega, omega}}; if (time >= 2 * time_max) { std::cout << std::endl << "Finished motion, shutting down example" << std::endl; return franka::MotionFinished(velocities); } return velocities; }); ``` -------------------------------- ### start_torque_control Source: https://github.com/frankarobotics/libfranka/blob/main/pylibfranka/docs/api/robot.rst Starts a new torque controller, enabling the robot to accept torque commands. Gravity is automatically compensated. ```APIDOC ## start_torque_control ### Description Starts a new torque controller. ### Method Signature `Robot.start_torque_control()` ### Returns * Active control interface for sending torque commands (`ActiveControlBase`) ### Raises * `ControlException`: if an error related to torque control occurred * `InvalidOperationException`: if a conflicting operation is already running * `NetworkException`: if the connection is lost, e.g. after a timeout ### Example ```python robot = pylibfranka.Robot("172.16.0.2") # Start torque control mode (gravity is automatically compensated) control = robot.start_torque_control() # Control loop at 1 kHz for i in range(5000): state, duration = control.readOnce() # Send zero torque for compliant mode tau = pylibfranka.Torques([0, 0, 0, 0, 0, 0, 0]) # Send torque command control.writeOnce(tau) ``` ### See Also * `ActiveControlBase.writeOnce` for sending torque commands ``` -------------------------------- ### start_cartesian_pose_control Source: https://github.com/frankarobotics/libfranka/blob/main/pylibfranka/docs/api/robot.rst Starts a new cartesian pose motion generator, allowing control over the robot's end-effector position and orientation in space. ```APIDOC ## start_cartesian_pose_control ### Description Starts a new cartesian pose motion generator. ### Method Signature `Robot.start_cartesian_pose_control(control_type)` ### Parameters * **control_type** (ControllerMode) - Controller mode for the operation ### Returns * Active control interface for sending position commands (`ActiveControlBase`) ### Raises * `ControlException`: if an error related to motion generation occurred * `InvalidOperationException`: if a conflicting operation is already running * `NetworkException`: if the connection is lost, e.g. after a timeout ``` -------------------------------- ### start_joint_position_control Source: https://github.com/frankarobotics/libfranka/blob/main/pylibfranka/docs/api/robot.rst Starts a new joint position motion generator, allowing control over individual joint positions. ```APIDOC ## start_joint_position_control ### Description Starts a new joint position motion generator. ### Method Signature `Robot.start_joint_position_control(control_type)` ### Parameters * **control_type** (ControllerMode) - Controller mode for the operation ### Returns * Active control interface for sending position commands (`ActiveControlBase`) ### Raises * `ControlException`: if an error related to motion generation occurred * `InvalidOperationException`: if a conflicting operation is already running * `NetworkException`: if the connection is lost, e.g. after a timeout ``` -------------------------------- ### Log Robot State Data to CSV Source: https://github.com/frankarobotics/libfranka/blob/main/pylibfranka/docs/api/state.rst Log detailed robot state data, including time, joint positions, velocities, and torques, over a period and save it to a CSV file. This example uses torque control and requires initializing Robot, Model, and Control objects. ```python import pylibfranka import numpy as np import csv def main(): robot = pylibfranka.Robot("172.16.0.2") model = robot.load_model() # Prepare data logging data_log = [] control = robot.start_torque_control() try: for i in range(1000): state, duration = control.readOnce() # Log state data_log.append({ 'time': state.time.to_sec(), 'q': state.q.copy(), 'dq': state.dq.copy(), 'tau_J': state.tau_J.copy(), 'tau_ext': state.tau_ext_hat_filtered.copy() }) # Control (gravity is automatically compensated) tau = pylibfranka.Torques([0, 0, 0, 0, 0, 0, 0]) control.writeOnce(tau) finally: robot.stop() # Save to CSV with open('robot_data.csv', 'w', newline='') as f: writer = csv.writer(f) writer.writerow(['time', 'q1', 'q2', 'q3', 'q4', 'q5', 'q6', 'q7', 'tau1', 'tau2', 'tau3', 'tau4', 'tau5', 'tau6', 'tau7']) for data in data_log: row = [data['time']] + list(data['q']) + list(data['tau_J']) writer.writerow(row) print(f"Logged {len(data_log)} samples to robot_data.csv") if __name__ == "__main__": main() ``` -------------------------------- ### Basic CMakeLists.txt for libfranka Source: https://github.com/frankarobotics/libfranka/blob/main/docs/assets/example_cmake_lists.txt This snippet shows the essential CMake commands to set up a project that uses libfranka. It finds the package, creates an executable, and links the library. ```cmake cmake_minimum_required(VERSION 3.16) project(MyRobotProject) # Find libfranka find_package(Franka REQUIRED) # Create executable add_executable(${PROJECT_NAME} src/main.cpp) # Link libfranka target_link_libraries(${PROJECT_NAME} Franka::Franka) ``` -------------------------------- ### Remove Existing libfranka Installations Source: https://github.com/frankarobotics/libfranka/blob/main/README.rst Uninstall any previously installed libfranka packages to avoid conflicts before building from source. ```bash sudo apt-get remove -y "*libfranka*" ``` -------------------------------- ### Connect to Robot and Gripper Source: https://github.com/frankarobotics/libfranka/blob/main/docs/overview.rst Establishes a connection to the robot arm and gripper using their IP addresses or hostnames. Exceptions of type franka::Exception are thrown on error. ```c++ #include #include ... franka::Gripper gripper(""); franka::Robot robot(""); ``` -------------------------------- ### Update CMake for Ubuntu 20.04 Source: https://github.com/frankarobotics/libfranka/blob/main/README.rst Ensure CMake version 3.22 or higher is installed on Ubuntu 20.04 by adding the Kitware repository and installing CMake. ```bash wget -O - https://apt.kitware.com/keys/kitware-archive-latest.asc | gpg --dearmor -o /usr/share/keyrings/kitware-archive-keyring.gpg echo "deb [signed-by=/usr/share/keyrings/kitware-archive-keyring.gpg] https://apt.kitware.com/ubuntu/ focal main" | sudo tee /etc/apt/sources.list.d/kitware.list sudo apt-get update sudo apt-get install -y cmake ``` -------------------------------- ### Run Docker Container and Build libfranka Source: https://github.com/frankarobotics/libfranka/blob/main/README.rst Execute the Docker container, mount the current directory, and perform the build process including CMake and cpack. ```bash docker run --rm -it -v $(pwd):/workspaces -w /workspaces libfranka-build:20.04 # Inside container: mkdir build && cd build cmake -DCMAKE_BUILD_TYPE=Release .. cmake --build . -- -j$(nproc) cpack -G DEB exit ``` -------------------------------- ### Defining and Running Control Loops Source: https://github.com/frankarobotics/libfranka/blob/main/docs/overview.rst This snippet shows how to define callback functions for motion generators and external controllers and then run them using the franka::Robot::control method. It includes basic error handling. ```c++ std::function my_external_controller_callback; // Define my_external_controller_callback ... std::function my_external_motion_generator_callback; // Define my_external_motion_generator_callback ... try { franka::Robot robot(""); // only a motion generator robot.control(my_external_motion_generator_callback); // only an external controller robot.control(my_external_controller_callback); // a motion generator and an external controller robot.control(my_external_motion_generator_callback, my_external_controller_callback); } catch (franka::Exception const& e) { std::cout << e.what() << std::endl; return -1; } return 0; ``` -------------------------------- ### Build libfranka Project with CMake Source: https://github.com/frankarobotics/libfranka/blob/main/docs/installation.rst Standard bash commands to create a build directory, configure the project with CMake, and compile the code. Execute these commands from your project's root directory. ```bash mkdir build && cd build cmake .. cmake --build . ``` -------------------------------- ### Execute Gripper and Robot Non-Realtime Commands Source: https://github.com/frankarobotics/libfranka/blob/main/docs/overview.rst Demonstrates calling non-realtime commands for the gripper (homing) and the robot (automatic error recovery). These commands are blocking and executed via TCP/IP. ```c++ gripper.homing(); robot.automaticErrorRecovery(); ``` -------------------------------- ### Build libfranka from source Source: https://github.com/frankarobotics/libfranka/blob/main/README.rst Clones the libfranka repository, checks out a specific version, updates submodules, and builds the library using CMake. ```bash git clone --recurse-submodules https://github.com/frankarobotics/libfranka.git cd libfranka git checkout 0.19.0 git submodule update --init --recursive mkdir build && cd build cmake -DCMAKE_BUILD_TYPE=Release \ -DCMAKE_INSTALL_PREFIX=/usr/local .. cmake --build . -- -j$(nproc) ``` -------------------------------- ### start_joint_velocity_control Source: https://github.com/frankarobotics/libfranka/blob/main/pylibfranka/docs/api/robot.rst Starts a new joint velocity motion generator, enabling control over the speed of individual joints. ```APIDOC ## start_joint_velocity_control ### Description Starts a new joint velocity motion generator. ### Method Signature `Robot.start_joint_velocity_control(control_type)` ### Parameters * **control_type** (ControllerMode) - Controller mode for the operation ### Returns * Active control interface for sending velocity commands (`ActiveControlBase`) ### Raises * `ControlException`: if an error related to motion generation occurred * `InvalidOperationException`: if a conflicting operation is already running * `NetworkException`: if the connection is lost, e.g. after a timeout ``` -------------------------------- ### Create Realtime Group Source: https://github.com/frankarobotics/libfranka/blob/main/docs/real_time_kernel.rst Create a 'realtime' group and add the current user to it. This group will be used for granting real-time permissions. ```bash sudo addgroup realtime sudo usermod -a -G realtime $(whoami) ``` -------------------------------- ### Selecting Internal Controllers Source: https://github.com/frankarobotics/libfranka/blob/main/docs/overview.rst Demonstrates how to set internal controllers (joint impedance and Cartesian impedance) for motion generators using optional arguments in the franka::Robot::control function. ```c++ // Set joint impedance (optional) robot.setJointImpedance({{3000, 3000, 3000, 3000, 3000, 3000, 3000}}); // Runs my_external_motion_generator_callback with the default joint impedance controller robot.control(my_external_motion_generator_callback); // Identical to the previous line (default franka::ControllerMode::kJointImpedance) robot.control(my_external_motion_generator_callback, franka::ControllerMode::kJointImpedance); // Set Cartesian impedance (optional) robot.setCartesianImpedance({{2000, 2000, 2000, 100, 100, 100}}); // Runs my_external_motion_generator_callback with the Cartesian impedance controller robot.control(my_external_motion_generator_callback, franka::ControllerMode::kCartesianImpedance); ``` -------------------------------- ### Build Docker Image for libfranka Source: https://github.com/frankarobotics/libfranka/blob/main/README.rst Build a Docker image for libfranka, specifying the Ubuntu version. This image is used for creating the build environment. ```bash # For Ubuntu 20.04 docker build --build-arg UBUNTU_VERSION=20.04 -t libfranka-build:20.04 .ci/ # For Ubuntu 22.04 docker build --build-arg UBUNTU_VERSION=22.04 -t libfranka-build:22.04 .ci/ # For Ubuntu 24.04 docker build --build-arg UBUNTU_VERSION=24.04 -t libfranka-build:24.04 .ci/ ``` -------------------------------- ### start_cartesian_velocity_control Source: https://github.com/frankarobotics/libfranka/blob/main/pylibfranka/docs/api/robot.rst Starts a new cartesian velocity motion generator, enabling control over the end-effector's linear and angular velocity. ```APIDOC ## start_cartesian_velocity_control ### Description Starts a new cartesian velocity motion generator. ### Method Signature `Robot.start_cartesian_velocity_control(control_type)` ### Parameters * **control_type** (ControllerMode) - Controller mode for the operation ### Returns * Active control interface for sending velocity commands (`ActiveControlBase`) ### Raises * `ControlException`: if an error related to motion generation occurred * `InvalidOperationException`: if a conflicting operation is already running * `NetworkException`: if the connection is lost, e.g. after a timeout ``` -------------------------------- ### ActiveControlBase Class Source: https://github.com/frankarobotics/libfranka/blob/main/pylibfranka/docs/api_overview.rst Allows the user to read the state of a Robot and to send new control commands after starting a control process of a Robot. ```APIDOC ## Class: ActiveControlBase ### Description Allows the user to read the state of a Robot and to send new control commands after starting a control process of a Robot. ### Type Class ``` -------------------------------- ### Creating the Python Module Source: https://github.com/frankarobotics/libfranka/blob/main/pylibfranka/CMakeLists.txt Uses pybind11 to add the C++ source files to create the '_pylibfranka' Python module. ```cmake pybind11_add_module(_pylibfranka src/pylibfranka.cpp src/async_control.cpp src/gripper.cpp # add more source files as needed for next splits ) ``` -------------------------------- ### InvalidOperationException Source: https://github.com/frankarobotics/libfranka/blob/main/pylibfranka/docs/api/exceptions.rst Raised when an operation is attempted that cannot be performed in the current state, such as starting an already running control loop or calling methods in an invalid sequence. ```APIDOC ## InvalidOperationException ### Description Thrown if an operation cannot be performed. This exception is raised when attempting to start a control loop while one is already running, calling methods in an invalid state, or when conflicting operations are requested. ### Hierarchy FrankaException -> InvalidOperationException ``` -------------------------------- ### Import GPG Keys for Verification Source: https://github.com/frankarobotics/libfranka/blob/main/docs/real_time_kernel.rst Imports necessary GPG public keys to verify the authenticity of downloaded kernel archives and patches. This is required if you encounter 'No public key' warnings during verification. ```bash gpg2 --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 6092693E gpg2 --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 2872E4CC ``` -------------------------------- ### RobotMode Enum Source: https://github.com/frankarobotics/libfranka/blob/main/pylibfranka/docs/api/state.rst Represents the operating mode of the robot. This enum provides distinct values for different robot states like Idle, Move, Guiding, Reflex, etc. ```APIDOC ## RobotMode Enum ### Description An enumeration representing the current operating mode of the robot. ### Values * **RobotMode.Other**: Other/unknown mode. * **RobotMode.Idle**: Robot is idle. * **RobotMode.Move**: Robot is executing a motion. * **RobotMode.Guiding**: Robot is in guiding mode (hand-guided). * **RobotMode.Reflex**: Robot triggered a reflex. * **RobotMode.UserStopped**: User stopped the robot. * **RobotMode.AutomaticErrorRecovery**: Automatic error recovery in progress. ### Example ```python state = robot.read_once() if state.robot_mode == pylibfranka.RobotMode.Idle: print("Robot is idle") elif state.robot_mode == pylibfranka.RobotMode.Move: print("Robot is moving") ``` ``` -------------------------------- ### Real-time Configuration Options Source: https://github.com/frankarobotics/libfranka/blob/main/pylibfranka/docs/api/robot.rst Enumeration for real-time configuration options. This helps in managing real-time requirements for robot control, either by enforcing them or ignoring them. ```APIDOC ## Real-time Configuration Options ### Description Enumeration for real-time configuration options. ### Members * **kEnforce**: Enforce real-time requirements (recommended for actual control) * **kIgnore**: Ignore real-time requirements (useful for testing/development) ``` -------------------------------- ### Start Torque Control Source: https://github.com/frankarobotics/libfranka/blob/main/pylibfranka/docs/api/robot.rst Initiates torque control mode, allowing for sending torque commands to the robot. Gravity is automatically compensated. Requires a control loop running at 1 kHz. ```python robot = pylibfranka.Robot("172.16.0.2") # Start torque control mode (gravity is automatically compensated) control = robot.start_torque_control() # Control loop at 1 kHz for i in range(5000): state, duration = control.readOnce() # Send zero torque for compliant mode tau = pylibfranka.Torques([0, 0, 0, 0, 0, 0, 0]) # Send torque command control.writeOnce(tau) ``` -------------------------------- ### CMakeLists.txt for libfranka Project Source: https://github.com/frankarobotics/libfranka/blob/main/docs/installation.rst This CMakeLists.txt file demonstrates how to find the libfranka package and link it to your executable. Ensure this file is in the root of your project. ```cmake cmake_minimum_required(VERSION 3.16) project(franka_example) find_package(Franka REQUIRED) add_executable(example_main main.cpp) target_link_libraries(example_main PRIVATE Franka::Franka) ``` -------------------------------- ### Setting Include Directories Source: https://github.com/frankarobotics/libfranka/blob/main/pylibfranka/CMakeLists.txt Specifies private include directories for the '_pylibfranka' target, including the local 'include' directory. ```cmake target_include_directories(_pylibfranka PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include ) ``` -------------------------------- ### Verify Real-Time Kernel Source: https://github.com/frankarobotics/libfranka/blob/main/docs/real_time_kernel.rst Check the kernel version and the existence of the realtime sysfs entry to confirm the real-time kernel is running. ```bash uname -a ``` ```bash ls /sys/kernel/realtime ``` -------------------------------- ### Configure Kernel Build Source: https://github.com/frankarobotics/libfranka/blob/main/docs/real_time_kernel.rst Copies the current running kernel's configuration to the new kernel source directory and disables specific debug options to reduce kernel size and improve performance. ```bash cp -v /boot/config-$(uname -r) .config scripts/config --disable DEBUG_INFO scripts/config --disable DEBUG_INFO_DWARF_TOOLCHAIN_DEFAULT scripts/config --disable DEBUG_KERNEL scripts/config --disable SYSTEM_TRUSTED_KEYS scripts/config --disable SYSTEM_REVOCATION_LIST ``` -------------------------------- ### Run Compiled libfranka Application Source: https://github.com/frankarobotics/libfranka/blob/main/docs/installation.rst Command to execute the built application after successful compilation. Ensure you are in the build directory when running this command. ```bash ./example_main ``` -------------------------------- ### Configure Real-Time Limits Source: https://github.com/frankarobotics/libfranka/blob/main/docs/real_time_kernel.rst Add specific real-time priority and memory lock limits for the 'realtime' group in the system's security configuration file. ```bash @realtime soft rtprio 99 @realtime soft priority 99 @realtime soft memlock 102400 @realtime hard rtprio 99 @realtime hard priority 99 @realtime hard memlock 102400 ``` -------------------------------- ### Check Ubuntu Version Source: https://github.com/frankarobotics/libfranka/blob/main/docs/installation.rst Use this command to determine your current Ubuntu version, which is necessary for downloading the correct libfranka Debian package. ```bash lsb_release -a ``` -------------------------------- ### Basic CMake Configuration Source: https://github.com/frankarobotics/libfranka/blob/main/pylibfranka/CMakeLists.txt Sets the minimum CMake version, project name, and C++ standard. Ensures position-independent code is enabled. ```cmake cmake_minimum_required(VERSION 3.16) project(franka_python_bindings VERSION ${libfranka_VERSION}) # Set C++ standard set(CMAKE_CXX_STANDARD 17) set(CMAKE_CXX_STANDARD_REQUIRED ON) set(CMAKE_POSITION_INDEPENDENT_CODE ON) ``` -------------------------------- ### Create Debian Package for libfranka Source: https://github.com/frankarobotics/libfranka/blob/main/README.rst Generates a Debian package from the build directory. This is an optional step for easier distribution. ```bash cpack -G DEB sudo dpkg -i libfranka*.deb ``` -------------------------------- ### Connect to Robot Source: https://github.com/frankarobotics/libfranka/blob/main/pylibfranka/docs/api/robot.rst Establishes a connection with the robot controller. Supports both enforcing and ignoring real-time scheduling requirements. ```python import pylibfranka # Connect with real-time enforcement robot = pylibfranka.Robot("172.16.0.2") # Connect without real-time enforcement (for testing) robot_test = pylibfranka.Robot( "172.16.0.2", pylibfranka.RealtimeConfig.kIgnore ) ``` -------------------------------- ### Read Single Robot State Sample Source: https://github.com/frankarobotics/libfranka/blob/main/docs/overview.rst Reads a single sample of the robot state using the readOnce function. Ensure a valid connection to the robot is established before calling this function. ```c++ franka::RobotState state = robot.readOnce(); ``` -------------------------------- ### Finding Required Packages Source: https://github.com/frankarobotics/libfranka/blob/main/pylibfranka/CMakeLists.txt Finds and configures dependencies including Python 3 (Interpreter, Development, NumPy), pybind11, Eigen3, Poco (Foundation, Net), and Pinocchio. ```cmake find_package(Python3 COMPONENTS Interpreter Development NumPy REQUIRED) find_package(pybind11 CONFIG REQUIRED) if(NOT pybind11_FOUND) find_package(pybind11 MODULE REQUIRED) endif() find_package(Eigen3 REQUIRED) find_package(Poco REQUIRED COMPONENTS Foundation Net) find_package(pinocchio REQUIRED) ``` -------------------------------- ### Configure Ubuntu Version for Docker Source: https://github.com/frankarobotics/libfranka/blob/main/README.rst Specify the desired Ubuntu version for the Docker build environment by editing the devcontainer_distro file. ```bash 22.04 # Ubuntu 22.04 (default) ```