88import numpy as np
99import math
1010import control as ct
11- import control .optimal as opt
11+ import control .optimal as obc
1212import matplotlib .pyplot as plt
1313import logging
1414import time
@@ -106,7 +106,7 @@ def plot_lanechange(t, y, u, yf=None, figure=None):
106106# Set up the cost functions
107107Q = np .diag ([.1 , 10 , .1 ]) # keep lateral error low
108108R = np .diag ([.1 , 1 ]) # minimize applied inputs
109- quad_cost = opt .quadratic_cost (vehicle , Q , R , x0 = xf , u0 = uf )
109+ quad_cost = obc .quadratic_cost (vehicle , Q , R , x0 = xf , u0 = uf )
110110
111111# Define the time horizon (and spacing) for the optimization
112112timepts = np .linspace (0 , Tf , 20 , endpoint = True )
@@ -124,7 +124,7 @@ def plot_lanechange(t, y, u, yf=None, figure=None):
124124
125125# Compute the optimal control, setting step size for gradient calculation (eps)
126126start_time = time .process_time ()
127- result1 = opt .solve_ocp (
127+ result1 = obc .solve_ocp (
128128 vehicle , timepts , x0 , quad_cost , initial_guess = straight_line , log = True ,
129129 # minimize_method='trust-constr',
130130 # minimize_options={'finite_diff_rel_step': 0.01},
@@ -158,9 +158,9 @@ def plot_lanechange(t, y, u, yf=None, figure=None):
158158print ("\n Approach 2: input cost and constraints plus terminal cost" )
159159
160160# Add input constraint, input cost, terminal cost
161- constraints = [ opt .input_range_constraint (vehicle , [8 , - 0.1 ], [12 , 0.1 ]) ]
162- traj_cost = opt .quadratic_cost (vehicle , None , np .diag ([0.1 , 1 ]), u0 = uf )
163- term_cost = opt .quadratic_cost (vehicle , np .diag ([1 , 10 , 10 ]), None , x0 = xf )
161+ constraints = [ obc .input_range_constraint (vehicle , [8 , - 0.1 ], [12 , 0.1 ]) ]
162+ traj_cost = obc .quadratic_cost (vehicle , None , np .diag ([0.1 , 1 ]), u0 = uf )
163+ term_cost = obc .quadratic_cost (vehicle , np .diag ([1 , 10 , 10 ]), None , x0 = xf )
164164
165165# Change logging to keep less information
166166logging .basicConfig (
@@ -175,7 +175,7 @@ def plot_lanechange(t, y, u, yf=None, figure=None):
175175
176176# Compute the optimal control
177177start_time = time .process_time ()
178- result2 = opt .solve_ocp (
178+ result2 = obc .solve_ocp (
179179 vehicle , timepts , x0 , traj_cost , constraints , terminal_cost = term_cost ,
180180 initial_guess = straight_line , log = True ,
181181 # minimize_method='SLSQP', minimize_options={'eps': 0.01}
@@ -207,10 +207,10 @@ def plot_lanechange(t, y, u, yf=None, figure=None):
207207
208208# Input cost and terminal constraints
209209R = np .diag ([1 , 1 ]) # minimize applied inputs
210- cost3 = opt .quadratic_cost (vehicle , np .zeros ((3 ,3 )), R , u0 = uf )
210+ cost3 = obc .quadratic_cost (vehicle , np .zeros ((3 ,3 )), R , u0 = uf )
211211constraints = [
212- opt .input_range_constraint (vehicle , [8 , - 0.1 ], [12 , 0.1 ]) ]
213- terminal = [ opt .state_range_constraint (vehicle , xf , xf ) ]
212+ obc .input_range_constraint (vehicle , [8 , - 0.1 ], [12 , 0.1 ]) ]
213+ terminal = [ obc .state_range_constraint (vehicle , xf , xf ) ]
214214
215215# Reset logging to its default values
216216logging .basicConfig (
@@ -219,7 +219,7 @@ def plot_lanechange(t, y, u, yf=None, figure=None):
219219
220220# Compute the optimal control
221221start_time = time .process_time ()
222- result3 = opt .solve_ocp (
222+ result3 = obc .solve_ocp (
223223 vehicle , timepts , x0 , cost3 , constraints ,
224224 terminal_constraints = terminal , initial_guess = straight_line , log = False ,
225225 # solve_ivp_kwargs={'atol': 1e-3, 'rtol': 1e-2},
@@ -254,7 +254,7 @@ def plot_lanechange(t, y, u, yf=None, figure=None):
254254
255255# Compute the optimal control
256256start_time = time .process_time ()
257- result4 = opt .solve_ocp (
257+ result4 = obc .solve_ocp (
258258 vehicle , timepts , x0 , quad_cost ,
259259 constraints ,
260260 terminal_constraints = terminal ,
0 commit comments