read_data_rt
This function reads the real-time output data from the robot controller. It retrieves the latest output structure containing motion, torque, and system states configured by set_rt_control_output.
Typically used inside a real-time loop after start_rt_control to continuously monitor joint positions, velocities, or external torques.
Definition
DRFLEx.h within class CDRFLEx, public section
LPRT_OUTPUT_DATA_LIST read_data_rt() {
return _read_data_rt(_rbtCtrlUDP);
};
Parameter
None
Return
Value |
Description |
|---|---|
LPRT_OUTPUT_DATA_LIST |
Pointer to the structure containing all RT output data fields |
Example
#include <chrono>
#include <cstring>
#include <thread>
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) {
// Copy the whole frame in one operation. Copying field by field leaves
// the buffer free to be overwritten between copies, so the fields can
// come from different frames.
RT_OUTPUT_DATA_LIST frame;
memcpy(&frame, drfl.read_data_rt(), sizeof(frame));
printf("Joint 1 Pos: %.1f Vel: %.1f Torque: %.1f\n",
frame.actual_joint_position[0],
frame.actual_joint_velocity[0],
frame.actual_joint_torque[0]);
// Custom condition to break the loop
if (frame.actual_joint_position[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();
In this example, the function continuously retrieves and prints the current joint position, velocity, and torque from the real-time stream.
Tips
Always call this function after RT streaming is started using start_rt_control.
The returned pointer is never null, so a null check is not a validity test.
The buffer it refers to is overwritten as new frames arrive, so a frame read field by field can mix values from two packets. Copy the whole structure in one operation, as the example does, and work from the copy.Use
memcpyor direct indexing to copy data safely inside the loop.For visualization, store data into arrays or send to a logger in real time.