### Partial C++ Example for RTDE Real-time Control Setup Source: https://github.com/medra-ai/ur_rtde/blob/master/doc/guides/guides.rst This partial C++ code snippet provides the initial setup for a real-time control example using `ur_rtde` interfaces. It includes necessary headers, namespace declarations, and defines parameters such as robot IP, RTDE frequency, and real-time priorities for the receive and control interfaces. This forms the foundation for a more complete real-time application. ```c++ #include #include #include #include #include using namespace ur_rtde; using namespace std::chrono; // interrupt flag bool running = true; void raiseFlag(int param) { running = false; } std::vector getCircleTarget(const std::vector &pose, double timestep, double radius=0.075, double freq=1.0) { std::vector circ_target = pose; circ_target[0] = pose[0] + radius * cos((2 * M_PI * freq * timestep)); circ_target[1] = pose[1] + radius * sin((2 * M_PI * freq * timestep)); return circ_target; } int main(int argc, char* argv[]) { // Setup parameters std::string robot_ip = "localhost"; double rtde_frequency = 500.0; // Hz double dt = 1.0 / rtde_frequency; // 2ms uint16_t flags = RTDEControlInterface::FLAG_VERBOSE | RTDEControlInterface::FLAG_UPLOAD_SCRIPT; int ur_cap_port = 50002; // ur_rtde realtime priorities int rt_receive_priority = 90; int rt_control_priority = 85; } ``` -------------------------------- ### Install and Configure Docker on Linux Source: https://github.com/medra-ai/ur_rtde/blob/master/doc/guides/guides.rst Provides commands to install Docker Engine on a Linux system, start and enable the Docker service, verify its status, and add the current user to the `docker` group to manage Docker without `sudo`. ```Shell sudo apt update sudo apt install docker.io sudo systemctl start docker sudo systemctl enable docker sudo systemctl status docker sudo usermod -aG docker $USER su - $USER ``` -------------------------------- ### Install Real-time Linux Kernel Debian Packages Source: https://github.com/medra-ai/ur_rtde/blob/master/doc/guides/guides.rst This command uses `dpkg` with `sudo` to install the compiled Linux kernel headers and image Debian packages. This step integrates the new real-time kernel into the system, making it available for booting. ```shell sudo dpkg -i ../linux-headers-*.deb ../linux-image-*.deb ``` -------------------------------- ### Initial Command Line Build Setup for ur_rtde Source: https://github.com/medra-ai/ur_rtde/blob/master/doc/installation/installation.rst Provides the sequence of shell commands to clone the ur_rtde repository, create a build directory, configure CMake with Boost paths, and compile the project using msbuild. This is a general setup with placeholders for Boost paths and core count. ```shell git clone https://gitlab.com/sdurobotics/ur_rtde.git cd ur_rtde mkdir Build cd Build cmake -DBOOST_ROOT=">" -DBOOST_LIBRARYDIR="\\>" -DPYTHON_BINDINGS=OFF .. msbuild ur_rtde.sln /property:Configuration=Release /maxcpucount: ``` -------------------------------- ### Example Command Line Build with Specific Boost Paths Source: https://github.com/medra-ai/ur_rtde/blob/master/doc/installation/installation.rst Demonstrates a concrete example of the CMake and msbuild commands for compiling ur_rtde on a Windows machine with 8 cores, Visual Studio 2019, and Boost 1.71.0, showing how to specify Boost root and library directories. ```shell cmake -DBOOST_ROOT="C:\\local\\boost_1_71_0" -DBOOST_LIBRARYDIR="C:\\local\\boost_1_71_0\\lib64-msvc-14.2" -DPYTHON_BINDINGS=OFF .. msbuild ur_rtde.sln /property:Configuration=Release /maxcpucount:8 ``` -------------------------------- ### Python Example: Control Robotiq Gripper with ur_rtde Source: https://github.com/medra-ai/ur_rtde/blob/master/doc/guides/guides.rst This snippet demonstrates how to use the `robotiq_gripper.py` class to connect, activate, and control a Robotiq gripper. It shows how to move the gripper to specific positions (fully open and fully closed) and log its current status, including position and open/closed state. ```python import robotiq_gripper import time ip = "127.0.0.1" def log_info(gripper): print(f"Pos: {str(gripper.get_current_position()): >3} "\ f"Open: {gripper.is_open(): <2} "\ f"Closed: {gripper.is_closed(): <2} ") print("Creating gripper...") gripper = robotiq_gripper.RobotiqGripper() print("Connecting to gripper...") gripper.connect(ip, 63352) print("Activating gripper...") gripper.activate() print("Testing gripper...") gripper.move_and_wait_for_pos(255, 255, 255) log_info(gripper) gripper.move_and_wait_for_pos(0, 255, 255) log_info(gripper) ``` -------------------------------- ### Clone URSim Docker Repository Source: https://github.com/medra-ai/ur_rtde/blob/master/doc/guides/guides.rst Clones the `ursim_docker` GitHub repository, which contains scripts and configurations for setting up a Dockerized Universal Robots Simulator environment. This is the first step in using URSim with Docker. ```Shell git clone https://github.com/urrsk/ursim_docker.git ``` -------------------------------- ### Install Kernel Build Dependencies on Ubuntu Source: https://github.com/medra-ai/ur_rtde/blob/master/doc/guides/guides.rst This command installs a comprehensive set of essential tools and libraries required for building a custom real-time kernel on various Ubuntu systems, including 20.04, 18.04, and 16.04. These dependencies encompass compilers, development headers, and various utilities crucial for the kernel compilation process. ```shell sudo apt-get install build-essential bc curl ca-certificates gnupg2 libssl-dev lsb-release libelf-dev zstd libncurses-dev dwarves gawk flex bison ``` -------------------------------- ### Example GPG Good Signature Verification Output Source: https://github.com/medra-ai/ur_rtde/blob/master/doc/guides/guides.rst This snippet displays an example of successful `gpg2` signature verification output. A 'Good signature' message confirms the file's authenticity, though a warning about key trust might still appear, which is common for kernel keys. ```none $ gpg2 --verify linux-*.tar.sign gpg: assuming signed data in 'linux-4.14.12.tar' gpg: Signature made Fr 05 Jan 2018 06:49:11 PST using RSA key ID 6092693E gpg: Good signature from "Greg Kroah-Hartman " [unknown] gpg: aka "Greg Kroah-Hartman " [unknown] gpg: aka "Greg Kroah-Hartman (Linux kernel stable release signing key) " [unknown] gpg: WARNING: This key is not certified with a trusted signature! gpg: There is no indication that the signature belongs to the owner. Primary key fingerprint: 647F 2865 4894 E3BD 4571 99BE 38DB BDC8 6092 693E ``` -------------------------------- ### Attach Ubuntu Advantage Subscription for Real-time Kernel Source: https://github.com/medra-ai/ur_rtde/blob/master/doc/guides/guides.rst This command attaches your personal machine to an Ubuntu Advantage subscription. This subscription is required to access the real-time beta kernel for free personal use on Ubuntu 22.04, and you must replace with the token from your Ubuntu One account. ```shell ua attach ``` -------------------------------- ### Install Git Build Package Source: https://github.com/medra-ai/ur_rtde/blob/master/debian/how_to_setup.md This command installs git-buildpackage, a tool that integrates Git with Debian package building, allowing developers to manage Debian packages using Git repositories. ```bash sudo apt-get install git-buildpackage ``` -------------------------------- ### Build URSim Docker Image Source: https://github.com/medra-ai/ur_rtde/blob/master/doc/guides/guides.rst Builds a custom Docker image for the Universal Robots Simulator (URSim) from the `ursim_docker` repository. This command allows specifying the URSim version and the download URL for the simulator package. ```Shell docker build ursim/e-series -t myursim --build-arg VERSION=5.11.1.108318 --build-arg URSIM="https://s3-eu-west-1.amazonaws.com/ur-support-site/118926/URSim_Linux-5.11.1.108318.tar.gz" ``` -------------------------------- ### Install Essential Build Packages Source: https://github.com/medra-ai/ur_rtde/blob/master/debian/how_to_setup.md This command installs a set of essential build tools and development utilities required for compiling and packaging software on Ubuntu-based systems. It includes compilers, scripting tools, and utilities for Debian package creation. ```bash sudo apt-get install build-essential devscripts ubuntu-dev-tools debhelper dh-make patch cdbs quilt gnupg fakeroot lintian ``` -------------------------------- ### Quick Install ur_rtde on Linux (Ubuntu) via APT Source: https://github.com/medra-ai/ur_rtde/blob/master/doc/installation/installation.rst Provides commands to quickly install the ur_rtde library and its development files on Ubuntu by adding the official PPA and using apt. ```shell sudo add-apt-repository ppa:sdurobotics/ur-rtde sudo apt-get update sudo apt install librtde librtde-dev ``` -------------------------------- ### Configure Real-time Kernel Build Options Source: https://github.com/medra-ai/ur_rtde/blob/master/doc/guides/guides.rst These commands prepare the kernel configuration. `make olddefconfig` updates the configuration with new options while keeping existing ones, and `make menuconfig` launches a terminal-based interface for interactive configuration, allowing selection of preemption models and other settings. ```shell make olddefconfig make menuconfig ``` -------------------------------- ### Example GPG Signature Verification Error Output Source: https://github.com/medra-ai/ur_rtde/blob/master/doc/guides/guides.rst This snippet shows an example output from `gpg2` when attempting to verify a signature without the corresponding public key. The error 'Can't check signature: No public key' indicates that the required signing key needs to be imported first. ```none $ gpg2 --verify linux-*.tar.sign gpg: assuming signed data in 'linux-4.14.12.tar' gpg: Signature made Fr 05 Jan 2018 06:49:11 PST using RSA key ID 6092693E gpg: Can't check signature: No public key ``` -------------------------------- ### Integrate ur_rtde Library with CMake Source: https://github.com/medra-ai/ur_rtde/blob/master/doc/examples/examples.rst Demonstrates how to find and link the ur_rtde library in a C++ CMake project using `find_package()`. It also provides instructions for handling non-standard installation paths by setting `ur_rtde_DIR` or specifying `PATHS` in `find_package()`. ```cmake cmake_minimum_required(VERSION 3.5) project(ur_rtde_cmake_example) find_package(ur_rtde REQUIRED) add_executable(ur_rtde_cmake_example main.cpp) target_link_libraries(ur_rtde_cmake_example PRIVATE ur_rtde::rtde) ``` -------------------------------- ### Full C++ Example: Record Robot Data to CSV Source: https://github.com/medra-ai/ur_rtde/blob/master/doc/examples/examples.rst This comprehensive C++ example illustrates how to set up a program to record robot data to a CSV file. It includes necessary headers, signal handling for graceful exit, and command-line argument parsing for robot IP, recording frequency, and output file name. The rtde_receive_interface is used to connect to the robot and start data recording. ```c++ #include #include #include #include #include #include #include using namespace ur_rtde; using namespace std::chrono; namespace po = boost::program_options; // Interrupt flag bool flag_loop = true; void raiseFlag(int param) { flag_loop = false; } int main(int argc, char* argv[]) { try { po::options_description desc("Allowed options"); desc.add_options() ("help", "Record robot data to a (.csv) file") ("robot_ip", po::value()->default_value("localhost"), "the IP address of the robot") ("frequency", po::value()->default_value(500.0), "the frequency at which the data is recorded (default is 500Hz)") ("output", po::value()->default_value("robot_data.csv"), ``` -------------------------------- ### Check Ubuntu Advantage Tools Version Source: https://github.com/medra-ai/ur_rtde/blob/master/doc/guides/guides.rst This command checks the current version of the ubuntu-advantage-tools package installed on your system. It is recommended to have at least version 27.8 to ensure compatibility and proper functionality when enabling the real-time kernel on Ubuntu 22.04. ```shell ua version ``` -------------------------------- ### Enable Real-time Beta Kernel on Ubuntu 22.04 Source: https://github.com/medra-ai/ur_rtde/blob/master/doc/guides/guides.rst This command enables the real-time beta kernel on Ubuntu 22.04 using the ubuntu-advantage-tools. After executing this command, a system reboot is essential for the real-time kernel to be properly loaded and become active. ```shell ua enable realtime-kernel --beta ``` -------------------------------- ### Control Universal Robot with RTDE in MATLAB Source: https://github.com/medra-ai/ur_rtde/blob/master/doc/guides/guides.rst This MATLAB example demonstrates how to establish a connection with a Universal Robot using RTDEReceiveInterface and RTDEControlInterface. It shows how to retrieve the robot's actual joint and TCP pose, convert the data to MATLAB arrays, and then command the robot to move to specified Cartesian positions using moveL. The 'clear' command is crucial at the end to release background threads. ```matlab import py.rtde_receive.RTDEReceiveInterface import py.rtde_control.RTDEControlInterface rtde_r = RTDEReceiveInterface("localhost"); rtde_c = RTDEControlInterface("localhost"); actual_q = rtde_r.getActualQ(); actual_tcp_pose = rtde_r.getActualTCPPose(); % Convert to MATLAB array of double actual_q_array = cellfun(@double, cell(actual_q)); actual_tcp_pose_array = cellfun(@double, cell(actual_tcp_pose)); actual_q_array actual_tcp_pose_array position1 = [-0.343, -0.435, 0.50, -0.001, 3.12, 0.04]; position2 = [-0.243, -0.335, 0.20, -0.001, 3.12, 0.04]; rtde_c.moveL(position1); rtde_c.moveL(position2); rtde_c.stopRobot(); clear ``` -------------------------------- ### Control Robotiq Gripper via Custom Script Function in Python Source: https://github.com/medra-ai/ur_rtde/blob/master/doc/guides/guides.rst This Python example demonstrates controlling a Robotiq gripper by sending a custom script function through the RTDEControlInterface. It initializes the gripper, sets its force and speed, and performs basic actions like opening, closing, and moving to a specific position. This method requires sending a preamble script with each function call, which can introduce delay. ```python from robotiq_gripper_control import RobotiqGripper from rtde_control import RTDEControlInterface import time rtde_c = RTDEControlInterface("") gripper = RobotiqGripper(rtde_c) # Activate the gripper and initialize force and speed gripper.activate() # returns to previous position after activation gripper.set_force(50) # from 0 to 100 % gripper.set_speed(100) # from 0 to 100 % # Perform some gripper actions gripper.open() gripper.close() time.sleep(1) gripper.open() gripper.move(10) # mm # Stop the rtde control script rtde_c.stopRobot() ``` -------------------------------- ### Download Real-time Kernel Sources for Ubuntu 20.04 (Kernel 5.9.1) Source: https://github.com/medra-ai/ur_rtde/blob/master/doc/guides/guides.rst This command initiates the download of kernel source files for Ubuntu 20.04, specifically for kernel version 5.9.1. This is the initial step in obtaining the necessary components required to compile a real-time kernel for this operating system version. ```shell curl -SLO https://www.kernel.org/pub/linux/kernel/v5.x/ ``` -------------------------------- ### Extract Kernel Source and Apply Real-time Patch Source: https://github.com/medra-ai/ur_rtde/blob/master/doc/guides/guides.rst These commands first extract the Linux kernel source from its tarball and then navigate into the extracted directory. Subsequently, the real-time patch is applied to the kernel source, transforming it into a real-time capable kernel. ```shell tar xf linux-*.tar cd linux-* patch -p1 < ../patch-*.patch ``` -------------------------------- ### Run URSim Docker Container Source: https://github.com/medra-ai/ur_rtde/blob/master/doc/guides/guides.rst Launches a Docker container from the built URSim image, mapping essential ports for VNC access (5900) and RTDE/external control (29999, 30001-30004). The `--rm` flag ensures the container is automatically removed upon exit. ```Shell docker run --rm -it -p 5900:5900 -p 29999:29999 -p 30001-30004:30001-30004 myursim ``` -------------------------------- ### Copy Current Kernel Configuration Source: https://github.com/medra-ai/ur_rtde/blob/master/doc/guides/guides.rst This command copies the configuration of the currently running kernel to the `.config` file in the new kernel source directory. This provides a baseline configuration, simplifying the process of customizing the new real-time kernel build. ```shell cp -v /boot/config-$(uname -r) .config ``` -------------------------------- ### Kernel Preemption Model Selection in Menuconfig Source: https://github.com/medra-ai/ur_rtde/blob/master/doc/guides/guides.rst This snippet illustrates the interactive menuconfig option for selecting the kernel preemption model. For a fully real-time kernel, option '5. Fully Preemptible Kernel (RT) (PREEMPT_RT_FULL)' should be chosen to ensure low-latency and deterministic behavior. ```none Preemption Model 1. No Forced Preemption (Server) (PREEMPT_NONE) > 2. Voluntary Kernel Preemption (Desktop) (PREEMPT_VOLUNTARY) 3. Preemptible Kernel (Low-Latency Desktop) (PREEMPT__LL) (NEW) 4. Preemptible Kernel (Basic RT) (PREEMPT_RTB) (NEW) 5. Fully Preemptible Kernel (RT) (PREEMPT_RT_FULL) (NEW) choice[1-5]: 5 ``` -------------------------------- ### Build ur_rtde from Source on Linux and macOS Source: https://github.com/medra-ai/ur_rtde/blob/master/doc/installation/installation.rst Comprehensive commands to clone the ur_rtde repository, initialize submodules, create a build directory, configure with CMake, compile, and install the library from source on Linux and macOS systems. ```shell git clone https://gitlab.com/sdurobotics/ur_rtde.git cd ur_rtde git submodule update --init --recursive mkdir build cd build cmake .. make sudo make install ``` -------------------------------- ### Upgrade Ubuntu Advantage Tools on Ubuntu 22.04 Source: https://github.com/medra-ai/ur_rtde/blob/master/doc/guides/guides.rst This command upgrades the ubuntu-advantage-tools package to version 27.8 specifically for Ubuntu 22.04, also known as Jammy Jellyfish. This particular version is necessary to successfully enable the real-time beta kernel on your system. ```shell sudo apt install ubuntu-advantage-tools=27.8~22.04.1 ``` -------------------------------- ### Define UR RTDE Example Executables (CMake) Source: https://github.com/medra-ai/ur_rtde/blob/master/CMakeLists.txt This CMake snippet defines various example executables for the UR RTDE library, such as I/O, asynchronous movement, path movement, Robotiq gripper control, move until contact, data recording, and real-time control examples. These executables are aliased for easier reference within the build system. ```CMake add_executable(ur_rtde::io_example ALIAS io_example) add_executable(ur_rtde::move_async_example ALIAS move_async_example) add_executable(ur_rtde::move_path_async_example ALIAS move_path_async_example) add_executable(ur_rtde::robotiq_gripper_example ALIAS robotiq_gripper_example) add_executable(ur_rtde::move_until_contact_example ALIAS move_until_contact_example) add_executable(ur_rtde::record_data_example ALIAS record_data_example) add_executable(ur_rtde::realtime_control_example ALIAS realtime_control_example) ``` -------------------------------- ### Verify Kernel and Patch Signatures with GPG Source: https://github.com/medra-ai/ur_rtde/blob/master/doc/guides/guides.rst These commands use `gpg2` to verify the digital signatures of the downloaded Linux kernel tarball and the real-time patch. This optional but recommended step ensures the integrity and authenticity of the files, preventing corruption or tampering. ```shell gpg2 --verify linux-*.tar.sign gpg2 --verify patch-*.patch.sign ``` -------------------------------- ### CMake Configuration for UR RTDE Example Executables Source: https://github.com/medra-ai/ur_rtde/blob/master/examples/cpp/CMakeLists.txt This CMakeLists.txt file configures the build process for several UR RTDE example applications. It sets the minimum required CMake version, defines the project, and then adds multiple executables, each corresponding to a specific robot control functionality (e.g., force mode, movement, I/O, gripper control). All executables are linked against the 'ur_rtde::rtde' library, which provides the core RTDE communication capabilities. ```CMake cmake_minimum_required(VERSION 3.5) project(ur_rtde_examples) if(POLICY CMP0074) cmake_policy(SET CMP0074 NEW) endif() set(DIR ${CMAKE_CURRENT_SOURCE_DIR}) message(STATUS "${DIR}") find_package(ur_rtde REQUIRED PATHS "${DIR}/../../Build/ur_rtde" "${DIR}/../../build/ur_rtde") add_executable(forcemode_example forcemode_example.cpp) target_link_libraries(forcemode_example PUBLIC ur_rtde::rtde) add_executable(move_until_contact move_until_contact.cpp) target_link_libraries(move_until_contact PUBLIC ur_rtde::rtde) add_executable(io io_example.cpp) target_link_libraries(io PUBLIC ur_rtde::rtde) add_executable(move_path_async_example move_path_async_example.cpp) target_link_libraries(move_path_async_example PUBLIC ur_rtde::rtde) add_executable(movej_path_with_blend movej_path_with_blend_example.cpp) target_link_libraries(movej_path_with_blend PUBLIC ur_rtde::rtde) add_executable(servoj servoj_example.cpp) target_link_libraries(servoj PUBLIC ur_rtde::rtde) add_executable(speedj speedj_example.cpp) target_link_libraries(speedj PUBLIC ur_rtde::rtde) add_executable(move_async move_async_example.cpp) target_link_libraries(move_async PUBLIC ur_rtde::rtde) add_executable(robotiq_gripper_example robotiq_gripper_example.cpp) target_link_libraries(robotiq_gripper_example PUBLIC ur_rtde::rtde) add_executable(contact_detection_example contact_detection_example.cpp) target_link_libraries(contact_detection_example PUBLIC ur_rtde::rtde) ``` -------------------------------- ### Configure ForceMode C++ Example Executable Source: https://github.com/medra-ai/ur_rtde/blob/master/CMakeLists.txt This snippet, part of the conditional examples build, defines the 'forcemode_example' executable. It specifies its C++ source file, sets up public include directories for Boost and the project, and links it against the 'rtde' library and Boost system/thread libraries. ```CMake add_executable(forcemode_example examples/cpp/forcemode_example.cpp) target_include_directories(forcemode_example PUBLIC ${Boost_INCLUDE_DIRS} $ $) target_link_libraries(forcemode_example PRIVATE rtde ${Boost_SYSTEM_LIBRARY} ${Boost_THREAD_LIBRARY}) ``` -------------------------------- ### Install Boost Libraries and Headers for Windows Installer (CMake) Source: https://github.com/medra-ai/ur_rtde/blob/master/CMakeLists.txt This CMake snippet, active only when `WINDOWS_INSTALLER` is enabled, uses the `getBoostLibraryList` macro to collect all necessary Boost library files and installs them to the specified library installation directory. It also installs a curated subset of Boost header directories and specific header files, ensuring Boost dependencies are correctly packaged for Windows distributions. ```CMake if(WINDOWS_INSTALLER) set(BOOST_LIBRARIES_INSTALL "") getBoostLibraryList(BOOST_LIBRARIES_INSTALL "${Boost_LIBRARIES}") # Install external libraries install( FILES ${BOOST_LIBRARIES_INSTALL} DESTINATION ${LIB_INSTALL_DIR} COMPONENT boost ) install( DIRECTORY "${Boost_INCLUDE_DIR}/boost/asio" "${Boost_INCLUDE_DIR}/boost/config" "${Boost_INCLUDE_DIR}/boost/core" "${Boost_INCLUDE_DIR}/boost/date_time" "${Boost_INCLUDE_DIR}/boost/detail" "${Boost_INCLUDE_DIR}/boost/exception" "${Boost_INCLUDE_DIR}/boost/mpl" "${Boost_INCLUDE_DIR}/boost/numeric" "${Boost_INCLUDE_DIR}/boost/predef" "${Boost_INCLUDE_DIR}/boost/preprocessor" "${Boost_INCLUDE_DIR}/boost/smart_ptr" "${Boost_INCLUDE_DIR}/boost/system" "${Boost_INCLUDE_DIR}/boost/type_traits" "${Boost_INCLUDE_DIR}/boost/winapi" DESTINATION "${INCLUDE_INSTALL_DIR}/ext/boost/" COMPONENT boost ) install( FILES "${Boost_INCLUDE_DIR}/boost/assert.hpp" "${Boost_INCLUDE_DIR}/boost/cerrno.hpp" "${Boost_INCLUDE_DIR}/boost/checked_delete.hpp" "${Boost_INCLUDE_DIR}/boost/config.hpp" "${Boost_INCLUDE_DIR}/boost/cstdint.hpp" "${Boost_INCLUDE_DIR}/boost/current_function.hpp" "${Boost_INCLUDE_DIR}/boost/limits.hpp" "${Boost_INCLUDE_DIR}/boost/operators.hpp" "${Boost_INCLUDE_DIR}/boost/shared_ptr.hpp" ) ``` -------------------------------- ### Create Temporary Directory for Real-time Kernel Build Source: https://github.com/medra-ai/ur_rtde/blob/master/doc/guides/guides.rst These commands first create a dedicated temporary directory named rt_kernel_build within the user's home folder. Subsequently, they navigate into this newly created directory, which will serve as the workspace for storing extracted kernel sources and build artifacts, requiring approximately 25GB of free space. ```shell mkdir -p ${HOME}/rt_kernel_build cd ${HOME}/rt_kernel_build ``` -------------------------------- ### Quick Install ur_rtde Python Interface via Pip Source: https://github.com/medra-ai/ur_rtde/blob/master/doc/installation/installation.rst Instructions to install only the Python interface of the ur_rtde library using pip. Ensure pip version is 19.3 or newer for successful installation. ```shell pip install --user ur_rtde ``` -------------------------------- ### Compile Real-time Linux Kernel into Debian Packages Source: https://github.com/medra-ai/ur_rtde/blob/master/doc/guides/guides.rst This command compiles the configured real-time Linux kernel into Debian packages (`.deb`). The `-j$(nproc)` option utilizes all available CPU cores for parallel compilation, significantly speeding up the build process. ```shell make -j$(nproc) deb-pkg ``` -------------------------------- ### Download Linux Kernel and RT Patch Sources Source: https://github.com/medra-ai/ur_rtde/blob/master/doc/guides/guides.rst This snippet uses `curl` to download the Linux kernel source tarball, its corresponding signature file, the real-time (RT) patch, and its signature file from the kernel.org archives. These files are essential for building a real-time Linux kernel. ```shell curl -SLO https://www.kernel.org/pub/linux/kernel/v5.x/linux-5.9.1.tar.xz curl -SLO https://www.kernel.org/pub/linux/kernel/v5.x/linux-5.9.1.tar.sign curl -SLO https://www.kernel.org/pub/linux/kernel/projects/rt/5.9/patch-5.9.1-rt20.patch.xz curl -SLO https://www.kernel.org/pub/linux/kernel/projects/rt/5.9/patch-5.9.1-rt20.patch.sign ``` -------------------------------- ### Move Robot to Pose using RTDE Control Interface Source: https://github.com/medra-ai/ur_rtde/blob/master/doc/examples/examples.rst Illustrates how to use the RTDE Control Interface to move the robot to a specified 6D pose using the `moveL` command. The example shows initialization of the interface with the robot's IP address and includes parameters for speed and acceleration. ```c++ // The constructor simply takes the IP address of the Robot RTDEControlInterface rtde_control("127.0.0.1"); // First argument is the pose 6d vector followed by speed and acceleration rtde_control.moveL({-0.143, -0.435, 0.20, -0.001, 3.12, 0.04}, 0.5, 0.2); ``` ```python import rtde_control rtde_c = rtde_control.RTDEControlInterface("127.0.0.1") rtde_c.moveL([-0.143, -0.435, 0.20, -0.001, 3.12, 0.04], 0.5, 0.3) ``` -------------------------------- ### Install Boost Dependency for ur_rtde Build Source: https://github.com/medra-ai/ur_rtde/blob/master/doc/installation/installation.rst Commands to install the Boost library, a core dependency for ur_rtde, on Ubuntu via apt-get and on macOS via Homebrew. For Windows, precompiled binaries are linked. ```shell sudo apt-get install libboost-all-dev ``` ```shell brew install boost ``` -------------------------------- ### Set Runtime Output Directory for UR RTDE Examples Source: https://github.com/medra-ai/ur_rtde/blob/master/CMakeLists.txt Sets the `RUNTIME_OUTPUT_DIRECTORY` property for a list of UR RTDE example executables to the `bin` subdirectory within the current source directory. This ensures all specified examples are built into a common output location. ```CMake set_target_properties(servoj_example forcemode_example speedj_example movej_path_with_blend_example io_example move_async_example move_path_async_example robotiq_gripper_example move_until_contact_example record_data_example realtime_control_example contact_detection_example PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/bin" ) ``` -------------------------------- ### Get Robot Joint Positions using RTDE Receive Interface Source: https://github.com/medra-ai/ur_rtde/blob/master/doc/examples/examples.rst Shows how to initialize the RTDE Receive Interface and retrieve the robot's actual joint positions. The constructor takes the robot's IP address, and by default, all variables are transmitted, though a subset can be specified. ```c++ /* The constructor takes the IP address of the robot, by default all variables are * transmitted. Optionally only a subset of variables, specified by a vector, are transmitted. */ RTDEReceiveInterface rtde_receive("127.0.0.1"); std::vector joint_positions = rtde_receive.getActualQ(); ``` ```python import rtde_receive rtde_r = rtde_receive.RTDEReceiveInterface("127.0.0.1") actual_q = rtde_r.getActualQ() ``` -------------------------------- ### Configure ServoJ C++ Example Executable Source: https://github.com/medra-ai/ur_rtde/blob/master/CMakeLists.txt This conditional block, active if EXAMPLES is enabled, defines the 'servoj_example' executable. It specifies the C++ source file, configures public include directories for Boost and the project, and links the executable against the 'rtde' library and Boost system/thread libraries. ```CMake add_executable(servoj_example examples/cpp/servoj_example.cpp) target_include_directories(servoj_example PUBLIC ${Boost_INCLUDE_DIRS} $ $) target_link_libraries(servoj_example PRIVATE rtde ${Boost_SYSTEM_LIBRARY} ${Boost_THREAD_LIBRARY}) ``` -------------------------------- ### Configure SpeedJ C++ Example Executable Source: https://github.com/medra-ai/ur_rtde/blob/master/CMakeLists.txt This block, within the conditional examples build, defines the 'speedj_example' executable. It specifies its C++ source file, configures public include directories for Boost and the project, and links it against the 'rtde' library and Boost system/thread libraries. ```CMake add_executable(speedj_example examples/cpp/speedj_example.cpp) ``` -------------------------------- ### Control Robotiq Gripper with ur_rtde Source: https://github.com/medra-ai/ur_rtde/blob/master/doc/examples/examples.rst This example illustrates how to connect to and control a Robotiq Gripper using the `RobotiqGripper` interface. It covers activating the gripper, testing emergency release functionality, and setting position units. A helper function `printStatus` is included to interpret gripper object detection states. ```C++ #include #include #include #include using namespace std; using namespace ur_rtde; /** * Print object detection status of gripper */ void printStatus(int Status) { switch (Status) { case RobotiqGripper::MOVING: std::cout << "moving"; break; case RobotiqGripper::STOPPED_OUTER_OBJECT: std::cout << "outer object detected"; break; case RobotiqGripper::STOPPED_INNER_OBJECT: std::cout << "inner object detected"; break; case RobotiqGripper::AT_DEST: std::cout << "at destination"; break; } std::cout << std::endl; } int main(int argc, char* argv[]) { std::cout << "Gripper test" << std::endl; ur_rtde::RobotiqGripper gripper("127.0.0.1", 63352, true); gripper.connect(); // Test emergency release functionality if (!gripper.isActive()) { gripper.emergencyRelease(RobotiqGripper::OPEN); } std::cout << "Fault status: 0x" << std::hex << gripper.faultStatus() << std::dec << std::endl; std::cout << "activating gripper" << std::endl; gripper.activate(); // Test setting of position units and conversion of position values gripper.setUnit(RobotiqGripper::POSITION, RobotiqGripper::UNIT_DEVICE); } ``` -------------------------------- ### Initialize RTDE Control and Move Robot (External UR Cap) Source: https://github.com/medra-ai/ur_rtde/blob/master/doc/examples/examples.rst This C++ snippet initializes the RTDEControlInterface for controlling a UR robot, specifying the robot's IP address, a frequency (500.0 Hz), and using the FLAG_USE_EXT_UR_CAP for external control. It then performs a linear move (moveL) to a specified pose with a given speed and acceleration. This setup requires the ExternalControl node configured on the robot. ```c++ RTDEControlInterface rtde_control("127.0.0.1", 500.0, RTDEControlInterface::FLAG_USE_EXT_UR_CAP); rtde_control.moveL({-0.143, -0.435, 0.20, -0.001, 3.12, 0.04}, 0.5, 0.2); ``` -------------------------------- ### Download Real-time Kernel Sources for Ubuntu 16.04 (Kernel 4.14.12) Source: https://github.com/medra-ai/ur_rtde/blob/master/doc/guides/guides.rst These curl commands download the specific kernel source tarball, its corresponding signature, and the necessary real-time patch for Ubuntu 16.04, targeting kernel version 4.14.12. These files are fundamental components required to compile a real-time capable kernel for the specified Ubuntu release. ```shell curl -SLO https://www.kernel.org/pub/linux/kernel/v4.x/linux-4.14.12.tar.xz curl -SLO https://www.kernel.org/pub/linux/kernel/v4.x/linux-4.14.12.tar.sign curl -SLO https://www.kernel.org/pub/linux/kernel/projects/rt/4.14/older/patch-4.14.12-rt10.patch.xz curl -SLO https://www.kernel.org/pub/linux/kernel/projects/rt/4.14/older/patch-4.14.12-rt10.patch.sign ``` -------------------------------- ### Install UR RTDE on Ubuntu via PPA Source: https://github.com/medra-ai/ur_rtde/blob/master/README.md Instructions for installing the UR RTDE library on Ubuntu systems using the sdurobotics PPA. This method installs both the C++ library and development files, providing system-wide access. ```Shell sudo add-apt-repository ppa:sdurobotics/ur-rtde sudo apt-get update sudo apt install librtde librtde-dev ``` -------------------------------- ### Configure CPack and NSIS for UR RTDE Project Source: https://github.com/medra-ai/ur_rtde/blob/master/CMakeLists.txt This CMake configuration block sets up CPack for creating installation packages and specifically configures NSIS for Windows installers. It defines package metadata such as name, vendor, description, homepage, and version. It also includes custom commands for adding and removing registry entries to ensure CMake can locate the installed UR RTDE package, and defines installation components and groups. ```CMake "${Boost_INCLUDE_DIR}/boost/static_assert.hpp" "${Boost_INCLUDE_DIR}/boost/throw_exception.hpp" "${Boost_INCLUDE_DIR}/boost/type.hpp" "${Boost_INCLUDE_DIR}/boost/version.hpp" DESTINATION "${INCLUDE_INSTALL_DIR}/ext/boost/" COMPONENT boost ) if(DEFINED MSVC) set(SLASH "\\") ############################### CPACK setup ######################################### set(CPACK_PACKAGE_NAME "${PROJECT_NAME}") set(CPACK_PACKAGE_VENDOR "University of Southern Denmark") set( CPACK_PACKAGE_DESCRIPTION_SUMMARY "A C++ interface for sending and receiving data to/from a UR robot using the Real-Time Data Exchange (RTDE) interface of the robot" ) set(CPACK_PACKAGE_HOMEPAGE_URL "https://sdurobotics.gitlab.io/ur_rtde/") set(CPACK_PACKAGE_INSTALL_DIRECTORY "ur_rtde") set(CPACK_RESOURCE_FILE_LICENSE "${PROJECT_SOURCE_DIR}${SLASH}LICENSE") set(CPACK_PACKAGE_CONTACT "Anders Prier Lindvig (anpl@mmmi.sdu.dk)") set(CPACK_PACKAGE_VERSION ${PROJECT_VERSION}) set(CPACK_PACKAGE_VERSION_MAJOR ${PROJECT_VERSION_MAJOR}) set(CPACK_PACKAGE_VERSION_MINOR ${PROJECT_VERSION_MINOR}) set(CPACK_PACKAGE_VERSION_PATCH ${PROJECT_VERSION_PATCH}) set(CPACK_PACKAGE_FILE_NAME ${CPACK_PACKAGE_NAME}-install) ############################### NSIS setup ######################################### set(CPACK_NSIS_DISPLAY_NAME "${PROJECT_NAME}") set(CPACK_NSIS_PACKAGE_NAME "${PROJECT_NAME}") set(CPACK_NSIS_HELP_LINK ${CPACK_PACKAGE_HOMEPAGE_URL}) set(CPACK_NSIS_URL_INFO_ABOUT ${CPACK_PACKAGE_HOMEPAGE_URL}) #set( # CPACK_NSIS_MUI_ICON # "${PROJECT_SOURCE_DIR}${SLASH}doc${SLASH}_static${SLASH}robots.png" # needs to be 32x32.ico file #) #set( # CPACK_NSIS_MUI_UNWELCOMEFINISHPAGE_BITMAP # "${PROJECT_SOURCE_DIR}${SLASH}doc${SLASH}_static${SLASH}robots.png" # needs to be 128x64.bmp file #) #set(CPACK_NSIS_MUI_WELCOMEFINISHPAGE_BITMAP ${CPACK_NSIS_MUI_UNWELCOMEFINISHPAGE_BITMAP}) set(CPACK_NSIS_ENABLE_UNINSTALL_BEFORE_INSTALL ON) # When installing on a previus # instalation ask to uninstall first set(CPACK_NSIS_UNINSTALL_NAME "ur_rtde_uninstall") set(CPACK_NSIS_CONTACT ${CPACK_PACKAGE_CONTACT}) # Make sure the system findes the project at installation if(BUILD_STATIC) set(CPACK_NSIS_MODIFY_PATH OFF) # Add the binary folder to PATH else() set(CPACK_NSIS_MODIFY_PATH ON) # Add the binary folder to PATH endif() set( CPACK_NSIS_EXTRA_INSTALL_COMMANDS # let cmake find ur_rtde "WriteRegStr HKCU \\\"Software${SLASH}Kitware${SLASH}CMake${SLASH}Packages${SLASH}ur_rtde\\\" \\\"Location\\\" \\\"$INSTDIR\\\"" "WriteRegStr HKLM \\\"Software${SLASH}Kitware${SLASH}CMake${SLASH}Packages${SLASH}ur_rtde\\\" \\\"Location\\\" \\\"$INSTDIR\\\"" ) set( CPACK_NSIS_EXTRA_UNINSTALL_COMMANDS # clean up when uninstalling ur_rtde "DeleteRegKey HKCU \\\"Software${SLASH}Kitware${SLASH}CMake${SLASH}Packages${SLASH}ur_rtde\\\"" "DeleteRegKey HKLM \\\"Software${SLASH}Kitware${SLASH}CMake${SLASH}Packages${SLASH}ur_rtde\\\"" ) string( REPLACE ";" "\n" CPACK_NSIS_EXTRA_INSTALL_COMMANDS "${CPACK_NSIS_EXTRA_INSTALL_COMMANDS}" ) string( REPLACE ";" "\n" CPACK_NSIS_EXTRA_UNSTALL_COMMANDS "${CPACK_NSIS_EXTRA_UNINSTALL_COMMANDS}" ) ############################### Package setup ######################################### get_cmake_property(CPACK_COMPONENTS_ALL COMPONENTS) # Get all components include(CPack) # Setup Install Groupes #### cpack_add_component_group(UR_RTDE DISPLAY_NAME "ur_rtde" DESCRIPTION "Libraries for controlling UR robots" EXPANDED BOLD_TITLE ) cpack_add_component_group(MISC DISPLAY_NAME "Miscellaneous" DESCRIPTION "These are miscellaneous packages" ) cpack_add_component_group(DEP DISPLAY_NAME "Dependencies" DESCRIPTION "These are external dependencies for the ur_rtde" ) cpack_add_component_group(DEVEL DISPLAY_NAME "Development Files" DESCRIPTION "These are packages needed when you want to use ur_rtde for development" ) # Setup Install Types #### cpack_add_install_type(Full DISPLAY_NAME "Full") # Setup Install Components cpack_add_component( ur_rtde_lib DISPLAY_NAME "DevelFiles" DESCRIPTION "This package includes the files necessary to run a program that depends on ur_rtde" GROUP UR_RTDE DEPENDS ur_rtde_lib INSTALL_TYPES Full # DOWNLOADED ARCHIVE_FILE #Name_of_file_to_generate_for_download ) cpack_add_component( ur_rtde_dev DISPLAY_NAME "DevelFiles" ``` -------------------------------- ### Control Robot Digital and Analog I/O with ur_rtde Source: https://github.com/medra-ai/ur_rtde/blob/master/doc/examples/examples.rst This example demonstrates how to interact with the robot's standard and tool digital outputs, as well as analog outputs, using the `RTDEIOInterface` and `RTDEReceiveInterface`. It shows how to read the current state of digital outputs and how to set their values, including setting an analog output current. ```C++ #include #include #include #include using namespace ur_rtde; int main(int argc, char* argv[]) { RTDEIOInterface rtde_io("127.0.0.1"); RTDEReceiveInterface rtde_receive("127.0.0.1"); /** How-to set and get standard and tool digital outputs. Notice that we need the * RTDEIOInterface for setting an output and RTDEReceiveInterface for getting the state * of an output. */ if (rtde_receive.getDigitalOutState(7)) std::cout << "Standard digital out (7) is HIGH" << std::endl; else std::cout << "Standard digital out (7) is LOW" << std::endl; if (rtde_receive.getDigitalOutState(16)) std::cout << "Tool digital out (16) is HIGH" << std::endl; else std::cout << "Tool digital out (16) is LOW" << std::endl; rtde_io.setStandardDigitalOut(7, true); rtde_io.setToolDigitalOut(0, true); std::this_thread::sleep_for(std::chrono::milliseconds(10)); if (rtde_receive.getDigitalOutState(7)) std::cout << "Standard digital out (7) is HIGH" << std::endl; else std::cout << "Standard digital out (7) is LOW" << std::endl; if (rtde_receive.getDigitalOutState(16)) std::cout << "Tool digital out (16) is HIGH" << std::endl; else std::cout << "Tool digital out (16) is LOW" << std::endl; // How to set a analog output with a specified current ratio rtde_io.setAnalogOutputCurrent(1, 0.25); return 0; } ``` ```Python import rtde_io import rtde_receive import time rtde_io_ = rtde_io.RTDEIOInterface("127.0.0.1") rtde_receive_ = rtde_receive.RTDEReceiveInterface("127.0.0.1") # How-to set and get standard and tool digital outputs. Notice that we need the # RTDEIOInterface for setting an output and RTDEReceiveInterface for getting the state # of an output. if rtde_receive_.getDigitalOutState(7): print("Standard digital out (7) is HIGH") else: print("Standard digital out (7) is LOW") if rtde_receive_.getDigitalOutState(16): print("Tool digital out (16) is HIGH") else: print("Tool digital out (16) is LOW") rtde_io_.setStandardDigitalOut(7, True) rtde_io_.setToolDigitalOut(0, True) time.sleep(0.01) if rtde_receive_.getDigitalOutState(7): print("Standard digital out (7) is HIGH") else: print("Standard digital out (7) is LOW") if rtde_receive_.getDigitalOutState(16): print("Tool digital out (16) is HIGH") else: print("Tool digital out (16) is LOW") # How to set a analog output with a specified current ratio rtde_io_.setAnalogOutputCurrent(1, 0.25) ``` -------------------------------- ### Conditionally Create Aliases for UR RTDE Example Executables Source: https://github.com/medra-ai/ur_rtde/blob/master/CMakeLists.txt Conditionally creates namespaced aliases for several UR RTDE example executables (e.g., `ur_rtde::servoj_example` for `servoj_example`) if the `EXAMPLES` CMake variable is true. This provides a consistent way to reference these targets. ```CMake if(${EXAMPLES}) add_executable(ur_rtde::servoj_example ALIAS servoj_example) add_executable(ur_rtde::forcemode_example ALIAS forcemode_example) add_executable(ur_rtde::speedj_example ALIAS speedj_example) add_executable(ur_rtde::movej_path_with_blend_example ALIAS movej_path_with_blend_example) endif() ``` -------------------------------- ### Initialize RTDE Control with Custom Script Source: https://github.com/medra-ai/ur_rtde/blob/master/doc/examples/examples.rst This example demonstrates initializing the RTDEControlInterface using the FLAG_CUSTOM_SCRIPT, indicating that a custom script is running on the robot controller. After initialization, it executes a linear movement command (moveL) to a target pose with specified speed and acceleration. This approach allows access to robot-installed functionalities. ```python from rtde_control import RTDEControlInterface as RTDEControl rtde_c = RTDEControl("127.0.0.1", RTDEControl.FLAG_CUSTOM_SCRIPT) rtde_c.moveL([-0.143, -0.435, 0.20, -0.001, 3.12, 0.04], 0.5, 0.3) ``` ```c++ RTDEControlInterface rtde_control("127.0.0.1", RTDEControlInterface::FLAG_CUSTOM_SCRIPT); rtde_control.moveL({-0.143, -0.435, 0.20, -0.001, 3.12, 0.04}, 0.5, 0.2); ``` -------------------------------- ### Control UR Robot Joints with ServoJ (C++/Python) Source: https://github.com/medra-ai/ur_rtde/blob/master/doc/examples/examples.rst This example illustrates the use of the servoJ command for incremental joint control. It continuously modifies the base and shoulder joints within a 500Hz control loop for 2 seconds, demonstrating precise, real-time joint trajectory following. The example highlights parameters like velocity, acceleration, and gain for smooth movement, and notes that joint positions must be close for fast control rates. ```C++ #include #include #include using namespace ur_rtde; using namespace std::chrono; int main(int argc, char* argv[]) { RTDEControlInterface rtde_control("127.0.0.1"); // Parameters double velocity = 0.5; double acceleration = 0.5; double dt = 1.0/500; // 2ms double lookahead_time = 0.1; double gain = 300; std::vector joint_q = {-1.54, -1.83, -2.28, -0.59, 1.60, 0.023}; // Move to initial joint position with a regular moveJ rtde_control.moveJ(joint_q); // Execute 500Hz control loop for 2 seconds, each cycle is ~2ms for (unsigned int i=0; i<1000; i++) { steady_clock::time_point t_start = rtde_control.initPeriod(); rtde_control.servoJ(joint_q, velocity, acceleration, dt, lookahead_time, gain); joint_q[0] += 0.001; joint_q[1] += 0.001; rtde_control.waitPeriod(t_start); } rtde_control.servoStop(); rtde_control.stopScript(); return 0; } ``` ```Python import rtde_control rtde_c = rtde_control.RTDEControlInterface("127.0.0.1") # Parameters velocity = 0.5 acceleration = 0.5 dt = 1.0/500 # 2ms lookahead_time = 0.1 gain = 300 joint_q = [-1.54, -1.83, -2.28, -0.59, 1.60, 0.023] # Move to initial joint position with a regular moveJ rtde_c.moveJ(joint_q) # Execute 500Hz control loop for 2 seconds, each cycle is 2ms for i in range(1000): t_start = rtde_c.initPeriod() rtde_c.servoJ(joint_q, velocity, acceleration, dt, lookahead_time, gain) joint_q[0] += 0.001 joint_q[1] += 0.001 rtde_c.waitPeriod(t_start) rtde_c.servoStop() rtde_c.stopScript() ```