8000 clean up steering-optimal example · python-control/python-control@5838c2f · GitHub
[go: up one dir, main page]

Skip to content

Commit 5838c2f

Browse files
committed
clean up steering-optimal example
1 parent d735f79 commit 5838c2f

File tree

1 file changed

+11
-18
lines changed

1 file changed

+11
-18
lines changed

examples/steering-optimal.py

Lines changed: 11 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -101,9 +101,6 @@ def plot_results(t, y, u, figure=None, yf=None):
101101
# distance form the desired final point while at the same time as not
102102
# exerting too much control effort to achieve our goal.
103103
#
104-
# Note: depending on what version of SciPy you are using, you might get a
105-
# warning message about precision loss, but the solution is pretty good.
106-
#
107104
print("Approach 1: standard quadratic cost")
108105

109106
# Set up the cost functions
@@ -126,11 +123,8 @@ def plot_results(t, y, u, figure=None, yf=None):
126123
start_time = time.process_time()
127124
result1 = opt.solve_ocp(
128125
vehicle, horizon, x0, quad_cost, initial_guess=bend_left, log=True,
129-
# solve_ivp_kwargs={'atol': 1e-2, 'rtol': 1e-2},
130-
# solve_ivp_kwargs={'method': 'RK23', 'atol': 1e-2, 'rtol': 1e-2},
131126
minimize_method='trust-constr',
132127
minimize_options={'finite_diff_rel_step': 0.01},
133-
# minimize_options={'eps': 0.01}
134128
)
135129
print("* Total time = %5g seconds\n" % (time.process_time() - start_time))
136130

@@ -171,7 +165,6 @@ def plot_results(t, y, u, figure=None, yf=None):
171165
result2 = opt.solve_ocp(
172166
vehicle, horizon, x0, traj_cost, constraints, terminal_cost=term_cost,
173167
initial_guess=bend_left, log=True,
174-
# solve_ivp_kwargs={'atol': 1e-4, 'rtol': 1e-2},
175168
minimize_method='SLSQP', minimize_options={'eps': 0.01})
176169
print("* Total time = %5g seconds\n" % (time.process_time() - start_time))
177170

@@ -191,13 +184,13 @@ def plot_results(t, y, u, figure=None, yf=None):
191184
# with a terminal *constraint* on the state. If a solution is found,
192185
# it guarantees we get to exactly the final state.
193186
#
194-
# To speeds things up a bit, we initalize the problem using the previous
195-
# optimal controller (which didn't quite hit the final value).
196-
#
197187
print("Approach 3: terminal constraints")
198188

199189
# Input cost and terminal constraints
190+
R = np.diag([1, 1]) # minimize applied inputs
200191
cost3 = opt.quadratic_cost(vehicle, np.zeros((3,3)), R, u0=uf)
192+
constraints = [
193+
opt.input_range_constraint(vehicle, [8, -0.1], [12, 0.1]) ]
201194
terminal = [ opt.state_range_constraint(vehicle, xf, xf) ]
202195

203196
# Reset logging to its default values
@@ -209,10 +202,10 @@ def plot_results(t, y, u, figure=None, yf=None):
209202
start_time = time.process_time()
210203
result3 = opt.solve_ocp(
211204
vehicle, horizon, x0, cost3, constraints,
212-
terminal_constraints=terminal, initial_guess=u2, log=False,
213-
solve_ivp_kwargs={'atol': 1e-4, 'rtol': 1e-2},
214-
# solve_ivp_kwargs={'method': 'RK23', 'atol': 1e-4, 'rtol': 1e-2},
215-
minimize_options={'eps': 0.01})
205+
terminal_constraints=terminal, initial_guess=bend_left, log=False,
206+
solve_ivp_kwargs={'atol': 1e-3, 'rtol': 1e-2},
207+
minimize_method='trust-constr',
208+
)
216209
print("* Total time = %5g seconds\n" % (time.process_time() - start_time))
217210

218211
# If we are running CI tests, make sure we succeeded
@@ -241,12 +234,12 @@ def plot_results(t, y, u, figure=None, yf=None):
241234
vehicle, horizon, x0, quad_cost,
242235
constraints,
243236
terminal_constraints=terminal,
244-
initial_guess=u3,
237+
initial_guess=bend_left,
245238
basis=flat.BezierFamily(4, T=Tf),
246-
solve_ivp_kwargs={'method': 'RK45', 'atol': 1e-2, 'rtol': 1e-2},
239+
# solve_ivp_kwargs={'method': 'RK45', 'atol': 1e-2, 'rtol': 1e-2},
240+
solve_ivp_kwargs={'atol': 1e-3, 'rtol': 1e-2},
247241
minimize_method='trust-constr', minimize_options={'disp': True},
248 5334 -
# method='SLSQP', options={'eps': 0.01}
249-
log=True
242+
log=False
250243
)
251244
print("* Total time = %5g seconds\n" % (time.process_time() - start_time))
252245

0 commit comments

Comments
 (0)
0