Skip to content

shaoanlu/PiMPC-python

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

36 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

A Python port of PiMPC.

Installation

Clone this repository

git clone https://github.com/shaoanlu/PiMPC-python.git

And install in edit mode

pip install -e .

Usage

Refer to examples:

  • examples/afti16_example.py (linear AFTI-16 aircraft model)
  • examples/unicycle_nmpc_example.py (nonlinear unicycle with time-varying linearization) Open In Colab

Create a model, configure with Modelsetup(), and solve with Model.solve().

model = Model()
model.setup(A, B, Np, kwargs...)
results = model.solve(x0, u0, yref, uref, w, verbose=False)

Required Arguments:

  • A: State matrix
  • B: Input matrix
  • Np: Prediction horizon

Optional Problem Arguments:

  • C: Output matrix (default: I, meaning y = x)
  • e: Affine term in dynamics (default: zeros)
  • Wy: Output weight matrix (default: I)
  • Wu: Input weight matrix (default: I)
  • Wdu: Input increment weight matrix (default: I)
  • Wf: Terminal cost weight matrix (default: Wy)
  • xmin, xmax: State constraints (default: ±Inf)
  • umin, umax: Input constraints (default: ±Inf)
  • dumin, dumax: Input increment constraints (default: ±Inf)

Solver Settings:

  • rho: ADMM penalty parameter (default: 1.0)
  • tol: Convergence tolerance (default: 1e-4)
  • eta: Acceleration restart factor (default: 0.999)
  • maxiter: Maximum iterations (default: 100)
  • precond: Use preconditioning (default: false)
  • accel: Use Nesterov acceleration (default: false)
  • device: Compute device, cpu or gpu (default: cpu)

System Model:

x_{k+1} = A * x_k + B * u_k + e + w
y_k = C * x_k

where:

  • e: Constant affine term (defined in setup!)
  • w: Known/measured disturbance (provided at solve time)

Arguments:

  • x0: Current state (nx)
  • u0: Previous input (nu)
  • yref: Output reference (ny)
  • uref: Input reference (nu)
  • w: Known disturbance (nx), use zeros(nx) if none

Testing

pytest tests/test_pimpc.py
# ================================================= test session starts # ==================================================
# platform linux -- Python 3.10.14, pytest-9.0.2, pluggy-1.6.0
# rootdir: /mnt/c/Users/shaoa/Documents/GitHub/PiMPC-python
# configfile: pyproject.toml
# collected 6 items
# 
# tests/test_pimpc.py ......                                                                                       # [100%]
# 
# ================================================== 6 passed in 0.43s # ===================================================

About

Unofficial Python port of piMPC: A Parallel-in-horizon and Construction-free NMPC Solver

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages

  • Python 100.0%