Skip to content

Sepishoon/Bicopter-MPC

Repository files navigation

Model Predictive Control — Mini Projects

A series of four mini projects implementing and comparing classical and advanced Model Predictive Control strategies for a tilt-rotor bicopter, progressing from linear MPC to robust tube-based formulations.

Course: Model Predictive Control
Department: Aerospace Engineering, Sharif University of Technology
Advisor: Dr. Emami
Author: Sepehr Mahfar


Overview

All four projects share the same plant: a tilt-rotor bicopter with 12 states and 4 inputs (two rotor speeds Ω₁, Ω₂ and two tilt angles δ₁, δ₂). The projects build progressively on each other:

Project Topic Best Result
Mini Project 1 LMPC and Stability Horizon N=30 approaches LQR; feasibility analysis with terminal sets
Mini Project 2 GPC and DMC LMPC (feedforward) best overall; GPC best under actuator fault
Mini Project 3 SLMPC, MPC-NLPT, NMPC NMPC-IP achieves IAE = 3.58 m·s — 100× better than SLMPC
Mini Project 4 Robust MPC RMPC-NC: zero violations, IAE = 0.0879; ROA ordering F(SLMPC) ≥ F(PTMPC) ≥ F(RMPC)

System: Tilt-Rotor Bicopter

Parameter Value
States 12 (position, velocity, Euler angles, angular rates)
Inputs 4 (Ω₁, Ω₂, δ₁, δ₂)
System type Nonlinear, underactuated, open-loop unstable
Hover rotor speed Ωₕ ≈ 700 rad/s
Rotor speed bounds [0, 1.3 Ωₕ] rad/s
Tilt angle bounds [−15°, +15°]
Reference trajectory Quadratic diagonal climb: pₙ(t) = 0.05t² + 0.1t + 1 m

State vector: x = [pn, pe, pd, u, v, w, φ, θ, ψ, p, q, r]ᵀ
Input vector: u = [Ω₁, Ω₂, δ₁, δ₂]ᵀ


Project Structure

.
├── 1) LMPC and Stability/
│   ├── Report.pdf
│   └── Codes/
│       ├── bicopter_linearize_continuous.m   # Continuous linearization
│       ├── bicopterEOM_with_inputs.m         # EOM with control inputs
│       ├── bicopterEOM.m                     # Equations of motion
│       ├── MPC_MiniProject1_final.m          # Main simulation script
│       └── solve_mpc_cvx.m                  # CVX-based QP solver
│
├── 2) GPC and DMC/
│   ├── Report.pdf
│   └── Codes/
│       ├── bicopterEOM.m
│       ├── linearize_bicopter.m
│       └── MPC_MiniProject2_final.m          # LMPC, GPC, DMC, LQR comparison
│
├── 3) SLMPC, MPC-NLPT, and NMPC/
│   ├── Report.pdf
│   └── Codes/
│       ├── bicopterEOM.m                     # Equations of motion
│       ├── linearize_bicopter_fast.m         # Fast symbolic Jacobians
│       ├── SLMPC_MiniProject3.m              # Sequential linearization MPC
│       ├── MPC_NLPT_MiniProject3.m           # Lawrynczuk trajectory linearization
│       ├── NMPC_IP_MiniProject3.m            # NMPC via CasADi + IPOPT
│       ├── NMPC_SQP_MiniProject3.m           # NMPC via custom SQP
│       └── MPC_MiniProject3_final.m          # Main simulation script (runs all methods)
│
└── 4) Robust MPC/
    ├── Report.pdf
    └── Codes/
        ├── bicopterEOM.m
        ├── linearize_bicopter_fast.m
        ├── MPC_MiniProject4_final.m          # MASTER RUNNER — runs all tasks (toggle flags at top)
        ├── PTMPC_CL_CombinedFG_Final.m       # Parameterized tube MPC (combined Fcl, Gcl)
        ├── PTMPC_ROA_CombinedFG.m            # PTMPC ROA analysis
        ├── RMPC_NominalCost_Final.m          # RMPC with nominal cost
        ├── RMPC_ROA_Analysis_Bicopter.m      # RMPC ROA analysis
        └── RMPC_WorstCaseCost_Final.m        # RMPC with worst-case cost

Methods

Mini Project 1 — Linear MPC and Stability

Linearizes the bicopter at hover (Ω₀ = √(mg/2kf), δ₀ = 0) and implements LMPC with a discrete-time LQR terminal cost. Two scenarios are studied: unconstrained and constrained (altitude + roll limits), tested across horizons N ∈ {2, 5, 10, 15, 20, 25, 30}.

Key sections:

  • Horizon sweep: Unconstrained LMPC approaches infinite-horizon LQR as N increases. Cost difference is negligible beyond N = 15.
  • Constrained LMPC: Horizons N = 5, 10, 15 are infeasible; N = 20, 25, 30 satisfy all constraints.
  • Nonlinear plant: LMPC applied to the nonlinear model; N = 100 needed for full feasibility. Without terminal cost, complete feasibility is achieved.
  • Terminal set analysis: Combining terminal cost + terminal constraint yields the best stability guarantees. Removing terminal cost improves feasibility but weakens guarantees.
  • Robustness: −10% mass uncertainty maintains stability with slightly increased cost.

Mini Project 2 — GPC and DMC

