MPC API
skelarm.mpc
Joint-space model predictive control.
A finite-horizon optimal-control tracker: at each control step it rolls out the forward dynamics over a horizon, optimizes the torque sequence to track a joint reference (with torque bounds and soft joint-limit penalties), applies only the first torque, and warm-starts the next solve from the shifted solution.
This is the stateful, model-based tracker from docs/reference/07_control.md; it
must be run with the fixed-step :func:skelarm.control.simulate_controlled loop.
JointSpaceMPC
Bases: Controller
Receding-horizon joint-space tracker using :func:scipy.optimize.minimize.
The prediction model is semi-implicit Euler over :func:compute_forward_dynamics,
matching the integration in :func:skelarm.control.simulate_controlled; run the
controller with the same dt.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
reference
|
JointReference
|
The joint reference providing |
required |
horizon
|
int
|
Number of prediction/control steps |
required |
dt
|
float
|
Control interval and rollout step (seconds); match |
required |
q_weight
|
float
|
Stage weights on the joint-position and joint-velocity tracking error. |
10.0
|
dq_weight
|
float
|
Stage weights on the joint-position and joint-velocity tracking error. |
10.0
|
tau_weight
|
float
|
Stage weight (effort penalty) on the torque. |
0.001
|
terminal_weight
|
float
|
Weight on the terminal joint-position error. |
50.0
|
tau_max
|
float | None
|
Symmetric torque bound; |
None
|
limit_weight
|
float
|
Soft joint-limit penalty weight (0 disables it). |
0.0
|
max_iter
|
int
|
Maximum optimizer iterations per control step. |
20
|
Source code in src/skelarm/mpc.py
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 | |
__init__(reference, *, horizon, dt, q_weight=10.0, dq_weight=1.0, tau_weight=0.001, terminal_weight=50.0, tau_max=None, limit_weight=0.0, max_iter=20)
Store the reference, horizon, weights, and optimizer settings.
Source code in src/skelarm/mpc.py
control(t, skeleton)
Optimize the horizon torque sequence and return only the first torque.
Source code in src/skelarm/mpc.py
log_channels()
Record the current reference and tracking error once control has run.
reset(skeleton)
Build the prediction model and clear the warm-start torque sequence.