User Input and Communication Interface
1. Overview
Section titled “1. Overview”The DR02 Pro SDK provides multiple user input methods, including keyboard, gamepad, and velocity command topics, all handled uniformly by UserCommandInterface.
2. Developer Modes
Section titled “2. Developer Modes”The DR02 Pro supports three developer modes. The SDK requires entering the corresponding mode via the gamepad before running:
| Developer Mode | Control Scope |
|---|---|
| High-Level Motion Control Mode | SDK controls motion via high-level commands such as /MOTION_STATE, /GAIT, /STEER |
| Full-Body Joint Control Mode | SDK directly controls all 31 joints via /JOINTS_CMD |
| Upper-Body Joint Control Mode | SDK controls waist and dual arms via /JOINTS_CMD; legs are controlled by the robot’s internal policy |
Important: Only one publisher is allowed for
/JOINTS_CMDat a time. Do not run other joint command publishers while the state machine is running.
3. User Command Interface
Section titled “3. User Command Interface”3.1 Function Description
Section titled “3.1 Function Description”The user command interface UserCommandInterface uniformly handles multiple input sources:
- Subscribe to
/GAMEPAD_KEYto receive gamepad button events - Subscribe to
/STEERto receive normalized velocity commands - Subscribe to
/REAL_STEERto receive actual velocity commands - Run
KeyboardLoopin an independent thread for keyboard input handling
3.2 UserCommand Structure
Section titled “3.2 UserCommand Structure”struct UserCommand { double time_stamp; // Timestamp int safe_control_mode; // Safety control mode (0=normal) uint8_t target_mode; // Target motion state float forward_vel_scale; // Forward velocity ratio float side_vel_scale; // Lateral velocity ratio float turning_vel_scale; // Rotational velocity ratio};4. Control Methods
Section titled “4. Control Methods”4.1 Keyboard Control
Section titled “4.1 Keyboard Control”| Key | Function | Applicable State |
|---|---|---|
z | Enter ZeroPos | Idle |
c | Enter RLControl | ZeroPos |
r | Enter JointDamping | Any |
w/s | Forward / Backward | RLControl |
a/d | Left / Right | RLControl |
q/e | Turn Left / Right | RLControl |
Keyboard velocity commands are fixed normalized values of 0.70, and auto-return to zero approximately 320ms after key release.
4.2 Gamepad Control
Section titled “4.2 Gamepad Control”| Button | Function |
|---|---|
| L1 | Enter ZeroPos (only valid in Idle state) |
| L2 | Enter RLControl (only valid in ZeroPos state) |
| R2 | Enter JointDamping |
| Left Stick | Forward / Left / Backward / Right |
| Right Stick | Rotation |
Gamepad button events are transmitted via the /GAMEPAD_KEY topic (string messages, e.g., G20_KEY_L1).
4.3 Velocity Command Interface
Section titled “4.3 Velocity Command Interface”The state machine subscribes to two velocity command topics simultaneously:
| Topic | Description | Input Range |
|---|---|---|
/STEER | Normalized velocity command | [-1.0, 1.0] |
/REAL_STEER | Actual velocity command | Auto-normalized internally (x/1.0, y/0.75, yaw/2.25) |
5. Usage Examples
Section titled “5. Usage Examples”5.1 Gamepad Button Subscription
Section titled “5.1 Gamepad Button Subscription”// Subscribe to gamepad button eventsauto gamepad_sub = node->create_subscription<std_msgs::msg::String>( "/GAMEPAD_KEY", 10, [](const std_msgs::msg::String::SharedPtr msg) { RCLCPP_INFO(node->get_logger(), "Gamepad key: %s", msg->data.c_str());
// Execute corresponding action based on button type if (msg->data == "G20_KEY_L1") { // L1 pressed, can trigger ZeroPos state } else if (msg->data == "G20_KEY_L2") { // L2 pressed, can trigger RLControl state } });5.2 Velocity Command Publishing
Section titled “5.2 Velocity Command Publishing”// Publish normalized velocity commandauto steer_pub = node->create_publisher<drdds::msg::Steer>( "/STEER", 10);
// Construct velocity commanddrdds::msg::Steer steer_cmd;steer_cmd.x = 0.5f; // Forward 50% velocitysteer_cmd.y = 0.0f; // No lateral movementsteer_cmd.z = 0.0f; // No vertical movementsteer_cmd.roll = 0.0f; // No rollsteer_cmd.pitch = 0.0f; // No pitchsteer_cmd.yaw = 0.3f; // Right turn 30% angular velocity
// Publish command (recommended 20Hz frequency)steer_pub->publish(steer_cmd);5.3 Actual Velocity Command Publishing
Section titled “5.3 Actual Velocity Command Publishing”// Publish actual velocity command (with units)auto real_steer_pub = node->create_publisher<drdds::msg::Steer>( "/REAL_STEER", 10);
drdds::msg::Steer real_cmd;real_cmd.x = 0.5f; // Forward 0.5 m/sreal_cmd.y = 0.3f; // Left 0.3 m/sreal_cmd.yaw = 0.5f; // Rotation 0.5 rad/s
real_steer_pub->publish(real_cmd);6. Safety Protection Mechanisms
Section titled “6. Safety Protection Mechanisms”6.1 SafeController Monitoring
Section titled “6.1 SafeController Monitoring”SafeController runs in an independent thread with a 2ms cycle, monitoring the following anomalies:
| Detection Item | Method | Trigger Condition | safe_control_mode |
|---|---|---|---|
| Joint Data Anomaly | IsJointDataNormal() | NaN values / Timeout 30ms / Data unchanged for 100 cycles | 3 |
| Motor Over-Temperature | IsMotorTemperatureNormal() | Temperature > 110°C | 2 |
| IMU Data Anomaly | IsImuDataNormal() | NaN / Timeout 40ms | 4 |
6.2 Error State Codes
Section titled “6.2 Error State Codes”union RobotErrorState { struct { uint32_t imu_num_error : 1; // IMU value anomaly uint32_t imu_update_overtime : 1; // IMU update timeout uint32_t motor_heat_warn : 1; // Motor over-temperature uint32_t joint_num_error : 1; // Joint value anomaly uint32_t joint_update_error : 1; // Joint update timeout uint32_t reserved : 26; }; uint32_t error_code;};6.3 Emergency Stop Mechanism
Section titled “6.3 Emergency Stop Mechanism”Important: The DR02 Pro currently does not implement a cross-process emergency stop mechanism (e.g., /EMERGENCY_STOP_SIGNAL).
The DR02 Pro emergency stop relies only on the following methods:
-
Gamepad Red Stop Button (Recommended)
- In case of anomaly, press the red button on the gamepad to directly disconnect the control signal
- The robot’s low-level controller enters a protective state upon receiving the signal
-
safe_control_modeSafety Degradation- SafeController sets
safe_control_mode != 0when an anomaly is detected - Next cycle automatically switches to
JointDampingstate (full-body pure damping) - Returns to
Idlestate after 3 seconds
- SafeController sets
-
Ctrl+C Soft Termination
- Press Ctrl+C in the terminal to stop the SDK program
- After state machine exit,
/JOINTS_CMDis no longer published; the robot may fall due to loss of support - Only applicable in simulation environments or scenarios requiring immediate power-off
[!WARNING]
When operating the real robot, the gamepad red stop button should be the primary method for emergency stopping.