@@ -89,7 +89,8 @@ def time_optimal_lq_basis(basis_name, basis_size, npoints):
89
89
basis = get_basis (basis_name , basis_size , Tf )
90
90
91
91
res = opt .solve_ocp (
92
- sys , timepts , x0 , traj_cost , constraints , terminal_cost = term_cost ,
92
+ sys , timepts , x0 , traj_cost , constraints , terminal_cost = term_cost ,
93
+ basis = basis ,
93
94
)
94
95
# Only count this as a benchmark if we converged
95
96
assert res .success
@@ -130,7 +131,7 @@ def time_optimal_lq_methods(integrator_name, minimizer_name):
130
131
basis = get_basis ('poly' , 12 , Tf )
131
132
132
133
res = opt .solve_ocp (
133
- sys , timepts , x0 , traj_cost , constraints , terminal_cost = term_cost ,
134
+ sys , timepts , x0 , traj_cost , constraints , terminal_cost = term_cost ,
134
135
solve_ivp_method = integrator [0 ], solve_ivp_kwargs = integrator [1 ],
135
136
minimize_method = minimizer [0 ], minimize_options = minimizer [1 ],
136
137
)
@@ -179,21 +180,21 @@ def time_optimal_lq_size(nstates, ninputs, npoints):
179
180
timepts = np .linspace (0 , Tf , npoints )
180
181
181
182
res = opt .solve_ocp (
182
- sys , timepts , x0 , traj_cost , constraints , terminal_cost = term_cost ,
183
+ sys , timepts , x0 , traj_cost , constraints , terminal_cost = term_cost ,
183
184
)
184
185
# Only count this as a benchmark if we converged
185
186
assert res .success
186
187
187
188
# Parameterize the test against different choices of integrator and minimizer
188
189
time_optimal_lq_size .param_names = ['nstates' , 'ninputs' , 'npoints' ]
189
190
time_optimal_lq_size .params = ([1 , 2 , 4 ], [1 , 2 , 4 ], [5 , 10 , 20 ])
190
-
191
+
191
192
192
193
#
193
194
# Aircraft MPC example (from multi-parametric toolbox)
194
195
#
195
196
196
- def time_aircraft_mpc ( ):
197
+ def time_discrete_aircraft_mpc ( minimizer_name ):
197
198
# model of an aircraft discretized with 0.2s sampling time
198
199
# Source: https://www.mpt3.org/UI/RegulationProblem
199
200
A = [[0.99 , 0.01 , 0.18 , - 0.09 , 0 ],
@@ -228,9 +229,18 @@ def time_aircraft_mpc():
228
229
R = np .diag ([3 , 2 ])
229
230
cost = opt .quadratic_cost (model , Q , R , x0 = xd , u0 = ud )
230
231
232
+ # Set the time horizon and time points
233
+ Tf = 3
234
+ timepts = np .arange (0 , 6 ) * 0.2
235
+
236
+ # Get the minimizer parameters to use
237
+ minimizer = minimizer_table [minimizer_name ]
238
+
231
239
# online MPC controller object is constructed with a horizon 6
232
240
ctrl = opt .create_mpc_iosystem (
233
- model , np .arange (0 , 6 ) * 0.2 , cost , constraints )
241
+ model , timepts , cost , constraints ,
242
+ minimize_method = minimizer [0 ], minimize_options = minimizer [1 ],
243
+ )
234
244
235
245
# Define an I/O system implementing model predictive control
236
246
loop = ct .feedback (sys , ctrl , 1 )
@@ -245,3 +255,8 @@ def time_aircraft_mpc():
245
255
# Make sure the system converged to the desired state
246
256
np .testing .assert_allclose (
247
257
xout [0 :sys .nstates , - 1 ], xd , atol = 0.1 , rtol = 0.01 )
258
+
259
+ # Parameterize the test against different choices of minimizer and basis
260
+ time_discrete_aircraft_mpc .param_names = ['minimizer' ]
261
+ time_discrete_aircraft_mpc .params = (
262
+ ['trust' , 'trust_bigstep' , 'SLSQP' , 'SLSQP_bigstep' , 'COBYLA' ])
0 commit comments