### start_rt_control usage example Source: https://doosanrobotics.github.io/doosan-robotics-api-manual/GL013302/_sources/mode/rt/session_lifecycle/start_rt_control.rst.txt A complete example demonstrating how to connect to the controller, configure RT output, and start the real-time data stream. ```cpp #include "DRFLEx.h" #include using namespace DRAFramework; int main() { CDRFLEx drfl; drfl.connect_rt_control("192.168.137.100", 12347); std::string version = "v1.0"; float period = 0.001f; // 1 msec = 1 kHz int lossCount = 4; // Configure RT output and start streaming drfl.set_rt_control_output(version, period, lossCount); if (drfl.start_rt_control()) std::cout << "RT streaming started." << std::endl; else std::cout << "Failed to start RT streaming." << std::endl; return 0; } ``` -------------------------------- ### connect_rt_control usage example Source: https://doosanrobotics.github.io/doosan-robotics-api-manual/GL013302/_sources/mode/rt/session_lifecycle/connect_rt_control.rst.txt A complete example demonstrating how to instantiate the CDRFLEx class and establish a UDP connection for RT control before starting the streaming process. ```cpp #include "DRFLEx.h" #include using namespace DRAFramework; int main() { CDRFLEx drfl; // Connect to the robot controller via UDP for RT control if (drfl.connect_rt_control("192.168.137.100", 12347)) { std::cout << "RT connection established successfully." << std::endl; // Ready to configure input/output schema and start RT streaming drfl.start_rt_control(); } else { std::cout << "RT connection failed." << std::endl; } return 0; } ``` -------------------------------- ### Example Configuration for EtherNet/IP Welding Signals Source: https://doosanrobotics.github.io/doosan-robotics-api-manual/GL013302/applications/welding/digital_eip_interface/app_weld_set_interface_eip_r2m_process.html This example demonstrates mapping the welding start, robot ready, and error reset signals to specific byte and bit positions in the EtherNet/IP communication frame. ```cpp CONFIG_DIGITAL_WELDING_INTERFACE_PROCESS processSetting; // Welding Start Signal Mapping processSetting._WeldingStart._bEnable = 1; processSetting._WeldingStart._bByteOffset = 5; processSetting._WeldingStart._bBitOffset = 3; processSetting._WeldingStart._bCommDataType = 4; // 8-bit data // Robot Ready Signal Mapping processSetting._RobotReady._bEnable = 1; processSetting._RobotReady._bByteOffset = 8; processSetting._RobotReady._bBitOffset = 0; processSetting._RobotReady._bCommDataType = 4; // Error Reset Signal Mapping processSetting._ErrorReset._bEnable = 1; processSetting._ErrorReset._bByteOffset = 10; processSetting._ErrorReset._bBitOffset = 2; processSetting._ErrorReset._bCommDataType = 4; // Apply configuration bool result = Drfl.app_weld_set_interface_eip_r2m_process(processSetting); ``` -------------------------------- ### Configuring welding interface signals Source: https://doosanrobotics.github.io/doosan-robotics-api-manual/GL013302/_sources/applications/welding/digital_eip_interface/app_weld_set_interface_eip_r2m_process.rst.txt Example showing how to map welding start and robot ready signals by configuring the CONFIG_DIGITAL_WELDING_INTERFACE_PROCESS structure. ```cpp CONFIG_DIGITAL_WELDING_INTERFACE_PROCESS processSetting; // Welding Start Signal Mapping processSetting._WeldingStart._bEnable = 1; processSetting._WeldingStart._bByteOffset = 5; processSetting._WeldingStart._bBitOffset = 3; processSetting._WeldingStart._bCommDataType = 4; // 8-bit data // Robot Ready Signal Mapping processSetting._RobotReady._bEnable = 1; processSetting._RobotReady._bByteOffset = 8; processSetting._RobotReady._bBitOffset = 0; processSetting._RobotReady._bCommDataType = 4; ``` -------------------------------- ### servoj usage example Source: https://doosanrobotics.github.io/doosan-robotics-api-manual/GL013302/_sources/mode/auto/velocity_servo/servoj.rst.txt Example demonstrating how to initialize the CDRFLEx class and execute a servoj command in Override mode, with a commented-out example for Queue mode. ```cpp #include "DRFLEx.h" using namespace DRAFramework; int main() { CDRFLEx drfl; // Preconditions: Connected, servo ON, **Auto mode** active // Target joint pose and limits float q[6] = { 0.f, 0.f, 90.f, 0.f, 0.f, 0.f }; float jvel[6] = { 10.f, 10.f, 10.f, 10.f, 10.f, 10.f }; float jacc[6] = { 10.f, 10.f, 10.f, 10.f, 10.f, 10.f }; // Override: keep following the most recent target drfl.servoj(q, jvel, jacc, 0.02f, DR_SERVO_OVERRIDE); // Queue example (buffer waypoints) // drfl.servoj(q, jvel, jacc, 0.02f, DR_SERVO_QUEUE); return 0; } ``` -------------------------------- ### movejx Usage Examples Source: https://doosanrobotics.github.io/doosan-robotics-api-manual/GL013302/_sources/mode/auto/motion_primitives_advanced/movejx.rst.txt Examples demonstrating velocity/acceleration-based movement, time-based movement, and setup for motion blending. ```cpp // CASE 1 — Velocity/acceleration-based joint-space move float x1[6] = {559, 34.5, 651.5, 0, 180, 0}; unsigned char sol = 2; float jvel = 10; float jacc = 20; drfl.movejx(x1, sol, jvel, jacc); // Moves to the target pose corresponding to x1 // using velocity 10 deg/s and acceleration 20 deg/s². // CASE 2 — Time-based motion float x2[6] = {559, 34.5, 651.5, 0, 180, 0}; drfl.movejx(x2, sol, 0, 0, 5); // Moves to the target joint configuration in 5 seconds. // CASE 3 — Motion blending with previous move float x3[6] = {559, 34.5, 651.5, 0, 180, 0}; float x4[6] = {559, 434.5, 651.5, 0, 180, 0}; float blend_radius = 50; ``` -------------------------------- ### Registering a real-time monitoring callback Source: https://doosanrobotics.github.io/doosan-robotics-api-manual/GL013302/_sources/mode/rt/diagnostics_callbacks/set_on_rt_monitoring_data.rst.txt Example demonstrating how to define a callback function and register it using set_on_rt_monitoring_data before starting real-time control. ```cpp // Define callback function void OnRTMonitoringData(LPRT_OUTPUT_DATA_LIST data) { static int count = 0; if (++count % 60 == 0) { // Print every 60 cycles (~0.06s at 1kHz) printf("Timestamp: %.3lf\n", data->_time_stamp); printf("Actual Joint Position: %.3f %.3f %.3f %.3f %.3f %.3f\n", data->_actual_joint_position[0], data->_actual_joint_position[1], data->_actual_joint_position[2], data->_actual_joint_position[3], data->_actual_joint_position[4], data->_actual_joint_position[5]); printf("Actual Motor Torque: %.3f %.3f %.3f %.3f %.3f %.3f\n", data->_actual_motor_torque[0], data->_actual_motor_torque[1], data->_actual_motor_torque[2], data->_actual_motor_torque[3], data->_actual_motor_torque[4], data->_actual_motor_torque[5]); printf("----------------------------------------\n"); } } // Main program int main() { CDRFLEx drfl; drfl.connect_rt_control("192.168.137.100", 12347); string version = "v1.0"; float period = 0.001f; // 1 ms int losscount = 4; // Register callback for RT monitoring drfl.set_on_rt_monitoring_data(OnRTMonitoringData); // Configure real-time input/output channels drfl.set_rt_control_input(version, period, losscount); drfl.set_rt_control_output(version, period, losscount); // Start real-time control drfl.start_rt_control(); while (true) { // Application logic or motion control loop } drfl.disconnect_rt_control(); return 0; } ``` -------------------------------- ### speedl usage example Source: https://doosanrobotics.github.io/doosan-robotics-api-manual/GL013302/_sources/mode/auto/velocity_servo/speedl.rst.txt A complete example demonstrating the initialization of velocity and acceleration parameters and the execution of the speedl command. ```cpp #include "DRFLEx.h" using namespace DRAFramework; int main() { CDRFLEx drfl; // Preconditions: Connected, servo ON, Auto mode active // Define linear velocity and acceleration in Cartesian space float jvel[6] = {10.f, 10.f, 10.f, 10.f, 10.f, 10.f}; float jacc[2] = {20.f, 20.f}; // Execute TCP velocity control drfl.speedl(jvel, jacc, -10000.f); return 0; } ``` -------------------------------- ### Verify system type before starting manual teaching Source: https://doosanrobotics.github.io/doosan-robotics-api-manual/GL013302/_sources/mode/manual/safety_servo_operations/get_robot_system.rst.txt This C++ example demonstrates how to retrieve the robot system type using get_robot_system and use a switch statement to handle different system environments (real, virtual, or emulator) before proceeding with operations. ```cpp #include "DRFLEx.h" #include using namespace DRAFramework; using namespace std; int main() { CDRFLEx drfl; // Preconditions: // - Connection established (open_connection) ROBOT_SYSTEM sysType = drfl.get_robot_system(); switch (sysType) { case ROBOT_SYSTEM_REAL: cout << "[System] Connected to a REAL robot.\n"; cout << "Proceeding with manual teaching operations.\n"; break; case ROBOT_SYSTEM_VIRTUAL: cout << "[System] Running on VIRTUAL controller.\n"; cout << "Motion commands will be simulated.\n"; break; case ROBOT_SYSTEM_EMULATOR: cout << "[System] Connected to EMULATOR environment.\n"; cout << "Force/IO feedback may be limited.\n"; break; default: cout << "[System] Unknown system type detected.\n"; break; } return 0; } ``` -------------------------------- ### Starting a Simple DRL Loop in Auto Mode Source: https://doosanrobotics.github.io/doosan-robotics-api-manual/GL013302/_sources/mode/auto/drl_program_control/drl_start.rst.txt This example demonstrates how to define a DRL program as a string and execute it using drl_start after verifying the robot is in Auto Mode and the standby state. ```cpp #include "DRFLEx.h" #include using namespace DRAFramework; int main() { CDRFLEx drfl; // 1) Connect & initialize (omitted here – handled in common setup code) // e.g., drfl.open_connection("192.168.137.100"); // drfl.set_robot_system(ROBOT_SYSTEM_REAL); // 2) Define a simple DRL program as a string // - Repeats a back-and-forth joint motion three times. std::string drlProgram = "loop = 0\r\n" "while loop < 3:\r\n" " movej(posj(10,10,10,10,10,10), vel=60, acc=60)\r\n" " movej(posj(0,0,0,0,0,0), vel=60, acc=60)\r\n" " loop = loop + 1\r\n" "end\r\n"; // 3) Ensure robot is in Auto Mode and ready if (drfl.get_robot_mode() == ROBOT_MODE_AUTONOMOUS && drfl.get_robot_state() == eSTATE_STANDBY) { // Choose target robot system: // - ROBOT_SYSTEM_REAL : real robot (field) // - ROBOT_SYSTEM_VIRTUAL : virtual system (simulation/test) ROBOT_SYSTEM targetSystem = ROBOT_SYSTEM_REAL; if (!drfl.drl_start(targetSystem, drlProgram)) { std::cerr << "Failed to start DRL program." << std::endl; return -1; } std::cout << "DRL program started in Auto Mode." << std::endl; } else { std::cerr << "Robot is not in Auto/Standby state. Cannot start DRL." << std::endl; } return 0; } ``` -------------------------------- ### Example usage of get_rt_control_input_version_list Source: https://doosanrobotics.github.io/doosan-robotics-api-manual/GL013302/_sources/mode/rt/schema_version/get_rt_control_input_version_list.rst.txt A complete example demonstrating how to connect to the controller and query the available RT input version list. ```cpp #include "DRFLEx.h" #include using namespace DRAFramework; int main() { CDRFLEx drfl; // Connect and query RT input version list drfl.connect_rt_control("192.168.137.100", 12347); std::string version_list = drfl.get_rt_control_input_version_list(); std::cout << "Available RT input versions: " << version_list << std::endl; drfl.disconnect_rt_control(); return 0; } ``` -------------------------------- ### get_rt_control_output_version_list usage example Source: https://doosanrobotics.github.io/doosan-robotics-api-manual/GL013302/_sources/mode/rt/schema_version/get_rt_control_output_version_list.rst.txt Example demonstrating how to connect to the robot controller and query the list of available RT output versions. ```cpp #include "DRFLEx.h" #include using namespace DRAFramework; int main() { CDRFLEx drfl; // Connect and query RT output version list drfl.connect_rt_control("192.168.137.100", 12347); std::string version_list = drfl.get_rt_control_output_version_list(); std::cout << "Available RT output versions: " << version_list << std::endl; drfl.disconnect_rt_control(); return 0; } ``` -------------------------------- ### Example usage of setup_monitoring_version Source: https://doosanrobotics.github.io/doosan-robotics-api-manual/GL013302/_sources/mode/common/monitoring_callbacks/setup_monitoring_version.rst.txt Example showing how to set the monitoring data version to 1 to enable extended monitoring features. ```cpp drfl.setup_monitoring_version(1); // Set monitoring data version information to 1 ``` -------------------------------- ### disconnect_rt_control usage example Source: https://doosanrobotics.github.io/doosan-robotics-api-manual/GL013302/_sources/mode/rt/session_lifecycle/disconnect_rt_control.rst.txt An example demonstrating the sequence of connecting, starting, stopping, and finally disconnecting an RT control session. ```cpp #include "DRFLEx.h" using namespace DRAFramework; int main() { CDRFLEx drfl; drfl.connect_rt_control("192.168.137.100", 12347); drfl.start_rt_control(); // Stop streaming and close the UDP channel drfl.stop_rt_control(); drfl.disconnect_rt_control(); return 0; } ``` -------------------------------- ### Controller Connection Setup Source: https://doosanrobotics.github.io/doosan-robotics-api-manual/GL013302/_sources/tutorials/scenarios/4_minimal_welding_sample.rst.txt Opens the TCP/IP connection and initializes monitoring version and system version. ```cpp assert(Drfl.open_connection(IP_ADDR)); Drfl.setup_monitoring_version(1); // (0 -> older version, 1 -> latest) SYSTEM_VERSION tSysVerion = {'\0',}; Drfl.get_system_version(&tSysVerion); ``` -------------------------------- ### stop_rt_control Usage Example Source: https://doosanrobotics.github.io/doosan-robotics-api-manual/GL013302/_sources/mode/rt/session_lifecycle/stop_rt_control.rst.txt A complete example demonstrating the lifecycle of real-time control, including connection, configuration, starting, stopping, and disconnecting. ```cpp #include "DRFLEx.h" #include using namespace DRAFramework; int main() { CDRFLEx drfl; // Connect and configure drfl.connect_rt_control("192.168.137.100", 12347); std::string version = "v1.0"; float period = 0.001f; // 1 msec = 1 kHz int lossCount = 4; drfl.set_rt_control_output(version, period, lossCount); drfl.start_rt_control(); // Perform RT operations // ... // Stop real-time communication drfl.stop_rt_control(); // Finally disconnect drfl.disconnect_rt_control(); return 0; } ``` -------------------------------- ### Switch to real robot system in C++ Source: https://doosanrobotics.github.io/doosan-robotics-api-manual/GL013302/_sources/mode/manual/safety_servo_operations/set_robot_system.rst.txt This example demonstrates how to configure the controller to real hardware mode using set_robot_system and verify the change with get_robot_system before initiating a move command. ```cpp #include "DRFLEx.h" #include #include using namespace std; using namespace DRAFramework; int main() { CDRFLEx drfl; // Preconditions: // - Connection established (open_connection) // - No motion currently in progress cout << "[System] Setting robot system to REAL hardware...\n"; if (drfl.set_robot_system(ROBOT_SYSTEM_REAL)) cout << "[System] Robot system set to REAL.\n"; else cout << "[System] Failed to change robot system.\n"; // Verify configuration ROBOT_SYSTEM sysType = drfl.get_robot_system(); cout << "[System] Current system type: " << sysType << endl; // Continue with manual teaching sequence float qTarget[6] = {0, -30, 90, 0, 90, 0}; drfl.movej(qTarget, 30, 30); return 0; } ``` -------------------------------- ### Initialize teaching environment after TP startup Source: https://doosanrobotics.github.io/doosan-robotics-api-manual/GL013302/_sources/mode/manual/tp_logging_lifecycle/set_on_tp_initializing_completed.rst.txt Registers a callback function to execute once the Teach Pendant is ready, demonstrating how to set an LED color to indicate system readiness. ```cpp #include "DRFLEx.h" #include #include using namespace std; using namespace DRAFramework; CDRFLEx drfl; // Callback executed after TP finishes initialization void OnTpInitCompleted() { cout << "-------------------------------------------\n"; cout << "[TP INITIALIZATION COMPLETED]\n"; cout << "Teach Pendant is now ready for user interaction.\n"; cout << "-------------------------------------------\n"; // Set LED to indicate readiness drfl.set_state_led_color(0, 255, 0); // Green: Ready } int main() { drfl.open_connection("192.168.137.100"); drfl.set_on_tp_initializing_completed(OnTpInitCompleted); cout << "[Teach] Waiting for TP initialization...\n"; // Keep running to detect initialization completion while (true) this_thread::sleep_for(chrono::seconds(1)); return 0; } ``` -------------------------------- ### Connect to controller and retrieve system version Source: https://doosanrobotics.github.io/doosan-robotics-api-manual/GL013302/_sources/mode/common/connection/openconnection.rst.txt This example demonstrates connecting to the robot controller using an IP address and subsequently retrieving and printing the controller's system version upon a successful connection. ```cpp CDRFLEx drfl; bool bConnected = drfl.open_connection("192.168.137.100"); if (bConnected) { SYSTEM_VERSION tSysVerion = { '\0', }; DrFl.get_system_version(&tSysVerion); cout << "System version: " << tSysVerion._szController << endl; } ``` -------------------------------- ### Writing to a Modbus Register to Start a Conveyor Source: https://doosanrobotics.github.io/doosan-robotics-api-manual/GL013302/_sources/mode/auto/gpio_modbus_flange/set_modbus_output.rst.txt This example demonstrates sending a start signal to a conveyor motor via Modbus before executing a joint motion in Auto Mode. ```cpp #include "DRFLEx.h" #include using namespace DRAFramework; int main() { CDRFLEx drfl; // Write value '1' to start a conveyor motor via Modbus if (!drfl.set_modbus_output("CONVEYOR_START", 1)) { printf("Failed to write Modbus output.\n"); return -1; } // Perform Auto Mode motion after triggering the conveyor float pos[6] = {400.f, 150.f, 300.f, 180.f, 0.f, 0.f}; drfl.movej(pos, 60.f, 30.f); return 0; } ``` -------------------------------- ### get_robot_mode Usage Example Source: https://doosanrobotics.github.io/doosan-robotics-api-manual/GL013302/_sources/mode/common/mode_state/get_robot_mode.rst.txt This example demonstrates checking the robot's operation mode to perform either a jog motion in manual mode or start a DRL program in automatic mode. ```cpp string strDrProgram = "\r\n" "loop = 0\r\n" "while loop < 3:\r\n" " movej(posj(10,10,10,10,10,10), vel=60, acc=60)\r\n" " movel(posx(00,00,00,00,00,00), vel=60, acc=60)\r\n" " loop=loop+1\r\n" "end\r\n" "movej(posj(10,10,10,10,10,10), vel=60, acc=60)\r\n"; if (drfl.get_robot_state() == ESTATE_STANDBY) { if (drfl.get_robot_mode() == ROBOT_MODE_MANUAL) { // Manual mode drfl.jog(JOG_AXIS_JOINT_3, MOVE_REFERENCE_BASE, 0.0f); sleep(2); drfl.jog(JOG_AXIS_JOINT_3, MOVE_REFERENCE_BASE, 0.0f); } else { // Automatic mode ROBOT_SYSTEM eTargetSystem = ROBOT_SYSTEM_VIRTUAL; drfl.drl_start(eTargetSystem, strDrProgram); } } ``` -------------------------------- ### Asynchronous Spline Motion Execution Example Source: https://doosanrobotics.github.io/doosan-robotics-api-manual/GL013302/_sources/mode/auto/motion_primitives_advanced/amovesx.rst.txt This example demonstrates performing an asynchronous spline motion through four TCP waypoints and triggering a digital output 3 seconds after the motion starts. ```cpp // Execute an asynchronous Cartesian spline motion through multiple waypoints. // D-Out is triggered 3 seconds after the spline motion starts. float xpos[4][6]; int xposNum = 4; float tvel[2] = { 50, 50 }; float tacc[2] = { 100, 100 }; xpos[0][0]=559; xpos[0][1]=434.5; xpos[0][2]=651.5; xpos[0][3]=0; xpos[0][4]=180; xpos[0][5]=0; xpos[1][0]=559; xpos[1][1]=484.5; xpos[1][2]=251.5; xpos[1][3]=0; xpos[1][4]=180; xpos[1][5]=0; xpos[2][0]=559; xpos[2][1]=234.5; xpos[2][2]=251.5; xpos[2][3]=0; xpos[2][4]=180; xpos[2][5]=0; xpos[3][0]=559; xpos[3][1]=134.5; xpos[3][2]=451.5; xpos[3][3]=0; xpos[3][4]=180; xpos[3][5]=0; drfl.amovesx(xpos, xposNum, tvel, tacc, 0, MOVE_MODE_ABSOLUTE); Sleep(3000); drfl.set_digital_output(GPIO_CTRLBOX_DIGITAL_INDEX_1, 1); ``` -------------------------------- ### Configure tool digital output type example Source: https://doosanrobotics.github.io/doosan-robotics-api-manual/GL013302/_sources/mode/common/io/set_tool_digital_output_type.rst.txt An example demonstrating how to configure tool digital output port #1 to PNP type using the CDRFLEx class. ```cpp #include "DRFLEx.h" using namespace DRAFramework; int main() { CDRFLEx drfl; // Configure tool digital output port #1 to PNP type bool result = drfl.set_tool_digital_output_type(1, OUTPUT_TYPE_PNP); if (result) printf("Tool DO port #1 configured to PNP output type.\n"); else printf("Failed to configure digital output type.\n"); } ``` -------------------------------- ### RT Console Logs Source: https://doosanrobotics.github.io/doosan-robotics-api-manual/GL013302/_sources/tutorials/scenarios/6_realtime_control_sample.rst.txt Example output showing the start and end positions for alternating loops. ```text Loop 0) Start position: 0, 0, 0, 0, 0, 0, Loop 0) End position: 30, 30, 60, -30, -90, 30, Loop 1) Start position: 30, 30, 60, -30, -90, 30, Loop 1) End position: 0, 0, 0, 0, 0, 0, ... ``` -------------------------------- ### Registering a New Tool Configuration in C++ Source: https://doosanrobotics.github.io/doosan-robotics-api-manual/GL013302/_sources/mode/auto/tool_tcp_payload/add_tool.rst.txt This example demonstrates how to define tool properties, register the tool using add_tool, and activate it with set_tool for Auto Mode operations. ```cpp #include "DRFLEx.h" #include using namespace DRAFramework; int main() { CDRFLEx drfl; float cog[3] = {0.f, 0.f, 40.f}; // in mm relative to flange/TCP float inertia[6] = {0.f, 0.f, 0.f, 0.f, 0.f, 0.f}; // Register a new tool if (drfl.add_tool("NEW_END_EFFECTOR", 1.2f, cog, inertia)) { printf("Tool registered successfully.\n"); } else { printf("Failed to register tool.\n"); return -1; } // Select the new tool for Auto Mode operation drfl.set_tool("NEW_END_EFFECTOR"); return 0; } ``` -------------------------------- ### Initialize and Start RT Control Source: https://doosanrobotics.github.io/doosan-robotics-api-manual/GL013302/_sources/mode/rt/create_destroy/create_robot_control_udp.rst.txt This example demonstrates how the CDRFLEx constructor automatically creates the UDP RT control instance, which is then used to connect to a specific IP and port and start real-time control. ```cpp #include "DRFLEx.h" using namespace DRAFramework; int main() { // Constructor automatically creates a UDP RT control instance CDRFLEx drfl; // The instance can now be used for real-time control operations drfl.connect_rt_control("192.168.137.100", 12347); drfl.start_rt_control(); } ``` -------------------------------- ### set_robot_system usage example Source: https://doosanrobotics.github.io/doosan-robotics-api-manual/GL013302/_sources/mode/common/mode_state/set_robot_system.rst.txt Example demonstrating how to check the current robot system and switch to the real robot system if necessary. ```cpp ROBOT_SYSTEM eRobotSystem = drfl.get_robot_system(); if (eRobotSystem != ROBOT_SYSTEM_REAL) { // Converts to real robot system drfl.set_robot_system(ROBOT_SYSTEM_REAL); } else { // Do something ... } ``` -------------------------------- ### Setup Connection and Variables Source: https://doosanrobotics.github.io/doosan-robotics-api-manual/GL013302/_sources/tutorials/scenarios/3_send_drl_script_sample.rst.txt Defines the communication protocol version, controller IP address, and state tracking variables required before establishing a connection. ```cpp #define DRCF_VERSION 2 // Set 2 or 3 according to drcf version. const std::string IP_ADDRESS = "192.168.137.100"; // real mode CDRFLEx robot; // Instance for APIs bool get_control_access = false; // Variable to check control authority bool is_standby = false; // Variable to check whether the robot state is standby. ``` -------------------------------- ### Terminate active alter motion session Source: https://doosanrobotics.github.io/doosan-robotics-api-manual/GL013302/_sources/mode/common/motion_execution/disable_alter_motion.rst.txt Example demonstrating how to start a thread for alter motion, enable the mode, and subsequently disable it to restore normal control. ```cpp #include "DRFLEx.h" #include using namespace DRAFramework; // Thread routine continuously sending small delta corrections void ThreadFunc() { CDRFLEx drfl; float delta[6] = {10.0f, 0, 0, 10.0f, 0, 0}; while (true) { drfl.alter_motion(delta); std::this_thread::sleep_for(std::chrono::milliseconds(20)); } } int main() { CDRFLEx drfl; // 1) Start a separate thread to run alter motion continuously std::thread th(ThreadFunc); // 2) Enable alter motion mode (prepare fine-tuning control) float limitDpos[2] = {50.0f, 90.0f}; float limitDposPer[2] = {5.0f, 50.0f}; drfl.enable_alter_motion(5, PATH_MODE_DPOS, COORDINATE_SYSTEM_BASE, limitDpos, limitDposPer); // ... Fine-tuning in progress ... // 3) Disable alter motion mode to restore normal control drfl.disable_alter_motion(); th.detach(); // clean up background thread return 0; } ``` -------------------------------- ### Checking Active TCP Before Starting a Task Source: https://doosanrobotics.github.io/doosan-robotics-api-manual/GL013302/_sources/mode/auto/tool_tcp_payload/get_tcp.rst.txt This example demonstrates how to retrieve the active TCP using get_tcp and validate it against an expected value to prevent incorrect automated behavior. ```cpp #include "DRFLEx.h" #include using namespace DRAFramework; int main() { CDRFLEx drfl; // Query currently active TCP std::string activeTcp = drfl.get_tcp(); printf("Active TCP: %s\n", activeTcp.c_str()); // Validate expected TCP for the upcoming recipe if (activeTcp != "TCP_GRIPPER_CENTER") { printf("Warning: Unexpected TCP is active.\n"); } return 0; } ``` -------------------------------- ### speedl_rt real-time streaming example Source: https://doosanrobotics.github.io/doosan-robotics-api-manual/GL013302/_sources/mode/rt/command_control/speedl_rt.rst.txt A complete example showing how to connect to the robot, configure RT streaming, and send a real-time TCP velocity command. ```cpp #include "DRFLEx.h" #include using namespace DRAFramework; int main() { CDRFLEx drfl; // Connect and configure RT streaming drfl.connect_rt_control("192.168.137.100", 12347); std::string version = "v1.0"; float period = 0.001f; // 1 ms cycle int lossCount = 4; drfl.set_rt_control_input(version, period, lossCount); drfl.set_rt_control_output(version, period, lossCount); drfl.start_rt_control(); // Define velocity and acceleration targets float fTargetVel[6] = {150.0f, 0.0f, 100.0f, 0.0f, 0.0f, 0.0f}; float fTargetAcc[6] = {800.0f, 800.0f, 800.0f, 100.0f, 100.0f, 100.0f}; float fTargetTime = 0.06f; // 60 ms // Send real-time TCP velocity command if (drfl.speedl_rt(fTargetVel, fTargetAcc, fTargetTime)) std::cout << "TCP velocity command successful." << std::endl; else std::cout << "TCP velocity command failed." << std::endl; drfl.stop_rt_control(); drfl.disconnect_rt_control(); return 0; } ``` -------------------------------- ### Real-time data reading example Source: https://doosanrobotics.github.io/doosan-robotics-api-manual/GL013302/_sources/mode/rt/data_io/read_data_rt.rst.txt A complete example demonstrating how to connect to RT control, configure streaming, and continuously read joint data in a loop. ```cpp #include "DRFLEx.h" #include #include using namespace DRAFramework; int main() { CDRFLEx drfl; drfl.connect_rt_control("192.168.137.100", 12347); std::string version = "v1.0"; float period = 0.001f; // 1 msec int lossCount = 4; // Configure input/output streaming drfl.set_rt_control_input(version, period, lossCount); drfl.set_rt_control_output(version, period, lossCount); drfl.start_rt_control(); // Real-time reading loop while (true) { auto data = drfl.read_data_rt(); if (!data) continue; // Read key fields float jointPos[6]; float jointVel[6]; float jointTorque[6]; memcpy(jointPos, data->actual_joint_position, sizeof(float) * 6); memcpy(jointVel, data->actual_joint_velocity, sizeof(float) * 6); memcpy(jointTorque, data->actual_joint_torque, sizeof(float) * 6); std::cout << "Joint 1 Pos: " << jointPos[0] << " Vel: " << jointVel[0] << " Torque: " << jointTorque[0] << std::endl; // Custom condition to break the loop if (jointPos[0] > 30.0f) break; // Sleep for the RT period std::this_thread::sleep_for(std::chrono::milliseconds(1)); } drfl.stop_rt_control(); drfl.disconnect_rt_control(); return 0; } ``` -------------------------------- ### Configuring analog output modes example Source: https://doosanrobotics.github.io/doosan-robotics-api-manual/GL013302/_sources/mode/common/io/set_mode_analog_output.rst.txt Example demonstrating how to set analog output #1 to current mode and analog output #2 to voltage mode. ```cpp #include "DRFLEx.h" using namespace DRAFramework; int main() { CDRFLEx drfl; // Set analog output #1 to current mode (4–20 mA) drfl.set_mode_analog_output(GPIO_CTRLBOX_ANALOG_INDEX_1, GPIO_ANALOG_TYPE_CURRENT); // Set analog output #2 to voltage mode (0–10 V) drfl.set_mode_analog_output(GPIO_CTRLBOX_ANALOG_INDEX_2, GPIO_ANALOG_TYPE_VOLTAGE); } ``` -------------------------------- ### Registering and managing a tool Source: https://doosanrobotics.github.io/doosan-robotics-api-manual/GL013302/_sources/mode/common/tool/add_tool.rst.txt Example demonstrating how to register a tool with specific physical properties, set it as the active tool, and subsequently remove the registration. ```cpp #include "DRFLEx.h" using namespace DRAFramework; int main() { CDRFLEx drfl; float fCog[3] = {10.f, 10.f, 10.f}; float fInertia[6] = {0.f, 0.f, 0.f, 0.f, 0.f, 0.f}; // (1) Register a new tool bool success = drfl.add_tool("tool#1", 5.3f, fCog, fInertia); // (2) Set it as the active tool if (success) drfl.set_tool("tool#1"); // (3) Remove the tool registration drfl.del_tool("tool#1"); } ``` -------------------------------- ### Resuming Motion After a Conditional Pause Source: https://doosanrobotics.github.io/doosan-robotics-api-manual/GL013302/_sources/mode/auto/motion_control_utilities/move_resume.rst.txt This example demonstrates using move_resume() to continue a trajectory after a pause triggered by real-time joint position feedback. It includes starting an asynchronous motion, monitoring joint 3, pausing the motion, and finally resuming it. ```cpp #include "DRFLEx.h" using namespace DRAFramework; int main() { CDRFLEx drfl; float target[6] = {0, 0, 90, 0, 90, 0}; // 1) Start asynchronous motion drfl.amovej(target, 20, 40); // 2) Pause when joint 3 reaches threshold while (true) { LPPOSITION pos = drfl.get_current_pose(ROBOT_POSE_JOINT); if (!pos) continue; if (pos->_fTargetPos[2] >= 45) { drfl.move_pause(); printf("Motion paused at J3 >= 45 degrees.\n"); Sleep(3000); // Wait three seconds break; } } // 3) Resume the paused motion if (!drfl.move_resume()) { printf("Failed to resume motion.\n"); return -1; } printf("Motion resumed.\n"); return 0; } ``` -------------------------------- ### Enable Cartesian Compliance for Automated Insertion Source: https://doosanrobotics.github.io/doosan-robotics-api-manual/GL013302/_sources/mode/auto/force_compliance/task_compliance_ctrl.rst.txt This example demonstrates the workflow of moving to a starting position, enabling compliance control with base stiffness, dynamically adjusting stiffness for an insertion task, and finally releasing compliance control to return to standard position control. ```cpp #include "DRFLEx.h" #include using namespace DRAFramework; int main() { CDRFLEx drfl; // Preconditions: // - Connection established, servo ON // - Auto mode active // 1) Move to a safe position for insertion float q0[6] = {0.0f, 0.0f, 90.0f, 0.0f, 90.0f, 0.0f}; drfl.movej(q0, 60, 30); drfl.mwait(); // 2) Enable compliance control with base stiffness float baseStiff[6] = {3000.f, 3000.f, 3000.f, 200.f, 200.f, 200.f}; drfl.task_compliance_ctrl(baseStiff, COORDINATE_SYSTEM_TOOL, 0.0f); // 3) Adjust stiffness dynamically for insertion task float newStiff[6] = {1000.f, 1500.f, 2000.f, 150.f, 150.f, 150.f}; drfl.set_stiffnessx(newStiff, COORDINATE_SYSTEM_TOOL, 0.5f); // 4) Finalize insertion task and return to position control drfl.release_compliance_ctrl(); printf("Compliance mode enabled for automated insertion.\n"); return 0; } ``` -------------------------------- ### Control Authority and Servo ON Output Source: https://doosanrobotics.github.io/doosan-robotics-api-manual/GL013302/tutorials/scenarios/4_minimal_welding_sample.html Example output showing the system and library versions after successful initialization. ```text System version: GF03050000 Library version: GL013300 ``` -------------------------------- ### get_tool usage example Source: https://doosanrobotics.github.io/doosan-robotics-api-manual/GL013302/_sources/mode/common/tool/get_tool.rst.txt Example demonstrating how to retrieve the current tool name and conditionally set a new tool if the current one does not match the expected value. ```cpp string strTool = drfl.get_tool(); // Check the currently mounted tool if (strTool != "tool#1") { drfl.set_tool("tool#1"); } ``` -------------------------------- ### get_current_rotm usage example Source: https://doosanrobotics.github.io/doosan-robotics-api-manual/GL013302/_sources/mode/common/position/get_current_rotm.rst.txt Example demonstrating how to retrieve and print the rotation matrix of the tool. ```cpp float (*result)[3] = drfl.get_current_rotm(); for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { cout << result[i][j] << " "; } cout << endl; } ``` -------------------------------- ### Realtime Connection Setup Source: https://doosanrobotics.github.io/doosan-robotics-api-manual/GL013302/_sources/tutorials/scenarios/2_minimal_rt_monitoring_sample.rst.txt Initializes the connection to the robot controller using the specified IP address. Realtime monitoring is read-only and does not require control authority. ```cpp int main() { // Connect to the drcf controller. bool ret = robot.connect_rt_control(IP_ADDRESS); std::cout << "open connection return value " << ret << std::endl; if (true != ret) { std::cout << "Cannot open connection to robot @ " << IP_ADDRESS << std::endl; return 1; } // For rt-monitoring, we don't need to have "Getting control access". // however, for rt-writing like servoj_rt, we still need to have "control access" and "state standby". ``` -------------------------------- ### get_robot_link_info usage example Source: https://doosanrobotics.github.io/doosan-robotics-api-manual/GL013302/_sources/mode/common/kinematics_math/get_robot_link_info.rst.txt An example demonstrating how to request DH/link parameters and print them for each joint. ```cpp #include "DRFLEx.h" using namespace DRAFramework; int main() { CDRFLEx drfl; // Connect, select robot system, etc... (omitted) ROBOT_LINK_INFO link{}; if (drfl.get_robot_link_info(link, 500)) { // Example: iterate joints and print DH-like parameters if provided by your firmware for (int j = 0; j < NUMBER_OF_JOINT; ++j) { // NOTE: actual field names depend on ROBOT_LINK_INFO definition in your SDK // e.g., link._tLink[j]._fA, link._tLink[j]._fD, link._tLink[j]._fAlpha, link._tLink[j]._fTheta printf("[J%d] a=%.6f, d=%.6f, alpha=%.6f, theta=%.6f\n", j+1, link._tLink[j]._fA, link._tLink[j]._fD, link._tLink[j]._fAlpha, link._tLink[j]._fTheta); } } else { fprintf(stderr, "get_robot_link_info() failed (timeout or comm error)\n"); } return 0; } ``` -------------------------------- ### set_rt_control_input usage example Source: https://doosanrobotics.github.io/doosan-robotics-api-manual/GL013302/_sources/mode/rt/schema_version/set_rt_control_input.rst.txt An example demonstrating how to connect to real-time control and configure the input settings with a 1ms period and a loss tolerance of 4 packets. ```cpp #include "DRFLEx.h" #include using namespace DRAFramework; int main() { CDRFLEx drfl; // Connect and configure RT input data drfl.connect_rt_control("192.168.137.100", 12347); std::string version = "v1.0"; float period = 0.001f; // 1 msec = 1 kHz int lossCount = 4; if (drfl.set_rt_control_input(version, period, lossCount)) std::cout << "RT input configuration set successfully." << std::endl; else std::cout << "Failed to set RT input configuration." << std::endl; drfl.disconnect_rt_control(); return 0; } ``` -------------------------------- ### get_desired_velx usage example Source: https://doosanrobotics.github.io/doosan-robotics-api-manual/GL013302/_sources/mode/common/velocity/get_desired_velx.rst.txt Example demonstrating how to retrieve and print the desired TCP velocity values. ```cpp #include "DRFLEx.h" using namespace DRAFramework; int main() { CDRFLEx drfl; // Assume connection and robot mode setup are complete LPROBOT_VEL lpVel = drfl.get_desired_velx(); if (lpVel) { printf("Desired TCP Velocity (Targeted by Controller):\n"); printf("Linear [m/s]: vx=%.4f vy=%.4f vz=%.4f\n", lpVel->_fLinearVel[0], lpVel->_fLinearVel[1], lpVel->_fLinearVel[2]); printf("Angular [rad/s]: wx=%.4f wy=%.4f wz=%.4f\n", lpVel->_fAngularVel[0], lpVel->_fAngularVel[1], lpVel->_fAngularVel[2]); } else { fprintf(stderr, "Failed to retrieve desired velocity.\n"); } return 0; } ``` -------------------------------- ### get_last_alarm usage example Source: https://doosanrobotics.github.io/doosan-robotics-api-manual/GL013302/_sources/mode/common/report_alarm/get_last_alarm.rst.txt Example demonstrating how to retrieve the most recent alarm and print its details to the console. ```cpp LPLOG_ALARM pLogAlarm = Drfl.get_last_alarm(); switch(pLogAlarm->_iGroup) { case LOG_GROUP_SYSTEMFK: switch(pLogAlarm->_iLevel) { case LOG_LEVEL_SYSINFO: cout << "index(" << pLogAlarm->_iIndex << "), "; cout << "param(" << pLogAlarm->_szParam[0] << "), "; cout << "param(" << pLogAlarm->_szParam[1] << "), "; cout << "param(" << pLogAlarm->_szParam[2] << ")" << endl; break; default: break; } break; default: break; } ``` -------------------------------- ### jog Teach Workflow Example Source: https://doosanrobotics.github.io/doosan-robotics-api-manual/GL013302/_sources/mode/manual/jogging_motion_control/jog.rst.txt Demonstrates a teach workflow involving coarse approach, fine approach, and safety back-off movements. Each movement is sustained for a specific duration using thread sleep before being stopped with a zero velocity command. ```cpp #include "DRFLEx.h" #include #include using namespace DRAFramework; int main() { CDRFLEx drfl; // (Assume connection / mode / servo are already prepared in the sample environment) // 1) Coarse approach along BASE +X at 20% speed (hold-to-run style) drfl.jog(JOG_AXIS_TASK_X, MOVE_REFERENCE_BASE, 20.0f); std::this_thread::sleep_for(std::chrono::milliseconds(800)); // keep jogging for 0.8s drfl.jog(JOG_AXIS_TASK_X, MOVE_REFERENCE_BASE, 0.0f); // stop jogging // 2) Fine approach along TOOL -Z at 5% speed drfl.jog(JOG_AXIS_TASK_Z, MOVE_REFERENCE_TOOL, -5.0f); std::this_thread::sleep_for(std::chrono::milliseconds(600)); // creep closer drfl.jog(JOG_AXIS_TASK_Z, MOVE_REFERENCE_TOOL, 0.0f); // stop jogging // 3) Safety back-off along BASE -X at 10% speed, then stop drfl.jog(JOG_AXIS_TASK_X, MOVE_REFERENCE_BASE, -10.0f); std::this_thread::sleep_for(std::chrono::milliseconds(500)); drfl.jog(JOG_AXIS_TASK_X, MOVE_REFERENCE_BASE, 0.0f); return 0; } ``` -------------------------------- ### get_desired_posx usage example Source: https://doosanrobotics.github.io/doosan-robotics-api-manual/GL013302/_sources/mode/common/position/get_desired_posx.rst.txt Example demonstrating how to retrieve the target pose and iterate through the position values. ```cpp LPROBOT_POSE result = drfl.get_desired_posx(); for (int i = 0; i < NUM_TASK; i++) { cout << result->_fPosition[i] << endl; } ``` -------------------------------- ### set_on_disconnected Usage Example Source: https://doosanrobotics.github.io/doosan-robotics-api-manual/GL013302/_sources/mode/common/monitoring_callbacks/set_on_disconnected.rst.txt An example demonstrating how to define a callback function and register it using set_on_disconnected. ```cpp void OnDisconnectedCB() { // Needs the reconnection of the robot controller and error handling } int main() { drfl.set_on_disconnected(OnDisconnectedCB); } ``` -------------------------------- ### Step-by-step Manual Teaching with mwait Source: https://doosanrobotics.github.io/doosan-robotics-api-manual/GL013302/_sources/mode/manual/jogging_motion_control/mwait.rst.txt This example demonstrates using mwait() to synchronize motion steps, ensuring the robot has fully stopped after moves and jogs before proceeding to the next action. ```cpp #include "DRFLEx.h" #include using namespace DRAFramework; int main() { CDRFLEx drfl; // Assume connection, Manual mode, and servo ON are active. // 1) Move to an initial position float pose1[6] = {500.0f, 200.0f, 400.0f, 180.0f, 0.0f, 90.0f}; drfl.movel(pose1, 50, 50); drfl.mwait(); // wait until motion completes // 2) Perform a short jog for fine adjustment drfl.jog(JOG_AXIS_TASK_Z, MOVE_REFERENCE_TOOL, -5.0f); std::this_thread::sleep_for(std::chrono::milliseconds(500)); drfl.stop(STOP_TYPE_SLOW); drfl.mwait(); // ensure stable stop before the next move // 3) Proceed to next taught position float pose2[6] = {550.0f, 250.0f, 420.0f, 180.0f, 0.0f, 90.0f}; drfl.movel(pose2, 40, 40); drfl.mwait(); return 0; } ```