@@ -112,15 +112,15 @@ problem into a standard optimization problem that can be solved by
112112:func: `scipy.optimize.minimize `. The optimal control problem can be solved
113113by using the :func: `~control.obc.solve_ocp ` function::
114114
115- res = obc.solve_ocp(sys, horizon , X0, cost, constraints)
115+ res = obc.solve_ocp(sys, timepts , X0, cost, constraints)
116116
117117The `sys ` parameter should be an :class: `~control.InputOutputSystem ` and the
118- `horizon ` parameter should represent a time vector that gives the list of
118+ `timepts ` parameter should represent a time vector that gives the list of
119119times at which the cost and constraints should be evaluated.
120120
121121The `cost ` function has call signature `cost(t, x, u) ` and should return the
122122(incremental) cost at the given time, state, and input. It will be
123- evaluated at each point in the `horizon ` vector. The `terminal_cost `
123+ evaluated at each point in the `timepts ` vector. The `terminal_cost `
124124parameter can be used to specify a cost function for the final point in the
125125trajectory.
126126
@@ -157,7 +157,7 @@ that has the following elements:
157157 * `res.success `: `True ` if the optimization was successfully solved
158158 * `res.inputs `: optimal input
159159 * `res.states `: state trajectory (if `return_x ` was `True `)
160- * `res.time `: copy of the time horizon vector
160+ * `res.time `: copy of the time timepts vector
161161
162162In addition, the results from :func: `scipy.optimize.minimize ` are also
163163available.
@@ -235,16 +235,16 @@ and constrain the velocity to be in the range of 9 m/s to 11 m/s::
235235
236236Finally, we solve for the optimal inputs::
237237
238- horizon = np.linspace(0, Tf, 3 , endpoint=True)
238+ timepts = np.linspace(0, Tf, 10 , endpoint=True)
239239 result = opt.solve_ocp(
240- vehicle, horizon , x0, traj_cost, constraints,
240+ vehicle, timepts , x0, traj_cost, constraints,
241241 terminal_cost=term_cost, initial_guess=u0)
242242
243243Plotting the results::
244244
245245 # Simulate the system dynamics (open loop)
246246 resp = ct.input_output_response(
247- vehicle, horizon , result.inputs, x0,
247+ vehicle, timepts , result.inputs, x0,
248248 t_eval=np.linspace(0, Tf, 100))
249249 t, y, u = resp.time, resp.outputs, resp.inputs
250250
@@ -262,7 +262,7 @@ Plotting the results::
262262
263263 plt.subplot(3, 1, 3)
264264 plt.plot(t, u[1])
265- plt.axis([0, 10, -0.01 , 0.01 ])
265+ plt.axis([0, 10, -0.015 , 0.015 ])
266266 plt.xlabel("t [sec]")
267267 plt.ylabel("u2 [rad/s]")
268268
@@ -282,6 +282,11 @@ toolbox and it can sometimes be tricky to get the optimization to converge.
282282If you are getting errors when solving optimal control problems or your
283283solutions do not seem close to optimal, here are a few things to try:
284284
285+ * The initial guess matters: providing a reasonable initial guess is often
286+ needed in order for the optimizer to find a good answer. For an optimal
287+ control problem that uses a larger terminal cost to get to a neighborhood
288+ of a final point, a straight line in the state space often works well.
289+
285290* Less is more: try using a smaller number of time points in your
286291 optimiation. The default optimal control problem formulation uses the
287292 value of the inputs at each time point as a free variable and this can
0 commit comments