.. _read_data_rt: 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 :ref:`set_rt_control_output `. Typically used inside a **real-time loop** after :ref:`start_rt_control ` to continuously monitor joint positions, velocities, or external torques. **Definition** |br| ``DRFLEx.h`` within class `CDRFLEx`, public section .. code-block:: cpp LPRT_OUTPUT_DATA_LIST read_data_rt() { return _read_data_rt(_rbtCtrlUDP); }; **Parameter** |br| None **Return** .. list-table:: :widths: 25 75 :header-rows: 1 * - **Value** - **Description** * - LPRT_OUTPUT_DATA_LIST - Pointer to the structure containing all RT output data fields |br| defined by :ref:`get_rt_control_output_data_list `. **Example** .. code-block:: cpp #include #include #include 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 :ref:`start_rt_control`. - The returned pointer is never null, so a null check is not a validity test. |br| 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 ``memcpy`` or direct indexing to copy data safely inside the loop. - For visualization, store data into arrays or send to a logger in real time.