### Install Python Testing Dependencies Source: https://github.com/robodk/robodk-api/blob/master/Python/tests/Readme.txt Commands to install the necessary Python modules for running tests, including Nose2 for test execution, Nose2 HTML Report for generating reports, and Parameterized for parameterized test cases. ```bash pip install nose2 pip install nose2-html-report pip install parameterized ``` -------------------------------- ### Install Python 3 and IDLE on Linux Source: https://github.com/robodk/robodk-api/blob/master/Python/readme.md Commands to install Python 3 and its integrated development environment (IDLE) on Debian/Ubuntu-based Linux distributions using the apt-get package manager. This ensures the necessary Python environment is available for RoboDK API usage. ```bash sudo apt-get install pip3 sudo apt-get install idle3 ``` -------------------------------- ### Run Pure Python Unittests Source: https://github.com/robodk/robodk-api/blob/master/Python/tests/Readme.txt Command-line instruction to execute Python's built-in unittest framework with verbose output, allowing for detailed feedback on test execution. ```bash python -m unittest -v ``` -------------------------------- ### CMake Build Configuration for RoboDK API Library Source: https://github.com/robodk/robodk-api/blob/master/C++/CMakeLists.txt This CMake script defines the build process for the 'robodk_api' static library. It specifies the minimum CMake version, project name and version, sets the installation prefix, finds required Qt5 components (Widgets, GUI, Concurrent, Core, Network), adds the static library target, defines public headers and include directories, links necessary Qt5 libraries, and sets up comprehensive installation rules for targets, exports, and CMake package configuration files. ```CMake cmake_minimum_required(VERSION 3.5) # TODO: Project version project(robodk_api VERSION 1.0.0) # Set the install location set(CMAKE_INSTALL_PREFIX "../install") # Find dependencies find_package(Qt5 NAMES Qt5 COMPONENTS Widgets GUI Concurrent Core Network REQUIRED) # TODO: Option for static vs shared add_library(robodk_api STATIC robodk_api.cpp) # Set the public header for the library so it can be installed set_target_properties(robodk_api PROPERTIES PUBLIC_HEADER robodk_api.h) # Set the include directories target_include_directories(robodk_api PUBLIC $ $ ) # Link the target to its dependent libraries target_link_libraries(robodk_api PUBLIC Qt5::Gui Qt5::Core Qt5::Network) # Specify where to install targets and define the EXPORT target name install(TARGETS robodk_api EXPORT robodk_apiTargets ARCHIVE DESTINATION lib LIBRARY DESTINATION lib RUNTIME DESTINATION bin INCLUDES DESTINATION include PUBLIC_HEADER DESTINATION include ) # Install the exported target install(EXPORT robodk_apiTargets FILE "robodk_apiTargets.cmake" NAMESPACE "robodk_api::" DESTINATION cmake ) # Create the Config and Version files include(CMakePackageConfigHelpers) configure_package_config_file(${CMAKE_CURRENT_SOURCE_DIR}/Config.cmake.in "${CMAKE_CURRENT_BINARY_DIR}/robodk_apiConfig.cmake" INSTALL_DESTINATION cmake ) write_basic_package_version_file( "${CMAKE_CURRENT_BINARY_DIR}/robodk_apiConfigVersion.cmake" VERSION ${PROJECT_VERSION} COMPATIBILITY AnyNewerVersion ) # Install the Config and Version Files install(FILES ${CMAKE_CURRENT_BINARY_DIR}/robodk_apiConfig.cmake ${CMAKE_CURRENT_BINARY_DIR}/robodk_apiConfigVersion.cmake DESTINATION cmake ) # Generate the export targets for the build tree export(EXPORT robodk_apiTargets FILE "${CMAKE_CURRENT_BINARY_DIR}/robodk_apiTargets.cmake" ) ``` -------------------------------- ### Install RoboDK Python Package via pip Source: https://github.com/robodk/robodk-api/blob/master/Python/readme.md Instructions to install the core RoboDK Python package using pip. This command fetches the latest version of the 'robodk' library from PyPi, making it available for Python projects. ```bash # cd path-to-python/Scripts pip install robodk ``` -------------------------------- ### Install RoboDK Python Package with Optional Dependencies Source: https://github.com/robodk/robodk-api/blob/master/Python/readme.md Command to install the RoboDK Python package along with specific optional dependencies. These extras, such as 'cv' for computer vision, 'apps' for RoboDK apps, and 'lint' for linting tools, extend the package's functionality. ```bash # cd path-to-python/Scripts pip install robodk[cv,apps,lint] ``` -------------------------------- ### Generate Robot Program with Linear and Circular Moves (RoboDK MATLAB) Source: https://github.com/robodk/robodk-api/blob/master/Matlab/html/Example_RoboDK.html This example shows how to initialize the RoboDK API, retrieve a robot item, create a new program, and add movement instructions. It demonstrates adding a linear move (`MoveL`) to a Cartesian target and a circular move (`MoveC`) defined by two intermediate points. ```MATLAB RDK = Robolink(); robot = RDK.Item('', RDK.ITEM_TYPE_ROBOT); % Get the current robot pose: pose0 = robot.Pose(); % Add a new program: prog = RDK.AddProgram('TestProgram'); % Create a linear move to the current robot position (MoveC is defined by 3 % points) target0 = RDK.AddTarget('First Point'); target0.setAsCartesianTarget(); % default behavior target0.setPose(pose0); prog.MoveL(target0); % Calculate the circular move: pose1 = pose0 * transl(50, 0, 0); pose2 = pose0 * transl(50, 50, 0); % Add the first target for the circular move target1 = RDK.AddTarget('Second Point'); target1.setAsCartesianTarget(); target1.setPose(pose1); % Add the second target for the circular move target2 = RDK.AddTarget('Third Point'); target2.setAsCartesianTarget(); target2.setPose(pose2); % Add the circular move instruction: prog.MoveC(target1, target2) ``` -------------------------------- ### RoboDK C++ API Robot Control Example Source: https://github.com/robodk/robodk-api/blob/master/C++/readme.md This comprehensive C++ example demonstrates how to use the RoboDK API to control a robot. It covers initializing the API, retrieving robot items, setting reference and tool frames, adjusting speed and rounding, and performing a sequence of movements to draw a hexagon. It also shows how to add comments and retrieve pose information (Euler angles) during program execution. ```cpp #include "robodk_api.h" // TIP: use #define RDK_SKIP_NAMESPACE to avoid using namespaces using namespace RoboDK_API; RoboDK *RDK = NULL; // RDK is the interface with RoboDK Item *ROBOT = NULL; // ROBOT is the robot item /// Start the RoboDK API void RoboDK_Start(){ // RoboDK starts when a RoboDK object is created. RDK = new RoboDK(); // Retrieve the robot ROBOT = new Item(RDK->getItem("Motoman SV3")); } /// Delete RDK and ROBOT objects void RoboDK_Finish(){ delete RDK; delete ROBOT; } void RoboDK_Test(){ // Start RoboDK RoboDK_Start(); if (ROBOT == NULL || !ROBOT->Valid()){ // Something is wrong! return; } // Draw a hexagon inside a circle of radius 100.0 mm int n_sides = 6; float size = 100.0; // retrieve the reference frame and the tool frame (TCP) Mat pose_frame = ROBOT->PoseFrame(); Mat pose_tool = ROBOT->PoseTool(); // retrieve the pose of the TCP with respect to the reference frame Mat pose_ref = ROBOT->Pose(); // Optional: set the run mode (define if you want to simulate, // generate the program or run the program on the robot) // RDK->setRunMode(RoboDK::RUNMODE_MAKE_ROBOTPROG) // RDK->ProgramStart('MatlabTest'); // Program start ROBOT->MoveJ(pose_ref); ROBOT->setPoseFrame(pose_frame); // set the reference frame ROBOT->setPoseTool(pose_tool); // set the tool frame: important for Online Programming ROBOT->setSpeed(100); // Set Speed to 100 mm/s ROBOT->setRounding(5); // set the rounding instruction //(C_DIS & APO_DIS / CNT / ZoneData / Blend Radius / ...) ROBOT->RunCodeCustom("CallOnStart"); // run a program for (int i = 0; i <= n_sides; i++) { // calculate angle in degrees: double angle = ((double) i / n_sides) * 360.0; // create a pose relative to the pose_ref Mat pose_i(pose_ref); pose_i.rotate(angle,0,0,1.0); pose_i.translate(size, 0, 0); pose_i.rotate(-angle,0,0,1.0); // add a comment (when generating code) ROBOT->RunCodeCustom("Moving to point " + QString::number(i), RoboDK::INSTRUCTION_COMMENT); // example to retrieve the pose as Euler angles (X,Y,Z,W,P,R) double xyzwpr[6]; pose_i.ToXYZRPW(xyzwpr); ROBOT->MoveL(pose_i); // move the robot } ROBOT->RunCodeCustom("CallOnFinish"); ROBOT->MoveL(pose_ref); // move back to the reference point // Delete allocated items RoboDK_Finish(); } ``` -------------------------------- ### Control Robot Movement and Program Flow with RoboDK C# API Source: https://github.com/robodk/robodk-api/blob/master/C This C# example demonstrates how to initialize the RoboDK API, select a robot, and control its movements. It shows how to set reference and tool frames, define speed and zone data, and execute linear and joint movements. The snippet also includes examples of adding custom instructions and comments to the robot program. ```csharp // RDK holds the main object to interact with RoboDK. // RoboDK starts when a RoboDK object is created. RoboDK RDK = new RoboDK(); // Select the robot among all available robots (there is no popup if there is only 1 robot) RoboDK.Item ROBOT = RDK.ItemUserPick("Select a robot", RoboDK.ITEM_TYPE_ROBOT); // retrieve the reference frame and the tool frame (TCP) as poses Mat frame = ROBOT.PoseFrame(); Mat tool = ROBOT.PoseTool(); /// Optional: set the run mode /// (define if you want to simulate, generate the program or run the program on the robot) // RDK.setRunMode(RoboDK.RUNMODE_MAKE_ROBOTPROG) // RDK.ProgramStart("MatlabTest"); // Program start ROBOT.MoveJ(pose_ref); ROBOT.setPoseFrame(frame); // set the reference frame ROBOT.setPoseTool(tool); // set the tool frame: important for Online Programming ROBOT.setSpeed(100); // Set Speed to 100 mm/s ROBOT.setZoneData(5); // set the rounding instruction // (C_DIS & APO_DIS / CNT / ZoneData / Blend Radius / ...) ROBOT.RunInstruction("CallOnStart"); for (int i = 0; i <= n_sides; i++) { double angle = ((double) i / n_sides) * 2.0 * Math.PI; Mat pose_i = pose_ref * Mat.rotz(angle) * Mat.transl(100, 0, 0) * Mat.rotz(-angle); ROBOT.RunInstruction("Moving to point " + i.ToString(), RoboDK.INSTRUCTION_COMMENT); double[] xyzwpr = pose_i.ToXYZRPW(); ROBOT.MoveL(pose_i); } ROBOT.RunInstruction("CallOnFinish"); ROBOT.MoveL(pose_ref); ``` -------------------------------- ### Load RoboDK Station & Run Program (MATLAB) Source: https://github.com/robodk/robodk-api/blob/master/Matlab/html/Example_RoboDK.html Initializes the RoboDK API, retrieves the library path, and loads a .rdk station file. Includes validation for the station file, lists available items, and demonstrates how to run a program within the loaded station. ```MATLAB clc clear close all % Generate a Robolink object RDK. This object interfaces with RoboDK. RDK = Robolink; % Get the library path % path = "C:\RoboDK\Library"; % Since RoboDK 5.5, PATH_LIBRARY points to Documents path = RDK.getParam('PATH_LIBRARY'); % Open example 1 % RDK.AddFile([path,'Example 01 - Pick and place.rdk']); % prior to RoboDK 4.0.0 station = RDK.AddFile([path, 'Example-06.b-Pick and place 2 tables.rdk']); if ~station.Valid() path = ['C:/RoboDK/Library/']; station = RDK.AddFile([path, 'Example-06.b-Pick and place 2 tables.rdk']); if ~station.Valid() RDK.ShowMessage(sprintf('This example requires Example-06.b-Pick and place 2 tables.rdk library folder:
%s.', library_path)) return end end % Display a list of all items fprintf('Available items in the station:\n'); disp(RDK.ItemList(-1, 1)); % Get one item by its name program = RDK.Item('Pick and place', RDK.ITEM_TYPE_PROGRAM); % Start "Pick and place" program program.RunProgram(); % Alternative call to run the program % program = RDK.Item('Pick and place').RunProgram(); % Another alternative call to run the same program % RDK.RunProgram('Pick and place'); ``` -------------------------------- ### Generate & Configure Robot Program in RoboDK (MATLAB) Source: https://github.com/robodk/robodk-api/blob/master/Matlab/html/Example_RoboDK.html Programmatically creates a robot program in RoboDK. Covers cleaning up old items, setting robot home joints, configuring reference and tool frames, and creating a new program object. Also shows how to disable rendering for performance. ```MATLAB % Clean up previous items automatically generated by this script % the keyword "macro" is used if we want to delete any items when the % script is executed again. tic() while 1 item = RDK.Item('macro'); if item.Valid() == 0 % Iterate until there are no items with the "macro" name break end % if Valid() returns 1 it means that an item was found % if so, delete the item in the RoboDK station item.Delete(); end % Set the home joints jhome = [0, 0, 0, 0, 30, 0]; % Set the robot at the home position robot.setJoints(jhome); % Turn off rendering (faster) RDK.Render(0); % Get the tool pose Htcp = tool.PoseTool(); % Create a reference frame with respect to the robot base reference ref = RDK.AddFrame('Frame macro', frameref); % Set the reference frame at coordinates XYZ, rotation of 90deg about Y plus rotation of 180 deg about Z Hframe = transl(750, 250, 500) * roty(pi / 2) * rotz(pi); ref.setPose(Hframe); % Set the robot's reference frame as the reference we just cretaed robot.setPoseFrame(ref); % Set the tool frame robot.setPoseTool(Htcp); % Get the position of the TCP wrt the robot base Hhome = inv(Hframe) * robot.SolveFK(jhome) * Htcp; % Create a new program "prog" prog = RDK.AddProgram('Prog macro'); ``` -------------------------------- ### Changing Item Parent and Listing Child Items in RoboDK Source: https://github.com/robodk/robodk-api/blob/master/Matlab/html/Example_RoboDK.html This example illustrates how to change the parent of an item in RoboDK, demonstrating both static and dynamic re-parenting methods. It also shows how to retrieve and iterate through an item's child objects, allowing for modification of their properties like name and visibility. ```MATLAB % Change the support of a target % The final result of the operations made to target1 and target2 is the same Htarget = target1.Pose(); target1.setParentStatic(frameref); target1.setPose(Htarget); target2.setParent(frameref); % We can list the items that depend on an item childs = frametable.Childs(); for i = 1:numel(childs) name = childs{i}.Name(); newname = [name, ' modified']; visible = childs{i}.Visible(); childs{i}.setName(newname); fprintf('%s %i\n', newname, visible); end ``` -------------------------------- ### RoboDK C API Example: Robot Control and Matrix Operations Source: https://github.com/robodk/robodk-api/blob/master/C/readme.md This C code example demonstrates how to connect to the RoboDK API, retrieve robot information, perform matrix transformations (translation and rotation), move the robot to target positions, and interact with a real robot or simulation. It showcases the use of `RoboDK_t`, `Item_t`, `Mat_t`, and `Joints_t` structures for API interaction, including error handling and user input for continuous movement. ```C #include #include "robodk_api_c.h" int main() { WSADATA wsaData; int iResult = WSAStartup(MAKEWORD(2, 2), &wsaData); if (iResult != 0) { printf("WSAStartup failed with error: %d\n", iResult); return 1; } //The RoboDK_t structures store the socket and parameters passed to robodk //This structure's pointer must remain valid as long as you are using the api, //all the api items it's used to create keep a copy of it's location. struct RoboDK_t rdk; RoboDK_Connect_default(&rdk); if (!_RoboDK_connected(&rdk)) { fprintf(stderr, "Failed to start RoboDK API!!"); return -1; } char bufferOut[1024]; RoboDK_ShowMessage(&rdk, "Hello world!\nLine 2", false); struct Item_t robotItem = RoboDK_getItem(&rdk, "", (enum eITEM_TYPE)ITEM_TYPE_ROBOT); if (!Item_Valid(&robotItem)) { printf("Currently open station has no robots\n"); return -1; } Item_Name(&robotItem, bufferOut); printf("Robot Name: %s\n", bufferOut); struct Mat_t poseStart = Item_Pose(&robotItem); Mat_ToString(&poseStart, bufferOut, false); printf("Matrix values retrieved:\n%s", bufferOut); //Matrix value 500 x offset struct Mat_t poseTranslated = Mat_makeCopy(&poseStart); struct Mat_t poseTransform = Mat_transl(500, 0, 0); Mat_Multiply_cumul(&poseTranslated, &poseTransform); Mat_ToString(&poseTranslated, bufferOut, false); printf("Matrix values translated by 500 in the x:\n%s", bufferOut); struct Mat_t poseTransformed = Mat_makeCopy(&poseStart); Mat_Multiply_rotxyz(&poseTransformed, 0, 0, 0); Mat_Multiply_cumul(&poseTransformed, &poseStart); Mat_ToString(&poseTransformed, bufferOut, false); printf("Matrix values transformed by 500 in the x:\n%s", bufferOut); printf("\n"); struct Joints_t curJoints = Item_Joints(&robotItem); Joints_ToString(&curJoints, bufferOut); printf(bufferOut); struct Joints_t targetJoints = Joints_create(6); for (int i = 0; i < 6; i++) { targetJoints._Values[i] = i * 10; } printf("Moving to joint position\n"); Item_MoveJ_joints(&robotItem, &targetJoints, true); printf("Moving to Start position\n"); Item_MoveJ_mat(&robotItem, &poseStart, true); // Connect to real robot if (Item_Connect(&robotItem,"")) { // Set simulation mode RoboDK_setRunMode(&rdk,RUNMODE_RUN_ROBOT); printf("Warning future moves will operate on the real robot!\n"); } else { printf("Could not connect to real robot, running in simulation mode.\n"); RoboDK_setRunMode(&rdk, RUNMODE_SIMULATE); } printf("Input e to exit, any other character causes a random movement\n"); while (getchar() != 'e') { int offSetX = rand() % 150 - 75; int offSetY = rand() % 150 - 75; int offSetZ = rand() % 150 - 75; poseTranslated = Mat_makeCopy(&poseStart); poseTransform = Mat_transl(offSetX, offSetY, offSetZ); Mat_Multiply_cumul(&poseTranslated, &poseTransform); Mat_ToString(&poseTranslated, bufferOut, true); printf("Moving to the following position:\n%s", bufferOut); Item_MoveJ_mat(&robotItem, &poseTranslated, true); ThreadSleep(100); while (getchar() != '\n') {}; } printf("Restoring robot to Start position\n"); Item_MoveJ_mat(&robotItem, &poseStart, true); printf("Done"); } ``` -------------------------------- ### Collision Detection and Object Scaling in RoboDK Source: https://github.com/robodk/robodk-api/blob/master/Matlab/html/Example_RoboDK.html This example illustrates various collision detection methods in RoboDK, including testing a joint path for collisions, checking for current collision pairs, and detecting intersections between a line and objects. It also demonstrates how to scale the geometry of an object and visualize collision points. ```MATLAB % Replace objects (we call the program previously set in example 1) RDK.Item('Replace objects', RDK.ITEM_TYPE_PROGRAM).RunProgram(); % Verify if a joint movement from j1 to j2 is free of colllision j1 = [-100, -50, -50, -50, -50, -50]; j2 = [100, 50, 50, 50, 50, 50]; collision = robot.MoveJ_Test(j1, j2, 1); disp(collision) % Activate the trace to see what path the robot tries to make % To activate the trace: Tools->Trace->Active (ALT+T) % Detect collisions: returns the number of pairs of objects in a collision state pairs = RDK.Collisions(); fprintf('Pairs collided: %i\n', pairs); % Scale the geometry of an object, scale can be one number or a scale per axis object.Scale([10, 10, 0.5]); % Detect the intersection between a line and any object p1 = [1000; 0; 8000]; p2 = [1000; 0; 0]; [collision, itempicked, xyz] = RDK.Collision_Line(p1, p2); if collision % or itempicked.Valid() fprintf('Line from p1 to p2 collides with %s\n', itempicked.Name()); % Create a point in the intersection to display collision ball.Copy(); newball = RDK.Paste(); % Set this ball at the collision point newball.setPose(transl(xyz(1), xyz(2), xyz(3))); newball.Scale(0.5); % Make this ball 50 % of the original size newball.Recolor([1 0 0]); % Make it a red ball end ``` -------------------------------- ### Robot Program Creation and Execution with RoboDK API Source: https://github.com/robodk/robodk-api/blob/master/Matlab/html/Example_RoboDK.html This snippet demonstrates how to define joint targets, create linear movements, execute a robot program, and wait for its completion using the RoboDK API in MATLAB. It includes setting up a home target, iterating through a sequence of linear movements, and running the generated program. ```MATLAB % Create a joint target home target = RDK.AddTarget('Home', ref, robot); target.setAsJointTarget(); target.setJoints(jhome) % Add joint movement into the program prog.MoveJ(target); % Generate a sequence of targets and move along the targets (linear move) angleY = 0; for dy = 600:-100:100 targetname = sprintf('Target TY=%i RY=%i', dy, angleY); target = RDK.AddTarget(targetname, ref, robot); % Move along Z direction of the reference frame pose = transl(0, dy, 0); % Keep the same orientation as home orientation pose(1:3, 1:3) = Hhome(1:3, 1:3); pose = pose \* roty(angleY \* pi / 180); target.setPose(pose); prog.MoveL(target); angleY = angleY + 20; end % Set automatic render on every call RDK.Render(1); % Run the program we just created prog.RunProgram(); % Wait for the movement to finish while robot.Busy() pause(1); fprintf('Waiting for the robot to finish...\n'); end % Run the program once again fprintf('Running the program again...\n'); prog.RunProgram(); ``` -------------------------------- ### Windows Batch Script to Run Nose2 Tests Source: https://github.com/robodk/robodk-api/blob/master/Python/tests/Readme.txt A Windows batch script (`runTests.cmd`) that executes Nose2, a test runner, which in turn generates an HTML test report based on the configuration. ```batch python -m nose2 report.html ``` -------------------------------- ### Nose2 Configuration for HTML Report Source: https://github.com/robodk/robodk-api/blob/master/Python/tests/Readme.txt Configuration settings for Nose2 in `nose2.cfg` to enable the `nose2_html_report` plugin. This ensures that an HTML report is always generated after test execution. ```ini [unittest] plugins = nose2_html_report.html_report [html-report] always-on = True ``` -------------------------------- ### Calculate Robot Forward and Inverse Kinematics (RoboDK MATLAB) Source: https://github.com/robodk/robodk-api/blob/master/Matlab/html/Example_RoboDK.html This snippet demonstrates how to retrieve current robot joint values, calculate the Tool Center Point (TCP) pose using forward kinematics (`SolveFK`), and then calculate the joint values required to reach that pose using inverse kinematics (`SolveIK`). It also shows how to find all possible inverse kinematic solutions (`SolveIK_All`) and visualize them, and how to calculate a new target pose by offsetting the original and move the robot to it. ```MATLAB % Get the current robot joints fprintf('Current robot joints:\n'); joints = robot.Joints(); disp(joints); % Get the current position of the TCP with respect to the reference frame fprintf('Calculated pose for current joints:\n'); H_tcp_wrt_frame = robot.SolveFK(joints); disp(H_tcp_wrt_frame); % Calculate the joints to reach this position (should be the same as joints) fprintf('Calculated robot joints from pose:\n'); joints2 = robot.SolveIK(H_tcp_wrt_frame); disp(joints2); % Calculate all solutions fprintf('All solutions available for the selected position:\n'); joints3_all = robot.SolveIK_All(H_tcp_wrt_frame); disp(joints3_all); % Show the sequence in the slider bar in RoboDK RDK.ShowSequence(joints3_all); pause(1); % Make joints 4 the solution to reach the target off by 100 mm in Z joints4 = robot.SolveIK(H_tcp_wrt_frame * transl(0, 0, -100)); % Set the robot at the new position calculated robot.setJoints(joints4); ``` -------------------------------- ### RoboDK API C# Robot Simulation and Programming Example Source: https://github.com/robodk/robodk-api/blob/master/C This C# code snippet demonstrates how to use the RoboDK API for robot simulation and offline programming. It illustrates retrieving and setting reference and tool frames, controlling robot speed and zone data, executing instructions, and performing linear movements to multiple points in a loop. ```C# // retrieve the reference frame and the tool frame (TCP) Mat frame = ROBOT.PoseFrame(); Mat tool = ROBOT.PoseTool(); int runmode = RDK.RunMode(); // retrieve the run mode // Program start ROBOT.MoveJ(pose_ref); ROBOT.setPoseFrame(frame); // set the reference frame ROBOT.setPoseTool(tool); // set the tool frame: important for Online Programming ROBOT.setSpeed(100); // Set Speed to 100 mm/s ROBOT.setZoneData(5); // set the rounding instruction (C_DIS & APO_DIS / CNT / ZoneData / Blend Radius / ...) ROBOT.RunInstruction("CallOnStart"); for (int i = 0; i <= n_sides; i++) { double angle = ((double) i / n_sides) * 2.0 * Math.PI; Mat pose_i = pose_ref * Mat.rotz(angle) * Mat.transl(100, 0, 0) * Mat.rotz(-angle); ROBOT.RunInstruction("Moving to point " + i.ToString(), RoboDK.INSTRUCTION_COMMENT); double[] xyzwpr = pose_i.ToXYZRPW(); ROBOT.MoveL(pose_i); } ROBOT.RunInstruction("CallOnFinish"); ROBOT.MoveL(pose_ref); ``` -------------------------------- ### C# RoboDK Robot Movement and Offline Programming Example Source: https://github.com/robodk/robodk-api/blob/master/C This C# code snippet demonstrates how to use the RoboDK API to control a robot. It illustrates retrieving and setting reference frames and tool frames, configuring robot speed and zone data, and executing both joint (MoveJ) and linear (MoveL) movements. The script also shows how to run custom instructions and iterate through a series of poses to define a complex path for robot simulation or offline programming. ```C# // retrieve the reference frame and the tool frame (TCP) Mat frame = ROBOT.PoseFrame(); Mat tool = ROBOT.PoseTool(); int runmode = RDK.RunMode(); // retrieve the run mode // Program start ROBOT.MoveJ(pose_ref); ROBOT.setPoseFrame(frame); // set the reference frame ROBOT.setPoseTool(tool); // set the tool frame: important for Online Programming ROBOT.setSpeed(100); // Set Speed to 100 mm/s ROBOT.setZoneData(5); // set the rounding instruction (C_DIS & APO_DIS / CNT / ZoneData / Blend Radius / ...) ROBOT.RunInstruction("CallOnStart"); for (int i = 0; i <= n_sides; i++) { double angle = ((double) i / n_sides) * 2.0 * Math.PI; Mat pose_i = pose_ref * Mat.rotz(angle) * Mat.transl(100, 0, 0) * Mat.rotz(-angle); ROBOT.RunInstruction("Moving to point " + i.ToString(), RoboDK.INSTRUCTION_COMMENT); double[] xyzwpr = pose_i.ToXYZRPW(); ROBOT.MoveL(pose_i); } ROBOT.RunInstruction("CallOnFinish"); ROBOT.MoveL(pose_ref); ``` -------------------------------- ### Retrieve & Identify RoboDK Station Items (MATLAB) Source: https://github.com/robodk/robodk-api/blob/master/Matlab/html/Example_RoboDK.html Accesses various items (robot, frames, objects, tools, targets) within a loaded RoboDK station by name and type. Demonstrates how to use RDK.Item() to retrieve specific elements and print their names for verification. ```MATLAB % Get some items in the station by their name. Each item is visible in the % current project tree robot = RDK.Item('ABB IRB 1600-8/1.45', RDK.ITEM_TYPE_ROBOT); fprintf('Robot selected:\t%s\n', robot.Name()); robot.setVisible(1); % We can validate the type of each item by calling: % robot.Type() % We can retreive the item position with respect to the station with PoseAbs() % robot.PoseAbs() frameref = robot.Parent(); fprintf('Robot reference selected:\t%s\n', frameref.Name()); object = RDK.Item('base', RDK.ITEM_TYPE_OBJECT); fprintf('Object selected:\t%s\n', object.Name()); ball = RDK.Item('ball'); fprintf('Ball selected:\t%s\n', ball.Name()); frametable = RDK.Item('Table 1', RDK.ITEM_TYPE_FRAME); fprintf('Table selected:\t%s\n', frametable.Name()); tool = RDK.Item('Tool', RDK.ITEM_TYPE_TOOL); fprintf('Tool selected:\t%s\n', tool.Name()); target1 = RDK.Item('Target b1', RDK.ITEM_TYPE_TARGET); fprintf('Target 1 selected:\t%s\n', target1.Name()); target2 = RDK.Item('Target b3', RDK.ITEM_TYPE_TARGET); fprintf('Target 2 selected:\t%s\n', target2.Name()); ``` -------------------------------- ### Direct Robot Movement without Program Creation in RoboDK Source: https://github.com/robodk/robodk-api/blob/master/Matlab/html/Example_RoboDK.html This snippet demonstrates how to control a robot's movement directly using the RoboDK API, bypassing the need to create a formal program. It covers setting the pose frame, simulation speed, robot speed, and executing joint and linear movements using target items or direct joint arrays. ```MATLAB % Replace objects (we call the program previously set in example 1) RDK.Item('Replace objects', RDK.ITEM_TYPE_PROGRAM).RunProgram(); % RDK.setRunMode(1); % this performs a quick validation without showing the dynamic movement % (1 = RUNMODE_QUICKVALIDATE) fprintf('Moving by target item...\n'); robot.setPoseFrame(frametable); RDK.setSimulationSpeed(10); for i = 1:2 robot.setSpeed(10000, 1000); robot.MoveJ(target1); robot.setSpeed(100, 200); robot.MoveL(target2); end fprintf('Moving by joints...\n'); J1 = [0, 0, 0, 0, 50, 0]; J2 = [40, 30, -30, 0, 50, 0]; for i = 1:2 robot.MoveJ(J1); robot.MoveL(J2); end fprintf('Moving by pose...\n'); % Follow these steps to retreive a pose: % 1-Double click a robot ``` -------------------------------- ### Calculate Inverse Kinematics with Synchronized Linear Rail (RoboDK MATLAB) Source: https://github.com/robodk/robodk-api/blob/master/Matlab/html/Example_RoboDK.html This snippet demonstrates how to handle a robot with an external synchronized linear axis. It initializes the RoboDK API, retrieves the robot, ensures it's the main robot arm (not just the external axis), sets joint limits including for the external axis, retrieves home joints, and calculates all inverse kinematic solutions for the current robot pose. ```MATLAB % Start the API RDK = Robolink(); % Retrieve the robot robot = RDK.Item('', RDK.ITEM_TYPE_ROBOT); % Make sure the robot is the robot arm, not the external axis (returns a % pointer to itself if it is the robot already) robot = robot.getLink(RDK.ITEM_TYPE_ROBOT); disp(robot.Name()); robot.setJointLimits([-180; -180; -180; -180; -180; -180; 0], [+180; +180; +180; +180; +180; +180; 5000]); [lower_limit, upper_limit] = robot.JointLimits(); disp(lower_limit) disp(upper_limit) joints = robot.JointsHome(); config = robot.JointsConfig(joints); disp(config); all_solutions = robot.SolveIK_All(robot.SolveFK(robot.Joints())); disp(all_solutions) ``` -------------------------------- ### Item Class SolveIK/SolveIK All Frame Support (2018-07-16) Source: https://github.com/robodk/robodk-api/blob/master/C Enhances SolveIK and SolveIK All methods in the Item class to accept tool and reference frames, providing more flexibility for inverse kinematics calculations. An example usage is provided. ```APIDOC Item.cs: SolveIK and SolveIK All accept tool and reference frames As an example, to calculate the current inverse kinematics you can do: var jnts=ROBOT.SolveIK(ROBOT.Pose(), null, ROBOT.PoseTool(), ROBOT.PoseFrame()); ``` -------------------------------- ### Move Robot Jointly and Linearly with Predefined Poses (RoboDK MATLAB) Source: https://github.com/robodk/robodk-api/blob/master/Matlab/html/Example_RoboDK.html This snippet demonstrates how to define two 4x4 transformation matrices (poses) and use them to move a robot. It utilizes `robot.MoveJ` for joint movement and `robot.MoveL` for linear movement, iterating through the poses. ```MATLAB H1 = [-0.492404, -0.642788, -0.586824, -101.791308; -0.413176, 0.766044, -0.492404, 1265.638417; 0.766044, 0.000000, -0.642788, 117.851733; 0.000000, 0.000000, 0.000000, 1.000000]; H2 = [-0.759717, -0.280123, -0.586823, -323.957442; 0.060192, 0.868282, -0.492405, 358.739694; 0.647462, -0.409410, -0.642787, 239.313006; 0.000000, 0.000000, 0.000000, 1.000000]; for i = 1:2 robot.MoveJ(H1); robot.MoveL(H2); end ``` -------------------------------- ### New IRoboDK API Functions (2018-05-30) Source: https://github.com/robodk/robodk-api/blob/master/C Adds methods to the IRoboDK interface for retrieving RoboDK build information, requiring specific builds, getting version details, retrieving collision items, and displaying an ISO9283 cube program popup. ```APIDOC IRoboDK.cs: RoboDKBuild RequireBuild() (internal) Version() GetCollisionItems() Popup_ISO9283_CubeProgram() ``` -------------------------------- ### Attaching and Detaching Objects to Robot Tool in RoboDK Source: https://github.com/robodk/robodk-api/blob/master/Matlab/html/Example_RoboDK.html This snippet demonstrates how to attach the closest object to a robot's tool using the RoboDK API. It also shows how to detach all objects currently attached to the tool. A note on adjusting the attachment tolerance is included. ```MATLAB % Attach the closest object to the tool attached = tool.AttachClosest(); % If we know what object we want to attach, we can use this function % instead: object.setParentStatic(tool); if attached.Valid() attachedname = attached.Name(); fprintf('Attached: %s\n', attachedname); else % The tolerance can be changed in: % Tools->Options->General tab->Maximum distance to attach an object to % a robot tool (default is 1000 mm) fprintf('No object is close enough\n'); end pause(2); tool.DetachAll(); fprintf('Detached all objects\n'); ``` -------------------------------- ### Item Class Color API Updates (2018-04-19) Source: https://github.com/robodk/robodk-api/blob/master/C Updates the Item class to use System.Windows.Media.Color for color operations, replacing anonymous double arrays. New methods for recoloring, getting, and setting colors are introduced. ```APIDOC Item.cs: Replaced all anonymous double[] arrays with System.Windows.Media.Color ReColor() GetColor() SetColor() ``` -------------------------------- ### Draw Hexagon and Trigger Program with RoboDK API (Python) Source: https://github.com/robodk/robodk-api/blob/master/Python/readme.md This Python code snippet demonstrates how to program a robot to draw a hexagon around a specified reference point using linear movements. It iteratively calculates the coordinates for each vertex of the hexagon and commands the robot to move to these points. After completing the path, it triggers a predefined program ('Program_Done') on the robot controller. This example assumes an initialized 'robot' object (RoboDK robot item), a 'target_pos' object (RoboDK target item), 'xyz_ref' as the center coordinates, and 'R' as the radius of the hexagon. ```python # Draw a hexagon around the reference target: for i in range(7): ang = i*2*pi/6 #ang = 0, 60, 120, ..., 360 # Calculate the new position around the reference: x = xyz_ref[0] + R*cos(ang) # new X coordinate y = xyz_ref[1] + R*sin(ang) # new Y coordinate z = xyz_ref[2] # new Z coordinate target_pos.setPos([x,y,z]) # Move to the new target: robot.MoveL(target_pos) # Trigger a program call at the end of the movement robot.RunCode('Program_Done') ``` -------------------------------- ### Build RoboDK C++ API Static Library with CMake Source: https://github.com/robodk/robodk-api/blob/master/C++/readme.md This snippet provides command-line instructions to build a static library for the RoboDK C++ API using CMake. It outlines the steps to create a build directory, configure CMake, and compile the project, making it easily integratable into other CMake-based projects. ```bash mkdir build cd build cmake .. cmake --build . ``` -------------------------------- ### New Item API Functions (2018-05-30) Source: https://github.com/robodk/robodk-api/blob/master/C Introduces methods to the Item class for showing instructions and targets. ```APIDOC Item.cs: ShowInstructions() ShowTargets() ``` -------------------------------- ### Configure Pylint with RoboDK Plugin Source: https://github.com/robodk/robodk-api/blob/master/Python/readme.md This command-line argument is used to integrate the `pylint_robodk` module with Pylint. By loading this plugin, developers can enable RoboDK-specific linting rules and checks when analyzing Python source code, ensuring adherence to best practices for RoboDK API usage. ```bash --load-plugins=pylint_robodk ```