Roban2 Docs
Roban2 (ROS1) Legacy VersionsFeature ExamplesGeneral Examples

Single-Step Control Example

Example Code

  • Path: ~/kuavo-ros-opensource/src/demo/examples_code/step_control/simStepControl.py

Description

The following is a detailed description of each function in the code, including its purpose, functionality, input parameters, and execution logic:

1. get_foot_pose_traj_msg

Purpose and Function

  • This function creates and returns a footPoseTargetTrajectories message object that contains the robot's gait information.

Input Parameters

  • time_traj: A list of time trajectories, representing the time point of each step.
  • foot_idx_traj: A list of foot index trajectories, indicating which foot moves in the current gait step.
  • foot_traj: A list of foot pose trajectories, containing the foot position and orientation for each step.
  • torso_traj: A list of torso pose trajectories, containing the torso position and orientation for each step.

Execution Logic

  1. Create a footPoseTargetTrajectories message instance.
  2. Assign the input time trajectory, foot index trajectory, and the initialized foot pose trajectory to the message object.
  3. Iterate over each time point, create the corresponding footPose message, and set the foot and torso poses.
  4. Append each footPose message to the footPoseTrajectory list.
  5. Return the constructed message object.

2. generate_steps

Purpose and Function

  • Compute and return the positions of the left and right feet based on the given torso position and yaw angle.

Input Parameters

  • torso_pos: An array of the torso position, containing the x, y, and z coordinates.
  • torso_yaw: The torso yaw angle, in radians.
  • foot_bias: The lateral offset of the feet, used to compute the positions of the left and right feet.

Execution Logic

  1. Compute the offsets of the left and right feet relative to the torso.
  2. Construct the rotation matrix R_z for rotation about the z-axis.
  3. Use the rotation matrix to compute the actual positions of the left and right feet.
  4. Return the computed positions of the left and right feet.

3. get_multiple_steps_msg

Purpose and Function

  • Generate a multi-step gait message object containing the time, foot index, foot pose, and torso pose for multiple gait steps.

Input Parameters

  • body_poses: A list of body poses, each containing x, y, and z coordinates and a yaw angle.
  • dt: The time interval between each step.
  • is_left_first: A boolean indicating whether the left foot steps first.
  • collision_check: A boolean indicating whether to perform collision checking.

Execution Logic

  1. Initialize the trajectory lists related to the gait.
  2. Create rotated rectangles for the left and right feet for collision checking.
  3. Iterate over each gait step, computing the time trajectory and body pose.
  4. Use generate_steps to compute the positions of the left and right feet.
  5. If collision checking is enabled, perform a collision check every two steps and adjust the gait order to avoid collisions.
  6. Update the foot index and foot pose trajectories according to the current gait order.
  7. Print the generated trajectory information.
  8. Call get_foot_pose_traj_msg to generate and return the gait message object.

Main Program Logic

  • Initialize the ROS node: Use rospy.init_node to initialize a ROS node named foot_pose_publisher.
  • Create the publisher: Use rospy.Publisher to create a publisher that publishes gait messages to the /humanoid_mpc_foot_pose_target_trajectories topic.
  • Set default parameters: Define the default gait order and collision check options.
  • Define the body pose sequence: Set a series of body poses, each corresponding to two steps.
  • Generate and publish the gait message: Call get_multiple_steps_msg to generate the gait message and publish it through the publisher.

Through these functions and this logic, the code generates robot gaits from a given sequence of body poses and publishes the gait information over ROS.

Execution

  • Start the main program on the lower-level controller
cd ~/kuavo-ros-opensource
source devel/setup.bash
roslaunch humanoid_controllers load_kuavo_real.launch
  • Source the SDK environment variables
source devel/setup.zsh # 或bash
  • Example program

    • ~/kuavo-ros-opensource/src/demo/examples_code/step_control/simStepControl.py
  • Running effect

Simulation effect of single-step control execution