Four controllers compared for a 40-second trajectory tracking task across five robustness scenarios (nominal, measurement noise, model uncertainty, external disturbance, actuator fault):

  • LMPC with feedforward (differential flatness): Best overall. Optimal at Nₚ = 20. Very long horizons (Nₚ = 80) cause numerical issues.
  • GPC (ARX model, no feedforward): Best under actuator fault (J = 139,136) due to unified disturbance optimization. Optimal at Nₚ = 10.
  • DMC (cascade outer-position / inner-attitude): Structurally decoupled — not a fair comparison. Fails completely under actuator fault due to inner LQR instability.
  • LQR with feedforward: Competitive in nominal case; degrades under noise and disturbances due to fixed gain.

Mini Project 3 — SLMPC, MPC-NLPT, and NMPC

Five methods compared, with a key design choice: QP-based methods run at Ts = 0.01 s (100 Hz) while NLP-based methods use Ts = 0.1 s (10 Hz), extending the real-time preview window 10×.

Method Ts IAE (Nₚ=20) Avg Comp (ms)
SLMPC 0.01 s 356.2 m·s 0.60
MPC-NLPT 0.01 s 347.7 m·s 8.95
NMPC-IP (CasADi/IPOPT) 0.1 s 3.58 m·s 117.4
NMPC-SQP (custom) 0.1 s 3.48 m·s 61.6
LQR baseline 0.01 s 140.7 m·s < 0.01
  • NMPC-IP uses multiple-shooting with CasADi symbolic AD + IPOPT interior-point solver. Warm-starting reduces iterations from ~10 to 3–7 per step.
  • NMPC-SQP uses a custom SQP with damped BFGS Hessian and L₁ merit line search. Faster than IPOPT at moderate horizons but scales worse at large Nₚ (dense BFGS vs. sparse KKT).
  • MPC-NLPT diverges catastrophically at Nₚ = 50 (IAE = 1949) due to open-loop free-response instability of the bicopter.
  • Key insight: Performance is governed by the real-time preview window NₚTs, not Nₚ alone.

Mini Project 4 — Robust MPC

Constraint tightening for |pₙ − pₙ,ref| ≤ 0.2 m under bounded additive disturbances (w ∈ W, ‖w‖∞ ≤ 1):

  • RMPC-NC (nominal cost): Minimizes quadratic tracking cost with tightened constraints via feedback parameterization u = uₕ + Kz + c.
  • RMPC-WC (worst-case cost): Extends cost via game-theoretic DARE at γ = 1.0. Nearly identical to RMPC-NC in practice (IAE difference ≤ 3.5%).
  • PTMPC (parameterized tube MPC): Closed-loop formulation solving an LP over nominal + vertex trajectories. Avoids input tightening → strictly larger ROA than RMPC, but worse tracking (LP cost minimizes tube size, not error) and ~126× slower.

ROA analysis (41×41 grid, linprog feasibility check, planes: (pₙ,θ) and (pₙ,pₑ)):

N = 40 RMPC PTMPC SLMPC
(pₙ, θ) plane 44.4% 60.4% 65.9%
(pₙ, pₑ) plane 51.2% 65.9% 65.9%

Key finding: RMPC ROA increases with N (2.4% → 44.4%) because the terminal set is extremely tight (±3.5 mm, convergence step Nterm = 646), requiring longer horizons to steer the state into it from wider initial conditions.


Installation

# MATLAB R2024b required
# Mini Project 3 (NMPC-IP) additionally requires:
# CasADi v3.7.2  →  https://web.casadi.org/get/

Add CasADi to MATLAB path before running NMPC scripts:

addpath('/path/to/casadi')

Usage

% Mini Project 1 — LMPC horizon sweep + terminal set analysis
run('1) LMPC and Stability/Codes/MPC_MiniProject1_final.m')

% Mini Project 2 — GPC, DMC, LMPC, LQR comparison (5 robustness scenarios)
run('2) GPC and DMC/Codes/MPC_MiniProject2_final.m')

% Mini Project 3 — All five methods, all horizons
run('3) SLMPC, MPC-NLPT, and NMPC/Codes/MPC_MiniProject3_final.m')

% Mini Project 4 — All tasks run from the master file
% Toggle RUN_TASK_11_12 / RUN_TASK_13 / RUN_TASK_21 / RUN_TASK_22 / RUN_TASK_3
% at the top of the script to enable/disable individual parts
run('4) Robust MPC/Codes/MPC_MiniProject4_final.m')

Key Findings

  1. Horizon length trades off feasibility vs. optimality — longer horizons approach LQR performance in unconstrained LMPC, but can cause infeasibility in constrained formulations at intermediate lengths.
  2. Feedforward from differential flatness is decisive — LMPC and LQR with feedforward dramatically outperform GPC in nominal tracking; GPC compensates via unified disturbance optimization under faults.
  3. Real-time preview window, not Nₚ alone, governs NMPC performance — Ts = 0.1 s at Nₚ = 20 gives 2.0 s of preview and 100× lower IAE than Ts = 0.01 s at the same Nₚ.
  4. MPC-NLPT is unstable at long horizons for open-loop-unstable systems — the free-response propagation with constant input causes finite-escape-time divergence of the bicopter at Nₚ = 50.
  5. PTMPC achieves a strictly larger ROA than open-loop RMPC by avoiding input tightening, but at the cost of LP-based tracking (not error-minimizing) and ~126× higher computation.
  6. Price of robustness is negligible for this disturbance magnitude — IAE(worst-case)/IAE(no-dist) ratios lie within [0.86, 1.08] for all robust controllers.

About

MATLAB implementation of Linear, Generalized, Nonlinear, and Robust MPC for a tilt-rotor bicopter — covering LMPC, GPC, DMC, SLMPC, NMPC (IPOPT/SQP), RMPC, and Tube MPC across four mini-projects.

Topics

Resources

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages