home / skills / benchflow-ai / skillsbench / mpc-horizon-tuning

This skill helps you tune MPC horizons and cost matrices for tension control, balancing tracking performance and actuator effort.

npx playbooks add skill benchflow-ai/skillsbench --skill mpc-horizon-tuning

Review the files below or copy the command above to add this skill to your agents.

Files (1)
SKILL.md
1.2 KB
---
name: mpc-horizon-tuning
description: Selecting MPC prediction horizon and cost matrices for web handling.
---

# MPC Tuning for Tension Control

## Prediction Horizon Selection

**Horizon N** affects performance and computation:
- Too short (N < 5): Poor disturbance rejection
- Too long (N > 20): Excessive computation
- Rule of thumb: N ≈ 2-3× settling time / dt

For R2R systems with dt=0.01s: **N = 5-15** typical

## Cost Matrix Design

**State cost Q**: Emphasize tension tracking
```python
Q_tension = 100 / T_ref²  # High weight on tensions
Q_velocity = 0.1 / v_ref²  # Lower weight on velocities
Q = diag([Q_tension × 6, Q_velocity × 6])
```

**Control cost R**: Penalize actuator effort
```python
R = 0.01-0.1 × eye(n_u)  # Smaller = more aggressive
```

## Trade-offs

| Higher Q | Effect |
|----------|--------|
| Faster tracking | More control effort |
| Lower steady-state error | More aggressive transients |

| Higher R | Effect |
|----------|--------|
| Smoother control | Slower response |
| Less actuator wear | Higher tracking error |

## Terminal Cost

Use LQR solution for terminal cost to guarantee stability:
```python
P = solve_continuous_are(A, B, Q, R)
```

Overview

This skill helps select an MPC prediction horizon and design state/control cost matrices specifically for web-handling tension control. It provides practical rules of thumb for horizon sizing, concrete Q/R scaling suggestions, and guidance on terminal cost selection to ensure stability. The guidance is tuned for roll-to-roll (R2R) systems and fast sampling rates.

How this skill works

The skill evaluates system sampling time and typical settling behavior to recommend a prediction horizon that balances disturbance rejection and computation. It prescribes how to scale state cost Q to prioritize tension tracking and how to choose control cost R to trade off aggression versus actuator wear. It also recommends computing an LQR terminal cost (P) to guarantee stability at the horizon.

When to use it

  • Tuning MPC for web tension control on roll-to-roll lines or drying ovens.
  • Balancing controller performance vs available computation for fast‑sampled systems (e.g., dt ≈ 0.01 s).
  • When disturbance rejection (tension spikes) is critical and needs explicit weighting.
  • Designing controllers where actuator effort or wear must be limited.
  • Before deploying to hardware—use these rules for simulation-first validation.

Best practices

  • Select N roughly 2–3 times the system settling time divided by dt; for R2R with dt=0.01 s, start with N = 5–15.
  • Scale Q to emphasize tension tracking: use a high weight on tension terms (e.g., Q_tension = 100 / T_ref^2) and lower weights on velocities.
  • Choose R in the 0.01–0.1 range per actuator (smaller values drive more aggressive control; larger values smooth commands and reduce wear).
  • Compute the terminal cost P by solving the continuous-time algebraic Riccati equation (CARE) for A, B, Q, R to improve closed-loop stability.
  • Validate settings in simulation across disturbance profiles and then iterate: increase N if rejection is poor, raise R if actuators saturate.

Example use cases

  • Tuning an MPC for a roll-to-roll coating line to reduce tension excursions during splicing events.
  • Designing an MPC for web transport where sampling is fast and computational budget is limited.
  • Adjusting trade-offs between tracking and actuator life on a high-speed printing press.
  • Rapidly choosing initial Q and R values for offline simulation before hardware-in-the-loop testing.
  • Applying terminal LQR cost to guarantee stability when using a finite horizon controller.

FAQ

How do I choose the initial prediction horizon N?

Start with N ≈ 2–3 × (settling time / dt). For typical R2R with dt=0.01 s use N = 5–15 and increase if disturbance rejection is insufficient.

What if actuators saturate with my chosen Q?

Increase R to penalize actuator effort more, or reduce Q on less critical states; also test slower horizon growth or add actuator constraints and re‑tune.