diff --git a/PROJECT_ANALYSIS_CN.md b/PROJECT_ANALYSIS_CN.md new file mode 100644 index 0000000..3747bc1 --- /dev/null +++ b/PROJECT_ANALYSIS_CN.md @@ -0,0 +1,328 @@ +# Hector 仿真项目分析报告 + +## 项目概述 + +**项目名称**: HECTOR - Humanoid for Enhanced ConTrol and Open-source Research (增强控制和开源研究人形机器人) + +**开发单位**: USC Dynamic Robotics and Control Laboratory (南加州大学动态机器人与控制实验室) + +**项目类型**: MATLAB/Simulink 双足人形机器人仿真软件 + +**许可证**: 3-Clause BSD License (开源) + +## 核心功能 + +本项目是一个基于 MATLAB/Simulink 的人形机器人完整仿真系统,主要用于: +1. 双足机器人的动力学仿真 +2. 基于力和力矩的模型预测控制 (Force-and-Moment-based MPC) +3. 高动态步态控制与规划 +4. 机器人行走、跳跃、跑步等运动模式的研究 + +## 技术架构 + +### 1. 核心依赖 + +- **MATLAB & Simulink 2023a+**: 主要开发平台 +- **Simscape Multibody**: 物理引擎和机械系统建模 +- **CasADi**: 符号计算和优化框架 +- **qpOASES**: 二次规划求解器(用于 MPC 实时优化) + +### 2. 系统要求 + +- 推荐 Windows 10 及以上系统 +- Linux 系统可运行但可能需要调整路径定义 + +## 项目结构 + +``` +Hector_Simulation-Matlab_Simulation/ +├── Hector_Simulation.slx # 主 Simulink 仿真模型 +├── Initiate_Simulation.m # 仿真初始化脚本 +├── Functions/ # 核心控制算法库 +│ ├── LocomotionMPC_qpoases.m # MPC 控制器实现 +│ ├── Swing_PD.m # 摆动腿 PD 控制 +│ ├── JacobianMapping.m # 雅可比映射 +│ ├── Formulate_Contact_Jacobian.m # 接触雅可比计算 +│ ├── Arm_Controller.m # 手臂控制器 +│ ├── AssignMPCStage.m # MPC 阶段分配 +│ └── misc/ # 辅助函数 +│ ├── foot_to_joint.m # 足端到关节映射 +│ ├── Rx.m, Ry.m, Rz.m # 旋转矩阵 +├── Readme.md # 英文说明文档 +└── License.md # BSD 许可证 + +``` + +## 核心算法详解 + +### 1. 模型预测控制 (MPC) - `LocomotionMPC_qpoases.m` + +**算法特点**: +- 基于力和力矩的 MPC 框架 +- 预测时域: 10 步 +- 使用 qpOASES 进行实时二次规划求解 +- 支持多种步态模式(站立、行走、跳跃) + +**关键参数**: +- 步态周期: 0.4 秒 (可调) +- MPC 采样时间: 0.04 秒 +- 优化变量: 12×h (h=10 个预测步) +- 约束数量: 34×h + +**实现的功能**: +- 质心位置和速度跟踪 +- 姿态稳定控制 +- 接触力优化 +- 欧拉角连续性处理(处理 2π=0 关系) + +### 2. 摆动腿控制 - `Swing_PD.m` + +**控制策略**: +- 基于启发式足部落点策略 +- 自适应频率步态规划 +- PD 反馈控制 + +**关键功能**: +- 足部轨迹规划(抬腿高度: 0.12m) +- 步态调度器(walking/hopping/running) +- 速度反馈补偿 +- 机体姿态补偿 + +**PD 增益**: +```matlab +Kp = diag([100 100 100 100 5]) % 位置增益 +Kd = diag([2 2 2 2 0.1]) # 速度增益 +``` + +### 3. 接触雅可比计算 - `Formulate_Contact_Jacobian.m` + +**功能**: +- 计算足部接触点的雅可比矩阵 +- 建立广义接触力到关节力矩的映射 + +**输出**: +- Contact_Jacobian: [12×5] 雅可比矩阵 +- Rotm_foot: 足端姿态矩阵 + +**机器人腿部配置**: +- 5 个关节每条腿: hip_yaw, hip_roll, hip_pitch, knee, ankle +- 使用符号计算 (CasADi) 自动求导 + +### 4. 雅可比映射 - `JacobianMapping.m` + +**功能**: 将 MPC 输出的接触力和力矩映射为关节驱动力矩 + +**映射关系**: +``` +τ = J_c^T × (-u) +``` +其中: +- τ: 关节力矩向量 +- J_c: 接触雅可比 +- u: MPC 输出的广义力 + +### 5. 手臂控制器 - `Arm_Controller.m` + +**控制模式**: +1. 启发式摆臂: 手臂运动与对侧腿部协调 +2. 固定位置: 手臂保持固定姿态 + +**关节配置**: +- 每个手臂 3 个关节: shoulder_roll, shoulder_pitch, elbow +- PD 控制增益: Kp=50, Kd=2 + +## 机器人模型参数 + +### 物理参数 + +**初始状态**: +- 初始高度: 0.525m +- 初始速度: [0, 0, 0] m/s +- 初始姿态: [0, 0, 0] deg + +**关节限位**: +- Hip Yaw: ±30° +- Hip Roll: ±18° +- Hip Pitch: -120° ~ 120° +- Knee: -160° ~ -15° +- Ankle: -75° ~ 75° + +**接触参数**: +- 地面刚度: 1×10^5 N/m +- 地面阻尼: 1×10^3 N·s/m +- 摩擦系数: μ_s = μ_k = 1.0 +- 接触点配置: 每只脚 15 个点(3 排 × 5 点) + +### 控制参数 + +**步态参数**: +- 步态模式: 0=站立, 1=行走, 2=跳跃, 3=跑步 +- 默认步态周期: 0.4 秒 +- 预测时域: 10 步 +- 步长反馈系数: K_step = 0.03 + +## 主要学术贡献 + +本项目实现了以下论文的算法: + +**论文标题**: "Force-and-moment-based model predictive control for achieving highly dynamic locomotion on bipedal robots" + +**作者**: Junheng Li, Quan Nguyen + +**发表**: 2021 IEEE Conference on Decision and Control (CDC) + +**核心创新**: +1. 基于力和力矩的 MPC 框架,突破传统 ZMP 方法限制 +2. 实现了高动态双足运动(包括跑步、跳跃) +3. 开源实现,便于研究复现和扩展 + +**相关研究**: +- 自适应频率 MPC 用于不平整地形行走 +- 动态步态切换 +- 鲁棒性控制设计 + +## 使用方法 + +### 安装步骤 + +1. 下载并解压本仿真软件到指定目录 +2. 下载 CasADi MATLAB 库到同一目录 +3. 安装 MATLAB 2023a 或更高版本 + +### 运行流程 + +1. 启动 MATLAB 2023a+ +2. 将整个仿真文件夹和 CasADi 库添加到 MATLAB 路径 +3. 运行 `Initiate_Simulation.m` 加载模型和参数 +4. 打开 `Hector_Simulation.slx` 并根据需要修改 +5. 按 Ctrl+D 构建模型 +6. 在 Mechanics Explorer 中运行仿真(非实时) +7. 可选:注释/取消注释手臂模块 + +### 可配置参数 + +在 `Initiate_Simulation.m` 中可以修改: + +**步态参数**: +```matlab +gait = 1; % 步态模式选择 +gaitcycle = 0.4; % 步态周期 +lift_height = 0.12; % 抬腿高度 +``` + +**MPC 参数**: +```matlab +h = 10; % 预测时域 +dt_MPC = gaitcycle/10; % MPC 采样时间 +``` + +**物理参数**: +```matlab +contact_stiffness = 1e5; % 接触刚度 +contact_damping = 1e3; % 接触阻尼 +mu_s = 1.0; % 静摩擦系数 +``` + +**初始状态**: +```matlab +body_z0 = 0.525; % 初始高度 +body_v0 = [0 0 0]; % 初始速度 +``` + +## 扩展功能 + +### 1. 不平整地形支持 + +代码中包含网格地形定义功能: +```matlab +x_grid = -1:0.01:5; +y_grid = -1:0.01:1; +[X,Y] = meshgrid(x_grid,y_grid); +z_heights = [0.05*cos(2*pi*X)-0.05]'; +``` + +使用时需在 Simulink 模型中切换到 "Mesh Grid Surface" + +### 2. 变步长 MPC + +支持自适应采样时间的 MPC,通过 `AssignMPCStage.m` 实现: +- 可根据步态阶段动态调整 MPC 采样时间 +- 适用于自适应频率步态控制 + +### 3. 可选手臂模块 + +通过设置 `addArm` 变量控制: +```matlab +addArm = 0; % 不包含手臂 +addArm = 1; % 包含手臂 +``` + +## 技术优势 + +1. **完整开源**: 提供完整的仿真和控制代码 +2. **高动态性能**: 支持跑步、跳跃等高难度动作 +3. **先进算法**: 基于最新的力-力矩 MPC 框架 +4. **易于扩展**: 模块化设计,便于添加新功能 +5. **学术支持**: 有对应的学术论文和理论支撑 +6. **可视化**: 使用 Simscape Multibody 提供 3D 可视化 + +## 应用场景 + +1. **研究**: 双足机器人控制算法研究 +2. **教学**: 机器人学、控制理论课程教学 +3. **开发**: 人形机器人控制器设计和测试 +4. **验证**: 控制算法在实际机器人前的仿真验证 + +## 潜在改进方向 + +1. **实时性优化**: 当前仿真非实时,可优化求解速度 +2. **鲁棒性增强**: 添加外力扰动处理 +3. **地形感知**: 集成视觉/感知系统 +4. **学习方法**: 结合机器学习优化步态 +5. **硬件接口**: 添加与真实机器人的接口 + +## 联系信息 + +**项目负责人**: Junheng Li +**邮箱**: junhengl@usc.edu + +**致谢**: +- Zhanhao Le +- Han Gong + +对开源软件的贡献。 + +## 引用格式 + +如果使用本软件进行研究,请引用: + +```bibtex +@inproceedings{li2021force, + title={Force-and-moment-based model predictive control for achieving highly dynamic locomotion on bipedal robots}, + author={Li, Junheng and Nguyen, Quan}, + booktitle={2021 60th IEEE Conference on Decision and Control (CDC)}, + pages={1024--1030}, + year={2021}, + organization={IEEE} +} +``` + +## 总结 + +Hector 仿真项目是一个功能完整、技术先进的双足人形机器人仿真平台。它不仅实现了最新的力-力矩 MPC 控制算法,还提供了完整的开源代码和详细的文档,非常适合机器人控制领域的研究人员和学生使用。 + +**主要特点**: +- ✅ 完整的双足机器人动力学模型 +- ✅ 先进的 MPC 控制框架 +- ✅ 多种步态模式(站立/行走/跳跃/跑步) +- ✅ 模块化、可扩展的代码结构 +- ✅ 完整的开源和学术支持 +- ✅ 3D 可视化仿真环境 + +**适用人群**: +- 机器人学研究人员 +- 控制理论研究者 +- 机器人工程专业学生 +- 人形机器人开发者 + +本项目为双足机器人控制研究提供了一个优秀的起点和参考实现。 diff --git a/PROJECT_ANALYSIS_EN.md b/PROJECT_ANALYSIS_EN.md new file mode 100644 index 0000000..d8ecc5f --- /dev/null +++ b/PROJECT_ANALYSIS_EN.md @@ -0,0 +1,327 @@ +# Hector Simulation Project Analysis Report + +## Project Overview + +**Project Name**: HECTOR - Humanoid for Enhanced ConTrol and Open-source Research + +**Developer**: USC Dynamic Robotics and Control Laboratory + +**Project Type**: MATLAB/Simulink Bipedal Humanoid Robot Simulation Software + +**License**: 3-Clause BSD License (Open Source) + +## Core Functionality + +This project is a complete humanoid robot simulation system based on MATLAB/Simulink, primarily used for: +1. Bipedal robot dynamics simulation +2. Force-and-Moment-based Model Predictive Control (MPC) +3. Highly dynamic gait control and planning +4. Research on robot walking, hopping, running, and other locomotion modes + +## Technical Architecture + +### 1. Core Dependencies + +- **MATLAB & Simulink 2023a+**: Main development platform +- **Simscape Multibody**: Physics engine and mechanical system modeling +- **CasADi**: Symbolic computation and optimization framework +- **qpOASES**: Quadratic programming solver (for MPC real-time optimization) + +### 2. System Requirements + +- Recommended: Windows 10 and above +- Linux systems can run but may require path adjustments + +## Project Structure + +``` +Hector_Simulation-Matlab_Simulation/ +├── Hector_Simulation.slx # Main Simulink simulation model +├── Initiate_Simulation.m # Simulation initialization script +├── Functions/ # Core control algorithm library +│ ├── LocomotionMPC_qpoases.m # MPC controller implementation +│ ├── Swing_PD.m # Swing leg PD control +│ ├── JacobianMapping.m # Jacobian mapping +│ ├── Formulate_Contact_Jacobian.m # Contact Jacobian calculation +│ ├── Arm_Controller.m # Arm controller +│ ├── AssignMPCStage.m # MPC stage assignment +│ └── misc/ # Utility functions +│ ├── foot_to_joint.m # Foot to joint mapping +│ ├── Rx.m, Ry.m, Rz.m # Rotation matrices +├── Readme.md # Documentation +└── License.md # BSD License +``` + +## Core Algorithm Details + +### 1. Model Predictive Control (MPC) - `LocomotionMPC_qpoases.m` + +**Algorithm Features**: +- Force-and-moment-based MPC framework +- Prediction horizon: 10 steps +- Real-time quadratic programming using qpOASES +- Multiple gait mode support (standing, walking, hopping) + +**Key Parameters**: +- Gait cycle: 0.4 seconds (adjustable) +- MPC sampling time: 0.04 seconds +- Optimization variables: 12×h (h=10 prediction steps) +- Constraint count: 34×h + +**Implemented Features**: +- Center of mass position and velocity tracking +- Attitude stabilization control +- Contact force optimization +- Euler angle continuity handling (2π=0 relation) + +### 2. Swing Leg Control - `Swing_PD.m` + +**Control Strategy**: +- Heuristic foot placement policy +- Adaptive frequency gait planning +- PD feedback control + +**Key Functions**: +- Foot trajectory planning (lift height: 0.12m) +- Gait scheduler (walking/hopping/running) +- Velocity feedback compensation +- Body attitude compensation + +**PD Gains**: +```matlab +Kp = diag([100 100 100 100 5]) # Position gains +Kd = diag([2 2 2 2 0.1]) # Velocity gains +``` + +### 3. Contact Jacobian Calculation - `Formulate_Contact_Jacobian.m` + +**Functionality**: +- Computes Jacobian matrix for foot contact points +- Establishes mapping from generalized contact forces to joint torques + +**Outputs**: +- Contact_Jacobian: [12×5] Jacobian matrix +- Rotm_foot: Foot orientation matrix + +**Robot Leg Configuration**: +- 5 joints per leg: hip_yaw, hip_roll, hip_pitch, knee, ankle +- Symbolic computation using CasADi for automatic differentiation + +### 4. Jacobian Mapping - `JacobianMapping.m` + +**Functionality**: Maps MPC output contact forces and moments to joint actuation torques + +**Mapping Relation**: +``` +τ = J_c^T × (-u) +``` +Where: +- τ: Joint torque vector +- J_c: Contact Jacobian +- u: MPC output generalized forces + +### 5. Arm Controller - `Arm_Controller.m` + +**Control Modes**: +1. Heuristic arm swing: Arm motion coordinated with opposite leg +2. Fixed position: Arms maintain fixed posture + +**Joint Configuration**: +- 3 joints per arm: shoulder_roll, shoulder_pitch, elbow +- PD control gains: Kp=50, Kd=2 + +## Robot Model Parameters + +### Physical Parameters + +**Initial State**: +- Initial height: 0.525m +- Initial velocity: [0, 0, 0] m/s +- Initial attitude: [0, 0, 0] deg + +**Joint Limits**: +- Hip Yaw: ±30° +- Hip Roll: ±18° +- Hip Pitch: -120° ~ 120° +- Knee: -160° ~ -15° +- Ankle: -75° ~ 75° + +**Contact Parameters**: +- Ground stiffness: 1×10^5 N/m +- Ground damping: 1×10^3 N·s/m +- Friction coefficient: μ_s = μ_k = 1.0 +- Contact point configuration: 15 points per foot (3 rows × 5 points) + +### Control Parameters + +**Gait Parameters**: +- Gait modes: 0=standing, 1=walking, 2=hopping, 3=running +- Default gait cycle: 0.4 seconds +- Prediction horizon: 10 steps +- Step feedback coefficient: K_step = 0.03 + +## Key Academic Contributions + +This project implements algorithms from the following paper: + +**Paper Title**: "Force-and-moment-based model predictive control for achieving highly dynamic locomotion on bipedal robots" + +**Authors**: Junheng Li, Quan Nguyen + +**Published**: 2021 IEEE Conference on Decision and Control (CDC) + +**Core Innovations**: +1. Force-and-moment-based MPC framework, breaking traditional ZMP method limitations +2. Achievement of highly dynamic bipedal locomotion (including running, hopping) +3. Open-source implementation for research reproduction and extension + +**Related Research**: +- Adaptive frequency MPC for uneven terrain walking +- Dynamic gait transitions +- Robust control design + +## Usage Instructions + +### Installation Steps + +1. Download and extract the simulation software to desired directory +2. Download CasADi MATLAB library to the same directory +3. Install MATLAB 2023a or later version + +### Running Procedure + +1. Launch MATLAB 2023a+ +2. Add entire simulation folder and CasADi library to MATLAB path +3. Run `Initiate_Simulation.m` to load model and parameters +4. Open `Hector_Simulation.slx` and modify as needed +5. Press Ctrl+D to build model +6. Run simulation in Mechanics Explorer (note: not real-time) +7. Optional: Comment/uncomment arm assembly and control + +### Configurable Parameters + +In `Initiate_Simulation.m`, you can modify: + +**Gait Parameters**: +```matlab +gait = 1; % Gait mode selection +gaitcycle = 0.4; % Gait cycle period +lift_height = 0.12; % Foot lift height +``` + +**MPC Parameters**: +```matlab +h = 10; % Prediction horizon +dt_MPC = gaitcycle/10; % MPC sampling time +``` + +**Physical Parameters**: +```matlab +contact_stiffness = 1e5; % Contact stiffness +contact_damping = 1e3; % Contact damping +mu_s = 1.0; % Static friction coefficient +``` + +**Initial State**: +```matlab +body_z0 = 0.525; % Initial height +body_v0 = [0 0 0]; % Initial velocity +``` + +## Extended Features + +### 1. Uneven Terrain Support + +Code includes grid terrain definition functionality: +```matlab +x_grid = -1:0.01:5; +y_grid = -1:0.01:1; +[X,Y] = meshgrid(x_grid,y_grid); +z_heights = [0.05*cos(2*pi*X)-0.05]'; +``` + +To use, switch to "Mesh Grid Surface" in Simulink model + +### 2. Variable-Step MPC + +Supports adaptive sampling time MPC, implemented via `AssignMPCStage.m`: +- Can dynamically adjust MPC sampling time based on gait phase +- Applicable for adaptive frequency gait control + +### 3. Optional Arm Module + +Controlled by setting `addArm` variable: +```matlab +addArm = 0; % Without arms +addArm = 1; % With arms +``` + +## Technical Advantages + +1. **Fully Open Source**: Complete simulation and control code provided +2. **High Dynamic Performance**: Supports challenging motions like running and hopping +3. **Advanced Algorithms**: Based on latest force-moment MPC framework +4. **Easy to Extend**: Modular design facilitates adding new features +5. **Academic Support**: Backed by corresponding academic papers and theory +6. **Visualization**: 3D visualization using Simscape Multibody + +## Application Scenarios + +1. **Research**: Bipedal robot control algorithm research +2. **Education**: Robotics and control theory course teaching +3. **Development**: Humanoid robot controller design and testing +4. **Validation**: Controller algorithm simulation before real robot deployment + +## Potential Improvement Directions + +1. **Real-time Optimization**: Current simulation is non-real-time, can optimize solver speed +2. **Robustness Enhancement**: Add external force disturbance handling +3. **Terrain Awareness**: Integrate vision/perception systems +4. **Learning Methods**: Combine machine learning for gait optimization +5. **Hardware Interface**: Add interface to real robots + +## Contact Information + +**Project Lead**: Junheng Li +**Email**: junhengl@usc.edu + +**Acknowledgments**: +- Zhanhao Le +- Han Gong + +For contributions to the open-source software. + +## Citation Format + +If using this software for research, please cite: + +```bibtex +@inproceedings{li2021force, + title={Force-and-moment-based model predictive control for achieving highly dynamic locomotion on bipedal robots}, + author={Li, Junheng and Nguyen, Quan}, + booktitle={2021 60th IEEE Conference on Decision and Control (CDC)}, + pages={1024--1030}, + year={2021}, + organization={IEEE} +} +``` + +## Summary + +The Hector simulation project is a fully-featured, technically advanced bipedal humanoid robot simulation platform. It not only implements the latest force-moment MPC control algorithm but also provides complete open-source code and detailed documentation, making it ideal for researchers and students in the field of robot control. + +**Key Features**: +- ✅ Complete bipedal robot dynamics model +- ✅ Advanced MPC control framework +- ✅ Multiple gait modes (standing/walking/hopping/running) +- ✅ Modular, extensible code structure +- ✅ Complete open-source and academic support +- ✅ 3D visualization simulation environment + +**Target Audience**: +- Robotics researchers +- Control theory researchers +- Robotics engineering students +- Humanoid robot developers + +This project provides an excellent starting point and reference implementation for bipedal robot control research.