A Python port of PiMPC.
Clone this repository
git clone https://github.com/shaoanlu/PiMPC-python.gitAnd install in edit mode
pip install -e .Refer to examples:
examples/afti16_example.py(linear AFTI-16 aircraft model)examples/unicycle_nmpc_example.py(nonlinear unicycle with time-varying linearization)
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 matrixB: Input matrixNp: 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,cpuorgpu(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 insetup!)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), usezeros(nx)if none
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 # ===================================================
