Skip to content

Commit bf232c0

Browse files
committed
Merge branch 'main' into feature/support-ltv
2 parents e987aaf + 3a37e4a commit bf232c0

File tree

2 files changed

+59
-6
lines changed

2 files changed

+59
-6
lines changed

README.md

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,56 @@ Refer to [examples](examples/):
1515
- `examples/afti16_example.py` (linear AFTI-16 aircraft model)
1616
- `examples/unicycle_nmpc_example.py` (nonlinear unicycle with time-varying linearization)
1717

18+
Create a model, configure with `Modelsetup()`, and solve with `Model.solve()`.
19+
20+
```python
21+
model = Model()
22+
model.setup(A, B, Np, kwargs...)
23+
results = model.solve(x0, u0, yref, uref, w, verbose=False)
24+
```
25+
26+
**Required Arguments:**
27+
- `A`: State matrix
28+
- `B`: Input matrix
29+
- `Np`: Prediction horizon
30+
31+
**Optional Problem Arguments:**
32+
- `C`: Output matrix (default: I, meaning y = x)
33+
- `e`: Affine term in dynamics (default: zeros)
34+
- `Wy`: Output weight matrix (default: I)
35+
- `Wu`: Input weight matrix (default: I)
36+
- `Wdu`: Input increment weight matrix (default: I)
37+
- `Wf`: Terminal cost weight matrix (default: Wy)
38+
- `xmin, xmax`: State constraints (default: ±Inf)
39+
- `umin, umax`: Input constraints (default: ±Inf)
40+
- `dumin, dumax`: Input increment constraints (default: ±Inf)
41+
42+
**Solver Settings:**
43+
- `rho`: ADMM penalty parameter (default: 1.0)
44+
- `tol`: Convergence tolerance (default: 1e-4)
45+
- `eta`: Acceleration restart factor (default: 0.999)
46+
- `maxiter`: Maximum iterations (default: 100)
47+
- `precond`: Use preconditioning (default: false)
48+
- `accel`: Use Nesterov acceleration (default: false)
49+
- `device`: Compute device, `cpu` or `gpu` (default: cpu)
50+
51+
**System Model:**
52+
```
53+
x_{k+1} = A * x_k + B * u_k + e + w
54+
y_k = C * x_k
55+
```
56+
57+
where:
58+
- `e`: Constant affine term (defined in `setup!`)
59+
- `w`: Known/measured disturbance (provided at solve time)
60+
61+
**Arguments:**
62+
- `x0`: Current state (nx)
63+
- `u0`: Previous input (nu)
64+
- `yref`: Output reference (ny)
65+
- `uref`: Input reference (nu)
66+
- `w`: Known disturbance (nx), use `zeros(nx)` if none
67+
1868
![](assets/example_afti16.png)
1969

2070
![](assets/example_unicycle.png)

pimpc/solver.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -381,16 +381,19 @@ def _solve_gpu(model, x0, u0, yref, uref, w, *, warm_vars=None, verbose=False):
381381
E_inv = cp.ones(nx_bar, dtype=dtype)
382382

383383
C_part = C_bar[:, :nx]
384-
Q_bar = cp.block(
384+
Q11 = C_part.T @ cp.asarray(model.Wy, dtype=dtype) @ C_part
385+
Q22 = cp.asarray(model.Wu, dtype=dtype)
386+
Q_bar = cp.vstack(
385387
[
386-
[C_part.T @ cp.asarray(model.Wy, dtype=dtype) @ C_part, cp.zeros((nx, nu), dtype=dtype)],
387-
[cp.zeros((nu, nx), dtype=dtype), cp.asarray(model.Wu, dtype=dtype)],
388+
cp.hstack([Q11, cp.zeros((nx, nu), dtype=dtype)]),
389+
cp.hstack([cp.zeros((nu, nx), dtype=dtype), Q22]),
388390
]
389391
)
390-
Q_bar_N = cp.block(
392+
Q11_N = C_part.T @ cp.asarray(model.Wf, dtype=dtype) @ C_part
393+
Q_bar_N = cp.vstack(
391394
[
392-
[C_part.T @ cp.asarray(model.Wf, dtype=dtype) @ C_part, cp.zeros((nx, nu), dtype=dtype)],
393-
[cp.zeros((nu, nx), dtype=dtype), cp.asarray(model.Wu, dtype=dtype)],
395+
cp.hstack([Q11_N, cp.zeros((nx, nu), dtype=dtype)]),
396+
cp.hstack([cp.zeros((nu, nx), dtype=dtype), Q22]),
394397
]
395398
)
396399
q_bar = cp.concatenate(

0 commit comments

Comments
 (0)