6.5 RT Tutorials
The Real-Time Tutorials section introduces the Doosan Robot API’s real-time control (RT) and monitoring features. This mode allows users to stream joint or task-space commands and receive real-time data through a dedicated UDP-based communication channel.
These examples demonstrate how to establish an RT connection, configure the transmission parameters, start and stop RT control, and process real-time feedback data.
Tutorial Flow
RT Connection Setup: Establish the real-time control link.
RT Output Configuration: Define the control frequency.
Start / Stop RT Control: Enable and disable real-time command streaming.
RT Data Monitoring: Retrieve and log real-time output data (position, velocity, torque).
Speed / Acceleration Limits (Extension): Set the velocity and acceleration values used by real-time commands.
Unified Safety Handling: Combine RT loop with safety stop and disconnection recovery.
RT Connection Setup
Purpose
Establish a dedicated UDP communication channel for real-time data exchange
between the robot controller and an external PC.
#include "DRFLEx.h"
#include <cstdio>
#include <atomic>
#include <thread>
#include <chrono>
using namespace DRAFramework;
CDRFLEx Drfl;
// Connect using default IP and port
Drfl.connect_rt_control();
// Alternatively, specify a custom host and port
// Drfl.connect_rt_control("192.168.137.100", 12348);
Check
The connection is established successfully without timeout,
and the controller responds with RT connection acknowledgment.
RT Output Configuration
Purpose
Define the update period for RT communication.
std::string version = "v1.0";
float period = 0.001f; // 1 ms update period
int loss_count = 4; // reserved, not used
Drfl.set_rt_control_output(version, period, loss_count);
Check
The robot accepts the configuration and prepares for RT command streaming.
Start / Stop RT Control
Purpose
Start and stop the real-time control loop for command transmission.
// Start streaming
Drfl.start_rt_control();
// Send RT commands and set_*_rt values here, while RT control is started
// End the RT session after use
Drfl.disconnect_rt_control();
// End the real-time session
Drfl.disconnect_rt_control();
Check
RT control starts successfully, and the robot transitions into real-time operation mode.
disconnect_rt_control() ends the real-time session and returns the controller to normal operation.
RT Data Monitoring
Purpose
Access and log real-time joint position, velocity, and torque data.
void OnRTMonitoringData(LPRT_OUTPUT_DATA_LIST tData) {
static int count = 0;
if (++count % 500 == 0) {
printf("timestamp: %.3f\n", tData->time_stamp);
printf("q = %.4f %.4f %.4f %.4f %.4f %.4f\n",
tData->actual_joint_position[0], tData->actual_joint_position[1],
tData->actual_joint_position[2], tData->actual_joint_position[3],
tData->actual_joint_position[4], tData->actual_joint_position[5]);
printf("q_dot = %.4f %.4f %.4f %.4f %.4f %.4f\n",
tData->actual_joint_velocity[0], tData->actual_joint_velocity[1],
tData->actual_joint_velocity[2], tData->actual_joint_velocity[3],
tData->actual_joint_velocity[4], tData->actual_joint_velocity[5]);
}
}
// Callback registration
Drfl.set_on_rt_monitoring_data(OnRTMonitoringData);
Check
RT callback outputs continuous joint position, velocity, and torque data at 1 ms intervals.
Speed / Acceleration Limits (Extension)
Purpose
Set the joint and task velocity and acceleration values used by real-time commands.
float vel[6] = {0.2, 0.0, 0.0, 0.0, 0.0, 0.0};
float acc[6] = {0.5, 0.5, 0.5, 0.5, 0.5, 0.5};
// Call after start_rt_control(); values sent before it are ignored
// Set joint velocity and acceleration in real-time
Drfl.set_velj_rt(vel);
Drfl.set_accj_rt(acc);
// Optional: Cartesian space velocity control
Drfl.set_velx_rt(0.2f, 0.2f);
Drfl.set_accx_rt(0.5f, 0.5f);
Check
The controller uses each value only while RT control is started, and each value has its own use, described on its page: set_velj_rt, set_accj_rt, set_velx_rt and set_accx_rt. set_velj_rt and set_accj_rt do not limit the servoj_rt trajectory; to cap joint speed, use the joint velocity limit of the safety settings.
Unified Safety Handling
Purpose
Integrate RT control with safety stop and reconnection logic for stable long-term operation.
std::atomic<bool> g_bDisconnected(false);
void OnDisconnected() {
// Record the event only; reconnect outside the callback
printf("[TCP] Disconnected from controller.\n");
g_bDisconnected = true;
}
std::atomic<int> g_nRecoverState(-1);
void OnMonitoringStateCB(const ROBOT_STATE eState) {
// Record the state only; recover outside the callback
if (eState == STATE_SAFE_STOP || eState == STATE_SAFE_OFF)
g_nRecoverState = (int)eState;
}
// Before the main loop
Drfl.set_on_disconnected(OnDisconnected);
Drfl.set_on_monitoring_state(OnMonitoringStateCB);
// In the main loop
if (g_bDisconnected.exchange(false)) {
printf("[TCP] Reconnecting...\n");
while (!Drfl.open_connection("192.168.137.100"))
std::this_thread::sleep_for(std::chrono::seconds(1));
// Callbacks other than the disconnect callback must be registered again
Drfl.set_on_monitoring_state(OnMonitoringStateCB);
}
int nState = g_nRecoverState.exchange(-1);
if (nState == STATE_SAFE_STOP || nState == STATE_SAFE_OFF) {
Drfl.stop_rt_control();
if (nState == STATE_SAFE_STOP)
Drfl.set_robot_control(CONTROL_RESET_SAFE_STOP);
else
Drfl.set_robot_control(CONTROL_SERVO_ON);
Drfl.start_rt_control();
}
Check
open_connection() restores the controller connection after a drop.
Re-establishing the real-time session requires restarting the application.
Call open_connection and set_robot_control outside the callbacks; see Rules for callback functions.
Note
Real-time control requires stable network conditions and a controller version that supports the UDP-based RT API.
Always verify connection using 6.2 Basic Tutorials and recovery logic from 6.3 Advanced Tutorials before running RT mode.