@@ -89,7 +89,8 @@ def time_optimal_lq_basis(basis_name, basis_size, npoints):
8989 basis = get_basis (basis_name , basis_size , Tf )
9090
9191 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 ,
9394 )
9495 # Only count this as a benchmark if we converged
9596 assert res .success
@@ -130,7 +131,7 @@ def time_optimal_lq_methods(integrator_name, minimizer_name):
130131 basis = get_basis ('poly' , 12 , Tf )
131132
132133 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 ,
134135 solve_ivp_method = integrator [0 ], solve_ivp_kwargs = integrator [1 ],
135136 minimize_method = minimizer [0 ], minimize_options = minimizer [1 ],
136137 )
@@ -179,21 +180,21 @@ def time_optimal_lq_size(nstates, ninputs, npoints):
179180 timepts = np .linspace (0 , Tf , npoints )
180181
181182 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 ,
183184 )
184185 # Only count this as a benchmark if we converged
185186 assert res .success
186187
187188# Parameterize the test against different choices of integrator and minimizer
188189time_optimal_lq_size .param_names = ['nstates' , 'ninputs' , 'npoints' ]
189190time_optimal_lq_size .params = ([1 , 2 , 4 ], [1 , 2 , 4 ], [5 , 10 , 20 ])
190-
191+
191192
192193#
193194# Aircraft MPC example (from multi-parametric toolbox)
194195#
195196
196- def time_aircraft_mpc ( ):
197+ def time_discrete_aircraft_mpc ( minimizer_name ):
197198 # model of an aircraft discretized with 0.2s sampling time
198199 # Source: https://www.mpt3.org/UI/RegulationProblem
199200 A = [[0.99 , 0.01 , 0.18 , - 0.09 , 0 ],
@@ -228,9 +229,18 @@ def time_aircraft_mpc():
228229 R = np .diag ([3 , 2 ])
229230 cost = opt .quadratic_cost (model , Q , R , x0 = xd , u0 = ud )
230231
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+
231239 # online MPC controller object is constructed with a horizon 6
232240 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+ )
234244
235245 # Define an I/O system implementing model predictive control
236246 loop = ct .feedback (sys , ctrl , 1 )
@@ -245,3 +255,8 @@ def time_aircraft_mpc():
245255 # Make sure the system converged to the desired state
246256 np .testing .assert_allclose (
247257 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