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
footPoseTargetTrajectoriesmessage 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
- Create a
footPoseTargetTrajectoriesmessage instance. - Assign the input time trajectory, foot index trajectory, and the initialized foot pose trajectory to the message object.
- Iterate over each time point, create the corresponding
footPosemessage, and set the foot and torso poses. - Append each
footPosemessage to thefootPoseTrajectorylist. - 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
- Compute the offsets of the left and right feet relative to the torso.
- Construct the rotation matrix
R_zfor rotation about the z-axis. - Use the rotation matrix to compute the actual positions of the left and right feet.
- 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
- Initialize the trajectory lists related to the gait.
- Create rotated rectangles for the left and right feet for collision checking.
- Iterate over each gait step, computing the time trajectory and body pose.
- Use
generate_stepsto compute the positions of the left and right feet. - If collision checking is enabled, perform a collision check every two steps and adjust the gait order to avoid collisions.
- Update the foot index and foot pose trajectories according to the current gait order.
- Print the generated trajectory information.
- Call
get_foot_pose_traj_msgto generate and return the gait message object.
Main Program Logic
- Initialize the ROS node: Use
rospy.init_nodeto initialize a ROS node namedfoot_pose_publisher. - Create the publisher: Use
rospy.Publisherto create a publisher that publishes gait messages to the/humanoid_mpc_foot_pose_target_trajectoriestopic. - 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_msgto 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
