This project implements walking control for the Go2 quadruped robot using optimal control methods. It supports both Open-loop Optimal Control (OPC) and Model Predictive Control (MPC) approaches with trajectory planning and visualization capabilities.
Due to conflicts with ROS, this project uses a dedicated Conda environment. Install the required dependencies:
# Create and activate conda environment
conda create -n walking python=3.8
conda activate walking
# Install core dependencies
conda install -c conda-forge pinocchio
conda install -c conda-forge pybullet
conda install -c conda-forge crocoddylAdditional dependencies may be required depending on your system configuration.
The conf_go2.py file contains all configurable parameters:
-
Control Mode: Switch between OPC and MPC
mpc_enabled = True # True for MPC, False for OPC
-
Walking Parameters:
step_length: Forward step distance (m)step_height: Maximum foot lift height (m)n_per_step: Number of time steps per leg movementn_steps: Number of steps to plan (OPC only)
-
MPC Parameters:
mpc_horizon: Planning horizon (number of full gait cycles)mpc_replan_frequency: How often to replan (in full gait cycles)mpc_warm_start: Enable warm starting with previous solution
-
Simulation Frequencies:
sim_freq: Simulation frequency (Hz)control_freq: Control frequency (Hz)
Execute the main script:
python main.pyYou can enable/disable trajectory visualization in main.py:
# In run_mpc_control function
VISU = True # Set to False to disable visualization
# In run_opc_control function
VISU = True # Set to False to disable visualizationWarning: Visualization may slow down the simulation, especially with large n_per_step values.
Main execution script that:
- Initializes the PyBullet simulator and Go2 robot
- Creates the controller and trajectory planner
- Runs either MPC or OPC control loop based on configuration
- Handles trajectory visualization
Configuration file containing:
- Robot parameters and URDF paths
- PD controller gains
- Simulation and control frequencies
- Walking gait parameters
- MPC/OPC settings
Go2 robot interface that:
- Initializes the robot model using example-robot-data
- Manages PyBullet simulation interface
- Handles state estimation (position, velocity, COM)
- Applies torque commands with PD control
Optimal control implementation featuring:
- Crocoddyl-based action models for walking
- Contact and swing phase dynamics
- Cost functions for tracking and regularization
- Solver interface for optimal control problems
- Support for both forward and inverse dynamics
Trajectory planning module that:
- Generates foot swing trajectories with specified step length/height
- Plans center-of-mass (COM) motion
- Supports multi-step planning for both OPC and MPC
- Handles gait cycle coordination (RR → LF → RF → LH sequence)
- Provides trajectory visualization capabilities
Model Predictive Control implementation that:
- Recalculates optimal control problems at specified intervals
- Manages warm starting with previous solutions
- Tracks gait cycles and leg coordination
- Provides reactive control compared to pre-planned OPC
- Handles replanning triggers and control execution
- Pre-plans entire walking sequence offline
- Solves one large optimal control problem
- Executes planned trajectory open-loop
- Faster execution but less adaptive to disturbances
- Replans trajectory online at specified intervals
- Uses receding horizon optimization
- More reactive to state changes and disturbances
- Higher computational cost but improved robustness
The implementation uses a trotting gait with the following leg sequence:
- RR (Rear Right) - swing phase
- LF (Left Front) - swing phase
- RF (Right Front) - swing phase
- LH (Left Hind) - swing phase
Each leg movement consists of n_per_step time steps plus one foot switch action.
- Warm Starting: MPC can use previous solutions as initial guesses to improve convergence
- Trajectory Visualization: Real-time display of planned foot and COM trajectories
- Configurable Gait: Adjustable step length, height, and timing parameters
- Robust Control: PD control with feedforward torques from optimal control
- Multi-Phase Planning: Handles both swing and stance phases with proper contact constraints
- Path Errors: Ensure all paths in
conf_go2.pypoint to correct locations - Visualization Slowdown: Disable visualization (
VISU = False) for faster simulation - MPC Convergence: Try adjusting horizon length or enabling warm start
- Control Instability: Check PD gains and time step parameters
- Use smaller horizons for faster MPC replanning
- Reduce
n_per_stepfor quicker gait cycles - Disable visualization for maximum simulation speed
- Enable warm starting for better MPC convergence
- Pinocchio: Rigid body dynamics and kinematics
- PyBullet: Physics simulation
- Crocoddyl: Optimal control framework
- NumPy: Numerical computations
- Example Robot Data: Robot model definitions