Core Interfaces and Data Types
Command Sending Interface
Section titled “Command Sending Interface”The Sender class is responsible for sending joint control commands and mode switching commands to the robot via UDP.
Construction Example
Section titled “Construction Example”Sender* send_cmd = new Sender("192.168.1.120", 43893); ///< Specify robot IP and portMain Interfaces
Section titled “Main Interfaces”void SendCmd(RobotCmd& robot_cmd); ///< Send 12-joint control commandvoid ControlGet(uint32_t mode); ///< Control switch: SDK(2) or ROBOT(1)void RobotStateInit(void); ///< All joints return to zero and acquire controlvoid AllJointBackZero(void); ///< All joints return to zerovoid SetCmd(uint32_t code, uint32_t value); ///< Send raw command codeControl Mode
Section titled “Control Mode”| Mode | Constant | Description |
|---|---|---|
| SDK Control | SDK (value 2) | SDK has control authority, can send joint commands |
| Robot Control | ROBOT (value 1) | Return control authority to the low-level controller |
Data Receiving Interface
Section titled “Data Receiving Interface”The Receiver class is responsible for receiving status data reported by the robot via UDP.
Construction and Start Example
Section titled “Construction and Start Example”Receiver* robot_data_recv = new Receiver(); ///< Create receiverrobot_data_recv->StartWork(); ///< Start receiving threadRobotData& data = robot_data_recv->GetState(); ///< Get latest state referenceCallback Registration Example
Section titled “Callback Registration Example”void OnMessageUpdate(uint32_t code) { if (code == 0x0906) { is_message_updated_ = true; ///< Mark that robot data has been received }}
robot_data_recv->RegisterCallBack(OnMessageUpdate);The callback function is invoked each time a robot data update is received. The parameter code value of 0x0906 indicates a joint data update event.
Safe Sending Protection
Section titled “Safe Sending Protection”It is recommended to confirm receipt of robot data before sending control commands:
if (is_message_updated_) { send_cmd->SendCmd(robot_joint_cmd);}High-Precision Timer Interface
Section titled “High-Precision Timer Interface”DRTimer implements millisecond-level precision timing control based on Linux timerfd + epoll.
Interface Example
Section titled “Interface Example”DRTimer set_timer;set_timer.TimeInit(1); ///< Initialize, period 1msdouble start_time = set_timer.GetCurrentTime(); ///< Get current timeif (set_timer.TimerInterrupt() == true) { continue; } ///< Wait for timer interruptdouble now_time = set_timer.GetIntervalTime(start_time); ///< Get elapsed time (seconds)Data Type Definitions
Section titled “Data Type Definitions”All data types are defined in robot_types.h.
Joint State Data (JointData)
Section titled “Joint State Data (JointData)”typedef struct { float position; ///< Joint position (unit: rad) float velocity; ///< Joint velocity (unit: rad/s) float torque; ///< Joint torque (unit: Nm) float temperature; ///< Motor temperature (unit: °C)} JointData;Joint Control Command (JointCmd)
Section titled “Joint Control Command (JointCmd)”typedef struct { float position; ///< Target position (unit: rad) float velocity; ///< Target velocity (unit: rad/s) float torque; ///< Feedforward torque (unit: Nm) float kp; ///< Position stiffness gain float kd; ///< Velocity damping gain} JointCmd;IMU Data (ImuData)
Section titled “IMU Data (ImuData)”struct ImuData { int32_t timestamp; ///< Timestamp (ms) float angle_roll; ///< Roll angle (°) float angle_pitch; ///< Pitch angle (°) float angle_yaw; ///< Yaw angle (°) float angular_velocity_roll; ///< Roll angular velocity (°/s) float angular_velocity_pitch; ///< Pitch angular velocity (°/s) float angular_velocity_yaw; ///< Yaw angular velocity (°/s) float acc_x; ///< X-axis acceleration (m/s²) float acc_y; ///< Y-axis acceleration (m/s²) float acc_z; ///< Z-axis acceleration (m/s²)};Robot Comprehensive Data (RobotData)
Section titled “Robot Comprehensive Data (RobotData)”typedef struct { uint32_t tick; ///< Running period count ImuData imu; ///< IMU data LegData joint_data; ///< 12-joint state data ContactForce contact_force; ///< Quadruped contact force data} RobotData;Joint Ordering
Section titled “Joint Ordering”The unified ordering of all 12 joints is:
| Index | Joint Name | Leg |
|---|---|---|
| 0 | FL_HipX | Front Left |
| 1 | FL_HipY | Front Left |
| 2 | FL_Knee | Front Left |
| 3 | FR_HipX | Front Right |
| 4 | FR_HipY | Front Right |
| 5 | FR_Knee | Front Right |
| 6 | HL_HipX | Rear Left |
| 7 | HL_HipY | Rear Left |
| 8 | HL_Knee | Rear Left |
| 9 | HR_HipX | Rear Right |
| 10 | HR_HipY | Rear Right |
| 11 | HR_Knee | Rear Right |
Joints can also be accessed via leg structures:
robot_data->joint_data.fl_leg[3] ///< Front left leg 3 jointsrobot_data->joint_data.fr_leg[3] ///< Front right leg 3 jointsrobot_data->joint_data.hl_leg[3] ///< Rear left leg 3 jointsrobot_data->joint_data.hr_leg[3] ///< Rear right leg 3 jointsContact Force Data
Section titled “Contact Force Data”robot_data->contact_force.fl_leg[] ///< Front left foot tip X/Y/Z tri-axial contact forcerobot_data->contact_force.fr_leg[] ///< Front right foot tip X/Y/Z tri-axial contact forcerobot_data->contact_force.hl_leg[] ///< Rear left foot tip X/Y/Z tri-axial contact forcerobot_data->contact_force.hr_leg[] ///< Rear right foot tip X/Y/Z tri-axial contact forcerobot_data->contact_force.leg_force[] ///< All 12-dimensional contact forceTip: In most application scenarios, only the Z-direction contact force is used.