Skip to content

Core Interfaces and Data Types

The Sender class is responsible for sending joint control commands and mode switching commands to the robot via UDP.

Sender* send_cmd = new Sender("192.168.1.120", 43893); ///< Specify robot IP and port
void SendCmd(RobotCmd& robot_cmd); ///< Send 12-joint control command
void ControlGet(uint32_t mode); ///< Control switch: SDK(2) or ROBOT(1)
void RobotStateInit(void); ///< All joints return to zero and acquire control
void AllJointBackZero(void); ///< All joints return to zero
void SetCmd(uint32_t code, uint32_t value); ///< Send raw command code
ModeConstantDescription
SDK ControlSDK (value 2)SDK has control authority, can send joint commands
Robot ControlROBOT (value 1)Return control authority to the low-level controller

The Receiver class is responsible for receiving status data reported by the robot via UDP.

Receiver* robot_data_recv = new Receiver(); ///< Create receiver
robot_data_recv->StartWork(); ///< Start receiving thread
RobotData& data = robot_data_recv->GetState(); ///< Get latest state reference
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.

It is recommended to confirm receipt of robot data before sending control commands:

if (is_message_updated_) {
send_cmd->SendCmd(robot_joint_cmd);
}

DRTimer implements millisecond-level precision timing control based on Linux timerfd + epoll.

DRTimer set_timer;
set_timer.TimeInit(1); ///< Initialize, period 1ms
double start_time = set_timer.GetCurrentTime(); ///< Get current time
if (set_timer.TimerInterrupt() == true) { continue; } ///< Wait for timer interrupt
double now_time = set_timer.GetIntervalTime(start_time); ///< Get elapsed time (seconds)

All data types are defined in robot_types.h.

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;
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;
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²)
};
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;

The unified ordering of all 12 joints is:

IndexJoint NameLeg
0FL_HipXFront Left
1FL_HipYFront Left
2FL_KneeFront Left
3FR_HipXFront Right
4FR_HipYFront Right
5FR_KneeFront Right
6HL_HipXRear Left
7HL_HipYRear Left
8HL_KneeRear Left
9HR_HipXRear Right
10HR_HipYRear Right
11HR_KneeRear Right

Joints can also be accessed via leg structures:

robot_data->joint_data.fl_leg[3] ///< Front left leg 3 joints
robot_data->joint_data.fr_leg[3] ///< Front right leg 3 joints
robot_data->joint_data.hl_leg[3] ///< Rear left leg 3 joints
robot_data->joint_data.hr_leg[3] ///< Rear right leg 3 joints
robot_data->contact_force.fl_leg[] ///< Front left foot tip X/Y/Z tri-axial contact force
robot_data->contact_force.fr_leg[] ///< Front right foot tip X/Y/Z tri-axial contact force
robot_data->contact_force.hl_leg[] ///< Rear left foot tip X/Y/Z tri-axial contact force
robot_data->contact_force.hr_leg[] ///< Rear right foot tip X/Y/Z tri-axial contact force
robot_data->contact_force.leg_force[] ///< All 12-dimensional contact force

Tip: In most application scenarios, only the Z-direction contact force is used.