Arm Trajectory Planning Example
- Arm Trajectory Planning Example
1. Description
- This document describes the implementation used to plan arm joint state trajectories for a humanoid robot.
- The example code is located at
/home/lab/kuavo-ros-opensource/src/demo/examples_code/hand_plan_arm_trajectory - Two interpolation methods are currently provided for arm joint state trajectory planning:
- Cubic spline interpolator (
plan_arm_traj_cubicspline_demo.py) - Bezier curve interpolator (
plan_arm_traj_bezier_demo.py)
- Cubic spline interpolator (
2. Build and Launch
2.1 Build
cd /home/lab/kuavo-ros-opensource #仓库目录
sudo su
catkin build kuavo_sdk humanoid_plan_arm_trajectory2.2 Launch Parameters
The following optional parameters are available when launching the trajectory planning module:
joint_state_topic: Name of the topic on which joint states are published; the default iskuavo_arm_trajjoint_state_unit: Unit of the joint angles;radordeg; the default isdeguse_nodelet: Whether to launch as a nodelet; the default isfalse
2.3 Launch Example
Before launching the scripts, you need to start the humanoid_plan_arm_trajectory.launch file first:
- Note: On some versions, the trajectory planning service starts automatically when the robot starts, so be careful not to start it twice
- How to check: enter
rosnode list | grep trajectoryin a terminal - If
/humanoid_plan_arm_trajectory_nodealready exists, skip this step - If
/humanoid_plan_arm_trajectory_nodedoes not exist, run:cd kuavo-ros-opensource # 进入下位机工作空间 sudo su source devel/setup.bash # 仿真 roslaunch humanoid_controllers load_kuavo_mujoco_sim.launch joystick_type:=sim # 启动rl控制器、wbc、仿真器(默认 sim_input_mode:=keyboard)。 # 如需 GUI 虚拟手柄输入: # roslaunch humanoid_controllers load_kuavo_mujoco_sim.launch joystick_type:=sim sim_input_mode:=gui # 实物 roslaunch humanoid_controllers load_kuavo_real.launch joystick_type:=h12 # 启动对应节点 roslaunch humanoid_plan_arm_trajectory humanoid_plan_arm_trajectory.launch
Open a new terminal to launch the script: cubic spline method
cd kuavo-ros-opensource
sudo su
source devel/setup.bash
cd src/demo/examples_code/hand_plan_arm_trajectory # 示例脚本路径
python3 plan_arm_traj_cubicspline_demo.pyThe result is shown below:

Open a new terminal to launch the script: Bezier curve method
cd kuavo-ros-opensource
sudo su
source devel/setup.bash
cd src/demo/examples_code/hand_plan_arm_trajectory # 示例脚本路径
python3 plan_arm_traj_bezier_demo.pyThe result is shown below:

3. ROS Interfaces
3.1 Topics
Published Topics
/<interpolate_type>/arm_traj
Topic description: publishes the planned arm trajectory
Message type: trajectory_msgs/JointTrajectory
| Field | Type | Description |
|---|---|---|
| header | std_msgs/Header | Message header |
| joint_names | string[] | Array of joint names |
| points | JointTrajectoryPoint[] | Array of trajectory points; only points[0] contains the latest joint values |
/<interpolate_type>/arm_traj_state
Topic description: publishes the trajectory execution state
Message type: humanoid_plan_arm_trajectory/planArmState
| Field | Type | Description |
|---|---|---|
| progress | int32 | Trajectory execution progress, in milliseconds |
| is_finished | bool | Whether the trajectory has finished executing |
/kuavo_arm_traj
Topic description: controls the hand joint positions
Message type: sensor_msgs/JointState
| Field | Type | Description |
|---|---|---|
| header | std_msgs/Header | Message header |
| name | string[] | Joint names |
| position | float64[] | Joint positions |
| velocity | float64[] | Joint velocities |
| effort | float64[] | Joint effort (unused) |
3.2 Services
/<interpolate_type>/plan_arm_trajectory
Service description: trajectory planning service
<interpolate_type> can be:
bezier: Bezier curve interpolationcubic_spline: Cubic spline interpolation
Bezier Curve Interpolation Service
Message type: humanoid_plan_arm_trajectory/planArmTrajectoryBezierCurve
Request parameters:
| Field | Type | Description |
|---|---|---|
| multi_joint_bezier_trajectory | jointBezierTrajectory[] | Array of Bezier trajectories for multiple joints |
| start_frame_time | float64 | Start time of the trajectory, in seconds |
| end_frame_time | float64 | End time of the trajectory, in seconds |
| joint_names | string[] | Array of joint names |
Return result:
| Field | Type | Description |
|---|---|---|
| success | bool | Whether planning succeeded |
Cubic Spline Interpolation Service
Message type: humanoid_plan_arm_trajectory/planArmTrajectoryCubicSpline
Request parameters:
| Field | Type | Description |
|---|---|---|
| joint_trajectory | trajectory_msgs/JointTrajectory | Joint trajectory specification |
Return result:
| Field | Type | Description |
|---|---|---|
| success | bool | Whether planning succeeded |
/<interpolate_type>/stop_plan_arm_trajectory
Service description: service for stopping trajectory execution
Message type: std_srvs/Trigger
4. Usage Guide
4.1 Cubic Spline Interpolator
4.1.1 Overview
plan_arm_traj_cubicspline_demo.py uses the cubic spline interpolator to plan the robot's arm trajectory.
4.1.2 Main Steps
-
Initialize the node and services:
- Initialize the ROS node
arm_trajectory_cubicspline_demo - Subscribe to the
/cubic_spline/arm_trajtopic - Publish to the
/kuavo_arm_trajtopic
- Initialize the ROS node
-
Service calls:
- Set the arm control mode
- Use the trajectory planning service
-
Trajectory planning:
- Define joint positions and time points
- Use the current joint state as the starting point
- Send the trajectory request
4.1.3 Notes
- Make sure all services and topics are configured correctly
- Make sure the
mpc_observationmessage is available
4.2 Bezier Curve Interpolator
4.2.1 Overview
plan_arm_traj_bezier_demo.py uses the Bezier curve interpolator to plan the robot's arm trajectory.
4.2.2 Main Steps
-
Initialize the node and services:
- Initialize the ROS node
arm_trajectory_bezier_demo - Subscribe to the
/bezier/arm_trajtopic - Publish to the
/kuavo_arm_trajtopic
- Initialize the ROS node
-
Service calls:
- Set the arm control mode
- Use the trajectory planning service
-
Trajectory planning:
- Read the JSON action data
- Define the Bezier curve control points
- Send the trajectory request
4.2.3 Notes
- Make sure all services and topics are configured correctly
- Make sure the JSON file path is correct and the data is valid
5. Additional Notes
5.1 TACT File Format
5.1.1 Overview
-
TACT files are used to edit the joint motions of Kuavo's head, arms, and fingers. The file contents are stored and organized in JSON format.
-
TACT files can be exported through the hand motion editing software (User Manual); welcome.tact is the welcome motion and is placed in the action_files folder in the same directory.
-
Users can define custom motion frames for the Bezier curve interpolator; for details, refer to plan_arm_traj_bezier_no_tact_demo.py
5.1.2 Main Fields
-
Top-level structure
Key Type Description frameslist Each item is the data for one time point, containing all joint data required by the Bezier curve interpolator musicslist Music data finishint Motion end time, in milliseconds firstint Motion start time, in milliseconds versionstr Version number of the .tactfile, e.g."1.0.0" -
frames
Key Type Description servoslist Each element corresponds to the angle of a specific joint in Kuavo (mapping table) keyframeint Time point of the keyframe, in milliseconds attributedict Contains the Bezier curve control point configuration for all joints, in one-to-one correspondence with each joint in servos; the key is the joint number, and the data holds the parameters used to adjust the shape of the Bezier curve -
attribute
Key Type Description CPlist List of control point coordinates, containing the data of the left control point and the right control point; a control point is defined as [time offset, angle offset], and its length matches that ofCPTypeCPTypelist Control point types, with the same length as CP, corresponding to the left control point and the right control point respectively; can beAUTOorMANUALselectbool Not used in the Bezier curve interpolator
5.1.3 Example
{
"frames": [
{
"servos": [20, 0, 0, -30, 15, -10, 0, 0, 5, -5, 10, 0, -5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
"keyframe": 50,
"attribute": {
"1": {
"CP": [[0, 0], [21, 0]],
"CPType": ["AUTO", "AUTO"],
"select": false
},
"2": {
"CP": [[10, 10], [20, 20]],
"CPType": ["MANUAL", "AUTO"],
"select": true
},
"3": {
...
},
...
}
},
{
...
},
...
],
"musics": [],
"finish": 500,
"first": 0,
"version": "1.0.0"
}5.1.4 Notes
- Each element in the "servos" field corresponds to the name of a Kuavo joint
| Index | Joint Name |
|---|---|
| 0 | l_arm_pitch |
| 1 | l_arm_roll |
| 2 | l_arm_yaw |
| 3 | l_forearm |
| 4 | l_hand_yaw |
| 5 | l_hand_pitch |
| 6 | l_hand_roll |
| 7 | r_arm_pitch |
| 8 | r_arm_roll |
| 9 | r_arm_yaw |
| 10 | r_forearm |
| 11 | r_hand_yaw |
| 12 | r_hand_pitch |
| 13 | r_hand_roll |
| 14 | l_thumb_distal_pitch |
| 15 | l_thumb_proximal_yaw |
| 16 | l_index_proximal_finger |
| 17 | l_middle_proximal_finger |
| 18 | l_ring_proximal_finger |
| 19 | l_pinky_proximal_finger |
| 20 | r_thumb_distal_pitch |
| 21 | r_thumb_proximal_yaw |
| 22 | r_index_proximal_finger |
| 23 | r_middle_proximal_finger |
| 24 | r_ring_proximal_finger |
| 25 | r_pinky_proximal_finger |
| 26 | head_yaw |
| 27 | head_pitch |