### CMake: Install Example Targets Source: https://github.com/rokaerobot/xcoresdk-cpp/blob/main/example/rt/CMakeLists.txt Installs the configured executable targets to the appropriate directories based on the build system's conventions. Libraries are installed to the library directory, and runtime binaries are installed to the binary directory. The OPTIONAL keyword indicates that the installation is not mandatory. ```cmake install(TARGETS ${RT_EXAMPLES} ${EXAMPLES_USE_XMATEMODEL} LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} OPTIONAL ) ``` -------------------------------- ### CMake: Setup RT Mode Examples Source: https://github.com/rokaerobot/xcoresdk-cpp/blob/main/example/rt/CMakeLists.txt Configures CMake to build several real-time mode example executables. It defines a list of example sources, adds them as executables, sets include directories, and links necessary libraries (Rokae, Eigen, Threads). It also handles platform-specific definitions like _USE_MATH_DEFINES for MSVC. ```cmake set(RT_EXAMPLES joint_position_control joint_impedance_control cartesian_impedance_control move_commands joint_s_line cartesian_s_line rt_industrial ) foreach(example ${RT_EXAMPLES}) add_executable(${example} ${example}.cpp ${EXAMPLE_HEADERS}) target_include_directories(${example} PUBLIC ${SHARED_INCLUDEDIR}) target_link_libraries(${example} Rokae::Rokae eigen Threads::Threads) if(MSVC) add_compile_definitions(_USE_MATH_DEFINES) endif() # for M_PI in cmath endforeach() ``` -------------------------------- ### CMake: Configure Example Executables Source: https://github.com/rokaerobot/xcoresdk-cpp/blob/main/example/CMakeLists.txt Sets up the project for C++ examples, defines necessary preprocessor macros for MSVC and shared library linking, and configures compiler options. It then iterates through a list of example source files to create executables, linking against Rokae, Threads, and eigen libraries. ```cmake project(xCoreSDK-examples CXX) add_compile_definitions( # for M_PI in cmath $<\:_USE_MATH_DEFINES> # if linking the shared library, add a macro for MSVC dllimport attribute $<\:XCORESDK_DLL>) add_compile_options($<\:/utf-8>) # Here puts required example source files set(EXAMPLES sdk_example move_example path_record rl_project read_robot_state ) set(EXAMPLE_HEADERS ${CMAKE_CURRENT_SOURCE_DIR}/print_helper.hpp ) # threading set(THREADS_PREFER_PTHREAD_FLAG ON) find_package (Threads REQUIRED) foreach(example ${EXAMPLES}) add_executable(${example} ${example}.cpp ${EXAMPLE_HEADERS}) target_include_directories(${example} PUBLIC ${SHARED_INCLUDEDIR}) target_link_libraries(${example} Rokae::Rokae Threads::Threads eigen) endforeach() # check for xMateModel library option if(XCORE_USE_XMATE_MODEL) set(EXAMPLES_USE_XMATEMODEL xmatemodel_er3_er7p ) foreach(example ${EXAMPLES_USE_XMATEMODEL}) add_executable(${example} ${example}.cpp ${EXAMPLE_HEADERS}) target_include_directories(${example} PUBLIC ${SHARED_INCLUDEDIR}) target_link_libraries(${example} Rokae::Rokae Threads::Threads eigen) target_compile_definitions(${example} PUBLIC XMATEMODEL_LIB_SUPPORTED) endforeach() endif() # ------------------------------------------------------------------------------ add_subdirectory(rt) #------------------------------------------------------------------------------- # Installation install(TARGETS ${EXAMPLES} ${EXAMPLES_USE_XMATEMODEL} LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} OPTIONAL ) ``` -------------------------------- ### CMake: Setup xMateModel Examples Source: https://github.com/rokaerobot/xcoresdk-cpp/blob/main/example/rt/CMakeLists.txt Conditionally sets up example executables that require the xMateModel library. This block is executed only if the XCORE_USE_XMATE_MODEL CMake option is enabled. It defines executables, specifies include paths, links libraries, and adds a specific compile definition for xMateModel support. ```cmake if(XCORE_USE_XMATE_MODEL) set(EXAMPLES_USE_XMATEMODEL torque_control follow_joint_position ) foreach(example ${EXAMPLES_USE_XMATEMODEL}) add_executable(${example} ${example}.cpp ${EXAMPLE_HEADERS}) target_include_directories(${example} PUBLIC ${SHARED_INCLUDEDIR}) target_link_libraries(${example} Rokae::Rokae eigen Threads::Threads) target_compile_definitions(${example} PUBLIC XMATEMODEL_LIB_SUPPORTED) endforeach() endif() ``` -------------------------------- ### Build xCore SDK with CMake Source: https://github.com/rokaerobot/xcoresdk-cpp/blob/main/README.md Demonstrates common CMake build targets for the xCore SDK C++ project. Includes options for building all, cleaning, building example programs, installing, and generating documentation. ```bash # Build all targets (default) cmake --build . # Clean build artifacts cmake --build . --target clean # Build the example program cmake --build . --target sdk_example # Install executables to CMAKE_INSTALL_PREFIX cmake --build . --target install # Generate API documentation (requires Doxygen) cmake --build . --target doc ``` -------------------------------- ### Install CMake and g++ on Ubuntu Source: https://github.com/rokaerobot/xcoresdk-cpp/blob/main/README.md Installs CMake and g++ compilers on Ubuntu systems, essential for building C++ projects with CMake. Includes steps for updating package lists and installing necessary software. ```bash sudo apt install cmake g++ ``` -------------------------------- ### CMake Project Setup and Configuration Source: https://github.com/rokaerobot/xcoresdk-cpp/blob/main/CMakeLists.txt Configures the CMake project version, sets output directories for archives, libraries, PDB files, and executables. It also defines default build type and C++ standard, along with enabling compile command export and Visual Studio folder usage. ```cmake cmake_minimum_required (VERSION 3.12) #------------------------------------------------------------------------------ ## Project setup project (xCoreSDK VERSION 0.3.4) message(STATUS "") message(STATUS " == ${PROJECT_NAME} project configuration ==") message(STATUS "") #------------------------------------------------------------------------------ ## General settings # Setup output path include(GNUInstallDirs) set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib" CACHE PATH "Archive output dir.") set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib" CACHE PATH "Library output dir.") set(CMAKE_PDB_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin" CACHE PATH "PDB (MSVC debug symbol)output dir.") set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin" CACHE PATH "Executable/dll output dir.") # default build type: release if(NOT CMAKE_BUILD_TYPE ) set(CMAKE_BUILD_TYPE Release CACHE STRING "The type of build, options are: Debug, Release, RelWithDebInfo, MinSizeRel." FORCE ) endif() # Compiler options set(CMAKE_CXX_STANDARD 17) set(CMAKE_CXX_STANDARD_REQUIRED ON) set(CMAKE_EXPORT_COMPILE_COMMANDS ON) # Be nice to visual studio set_property(GLOBAL PROPERTY USE_FOLDERS ON) ``` -------------------------------- ### Tool and Workpiece Coordinate System Setup (C++) Source: https://context7.com/rokaerobot/xcoresdk-cpp/llms.txt Illustrates two methods for setting the toolset: directly specifying load, end effector, and reference frame parameters, or using predefined tool and workpiece names from an RL project. It also shows how to query the current toolset and apply offsets relative to the workpiece or tool during motion commands. Requires the 'rokae/robot.h' header. ```cpp #include "rokae/robot.h" using namespace rokae; xMateRobot robot("192.168.0.160"); std::error_code ec; // Method 1: Set toolset directly with load, end frame, and reference frame Toolset toolset; toolset.load.mass = 2.0; // kg toolset.load.cog = {0.0, 0.0, 0.05}; // center of gravity [x, y, z] in meters toolset.load.inertia = {0.01, 0.01, 0.01}; // [Ixx, Iyy, Izz] in kg·m² // End effector frame relative to flange toolset.end.trans = {0.0, 0.0, 0.15}; // [x, y, z] in meters toolset.end.rpy = {0.0, 0.0, 0.0}; // [Rx, Ry, Rz] in radians // Reference frame (workpiece) relative to base toolset.ref.trans = {0.5, 0.0, 0.0}; toolset.ref.rpy = {0.0, 0.0, M_PI/4}; robot.setToolset(toolset, ec); // Method 2: Use predefined tool/workpiece names from RL project auto currentToolset = robot.setToolset("tool1", "wobj1", ec); if (!ec) { std::cout << "Toolset configured successfully" << std::endl; std::cout << "Load mass: " << currentToolset.load.mass << " kg" << std::endl; } // Query current toolset auto queryToolset = robot.toolset(ec); // Set motion with offset relative to workpiece or tool std::array pos = {0.5, 0.0, 0.4, M_PI, 0.0, M_PI}; std::array offset = {0.0, 0.0, 0.1, 0.0, 0.0, 0.0}; // Z+ 100mm MoveLCommand moveL(pos, 500, 5); moveL.offset = {CartesianPosition::Offset::offs, offset}; // Offset relative to workpiece // Or offset relative to tool moveL.offset = {CartesianPosition::Offset::relTool, offset}; std::string cmdID; robot.moveAppend({moveL}, cmdID, ec); robot.moveStart(ec); ``` -------------------------------- ### Install Latest CMake on Ubuntu 18.04 Source: https://github.com/rokaerobot/xcoresdk-cpp/blob/main/README.md Provides a detailed procedure to install the latest version of CMake on Ubuntu 18.04, bypassing the default version. This involves removing existing CMake, adding a new repository, and installing the updated package. ```bash sudo apt remove --purge --auto-remove cmake sudo apt update && \ sudo apt install -y software-properties-common lsb-release && \ sudo apt clean all wget -O - https://apt.kitware.com/keys/kitware-archive-latest.asc 2>/dev/null | gpg --dearmor - | sudo tee /etc/apt/trusted.gpg.d/kitware.gpg >/dev/null sudo apt-add-repository "deb https://apt.kitware.com/ubuntu/ $(lsb_release -cs) main" sudo apt update sudo apt install kitware-archive-keyring sudo rm /etc/apt/trusted.gpg.d/kitware.gpg sudo apt update sudo apt install cmake ``` -------------------------------- ### Robot Jogging Control in C++ Source: https://context7.com/rokaerobot/xcoresdk-cpp/llms.txt Provides examples of how to jog a Rokae robot in different coordinate systems and modes using the SDK. This includes jogging in world, joint, and tool coordinate systems, as well as specialized modes like singularity avoidance and base parallel mode for xMateCR/xMateSR robots. Ensure the robot is in manual mode and powered on before jogging. Dependencies include the rokae/robot.h header. ```cpp #include "rokae/robot.h" using namespace rokae; xMateRobot robot("192.168.0.160"); std::error_code ec; // Set to manual mode for jogging robot.setOperateMode(OperateMode::manual, ec); robot.setPowerState(true, ec); // Jog in world coordinate system // Parameters: space, rate, step, index, direction // Move along Z+ axis, 50mm, at 50% speed robot.startJog(JogOpt::world, 0.5, 50.0, 2, true, ec); // Wait for motion to complete... robot.stop(ec); // Always call stop() after jog // Jog in joint space // Rotate joint 5 (index 5) in negative direction, 5000mm step, 5% speed robot.startJog(JogOpt::jointSpace, 0.05, 5000.0, 5, false, ec); // User can manually stop... robot.stop(ec); // Jog in tool coordinate system robot.startJog(JogOpt::toolFrame, 0.3, 100.0, 0, true, ec); // X+ direction robot.stop(ec); // For xMateCR/xMateSR: Singularity avoidance jog mode robot.startJog(JogOpt::singularityAvoidMode, 0.2, 50.0, 1, true, ec); // Y+ direction robot.stop(ec); // For xMateCR/xMateSR: Base parallel mode robot.startJog(JogOpt::baseParallelMode, 0.2, 50.0, 2, true, ec); // Z+ direction robot.stop(ec); ``` -------------------------------- ### Real-time Joint Position Control in C++ Source: https://context7.com/rokaerobot/xcoresdk-cpp/llms.txt This snippet demonstrates how to perform real-time joint position control. It initializes the robot, sets up for real-time commands, and then uses a callback function to generate a sinusoidal trajectory for each joint. The control loop is started in blocking mode. Dependencies include the `rokae/robot.h` header. ```cpp #include "rokae/robot.h" using namespace rokae; xMateRobot robot("192.168.0.160", "192.168.0.100"); std::error_code ec; // Setup for realtime control robot.setOperateMode(OperateMode::automatic, ec); robot.setMotionControlMode(MotionControlMode::RtCommand, ec); robot.setPowerState(true, ec); try { // Get realtime motion controller auto rtCon = robot.getRtMotionController().lock(); // Start receiving robot state at 1ms interval robot.startReceiveRobotState( std::chrono::milliseconds(1), {RtSupportedFields::jointPos_m, RtSupportedFields::jointVel_m} ); // Set filter parameters (optional) rtCon->setFilterFrequency(50.0, 50.0, 50.0, ec); // joint, cartesian, torque // Initial joint positions std::array init_pos = robot.jointPos(ec); std::array target_pos = {0.0, M_PI/6, M_PI/3, 0.0, M_PI/2, 0.0}; // Move to starting position using MoveJ rtCon->MoveJ(0.3, init_pos, target_pos); // Define control loop callback bool init = true; double time = 0.0; std::array start_pos; std::function callback = [&]() { if (init) { start_pos = robot.jointPos(ec); init = false; } time += 0.001; // 1ms increment // Generate sinusoidal motion double delta = M_PI / 20.0 * (1.0 - std::cos(M_PI / 2.5 * time)); JointPosition cmd({ start_pos[0] + delta, start_pos[1] + delta, start_pos[2] - delta, start_pos[3] + delta, start_pos[4] - delta, start_pos[5] + delta }); if (time > 10.0) { cmd.setFinished(); // End after 10 seconds } return cmd; }; // Set control loop and start rtCon->setControlLoop(callback, 0, true); // priority=0, use state data in loop rtCon->startMove(RtControllerMode::jointPosition); rtCon->startLoop(true); // Blocking call std::cout << "Realtime control finished" << std::endl; } catch (const RealtimeControlException& e) { std::cerr << "Realtime control error: " << e.what() << std::endl; } catch (const std::exception& e) { std::cerr << "Error: " << e.what() << std::endl; } robot.stopReceiveRobotState(); ``` -------------------------------- ### Real-time Cartesian Impedance Control in C++ Source: https://context7.com/rokaerobot/xcoresdk-cpp/llms.txt This example illustrates real-time Cartesian impedance control. It configures impedance parameters, desired contact force, force control coordinate frame, filter frequency, and the robot's tool center point (TCP). A callback function generates a circular trajectory in the XY plane. Dependencies include the `rokae/robot.h` header. ```cpp #include "rokae/robot.h" using namespace rokae; Cobot<6> robot("192.168.0.160", "192.168.0.100"); std::error_code ec; robot.setOperateMode(OperateMode::automatic, ec); robot.setMotionControlMode(MotionControlMode::RtCommand, ec); robot.setPowerState(true, ec); auto rtCon = robot.getRtMotionController().lock(); // Set Cartesian impedance parameters // Stiffness: [X, Y, Z, Rx, Ry, Rz] - max: {1500, 1500, 1500, 100, 100, 100} std::array impedance = {1000.0, 1000.0, 1000.0, 50.0, 50.0, 50.0}; rtCon->setCartesianImpedance(impedance, ec); // Set desired contact force (optional) std::array desired_force = {0.0, 0.0, -10.0, 0.0, 0.0, 0.0}; // -10N in Z rtCon->setCartesianImpedanceDesiredTorque(desired_force, ec); // Set force control coordinate frame std::array fc_frame; std::fill(fc_frame.begin(), fc_frame.end(), 0.0); fc_frame[0] = fc_frame[5] = fc_frame[10] = fc_frame[15] = 1.0; rtCon->setFcCoor(fc_frame, FrameType::world, ec); // Set filter frequency rtCon->setFilterFrequency(50.0, 30.0, 50.0, ec); // Set TCP std::array tcp_frame; std::fill(tcp_frame.begin(), tcp_frame.end(), 0.0); tcp_frame[0] = tcp_frame[5] = tcp_frame[10] = 1.0; tcp_frame[11] = 0.15; // 150mm offset in Z tcp_frame[15] = 1.0; rtCon->setEndEffectorFrame(tcp_frame, ec); robot.startReceiveRobotState(std::chrono::milliseconds(1), { RtSupportedFields::jointPos_m, RtSupportedFields::tcpPose_m }); CartesianPosition start_pos = robot.cartPosture(CoordinateType::flangeInBase, ec); double time = 0.0; std::function callback = [&]() { time += 0.001; // Circular motion in XY plane double radius = 0.05; double omega = 2.0 * M_PI / 5.0; // 5 second period CartesianPosition cmd; cmd.trans[0] = start_pos.trans[0] + radius * std::cos(omega * time); cmd.trans[1] = start_pos.trans[1] + radius * std::sin(omega * time); cmd.trans[2] = start_pos.trans[2]; cmd.rpy = start_pos.rpy; cmd.pos = start_pos.pos; // Or compute from trans and rpy if (time > 20.0) { cmd.setFinished(); } return cmd; }; rtCon->setControlLoop(callback, 0, true); rtCon->startMove(RtControllerMode::cartesianImpedance); rtCon->startLoop(true); robot.stopReceiveRobotState(); ``` -------------------------------- ### CMake Compile Options and Subdirectory Inclusion Source: https://github.com/rokaerobot/xcoresdk-cpp/blob/main/CMakeLists.txt Defines compile-time options for linking shared libraries and utilizing the xMateModel library. It also includes subdirectories for external resources, public headers, SDK libraries, examples, and documentation. ```cmake #------------------------------------------------------------------------------- ## Compile options # Using static/shared libraries option option(XCORE_LINK_SHARED_LIBS "Example executables link shared library" OFF) # Compile option: whether using xMateModel library, supports Linux x86_64 and Windows 64bit option(XCORE_USE_XMATE_MODEL "The library of kinematics and dynamics calculation for cobot" OFF) #------------------------------------------------------------------------------- # Set default install location to dist folder in build dir if (CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT) set (CMAKE_INSTALL_PREFIX "${CMAKE_BINARY_DIR}/dist" CACHE PATH "Install path prefix, prepended onto install directories." FORCE ) endif() #------------------------------------------------------------------------------ # Included CMakeLists.txt # External resources/repositories are downloaded here add_subdirectory(external) # Public headers add_subdirectory(include) # xCore-SDK libraries add_subdirectory(lib) # Example usages add_subdirectory(example) # doc add_subdirectory(doc) #------------------------------------------------------------------------------- # Wrap up of settings printed on build message(STATUS "") message(STATUS " == Final overview for ${PROJECT_NAME} ==") message(STATUS "Version: ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}.${PROJECT_VERSION_PATCH} ${VERSION_TYPE} @ ${VERSION_HOST}") message(STATUS "Install prefix: ${CMAKE_INSTALL_PREFIX}") message(STATUS "Compiler: ${CMAKE_CXX_COMPILER}") message(STATUS "CMAKE_BUILD_TYPE: ${CMAKE_BUILD_TYPE}") message(STATUS " possible options: Debug Release RelWithDebInfo MinSizeRel") message(STATUS " set with ` cmake -DCMAKE_BUILD_TYPE=Debug .. `") message(STATUS "") ``` -------------------------------- ### Realtime Torque Control for Cobots Source: https://context7.com/rokaerobot/xcoresdk-cpp/llms.txt Demonstrates setting up realtime torque control for a 6-axis cobot. It configures motion control modes, torque filter, load parameters, and starts a control loop to apply sinusoidal torque to specific joints. Requires the rokae/robot.h header. ```cpp #include "rokae/robot.h" using namespace rokae; Cobot<6> robot("192.168.0.160", "192.168.0.100"); std::error_code ec; robot.setOperateMode(OperateMode::automatic, ec); robot.setMotionControlMode(MotionControlMode::RtCommand, ec); robot.setPowerState(true, ec); auto rtCon = robot.getRtMotionController().lock(); // Set torque filter cutoff frequency rtCon->setTorqueFilterCutOffFrequency(100.0, ec); // 100 Hz // Set load parameters Load load; load.mass = 1.5; // kg load.cog = {0.0, 0.0, 0.05}; // meters load.inertia = {0.01, 0.01, 0.01}; // kg·m² rtCon->setLoad(load, ec); robot.startReceiveRobotState(std::chrono::milliseconds(1), { RtSupportedFields::jointPos_m, RtSupportedFields::jointVel_m, RtSupportedFields::tau_m }); std::array initial_torque; double time = 0.0; bool init = true; std::function callback = [&]() { if (init) { robot.getStateData(RtSupportedFields::tau_m, initial_torque); init = false; } time += 0.001; // Apply sinusoidal torque to joints double amplitude = 5.0; // Nm double freq = 0.5; // Hz double torque_delta = amplitude * std::sin(2.0 * M_PI * freq * time); Torque cmd({ initial_torque[0] + torque_delta, initial_torque[1], initial_torque[2], initial_torque[3] - torque_delta, initial_torque[4], initial_torque[5] }); if (time > 15.0) { cmd.setFinished(); } return cmd; }; rtCon->setControlLoop(callback, 0, true); rtCon->startMove(RtControllerMode::torque); rtCon->startLoop(true); robot.stopReceiveRobotState(); ``` -------------------------------- ### Non-Realtime Motion Commands for Rokaet Robot (C++) Source: https://context7.com/rokaerobot/xcoresdk-cpp/llms.txt Demonstrates setting up motion control, defining various motion commands (MoveJ, MoveL, MoveC, MoveAbsJ), appending them to the motion buffer, executing them, and waiting for completion. It also shows how to pause, resume, and adjust speed during motion. Requires the 'rokae/robot.h' header. ```cpp #include "rokae/robot.h" using namespace rokae; xMateRobot robot("192.168.0.160"); std::error_code ec; // Setup for motion control robot.setOperateMode(OperateMode::automatic, ec); robot.setPowerState(true, ec); robot.setMotionControlMode(MotionControlMode::NrtCommand, ec); // Set default motion parameters robot.setDefaultSpeed(500, ec); // mm/s, converts to joint velocity robot.setDefaultZone(50, ec); // mm, blend radius // Reset motion buffer before starting new motion sequence robot.moveReset(ec); // Define motion commands std::string cmdID; // MoveJ - Joint space motion to Cartesian target MoveJCommand moveJ({0.5, 0.0, 0.4, M_PI, 0.0, M_PI}, 200, 5); // MoveL - Linear motion in Cartesian space MoveLCommand moveL1({0.6, 0.1, 0.4, M_PI, 0.0, M_PI}, 300, 10); MoveLCommand moveL2({0.6, -0.1, 0.4, M_PI, 0.0, M_PI}, 300, 0); // zone=0 means fine point // MoveC - Circular arc motion CartesianPosition target({0.7, 0.0, 0.4, M_PI, 0.0, M_PI}); CartesianPosition aux({0.65, 0.1, 0.45, M_PI, 0.0, M_PI}); MoveCCommand moveC(target, aux, 400, 20); // MoveAbsJ - Joint space motion to joint target MoveAbsJCommand moveAbsJ({0.0, M_PI/6, M_PI/3, 0.0, M_PI/2, 0.0}); // Append commands to motion buffer robot.moveAppend({moveJ, moveL1, moveL2}, cmdID, ec); robot.moveAppend({moveC}, cmdID, ec); // Start motion execution robot.moveStart(ec); // Wait for completion by querying event info while (true) { auto info = robot.queryEventInfo(Event::moveExecution, ec); auto id = std::any_cast(info.at("cmdID")); bool reached = std::any_cast(info.at("reachTarget")); if (id == cmdID && reached) { std::cout << "Motion completed" << std::endl; break; } std::this_thread::sleep_for(std::chrono::milliseconds(100)); } // Pause and resume motion robot.stop(ec); // Pause robot.moveStart(ec); // Resume // Adjust speed online during motion robot.adjustSpeedOnline(0.5, ec); // Set to 50% speed ``` -------------------------------- ### Kinematic and Dynamic Calculations using xMateRobot Source: https://context7.com/rokaerobot/xcoresdk-cpp/llms.txt Demonstrates how to perform forward and inverse kinematics calculations for an xMateRobot. It utilizes the rokae/model.h header to obtain a robot model and then calls `calcFk` and `calcIk` methods. Includes error handling and verification of IK results. Requires rokae/robot.h and rokae/model.h headers. ```cpp #include "rokae/robot.h" #include "rokae/model.h" using namespace rokae; xMateRobot robot("192.168.0.160"); std::error_code ec; // Get robot model for calculations auto model = robot.model(); // Forward kinematics: joint angles -> Cartesian pose std::array joint_angles = {0.0, M_PI/6, M_PI/3, 0.0, M_PI/2, 0.0}; std::array cartesian_pose = model.calcFk(joint_angles, ec); if (!ec) { std::cout << "Forward kinematics result:" << std::endl; std::cout << "Position: [" << cartesian_pose[0] << ", " << cartesian_pose[1] << ", " << cartesian_pose[2] << "]" << std::endl; std::cout << "Orientation: [" << cartesian_pose[3] << ", " << cartesian_pose[4] << ", " << cartesian_pose[5] << "]" << std::endl; } // Inverse kinematics: Cartesian pose -> joint angles std::array target_pose = {0.5, 0.0, 0.4, M_PI, 0.0, M_PI}; std::array ik_result = model.calcIk(target_pose, ec); if (!ec) { std::cout << "Inverse kinematics result:" << std::endl; for (int i = 0; i < 6; i++) { std::cout << "Joint " << i << ": " << ik_result[i] << " rad" << std::endl; } } else { std::cerr << "IK failed: " << ec.message() << std::endl; } // Verify with forward kinematics auto fk_verify = model.calcFk(ik_result, ec); std::cout << "Verification - Position error: " << std::sqrt(std::pow(fk_verify[0] - target_pose[0], 2) + std::pow(fk_verify[1] - target_pose[1], 2) + std::pow(fk_verify[2] - target_pose[2], 2)) << " m" << std::endl; ``` -------------------------------- ### Execute RL Projects with ROKAE Robots Source: https://context7.com/rokaerobot/xcoresdk-cpp/llms.txt This C++ snippet shows how to execute Reinforcement Learning (RL) projects on a ROKAE robot. It covers setting the motion control mode for RL tasks, querying available projects and their tasks, loading a specific project, and running it with configurable options. It also demonstrates pausing the project and querying information about tools and workpieces within the loaded project. ```cpp #include "rokae/robot.h" using namespace rokae; xMateRobot robot("192.168.0.160"); std::error_code ec; // Set motion control mode to RL task execution robot.setMotionControlMode(MotionControlMode::NrtRLTask, ec); robot.setOperateMode(OperateMode::automatic, ec); robot.setPowerState(true, ec); // Query available projects auto projects = robot.projectsInfo(ec); for (const auto& proj : projects) { std::cout << "Project: " << proj.name << std::endl; std::cout << "Tasks: "; for (const auto& task : proj.taskList) { std::cout << task << " "; } std::cout << std::endl; } // Load project with specific tasks if (!projects.empty()) { std::string project_name = projects[0].name; std::vector tasks = projects[0].taskList; robot.loadProject(project_name, tasks, ec); if (ec) { std::cerr << "Failed to load project: " << ec.message() << std::endl; } // Move program pointer to main robot.ppToMain(ec); // Set running options robot.setProjectRunningOpt(0.8, false, ec); // 80% speed, no loop // Run project robot.runProject(ec); std::cout << "Project running..." << std::endl; std::this_thread::sleep_for(std::chrono::seconds(5)); // Pause project robot.pauseProject(ec); std::cout << "Project paused" << std::endl; // Query tools and workpieces in loaded project auto tools = robot.toolsInfo(ec); auto wobjs = robot.wobjsInfo(ec); std::cout << "Available tools:" << std::endl; for (const auto& tool : tools) { std::cout << " " << tool.name << " (held: " << tool.robotHeld << ")" << std::endl; } std::cout << "Available workpieces:" << std::endl; for (const auto& wobj : wobjs) { std::cout << " " << wobj.name << std::endl; } } ``` -------------------------------- ### Connect and Control Robot Source: https://context7.com/rokaerobot/xcoresdk-cpp/llms.txt Establishes a connection to a ROKAE robot, queries its information, sets operating mode and power state, and disconnects. Handles network and execution exceptions. ```cpp #include "rokae/robot.h" using namespace rokae; try { // Connect to 6-axis collaborative robot xMateRobot robot("192.168.0.160", "192.168.0.100"); // Or connect to other robot types // xMateErProRobot robot("192.168.0.160", "192.168.0.100"); // 7-axis collaborative // StandardRobot robot("192.168.0.160", "192.168.0.100"); // Industrial 6-axis // PCB4Robot robot("192.168.0.160"); // PCB 4-axis std::error_code ec; // Query robot information auto info = robot.robotInfo(ec); if (!ec) { std::cout << "Robot Type: " << info.type << std::endl; std::cout << "Controller Version: " << info.version << std::endl; std::cout << "Joint Count: " << info.joint_num << std::endl; } // Set to automatic mode and power on robot.setOperateMode(OperateMode::automatic, ec); robot.setPowerState(true, ec); // Disconnect when done robot.disconnectFromRobot(ec); } catch (const NetworkException& e) { std::cerr << "Network error: " << e.what() << std::endl; } catch (const ExecutionException& e) { std::cerr << "Execution error: " << e.what() << std::endl; } ``` -------------------------------- ### Add CMake GPG Key on Ubuntu Source: https://github.com/rokaerobot/xcoresdk-cpp/blob/main/README.md Adds the necessary public key for the Kitware APT repository on Ubuntu, resolving potential `NO_PUBKEY` errors during `sudo apt update`. This ensures secure access to CMake packages. ```bash sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 6AF7F09730B3F0A4 ``` -------------------------------- ### CMake Doxygen Integration for API Documentation Source: https://github.com/rokaerobot/xcoresdk-cpp/blob/main/doc/CMakeLists.txt This CMake configuration block integrates Doxygen for generating API documentation. It checks if Doxygen is found, sets up input directories for documentation, configures the Doxyfile using a template, and adds a custom 'doc' target to build the documentation. This target is excluded from the default build process and must be invoked explicitly. ```cmake find_package(Doxygen 1.9.4) message(STATUS "Can build doc? ${DOXYGEN_FOUND}") if(DOXYGEN_FOUND) set(DOXYGEN_EXAMPLE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/../example/cpp) set(DOXYGEN_INPUT_FILES ${CMAKE_CURRENT_SOURCE_DIR}/../include) path_win_to_linux(${CMAKE_CURRENT_SOURCE_DIR} CMAKE_CURRENT_SOURCE_DIR_LINUX) path_win_to_linux(${PROJECT_SOURCE_DIR} PROJECT_SOURCE_DIR_LINUX) path_win_to_linux(${CMAKE_CURRENT_BINARY_DIR} CMAKE_CURRENT_BINARY_DIR_LINUX) set(doxyfile_in ${CMAKE_CURRENT_SOURCE_DIR}/doxygen/Doxyfile.in) set(doxyfile ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile) configure_file(${doxyfile_in} ${doxyfile} @ONLY) add_custom_target(doc COMMAND ${DOXYGEN_EXECUTABLE} ${doxyfile} WORKING_DIRECTORY ${PROJECT_SOURCE_DIR} COMMENT "Generating API documentation with Doxygen" EXCLUDE_FROM_ALL VERBATIM) endif() ``` -------------------------------- ### Robot Frame Calibration (Tool, Workpiece, Base) in C++ Source: https://context7.com/rokaerobot/xcoresdk-cpp/llms.txt Demonstrates how to calibrate the tool, workpiece, and base frames of a Rokae robot using different point collection methods. It involves collecting joint positions, performing the calibration, and handling potential errors. Dependencies include the rokae/robot.h header and an active robot connection. ```cpp #include "rokae/robot.h" using namespace rokae; xMateRobot robot("192.168.0.160"); std::error_code ec; // Calibrate tool frame using 4-point method const int point_count = 4; std::vector> calibration_points; // Collect calibration points by jogging robot for (int i = 0; i < point_count; i++) { std::cout << "Move robot to calibration point " << (i+1) << " and press Enter" << std::endl; std::cin.get(); auto joint_pos = robot.jointPos(ec); calibration_points.push_back(joint_pos); } // Perform calibration bool is_robot_held = true; // true if tool is robot-held, false if external FrameCalibrationResult result = robot.calibrateFrame( FrameType::tool, calibration_points, is_robot_held, ec ); if (!ec) { std::cout << "Calibration successful!" << std::endl; std::cout << "Frame position: [" << result.frame.trans[0] << ", " << result.frame.trans[1] << ", " << result.frame.trans[2] << "]" << std::endl; std::cout << "Frame orientation: [" << result.frame.rpy[0] << ", " << result.frame.rpy[1] << ", " << result.frame.rpy[2] << "]" << std::endl; std::cout << "Errors (min/avg/max): [" << result.errors[0] << ", " << result.errors[1] << ", " << result.errors[2] << "] m" << std::endl; } else { std::cerr << "Calibration failed: " << ec.message() << std::endl; } // Calibrate workpiece using 3-point method std::vector> wobj_points(3); // ... collect 3 points auto wobj_result = robot.calibrateFrame(FrameType::wobj, wobj_points, false, ec); // Calibrate base frame using 6-point method (requires aux point) std::vector> base_points(6); std::array base_aux = {1.0, 0.0, 0.5}; // Auxiliary point in meters // ... collect 6 points auto base_result = robot.calibrateFrame(FrameType::base, base_points, false, ec, base_aux); ``` -------------------------------- ### Add and Configure Imported Libraries (CMake) Source: https://github.com/rokaerobot/xcoresdk-cpp/blob/main/lib/CMakeLists.txt This snippet demonstrates how to add imported shared and static libraries using CMake's `add_library` command. It then configures properties like `IMPORTED_LOCATION` and `INTERFACE_LINK_LIBRARIES` based on the operating system and architecture, ensuring correct library linking for both release and debug builds. It also sets up an alias for the main project library. ```cmake add_library(${PROJECT_NAME}_lib SHARED IMPORTED GLOBAL) add_library(${PROJECT_NAME}_static STATIC IMPORTED GLOBAL) add_library(xmatemodel_lib STATIC IMPORTED) if(WIN32) if(${CMAKE_SIZEOF_VOID_P} EQUAL 8) #64bit set(_ARCH_NAME "64bit") elseif(${CMAKE_SIZEOF_VOID_P} EQUAL 4) #32bit set(_ARCH_NAME "32bit") endif() set_target_properties(xmatemodel_lib PROPERTIES IMPORTED_LOCATION_RELEASE ${CMAKE_CURRENT_SOURCE_DIR}/Windows/cpp/Release/64bit/xMateModel.lib IMPORTED_LOCATION_DEBUG ${CMAKE_CURRENT_SOURCE_DIR}/Windows/cpp/Debug/64bit/xMateModeld.lib) set_target_properties(${PROJECT_NAME}_lib PROPERTIES IMPORTED_IMPLIB_RELEASE ${CMAKE_CURRENT_SOURCE_DIR}/Windows/cpp/Release/${_ARCH_NAME}/${PROJECT_NAME}.lib IMPORTED_LOCATION_RELEASE ${CMAKE_CURRENT_SOURCE_DIR}/Windows/cpp/Release/${_ARCH_NAME}/${PROJECT_NAME}.dll IMPORTED_IMPLIB_DEBUG ${CMAKE_CURRENT_SOURCE_DIR}/Windows/cpp/Debug/${_ARCH_NAME}/${PROJECT_NAME}.lib IMPORTED_LOCATION_DEBUG ${CMAKE_CURRENT_SOURCE_DIR}/Windows/cpp/Debug/${_ARCH_NAME}/${PROJECT_NAME}.dll ) set_target_properties(${PROJECT_NAME}_static PROPERTIES IMPORTED_LOCATION_RELEASE ${CMAKE_CURRENT_SOURCE_DIR}/Windows/cpp/Release/${_ARCH_NAME}/${PROJECT_NAME}_static.lib IMPORTED_LOCATION_DEBUG ${CMAKE_CURRENT_SOURCE_DIR}/Windows/cpp/Debug/${_ARCH_NAME}/${PROJECT_NAME}_static.lib INTERFACE_LINK_LIBRARIES xmatemodel_lib ) elseif(UNIX) if(${CMAKE_SYSTEM_PROCESSOR} STREQUAL "x86_64") if(XCORE_USE_XMATE_MODEL) set_target_properties(${PROJECT_NAME}_lib PROPERTIES INTERFACE_LINK_LIBRARIES xmatemodel_lib) else() set(SHARED_LIB_SUFFIX ".nomodel") endif() elseif((NOT ${CMAKE_SYSTEM_PROCESSOR} STREQUAL "aarch64") OR ${XCORE_USE_XMATE_MODEL}) message(FATAL_ERROR "Unsupported: target ${CMAKE_SYSTEM_PROCESSOR} OR XCORE_USE_XMATE_MODEL option") endif() # set path to model library set_target_properties(xmatemodel_lib PROPERTIES IMPORTED_LOCATION ${CMAKE_CURRENT_SOURCE_DIR}/Linux/cpp/x86_64/libxMateModel.a) set(XCORESDK_LIBRARY_DIR ${CMAKE_CURRENT_SOURCE_DIR}/Linux/cpp/${CMAKE_SYSTEM_PROCESSOR}) set_target_properties(${PROJECT_NAME}_lib PROPERTIES IMPORTED_LOCATION ${XCORESDK_LIBRARY_DIR}/lib${PROJECT_NAME}${SHARED_LIB_SUFFIX}.so.${CMAKE_PROJECT_VERSION} ) set_target_properties(${PROJECT_NAME}_static PROPERTIES IMPORTED_LOCATION ${XCORESDK_LIBRARY_DIR}/lib${PROJECT_NAME}.a INTERFACE_LINK_LIBRARIES xmatemodel_lib ) endif() if(XCORE_LINK_SHARED_LIBS) add_library(Rokae::Rokae ALIAS ${CMAKE_PROJECT_NAME}_lib) else() add_library(Rokae::Rokae ALIAS ${CMAKE_PROJECT_NAME}_static) endif() install(IMPORTED_RUNTIME_ARTIFACTS ${PROJECT_NAME}_lib RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) ``` -------------------------------- ### CMake Macros for Path Conversion (Linux/Windows) Source: https://github.com/rokaerobot/xcoresdk-cpp/blob/main/doc/CMakeLists.txt These CMake macros, path_linux_to_win and path_win_to_linux, are designed to convert paths between Linux-style (e.g., '/c/Users/') and Windows-style (e.g., 'C:/Users/') formats. They utilize regular expressions for string manipulation and are useful in cross-platform build environments like MSYS. ```cmake macro(path_linux_to_win MsysPath ResultingPath) string(REGEX REPLACE "^/([a-zA-Z])/" "\1:/" ${ResultingPath} "${MsysPath}") endmacro() macro(path_win_to_linux MsysPath ResultingPath) string(REGEX REPLACE "^([a-zA-Z]):/" "/\1/" ${ResultingPath} "${MsysPath}") endmacro() ```