Head and Hand Control
The KUAVO Humanoid WebSocket SDK provides comprehensive head and hand control interfaces, supporting robot head motion control, arm motion control, and operation of different types of robotic hands (such as LejuClaw and DexterousHand). This document describes in detail how to use these control interfaces.
Interface Description
Head Control Interface
KuavoRobotHead
The KuavoRobotHead class provides interfaces for controlling robot head motion.
The main interfaces are described below:
| Function Name | control_head |
|---|---|
| Function Prototype | bool control_head(float yaw, float pitch) |
| Functional Overview | Controls the yaw and pitch angles of the robot head. |
| Parameters | yaw: Head horizontal rotation angle, range [-1.396, 1.396] radians (approximately -80° to 80°) pitch: Head pitch angle, range [-0.436, 0.436] radians (approximately -25° to 25°) |
| Return Value | true: Control succeeded false: Control failed |
| Remarks | The angle unit is radians; values outside the range are automatically clamped to the valid range |
Arm Control Interface
KuavoRobotArm
The KuavoRobotArm class provides interfaces for controlling the robot arm.
The main interfaces are described below:
| Function Name | control_arm_joint_positions |
|---|---|
| Function Prototype | bool control_arm_joint_positions(list joint_positions) |
| Functional Overview | Controls the robot arm joint positions. |
| Parameters | joint_positions: List of target joint positions, in radians, with a length equal to the number of arm joints (14 joints) |
| Return Value | true: Control succeeded false: Control failed |
| Remarks | 1. The joint angle range must be [-π, π] radians 2. The robot must be in a standing state 3. The arm must be in external control mode |
| Function Name | arm_fk |
|---|---|
| Function Prototype | Tuple[KuavoPose, KuavoPose] arm_fk(list q) |
| Functional Overview | Computes the forward kinematics of the robot arm. |
| Parameters | q: List of joint positions, in radians |
| Return Value | A tuple of poses of the left and right arm end effectors; returns (None, None) if the computation fails |
| Remarks | The returned KuavoPose contains position and orientation information |
| Function Name | control_arm_joint_trajectory |
|---|---|
| Function Prototype | bool control_arm_joint_trajectory(list times, list joint_q) |
| Functional Overview | Controls the robot arm joint trajectory. |
| Parameters | times: List of time points, in seconds joint_q: List of joint positions, one set of joint positions per time point, in radians |
| Return Value | true: Control succeeded false: Control failed |
| Remarks | 1. times and joint_q must have the same length 2. The joint angle range must be [-π, π] radians 3. The robot must be in a standing state 4. The arm must be in external control mode |
| Function Name | arm_ik |
|---|---|
| Function Prototype | list arm_ik(KuavoPose left_pose, KuavoPose right_pose, list left_elbow_pos_xyz=[0.0, |
| 0.0, 0.0], list right_elbow_pos_xyz=[0.0, 0.0, 0.0], list arm_q0=None, KuavoIKParams | |
| params=None) | |
| Functional Overview | Computes the inverse kinematics of the robot arm. |
| Parameters | left_pose: Target pose of the left arm right_pose: Target pose of the right arm left_elbow_pos_xyz: Left elbow position<br/ |
| right_elbow_pos_xyz: Right elbow position arm_q0: Initial joint positions params: Inverse kinematics parameters | |
| Return Value | List of joint positions; returns None if the computation fails |
| Remarks | The computation accuracy and constraints can be adjusted via the params parameter |
| Function Name | control_robot_end_effector_pose |
|---|---|
| Function Prototype | bool control_robot_end_effector_pose(KuavoPose left_pose, KuavoPose right_pose, KuavoManipulationMpcFrame frame) |
| Functional Overview | Controls the pose of the robot arm end effectors. |
| Parameters | left_pose: Target pose of the left arm right_pose: Target pose of the right arm frame: Control coordinate frame |
| Return Value | true: Control succeeded false: Control failed |
| Function Name | set_fixed_arm_mode |
|---|---|
| Function Prototype | bool set_fixed_arm_mode() |
| Functional Overview | Sets the arm to fixed mode. |
| Return Value | true: Set successfully false: Failed to set |
| Remarks | In fixed mode, the arm stays at its current position without moving |
| Function Name | set_auto_swing_arm_mode |
|---|---|
| Function Prototype | bool set_auto_swing_arm_mode() |
| Functional Overview | Sets the arm to auto-swing mode. |
| Return Value | true: Set successfully false: Failed to set |
| Remarks | In auto-swing mode, the arm swings automatically with the gait |
| Function Name | set_external_control_arm_mode |
|---|---|
| Function Prototype | bool set_external_control_arm_mode() |
| Functional Overview | Sets the arm to external control mode. |
| Return Value | true: Set successfully false: Failed to set |
| Remarks | In external control mode, the arm can be controlled through interfaces such as control_arm_joint_positions |
| Function Name | arm_reset |
|---|---|
| Function Prototype | bool arm_reset() |
| Functional Overview | Resets the arm to the default position. |
| Return Value | true: Reset succeeded false: Reset failed |
| Remarks | Typically used to initialize the arm position |
Hand Control Interface
The KUAVO Humanoid SDK supports two types of robotic hands:
- LejuClaw - Simple gripper
- DexterousHand - Dexterous hand
LejuClaw Interface
The LejuClaw class provides the following main interfaces:
| Function Name | open |
|---|---|
| Function Prototype | bool open(EndEffectorSide side = EndEffectorSide.BOTH) |
| Functional Overview | Opens the gripper. |
| Parameters | side: Which side's gripper to control; options: - LEFT: Left hand - RIGHT: Right hand - BOTH: Both hands (default) |
| Return Value | true: Control succeeded false: Control failed |
| Remarks | After calling, you can use wait_for_finish() to wait for the action to complete |
| Function Name | close |
|---|---|
| Function Prototype | bool close(EndEffectorSide side = EndEffectorSide.BOTH) |
| Functional Overview | Closes the gripper. |
| Parameters | side: Which side's gripper to control; options are the same as open |
| Return Value | true: Control succeeded false: Control failed |
| Remarks | After calling, you can use wait_for_finish() to wait for the action to complete |
| Function Name | control |
|---|---|
| Function Prototype | bool control(list target_positions, list target_velocities = None, list target_torques = None) |
| Functional Overview | Controls the position, velocity, and torque of the gripper. |
| Parameters | target_positions: List of target positions, length 2 (one value for each hand), range [0.0 ~ 100.0] target_velocities: List of target velocities, length 2; if None, the default [90, 90] is used target_torques: List of target torques, length 2; if None, the default [1.0, 1.0] is used |
| Return Value | true: Control succeeded false: Control failed |
| Remarks | 1. After calling, you can use wait_for_finish() to wait for the action to complete 2. If the gripper is still executing the previous action, the new request may be discarded |
| Function Name | control_left |
|---|---|
| Function Prototype | bool control_left(list target_positions, list target_velocities = None, list target_torques = None) |
| Functional Overview | Controls the position, velocity, and torque of the left gripper. |
| Parameters | target_positions: List of target positions, length 1, range [0.0 ~ 100.0] target_velocities: List of target velocities, length 1; if None, the default 90 is used target_torques: List of target torques, length 1; if None, the default 1.0 is used |
| Return Value | true: Control succeeded false: Control failed |
| Remarks | 1. After calling, you can use wait_for_finish() to wait for the action to complete 2. If the gripper is still executing the previous action, the new request may be discarded |
| Function Name | control_right |
|---|---|
| Function Prototype | bool control_right(list target_positions, list target_velocities = None, list target_torques = None) |
| Functional Overview | Controls the position, velocity, and torque of the right gripper. |
| Parameters | target_positions: List of target positions, length 1, range [0.0 ~ 100.0] target_velocities: List of target velocities, length 1; if None, the default 90 is used target_torques: List of target torques, length 1; if None, the default 1.0 is used |
| Return Value | true: Control succeeded false: Control failed |
| Remarks | 1. After calling, you can use wait_for_finish() to wait for the action to complete 2. If the gripper is still executing the previous action, the new request may be discarded |
DexterousHand Interface
The DexterousHand class provides the following main interfaces:
| Function Name | control |
|---|---|
| Function Prototype | bool control(list target_positions, list target_velocities = None, list target_torques = None) |
| Functional Overview | Controls the joint positions of the dexterous hand. |
| Parameters | target_positions: List of target positions, length 12 (6 joints per hand), range [0.0 ~ 100.0] target_velocities: Not supported yet target_torques: Not supported yet |
| Return Value | true: Control succeeded false: Control failed |
| Remarks | Only position control is supported |
| Function Name | control_left |
| ------- | ------------- |
| Function Prototype | bool control_left(list target_positions, list target_velocities = None, list target_torques = None) |
| Functional Overview | Controls the joint positions of the left dexterous hand |
| Parameters | target_positions: List of target positions, length 6 (6 joints of the left hand), range [0.0 ~ 100.0] target_velocities: Not supported yet target_torques: Not supported yet |
| Return Value | true: Control succeeded false: Control failed |
| Function Name | control_right |
|---|---|
| Function Prototype | bool control_right(list target_positions, list target_velocities = None, list target_torques = None) |
| Functional Overview | Controls the joint positions of the right dexterous hand |
| Parameters | target_positions: List of target positions, length 6 (6 joints of the right hand), range [0.0 ~ 100.0] target_velocities: Not supported yet target_torques: Not supported yet |
| Return Value | true: Control succeeded false: Control failed |
| Function Name | make_gesture |
|---|---|
| Function Prototype | bool make_gesture(str l_gesture_name, str r_gesture_name) |
| Functional Overview | Controls the dexterous hand to make predefined gestures. |
| Parameters | l_gesture_name: Name of the left-hand gesture r_gesture_name: Name of the right-hand gesture |
| Return Value | true: Control succeeded false: Control failed |
| Remarks | Supported gestures include: 'fist', 'ok', 'thumbs_up', '666', 'number_1', etc. |
Examples
Refer to the SDK example code:
Head control: /home/lab/kuavo-ros-opensource/src/kuavo_humanoid_websocket_sdk/examples/atomic_skills/ctrl_head_example.py
Demonstrates how to control the pitch and yaw angles of the robot head through the SDK to achieve up-and-down and left-and-right head movements.
The example code demonstrates two motion modes:
-
Head nodding up and down:
- Starts at 0 degrees, first rotates down to -25 degrees
- Then rotates up from -25 degrees to 25 degrees
- Finally returns from 25 degrees to 0 degrees
- Repeated for 2 cycles
-
Head shaking left and right:
- Starts at 0 degrees, first rotates left to 60 degrees
- Then rotates right from 60 degrees to -60 degrees
- Finally returns from -60 degrees to 0 degrees
- Repeated for 2 cycles
Each movement changes in small angle increments (2 degrees) with a 0.1-second interval to achieve smooth motion.
Arm control: /home/lab/kuavo-ros-opensource/src/kuavo_humanoid_websocket_sdk/examples/atomic_skills/ctrl_arm_example.py
Shows examples of arm trajectory control and target pose control.
It covers various arm operation methods such as joint angle interpolation motion, joint trajectory control, and end effector pose control, and is suitable for testing the arm's basic motions, trajectory tracking, and end effector control capabilities.
The example code contains three main control functions:
-
control_arm_traj(): Joint angle interpolation motion
- Starts from the initial position q0 and moves to the target position q1 through 90 interpolation steps
- q1 defines a pose with the right arm raised 50 degrees
- 0.02 seconds between each step for a smooth transition
- Returns to the initial position after the motion completes
- Finally resets the arm position
-
control_arm_joint_trajectory(): Joint trajectory control
- Defines target poses at 7 key time points
- The robot automatically performs trajectory planning between keyframes
- Resets the arm position after execution
-
control_arm_end_effector_pose(): End effector pose control
- Directly specifies the target position and orientation of the left and right end effectors in the world coordinate system
- Automatically computes the required joint angles via inverse kinematics
- The robot automatically plans a trajectory to reach the target pose
- Resets the arm position when done
Gripper control: /home/lab/kuavo-ros-opensource/src/kuavo_humanoid_websocket_sdk/examples/atomic_skills/lejuclaw_example.py
Demonstrates how to control the LejuClaw gripper end effector, including position, velocity, and torque control.
It supports various operations such as overall open/close, single-side control, and target position setting, implemented through interfaces such as claw.open(), claw.close(), claw.control_left(), claw.control_right(), and claw.control().
The example code demonstrates the following main functions:
-
Basic open/close control:
claw.close()fully closes the gripperclaw.open()fully opens the gripper- After each action, use
wait_for_finish()to wait for the action to complete
-
Single-side gripper control:
claw.control_left([50])controls the left gripper to the 50-degree positionclaw.control_right([80])controls the right gripper to the 80-degree position- The positions of the left and right grippers can be precisely controlled separately
-
Dual-side synchronous control:
claw.control([20, 100])controls the left and right grippers to different positions simultaneously- The first parameter controls the left side, the second parameter controls the right side
- The position range is 0-100 degrees; 0 means fully closed, 100 means fully open
Notes:
- It is recommended to call
wait_for_finish()after each action to wait for completion and avoid stacking actions - A timeout can be set, e.g.
wait_for_finish(timeout=2.0) - When sending commands consecutively, be sure to wait for the previous action to complete, otherwise they may be discarded
Dexterous hand control: /home/lab/kuavo-ros-opensource/src/kuavo_humanoid_websocket_sdk/examples/atomic_skills/dexhand_example.py
Demonstrates how to control the basic motions and preset gestures of the dexterous hand.
It supports single-side control, dual-side synchronous control, preset gesture invocation, and other functions. The example code demonstrates:
- Single-side finger control:
- The left hand makes a "thumbs up" gesture
- The right hand makes a "666" gesture
- Preset gesture invocation:
- Get the names of all supported gestures
- Invoke preset gestures (such as the "thumbs up" and "OK" gestures)