control.flatsys.solve_flat_ocp
- control.flatsys.solve_flat_ocp(sys, timepts, x0=0, u0=0, trajectory_cost=None, basis=None, terminal_cost=None, trajectory_constraints=None, initial_guess=None, params=None, **kwargs)[source]
Compute trajectory between an initial and final conditions.
Compute an optimial trajectory for a differentially flat system starting from an initial state and input value.
- Parameters
flatsys (FlatSystem object) – Description of the differentially flat system. This object must define a function flatsys.forward() that takes the system state and produceds the flag of flat outputs and a system flatsys.reverse() that takes the flag of the flat output and prodes the state and input.
timepts (float or 1D array_like) – The list of points for evaluating cost and constraints, as well as the time horizon. If given as a float, indicates the final time for the trajectory (corresponding to xf)
x0 (1D arrays) – Define the initial conditions for the system. If either of the values are given as None, they are replaced by a vector of zeros of the appropriate dimension.
u0 (1D arrays) – Define the initial conditions for the system. If either of the values are given as None, they are replaced by a vector of zeros of the appropriate dimension.
basis (
BasisFamily
object, optional) – The basis functions to use for generating the trajectory. If not specified, thePolyFamily
basis family will be used, with the minimal number of elements required to find a feasible trajectory (twice the number of system states)trajectory_cost (callable) – Function that returns the integral cost given the current state and input. Called as cost(x, u).
terminal_cost (callable) – Function that returns the terminal cost given the state and input. Called as cost(x, u).
trajectory_constraints (list of tuples, optional) –
List of constraints that should hold at each point in the time vector. Each element of the list should consist of a tuple with first element given by
scipy.optimize.LinearConstraint
orscipy.optimize.NonlinearConstraint
and the remaining elements of the tuple are the arguments that would be passed to those functions. The following tuples are supported:(LinearConstraint, A, lb, ub): The matrix A is multiplied by stacked vector of the state and input at each point on the trajectory for comparison against the upper and lower bounds.
(NonlinearConstraint, fun, lb, ub): a user-specific constraint function fun(x, u) is called at each point along the trajectory and compared against the upper and lower bounds.
The constraints are applied at each time point along the trajectory.
initial_guess (2D array_like, optional) – Initial guess for the optimal trajectory of the flat outputs.
minimize_kwargs (str, optional) – Pass additional keywords to
scipy.optimize.minimize()
.
- Returns
traj – The system trajectory is returned as an object that implements the eval() function, we can be used to compute the value of the state and input and a given time t.
- Return type
SystemTrajectory
object
Notes
Additional keyword parameters can be used to fine tune the behavior of the underlying optimization function. See minimize_* keywords in
OptimalControlProblem()
for more information.- The return data structure includes the following additional attributes:
success : bool indicating whether the optimization succeeded
cost : computed cost of the returned trajectory
message : message returned by optimization if success if False
A common failure in solving optimal control problem is that the default initial guess violates the constraints and the optimizer can’t find a feasible solution. Using the initial_guess parameter can often be used to overcome these errors.