Kuavo Docs
Feature ExamplesGeneral Examples

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:
    1. Cubic spline interpolator (plan_arm_traj_cubicspline_demo.py)
    2. Bezier curve interpolator (plan_arm_traj_bezier_demo.py)

2. Build and Launch

2.1 Build

cd /home/lab/kuavo-ros-opensource #仓库目录
sudo su
catkin build kuavo_sdk humanoid_plan_arm_trajectory

2.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 is kuavo_arm_traj
  • joint_state_unit: Unit of the joint angles; rad or deg; the default is deg
  • use_nodelet: Whether to launch as a nodelet; the default is false

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 trajectory in a terminal
  • If /humanoid_plan_arm_trajectory_node already exists, skip this step
  • If /humanoid_plan_arm_trajectory_node does 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.py

The result is shown below:

Cubic spline result

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.py

The result is shown below:

Bezier result

3. ROS Interfaces

3.1 Topics

Published Topics

/<interpolate_type>/arm_traj

Topic description: publishes the planned arm trajectory

Message type: trajectory_msgs/JointTrajectory

FieldTypeDescription
headerstd_msgs/HeaderMessage header
joint_namesstring[]Array of joint names
pointsJointTrajectoryPoint[]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

FieldTypeDescription
progressint32Trajectory execution progress, in milliseconds
is_finishedboolWhether the trajectory has finished executing
/kuavo_arm_traj

Topic description: controls the hand joint positions

Message type: sensor_msgs/JointState

FieldTypeDescription
headerstd_msgs/HeaderMessage header
namestring[]Joint names
positionfloat64[]Joint positions
velocityfloat64[]Joint velocities
effortfloat64[]Joint effort (unused)

3.2 Services

/<interpolate_type>/plan_arm_trajectory

Service description: trajectory planning service

<interpolate_type> can be:

  • bezier: Bezier curve interpolation
  • cubic_spline: Cubic spline interpolation

Bezier Curve Interpolation Service

Message type: humanoid_plan_arm_trajectory/planArmTrajectoryBezierCurve

Request parameters:

FieldTypeDescription
multi_joint_bezier_trajectoryjointBezierTrajectory[]Array of Bezier trajectories for multiple joints
start_frame_timefloat64Start time of the trajectory, in seconds
end_frame_timefloat64End time of the trajectory, in seconds
joint_namesstring[]Array of joint names

Return result:

FieldTypeDescription
successboolWhether planning succeeded

Cubic Spline Interpolation Service

Message type: humanoid_plan_arm_trajectory/planArmTrajectoryCubicSpline

Request parameters:

FieldTypeDescription
joint_trajectorytrajectory_msgs/JointTrajectoryJoint trajectory specification

Return result:

FieldTypeDescription
successboolWhether 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

  1. Initialize the node and services:

    • Initialize the ROS node arm_trajectory_cubicspline_demo
    • Subscribe to the /cubic_spline/arm_traj topic
    • Publish to the /kuavo_arm_traj topic
  2. Service calls:

    • Set the arm control mode
    • Use the trajectory planning service
  3. 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_observation message 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

  1. Initialize the node and services:

    • Initialize the ROS node arm_trajectory_bezier_demo
    • Subscribe to the /bezier/arm_traj topic
    • Publish to the /kuavo_arm_traj topic
  2. Service calls:

    • Set the arm control mode
    • Use the trajectory planning service
  3. 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

  1. 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.

  2. 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.

  3. 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

  1. Top-level structure

    KeyTypeDescription
    frameslistEach item is the data for one time point, containing all joint data required by the Bezier curve interpolator
    musicslistMusic data
    finishintMotion end time, in milliseconds
    firstintMotion start time, in milliseconds
    versionstrVersion number of the .tact file, e.g. "1.0.0"
  2. frames

    KeyTypeDescription
    servoslistEach element corresponds to the angle of a specific joint in Kuavo (mapping table)
    keyframeintTime point of the keyframe, in milliseconds
    attributedictContains 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
  3. attribute

    KeyTypeDescription
    CPlistList 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 of CPType
    CPTypelistControl point types, with the same length as CP, corresponding to the left control point and the right control point respectively; can be AUTO or MANUAL
    selectboolNot 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

  1. Each element in the "servos" field corresponds to the name of a Kuavo joint
IndexJoint Name
0l_arm_pitch
1l_arm_roll
2l_arm_yaw
3l_forearm
4l_hand_yaw
5l_hand_pitch
6l_hand_roll
7r_arm_pitch
8r_arm_roll
9r_arm_yaw
10r_forearm
11r_hand_yaw
12r_hand_pitch
13r_hand_roll
14l_thumb_distal_pitch
15l_thumb_proximal_yaw
16l_index_proximal_finger
17l_middle_proximal_finger
18l_ring_proximal_finger
19l_pinky_proximal_finger
20r_thumb_distal_pitch
21r_thumb_proximal_yaw
22r_index_proximal_finger
23r_middle_proximal_finger
24r_ring_proximal_finger
25r_pinky_proximal_finger
26head_yaw
27head_pitch